blob: 6fe81234f5bdde9dc2b23fe607bb4362ea350327 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Gopichand Nakkala92f07d82013-01-08 21:16:34 -08002 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21/*
Jeff Johnson32d95a32012-09-10 13:15:23 -070022 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -070023 *
24 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
25 *
26 *
27 * Permission to use, copy, modify, and/or distribute this software for
28 * any purpose with or without fee is hereby granted, provided that the
29 * above copyright notice and this permission notice appear in all
30 * copies.
31 *
32 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
33 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
35 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
36 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
37 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
38 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
39 * PERFORMANCE OF THIS SOFTWARE.
40 */
41
Jeff Johnson40b59aa2013-03-19 14:43:18 -070042/** ------------------------------------------------------------------------- *
43 ------------------------------------------------------------------------- *
Jeff Johnson295189b2012-06-20 16:38:30 -070044
Jeff Johnson40b59aa2013-03-19 14:43:18 -070045
Jeff Johnson295189b2012-06-20 16:38:30 -070046 \file csrApiScan.c
Jeff Johnson40b59aa2013-03-19 14:43:18 -070047
Jeff Johnson295189b2012-06-20 16:38:30 -070048 Implementation for the Common Scan interfaces.
Jeff Johnson40b59aa2013-03-19 14:43:18 -070049
50 Copyright (C) 2006 Airgo Networks, Incorporated
Jeff Johnson295189b2012-06-20 16:38:30 -070051 ========================================================================== */
52
53#include "aniGlobal.h"
54
55#include "palApi.h"
56#include "csrInsideApi.h"
57#include "smeInside.h"
58#include "smsDebug.h"
59
60#include "csrSupport.h"
61#include "wlan_qct_tl.h"
62
63#include "vos_diag_core_log.h"
64#include "vos_diag_core_event.h"
65
66#include "vos_nvitem.h"
67#include "wlan_qct_wda.h"
Jeff Johnson40b59aa2013-03-19 14:43:18 -070068
Jeff Johnson295189b2012-06-20 16:38:30 -070069#define CSR_VALIDATE_LIST //This portion of code need to be removed once the issue is resolved.
Kiet Lamd1f3dc82013-11-05 20:45:04 +053070#define MIN_CHN_TIME_TO_FIND_GO 100
71#define MAX_CHN_TIME_TO_FIND_GO 100
72#define DIRECT_SSID_LEN 7
Jeff Johnson295189b2012-06-20 16:38:30 -070073
74#ifdef CSR_VALIDATE_LIST
75tDblLinkList *g_pchannelPowerInfoList24 = NULL, * g_pchannelPowerInfoList5 = NULL;
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -070076tpAniSirGlobal g_pMac;
Jeff Johnson295189b2012-06-20 16:38:30 -070077#endif
78
79/* Purpose of HIDDEN_TIMER
80** When we remove hidden ssid from the profile i.e., forget the SSID via GUI that SSID shouldn't see in the profile
81** For above requirement we used timer limit, logic is explained below
82** Timer value is initialsed to current time when it receives corresponding probe response of hidden SSID (The probe request is
83** received regularly till SSID in the profile. Once it is removed from profile probe request is not sent.) when we receive probe response
84** for broadcast probe request, during update SSID with saved SSID we will diff current time with saved SSID time if it is greater than 1 min
85** then we are not updating with old one
86*/
87
88#define HIDDEN_TIMER (1*60*1000)
89#define CSR_SCAN_RESULT_RSSI_WEIGHT 80 // must be less than 100, represent the persentage of new RSSI
90
91/*---------------------------------------------------------------------------
92 PER filter constant fraction: it is a %
93---------------------------------------------------------------------------*/
94#define CSR_SCAN_PER_FILTER_FRAC 100
95
96/*---------------------------------------------------------------------------
97 RSSI filter constant fraction: it is a %
98---------------------------------------------------------------------------*/
99#define CSR_SCAN_RSSI_FILTER_FRAC 100
100
101/*---------------------------------------------------------------------------
102Convert RSSI into overall score: Since RSSI is in -dBm values, and the
103overall needs to be weighted inversely (where greater value means better
104system), we convert.
105RSSI *cannot* be more than 0xFF or less than 0 for meaningful WLAN operation
106---------------------------------------------------------------------------*/
107#define CSR_SCAN_MAX_SCORE_VAL 0xFF
108#define CSR_SCAN_MIN_SCORE_VAL 0x0
109#define CSR_SCAN_HANDOFF_DELTA 10
Jeff Johnson32d95a32012-09-10 13:15:23 -0700110#define MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL 140
111#define MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL 120
Madan Mohan Koyyalamudia53c4dc2012-11-13 10:35:42 -0800112#define CSR_SCAN_OVERALL_SCORE( rssi ) \
113 (( rssi < CSR_SCAN_MAX_SCORE_VAL ) \
114 ? (CSR_SCAN_MAX_SCORE_VAL-rssi) : CSR_SCAN_MIN_SCORE_VAL)
Jeff Johnson295189b2012-06-20 16:38:30 -0700115
116
117#define CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) \
118 ( (pMac)->scan.nBssLimit <= (csrLLCount(&(pMac)->scan.scanResultList)) )
119
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530120/* Maximum number of channels per country can be ignored */
121#define MAX_CHANNELS_IGNORE 10
122
Wilson Yange3d2b292013-10-09 00:35:43 -0700123#define MAX_COUNTRY_IGNORE 5
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530124
Agarwal Ashishd9d72602013-09-13 00:06:17 +0530125#define THIRTY_PERCENT(x) (x*30/100);
126
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530127/*struct to hold the ignored channel list based on country */
128typedef struct sCsrIgnoreChannels
129{
130 tANI_U8 countryCode[NV_FIELD_COUNTRY_CODE_SIZE];
131 tANI_U16 channelList[MAX_CHANNELS_IGNORE];
132 tANI_U16 channelCount;
133}tCsrIgnoreChannels;
134
135static tCsrIgnoreChannels countryIgnoreList[MAX_COUNTRY_IGNORE] = {
136 { {'U','A'}, { 136, 140}, 2},
137 { {'T','W'}, { 36, 40, 44, 48, 52}, 5},
Madan Mohan Koyyalamudi28dd0422013-08-12 15:06:21 +0530138 { {'I','D'}, { 165}, 1 },
Wilson Yange3d2b292013-10-09 00:35:43 -0700139 { {'A','U'}, { 120, 124, 128}, 3 },
140 { {'A','G'}, { 120, 124, 128}, 3 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530141 };
142
Jeff Johnson295189b2012-06-20 16:38:30 -0700143//*** This is temporary work around. It need to call CCM api to get to CFG later
144/// Get string parameter value
145extern tSirRetStatus wlan_cfgGetStr(tpAniSirGlobal, tANI_U16, tANI_U8*, tANI_U32*);
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530146
Jeff Johnson295189b2012-06-20 16:38:30 -0700147void csrScanGetResultTimerHandler(void *);
148void csrScanResultAgingTimerHandler(void *pv);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800149static void csrScanResultCfgAgingTimerHandler(void *pv);
Jeff Johnson295189b2012-06-20 16:38:30 -0700150void csrScanIdleScanTimerHandler(void *);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700151static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest);
Jeff Johnson295189b2012-06-20 16:38:30 -0700152#ifdef WLAN_AP_STA_CONCURRENCY
153static void csrStaApConcTimerHandler(void *);
154#endif
Jeff Johnsone7245742012-09-05 17:12:55 -0700155tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -0700156eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand );
157void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels );
158void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId );
159void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode );
160void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList );
161//if bgPeriod is 0, background scan is disabled. It is in millisecond units
162eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod);
163eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand);
164void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus);
165static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
166 tANI_U8 numChn, tSirBssDescription *pBssDesc,
167 tDot11fBeaconIEs **ppIes );
168eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels);
169void csrReleaseCmdSingle(tpAniSirGlobal pMac, tSmeCmd *pCommand);
170tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel );
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700171void csrPruneChannelListForMode( tpAniSirGlobal pMac, tCsrChannel *pChannelList );
Jeff Johnson295189b2012-06-20 16:38:30 -0700172
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700173#define CSR_IS_SOCIAL_CHANNEL(channel) (((channel) == 1) || ((channel) == 6) || ((channel) == 11) )
174
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700175
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700176
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800177static void csrReleaseScanCmdPendingList(tpAniSirGlobal pMac)
178{
179 tListElem *pEntry;
180 tSmeCmd *pCommand;
181
182 while((pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK)) != NULL)
183 {
184 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
185 if ( eSmeCsrCommandMask & pCommand->command )
186 {
187 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_TRUE );
188 }
189 else
190 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800191 smsLog(pMac, LOGE, FL("Error: Received command : %d"),pCommand->command);
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800192 }
193 }
194}
Jeff Johnson295189b2012-06-20 16:38:30 -0700195//pResult is invalid calling this function.
196void csrFreeScanResultEntry( tpAniSirGlobal pMac, tCsrScanResult *pResult )
197{
198 if( NULL != pResult->Result.pvIes )
199 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530200 vos_mem_free(pResult->Result.pvIes);
Jeff Johnson295189b2012-06-20 16:38:30 -0700201 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530202 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700203}
204
205
206static eHalStatus csrLLScanPurgeResult(tpAniSirGlobal pMac, tDblLinkList *pList)
207{
208 eHalStatus status = eHAL_STATUS_SUCCESS;
209 tListElem *pEntry;
210 tCsrScanResult *pBssDesc;
211
212 csrLLLock(pList);
213
214 while((pEntry = csrLLRemoveHead(pList, LL_ACCESS_NOLOCK)) != NULL)
215 {
216 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
217 csrFreeScanResultEntry( pMac, pBssDesc );
218 }
219
220 csrLLUnlock(pList);
221
222 return (status);
223}
224
225
226int csrCheckValidateLists(void * dest, const void *src, v_SIZE_t num, int idx)
227{
228#ifdef CSR_VALIDATE_LIST
229
230 int ii = 1;
231
232 if( (NULL == g_pMac) || (!g_pMac->scan.fValidateList ) )
233 {
234 return ii;
235 }
236 if(g_pchannelPowerInfoList24)
237 {
238 //check 2.4 list
239 tListElem *pElem, *pHead;
240 int count;
241
242 count = (int)(g_pchannelPowerInfoList24->Count);
243 pHead = &g_pchannelPowerInfoList24->ListHead;
244 pElem = pHead->next;
245 if((tANI_U32)(pHead->next) > 0x00010000) //Assuming kernel address is not that low.
246 {
247 //this loop crashes if the pointer is not right
248 while(pElem->next != pHead)
249 {
250 if((tANI_U32)(pElem->next) > 0x00010000)
251 {
252 pElem = pElem->next;
253 VOS_ASSERT(count > 0);
254 count--;
255 }
256 else
257 {
258 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_FATAL,
259 " %d Detect 1 list(0x%X) error Head(0x%X) next(0x%X) Count %d, dest(0x%X) src(0x%X) numBytes(%d)",
260 idx, (unsigned int)g_pchannelPowerInfoList24, (unsigned int)pHead,
261 (unsigned int)(pHead->next), (int)g_pchannelPowerInfoList24->Count,
262 (unsigned int)dest, (unsigned int)src, (int)num);
263 VOS_ASSERT(0);
264 ii = 0;
265 break;
266 }
267 }
268 }
269 else
270 {
271 //Bad list
272 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_FATAL, " %d Detect list(0x%X) error Head(0x%X) next(0x%X) Count %d, dest(0x%X) src(0x%X) numBytes(%d)",
273 idx, (unsigned int)g_pchannelPowerInfoList24, (unsigned int)pHead,
274 (unsigned int)(pHead->next), (int)g_pchannelPowerInfoList24->Count,
275 (unsigned int)dest, (unsigned int)src, (int)num);
276 VOS_ASSERT(0);
277 ii = 0;
278 }
279 }
280 else
281 {
282 //list ok
283 ii = 1;
284 }
285
286
287 return ii;
288
289#else
290 return 1;
291#endif //#ifdef CSR_VALIDATE_LIST
292}
293
294
295eHalStatus csrScanOpen( tpAniSirGlobal pMac )
296{
297 eHalStatus status;
298
299 do
300 {
301 csrLLOpen(pMac->hHdd, &pMac->scan.scanResultList);
302 csrLLOpen(pMac->hHdd, &pMac->scan.tempScanResults);
303 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList24);
304 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList5G);
305#ifdef WLAN_AP_STA_CONCURRENCY
306 csrLLOpen(pMac->hHdd, &pMac->scan.scanCmdPendingList);
307#endif
308#ifdef CSR_VALIDATE_LIST
309 g_pchannelPowerInfoList5 = &pMac->scan.channelPowerInfoList5G;
310 g_pMac = pMac;
311 g_pchannelPowerInfoList24 = &pMac->scan.channelPowerInfoList24;
312#endif
313 pMac->scan.fFullScanIssued = eANI_BOOLEAN_FALSE;
314 pMac->scan.nBssLimit = CSR_MAX_BSS_SUPPORT;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530315 status = vos_timer_init(&pMac->scan.hTimerGetResult, VOS_TIMER_TYPE_SW, csrScanGetResultTimerHandler, pMac);
316 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700317 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800318 smsLog(pMac, LOGE, FL("cannot allocate memory for getResult timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700319 break;
320 }
321#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530322 status = vos_timer_init(&pMac->scan.hTimerStaApConcTimer, VOS_TIMER_TYPE_SW, csrStaApConcTimerHandler, pMac);
323 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700324 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800325 smsLog(pMac, LOGE, FL("cannot allocate memory for hTimerStaApConcTimer timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700326 break;
327 }
328#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530329 status = vos_timer_init(&pMac->scan.hTimerIdleScan, VOS_TIMER_TYPE_SW, csrScanIdleScanTimerHandler, pMac);
330 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700331 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800332 smsLog(pMac, LOGE, FL("cannot allocate memory for idleScan timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700333 break;
334 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530335 status = vos_timer_init(&pMac->scan.hTimerResultAging, VOS_TIMER_TYPE_SW, csrScanResultAgingTimerHandler, pMac);
336 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700337 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800338 smsLog(pMac, LOGE, FL("cannot allocate memory for ResultAging timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700339 break;
340 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530341 status = vos_timer_init(&pMac->scan.hTimerResultCfgAging, VOS_TIMER_TYPE_SW,
342 csrScanResultCfgAgingTimerHandler, pMac);
343 if (!HAL_STATUS_SUCCESS(status))
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800344 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800345 smsLog(pMac, LOGE, FL("cannot allocate memory for CFG ResultAging timer"));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800346 break;
347 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700348 }while(0);
349
350 return (status);
351}
352
353
354eHalStatus csrScanClose( tpAniSirGlobal pMac )
355{
356#ifdef CSR_VALIDATE_LIST
357 g_pchannelPowerInfoList24 = NULL;
358 g_pchannelPowerInfoList5 = NULL;
359 g_pMac = NULL;
360#endif
361 csrLLScanPurgeResult(pMac, &pMac->scan.tempScanResults);
362 csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList);
363#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800364 csrReleaseScanCmdPendingList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700365#endif
366 csrLLClose(&pMac->scan.scanResultList);
367 csrLLClose(&pMac->scan.tempScanResults);
368#ifdef WLAN_AP_STA_CONCURRENCY
369 csrLLClose(&pMac->scan.scanCmdPendingList);
370#endif
371 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList24);
372 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList5G);
373 csrLLClose(&pMac->scan.channelPowerInfoList24);
374 csrLLClose(&pMac->scan.channelPowerInfoList5G);
375 csrScanDisable(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530376 vos_timer_destroy(&pMac->scan.hTimerResultAging);
377 vos_timer_destroy(&pMac->scan.hTimerResultCfgAging);
378 vos_timer_destroy(&pMac->scan.hTimerGetResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700379#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530380 vos_timer_destroy(&pMac->scan.hTimerStaApConcTimer);
Jeff Johnson295189b2012-06-20 16:38:30 -0700381#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530382 vos_timer_destroy(&pMac->scan.hTimerIdleScan);
Jeff Johnson295189b2012-06-20 16:38:30 -0700383 return eHAL_STATUS_SUCCESS;
384}
385
386
387eHalStatus csrScanEnable( tpAniSirGlobal pMac )
388{
389
390 pMac->scan.fScanEnable = eANI_BOOLEAN_TRUE;
391 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
392
393 return eHAL_STATUS_SUCCESS;
394}
395
396
397eHalStatus csrScanDisable( tpAniSirGlobal pMac )
398{
399
400 csrScanStopTimers(pMac);
401 pMac->scan.fScanEnable = eANI_BOOLEAN_FALSE;
402
403 return eHAL_STATUS_SUCCESS;
404}
405
406
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700407//Set scan timing parameters according to state of other driver sessions
408//No validation of the parameters is performed.
409static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest)
410{
411#ifdef WLAN_AP_STA_CONCURRENCY
412 if(csrIsAnySessionConnected(pMac))
413 {
414 //If multi-session, use the appropriate default scan times
415 if(scanType == eSIR_ACTIVE_SCAN)
416 {
417 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTimeConc;
418 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTimeConc;
419 }
420 else
421 {
422 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTimeConc;
423 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTimeConc;
424 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530425 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
426 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700427
428 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
429
430 //Return so that fields set above will not be overwritten.
431 return;
432 }
433#endif
434
435 //This portion of the code executed if multi-session not supported
436 //(WLAN_AP_STA_CONCURRENCY not defined) or no multi-session.
437 //Use the "regular" (non-concurrency) default scan timing.
438 if(pScanRequest->scanType == eSIR_ACTIVE_SCAN)
439 {
440 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
441 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTime;
442 }
443 else
444 {
445 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
446 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
447 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530448 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
449 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700450
451#ifdef WLAN_AP_STA_CONCURRENCY
452 //No rest time if no sessions are connected.
453 pScanRequest->restTime = 0;
454#endif
455}
456
Jeff Johnson295189b2012-06-20 16:38:30 -0700457#ifdef WLAN_AP_STA_CONCURRENCY
458//Return SUCCESS is the command is queued, else returns eHAL_STATUS_FAILURE
459eHalStatus csrQueueScanRequest( tpAniSirGlobal pMac, tSmeCmd *pScanCmd )
460{
461 eHalStatus status = eHAL_STATUS_SUCCESS;
462
463 tANI_BOOLEAN fNoCmdPending;
464 tSmeCmd *pQueueScanCmd=NULL;
465 tSmeCmd *pSendScanCmd=NULL;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700466 tANI_U8 nNumChanCombinedConc = 0;
Gopichand Nakkala114718f2013-03-25 19:19:46 -0700467 if (NULL == pScanCmd)
468 {
469 smsLog (pMac, LOGE, FL("Scan Req cmd is NULL"));
470 return eHAL_STATUS_FAILURE;
471 }
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800472 /* split scan if any one of the following:
473 * - STA session is connected and the scan is not a P2P search
474 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -0800475 * Do not split scans if no concurrent infra connections are
476 * active and if the scan is a BG scan triggered by LFR (OR)
477 * any scan if LFR is in the middle of a BG scan. Splitting
478 * the scan is delaying the time it takes for LFR to find
479 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800480 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700481
482 if(csrIsStaSessionConnected(pMac) &&
483 !csrIsP2pSessionConnected(pMac))
484 {
485 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
486 }
487 else if(csrIsP2pSessionConnected(pMac))
488 {
489 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
490 }
Srikant Kuppa866893f2012-12-27 17:28:14 -0800491 if ( (csrIsStaSessionConnected(pMac) &&
492#ifdef FEATURE_WLAN_LFR
493 (csrIsConcurrentInfraConnected(pMac) ||
494 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
495 (pMac->roam.neighborRoamInfo.neighborRoamState !=
496 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
497#endif
498 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Vinay Malekal05fdc812012-12-17 13:04:30 -0800499 (csrIsP2pSessionConnected(pMac)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700500 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700501 tCsrScanRequest scanReq;
502 tANI_U8 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
503 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
504 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Jeff Johnson295189b2012-06-20 16:38:30 -0700505 tANI_BOOLEAN bMemAlloc = eANI_BOOLEAN_FALSE;
506
507 if (numChn == 0)
508 {
509
510 numChn = pMac->scan.baseChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700511
Kiet Lam64c1b492013-07-12 13:56:44 +0530512 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(numChn);
513 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700514 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800515 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800516 return eHAL_STATUS_FAILURE;
517 }
518 bMemAlloc = eANI_BOOLEAN_TRUE;
Kiet Lam64c1b492013-07-12 13:56:44 +0530519 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
520 pMac->scan.baseChannels.channelList, numChn);
521 status = eHAL_STATUS_SUCCESS;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800522 if( !HAL_STATUS_SUCCESS( status ) )
523 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530524 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800525 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800526 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800527 return eHAL_STATUS_FAILURE;
528 }
529 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn;
530 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700531
Vinay Malekal05fdc812012-12-17 13:04:30 -0800532 //Whenever we get a scan request with multiple channels we break it up into 2 requests
533 //First request for first channel to scan and second request to scan remaining channels
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700534 if ( numChn > nNumChanCombinedConc)
Vinay Malekal05fdc812012-12-17 13:04:30 -0800535 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530536 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800537
538 pQueueScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
539 if (!pQueueScanCmd)
540 {
541 if (bMemAlloc)
Jeff Johnson295189b2012-06-20 16:38:30 -0700542 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530543 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800544 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
545
Jeff Johnson295189b2012-06-20 16:38:30 -0700546 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800547 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800548 return eHAL_STATUS_FAILURE;
549 }
550 pQueueScanCmd->command = pScanCmd->command;
551 pQueueScanCmd->sessionId = pScanCmd->sessionId;
552 pQueueScanCmd->u.scanCmd.callback = pScanCmd->u.scanCmd.callback;
553 pQueueScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
554 pQueueScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
555 pQueueScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700556
Vinay Malekal05fdc812012-12-17 13:04:30 -0800557 /* First copy all the parameters to local variable of scan request */
558 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -0700559
Vinay Malekal05fdc812012-12-17 13:04:30 -0800560 /* Now modify the elements of local var scan request required to be modified for split scan */
561 if(scanReq.ChannelInfo.ChannelList != NULL)
562 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530563 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -0800564 scanReq.ChannelInfo.ChannelList = NULL;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800565 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700566
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700567 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700568
Vinay Malekal05fdc812012-12-17 13:04:30 -0800569 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +0530570 FL(" &channelToScan %p pScanCmd(%p) pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList(%p)numChn(%d)"),
571 &channelToScan[0], pScanCmd,
572 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700573
Kiet Lam64c1b492013-07-12 13:56:44 +0530574 vos_mem_copy(&channelToScan[0],
575 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[
576 nNumChanCombinedConc],
577 pChnInfo->numOfChannels * sizeof(tANI_U8));
Vinay Malekal05fdc812012-12-17 13:04:30 -0800578
579 pChnInfo->ChannelList = &channelToScan[0];
580
581 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
582 //Modify callers parameters in case of concurrency
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530583 if (!pScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
584 scanReq.scanType = eSIR_ACTIVE_SCAN;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800585 //Use concurrency values for min/maxChnTime.
586 //We know csrIsAnySessionConnected(pMac) returns TRUE here
587 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
588
589 status = csrScanCopyRequest(pMac, &pQueueScanCmd->u.scanCmd.u.scanRequest, &scanReq);
590
591 if(!HAL_STATUS_SUCCESS(status))
592 {
593 if (bMemAlloc)
594 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530595 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800596 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
597
598 }
599 if( scanReq.pIEField != NULL)
600 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530601 vos_mem_free(scanReq.pIEField);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800602 scanReq.pIEField = NULL;
603 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800604 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800605 return eHAL_STATUS_FAILURE;
606 }
607 /* Clean the local scan variable */
608 scanReq.ChannelInfo.ChannelList = NULL;
609 scanReq.ChannelInfo.numOfChannels = 0;
610 csrScanFreeRequest(pMac, &scanReq);
611
612 /* setup the command to scan 2 channels */
613 pSendScanCmd = pScanCmd;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700614 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nNumChanCombinedConc;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800615 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530616 if (!pSendScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
617 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800618 //Use concurrency values for min/maxChnTime.
619 //We know csrIsAnySessionConnected(pMac) returns TRUE here
620 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
621 pSendScanCmd->u.scanCmd.callback = NULL;
622 } else {
623 pSendScanCmd = pScanCmd;
624 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530625 if (!pSendScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
626 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800627 //Use concurrency values for min/maxChnTime.
628 //We know csrIsAnySessionConnected(pMac) returns TRUE here
629 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
630 }
631
632 fNoCmdPending = csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK );
633
634 //Logic Below is as follows
635 // If the scanCmdPendingList is empty then we directly send that command
636 // to smeCommandQueue else we buffer it in our scanCmdPendingList Queue
637 if( fNoCmdPending )
638 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700639 if (pQueueScanCmd != NULL)
640 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800641 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -0700642 }
643
644 if (pSendScanCmd != NULL)
645 {
646 return csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
647 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800648 }
649 else
650 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700651 if (pSendScanCmd != NULL)
652 {
653 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pSendScanCmd->Link, LL_ACCESS_LOCK );
654 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800655
Jeff Johnson295189b2012-06-20 16:38:30 -0700656 if (pQueueScanCmd != NULL)
657 {
658 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
659 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800660 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700661 }
662 else
663 { //No concurrency case
Srikant Kuppa866893f2012-12-27 17:28:14 -0800664 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800665 " numOfChannels=%d)"),
Srikant Kuppa866893f2012-12-27 17:28:14 -0800666 pScanCmd->u.scanCmd.reason,
667 pMac->roam.neighborRoamInfo.neighborRoamState,
668 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -0700669 return csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
670 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700671
672 return ( status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700673}
674#endif
675
Jeff Johnsone7245742012-09-05 17:12:55 -0700676/* ---------------------------------------------------------------------------
677 \fn csrScan2GOnyRequest
678 \brief This function will update the scan request with only
Jeff Johnsonb88db982012-12-10 13:34:59 -0800679 2.4GHz valid channel list.
Jeff Johnsone7245742012-09-05 17:12:55 -0700680 \param pMac
681 \param pScanCmd
682 \param pScanRequest
683 \return None
684 -------------------------------------------------------------------------------*/
685static void csrScan2GOnyRequest(tpAniSirGlobal pMac,tSmeCmd *pScanCmd,
686 tCsrScanRequest *pScanRequest)
687{
688 tANI_U8 index, channelId, channelListSize = 0;
689 tANI_U8 channelList2G[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
690 static tANI_U8 validchannelList[CSR_MAX_2_4_GHZ_SUPPORTED_CHANNELS] = {0};
691
692 VOS_ASSERT(pScanCmd && pScanRequest);
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700693 /* To silence the KW tool null check is added */
694 if((pScanCmd == NULL) || (pScanRequest == NULL))
695 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800696 smsLog( pMac, LOGE, FL(" pScanCmd or pScanRequest is NULL "));
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700697 return;
698 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700699
700 if (pScanCmd->u.scanCmd.scanID ||
701 (eCSR_SCAN_REQUEST_FULL_SCAN != pScanRequest->requestType))
702 return;
703
704 //Contsruct valid Supported 2.4 GHz Channel List
705 for( index = 0; index < ARRAY_SIZE(channelList2G); index++ )
706 {
707 channelId = channelList2G[index];
708 if ( csrIsSupportedChannel( pMac, channelId ) )
709 {
710 validchannelList[channelListSize++] = channelId;
711 }
712 }
713
714 pScanRequest->ChannelInfo.numOfChannels = channelListSize;
715 pScanRequest->ChannelInfo.ChannelList = validchannelList;
716}
717
Jeff Johnson295189b2012-06-20 16:38:30 -0700718eHalStatus csrScanRequest(tpAniSirGlobal pMac, tANI_U16 sessionId,
719 tCsrScanRequest *pScanRequest, tANI_U32 *pScanRequestID,
720 csrScanCompleteCallback callback, void *pContext)
721{
722 eHalStatus status = eHAL_STATUS_FAILURE;
723 tSmeCmd *pScanCmd = NULL;
Madan Mohan Koyyalamudicb90bb22012-10-30 18:24:43 -0700724 eCsrConnectState ConnectState;
Jeff Johnson295189b2012-06-20 16:38:30 -0700725
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800726 if(pScanRequest == NULL)
727 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800728 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800729 VOS_ASSERT(0);
730 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700731
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530732 /* During group formation, the P2P client scans for GO with the specific SSID.
733 * There will be chances of GO switching to other channels because of scan or
734 * to STA channel in case of STA+GO MCC scenario. So to increase the possibility
735 * of client to find the GO, the dwell time of scan is increased to 100ms.
736 */
737 if(pScanRequest->p2pSearch)
738 {
739 //If the scan request is for specific SSId the length of SSID will be
740 //greater than 7 as SSID for p2p search contains "DIRECT-")
741 if(pScanRequest->SSIDs.SSIDList->SSID.length > DIRECT_SSID_LEN)
742 {
743 smsLog( pMac, LOG1, FL(" Increase the Dwell time to 100ms."));
744 pScanRequest->maxChnTime = MAX_CHN_TIME_TO_FIND_GO;
745 pScanRequest->minChnTime = MIN_CHN_TIME_TO_FIND_GO;
746 }
747 }
748
Jeff Johnson295189b2012-06-20 16:38:30 -0700749 do
750 {
751 if(pMac->scan.fScanEnable)
752 {
753 pScanCmd = csrGetCommandBuffer(pMac);
754 if(pScanCmd)
755 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530756 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700757 pScanCmd->command = eSmeCommandScan;
758 pScanCmd->sessionId = sessionId;
759 pScanCmd->u.scanCmd.callback = callback;
760 pScanCmd->u.scanCmd.pContext = pContext;
761 if(eCSR_SCAN_REQUEST_11D_SCAN == pScanRequest->requestType)
762 {
763 pScanCmd->u.scanCmd.reason = eCsrScan11d1;
764 }
765 else if((eCSR_SCAN_REQUEST_FULL_SCAN == pScanRequest->requestType) ||
766 (eCSR_SCAN_P2P_DISCOVERY == pScanRequest->requestType)
767#ifdef SOFTAP_CHANNEL_RANGE
768 ||(eCSR_SCAN_SOFTAP_CHANNEL_RANGE == pScanRequest->requestType)
769#endif
770 )
771 {
772 pScanCmd->u.scanCmd.reason = eCsrScanUserRequest;
773 }
774 else if(eCSR_SCAN_HO_BG_SCAN == pScanRequest->requestType)
775 {
776 pScanCmd->u.scanCmd.reason = eCsrScanBgScan;
777 }
778 else if(eCSR_SCAN_HO_PROBE_SCAN == pScanRequest->requestType)
779 {
780 pScanCmd->u.scanCmd.reason = eCsrScanProbeBss;
781 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700782 else if(eCSR_SCAN_P2P_FIND_PEER == pScanRequest->requestType)
783 {
784 pScanCmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
785 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700786 else
787 {
788 pScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
789 }
790 if(pScanRequest->minChnTime == 0 && pScanRequest->maxChnTime == 0)
791 {
792 //The caller doesn't set the time correctly. Set it here
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700793 csrSetDefaultScanTiming(pMac, pScanRequest->scanType, pScanRequest);
794 }
795#ifdef WLAN_AP_STA_CONCURRENCY
796 if(pScanRequest->restTime == 0)
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800797 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700798 //Need to set restTime only if at least one session is connected
799 if(csrIsAnySessionConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700800 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700801 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700802 }
803 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700804#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -0700805 /*For Standalone wlan : channel time will remain the same.
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530806 For BTC with A2DP up: Channel time = Channel time * 2, if station is not already associated.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800807 This has been done to provide a larger scan window for faster connection during btc.Else Scan is seen
808 to take a long time.
809 For BTC with A2DP up: Channel time will not be doubled, if station is already associated.
810 */
Jeff Johnson32d95a32012-09-10 13:15:23 -0700811 status = csrRoamGetConnectState(pMac,sessionId,&ConnectState);
Srinivas Girigowdac84c57c2013-02-19 17:41:56 -0800812 if (HAL_STATUS_SUCCESS(status) &&
813 pMac->btc.fA2DPUp &&
Jeff Johnson32d95a32012-09-10 13:15:23 -0700814 (eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED != ConnectState) &&
815 (eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED != ConnectState))
816 {
817 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
818 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
819 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800820
Kiet Lam64c1b492013-07-12 13:56:44 +0530821 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
822 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700823 //Need to make the following atomic
824 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
825
826 if(pScanRequestID)
827 {
828 *pScanRequestID = pScanCmd->u.scanCmd.scanID;
829 }
830
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800831 // If it is the first scan request from HDD, CSR checks if it is for 11d.
Jeff Johnson295189b2012-06-20 16:38:30 -0700832 // If it is not, CSR will save the scan request in the pending cmd queue
833 // & issue an 11d scan request to PE.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800834 if (((0 == pScanCmd->u.scanCmd.scanID)
Jeff Johnson295189b2012-06-20 16:38:30 -0700835 && (eCSR_SCAN_REQUEST_11D_SCAN != pScanRequest->requestType))
836#ifdef SOFTAP_CHANNEL_RANGE
837 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != pScanRequest->requestType)
838#endif
839 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d)
840 )
841 {
842 tSmeCmd *p11dScanCmd;
843 tCsrScanRequest scanReq;
844 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
845
Kiet Lam64c1b492013-07-12 13:56:44 +0530846 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700847
848 p11dScanCmd = csrGetCommandBuffer(pMac);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800849 if (p11dScanCmd)
Jeff Johnson295189b2012-06-20 16:38:30 -0700850 {
851 tANI_U32 numChn = pMac->scan.baseChannels.numChannels;
852
Kiet Lam64c1b492013-07-12 13:56:44 +0530853 vos_mem_set(&p11dScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
854 pChnInfo->ChannelList = vos_mem_malloc(numChn);
855 if ( NULL == pChnInfo->ChannelList )
856 return eHAL_STATUS_FAILURE;
857 vos_mem_copy(pChnInfo->ChannelList,
858 pMac->scan.baseChannels.channelList, numChn);
859 status = eHAL_STATUS_SUCCESS;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800860 if ( !HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700861 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530862 vos_mem_free(pChnInfo->ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -0700863 pChnInfo->ChannelList = NULL;
864 break;
865 }
866 pChnInfo->numOfChannels = (tANI_U8)numChn;
867 p11dScanCmd->command = eSmeCommandScan;
868 p11dScanCmd->u.scanCmd.callback = NULL;
869 p11dScanCmd->u.scanCmd.pContext = NULL;
870 p11dScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++;
871 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
872
873 if ( csrIs11dSupported(pMac) )
874 {
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530875 scanReq.bcnRptReqScan = pScanRequest->bcnRptReqScan;
876 if (pScanRequest->bcnRptReqScan)
877 scanReq.scanType = pScanRequest->scanType ?
878 eSIR_PASSIVE_SCAN :
879 pScanRequest->scanType;
880 else
881 scanReq.scanType = eSIR_PASSIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700882 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
883 p11dScanCmd->u.scanCmd.reason = eCsrScan11d1;
884 scanReq.maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
885 scanReq.minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
886 }
887 else
888 {
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530889 scanReq.bcnRptReqScan = pScanRequest->bcnRptReqScan;
890 if (pScanRequest->bcnRptReqScan)
891 scanReq.scanType = pScanRequest->scanType;
892 else
893 scanReq.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700894 scanReq.requestType = eCSR_SCAN_IDLE_MODE_SCAN;
895 p11dScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
896 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
897 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800898
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530899 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
900 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700901 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700902
Jeff Johnson295189b2012-06-20 16:38:30 -0700903 status = csrScanCopyRequest(pMac, &p11dScanCmd->u.scanCmd.u.scanRequest, &scanReq);
904 //Free the channel list
Kiet Lam64c1b492013-07-12 13:56:44 +0530905 vos_mem_free(pChnInfo->ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -0700906 pChnInfo->ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700907
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800908 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700909 {
910 //Start process the command
911#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530912 if (!pMac->fScanOffload)
913 status = csrQueueScanRequest(pMac, p11dScanCmd);
914 else
915 status = csrQueueSmeCommand(pMac, p11dScanCmd,
916 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700917#else
918 status = csrQueueSmeCommand(pMac, p11dScanCmd, eANI_BOOLEAN_FALSE);
919#endif
920 if( !HAL_STATUS_SUCCESS( status ) )
921 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800922 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700923 break;
924 }
925 }
926 else
927 {
928 break;
929 }
930 }
931 else
932 {
933 //error
934 break;
935 }
936 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700937
938 //Scan only 2G Channels if set in ini file
939 //This is mainly to reduce the First Scan duration
940 //Once we turn on Wifi
941 if(pMac->scan.fFirstScanOnly2GChnl)
942 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800943 smsLog( pMac, LOG1, FL("Scanning only 2G Channels during first scan"));
Jeff Johnsone7245742012-09-05 17:12:55 -0700944 csrScan2GOnyRequest(pMac, pScanCmd, pScanRequest);
945 }
946
Jeff Johnson295189b2012-06-20 16:38:30 -0700947 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
948 if(HAL_STATUS_SUCCESS(status))
949 {
950 //Start process the command
951#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530952 if (!pMac->fScanOffload)
953 status = csrQueueScanRequest(pMac,pScanCmd);
954 else
955 status = csrQueueSmeCommand(pMac, pScanCmd,
956 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700957#else
958 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
959#endif
960 if( !HAL_STATUS_SUCCESS( status ) )
961 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800962 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700963 break;
964 }
965 }
966 else
967 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800968 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700969 break;
970 }
971 }
972 else
973 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800974 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700975 break;
976 }
977 }
978 } while(0);
979 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
980 {
981 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
982 {
983 //Set the flag back for restarting idle scan
984 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
985 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800986 smsLog( pMac, LOGE, FL(" failed with status = %d, releasing scan cmd"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700987 csrReleaseCommandScan(pMac, pScanCmd);
988 }
989
990 return (status);
991}
992
993
994eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
995{
996 eHalStatus status = eHAL_STATUS_SUCCESS;
997 tSmeCmd *pScanCmd;
998
999 if(pMac->scan.fScanEnable)
1000 {
1001 pScanCmd = csrGetCommandBuffer(pMac);
1002 if(pScanCmd)
1003 {
1004 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +05301005 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001006 pScanCmd->u.scanCmd.callback = NULL;
1007 pScanCmd->u.scanCmd.pContext = NULL;
1008 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
1009 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07001010 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -07001011 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1012 if( !HAL_STATUS_SUCCESS( status ) )
1013 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001014 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001015 csrReleaseCommandScan(pMac, pScanCmd);
1016 }
1017 }
1018 else
1019 {
1020 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001021 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001022 status = eHAL_STATUS_RESOURCES;
1023 }
1024 }
1025
1026 return (status);
1027}
1028
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001029#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1030eHalStatus csrScanRequestLfrResult(tpAniSirGlobal pMac, tANI_U32 sessionId,
1031 csrScanCompleteCallback callback, void *pContext)
1032{
1033 eHalStatus status = eHAL_STATUS_SUCCESS;
1034 tSmeCmd *pScanCmd;
1035
1036 if (pMac->scan.fScanEnable)
1037 {
1038 pScanCmd = csrGetCommandBuffer(pMac);
1039 if (pScanCmd)
1040 {
1041 pScanCmd->command = eSmeCommandScan;
1042 pScanCmd->sessionId = sessionId;
Kiet Lam64c1b492013-07-12 13:56:44 +05301043 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001044 pScanCmd->u.scanCmd.callback = callback;
1045 pScanCmd->u.scanCmd.pContext = pContext;
1046 pScanCmd->u.scanCmd.reason = eCsrScanGetLfrResult;
1047 //Need to make the following atomic
1048 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
1049 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_TRUE);
1050 if ( !HAL_STATUS_SUCCESS( status ) )
1051 {
1052 smsLog( pMac, LOGE, FL(" fail to send message status = %d\n"), status );
1053 csrReleaseCommandScan(pMac, pScanCmd);
1054 }
1055 }
1056 else
1057 {
1058 //log error
1059 smsLog(pMac, LOGE, FL("can not obtain a common buffer\n"));
1060 status = eHAL_STATUS_RESOURCES;
1061 }
1062 }
1063
1064 return (status);
1065}
1066#endif //WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Jeff Johnson295189b2012-06-20 16:38:30 -07001067
1068eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
1069{
1070 eHalStatus status = eHAL_STATUS_SUCCESS;
1071 tANI_U32 scanId;
1072 tCsrScanRequest scanReq;
1073
Kiet Lam64c1b492013-07-12 13:56:44 +05301074 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001075 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
1076 scanReq.scanType = eSIR_ACTIVE_SCAN;
1077 scanReq.requestType = reqType;
1078 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1079 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001080 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1081 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001082 //Scan with invalid sessionId.
1083 //This results in SME using the first available session to scan.
1084 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
1085 &scanId, NULL, NULL);
1086
1087 return (status);
1088}
1089
1090
1091
1092
1093eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
1094{
1095 eHalStatus status = eHAL_STATUS_FAILURE;
1096 tScanResultHandle hBSSList = NULL;
1097 tCsrScanResultFilter *pScanFilter = NULL;
1098 tANI_U32 roamId = 0;
1099 tCsrRoamProfile *pProfile = NULL;
1100 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1101
Jeff Johnson32d95a32012-09-10 13:15:23 -07001102 if(!pSession)
1103 {
1104 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1105 return eHAL_STATUS_FAILURE;
1106 }
1107
Jeff Johnson295189b2012-06-20 16:38:30 -07001108 do
1109 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001110 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -07001111 if(pSession->fCancelRoaming)
1112 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001113 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -07001114 csrScanStartIdleScan(pMac);
1115 status = eHAL_STATUS_SUCCESS;
1116 break;
1117 }
1118 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301119 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1120 if ( NULL == pScanFilter)
1121 status = eHAL_STATUS_FAILURE;
1122 else
1123 status = eHAL_STATUS_SUCCESS;
1124 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001125 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301126 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001127 if(NULL == pSession->pCurRoamProfile)
1128 {
1129 pScanFilter->EncryptionType.numEntries = 1;
1130 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1131 }
1132 else
1133 {
1134 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301135 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1136 if ( NULL == pProfile )
1137 status = eHAL_STATUS_FAILURE;
1138 else
1139 status = eHAL_STATUS_SUCCESS;
1140 if (!HAL_STATUS_SUCCESS(status))
1141 break;
1142 vos_mem_set(pProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001143 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1144 if(!HAL_STATUS_SUCCESS(status))
1145 break;
1146 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1147 }//We have a profile
1148 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1149 if(HAL_STATUS_SUCCESS(status))
1150 {
1151 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1152 if(HAL_STATUS_SUCCESS(status))
1153 {
1154 if(eCsrLostLink1 == reason)
1155 {
1156 //we want to put the last connected BSS to the very beginning, if possible
1157 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1158 }
1159 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1160 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1161 if(!HAL_STATUS_SUCCESS(status))
1162 {
1163 csrScanResultPurge(pMac, hBSSList);
1164 }
1165 }//Have scan result
1166 }
1167 }while(0);
1168 if(pScanFilter)
1169 {
1170 //we need to free memory for filter if profile exists
1171 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301172 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001173 }
1174 if(NULL != pProfile)
1175 {
1176 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301177 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001178 }
1179
1180 return (status);
1181}
1182
1183
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05301184eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, tANI_U8 sessionId,
1185 void *pContext, void *callback)
Jeff Johnson295189b2012-06-20 16:38:30 -07001186{
1187 eHalStatus status = eHAL_STATUS_SUCCESS;
1188 tSmeCmd *pScanCmd;
1189
1190 if(pMac->scan.fScanEnable)
1191 {
1192 pScanCmd = csrGetCommandBuffer(pMac);
1193 if(pScanCmd)
1194 {
1195 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +05301196 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson32d95a32012-09-10 13:15:23 -07001197 pScanCmd->u.scanCmd.callback = callback;
1198 pScanCmd->u.scanCmd.pContext = pContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07001199 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1200 //Need to make the following atomic
1201 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05301202 pScanCmd->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07001203 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1204 if( !HAL_STATUS_SUCCESS( status ) )
1205 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001206 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001207 csrReleaseCommandScan(pMac, pScanCmd);
1208 }
1209 }
1210 else
1211 {
1212 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001213 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001214 status = eHAL_STATUS_RESOURCES;
1215 }
1216 }
1217
1218 return (status);
1219}
1220
1221
1222eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1223{
1224 eHalStatus status = eHAL_STATUS_FAILURE;
1225 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1226
Jeff Johnson32d95a32012-09-10 13:15:23 -07001227 if(!pSession)
1228 {
1229 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1230 return eHAL_STATUS_FAILURE;
1231 }
1232
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001233 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001234 if(pSession->fCancelRoaming)
1235 {
1236 csrScanStartIdleScan(pMac);
1237 }
1238 else if(pSession->pCurRoamProfile)
1239 {
1240 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1241 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1242 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1243 {
1244 //try lostlink scan2
1245 status = csrScanRequestLostLink2(pMac, sessionId);
1246 }
1247 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1248 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1249 {
1250 //go straight to lostlink scan3
1251 status = csrScanRequestLostLink3(pMac, sessionId);
1252 }
1253 else
1254 {
1255 //we are done with lostlink
1256 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1257 {
1258 csrScanStartIdleScan(pMac);
1259 }
1260 status = eHAL_STATUS_SUCCESS;
1261 }
1262 }
1263 else
1264 {
1265 status = csrScanRequestLostLink3(pMac, sessionId);
1266 }
1267
1268 return (status);
1269}
1270
1271
1272
1273eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1274{
1275 eHalStatus status = eHAL_STATUS_FAILURE;
1276 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1277
Jeff Johnson32d95a32012-09-10 13:15:23 -07001278 if(!pSession)
1279 {
1280 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1281 return eHAL_STATUS_FAILURE;
1282 }
1283
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001284 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001285 if(pSession->fCancelRoaming)
1286 {
1287 csrScanStartIdleScan(pMac);
1288 }
1289 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1290 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1291 {
1292 //try lostlink scan3
1293 status = csrScanRequestLostLink3(pMac, sessionId);
1294 }
1295 else
1296 {
1297 //we are done with lostlink
1298 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1299 {
1300 csrScanStartIdleScan(pMac);
1301 }
1302 }
1303
1304 return (status);
1305}
1306
1307
1308
1309eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1310{
1311 eHalStatus status = eHAL_STATUS_SUCCESS;
1312
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001313 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001314 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1315 {
1316 //we are done with lostlink
1317 csrScanStartIdleScan(pMac);
1318 }
1319
1320 return (status);
1321}
1322
1323
1324
1325
1326//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1327//If no roam profile (it should not), it is like lostlinkscan3
1328eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1329{
1330 eHalStatus status = eHAL_STATUS_SUCCESS;
1331 tSmeCmd *pCommand = NULL;
1332 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1333 tCsrScanResultFilter *pScanFilter = NULL;
1334 tScanResultHandle hBSSList = NULL;
1335 tCsrScanResultInfo *pScanResult = NULL;
1336 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1337
Jeff Johnson32d95a32012-09-10 13:15:23 -07001338 if(!pSession)
1339 {
1340 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1341 return eHAL_STATUS_FAILURE;
1342 }
1343
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001344 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001345 do
1346 {
1347 pCommand = csrGetCommandBuffer(pMac);
1348 if(!pCommand)
1349 {
1350 status = eHAL_STATUS_RESOURCES;
1351 break;
1352 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301353 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001354 pCommand->command = eSmeCommandScan;
1355 pCommand->sessionId = (tANI_U8)sessionId;
1356 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1357 pCommand->u.scanCmd.callback = NULL;
1358 pCommand->u.scanCmd.pContext = NULL;
1359 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1360 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001361 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1362 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001363 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1364 if(pSession->connectedProfile.SSID.length)
1365 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301366 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(sizeof(tCsrSSIDInfo));
1367 if ( NULL == pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
1368 status = eHAL_STATUS_FAILURE;
1369 else
1370 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001371 if(!HAL_STATUS_SUCCESS(status))
1372 {
1373 break;
1374 }
1375 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05301376 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1377 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001378 }
1379 else
1380 {
1381 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1382 }
1383 if(pSession->pCurRoamProfile)
1384 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301385 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1386 if ( NULL == pScanFilter )
1387 status = eHAL_STATUS_FAILURE;
1388 else
1389 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001390 if(!HAL_STATUS_SUCCESS(status))
1391 {
1392 break;
1393 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301394 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001395 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1396 if(!HAL_STATUS_SUCCESS(status))
1397 {
1398 break;
1399 }
1400 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1401 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1402 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1403 {
1404 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301405 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1406 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1407 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1408 status = eHAL_STATUS_FAILURE;
1409 else
1410 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001411 if(!HAL_STATUS_SUCCESS(status))
1412 {
1413 break;
1414 }
1415 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1416 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1417 {
1418 for(i = 0; i < nChn; i++)
1419 {
1420 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1421 pScanResult->BssDescriptor.channelId)
1422 {
1423 break;
1424 }
1425 }
1426 if(i == nChn)
1427 {
1428 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1429 }
1430 }
1431 //Include the last connected BSS' channel
1432 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1433 {
1434 for(i = 0; i < nChn; i++)
1435 {
1436 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1437 pSession->connectedProfile.operationChannel)
1438 {
1439 break;
1440 }
1441 }
1442 if(i == nChn)
1443 {
1444 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1445 }
1446 }
1447 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1448 }
1449 else
1450 {
1451 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1452 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301453 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(1);
1454 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1455 status = eHAL_STATUS_FAILURE;
1456 else
1457 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001458 //just try the last connected channel
1459 if(HAL_STATUS_SUCCESS(status))
1460 {
1461 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1462 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1463 }
1464 else
1465 {
1466 break;
1467 }
1468 }
1469 }
1470 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301471 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001472 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1473 if( !HAL_STATUS_SUCCESS( status ) )
1474 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001475 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001476 break;
1477 }
1478 } while( 0 );
1479
1480 if(!HAL_STATUS_SUCCESS(status))
1481 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001482 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001483 if(pCommand)
1484 {
1485 csrReleaseCommandScan(pMac, pCommand);
1486 }
1487 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1488 }
1489 if(pScanFilter)
1490 {
1491 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301492 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001493 }
1494 if(hBSSList)
1495 {
1496 csrScanResultPurge(pMac, hBSSList);
1497 }
1498
1499 return( status );
1500}
1501
1502
1503//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1504//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1505eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1506{
1507 eHalStatus status = eHAL_STATUS_SUCCESS;
1508 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1509 tCsrScanResultFilter *pScanFilter = NULL;
1510 tScanResultHandle hBSSList = NULL;
1511 tCsrScanResultInfo *pScanResult = NULL;
1512 tSmeCmd *pCommand = NULL;
1513 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1514
Jeff Johnson32d95a32012-09-10 13:15:23 -07001515 if(!pSession)
1516 {
1517 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1518 return eHAL_STATUS_FAILURE;
1519 }
1520
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001521 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001522 do
1523 {
1524 pCommand = csrGetCommandBuffer(pMac);
1525 if(!pCommand)
1526 {
1527 status = eHAL_STATUS_RESOURCES;
1528 break;
1529 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301530 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001531 pCommand->command = eSmeCommandScan;
1532 pCommand->sessionId = (tANI_U8)sessionId;
1533 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1534 pCommand->u.scanCmd.callback = NULL;
1535 pCommand->u.scanCmd.pContext = NULL;
1536 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1537 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001538 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1539 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001540 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1541 if(pSession->pCurRoamProfile)
1542 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301543 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1544 if ( NULL == pScanFilter )
1545 status = eHAL_STATUS_FAILURE;
1546 else
1547 status = eHAL_STATUS_SUCCESS;
1548 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001549 {
1550 break;
1551 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301552 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001553 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1554 if(!HAL_STATUS_SUCCESS(status))
1555 {
1556 break;
1557 }
1558 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1559 if(!HAL_STATUS_SUCCESS(status))
1560 {
1561 break;
1562 }
1563 if(hBSSList)
1564 {
1565 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301566 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1567 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1568 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1569 status = eHAL_STATUS_FAILURE;
1570 else
1571 status = eHAL_STATUS_SUCCESS;
1572 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001573 {
1574 break;
1575 }
1576 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1577 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1578 {
1579 for(i = 0; i < nChn; i++)
1580 {
1581 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1582 pScanResult->BssDescriptor.channelId)
1583 {
1584 break;
1585 }
1586 }
1587 if(i == nChn)
1588 {
1589 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1590 }
1591 }
1592 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1593 }
1594 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301595 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001596 //Put to the head in pending queue
1597 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1598 if( !HAL_STATUS_SUCCESS( status ) )
1599 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001600 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001601 break;
1602 }
1603 } while( 0 );
1604
1605 if(!HAL_STATUS_SUCCESS(status))
1606 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001607 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001608 if(pCommand)
1609 {
1610 csrReleaseCommandScan(pMac, pCommand);
1611 }
1612 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1613 }
1614 if(pScanFilter)
1615 {
1616 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301617 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001618 }
1619 if(hBSSList)
1620 {
1621 csrScanResultPurge(pMac, hBSSList);
1622 }
1623
1624 return( status );
1625}
1626
1627
1628//To actively scan all valid channels
1629eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1630{
1631 eHalStatus status = eHAL_STATUS_SUCCESS;
1632 tSmeCmd *pCommand;
1633 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1634
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001635 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001636 do
1637 {
1638 pCommand = csrGetCommandBuffer(pMac);
1639 if(!pCommand)
1640 {
1641 status = eHAL_STATUS_RESOURCES;
1642 break;
1643 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301644 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001645 pCommand->command = eSmeCommandScan;
1646 pCommand->sessionId = (tANI_U8)sessionId;
1647 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1648 pCommand->u.scanCmd.callback = NULL;
1649 pCommand->u.scanCmd.pContext = NULL;
1650 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1651 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001652 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1653 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001654 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Kiet Lam64c1b492013-07-12 13:56:44 +05301655 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001656 //Put to the head of pending queue
1657 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1658 if( !HAL_STATUS_SUCCESS( status ) )
1659 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001660 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001661 break;
1662 }
1663 } while( 0 );
1664 if(!HAL_STATUS_SUCCESS(status))
1665 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001666 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001667 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1668 {
1669 csrScanStartIdleScan(pMac);
1670 }
1671 if(pCommand)
1672 {
1673 csrReleaseCommandScan(pMac, pCommand);
1674 }
1675 }
1676
1677 return( status );
1678}
1679
1680
1681eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1682{
1683 eHalStatus status = eHAL_STATUS_FAILURE;
1684 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1685 tCsrScanResultFilter *pScanFilter = NULL;
1686 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1687 tANI_U32 sessionId = pCommand->sessionId;
1688#ifdef FEATURE_WLAN_BTAMP_UT_RF
1689 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1690#endif
1691 do
1692 {
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001693#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1694 //if this scan is for LFR
1695 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1696 {
1697 //notify LFR state m/c
1698 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_SUCCESS))
1699 {
Varun Reddy Yeturue3af4282013-06-07 00:56:52 -07001700 csrNeighborRoamStartLfrScan(pMac);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001701 }
1702 status = eHAL_STATUS_SUCCESS;
1703 break;
1704 }
1705#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001706 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1707 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1708 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001709 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001710 break;
1711 }
1712 if(pProfile == NULL)
1713 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301714 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1715 if ( NULL == pScanFilter )
1716 status = eHAL_STATUS_FAILURE;
1717 else
1718 status = eHAL_STATUS_SUCCESS;
1719 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001720 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301721 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001722 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1723 if(!HAL_STATUS_SUCCESS(status))
1724 break;
1725 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1726 if(!HAL_STATUS_SUCCESS(status))
1727 break;
1728 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1729 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1730 if(!HAL_STATUS_SUCCESS(status))
1731 {
1732 break;
1733 }
1734 }while(0);
1735 if(!HAL_STATUS_SUCCESS(status))
1736 {
1737 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1738 {
1739 csrScanResultPurge(pMac, hBSSList);
1740 }
1741 //We haven't done anything to this profile
1742 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId,
1743 eCSR_ROAM_ASSOCIATION_FAILURE, eCSR_ROAM_RESULT_FAILURE);
1744 //In case we have nothing else to do, restart idle scan
1745 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1746 {
1747 status = csrScanStartIdleScan(pMac);
1748 }
1749#ifdef FEATURE_WLAN_BTAMP_UT_RF
1750 //In case of WDS station, let it retry.
1751 if( CSR_IS_WDS_STA(pProfile) )
1752 {
1753 //Save the roma profile so we can retry
1754 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301755 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1756 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001757 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301758 vos_mem_set(pSession->pCurRoamProfilee, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001759 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1760 }
1761 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1762 }
1763#endif
1764 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301765 if (pScanFilter)
Jeff Johnson295189b2012-06-20 16:38:30 -07001766 {
1767 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301768 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001769 }
1770
1771 return (status);
1772}
1773
1774
1775eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1776{
1777 eHalStatus status = eHAL_STATUS_SUCCESS;
1778 tANI_U32 sessionId = pCommand->sessionId;
1779 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1780 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001781#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1782 //if this scan is for LFR
1783 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1784 {
1785 //notify LFR state m/c
1786 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_FAILURE))
1787 {
Varun Reddy Yeturue3af4282013-06-07 00:56:52 -07001788 csrNeighborRoamStartLfrScan(pMac);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001789 }
1790 return eHAL_STATUS_SUCCESS;
1791 }
1792#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07001793 if(!pSession)
1794 {
1795 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1796 return eHAL_STATUS_FAILURE;
1797 }
1798
Jeff Johnson295189b2012-06-20 16:38:30 -07001799#if defined(WLAN_DEBUG)
1800 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1801 {
1802 char str[36];
Kiet Lam64c1b492013-07-12 13:56:44 +05301803 vos_mem_copy(str,
1804 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1805 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07001806 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001807 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001808 }
1809#endif
1810 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1811 if(pProfile && CSR_IS_START_IBSS(pProfile))
1812 {
1813 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1814 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1815 if(!HAL_STATUS_SUCCESS(status))
1816 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001817 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001818 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1819 }
1820 }
1821 else
1822 {
1823 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1824
1825 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1826 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1827 {
1828 status = csrScanStartIdleScan(pMac);
1829 }
1830 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1831 {
1832 //Only indicate assoc_completion if we indicate assoc_start.
1833 if(pSession->bRefAssocStartCnt > 0)
1834 {
1835 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
Kiet Lam64c1b492013-07-12 13:56:44 +05301836 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001837 pRoamInfo = &roamInfo;
1838 if(pCommand->u.roamCmd.pRoamBssEntry)
1839 {
1840 tCsrScanResult *pScanResult =
1841 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1842 tCsrScanResult, Link);
1843 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1844 }
1845 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1846 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1847 pSession->bRefAssocStartCnt--;
1848 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1849 pCommand->u.scanCmd.roamId,
1850 eCSR_ROAM_ASSOCIATION_COMPLETION,
1851 eCSR_ROAM_RESULT_FAILURE);
1852 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001853 else
1854 {
1855 csrRoamCallCallback(pMac, sessionId, NULL,
1856 pCommand->u.scanCmd.roamId,
1857 eCSR_ROAM_ASSOCIATION_FAILURE,
1858 eCSR_ROAM_RESULT_FAILURE);
1859 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001860#ifdef FEATURE_WLAN_BTAMP_UT_RF
1861 //In case of WDS station, let it retry.
1862 if( CSR_IS_WDS_STA(pProfile) )
1863 {
1864 //Save the roma profile so we can retry
1865 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301866 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1867 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001868 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301869 vos_mem_set(pSession->pCurRoamProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001870 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1871 }
1872 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1873 }
1874#endif
1875 }
1876 else
1877 {
1878 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1879 }
1880 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1881 }
1882
1883 return (status);
1884}
1885
1886
1887//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1888eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1889{
1890 eHalStatus status = eHAL_STATUS_FAILURE;
1891 tScanResultHandle hBSSList = NULL;
1892 tCsrScanResultFilter *pScanFilter = NULL;
1893 tANI_U32 roamId = 0;
1894 tCsrRoamProfile *pProfile = NULL;
1895 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1896
1897 do
1898 {
1899 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301900 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1901 if ( NULL == pScanFilter )
1902 status = eHAL_STATUS_FAILURE;
1903 else
1904 status = eHAL_STATUS_SUCCESS;
1905 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001906 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301907 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
1908 if (NULL == pSession) break;
1909 if (NULL == pSession->pCurRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07001910 {
1911 pScanFilter->EncryptionType.numEntries = 1;
1912 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1913 }
1914 else
1915 {
1916 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301917 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1918 if ( NULL == pProfile )
1919 status = eHAL_STATUS_FAILURE;
1920 else
1921 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001922 if(!HAL_STATUS_SUCCESS(status))
1923 break;
1924 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1925 if(!HAL_STATUS_SUCCESS(status))
1926 break;
1927 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1928 }//We have a profile
1929 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1930 if(HAL_STATUS_SUCCESS(status))
1931 {
1932 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1933 if(HAL_STATUS_SUCCESS(status))
1934 {
1935 //we want to put the last connected BSS to the very beginning, if possible
1936 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1937 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1938 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1939 if(!HAL_STATUS_SUCCESS(status))
1940 {
1941 csrScanResultPurge(pMac, hBSSList);
1942 }
1943 }//Have scan result
1944 else
1945 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001946 smsLog(pMac, LOGW, FL("cannot find matching BSS of %02X-%02X-%02X-%02X-%02X-%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001947 pSession->connectedProfile.bssid[0],
1948 pSession->connectedProfile.bssid[1],
1949 pSession->connectedProfile.bssid[2],
1950 pSession->connectedProfile.bssid[3],
1951 pSession->connectedProfile.bssid[4],
1952 pSession->connectedProfile.bssid[5]);
1953 //Disconnect
1954 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1955 }
1956 }
1957 }while(0);
1958 if(pScanFilter)
1959 {
1960 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301961 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001962 }
1963 if(NULL != pProfile)
1964 {
1965 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301966 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001967 }
1968
1969 return (status);
1970}
1971
1972
1973
1974eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
1975{
1976 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
1977 tScanResultList *pScanList = (tScanResultList *)hScanList;
1978
1979 if(pScanList)
1980 {
1981 status = csrLLScanPurgeResult(pMac, &pScanList->List);
1982 csrLLClose(&pScanList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05301983 vos_mem_free(pScanList);
Jeff Johnson295189b2012-06-20 16:38:30 -07001984 }
1985 return (status);
1986}
1987
1988
1989static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
1990{
1991 tANI_U32 ret = 0;
1992 int i = CSR_NUM_RSSI_CAT - 1;
1993
1994 while(i >= 0)
1995 {
1996 if(rssi >= pMac->roam.configParam.RSSICat[i])
1997 {
1998 ret = pMac->roam.configParam.BssPreferValue[i];
1999 break;
2000 }
2001 i--;
2002 };
2003
2004 return (ret);
2005}
2006
2007
2008//Return a CapValue base on the capabilities of a BSS
2009static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
2010{
2011 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08002012#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
2013 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
2014 {
2015 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
2016 {
2017 ret += CSR_BSS_CAP_VALUE_5GHZ;
2018 }
2019 }
2020#endif
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002021 /* if strict select 5GHz is non-zero then ignore the capability checking */
2022 if (pIes && !CSR_IS_SELECT_5GHZ_MARGIN(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07002023 {
2024 //We only care about 11N capability
2025 if(pIes->HTCaps.present)
2026 {
2027 ret += CSR_BSS_CAP_VALUE_HT;
2028 }
2029 if(CSR_IS_QOS_BSS(pIes))
2030 {
2031 ret += CSR_BSS_CAP_VALUE_WMM;
2032 //Give advantage to UAPSD
2033 if(CSR_IS_UAPSD_BSS(pIes))
2034 {
2035 ret += CSR_BSS_CAP_VALUE_UAPSD;
2036 }
2037 }
2038 }
2039
2040 return (ret);
2041}
2042
2043
2044//To check whther pBss1 is better than pBss2
2045static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
2046{
2047 tANI_BOOLEAN ret;
2048
2049 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2050 {
2051 ret = eANI_BOOLEAN_TRUE;
2052 }
2053 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2054 {
2055 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
2056 {
2057 ret = eANI_BOOLEAN_TRUE;
2058 }
2059 else
2060 {
2061 ret = eANI_BOOLEAN_FALSE;
2062 }
2063 }
2064 else
2065 {
2066 ret = eANI_BOOLEAN_FALSE;
2067 }
2068
2069 return (ret);
2070}
2071
2072
Srikant Kuppa866893f2012-12-27 17:28:14 -08002073#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002074//Add the channel to the occupiedChannels array
2075static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08002076 tpAniSirGlobal pMac,
2077 tCsrScanResult *pResult,
2078 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002079 tDot11fBeaconIEs *pIes)
2080{
2081 eHalStatus status;
2082 tANI_U8 channel;
2083 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2084 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2085
2086 channel = pResult->Result.BssDescriptor.channelId;
2087
2088 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002089 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002090 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08002091 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002092 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08002093 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002094 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002095 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002096 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08002097 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2098 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2099 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002100 }
2101}
2102#endif
2103
Jeff Johnson295189b2012-06-20 16:38:30 -07002104//Put the BSS into the scan result list
2105//pIes can not be NULL
2106static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
2107{
Srinivas28b5b4e2012-12-12 13:07:53 -08002108#ifdef FEATURE_WLAN_LFR
2109 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
2110#endif
2111
Jeff Johnson295189b2012-06-20 16:38:30 -07002112 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
2113 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
2114 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08002115#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08002116 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
2117 {
2118 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
2119 NOT set in the cfg.ini file */
2120 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
2121 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002122#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002123}
2124
2125
2126eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2127{
2128 eHalStatus status;
2129 tScanResultList *pRetList;
2130 tCsrScanResult *pResult, *pBssDesc;
2131 tANI_U32 count = 0;
2132 tListElem *pEntry;
2133 tANI_U32 bssLen, allocLen;
2134 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2135 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2136 tDot11fBeaconIEs *pIes, *pNewIes;
2137 tANI_BOOLEAN fMatch;
2138
2139 if(phResult)
2140 {
2141 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2142 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002143
2144 if (pMac->roam.configParam.nSelect5GHzMargin)
2145 {
2146 pMac->scan.inScanResultBestAPRssi = -128;
2147 csrLLLock(&pMac->scan.scanResultList);
2148
2149 /* Find out the best AP Rssi going thru the scan results */
2150 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2151 while ( NULL != pEntry)
2152 {
2153 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2154 if (pBssDesc->Result.BssDescriptor.rssi > pMac->scan.inScanResultBestAPRssi)
2155 {
2156 pMac->scan.inScanResultBestAPRssi = pBssDesc->Result.BssDescriptor.rssi;
2157 }
2158 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2159 }
2160
2161 /* Modify Rssi category based on best AP Rssi */
2162 csrAssignRssiForCategory(pMac, pMac->scan.inScanResultBestAPRssi, pMac->roam.configParam.bCatRssiOffset);
2163 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2164 while ( NULL != pEntry)
2165 {
2166 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2167
2168 /* re-assign preference value based on modified rssi bucket */
2169 pBssDesc->preferValue = csrGetBssPreferValue(pMac, (int)pBssDesc->Result.BssDescriptor.rssi);
2170
2171 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2172 }
2173
2174 csrLLUnlock(&pMac->scan.scanResultList);
2175 }
2176
Kiet Lam64c1b492013-07-12 13:56:44 +05302177 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2178 if ( NULL == pRetList )
2179 status = eHAL_STATUS_FAILURE;
2180 else
2181 status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002182 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002183 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302184 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002185 csrLLOpen(pMac->hHdd, &pRetList->List);
2186 pRetList->pCurEntry = NULL;
2187
2188 csrLLLock(&pMac->scan.scanResultList);
2189 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2190 while( pEntry )
2191 {
2192 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2193 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2194 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2195 //for any error condition, otherwiase, it will be freed later.
2196 //reset
2197 fMatch = eANI_BOOLEAN_FALSE;
2198 pNewIes = NULL;
2199
2200 if(pFilter)
2201 {
2202 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2203 if( NULL != pIes )
2204 {
2205 //Only save it when matching
2206 if(fMatch)
2207 {
2208 if( !pBssDesc->Result.pvIes )
2209 {
2210 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2211 pNewIes = pIes;
2212 }
2213 else
2214 {
2215 //The pIes is allocated by someone else. make a copy
2216 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2217 //is using to for association, hence save the parsed IEs
Kiet Lam64c1b492013-07-12 13:56:44 +05302218 pNewIes = vos_mem_malloc(sizeof(tDot11fBeaconIEs));
2219 if ( NULL == pNewIes )
2220 status = eHAL_STATUS_FAILURE;
2221 else
2222 status = eHAL_STATUS_SUCCESS;
2223 if ( HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002224 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302225 vos_mem_copy(pNewIes, pIes, sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002226 }
2227 else
2228 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002229 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002230 //Need to free memory allocated by csrMatchBSS
2231 if( !pBssDesc->Result.pvIes )
2232 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302233 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002234 }
2235 break;
2236 }
2237 }
2238 }//fMatch
2239 else if( !pBssDesc->Result.pvIes )
2240 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302241 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002242 }
2243 }
2244 }
2245 if(NULL == pFilter || fMatch)
2246 {
2247 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2248 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302249 pResult = vos_mem_malloc(allocLen);
2250 if ( NULL == pResult )
2251 status = eHAL_STATUS_FAILURE;
2252 else
2253 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002254 if(!HAL_STATUS_SUCCESS(status))
2255 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002256 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002257 if(pNewIes)
2258 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302259 vos_mem_free(pNewIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002260 }
2261 break;
2262 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302263 vos_mem_set(pResult, allocLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002264 pResult->capValue = pBssDesc->capValue;
2265 pResult->preferValue = pBssDesc->preferValue;
2266 pResult->ucEncryptionType = uc;
2267 pResult->mcEncryptionType = mc;
2268 pResult->authType = auth;
2269 pResult->Result.ssId = pBssDesc->Result.ssId;
2270 pResult->Result.timer = 0;
2271 //save the pIes for later use
2272 pResult->Result.pvIes = pNewIes;
2273 //save bss description
Kiet Lam64c1b492013-07-12 13:56:44 +05302274 vos_mem_copy(&pResult->Result.BssDescriptor,
2275 &pBssDesc->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002276 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2277 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2278 {
2279 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2280 }
2281 else
2282 {
2283 //To sort the list
2284 tListElem *pTmpEntry;
2285 tCsrScanResult *pTmpResult;
2286
2287 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2288 while(pTmpEntry)
2289 {
2290 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
2291 if(csrIsBetterBss(pResult, pTmpResult))
2292 {
2293 csrLLInsertEntry(&pRetList->List, pTmpEntry, &pResult->Link, LL_ACCESS_NOLOCK);
2294 //To indicate we are done
2295 pResult = NULL;
2296 break;
2297 }
2298 pTmpEntry = csrLLNext(&pRetList->List, pTmpEntry, LL_ACCESS_NOLOCK);
2299 }
2300 if(pResult != NULL)
2301 {
2302 //This one is not better than any one
2303 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2304 }
2305 }
2306 count++;
2307 }
2308 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2309 }//while
2310 csrLLUnlock(&pMac->scan.scanResultList);
2311
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002312 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002313
2314 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2315 {
2316 //Fail or No one wants the result.
2317 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2318 }
2319 else
2320 {
2321 if(0 == count)
2322 {
2323 //We are here meaning the there is no match
2324 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302325 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002326 status = eHAL_STATUS_E_NULL_VALUE;
2327 }
2328 else if(phResult)
2329 {
2330 *phResult = pRetList;
2331 }
2332 }
2333 }//Allocated pRetList
2334
2335 return (status);
2336}
2337
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002338/*
2339 * NOTE: This routine is being added to make
2340 * sure that scan results are not being flushed
2341 * while roaming. If the scan results are flushed,
2342 * we are unable to recover from
2343 * csrRoamRoamingStateDisassocRspProcessor.
2344 * If it is needed to remove this routine,
2345 * first ensure that we recover gracefully from
2346 * csrRoamRoamingStateDisassocRspProcessor if
2347 * csrScanGetResult returns with a failure because
2348 * of not being able to find the roaming BSS.
2349 */
2350tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2351{
2352 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2353 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2354 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2355 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2356 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2357 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2358 default:
2359 return 0;
2360 }
2361}
2362
Jeff Johnson295189b2012-06-20 16:38:30 -07002363eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2364{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002365 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
2366 if (isFlushDenied) {
2367 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2368 __func__, isFlushDenied);
2369 return eHAL_STATUS_FAILURE;
2370 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002371 return ( csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList) );
2372}
2373
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302374eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002375{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302376 eHalStatus status = eHAL_STATUS_SUCCESS;
2377 tListElem *pEntry,*pFreeElem;
2378 tCsrScanResult *pBssDesc;
2379 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002380
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302381 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002382
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302383 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2384 while( pEntry != NULL)
2385 {
2386 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2387 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2388 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002389 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302390 pFreeElem = pEntry;
2391 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2392 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2393 csrFreeScanResultEntry( pMac, pBssDesc );
2394 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002395 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302396 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2397 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002398
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302399 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002400
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302401 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002402}
2403
Jeff Johnson295189b2012-06-20 16:38:30 -07002404/**
2405 * csrCheck11dChannel
2406 *
2407 *FUNCTION:
2408 * This function is called from csrScanFilter11dResult function and
2409 * compare channel number with given channel list.
2410 *
2411 *LOGIC:
2412 * Check Scan result channel number with CFG channel list
2413 *
2414 *ASSUMPTIONS:
2415 *
2416 *
2417 *NOTE:
2418 *
2419 * @param channelId channel number
2420 * @param pChannelList Pointer to channel list
2421 * @param numChannels Number of channel in channel list
2422 *
2423 * @return Status
2424 */
2425
2426eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2427{
2428 eHalStatus status = eHAL_STATUS_FAILURE;
2429 tANI_U8 i = 0;
2430
2431 for (i = 0; i < numChannels; i++)
2432 {
2433 if(pChannelList[ i ] == channelId)
2434 {
2435 status = eHAL_STATUS_SUCCESS;
2436 break;
2437 }
2438 }
2439 return status;
2440}
2441
2442/**
2443 * csrScanFilter11dResult
2444 *
2445 *FUNCTION:
2446 * This function is called from csrApplyCountryInformation function and
2447 * filter scan result based on valid channel list number.
2448 *
2449 *LOGIC:
2450 * Get scan result from scan list and Check Scan result channel number
2451 * with 11d channel list if channel number is found in 11d channel list
2452 * then do not remove scan result entry from scan list
2453 *
2454 *ASSUMPTIONS:
2455 *
2456 *
2457 *NOTE:
2458 *
2459 * @param pMac Pointer to Global MAC structure
2460 *
2461 * @return Status
2462 */
2463
2464eHalStatus csrScanFilter11dResult(tpAniSirGlobal pMac)
2465{
2466 eHalStatus status = eHAL_STATUS_SUCCESS;
2467 tListElem *pEntry,*pTempEntry;
2468 tCsrScanResult *pBssDesc;
2469 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2470
2471 /* Get valid channels list from CFG */
2472 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2473 pMac->roam.validChannelList, &len)))
2474 {
2475 smsLog( pMac, LOG1, "Failed to get Channel list from CFG");
2476 }
2477
2478 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2479 while( pEntry )
2480 {
2481 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2482 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
2483 LL_ACCESS_LOCK );
2484 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2485 pMac->roam.validChannelList, len))
2486 {
2487 /* Remove Scan result which does not have 11d channel */
2488 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2489 LL_ACCESS_LOCK ))
2490 {
2491 csrFreeScanResultEntry( pMac, pBssDesc );
2492 }
2493 }
2494 pEntry = pTempEntry;
2495 }
2496 return status;
2497}
2498
2499
2500eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
2501{
2502 eHalStatus status = eHAL_STATUS_SUCCESS;
2503 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
2504 tCsrScanResult *pResult, *pScanResult;
2505 tANI_U32 count = 0;
2506 tListElem *pEntry;
2507 tANI_U32 bssLen, allocLen;
2508
2509 if(phResult)
2510 {
2511 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2512 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302513 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2514 if ( NULL == pRetList )
2515 status = eHAL_STATUS_FAILURE;
2516 else
Jeff Johnson295189b2012-06-20 16:38:30 -07002517 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302518 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002519 csrLLOpen(pMac->hHdd, &pRetList->List);
2520 pRetList->pCurEntry = NULL;
2521 csrLLLock(&pMac->scan.scanResultList);
2522 csrLLLock(&pInList->List);
2523
2524 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
2525 while( pEntry )
2526 {
2527 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2528 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
2529 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302530 pResult = vos_mem_malloc(allocLen);
2531 if ( NULL == pResult )
2532 status = eHAL_STATUS_FAILURE;
2533 else
2534 status = eHAL_STATUS_SUCCESS;
2535 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002536 {
2537 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2538 count = 0;
2539 break;
2540 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302541 vos_mem_set(pResult, allocLen , 0);
2542 vos_mem_copy(&pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002543 if( pScanResult->Result.pvIes )
2544 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302545 pResult->Result.pvIes = vos_mem_malloc(sizeof( tDot11fBeaconIEs ));
2546 if ( NULL == pResult->Result.pvIes )
2547 status = eHAL_STATUS_FAILURE;
2548 else
2549 status = eHAL_STATUS_SUCCESS;
2550 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002551 {
2552 //Free the memory we allocate above first
Kiet Lam64c1b492013-07-12 13:56:44 +05302553 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07002554 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2555 count = 0;
2556 break;
2557 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302558 vos_mem_copy(pResult->Result.pvIes, pScanResult->Result.pvIes,
2559 sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002560 }
2561 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
2562 count++;
2563 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
2564 }//while
2565 csrLLUnlock(&pInList->List);
2566 csrLLUnlock(&pMac->scan.scanResultList);
2567
2568 if(HAL_STATUS_SUCCESS(status))
2569 {
2570 if(0 == count)
2571 {
2572 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302573 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002574 status = eHAL_STATUS_E_NULL_VALUE;
2575 }
2576 else if(phResult)
2577 {
2578 *phResult = pRetList;
2579 }
2580 }
2581 }//Allocated pRetList
2582
2583 return (status);
2584}
2585
2586
2587
2588eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
2589{
2590 eHalStatus status = eHAL_STATUS_SUCCESS;
2591 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
2592
2593 if((eWNI_SME_SCAN_RSP == pMsg->type) || (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
2594 {
2595 status = csrScanSmeScanResponse( pMac, pMsgBuf );
2596 }
2597 else
2598 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002599 if(pMsg->type == eWNI_SME_UPPER_LAYER_ASSOC_CNF)
Jeff Johnson295189b2012-06-20 16:38:30 -07002600 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002601 tCsrRoamSession *pSession;
2602 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
2603 tCsrRoamInfo roamInfo;
2604 tCsrRoamInfo *pRoamInfo = NULL;
2605 tANI_U32 sessionId;
2606 eHalStatus status;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002607 smsLog( pMac, LOG1, FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
Kiet Lam64c1b492013-07-12 13:56:44 +05302608 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002609 pRoamInfo = &roamInfo;
2610 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
2611 status = csrRoamGetSessionIdFromBSSID( pMac, (tCsrBssid *)pUpperLayerAssocCnf->bssId, &sessionId );
2612 pSession = CSR_GET_SESSION(pMac, sessionId);
2613
2614 if(!pSession)
2615 {
2616 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2617 return eHAL_STATUS_FAILURE;
2618 }
2619
2620 pRoamInfo->statusCode = eSIR_SME_SUCCESS; //send the status code as Success
2621 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
2622 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
2623 pRoamInfo->rsnIELen = (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
2624 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
2625 pRoamInfo->addIELen = (tANI_U8)pUpperLayerAssocCnf->addIE.length;
2626 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
Kiet Lam64c1b492013-07-12 13:56:44 +05302627 vos_mem_copy(pRoamInfo->peerMac, pUpperLayerAssocCnf->peerMacAddr, sizeof(tSirMacAddr));
2628 vos_mem_copy(&pRoamInfo->bssid, pUpperLayerAssocCnf->bssId, sizeof(tCsrBssid));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002629 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
2630 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
2631 {
2632 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
2633 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
2634 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_INFRA_IND, eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
2635 }
2636 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
2637 {
2638 vos_sleep( 100 );
2639 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
2640 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_WDS_IND, eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
2641 }
2642
Jeff Johnson295189b2012-06-20 16:38:30 -07002643 }
2644 else
2645 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002646
2647 if( csrIsAnySessionInConnectState( pMac ) )
2648 {
2649 //In case of we are connected, we need to check whether connect status changes
2650 //because scan may also run while connected.
2651 csrRoamCheckForLinkStatusChange( pMac, ( tSirSmeRsp * )pMsgBuf );
2652 }
2653 else
2654 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002655 smsLog( pMac, LOGW, "Message [0x%04x] received in state, when expecting Scan Response", pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002656 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002657 }
2658 }
2659
2660 return (status);
2661}
2662
2663
2664
2665void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
2666{
2667 int idx, len;
2668 tANI_U8 *pbIe;
2669
2670 //If failed to remove, assuming someone else got it.
2671 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
2672 (0 == pNewBssDescr->WscIeLen))
2673 {
2674 idx = 0;
2675 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
2676 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
2677 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
2678 //Save WPS IE if it exists
2679 pNewBssDescr->WscIeLen = 0;
2680 while(idx < len)
2681 {
2682 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
2683 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
2684 {
2685 //Founrd it
2686 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
2687 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302688 vos_mem_copy(pNewBssDescr->WscIeProbeRsp, pbIe, pbIe[1] + 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07002689 pNewBssDescr->WscIeLen = pbIe[1] + 2;
2690 }
2691 break;
2692 }
2693 idx += pbIe[1] + 2;
2694 pbIe += pbIe[1] + 2;
2695 }
2696 }
2697}
2698
2699
2700
2701//pIes may be NULL
2702tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05302703 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07002704{
2705 tListElem *pEntry;
2706
2707 tCsrScanResult *pBssDesc;
2708 tANI_BOOLEAN fRC = FALSE;
2709
2710 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
2711 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
2712 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
2713 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2714
2715 while( pEntry )
2716 {
2717 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2718
2719 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
2720 // matches
2721 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07002722 pSirBssDescr, pIes, fForced ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002723 {
2724 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
2725 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
2726 // Remove the 'old' entry from the list....
2727 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
2728 {
2729 // !we need to free the memory associated with this node
2730 //If failed to remove, assuming someone else got it.
2731 *pSsid = pBssDesc->Result.ssId;
2732 *timer = pBssDesc->Result.timer;
2733 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
2734
2735 csrFreeScanResultEntry( pMac, pBssDesc );
2736 }
2737 else
2738 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002739 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07002740 }
2741 fRC = TRUE;
2742
2743 // If we found a match, we can stop looking through the list.
2744 break;
2745 }
2746
2747 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
2748 }
2749
2750 return fRC;
2751}
2752
2753
2754eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2755 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2756{
2757 eHalStatus status = eHAL_STATUS_FAILURE;
2758 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2759
Jeff Johnson32d95a32012-09-10 13:15:23 -07002760 if(!pSession)
2761 {
2762 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2763 return eHAL_STATUS_FAILURE;
2764 }
2765
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002766 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002767 if( pIes )
2768 {
2769 // check if this is a RSN BSS
2770 if( pIes->RSN.present )
2771 {
2772 // Check if the BSS is capable of doing pre-authentication
2773 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
2774 {
2775
2776#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2777 {
2778 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
Kiet Lam64c1b492013-07-12 13:56:44 +05302779 vos_mem_set(&secEvent, sizeof(vos_event_wlan_security_payload_type), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002780 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
2781 secEvent.encryptionModeMulticast =
2782 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
2783 secEvent.encryptionModeUnicast =
2784 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
Kiet Lam64c1b492013-07-12 13:56:44 +05302785 vos_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07002786 secEvent.authMode =
2787 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
2788 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
2789 }
2790#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2791
2792 // if yes, then add to PMKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05302793 vos_mem_copy(pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
2794 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2795 // Bit 0 offirst byte - PreAuthentication Capability
2796 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002797 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302798 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
2799 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07002800 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302801 else
2802 {
2803 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
2804 = eANI_BOOLEAN_FALSE;
2805 }
2806 pSession->NumPmkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07002807 }
2808 else
2809 {
2810 status = eHAL_STATUS_FAILURE;
2811 }
2812 }
2813 }
2814
2815 return (status);
2816}
2817
2818//This function checks whether new AP is found for the current connected profile
2819//If it is found, it return the sessionId, else it return invalid sessionID
2820tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
2821 tSirBssDescription *pBssDesc,
2822 tDot11fBeaconIEs *pIes)
2823{
2824 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
2825 tCsrRoamSession *pSession;
2826 tDot11fBeaconIEs *pIesLocal = pIes;
2827
2828 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2829 {
2830 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
2831 {
2832 if( CSR_IS_SESSION_VALID( pMac, i ) )
2833 {
2834 pSession = CSR_GET_SESSION( pMac, i );
2835 if( csrIsConnStateConnectedInfra( pMac, i ) &&
2836 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
2837 {
2838 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
2839 {
2840 //this new BSS fits the current profile connected
2841 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
2842 {
2843 bRet = i;
2844 }
2845 break;
2846 }
2847 }
2848 }
2849 }
2850 if( !pIes )
2851 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302852 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002853 }
2854 }
2855
2856 return (tANI_U8)bRet;
2857}
2858
2859#ifdef FEATURE_WLAN_WAPI
2860eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2861 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2862{
2863 eHalStatus status = eHAL_STATUS_FAILURE;
2864 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2865
Jeff Johnson32d95a32012-09-10 13:15:23 -07002866 if(!pSession)
2867 {
2868 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2869 return eHAL_STATUS_FAILURE;
2870 }
2871
Kiet Lam64c1b492013-07-12 13:56:44 +05302872 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d",
2873 pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002874 if( pIes )
2875 {
2876 // check if this is a WAPI BSS
2877 if( pIes->WAPI.present )
2878 {
2879 // Check if the BSS is capable of doing pre-authentication
2880 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
2881 {
2882
2883 // if yes, then add to BKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05302884 vos_mem_copy(pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
2885 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2886 if ( pIes->WAPI.preauth )
Jeff Johnson295189b2012-06-20 16:38:30 -07002887 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302888 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
2889 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07002890 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302891 else
2892 {
2893 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
2894 = eANI_BOOLEAN_FALSE;
2895 }
2896 pSession->NumBkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07002897 }
2898 else
2899 {
2900 status = eHAL_STATUS_FAILURE;
2901 }
2902 }
2903 }
2904
2905 return (status);
2906}
2907
2908//This function checks whether new AP is found for the current connected profile
2909//if so add to BKIDCandidateList
2910tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
2911 tDot11fBeaconIEs *pIes)
2912{
2913 tANI_BOOLEAN fRC = FALSE;
2914 tDot11fBeaconIEs *pIesLocal = pIes;
2915 tANI_U32 sessionId;
2916 tCsrRoamSession *pSession;
2917
2918 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2919 {
2920 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
2921 {
2922 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
2923 {
2924 pSession = CSR_GET_SESSION( pMac, sessionId );
2925 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
2926 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
2927 {
2928 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
2929 {
2930 //this new BSS fits the current profile connected
2931 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
2932 {
2933 fRC = TRUE;
2934 }
2935 }
2936 }
2937 }
2938 }
2939 if(!pIes)
2940 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302941 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002942 }
2943
2944 }
2945 return fRC;
2946}
2947
2948#endif
2949
2950
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07002951static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07002952{
2953 tListElem *pEntry;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05302954 tListElem *pEntryTemp;
2955 tListElem *pNext;
Jeff Johnson295189b2012-06-20 16:38:30 -07002956 tCsrScanResult *pBssDescription;
2957 tANI_S8 cand_Bss_rssi;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05302958 tANI_S8 rssi_of_current_country;
Jeff Johnson295189b2012-06-20 16:38:30 -07002959 tANI_BOOLEAN fDupBss;
2960#ifdef FEATURE_WLAN_WAPI
2961 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
2962#endif /* FEATURE_WLAN_WAPI */
2963 tDot11fBeaconIEs *pIesLocal = NULL;
2964 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
2965 tAniSSID tmpSsid;
2966 v_TIME_t timer=0;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05302967 tCsrBssid bssid_temp = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
Jeff Johnson295189b2012-06-20 16:38:30 -07002968
2969 tmpSsid.length = 0;
2970 cand_Bss_rssi = -128; // RSSI coming from PE is -ve
Agarwal Ashishd9d72602013-09-13 00:06:17 +05302971 rssi_of_current_country = -128;
Jeff Johnson295189b2012-06-20 16:38:30 -07002972
2973 // remove the BSS descriptions from temporary list
2974 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
2975 {
2976 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2977
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002978 smsLog( pMac, LOGW, "...Bssid= %02x-%02x-%02x-%02x-%02x-%02x chan= %d, rssi = -%d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002979 pBssDescription->Result.BssDescriptor.bssId[ 0 ], pBssDescription->Result.BssDescriptor.bssId[ 1 ],
2980 pBssDescription->Result.BssDescriptor.bssId[ 2 ], pBssDescription->Result.BssDescriptor.bssId[ 3 ],
2981 pBssDescription->Result.BssDescriptor.bssId[ 4 ], pBssDescription->Result.BssDescriptor.bssId[ 5 ],
2982 pBssDescription->Result.BssDescriptor.channelId,
2983 pBssDescription->Result.BssDescriptor.rssi * (-1) );
2984
2985 //At this time, pBssDescription->Result.pvIes may be NULL
2986 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
2987 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
2988 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002989 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002990 csrFreeScanResultEntry(pMac, pBssDescription);
2991 continue;
2992 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05302993 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07002994 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
2995 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
2996#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2997 && !( eCsrScanGetLfrResult == reason )
2998#endif
2999 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003000 {
3001 //Limit reach
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003002 smsLog(pMac, LOGW, FL(" BSS limit reached"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003003 //Free the resources
3004 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
3005 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303006 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003007 }
3008 csrFreeScanResultEntry(pMac, pBssDescription);
3009 //Continue because there may be duplicated BSS
3010 continue;
3011 }
3012 // check for duplicate scan results
3013 if ( !fDupBss )
3014 {
3015 //Found a new BSS
3016 sessionId = csrProcessBSSDescForPMKIDList(pMac,
3017 &pBssDescription->Result.BssDescriptor, pIesLocal);
3018 if( CSR_SESSION_ID_INVALID != sessionId)
3019 {
3020 csrRoamCallCallback(pMac, sessionId, NULL, 0,
3021 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
3022 }
3023 }
3024 else
3025 {
3026 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3027 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
3028 {
3029 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3030 //if diff of saved SSID time and current time is less than 1 min to avoid
3031 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3032 //hidden, we may never see it and also to address the requirement of
3033 //When we remove hidden ssid from the profile i.e., forget the SSID via
3034 // GUI that SSID shouldn't see in the profile
3035 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
3036 {
3037 pBssDescription->Result.timer = timer;
3038 pBssDescription->Result.ssId = tmpSsid;
3039 }
3040 }
3041 }
3042
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303043 //Find a good AP for 11d info
3044 if ( csrIs11dSupported( pMac ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003045 {
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303046 if (cand_Bss_rssi < pBssDescription->Result.BssDescriptor.rssi)
Jeff Johnson295189b2012-06-20 16:38:30 -07003047 {
3048 // check if country information element is present
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303049 if (pIesLocal->Country.present)
Jeff Johnson295189b2012-06-20 16:38:30 -07003050 {
3051 cand_Bss_rssi = pBssDescription->Result.BssDescriptor.rssi;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303052 smsLog(pMac, LOGW, FL("11d AP Bssid " MAC_ADDRESS_STR
3053 " chan= %d, rssi = -%d, countryCode %c%c"),
3054 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3055 pBssDescription->Result.BssDescriptor.channelId,
3056 pBssDescription->Result.BssDescriptor.rssi * (-1),
3057 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3058 //Getting BSSID for best AP in scan result.
3059 palCopyMemory(pMac->hHdd, bssid_temp,
3060 pBssDescription->Result.BssDescriptor.bssId, sizeof(tSirMacAddr));
3061
Jeff Johnson295189b2012-06-20 16:38:30 -07003062 }
3063
3064 }
3065 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303066 //get current rssi for BSS from which country code is acquired.
3067 if ( csrIs11dSupported(pMac) && (csrIsMacAddressEqual(pMac,
3068 &pMac->scan.currentCountryBssid,
3069 &pBssDescription->Result.BssDescriptor.bssId) ))
3070 {
3071 smsLog(pMac, LOGW, FL("Information about current country Bssid "
3072 MAC_ADDRESS_STR
3073 " chan= %d, rssi = -%d, countryCode %c%c"),
3074 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3075 pBssDescription->Result.BssDescriptor.channelId,
3076 pBssDescription->Result.BssDescriptor.rssi * (-1),
3077 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3078 rssi_of_current_country = pBssDescription->Result.BssDescriptor.rssi ;
3079 }
3080
Jeff Johnson295189b2012-06-20 16:38:30 -07003081
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08003082
Jeff Johnson295189b2012-06-20 16:38:30 -07003083 // append to main list
3084 csrScanAddResult(pMac, pBssDescription, pIesLocal);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303085 if ( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
Jeff Johnson295189b2012-06-20 16:38:30 -07003086 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303087 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003088 }
3089 }
3090
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303091 // Calculating 30% of current rssi is an idea for not to change
3092 // country code so freq.
3093 if (rssi_of_current_country != -128)
3094 {
3095 rssi_of_current_country = rssi_of_current_country
3096 - THIRTY_PERCENT(rssi_of_current_country);
3097 }
3098
3099 if ((rssi_of_current_country <= cand_Bss_rssi ) || rssi_of_current_country == -128)
3100 {
3101 csrLLLock(&pMac->scan.scanResultList);
3102 pEntryTemp = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
3103 while ( NULL != pEntryTemp)
3104 {
3105 pNext = csrLLNext(&pMac->scan.scanResultList, pEntryTemp,
3106 LL_ACCESS_NOLOCK);
3107 pBssDescription = GET_BASE_ADDR( pEntryTemp, tCsrScanResult, Link );
3108 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3109 // Need to traverse whole scan list to get description for best 11d AP.
3110 if (csrIsMacAddressEqual(pMac, (tCsrBssid *)&bssid_temp,
3111 (tCsrBssid *) pBssDescription->Result.BssDescriptor.bssId))
3112 {
3113 palCopyMemory(pMac->hHdd, pMac->scan.currentCountryBssid,
3114 bssid_temp, sizeof(tSirMacAddr));
3115 // Best AP should be passed to update reg domain.
3116 csrLearnCountryInformation( pMac, &pBssDescription->Result.BssDescriptor,
3117 pIesLocal, eANI_BOOLEAN_FALSE );
3118 break;
3119 }
3120 pEntryTemp = pNext;
3121 }
3122 csrLLUnlock(&pMac->scan.scanResultList);
3123 }
3124
3125
Jeff Johnson295189b2012-06-20 16:38:30 -07003126 //Tush: If we can find the current 11d info in any of the scan results, or
3127 // a good enough AP with the 11d info from the scan results then no need to
3128 // get into ambiguous state
3129 if(pMac->scan.fAmbiguous11dInfoFound)
3130 {
3131 if((pMac->scan.fCurrent11dInfoMatch) || (cand_Bss_rssi != -128))
3132 {
3133 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3134 }
3135 }
3136
3137#ifdef FEATURE_WLAN_WAPI
3138 if(fNewWapiBSSForCurConnection)
3139 {
3140 //remember it first
3141 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3142 }
3143#endif /* FEATURE_WLAN_WAPI */
3144
3145 return;
3146}
3147
3148
3149static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3150 tDot11fBeaconIEs *pIes)
3151{
3152 tCsrScanResult *pCsrBssDescription = NULL;
3153 tANI_U32 cbBSSDesc;
3154 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07003155
3156 // figure out how big the BSS description is (the BSSDesc->length does NOT
3157 // include the size of the length field itself).
3158 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3159
3160 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3161
Kiet Lam64c1b492013-07-12 13:56:44 +05303162 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3163 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003164 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303165 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003166 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303167 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003168#if defined(VOSS_ENSBALED)
3169 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3170#endif
3171 csrScanAddResult(pMac, pCsrBssDescription, pIes);
3172 }
3173
3174 return( pCsrBssDescription );
3175}
3176
3177// Append a Bss Description...
3178tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3179 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003180 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003181{
3182 tCsrScanResult *pCsrBssDescription = NULL;
3183 tAniSSID tmpSsid;
3184 v_TIME_t timer = 0;
3185 int result;
3186
3187 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003188 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003189 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3190 if (result && (pCsrBssDescription != NULL))
3191 {
3192 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3193 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3194 {
3195 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3196 //if diff of saved SSID time and current time is less than 1 min to avoid
3197 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3198 //hidden, we may never see it and also to address the requirement of
3199 //When we remove hidden ssid from the profile i.e., forget the SSID via
3200 // GUI that SSID shouldn't see in the profile
3201 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3202 {
3203 pCsrBssDescription->Result.ssId = tmpSsid;
3204 pCsrBssDescription->Result.timer = timer;
3205 }
3206 }
3207 }
3208
3209
3210 return( pCsrBssDescription );
3211}
3212
3213
3214
3215void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3216{
3217 tCsrChannelPowerInfo *pChannelSet;
3218 tListElem *pEntry;
3219
3220 csrLLLock(pChannelList);
3221 // Remove the channel sets from the learned list and put them in the free list
3222 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3223 {
3224 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3225 if( pChannelSet )
3226 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303227 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003228 }
3229 }
3230 csrLLUnlock(pChannelList);
3231 return;
3232}
3233
3234
3235/*
3236 * Save the channelList into the ultimate storage as the final stage of channel
3237 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3238 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003239eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003240{
3241 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3242 tSirMacChanInfo *pChannelInfo;
3243 tCsrChannelPowerInfo *pChannelSet;
3244 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3245 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003246
3247 pChannelInfo = channelTable;
3248 // atleast 3 bytes have to be remaining -- from "countryString"
3249 while ( i-- )
3250 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303251 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
3252 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07003253 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303254 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003255 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3256 pChannelSet->numChannels = pChannelInfo->numChannels;
3257
3258 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003259 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003260 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003261
Jeff Johnson295189b2012-06-20 16:38:30 -07003262 {
3263 pChannelSet->interChannelOffset = 1;
3264 f2GHzInfoFound = TRUE;
3265 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003266 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003267 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003268 {
3269 pChannelSet->interChannelOffset = 4;
3270 f2GHzInfoFound = FALSE;
3271 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003272 else
3273 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003274 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003275 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303276 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07003277 return eHAL_STATUS_FAILURE;
3278 }
3279
Jeff Johnson295189b2012-06-20 16:38:30 -07003280 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3281
3282 if( f2GHzInfoFound )
3283 {
3284 if( !f2GListPurged )
3285 {
3286 // purge previous results if found new
3287 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3288 f2GListPurged = TRUE;
3289 }
3290
3291 if(CSR_IS_OPERATING_BG_BAND(pMac))
3292 {
3293 // add to the list of 2.4 GHz channel sets
3294 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3295 }
3296 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003297 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003298 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303299 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003300 }
3301 }
3302 else
3303 {
3304 // 5GHz info found
3305 if( !f5GListPurged )
3306 {
3307 // purge previous results if found new
3308 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3309 f5GListPurged = TRUE;
3310 }
3311
3312 if(CSR_IS_OPERATING_A_BAND(pMac))
3313 {
3314 // add to the list of 5GHz channel sets
3315 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3316 }
3317 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003318 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003319 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303320 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003321 }
3322 }
3323 }
3324
3325 pChannelInfo++; // move to next entry
3326 }
3327
Jeff Johnsone7245742012-09-05 17:12:55 -07003328 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003329}
3330
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303331static void csrClearDfsChannelList( tpAniSirGlobal pMac )
3332{
3333 tSirMbMsg *pMsg;
3334 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07003335
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303336 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05303337 pMsg = vos_mem_malloc(msgLen);
3338 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303339 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303340 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303341 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
3342 pMsg->msgLen = pal_cpu_to_be16(msgLen);
3343 palSendMBMessage(pMac->hHdd, pMsg);
3344 }
3345}
Jeff Johnson295189b2012-06-20 16:38:30 -07003346
3347void csrApplyPower2Current( tpAniSirGlobal pMac )
3348{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003349 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003350 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3351 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3352}
3353
3354
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003355void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003356{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303357 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003358 eNVChannelEnabledType channelEnabledType;
3359 tANI_U8 numChannels = 0;
3360 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303361 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003362 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303363
Jeff Johnson295189b2012-06-20 16:38:30 -07003364 if( pChannelList->numChannels )
3365 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303366 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3367 {
3368 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3369 VOS_COUNTRY_CODE_LEN))
3370 {
3371 countryIndex = count;
3372 break;
3373 }
3374 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003375 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
3376 /* If user doesn't want to scan the DFS channels lets trim them from
3377 the valid channel list*/
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303378 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003379 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303380 channelIgnore = FALSE;
3381 if( FALSE == pMac->scan.fEnableDFSChnlScan )
3382 {
3383 channelEnabledType =
3384 vos_nv_getChannelEnabledState(pChannelList->channelList[i]);
3385 }
3386 else
3387 {
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003388 channelEnabledType = NV_CHANNEL_ENABLE;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303389 }
3390 if( NV_CHANNEL_ENABLE == channelEnabledType )
3391 {
3392 if( countryIndex != -1 )
3393 {
3394 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
3395 {
3396 if( pChannelList->channelList[i] ==
3397 countryIgnoreList[countryIndex].channelList[j] )
3398 {
3399 channelIgnore = TRUE;
3400 break;
3401 }
3402 }
3403 }
3404 if( FALSE == channelIgnore )
3405 {
3406 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
3407 numChannels++;
3408 }
3409 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003410 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303411 ChannelList.numChannels = numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07003412 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3413 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303414 // build a scan list based on the channel list : channel# + active/passive scan
3415 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303416 /*Send msg to Lim to clear DFS channel list */
3417 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003418#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003419 if (updateRiva)
3420 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003421 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003422 // Send HAL UpdateScanParams message
3423 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
3424 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003425#endif // FEATURE_WLAN_SCAN_PNO
3426 }
3427 else
3428 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003429 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003430 }
3431 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
3432 csrSetCfgCountryCode(pMac, countryCode);
3433}
3434
3435
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003436void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07003437{
3438 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
3439 {
3440
3441#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3442 {
3443 vos_log_802_11d_pkt_type *p11dLog;
3444 int Index;
3445
3446 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3447 if(p11dLog)
3448 {
3449 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303450 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003451 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
3452 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3453 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303454 vos_mem_copy(p11dLog->Channels,
3455 pMac->scan.base20MHzChannels.channelList,
3456 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003457 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
3458 {
3459 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3460 }
3461 }
3462 if(!pMac->roam.configParam.Is11dSupportEnabled)
3463 {
3464 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3465 }
3466 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3467 {
3468 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3469 }
3470 else
3471 {
3472 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3473 }
3474 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3475 }
3476 }
3477#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3478
3479 // switch to passive scans only when 11d is enabled
3480 if( csrIs11dSupported( pMac ) )
3481 {
3482 pMac->scan.curScanType = eSIR_PASSIVE_SCAN;
3483 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003484
3485 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
3486 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
3487
Jeff Johnson295189b2012-06-20 16:38:30 -07003488 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
3489 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
3490 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003491 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07003492 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05303493 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003494 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
3495 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
3496 }
3497
3498 return;
3499}
3500
3501
3502eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
3503{
3504 eHalStatus status = eHAL_STATUS_SUCCESS;
3505 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
3506
3507 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05303508 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
3509 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003510 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07003511 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
3512 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07003513 {
3514 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003515 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003516 }
3517 if(pfRestartNeeded)
3518 {
3519 *pfRestartNeeded = fRestart;
3520 }
3521
3522 return (status);
3523}
3524
3525
3526eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
3527{
3528 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
3529 v_REGDOMAIN_t domainId;
3530
3531 if(pCountry)
3532 {
3533 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId);
3534 if(HAL_STATUS_SUCCESS(status))
3535 {
3536 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
3537 if(HAL_STATUS_SUCCESS(status))
3538 {
3539 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
3540 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05303541 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003542 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
3543 {
3544 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
3545 csrSetCfgCountryCode(pMac, pCountry);
3546 }
3547 }
3548 }
3549 }
3550
3551 return (status);
3552}
3553
3554
3555
3556//caller allocated memory for pNumChn and pChnPowerInfo
3557//As input, *pNumChn has the size of the array of pChnPowerInfo
3558//Upon return, *pNumChn has the number of channels assigned.
3559void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
3560 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
3561{
3562 tListElem *pEntry;
3563 tANI_U32 chnIdx = 0, idx;
3564 tCsrChannelPowerInfo *pChannelSet;
3565
3566 //Get 2.4Ghz first
3567 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
3568 while( pEntry && (chnIdx < *pNumChn) )
3569 {
3570 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3571 if ( 1 != pChannelSet->interChannelOffset )
3572 {
3573 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3574 {
3575 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
3576 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3577 }
3578 }
3579 else
3580 {
3581 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3582 {
3583 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
3584 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3585 }
3586 }
3587
3588 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
3589 }
3590 *pNumChn = chnIdx;
3591
3592 return ;
3593}
3594
3595
3596
3597void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
3598{
3599 v_REGDOMAIN_t domainId;
3600 eHalStatus status = eHAL_STATUS_SUCCESS;
3601
3602 do
3603 {
3604 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
3605 if( pMac->scan.fAmbiguous11dInfoFound )
3606 {
3607 // ambiguous info found
3608 //Restore te default domain as well
3609 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pMac->scan.countryCodeCurrent, &domainId )))
3610 {
3611 pMac->scan.domainIdCurrent = domainId;
3612 }
3613 else
3614 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003615 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003616 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
3617 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003618 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003619 break;
3620 }
3621 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
3622 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pMac->scan.countryCode11d, &domainId )))
3623 {
3624 //Check whether we need to enforce default domain
3625 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
3626 (pMac->scan.domainIdCurrent == domainId) )
3627 {
3628
3629#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3630 {
3631 vos_log_802_11d_pkt_type *p11dLog;
3632 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
3633 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
3634
3635 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3636 if(p11dLog)
3637 {
3638 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303639 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003640 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
3641 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3642 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303643 vos_mem_copy(p11dLog->Channels,
3644 pMac->scan.channels11d.channelList,
3645 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003646 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
3647 &nChnInfo, chnPwrInfo);
3648 nTmp = nChnInfo;
3649 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
3650 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
3651 &nChnInfo, &chnPwrInfo[nTmp]);
3652 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
3653 {
3654 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
3655 {
3656 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
3657 {
3658 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
3659 break;
3660 }
3661 }
3662 }
3663 }
3664 if(!pMac->roam.configParam.Is11dSupportEnabled)
3665 {
3666 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3667 }
3668 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3669 {
3670 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3671 }
3672 else
3673 {
3674 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3675 }
3676 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3677 }
3678 }
3679#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3680 if(pMac->scan.domainIdCurrent != domainId)
3681 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003682 smsLog(pMac, LOGW, FL("Domain Changed Old %d, new %d"),
3683 pMac->scan.domainIdCurrent, domainId);
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05303684 status = WDA_SetRegDomain(pMac, domainId);
Jeff Johnson295189b2012-06-20 16:38:30 -07003685 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003686 if (status != eHAL_STATUS_SUCCESS)
3687 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003688 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003689 }
3690 pMac->scan.domainIdCurrent = domainId;
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003691 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.channels11d, pMac->scan.countryCode11d, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003692 // switch to active scans using this new channel list
3693 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
3694 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
3695 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
3696 }
3697 }
3698
3699 } while( 0 );
3700
3701 return;
3702}
3703
3704
3705
3706tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
3707 tANI_BOOLEAN fForce)
3708{
3709 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
3710 tANI_U32 i;
3711
3712 // convert to UPPER here so we are assured the strings are always in upper case.
3713 for( i = 0; i < 3; i++ )
3714 {
3715 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3716 }
3717
3718 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
3719 // NA is not a valid country code or domain so let's allow this by changing it to the proper
3720 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
3721 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
3722 // 11d information element, let's default to US.
3723 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pCountryCode, NULL ) ) )
3724 {
3725 // Check the enforcement first
3726 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
3727 {
3728 fUnknownCountryCode = TRUE;
3729 }
3730 else
3731 {
3732 pCountryCode[ 0 ] = 'U';
3733 pCountryCode[ 1 ] = 'S';
3734 }
3735 }
3736
3737 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
3738 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
3739 // if we see a 0 in this third character, let's change it to a ' '.
3740 if ( 0 == pCountryCode[ 2 ] )
3741 {
3742 pCountryCode[ 2 ] = ' ';
3743 }
3744
3745 if( !fUnknownCountryCode )
3746 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303747 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07003748
3749
3750 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
3751 || (fForce))
3752 {
3753 // this is the first .11d information
Kiet Lam64c1b492013-07-12 13:56:44 +05303754 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
3755 sizeof( pMac->scan.countryCode11d ));
Jeff Johnson295189b2012-06-20 16:38:30 -07003756 }
3757 }
3758
3759 return( fCountryStringChanged );
3760}
3761
3762
3763void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
3764{
3765 tANI_U32 Index, count=0;
3766 tSirMacChanInfo *pChanInfo;
3767 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003768 tANI_S32 maxChannelIndex;
3769
3770 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
3771 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07003772
Kiet Lam64c1b492013-07-12 13:56:44 +05303773 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
3774 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07003775 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303776 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003777 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003778 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003779 {
3780 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
3781 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
3782 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003783 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
3784 {
3785 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
3786 break;
3787 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003788 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
3789 pChanInfo->numChannels = 1;
3790 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3791 pChanInfo++;
3792 count++;
3793 }
3794 }
3795 if(count)
3796 {
3797 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
3798 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303799 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07003800 }
3801}
3802
3803
3804void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
3805{
3806 tANI_BOOLEAN fPopulate5GBand = FALSE;
3807
3808 do
3809 {
3810 // if this is not a dual band product, then we don't need to set the opposite
3811 // band info. We only work in one band so no need to look in the other band.
3812 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
3813 // if we found channel info on the 5.0 band and...
3814 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
3815 {
3816 // and the 2.4 band is empty, then populate the 2.4 channel info
Jeff Johnson295189b2012-06-20 16:38:30 -07003817 fPopulate5GBand = FALSE;
3818 }
3819 else
3820 {
3821 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
3822 // set the 5.0 band info from the 2.4 country code.
Jeff Johnson295189b2012-06-20 16:38:30 -07003823 fPopulate5GBand = TRUE;
3824 }
3825 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
3826
3827 } while( 0 );
3828}
3829
3830
3831tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
3832{
3833 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3834 tANI_U32 i;
3835
3836 //Make sure it is a channel that is in our supported list.
3837 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
3838 {
3839 if ( channelId == pMac->scan.baseChannels.channelList[i] )
3840 {
3841 fRet = eANI_BOOLEAN_TRUE;
3842 break;
3843 }
3844 }
3845
3846 //If it is configured to limit a set of the channels
3847 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
3848 {
3849 fRet = eANI_BOOLEAN_FALSE;
3850 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
3851 {
3852 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
3853 {
3854 fRet = eANI_BOOLEAN_TRUE;
3855 break;
3856 }
3857 }
3858 }
3859
3860 return (fRet);
3861}
3862
3863
3864
3865//bSize specify the buffer size of pChannelList
3866tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
3867{
3868 tANI_U8 i, j = 0, chnId;
3869
3870 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
3871 for( i = 0; i < bSize; i++ )
3872 {
3873 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
3874 if ( csrIsSupportedChannel( pMac, chnId ) )
3875 {
3876 pChannelList[j++] = chnId;
3877 }
3878 }
3879
3880 return (j);
3881}
3882
3883
3884
3885//bSize -- specify the buffer size of pChannelList
3886void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
3887 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
3888{
3889 tListElem *pEntry;
3890 tCsrChannelPowerInfo *pChannelSet;
3891 tANI_U8 numChannels;
3892 tANI_U8 *pChannels;
3893
3894 if( pChannelSetList && pChannelList && pNumChannels )
3895 {
3896 pChannels = pChannelList;
3897 *pNumChannels = 0;
3898 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
3899 while( pEntry )
3900 {
3901 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3902 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
3903 pChannels += numChannels;
3904 *pNumChannels += numChannels;
3905 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
3906 }
3907 }
3908}
3909
3910
3911/*
3912 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
3913*/
3914tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
3915 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
3916{
3917 tANI_U8 Num2GChannels, bMaxNumChn;
3918 eHalStatus status;
3919 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3920 v_REGDOMAIN_t domainId;
3921 tDot11fBeaconIEs *pIesLocal = pIes;
3922
Jeff Johnson295189b2012-06-20 16:38:30 -07003923 if (VOS_STA_SAP_MODE == vos_get_conparam ())
3924 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003925
3926 do
3927 {
3928 // check if .11d support is enabled
3929 if( !csrIs11dSupported( pMac ) ) break;
3930 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc, &pIesLocal))) )
3931 {
3932 break;
3933 }
3934 // check if country information element is present
3935 if(!pIesLocal->Country.present)
3936 {
3937 //No country info
3938 break;
3939 }
3940
3941 if( csrSave11dCountryString( pMac, pIesLocal->Country.country, fForce ) )
3942 {
3943 // country string changed, this should not happen
3944 //Need to check whether we care about this BSS' domain info
3945 //If it doesn't match of the connected profile or roaming profile, let's ignore it
3946 tANI_U32 i;
3947 tCsrRoamSession *pSession;
3948
3949 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3950 {
3951 if( CSR_IS_SESSION_VALID( pMac, i ) )
3952 {
3953 pSession = CSR_GET_SESSION( pMac, i );
3954 if(pSession->pCurRoamProfile)
3955 {
3956 tCsrScanResultFilter filter;
3957
Kiet Lam64c1b492013-07-12 13:56:44 +05303958 vos_mem_set(&filter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003959 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, &filter);
3960 if(HAL_STATUS_SUCCESS(status))
3961 {
3962 tANI_BOOLEAN fMatch = csrMatchBSS(pMac, pSirBssDesc, &filter, NULL, NULL, NULL, NULL);
3963 //Free the resource first
3964 csrFreeScanFilter( pMac, &filter );
3965 if(fMatch)
3966 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003967 smsLog(pMac, LOGW, " Matching roam profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07003968 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
3969 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
3970 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3971 break;
3972 }
3973 }
3974 }
3975 else if( csrIsConnStateConnected(pMac, i))
3976 {
3977 //Reach here only when the currention is base on no profile.
3978 //User doesn't give profile and just connect to anything.
3979 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pSirBssDesc, pIesLocal))
3980 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003981 smsLog(pMac, LOGW, " Matching connect profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07003982 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
3983 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
3984 //Tush
3985 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3986 if(csrIsBssidMatch(pMac, (tCsrBssid *)&pSirBssDesc->bssId,
3987 &pSession->connectedProfile.bssid))
3988 {
3989 //AP changed the 11d info on the fly, modify cfg
3990 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3991 fRet = eANI_BOOLEAN_TRUE;
3992 }
3993 break;
3994 }
3995 }
3996 } //valid session
3997 } //for
3998 if ( i == CSR_ROAM_SESSION_MAX )
3999 {
4000 //Check whether we can use this country's 11d information
4001 if( !pMac->roam.configParam.fEnforceDefaultDomain )
4002 {
4003 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
4004 }
4005 else
4006 {
4007 VOS_ASSERT( pMac->scan.domainIdCurrent == pMac->scan.domainIdDefault );
4008 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
4009 pMac, pIesLocal->Country.country, &domainId )) &&
4010 ( domainId == pMac->scan.domainIdCurrent ) )
4011 {
4012 //Two countries in the same domain
4013 }
4014 }
4015 }
4016 }
4017 else //Tush
4018 {
4019 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_TRUE;
4020 }
4021
4022 //In case that some channels in 5GHz have the same channel number as 2.4GHz (<= 14)
4023 if(CSR_IS_CHANNEL_5GHZ(pSirBssDesc->channelId))
4024 {
4025 tANI_U8 iC;
4026 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
4027
4028 for(iC = 0; iC < pIesLocal->Country.num_triplets; iC++)
4029 {
4030 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[iC].firstChanNum))
4031 {
4032 pMacChnSet[iC].firstChanNum += 200; //*** Where is this 200 defined?
4033 }
4034 }
4035 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004036 smsLog(pMac, LOG3, FL(" %d sets each one is %d"), pIesLocal->Country.num_triplets, sizeof(tSirMacChanInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07004037 // save the channel/power information from the Channel IE.
4038 //sizeof(tSirMacChanInfo) has to be 3
Jeff Johnsone7245742012-09-05 17:12:55 -07004039 if (eHAL_STATUS_SUCCESS != csrSaveToChannelPower2G_5G( pMac, pIesLocal->Country.num_triplets * sizeof(tSirMacChanInfo),
4040 (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]) ))
4041 {
4042 fRet = eANI_BOOLEAN_FALSE;
Kiet Lamb537cfb2013-11-07 12:56:49 +05304043 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004044 }
4045
Jeff Johnson295189b2012-06-20 16:38:30 -07004046 // set the indicator of the channel where the country IE was found...
4047 pMac->scan.channelOf11dInfo = pSirBssDesc->channelId;
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004048 csrGetRegulatoryDomainForCountry(pMac, pIesLocal->Country.country, &domainId );
4049 // Checking for Domain Id change
4050 if ( domainId != pMac->scan.domainIdCurrent )
4051 {
4052 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304053 palCopyMemory( pMac->hHdd, pMac->scan.countryCode11d, pIesLocal->Country.country,
4054 sizeof( pMac->scan.countryCode11d ) );
4055 csrSetCfgCountryCode(pMac, pIesLocal->Country.country);
4056 WDA_SetRegDomain(pMac, domainId);
4057 pMac->scan.domainIdCurrent = domainId;
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05304058 // Check whether AP provided the 2.4GHZ list or 5GHZ list
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004059 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[0].firstChanNum))
4060 {
4061 // AP Provided the 2.4 Channels, Update the 5GHz channels from nv.bin
4062 csrGet5GChannels(pMac );
4063 }
4064 else
4065 {
4066 // AP Provided the 5G Channels, Update the 2.4GHZ channel list from nv.bin
4067 csrGet24GChannels(pMac );
4068 }
4069 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004070 // Populate both band channel lists based on what we found in the country information...
4071 csrSetOppositeBandChannelInfo( pMac );
4072 bMaxNumChn = WNI_CFG_VALID_CHANNEL_LIST_LEN;
4073 // construct 2GHz channel list first
4074 csrConstructCurrentValidChannelList( pMac, &pMac->scan.channelPowerInfoList24, pMac->scan.channels11d.channelList,
4075 bMaxNumChn, &Num2GChannels );
4076 // construct 5GHz channel list now
4077 if(bMaxNumChn > Num2GChannels)
4078 {
4079 csrConstructCurrentValidChannelList( pMac, &pMac->scan.channelPowerInfoList5G, pMac->scan.channels11d.channelList + Num2GChannels,
4080 bMaxNumChn - Num2GChannels,
4081 &pMac->scan.channels11d.numChannels );
4082 }
4083
4084 pMac->scan.channels11d.numChannels += Num2GChannels;
4085 fRet = eANI_BOOLEAN_TRUE;
4086
4087 } while( 0 );
4088
4089 if( !pIes && pIesLocal )
4090 {
4091 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05304092 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07004093 }
4094
4095 return( fRet );
4096}
4097
4098
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004099static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004100{
4101 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4102 // will set this to the channel where an .11d beacon is seen
4103 pMac->scan.channelOf11dInfo = 0;
4104 // if we get any ambiguous .11d information then this will be set to TRUE
4105 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4106 //Tush
4107 // if we get any ambiguous .11d information, then this will be set to TRUE
4108 // only if the applied 11d info could be found in one of the scan results
4109 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4110 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004111 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004112
4113 // Now check if we gathered any domain/country specific information
4114 // If so, we should update channel list and apply Tx power settings
Jeff Johnsone7245742012-09-05 17:12:55 -07004115 if( csrIs11dSupported(pMac) )
4116 {
4117 csrApplyCountryInformation( pMac, FALSE );
4118 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004119}
4120
4121
4122void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4123{
4124 switch (pCommand->u.scanCmd.reason)
4125 {
4126 case eCsrScanSetBGScanParam:
4127 case eCsrScanAbortBgScan:
4128 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4129 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304130 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004131 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4132 }
4133 break;
4134 case eCsrScanBGScanAbort:
4135 case eCsrScanBGScanEnable:
4136 case eCsrScanGetScanChnInfo:
4137 break;
4138 case eCsrScanAbortNormalScan:
4139 default:
4140 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4141 break;
4142 }
4143 if(pCommand->u.scanCmd.pToRoamProfile)
4144 {
4145 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05304146 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004147 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304148 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004149}
4150
4151
4152tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
4153{
4154 tANI_U32 index11dChannels, index;
4155 tANI_U32 indexCurrentChannels;
4156 tANI_BOOLEAN fChannelAlreadyScanned;
4157 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4158
4159 *pcChannels = 0;
4160 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4161 {
4162 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4163 {
4164 //Find the channel index where we found the 11d info
4165 for(index = 0; index < len; index++)
4166 {
4167 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4168 break;
4169 }
4170 //check whether we found the channel index
4171 if(index < len)
4172 {
4173 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4174 // NOT in the current channel list. This gives us a list of the new channels that have not been
4175 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4176 // initially.
4177 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4178 {
4179 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4180
4181 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4182 {
4183 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4184 {
4185 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4186 break;
4187 }
4188 }
4189
4190 if ( !fChannelAlreadyScanned )
4191 {
4192 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4193 ( *pcChannels )++;
4194 }
4195 }
4196 }
4197 }//GetCFG
4198 }
4199 return( *pcChannels );
4200}
4201
4202
4203eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4204{
4205 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4206
4207 switch( pCommand->u.scanCmd.reason )
4208 {
4209 case eCsrScan11d1:
4210 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4211 break;
4212 case eCsrScan11d2:
4213 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4214 break;
4215 case eCsrScan11dDone:
4216 NextCommand = eCsrNext11dScanComplete;
4217 break;
4218 case eCsrScanLostLink1:
4219 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4220 break;
4221 case eCsrScanLostLink2:
4222 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4223 break;
4224 case eCsrScanLostLink3:
4225 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4226 break;
4227 case eCsrScanForSsid:
4228 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4229 break;
4230 case eCsrScanForCapsChange:
4231 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4232 break;
4233 case eCsrScanIdleScan:
4234 NextCommand = eCsrNextIdleScanComplete;
4235 break;
4236 default:
4237 NextCommand = eCsrNextScanNothing;
4238 break;
4239 }
4240 return( NextCommand );
4241}
4242
4243
4244//Return whether the pCommand is finished.
4245tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4246{
4247 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4248
4249 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004250 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004251 pCommand->u.scanCmd.reason = eCsrScan11d2;
4252 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4253 {
4254 fRet = eANI_BOOLEAN_FALSE;
4255 }
4256
4257 return (fRet);
4258}
4259
4260
4261tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4262{
4263 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4264 tANI_U8 *pChannels;
4265 tANI_U8 cChannels;
4266
Kiet Lam64c1b492013-07-12 13:56:44 +05304267 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
4268 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07004269 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304270 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004271 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4272 {
4273 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4274 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4275 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304276 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07004277 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004278 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304279 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
4280 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07004281 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304282 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
4283 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004284 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4285 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4286 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4287 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4288 {
4289 //Reuse the same command buffer
4290 fRet = eANI_BOOLEAN_FALSE;
4291 }
4292 }
4293 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304294 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004295 }
4296
4297 return (fRet);
4298}
4299
4300//Return whether the command should be removed
4301tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
4302{
4303 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4304 tListElem *pEntry;
4305 tSmeCmd *pCommand;
4306 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4307 tANI_BOOLEAN fSuccess;
4308
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304309 if (pMac->fScanOffload)
4310 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
4311 else
4312 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004313
4314 if ( pEntry )
4315 {
4316 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4317
4318 // If the head of the queue is Active and it is a SCAN command, remove
4319 // and put this on the Free queue.
4320 if ( eSmeCommandScan == pCommand->command )
4321 {
4322 tANI_U32 sessionId = pCommand->sessionId;
4323
4324 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
4325 {
4326 fSuccess = eANI_BOOLEAN_FALSE;
4327 }
4328 else
4329 {
4330 //pMac->scan.tempScanResults is not empty meaning the scan found something
4331 //This check only valid here because csrSaveScanresults is not yet called
4332 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
4333 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004334 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07004335
4336#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4337 {
4338 vos_log_scan_pkt_type *pScanLog = NULL;
4339 tScanResultHandle hScanResult;
4340 tCsrScanResultInfo *pScanResult;
4341 tDot11fBeaconIEs *pIes;
4342 int n = 0, c = 0;
4343
4344 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
4345 if(pScanLog)
4346 {
4347 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4348 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4349 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4350 {
4351 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
4352 }
4353 else
4354 {
4355 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
4356 {
4357 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
4358 }
4359 else
4360 {
4361 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
4362 }
4363 }
4364 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
4365 {
4366 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
4367 {
4368 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
4369 {
4370 if( n < VOS_LOG_MAX_NUM_BSSID )
4371 {
4372 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
4373 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004374 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004375 break;
4376 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304377 vos_mem_copy(pScanLog->bssid[n],
4378 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07004379 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
4380 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304381 vos_mem_copy(pScanLog->ssid[n],
4382 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07004383 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304384 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004385 n++;
4386 }
4387 c++;
4388 }
4389 pScanLog->numSsid = (v_U8_t)n;
4390 pScanLog->totalSsid = (v_U8_t)c;
4391 csrScanResultPurge(pMac, hScanResult);
4392 }
4393 }
4394 else
4395 {
4396 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
4397 }
4398 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
4399 }
4400 }
4401#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4402
4403 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
4404 //We reuse the command here instead reissue a new command
4405 switch(NextCommand)
4406 {
4407 case eCsrNext11dScan1Success:
4408 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004409 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004410 // if we found country information, no need to continue scanning further, bail out
4411 fRemoveCommand = eANI_BOOLEAN_TRUE;
4412 NextCommand = eCsrNext11dScanComplete;
4413 break;
4414 case eCsrNext11dScan1Failure:
4415 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
4416 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
4417 //we clear the "old" 11d info and give it once more chance
4418 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
4419 if(fRemoveCommand)
4420 {
4421 NextCommand = eCsrNext11dScanComplete;
4422 }
4423 break;
4424 case eCsrNextLostLinkScan1Success:
4425 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
4426 {
4427 csrScanHandleFailedLostlink1(pMac, sessionId);
4428 }
4429 break;
4430 case eCsrNextLostLinkScan2Success:
4431 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
4432 {
4433 csrScanHandleFailedLostlink2(pMac, sessionId);
4434 }
4435 break;
4436 case eCsrNextLostLinkScan3Success:
4437 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
4438 {
4439 csrScanHandleFailedLostlink3(pMac, sessionId);
4440 }
4441 break;
4442 case eCsrNextLostLinkScan1Failed:
4443 csrScanHandleFailedLostlink1(pMac, sessionId);
4444 break;
4445 case eCsrNextLostLinkScan2Failed:
4446 csrScanHandleFailedLostlink2(pMac, sessionId);
4447 break;
4448 case eCsrNextLostLinkScan3Failed:
4449 csrScanHandleFailedLostlink3(pMac, sessionId);
4450 break;
4451 case eCsrNexteScanForSsidSuccess:
4452 csrScanHandleSearchForSSID(pMac, pCommand);
4453 break;
4454 case eCsrNexteScanForSsidFailure:
4455 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
4456 break;
4457 case eCsrNextIdleScanComplete:
4458 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
4459 break;
4460 case eCsrNextCapChangeScanComplete:
4461 csrScanHandleCapChangeScanComplete(pMac, sessionId);
4462 break;
4463 default:
4464
4465 break;
4466 }
4467 }
4468 else
4469 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004470 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004471 fRemoveCommand = eANI_BOOLEAN_FALSE;
4472 }
4473 }
4474 else
4475 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004476 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004477 fRemoveCommand = eANI_BOOLEAN_FALSE;
4478 }
4479
4480 return( fRemoveCommand );
4481}
4482
4483
4484
4485static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
4486 tSirBssDescription *pSirBssDescr,
4487 tDot11fBeaconIEs *pIes)
4488{
4489 tListElem *pEntry;
4490 tCsrScanResult *pCsrBssDescription;
4491
4492 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
4493 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
4494 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
4495 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
4496 while( pEntry )
4497 {
4498 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4499
4500 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
4501 // matches
4502
4503 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004504 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004505 {
4506 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
4507 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
4508
4509 // Remove the 'old' entry from the list....
4510 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
4511 {
4512 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
4513 // we need to free the memory associated with this node
4514 csrFreeScanResultEntry( pMac, pCsrBssDescription );
4515 }
4516
4517 // If we found a match, we can stop looking through the list.
4518 break;
4519 }
4520
4521 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
4522 }
4523}
4524
4525
4526
4527//Caller allocated memory pfNewBssForConn to return whether new candidate for
4528//current connection is found. Cannot be NULL
4529tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
4530 tSirBssDescription *pBSSDescription,
4531 tDot11fBeaconIEs *pIes)
4532{
4533 tCsrScanResult *pCsrBssDescription = NULL;
4534 tANI_U32 cbBSSDesc;
4535 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07004536
4537 // figure out how big the BSS description is (the BSSDesc->length does NOT
4538 // include the size of the length field itself).
4539 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
4540
4541 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
4542
Kiet Lam64c1b492013-07-12 13:56:44 +05304543 pCsrBssDescription = vos_mem_malloc(cbAllocated);
4544 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07004545 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304546 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004547 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05304548 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07004549 //Save SSID separately for later use
4550 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
4551 {
4552 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07004553 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07004554 if (len > SIR_MAC_MAX_SSID_LENGTH)
4555 {
4556 // truncate to fit in our struct
4557 len = SIR_MAC_MAX_SSID_LENGTH;
4558 }
4559 pCsrBssDescription->Result.ssId.length = len;
4560 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05304561 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07004562 }
4563 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
4564 }
4565
4566 return( pCsrBssDescription );
4567}
4568
4569
4570
4571
4572tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004573 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07004574{
4575 tANI_BOOLEAN fMatch = FALSE;
4576 tSirMacCapabilityInfo *pCap1, *pCap2;
4577 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004578 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07004579
4580 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
4581 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
4582 if(pCap1->ess == pCap2->ess)
4583 {
4584 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07004585 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004586 (fForced || (pSirBssDesc1->channelId == pSirBssDesc2->channelId)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004587 {
4588 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004589 // Check for SSID match, if exists
4590 do
4591 {
4592 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4593 {
4594 break;
4595 }
4596 if( NULL == pIesTemp )
4597 {
4598 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4599 {
4600 break;
4601 }
4602 }
4603 if(pIes1->SSID.present && pIesTemp->SSID.present)
4604 {
4605 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4606 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4607 }
4608 }while(0);
4609
Jeff Johnson295189b2012-06-20 16:38:30 -07004610 }
4611 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
4612 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004613
4614 do
4615 {
4616 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4617 {
4618 break;
4619 }
4620 if( NULL == pIesTemp )
4621 {
4622 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4623 {
4624 break;
4625 }
4626 }
4627 //Same channel cannot have same SSID for different IBSS
4628 if(pIes1->SSID.present && pIesTemp->SSID.present)
4629 {
4630 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4631 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4632 }
4633 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004634 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004635 /* In case of P2P devices, ess and ibss will be set to zero */
4636 else if (!pCap1->ess &&
4637 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
4638 {
4639 fMatch = TRUE;
4640 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004641 }
4642
4643 if(pIes1)
4644 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304645 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07004646 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004647
4648 if( (NULL == pIes2) && pIesTemp )
4649 {
4650 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05304651 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07004652 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004653
4654 return( fMatch );
4655}
4656
4657
4658tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
4659{
4660 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
4661}
4662
4663
4664//to check whether the BSS matches the dot11Mode
4665static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
4666 tDot11fBeaconIEs *pIes)
4667{
4668 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
4669 eCsrPhyMode phyMode;
4670
4671 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
4672 {
4673 switch(pMac->roam.configParam.phyMode)
4674 {
4675 case eCSR_DOT11_MODE_11b:
4676 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4677 break;
4678 case eCSR_DOT11_MODE_11g:
4679 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4680 break;
4681 case eCSR_DOT11_MODE_11g_ONLY:
4682 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
4683 break;
4684 case eCSR_DOT11_MODE_11a:
4685 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
4686 break;
4687 case eCSR_DOT11_MODE_11n_ONLY:
4688 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4689 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004690
4691#ifdef WLAN_FEATURE_11AC
4692 case eCSR_DOT11_MODE_11ac_ONLY:
4693 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4694 break;
4695#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004696 case eCSR_DOT11_MODE_11b_ONLY:
4697 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
4698 break;
4699 case eCSR_DOT11_MODE_11a_ONLY:
4700 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
4701 break;
4702 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07004703#ifdef WLAN_FEATURE_11AC
4704 case eCSR_DOT11_MODE_11ac:
4705#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004706 case eCSR_DOT11_MODE_TAURUS:
4707 default:
4708 fAllowed = eANI_BOOLEAN_TRUE;
4709 break;
4710 }
4711 }
4712
4713 return (fAllowed);
4714}
4715
4716
4717
4718//Return pIes to caller for future use when returning TRUE.
4719static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
4720 tANI_U8 numChn, tSirBssDescription *pBssDesc,
4721 tDot11fBeaconIEs **ppIes )
4722{
4723 tANI_BOOLEAN fValidChannel = FALSE;
4724 tDot11fBeaconIEs *pIes = NULL;
4725 tANI_U8 index;
4726
4727 for( index = 0; index < numChn; index++ )
4728 {
4729 // This check relies on the fact that a single BSS description is returned in each
4730 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
4731 // to this model when we ran with a large number of APs. If this were to change, then
4732 // this check would have to mess with removing the bssDescription from somewhere in an
4733 // arbitrary index in the bssDescription array.
4734 if ( pChannels[ index ] == pBssDesc->channelId )
4735 {
4736 fValidChannel = TRUE;
4737 break;
4738 }
4739 }
4740 *ppIes = NULL;
4741 if(fValidChannel)
4742 {
4743 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
4744 {
4745 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
4746 if( fValidChannel )
4747 {
4748 *ppIes = pIes;
4749 }
4750 else
4751 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304752 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004753 }
4754 }
4755 else
4756 {
4757 fValidChannel = FALSE;
4758 }
4759 }
4760
4761 return( fValidChannel );
4762}
4763
4764
4765//Return whether last scan result is received
4766static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
4767 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
4768{
4769 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
4770 tDot11fBeaconIEs *pIes = NULL;
4771 tANI_U32 cbParsed;
4772 tSirBssDescription *pSirBssDescription;
4773 tANI_U32 cbBssDesc;
4774 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
4775 + sizeof(tSirBssDescription); //We need at least one CB
4776
4777 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
4778 // is returned when the scan could not find anything. so if we get scan failure return that
4779 // the scan response is invalid. Also check the lenght in the scan result for valid scan
4780 // BssDescriptions....
4781 do
4782 {
4783 if ( ( cbScanResult <= pScanRsp->length ) &&
4784 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
4785 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
4786 {
4787 tANI_U8 *pChannelList = NULL;
4788 tANI_U8 cChannels = 0;
4789
4790 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004791#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4792 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
4793 {
4794 pChannelList = NULL;
4795 cChannels = 0;
4796 }
4797 else
4798#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004799 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
4800 {
4801 //eCsrScanSetBGScanParam uses different structure
4802 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
4803
4804 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
4805 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
4806 }
4807 else
4808 {
4809 //the rest use generic scan request
4810 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
4811 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
4812 }
4813
4814 // if the scan result is not on one of the channels in the Valid channel list, then it
4815 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
4816 // let's drop the scan result.
4817 //
4818 // The other situation is where the scan request is for a scan on a particular channel set
4819 // and the scan result is from a
4820
4821 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
4822 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
4823 // as the valid channels.
4824 if ( 0 == cChannels )
4825 {
4826 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4827
4828 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4829 {
4830 pChannelList = pMac->roam.validChannelList;
4831 cChannels = (tANI_U8)len;
4832 }
4833 else
4834 {
4835 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004836 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07004837 break;
4838 }
4839 }
4840
4841 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
4842 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
4843 pSirBssDescription = pScanRsp->bssDescription;
4844 while( cbParsed < pScanRsp->length )
4845 {
4846 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
4847 {
4848 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
4849 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
4850 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
4851 {
4852 if( csrIs11dSupported( pMac) )
4853 {
4854 //Check whether the BSS is acceptable base on 11d info and our configs.
4855 if( csrMatchCountryCode( pMac, NULL, pIes ) )
4856 {
4857 //Double check whether the channel is acceptable by us.
4858 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
4859 {
4860 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4861 }
4862 }
4863 }
4864 else
4865 {
4866 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4867 }
4868 }
4869 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05304870 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004871 }
4872 // skip over the BSS description to the next one...
4873 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
4874
4875 cbParsed += cbBssDesc;
4876 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
4877
4878 } //while
4879 }
4880 else
4881 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004882 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08004883 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004884 //HO bg scan/probe failed no need to try autonomously
4885 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4886 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004887#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4888 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
4889#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004890 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4891 {
4892 fRemoveCommand = eANI_BOOLEAN_TRUE;
4893 }
4894 }
4895 }while(0);
4896 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4897 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004898 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 -07004899 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
4900 fRet = eANI_BOOLEAN_TRUE;
4901 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4902 if(pfRemoveCommand)
4903 {
4904 *pfRemoveCommand = fRemoveCommand;
4905 }
4906
4907#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304908 if (pMac->fScanOffload)
4909 return fRet;
4910
Jeff Johnson295189b2012-06-20 16:38:30 -07004911 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
4912 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004913 /* Pending scan commands in the list because the previous scan command
4914 * was split into a scan command on one channel + a scan command for all
4915 * remaining channels.
4916 *
4917 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08004918 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304919 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08004920 * active and if the scan is a BG scan triggered by LFR (OR)
4921 * any scan if LFR is in the middle of a BG scan. Splitting
4922 * the scan is delaying the time it takes for LFR to find
4923 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004924 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304925 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08004926#ifdef FEATURE_WLAN_LFR
4927 (csrIsConcurrentInfraConnected(pMac) ||
4928 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304929 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08004930 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
4931#endif
4932 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304933 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004934 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004935 /* if active connected sessions present then continue to split scan
4936 * with specified interval between consecutive scans */
4937 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05304938 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
4939 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004940 } else {
4941 /* if no connected sessions present then initiate next scan command immediately */
4942 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05304943 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004944 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004945 }
4946#endif
4947 return (fRet);
4948}
4949
4950
4951tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
4952{
4953 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05304954 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
4955 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07004956
4957 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
4958 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
4959 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
4960}
4961
4962
4963eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
4964{
4965 eHalStatus status = eHAL_STATUS_SUCCESS;
4966 tListElem *pEntry;
4967 tSmeCmd *pCommand;
4968 eCsrScanStatus scanStatus;
4969 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
4970 tSmeGetScanChnRsp *pScanChnInfo;
4971 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4972 eCsrScanReason reason = eCsrScanOther;
4973
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304974 if (pMac->fScanOffload)
4975 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
4976 LL_ACCESS_LOCK);
4977 else
4978 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004979
4980 if ( pEntry )
4981 {
4982 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4983 if ( eSmeCommandScan == pCommand->command )
4984 {
4985 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
4986 reason = pCommand->u.scanCmd.reason;
4987 switch(pCommand->u.scanCmd.reason)
4988 {
4989 case eCsrScanAbortBgScan:
4990 case eCsrScanAbortNormalScan:
4991 case eCsrScanBGScanAbort:
4992 case eCsrScanBGScanEnable:
4993 break;
4994 case eCsrScanGetScanChnInfo:
4995 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004996 /*
4997 * status code not available in tSmeGetScanChnRsp, so
4998 * by default considereing it to be success
4999 */
5000 scanStatus = eSIR_SME_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07005001 csrScanAgeResults(pMac, pScanChnInfo);
5002 break;
5003 case eCsrScanForCapsChange:
5004 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5005 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005006 case eCsrScanP2PFindPeer:
5007 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) && (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5008 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5009 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005010 case eCsrScanSetBGScanParam:
5011 default:
5012 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5013 {
5014 //Not to get channel info if the scan is not a wildcard scan because
5015 //it may cause scan results got aged out incorrectly.
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005016 if( csrScanIsWildCardScan( pMac, pCommand ) && (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
5017#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5018 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5019#endif
5020 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005021 {
5022 //Get the list of channels scanned
Jeff Johnson32d95a32012-09-10 13:15:23 -07005023 if( pCommand->u.scanCmd.reason != eCsrScanUserRequest)
5024 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305025 csrScanGetScanChnInfo(pMac, pCommand->sessionId,
5026 NULL, NULL);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005027 }
5028 else
5029 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305030 csrScanGetScanChnInfo(pMac,
5031 pCommand->sessionId,
5032 pCommand->u.scanCmd.pContext,
5033 pCommand->u.scanCmd.callback);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005034 pCommand->u.scanCmd.callback = NULL;
5035 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005036 }
5037 }
5038 break;
5039 }//switch
5040 if(fRemoveCommand)
5041 {
5042
5043 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5044
Srikant Kuppa866893f2012-12-27 17:28:14 -08005045 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005046 smeProcessPendingQueue( pMac );
5047 }
5048 else
5049 {
5050 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5051 status = eHAL_STATUS_FAILURE;
5052 }
5053 }
5054 else
5055 {
5056 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5057 status = eHAL_STATUS_FAILURE;
5058 }
5059
5060 return (status);
5061}
5062
5063
5064
5065
5066tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5067{
5068 tListElem *pEntry;
5069 tCsrScanResult *pResult;
5070 tCsrScanResultInfo *pRet = NULL;
5071 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5072
5073 if(pResultList)
5074 {
5075 csrLLLock(&pResultList->List);
5076 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5077 if(pEntry)
5078 {
5079 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5080 pRet = &pResult->Result;
5081 }
5082 pResultList->pCurEntry = pEntry;
5083 csrLLUnlock(&pResultList->List);
5084 }
5085
5086 return pRet;
5087}
5088
5089
5090tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5091{
5092 tListElem *pEntry = NULL;
5093 tCsrScanResult *pResult = NULL;
5094 tCsrScanResultInfo *pRet = NULL;
5095 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5096
5097 if(pResultList)
5098 {
5099 csrLLLock(&pResultList->List);
5100 if(NULL == pResultList->pCurEntry)
5101 {
5102 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5103 }
5104 else
5105 {
5106 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5107 }
5108 if(pEntry)
5109 {
5110 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5111 pRet = &pResult->Result;
5112 }
5113 pResultList->pCurEntry = pEntry;
5114 csrLLUnlock(&pResultList->List);
5115 }
5116
5117 return pRet;
5118}
5119
5120
5121//This function moves the first BSS that matches the bssid to the head of the result
5122eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5123{
5124 eHalStatus status = eHAL_STATUS_FAILURE;
5125 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5126 tCsrScanResult *pResult = NULL;
5127 tListElem *pEntry = NULL;
5128
5129 if(pResultList && bssid)
5130 {
5131 csrLLLock(&pResultList->List);
5132 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5133 while(pEntry)
5134 {
5135 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05305136 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005137 {
5138 status = eHAL_STATUS_SUCCESS;
5139 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5140 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5141 break;
5142 }
5143 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5144 }
5145 csrLLUnlock(&pResultList->List);
5146 }
5147
5148 return (status);
5149}
5150
5151
5152//Remove the BSS if possible.
5153//Return -- TRUE == the BSS is remove. False == Fail to remove it
5154//This function is called when list lock is held. Be caution what functions it can call.
5155tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5156{
5157 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5158 tANI_U32 i;
5159 tCsrRoamSession *pSession;
5160
5161 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5162 {
5163 if( CSR_IS_SESSION_VALID( pMac, i ) )
5164 {
5165 pSession = CSR_GET_SESSION( pMac, i );
5166 //Not to remove the BSS we are connected to.
5167 if(csrIsConnStateDisconnected(pMac, i) || (NULL == pSession->pConnectBssDesc) ||
5168 (!csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005169 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005170 )
5171 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005172 smsLog(pMac, LOGW, "Aging out BSS %02X-%02X-%02X-%02X-%02X-%02X Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005173 pResult->Result.BssDescriptor.bssId[0],
5174 pResult->Result.BssDescriptor.bssId[1],
5175 pResult->Result.BssDescriptor.bssId[2],
5176 pResult->Result.BssDescriptor.bssId[3],
5177 pResult->Result.BssDescriptor.bssId[4],
5178 pResult->Result.BssDescriptor.bssId[5],
5179 pResult->Result.BssDescriptor.channelId);
5180 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5181 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5182 {
5183 csrFreeScanResultEntry(pMac, pResult);
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005184 fRet = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005185 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005186 break;
5187 }
5188 } //valid session
5189 } //for
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005190 if( CSR_ROAM_SESSION_MAX == i && fRet != eANI_BOOLEAN_TRUE )
Jeff Johnson295189b2012-06-20 16:38:30 -07005191 {
5192 //reset the counter so this won't hapeen too soon
5193 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
5194 pResult->Result.BssDescriptor.nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
5195 }
5196
5197 return (fRet);
5198}
5199
5200
5201eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5202{
5203 eHalStatus status = eHAL_STATUS_SUCCESS;
5204 tListElem *pEntry, *tmpEntry;
5205 tCsrScanResult *pResult;
5206 tLimScanChn *pChnInfo;
5207 tANI_U8 i;
5208
5209 csrLLLock(&pMac->scan.scanResultList);
5210 for(i = 0; i < pScanChnInfo->numChn; i++)
5211 {
5212 pChnInfo = &pScanChnInfo->scanChn[i];
5213 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5214 while( pEntry )
5215 {
5216 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5217 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5218 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
5219 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005220 if(pResult->AgingCount <= 0)
5221 {
5222 smsLog(pMac, LOGW, " age out due to ref count");
5223 csrScanAgeOutBss(pMac, pResult);
5224 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07005225 else
5226 {
5227 pResult->AgingCount--;
5228 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005229 }
5230 pEntry = tmpEntry;
5231 }
5232 }
5233 csrLLUnlock(&pMac->scan.scanResultList);
5234
5235 return (status);
5236}
5237
5238
5239eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
5240 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
5241{
5242 eHalStatus status = eHAL_STATUS_SUCCESS;
5243 tSirSmeScanReq *pMsg;
5244 tANI_U16 msgLen;
5245 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
5246 tSirScanType scanType = pScanReq->scanType;
5247 tANI_U32 minChnTime; //in units of milliseconds
5248 tANI_U32 maxChnTime; //in units of milliseconds
5249 tANI_U32 i;
5250 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
5251 tANI_U8 *pSelfMac = NULL;
5252
5253 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5254 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
5255 ( pScanReq->uIEFieldLen ) ;
5256
Kiet Lam64c1b492013-07-12 13:56:44 +05305257 pMsg = vos_mem_malloc(msgLen);
5258 if ( NULL == pMsg )
5259 status = eHAL_STATUS_FAILURE;
5260 else
5261 status = eHAL_STATUS_SUCCESS;
5262 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005263 {
5264 do
5265 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305266 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005267 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5268 pMsg->length = pal_cpu_to_be16(msgLen);
5269 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05305270 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
5271 {
5272 pMsg->sessionId = sessionId;
5273 }
5274 else
5275 {
5276 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
5277 request on first available session */
5278 pMsg->sessionId = 0;
5279 }
5280
Jeff Johnson295189b2012-06-20 16:38:30 -07005281 pMsg->transactionId = 0;
5282 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
5283 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
5284
5285 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
5286 {
5287 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
5288 }
5289 else
5290 {
5291 // Since we don't have session for the scanning, we find a valid session. In case we fail to
5292 // do so, get the WNI_CFG_STA_ID
5293 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5294 {
5295 if( CSR_IS_SESSION_VALID( pMac, i ) )
5296 {
5297 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
5298 break;
5299 }
5300 }
5301 if( CSR_ROAM_SESSION_MAX == i )
5302 {
5303 tANI_U32 len = WNI_CFG_BSSID_LEN;
5304 pSelfMac = selfMacAddr;
5305 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
5306 if( !HAL_STATUS_SUCCESS( status ) ||
5307 ( len < WNI_CFG_BSSID_LEN ) )
5308 {
5309 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
5310 //Force failed status
5311 status = eHAL_STATUS_FAILURE;
5312 break;
5313 }
5314 }
5315 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305316 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07005317
5318 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05305319 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
5320 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005321 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305322 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07005323 }
5324 else
5325 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305326 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07005327 }
5328 minChnTime = pScanReq->minChnTime;
5329 maxChnTime = pScanReq->maxChnTime;
5330
5331 //Verify the scan type first, if the scan is active scan, we need to make sure we
5332 //are allowed to do so.
5333 /* if 11d is enabled & we don't see any beacon around, scan type falls
5334 back to passive. But in BT AMP STA mode we need to send out a
5335 directed probe*/
5336 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
5337 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
5338 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
5339 {
5340 scanType = pMac->scan.curScanType;
5341 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
5342 {
5343 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
5344 {
5345 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
5346 }
5347 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
5348 {
5349 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
5350 }
5351 }
5352 }
5353 pMsg->scanType = pal_cpu_to_be32(scanType);
5354
5355 pMsg->numSsid = (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ? pScanReq->SSIDs.numOfSSIDs :
5356 SIR_SCAN_MAX_NUM_SSID;
5357 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
5358 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005359 for (i = 0; i < pMsg->numSsid; i++)
5360 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305361 vos_mem_copy(&pMsg->ssId[i],
5362 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005363 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005364 }
5365 else
5366 {
5367 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005368 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
5369 {
5370 pMsg->ssId[i].length = 0;
5371 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005372 }
5373
Jeff Johnson295189b2012-06-20 16:38:30 -07005374 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
5375 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08005376 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
5377 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07005378 //hidden SSID option
5379 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
5380 //rest time
5381 //pMsg->restTime = pScanReq->restTime;
5382 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5383 // All the scan results caching will be done by Roaming
5384 // We do not want LIM to do any caching of scan results,
5385 // so delete the LIM cache on all scan requests
5386 pMsg->returnFreshResults = pScanReqParam->freshScan;
5387 //Always ask for unique result
5388 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5389 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
5390 if(pScanReq->ChannelInfo.numOfChannels)
5391 {
5392 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05305393 vos_mem_copy(pMsg->channelList.channelNumber,
5394 pScanReq->ChannelInfo.ChannelList,
5395 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005396 }
5397
5398 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
5399 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5400 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
5401 if(pScanReq->uIEFieldLen != 0)
5402 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305403 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
5404 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07005405 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005406 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005407
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07005408 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
5409 {
5410 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
5411 }
5412
Jeff Johnson295189b2012-06-20 16:38:30 -07005413 }while(0);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005414 smsLog(pMac, LOG1, FL("domainIdCurrent %d scanType %d bssType %d requestType %d numChannels %d "),
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005415 pMac->scan.domainIdCurrent, pMsg->scanType, pMsg->bssType,
5416 pScanReq->requestType, pMsg->channelList.numChannels);
5417
5418 for(i = 0; i < pMsg->channelList.numChannels; i++)
5419 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005420 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005421 }
5422
Jeff Johnson295189b2012-06-20 16:38:30 -07005423 if(HAL_STATUS_SUCCESS(status))
5424 {
5425 status = palSendMBMessage(pMac->hHdd, pMsg);
5426 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005427 else
5428 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005429 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05305430 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07005431 }
5432 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005433 else
5434 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005435 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005436 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005437
5438 return( status );
5439}
5440
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005441eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07005442{
5443 eHalStatus status = eHAL_STATUS_SUCCESS;
5444 tSirSmeScanReq *pMsg;
5445 tANI_U16 msgLen;
5446
5447 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05305448 pMsg = vos_mem_malloc(msgLen);
5449 if ( NULL == pMsg )
5450 status = eHAL_STATUS_FAILURE;
5451 else
Jeff Johnson295189b2012-06-20 16:38:30 -07005452 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305453 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005454 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5455 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005456 pMsg->sessionId = sessionId;
5457 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005458 pMsg->returnFreshResults = pScanReqParam->freshScan;
5459 //Always ask for unique result
5460 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5461 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5462 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005463 if (!HAL_STATUS_SUCCESS(status))
5464 {
5465 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
5466 }
5467
Jeff Johnson295189b2012-06-20 16:38:30 -07005468 }
5469
5470 return( status );
5471}
5472
5473
5474
5475eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5476{
5477 eHalStatus status = eHAL_STATUS_FAILURE;
5478 tScanReqParam scanReq;
5479
5480 do
5481 {
5482 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
5483 scanReq.fUniqueResult = TRUE;
5484 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
5485 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
5486 {
5487 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
5488 }
5489 else
5490 {
5491 // Basically do scan on all channels even for 11D 1st scan case.
5492 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5493 }
5494 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
5495 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
5496 {
5497 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
5498 }
5499
5500#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5501 {
5502 vos_log_scan_pkt_type *pScanLog = NULL;
5503
5504 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5505 if(pScanLog)
5506 {
5507 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5508 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
5509 {
5510 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
5511 }
5512 else
5513 {
5514 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
5515 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
5516 {
5517 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
5518 }
5519 else
5520 {
5521 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
5522 }
5523 }
5524 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
5525 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
5526 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5527 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
5528 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305529 vos_mem_copy(pScanLog->channels,
5530 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5531 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07005532 }
5533 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5534 }
5535 }
5536#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5537
5538
5539 status = csrSendMBScanReq(pMac, pCommand->sessionId,
5540 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
5541 }while(0);
5542
5543 return( status );
5544}
5545
5546
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005547eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07005548{
5549 eHalStatus status = eHAL_STATUS_FAILURE;
5550 tScanReqParam scanReq;
5551
5552 do
5553 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005554#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5555 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
5556 {
5557 //to get the LFR candidates from PE cache
5558 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
5559 scanReq.fUniqueResult = TRUE;
5560 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5561 }
5562 else
5563#endif
5564 {
5565 //not a fresh scan
5566 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
5567 scanReq.fUniqueResult = TRUE;
5568 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5569 }
5570 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005571 }while(0);
5572
5573 return (status);
5574}
5575
5576
5577
5578eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5579{
5580 eHalStatus status = eHAL_STATUS_SUCCESS;
5581 tCsrChannelInfo newChannelInfo = {0, NULL};
5582 int i, j;
5583 tANI_U8 *pChannel = NULL;
5584 tANI_U32 len = 0;
5585
5586 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305587 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07005588 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305589 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5590 {
5591 pCommand->u.scanCmd.lastRoamState[i] =
5592 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
5593 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
5594 " reason is %d", pCommand->u.scanCmd.lastRoamState[i],
5595 pCommand->u.scanCmd.reason );
5596 }
5597 }
5598 else
5599 {
5600 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId] =
5601 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
5602 pCommand->sessionId);
5603 smsLog( pMac, LOG3,
5604 "starting SCAN command from %d state.... reason is %d",
5605 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
5606 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07005607 }
5608
5609 switch(pCommand->u.scanCmd.reason)
5610 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005611#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5612 case eCsrScanGetLfrResult:
5613#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005614 case eCsrScanGetResult:
5615 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005616 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005617 break;
5618 case eCsrScanSetBGScanParam:
5619 status = csrProcessSetBGScanParam(pMac, pCommand);
5620 break;
5621 case eCsrScanBGScanAbort:
5622 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
5623 break;
5624 case eCsrScanBGScanEnable:
5625 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
5626 break;
5627 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305628 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07005629 break;
5630 case eCsrScanUserRequest:
5631 if(pMac->roam.configParam.fScanTwice)
5632 {
5633 //We scan 2.4 channel twice
5634 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
5635 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
5636 {
5637 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5638 //allocate twice the channel
5639 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(newChannelInfo.numOfChannels * 2);
5640 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5641 }
5642 else
5643 {
5644 //get the valid channel list to scan all.
5645 len = sizeof(pMac->roam.validChannelList);
5646
5647 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5648 {
5649 //allocate twice the channel
5650 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
5651 pChannel = pMac->roam.validChannelList;
5652 }
5653 }
5654 if(NULL == newChannelInfo.ChannelList)
5655 {
5656 newChannelInfo.numOfChannels = 0;
5657 }
5658 else
5659 {
5660 j = 0;
5661 for(i = 0; i < len; i++)
5662 {
5663 newChannelInfo.ChannelList[j++] = pChannel[i];
5664 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
5665 {
5666 newChannelInfo.ChannelList[j++] = pChannel[i];
5667 }
5668 }
5669 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5670 {
5671 //pChannel points to the channellist from the command, free it.
5672 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07005673 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005674 }
5675 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
5676 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
5677 }
5678 } //if(pMac->roam.configParam.fScanTwice)
5679
5680 status = csrScanChannels(pMac, pCommand);
5681
5682 break;
5683 default:
5684 status = csrScanChannels(pMac, pCommand);
5685 break;
5686 }
5687
5688 if(!HAL_STATUS_SUCCESS(status))
5689 {
5690 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
5691 }
5692
5693 return (status);
5694}
5695
5696
5697eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
5698{
5699 eHalStatus status = eHAL_STATUS_SUCCESS;
5700 tSmeCmd *pCommand = NULL;
5701
5702 if(pScanReq)
5703 {
5704 do
5705 {
5706 pCommand = csrGetCommandBuffer(pMac);
5707 if(!pCommand)
5708 {
5709 status = eHAL_STATUS_RESOURCES;
5710 break;
5711 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305712 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005713 pCommand->command = eSmeCommandScan;
5714 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
5715 pCommand->u.scanCmd.callback = NULL;
5716 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05305717 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07005718 //we have to do the follow
5719 if(pScanReq->ChannelInfo.numOfChannels == 0)
5720 {
5721 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
5722 }
5723 else
5724 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305725 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
5726 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
5727 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07005728 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305729 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5730 pScanReq->ChannelInfo.ChannelList,
5731 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005732 }
5733 else
5734 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005735 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005736 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05305737 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005738 }
5739 }
5740
5741 //scan req for SSID
5742 if(pScanReq->SSID.length)
5743 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305744 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
5745 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07005746 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
5747
5748 }
5749 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
5750 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
5751 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
5752
5753
5754 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5755 if( !HAL_STATUS_SUCCESS( status ) )
5756 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005757 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005758 csrReleaseCommandScan( pMac, pCommand );
5759 break;
5760 }
5761 }while(0);
5762 }
5763
5764 return (status);
5765}
5766
5767eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
5768{
5769 eHalStatus status = eHAL_STATUS_SUCCESS;
5770 tSmeCmd *pCommand = NULL;
5771
5772 do
5773 {
5774 pCommand = csrGetCommandBuffer(pMac);
5775 if(!pCommand)
5776 {
5777 status = eHAL_STATUS_RESOURCES;
5778 break;
5779 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305780 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005781 pCommand->command = eSmeCommandScan;
5782 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
5783 pCommand->u.scanCmd.callback = NULL;
5784 pCommand->u.scanCmd.pContext = NULL;
5785 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5786 if( !HAL_STATUS_SUCCESS( status ) )
5787 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005788 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005789 csrReleaseCommandScan( pMac, pCommand );
5790 break;
5791 }
5792 }while(0);
5793
5794 return (status);
5795}
5796
5797
5798//This will enable the background scan with the non-zero interval
5799eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
5800{
5801 eHalStatus status = eHAL_STATUS_SUCCESS;
5802 tSmeCmd *pCommand = NULL;
5803
5804 if(pMac->roam.configParam.bgScanInterval)
5805 {
5806 do
5807 {
5808 pCommand = csrGetCommandBuffer(pMac);
5809 if(!pCommand)
5810 {
5811 status = eHAL_STATUS_RESOURCES;
5812 break;
5813 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305814 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005815 pCommand->command = eSmeCommandScan;
5816 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
5817 pCommand->u.scanCmd.callback = NULL;
5818 pCommand->u.scanCmd.pContext = NULL;
5819 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5820 if( !HAL_STATUS_SUCCESS( status ) )
5821 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005822 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005823 csrReleaseCommandScan( pMac, pCommand );
5824 break;
5825 }
5826 }while(0);
5827 //BG scan results are reported automatically by PE to SME once the scan is done.
5828 //No need to fetch the results explicitly.
5829 //csrScanStartGetResultTimer(pMac);
5830 csrScanStartResultAgingTimer(pMac);
5831 }
5832 else
5833 {
5834 //We don't have BG scan so stop the aging timer
5835 csrScanStopResultAgingTimer(pMac);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005836 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005837 status = eHAL_STATUS_INVALID_PARAMETER;
5838 }
5839
5840 return (status);
5841}
5842
5843
5844eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
5845{
5846 eHalStatus status = eHAL_STATUS_SUCCESS;
5847 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5848 tANI_U32 index = 0;
5849 tANI_U32 new_index = 0;
5850
5851 do
5852 {
5853 status = csrScanFreeRequest(pMac, pDstReq);
5854 if(HAL_STATUS_SUCCESS(status))
5855 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305856 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08005857 /* Re-initialize the pointers to NULL since we did a copy */
5858 pDstReq->pIEField = NULL;
5859 pDstReq->ChannelInfo.ChannelList = NULL;
5860 pDstReq->SSIDs.SSIDList = NULL;
5861
Jeff Johnson295189b2012-06-20 16:38:30 -07005862 if(pSrcReq->uIEFieldLen == 0)
5863 {
5864 pDstReq->pIEField = NULL;
5865 }
5866 else
5867 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305868 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
5869 if ( NULL == pDstReq->pIEField )
5870 status = eHAL_STATUS_FAILURE;
5871 else
5872 status = eHAL_STATUS_SUCCESS;
5873 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005874 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305875 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField, pSrcReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07005876 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
5877 }
5878 else
5879 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005880 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnson295189b2012-06-20 16:38:30 -07005881 break;
5882 }
5883 }//Allocate memory for IE field
5884 {
5885 if(pSrcReq->ChannelInfo.numOfChannels == 0)
5886 {
5887 pDstReq->ChannelInfo.ChannelList = NULL;
5888 pDstReq->ChannelInfo.numOfChannels = 0;
5889 }
5890 else
5891 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305892 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
5893 pSrcReq->ChannelInfo.numOfChannels
5894 * sizeof(*pDstReq->ChannelInfo.ChannelList));
5895 if ( NULL == pDstReq->ChannelInfo.ChannelList )
5896 status = eHAL_STATUS_FAILURE;
5897 else
5898 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07005899 if(!HAL_STATUS_SUCCESS(status))
5900 {
5901 pDstReq->ChannelInfo.numOfChannels = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005902 smsLog(pMac, LOGE, "No memory for scanning Channel List");
Jeff Johnson295189b2012-06-20 16:38:30 -07005903 break;
5904 }
5905
5906 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
5907 {
5908 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5909 {
5910 pDstReq->ChannelInfo.ChannelList[new_index] =
5911 pSrcReq->ChannelInfo.ChannelList[index];
5912 new_index++;
5913 }
5914 pDstReq->ChannelInfo.numOfChannels = new_index;
5915 }
5916 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
5917 {
5918 new_index = 0;
5919 pMac->roam.numValidChannels = len;
5920 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5921 {
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005922 /* Allow scan on valid channels only.
5923 * If it is p2p scan and valid channel list doesnt contain
5924 * social channels, enforce scan on social channels because
5925 * that is the only way to find p2p peers.
5926 * This can happen only if band is set to 5Ghz mode.
5927 */
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005928 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index])) ||
5929 ((eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType) &&
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005930 CSR_IS_SOCIAL_CHANNEL(pSrcReq->ChannelInfo.ChannelList[index])))
Jeff Johnson295189b2012-06-20 16:38:30 -07005931 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08005932 if( (pSrcReq->skipDfsChnlInP2pSearch &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005933 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08005934#ifdef FEATURE_WLAN_LFR
5935 /*
5936 * If LFR is requesting a contiguous scan
5937 * (i.e. numOfChannels > 1), then ignore
5938 * DFS channels.
5939 * TODO: vos_nv_getChannelEnabledState is returning
5940 * 120, 124 and 128 as non-DFS channels. Hence, the
5941 * use of direct check for channels below.
5942 */
5943 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
5944 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Srinivas Girigowdade697412013-02-14 16:31:48 -08005945 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])))
Srikant Kuppa866893f2012-12-27 17:28:14 -08005946#endif
5947 )
5948 {
5949#ifdef FEATURE_WLAN_LFR
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005950 smsLog(pMac, LOG2,
Srikant Kuppa866893f2012-12-27 17:28:14 -08005951 "%s: reqType=%d, numOfChannels=%d,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005952 " ignoring DFS channel %d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005953 __func__, pSrcReq->requestType,
5954 pSrcReq->ChannelInfo.numOfChannels,
5955 pSrcReq->ChannelInfo.ChannelList[index]);
5956#endif
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005957 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08005958 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005959
Jeff Johnson295189b2012-06-20 16:38:30 -07005960 pDstReq->ChannelInfo.ChannelList[new_index] =
5961 pSrcReq->ChannelInfo.ChannelList[index];
5962 new_index++;
5963 }
5964 }
5965 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08005966#ifdef FEATURE_WLAN_LFR
5967 if ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
5968 (0 == pDstReq->ChannelInfo.numOfChannels))
5969 {
5970 /*
5971 * No valid channels found in the request.
5972 * Only perform scan on the channels passed
5973 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN.
5974 * Passing 0 to LIM will trigger a scan on
5975 * all valid channels which is not desirable.
5976 */
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005977 smsLog(pMac, LOGE, "%s: no valid channels found (request=%d)",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005978 __func__, pSrcReq->requestType);
5979 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5980 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005981 smsLog(pMac, LOGE, "pSrcReq index=%d channel=%d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005982 index, pSrcReq->ChannelInfo.ChannelList[index]);
5983 }
5984 status = eHAL_STATUS_FAILURE;
5985 break;
5986 }
5987#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005988 }
5989 else
5990 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005991 smsLog(pMac, LOGE, "Couldn't get the valid Channel List, keeping requester's list");
Kiet Lam64c1b492013-07-12 13:56:44 +05305992 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
5993 pSrcReq->ChannelInfo.ChannelList,
5994 pSrcReq->ChannelInfo.numOfChannels
5995 * sizeof(*pDstReq->ChannelInfo.ChannelList));
Jeff Johnson295189b2012-06-20 16:38:30 -07005996 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
5997 }
5998 }//Allocate memory for Channel List
5999 }
6000 if(pSrcReq->SSIDs.numOfSSIDs == 0)
6001 {
6002 pDstReq->SSIDs.numOfSSIDs = 0;
6003 pDstReq->SSIDs.SSIDList = NULL;
6004 }
6005 else
6006 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306007 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
6008 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
6009 if ( NULL == pDstReq->SSIDs.SSIDList )
6010 status = eHAL_STATUS_FAILURE;
6011 else
6012 status = eHAL_STATUS_SUCCESS;
6013 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006014 {
6015 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05306016 vos_mem_copy(pDstReq->SSIDs.SSIDList,
6017 pSrcReq->SSIDs.SSIDList,
6018 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006019 }
6020 else
6021 {
6022 pDstReq->SSIDs.numOfSSIDs = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006023 smsLog(pMac, LOGE, "No memory for scanning SSID List");
Jeff Johnson295189b2012-06-20 16:38:30 -07006024 break;
6025 }
6026 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006027 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006028 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006029
6030 }
6031 }while(0);
6032
6033 if(!HAL_STATUS_SUCCESS(status))
6034 {
6035 csrScanFreeRequest(pMac, pDstReq);
6036 }
6037
6038 return (status);
6039}
6040
6041
6042eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6043{
Jeff Johnson295189b2012-06-20 16:38:30 -07006044
6045 if(pReq->ChannelInfo.ChannelList)
6046 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306047 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006048 pReq->ChannelInfo.ChannelList = NULL;
6049 }
6050 pReq->ChannelInfo.numOfChannels = 0;
6051 if(pReq->pIEField)
6052 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306053 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07006054 pReq->pIEField = NULL;
6055 }
6056 pReq->uIEFieldLen = 0;
6057 if(pReq->SSIDs.SSIDList)
6058 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306059 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006060 pReq->SSIDs.SSIDList = NULL;
6061 }
6062 pReq->SSIDs.numOfSSIDs = 0;
6063
Kiet Lam64c1b492013-07-12 13:56:44 +05306064 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006065}
6066
6067
6068void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6069{
6070 if(pCommand->u.scanCmd.callback)
6071 {
6072// sme_ReleaseGlobalLock( &pMac->sme );
6073 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
6074// sme_AcquireGlobalLock( &pMac->sme );
6075 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006076 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006077 }
6078}
6079
6080
6081void csrScanStopTimers(tpAniSirGlobal pMac)
6082{
6083 csrScanStopResultAgingTimer(pMac);
6084 csrScanStopIdleScanTimer(pMac);
6085 csrScanStopGetResultTimer(pMac);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006086 if(0 != pMac->scan.scanResultCfgAgingTime )
6087 {
6088 csrScanStopResultCfgAgingTimer(pMac);
6089 }
6090
Jeff Johnson295189b2012-06-20 16:38:30 -07006091}
6092
6093
6094eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
6095{
6096 eHalStatus status;
6097
6098 if(pMac->scan.fScanEnable)
6099 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306100 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006101 }
6102 else
6103 {
6104 status = eHAL_STATUS_FAILURE;
6105 }
6106
6107 return (status);
6108}
6109
6110
6111eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
6112{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306113 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07006114}
6115
6116
6117void csrScanGetResultTimerHandler(void *pv)
6118{
6119 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6120
6121 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306122
6123 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006124}
6125
6126#ifdef WLAN_AP_STA_CONCURRENCY
6127static void csrStaApConcTimerHandler(void *pv)
6128{
6129 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6130 tListElem *pEntry;
6131 tSmeCmd *pScanCmd;
6132
6133 csrLLLock(&pMac->scan.scanCmdPendingList);
6134
6135 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
6136 {
6137 tCsrScanRequest scanReq;
6138 tSmeCmd *pSendScanCmd = NULL;
6139 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006140 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08006141 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07006142 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
6143 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6144 eHalStatus status;
6145
Jeff Johnson295189b2012-06-20 16:38:30 -07006146 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
6147 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006148
6149 /* if any session is connected and the number of channels to scan is
6150 * greater than 1 then split the scan into multiple scan operations
6151 * on each individual channel else continue to perform scan on all
6152 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006153
6154 /* split scan if number of channels to scan is greater than 1 and
6155 * any one of the following:
6156 * - STA session is connected and the scan is not a P2P search
6157 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08006158 * Do not split scans if no concurrent infra connections are
6159 * active and if the scan is a BG scan triggered by LFR (OR)
6160 * any scan if LFR is in the middle of a BG scan. Splitting
6161 * the scan is delaying the time it takes for LFR to find
6162 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006163 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006164
6165 if((csrIsStaSessionConnected(pMac) &&
6166 !csrIsP2pSessionConnected(pMac)))
6167 {
6168 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
6169 }
6170 else if(csrIsP2pSessionConnected(pMac))
6171 {
6172 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
6173 }
6174
6175 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08006176 ((csrIsStaSessionConnected(pMac) &&
6177#ifdef FEATURE_WLAN_LFR
6178 (csrIsConcurrentInfraConnected(pMac) ||
6179 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
6180 (pMac->roam.neighborRoamInfo.neighborRoamState !=
6181 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
6182#endif
6183 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006184 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07006185 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306186 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006187
6188 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
6189 if (!pSendScanCmd)
6190 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006191 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006192 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6193 return;
6194 }
6195 pSendScanCmd->command = pScanCmd->command;
6196 pSendScanCmd->sessionId = pScanCmd->sessionId;
6197 pSendScanCmd->u.scanCmd.callback = NULL;
6198 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
6199 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
6200 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6201
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07006202 /* First copy all the parameters to local variable of scan request */
6203 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
6204
6205 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006206 if(scanReq.ChannelInfo.ChannelList != NULL)
6207 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306208 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006209 scanReq.ChannelInfo.ChannelList = NULL;
6210 }
6211
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006212 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05306213 vos_mem_copy(&channelToScan[0],
6214 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
6215 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07006216 pChnInfo->ChannelList = &channelToScan[0];
6217
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006218 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006219 {
6220 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08006221 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07006222 }
6223
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006224 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07006225
6226 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
6227 //Modify callers parameters in case of concurrency
6228 scanReq.scanType = eSIR_ACTIVE_SCAN;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07006229 //Use concurrency values for min/maxChnTime.
6230 //We know csrIsAnySessionConnected(pMac) returns TRUE here
6231 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006232
6233 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
6234 if(!HAL_STATUS_SUCCESS(status))
6235 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006236 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006237 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6238 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006239 }
6240 /* Clean the local scan variable */
6241 scanReq.ChannelInfo.ChannelList = NULL;
6242 scanReq.ChannelInfo.numOfChannels = 0;
6243 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006244 }
6245 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006246 {
6247 /* no active connected session present or numChn == 1
6248 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07006249 pSendScanCmd = pScanCmd;
6250 //remove this command from pending list
6251 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
6252 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006253 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006254 }
6255
6256 }
6257 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
6258
6259 }
6260
Jeff Johnson295189b2012-06-20 16:38:30 -07006261 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6262
6263}
6264#endif
6265
6266eHalStatus csrScanStartResultAgingTimer(tpAniSirGlobal pMac)
6267{
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006268 eHalStatus status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006269
6270 if(pMac->scan.fScanEnable)
6271 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306272 status = vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006273 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006274 return (status);
6275}
6276
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006277eHalStatus csrScanStartResultCfgAgingTimer(tpAniSirGlobal pMac)
6278{
6279 eHalStatus status = eHAL_STATUS_FAILURE;
6280
6281 if(pMac->scan.fScanEnable)
6282 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306283 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 -08006284 }
6285 return (status);
6286}
Jeff Johnson295189b2012-06-20 16:38:30 -07006287
6288eHalStatus csrScanStopResultAgingTimer(tpAniSirGlobal pMac)
6289{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306290 return (vos_timer_stop(&pMac->scan.hTimerResultAging));
Jeff Johnson295189b2012-06-20 16:38:30 -07006291}
6292
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006293eHalStatus csrScanStopResultCfgAgingTimer(tpAniSirGlobal pMac)
6294{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306295 return (vos_timer_stop(&pMac->scan.hTimerResultCfgAging));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006296}
Jeff Johnson295189b2012-06-20 16:38:30 -07006297
6298//This function returns the maximum time a BSS is allowed in the scan result.
6299//The time varies base on connection and power saving factors.
6300//Not connected, No PS
6301//Not connected, with PS
6302//Connected w/o traffic, No PS
6303//Connected w/o traffic, with PS
6304//Connected w/ traffic, no PS -- Not supported
6305//Connected w/ traffic, with PS -- Not supported
6306//the return unit is in seconds.
6307tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
6308{
6309 tANI_U32 nRet;
6310
6311 if(pMac->scan.nAgingCountDown)
6312 {
6313 //Calculate what should be the timeout value for this
6314 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
6315 pMac->scan.nAgingCountDown--;
6316 }
6317 else
6318 {
6319 if( csrIsAllSessionDisconnected( pMac ) )
6320 {
6321 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
6322 {
6323 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
6324 }
6325 else
6326 {
6327 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
6328 }
6329 }
6330 else
6331 {
6332 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
6333 {
6334 nRet = pMac->roam.configParam.scanAgeTimeCPS;
6335 }
6336 else
6337 {
6338 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
6339 }
6340 }
6341 //If state-change causing aging time out change, we want to delay it somewhat to avoid
6342 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
6343 if(pMac->scan.nLastAgeTimeOut > nRet)
6344 {
6345 if(nRet)
6346 {
6347 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
6348 }
6349 pMac->scan.nLastAgeTimeOut = nRet;
6350 nRet *= pMac->scan.nAgingCountDown;
6351 }
6352 else
6353 {
6354 pMac->scan.nLastAgeTimeOut = nRet;
6355 }
6356 }
6357
6358 return (nRet);
6359}
6360
6361
6362void csrScanResultAgingTimerHandler(void *pv)
6363{
6364 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6365 tANI_BOOLEAN fDisconnected = csrIsAllSessionDisconnected(pMac);
6366
6367 //no scan, no aging
6368 if(pMac->scan.fScanEnable &&
6369 (((eANI_BOOLEAN_FALSE == fDisconnected) && pMac->roam.configParam.bgScanInterval)
6370 || (fDisconnected && (pMac->scan.fCancelIdleScan == eANI_BOOLEAN_FALSE)))
6371 )
6372 {
6373 tListElem *pEntry, *tmpEntry;
6374 tCsrScanResult *pResult;
6375 tANI_TIMESTAMP ageOutTime = (tANI_TIMESTAMP)(csrScanGetAgeOutTime(pMac) * PAL_TICKS_PER_SECOND); //turn it into 10ms units
6376 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6377
6378 csrLLLock(&pMac->scan.scanResultList);
6379 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6380 while( pEntry )
6381 {
6382 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6383 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6384 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6385 {
6386 smsLog(pMac, LOGW, " age out due to time out");
6387 csrScanAgeOutBss(pMac, pResult);
6388 }
6389 pEntry = tmpEntry;
6390 }
6391 csrLLUnlock(&pMac->scan.scanResultList);
6392 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306393 vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006394}
6395
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006396static void csrScanResultCfgAgingTimerHandler(void *pv)
6397{
6398 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6399 tListElem *pEntry, *tmpEntry;
6400 tCsrScanResult *pResult;
6401 tANI_TIMESTAMP ageOutTime = pMac->scan.scanResultCfgAgingTime * PAL_TICKS_PER_SECOND;
6402 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6403
6404 csrLLLock(&pMac->scan.scanResultList);
6405 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6406 while( pEntry )
6407 {
6408 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6409 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6410 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6411 {
6412 smsLog(pMac, LOGW, " age out due to time out");
6413 csrScanAgeOutBss(pMac, pResult);
6414 }
6415 pEntry = tmpEntry;
6416 }
6417 csrLLUnlock(&pMac->scan.scanResultList);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306418 vos_timer_start(&pMac->scan.hTimerResultCfgAging, CSR_SCAN_RESULT_CFG_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006419}
Jeff Johnson295189b2012-06-20 16:38:30 -07006420
6421eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
6422{
6423 eHalStatus status;
6424
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006425 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07006426 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
6427 {
6428 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306429 vos_timer_stop(&pMac->scan.hTimerIdleScan);
6430 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006431 if( !HAL_STATUS_SUCCESS(status) )
6432 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006433 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07006434 //This should not happen but set the flag to restart when ready
6435 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6436 }
6437 }
6438 else
6439 {
6440 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
6441 {
6442 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6443 }
6444 status = eHAL_STATUS_FAILURE;
6445 }
6446
6447 return (status);
6448}
6449
6450
6451eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
6452{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306453 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07006454}
6455
6456
6457//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
6458void csrScanSuspendIMPS( tpAniSirGlobal pMac )
6459{
6460 csrScanCancelIdleScan(pMac);
6461}
6462
6463
6464//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
6465//because IMPS maybe disabled.
6466void csrScanResumeIMPS( tpAniSirGlobal pMac )
6467{
6468 csrScanStartIdleScan( pMac );
6469}
6470
6471
6472void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
6473{
6474 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
6475
6476 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6477 {
6478 if(pMac->roam.configParam.IsIdleScanEnabled)
6479 {
6480 if(HAL_STATUS_SUCCESS(status))
6481 {
6482 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
6483 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006484 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006485 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
6486 }
6487 else
6488 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006489 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006490 //even though we are in timer handle, calling stop timer will make sure the timer
6491 //doesn't get to restart.
6492 csrScanStopIdleScanTimer(pMac);
6493 }
6494 }
6495 else
6496 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006497 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006498 }
6499 }
6500 else
6501 {//we might need another flag to check if CSR needs to request imps at all
6502
6503 tANI_U32 nTime = 0;
6504
6505 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
6506 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
6507 {
6508 csrScanStartIdleScanTimer(pMac, nTime);
6509 }
6510 }
6511 }
6512}
6513
6514
6515//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
6516//idle scan timer interval
6517//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
6518eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
6519{
6520 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6521
6522 //Do not trigger IMPS in case of concurrency
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006523 if (vos_concurrent_sessions_running() && csrIsAnySessionInConnectState(pMac))
6524 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006525 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006526 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006527 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006528
6529 if(pTimeInterval)
6530 {
6531 *pTimeInterval = 0;
6532 }
6533
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006534 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006535 if( smeCommandPending( pMac ) )
6536 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006537 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006538 //Not to enter IMPS because more work to do
6539 if(pTimeInterval)
6540 {
6541 *pTimeInterval = 0;
6542 }
6543 //restart when ready
6544 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6545
6546 return (status);
6547 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006548 if (IsPmcImpsReqFailed (pMac))
6549 {
6550 if(pTimeInterval)
6551 {
6552 *pTimeInterval = 1000000; //usec
6553 }
6554 //restart when ready
6555 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006556
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006557 return status;
6558 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006559 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6560 /*&& pMac->roam.configParam.impsSleepTime*/)
6561 {
6562 //Stop get result timer because idle scan gets scan result out of PE
6563 csrScanStopGetResultTimer(pMac);
6564 if(pTimeInterval)
6565 {
6566 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
6567 }
6568 //pmcRequestImps take a period in millisecond unit.
6569 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
6570 if(!HAL_STATUS_SUCCESS(status))
6571 {
6572 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
6573 {
6574 //Do restart the timer if CSR thinks it cannot do IMPS
6575 if( !csrCheckPSReady( pMac ) )
6576 {
6577 if(pTimeInterval)
6578 {
6579 *pTimeInterval = 0;
6580 }
6581 //Set the restart flag to true because that idle scan
6582 //can be restarted even though the timer will not be running
6583 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6584 }
6585 else
6586 {
6587 //For not now, we do a quicker retry
6588 if(pTimeInterval)
6589 {
6590 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
6591 }
6592 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006593 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006594 }
6595 else
6596 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006597 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006598 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
6599 //the callback will be called in the future. Should not happen though.
6600 status = eHAL_STATUS_SUCCESS;
6601 pMac->scan.nIdleScanTimeGap = 0;
6602 }
6603 }
6604 else
6605 {
6606 //requested so let's reset the value
6607 pMac->scan.nIdleScanTimeGap = 0;
6608 }
6609 }
6610
6611 return (status);
6612}
6613
6614
6615eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
6616{
6617 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6618 tANI_U32 nTime = 0;
6619
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006620 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006621 if(pMac->roam.configParam.IsIdleScanEnabled)
6622 {
6623 //stop bg scan first
6624 csrScanBGScanAbort(pMac);
6625 //Stop get result timer because idle scan gets scan result out of PE
6626 csrScanStopGetResultTimer(pMac);
6627 //Enable aging timer since idle scan is going on
6628 csrScanStartResultAgingTimer(pMac);
6629 }
6630 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
6631 status = csrScanTriggerIdleScan(pMac, &nTime);
6632 if(!HAL_STATUS_SUCCESS(status))
6633 {
6634 csrScanStartIdleScanTimer(pMac, nTime);
6635 }
6636
6637 return (status);
6638}
6639
6640
6641void csrScanCancelIdleScan(tpAniSirGlobal pMac)
6642{
6643 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6644 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006645 if (vos_concurrent_sessions_running()) {
6646 return;
6647 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006648 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07006649 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
6650 //Set the restart flag in case later on it is uncancelled
6651 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6652 csrScanStopIdleScanTimer(pMac);
6653 csrScanRemoveNotRoamingScanCommand(pMac);
6654 }
6655}
6656
6657
6658void csrScanIdleScanTimerHandler(void *pv)
6659{
6660 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6661 eHalStatus status;
6662 tANI_U32 nTime = 0;
6663
6664 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006665 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006666 status = csrScanTriggerIdleScan(pMac, &nTime);
6667 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
6668 {
6669 //Check whether it is time to actually do an idle scan
6670 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
6671 {
6672 pMac->scan.nIdleScanTimeGap = 0;
6673 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
6674 }
6675 else
6676 {
6677 csrScanStartIdleScanTimer(pMac, nTime);
6678 }
6679 }
6680}
6681
6682
6683
6684
6685tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
6686{
6687 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6688 tListElem *pEntry, *pEntryTmp;
6689 tSmeCmd *pCommand;
6690 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306691 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006692
6693 vos_mem_zero(&localList, sizeof(tDblLinkList));
6694 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6695 {
6696 smsLog(pMac, LOGE, FL(" failed to open list"));
6697 return fRet;
6698 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306699 if (!pMac->fScanOffload)
6700 pCmdList = &pMac->sme.smeCmdPendingList;
6701 else
6702 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006703
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306704 csrLLLock(pCmdList);
6705 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006706 while(pEntry)
6707 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306708 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006709 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6710 if( eSmeCommandScan == pCommand->command )
6711 {
6712 switch( pCommand->u.scanCmd.reason )
6713 {
6714 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306715 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006716 {
6717 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6718 }
6719 fRet = eANI_BOOLEAN_TRUE;
6720 break;
6721
6722 default:
6723 break;
6724 } //switch
6725 }
6726 pEntry = pEntryTmp;
6727 }
6728
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306729 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006730
6731 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6732 {
6733 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6734 csrReleaseCommandScan( pMac, pCommand );
6735 }
6736
6737 csrLLClose(&localList);
6738
6739 return (fRet);
6740}
6741
6742
6743tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
6744{
6745 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6746 tListElem *pEntry, *pEntryTmp;
6747 tSmeCmd *pCommand;
6748 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306749 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006750
6751 vos_mem_zero(&localList, sizeof(tDblLinkList));
6752 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6753 {
6754 smsLog(pMac, LOGE, FL(" failed to open list"));
6755 return fRet;
6756 }
6757
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306758 if (!pMac->fScanOffload)
6759 pCmdList = &pMac->sme.smeCmdPendingList;
6760 else
6761 pCmdList = &pMac->sme.smeScanCmdPendingList;
6762
6763 csrLLLock(pCmdList);
6764 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006765 while(pEntry)
6766 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306767 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006768 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6769 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
6770 {
6771 switch(pCommand->u.scanCmd.reason)
6772 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006773#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6774 case eCsrScanGetLfrResult:
6775#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006776 case eCsrScanGetResult:
6777 case eCsrScanSetBGScanParam:
6778 case eCsrScanBGScanAbort:
6779 case eCsrScanBGScanEnable:
6780 case eCsrScanGetScanChnInfo:
6781 break;
6782 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006783 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006784 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006785 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306786 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006787 {
6788 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6789 }
6790 fRet = eANI_BOOLEAN_TRUE;
6791 break;
6792 }
6793 }
6794 pEntry = pEntryTmp;
6795 }
6796
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306797 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006798
6799 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6800 {
6801 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6802 if (pCommand->u.scanCmd.callback)
6803 {
6804 /* User scan request is pending,
6805 * send response with status eCSR_SCAN_ABORT*/
6806 pCommand->u.scanCmd.callback(pMac,
6807 pCommand->u.scanCmd.pContext,
6808 pCommand->u.scanCmd.scanID,
6809 eCSR_SCAN_ABORT);
6810 }
6811 csrReleaseCommandScan( pMac, pCommand );
6812 }
6813 csrLLClose(&localList);
6814
6815 return (fRet);
6816}
6817
6818
6819void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6820{
6821 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306822 tANI_BOOLEAN status;
6823
6824 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07006825 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306826 tANI_U32 i;
6827 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
6828 csrRoamStateChange(pMac, pCommand->u.scanCmd.lastRoamState[i], i);
6829 }
6830 else
6831 {
6832 csrRoamStateChange(pMac,
6833 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
6834 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07006835 }
6836
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306837 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07006838
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006839 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306840 if (pMac->fScanOffload)
6841 {
6842 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
6843 &pCommand->Link, LL_ACCESS_LOCK);
6844 }
6845 else
6846 {
6847 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
6848 &pCommand->Link, LL_ACCESS_LOCK);
6849 }
6850
6851 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006852 {
6853 csrReleaseCommandScan( pMac, pCommand );
6854 }
6855 else
6856 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306857 smsLog(pMac, LOGE,
6858 " ********csrReleaseScanCommand cannot release command reason %d",
6859 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006860 }
6861}
6862
6863
6864eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6865 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
6866{
6867 eHalStatus status = eHAL_STATUS_SUCCESS;
6868 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6869
Jeff Johnson32d95a32012-09-10 13:15:23 -07006870 if(!pSession)
6871 {
6872 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6873 return eHAL_STATUS_FAILURE;
6874 }
6875
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006876 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006877 csrResetPMKIDCandidateList(pMac, sessionId);
6878 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6879 {
6880 tCsrScanResultFilter *pScanFilter;
6881 tCsrScanResultInfo *pScanResult;
6882 tScanResultHandle hBSSList;
6883 tANI_U32 nItems = *pNumItems;
6884
6885 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05306886 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
6887 if ( NULL == pScanFilter )
6888 status = eHAL_STATUS_FAILURE;
6889 else
Jeff Johnson295189b2012-06-20 16:38:30 -07006890 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306891 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006892 //Here is the profile we need to connect to
6893 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
6894 if(HAL_STATUS_SUCCESS(status))
6895 {
6896 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
6897 if(HAL_STATUS_SUCCESS(status))
6898 {
6899 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
6900 {
6901 //NumPmkidCandidate adds up here
6902 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
6903 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
6904 }
6905 if(pSession->NumPmkidCandidate)
6906 {
6907 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05306908 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
6909 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07006910 }
6911 csrScanResultPurge(pMac, hBSSList);
6912 }//Have scan result
6913 csrFreeScanFilter(pMac, pScanFilter);
6914 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306915 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006916 }
6917 }
6918
6919 return (status);
6920}
6921
6922
6923
6924#ifdef FEATURE_WLAN_WAPI
6925eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6926 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
6927{
6928 eHalStatus status = eHAL_STATUS_SUCCESS;
6929 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6930
Jeff Johnson32d95a32012-09-10 13:15:23 -07006931 if(!pSession)
6932 {
6933 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6934 return eHAL_STATUS_FAILURE;
6935 }
6936
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006937 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006938 csrResetBKIDCandidateList(pMac, sessionId);
6939 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6940 {
6941 tCsrScanResultFilter *pScanFilter;
6942 tCsrScanResultInfo *pScanResult;
6943 tScanResultHandle hBSSList;
6944 tANI_U32 nItems = *pNumItems;
6945 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05306946 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
6947 if ( NULL == pScanFilter )
6948 status = eHAL_STATUS_FAILURE;
6949 else
Jeff Johnson295189b2012-06-20 16:38:30 -07006950 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306951 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006952 //Here is the profile we need to connect to
6953 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
6954 if(HAL_STATUS_SUCCESS(status))
6955 {
6956 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
6957 if(HAL_STATUS_SUCCESS(status))
6958 {
6959 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
6960 {
6961 //pMac->scan.NumBkidCandidate adds up here
6962 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
6963 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
6964
6965 }
6966 if(pSession->NumBkidCandidate)
6967 {
6968 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05306969 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07006970 }
6971 csrScanResultPurge(pMac, hBSSList);
6972 }//Have scan result
6973 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306974 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006975 }
6976 }
6977
6978 return (status);
6979}
6980#endif /* FEATURE_WLAN_WAPI */
6981
6982
6983
6984//This function is usually used for BSSs that suppresses SSID so the profile
6985//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07006986eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07006987{
6988 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
6989 tSmeCmd *pScanCmd = NULL;
6990 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
6991 tANI_U8 index = 0;
6992 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
6993
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006994 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006995 //For WDS, we use the index 0. There must be at least one in there
6996 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
6997 {
6998 numSsid = 1;
6999 }
7000 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
7001 {
7002 do
7003 {
7004 pScanCmd = csrGetCommandBuffer(pMac);
7005 if(!pScanCmd)
7006 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007007 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007008 break;
7009 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307010 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
7011 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
7012 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
7013 status = eHAL_STATUS_FAILURE;
7014 else
7015 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007016 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
7017 if(!HAL_STATUS_SUCCESS(status))
7018 break;
7019 pScanCmd->u.scanCmd.roamId = roamId;
7020 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07007021 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007022 pScanCmd->u.scanCmd.callback = NULL;
7023 pScanCmd->u.scanCmd.pContext = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007024 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 -07007025 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05307026 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007027 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07007028 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07007029 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
7030 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
7031 {
7032 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
7033 }
7034 if(pProfile->pAddIEScan)
7035 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307036 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
7037 pProfile->nAddIEScanLength);
7038 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
7039 status = eHAL_STATUS_FAILURE;
7040 else
7041 status = eHAL_STATUS_SUCCESS;
7042 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7043 pProfile->nAddIEScanLength, 0);
7044 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07007045 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307046 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7047 pProfile->pAddIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07007048 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
7049 }
7050 else
7051 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007052 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07007053 }
7054 } //Allocate memory for IE field
7055 else
7056 {
7057 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
7058 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07007059 /* For one channel be good enpugh time to receive beacon atleast */
7060 if( 1 == pProfile->ChannelInfo.numOfChannels )
7061 {
7062 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7063 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7064 }
7065 else
7066 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307067 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
7068 pMac->roam.configParam.nActiveMaxChnTime;
7069 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
7070 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07007071 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307072 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc =
7073 pMac->roam.configParam.nActiveMaxChnTimeBtc;
7074 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc =
7075 pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07007076 if(pProfile->BSSIDs.numOfBSSIDs == 1)
7077 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307078 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
7079 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07007080 }
7081 else
7082 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307083 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07007084 }
7085 if(pProfile->ChannelInfo.numOfChannels)
7086 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307087 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
7088 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
7089 * pProfile->ChannelInfo.numOfChannels);
7090 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
7091 status = eHAL_STATUS_FAILURE;
7092 else
7093 status = eHAL_STATUS_SUCCESS;
7094 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7095 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07007096 {
7097 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
7098 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
7099 {
7100 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
7101 {
7102 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
7103 = pProfile->ChannelInfo.ChannelList[index];
7104 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
7105 }
7106 else
7107 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007108 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007109 }
7110
7111 }
7112 }
7113 else
7114 {
7115 break;
7116 }
7117
7118 }
7119 else
7120 {
7121 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7122 }
7123 if(pProfile->SSIDs.numOfSSIDs)
7124 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307125 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
7126 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
7127 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
7128 status = eHAL_STATUS_FAILURE;
7129 else
7130 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007131 if(!HAL_STATUS_SUCCESS(status))
7132 {
7133 break;
7134 }
7135 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05307136 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
7137 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007138 }
7139 //Start process the command
7140 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7141 if( !HAL_STATUS_SUCCESS( status ) )
7142 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007143 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007144 break;
7145 }
7146 }while(0);
7147 if(!HAL_STATUS_SUCCESS(status))
7148 {
7149 if(pScanCmd)
7150 {
7151 csrReleaseCommandScan(pMac, pScanCmd);
7152 //TODO:free the memory that is allocated in this function
7153 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007154 if(notify)
7155 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007156 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
7157 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007158 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007159 }//valid
7160 else
7161 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007162 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07007163 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
7164 }
7165
7166 return (status);
7167}
7168
7169
7170//Issue a scan base on the new capability infomation
7171//This should only happen when the associated AP changes its capability.
7172//After this scan is done, CSR reroams base on the new scan results
7173eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
7174{
7175 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7176 tSmeCmd *pScanCmd = NULL;
7177
7178 if(pNewCaps)
7179 {
7180 do
7181 {
7182 pScanCmd = csrGetCommandBuffer(pMac);
7183 if(!pScanCmd)
7184 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007185 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007186 status = eHAL_STATUS_RESOURCES;
7187 break;
7188 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307189 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007190 status = eHAL_STATUS_SUCCESS;
7191 pScanCmd->u.scanCmd.roamId = 0;
7192 pScanCmd->command = eSmeCommandScan;
7193 pScanCmd->u.scanCmd.callback = NULL;
7194 pScanCmd->u.scanCmd.pContext = NULL;
7195 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
7196 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7197 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7198 if( !HAL_STATUS_SUCCESS( status ) )
7199 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007200 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007201 break;
7202 }
7203 }while(0);
7204 if(!HAL_STATUS_SUCCESS(status))
7205 {
7206 if(pScanCmd)
7207 {
7208 csrReleaseCommandScan(pMac, pScanCmd);
7209 }
7210 }
7211 }
7212
7213 return (status);
7214}
7215
7216
7217
7218void csrInitBGScanChannelList(tpAniSirGlobal pMac)
7219{
7220 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
7221
Kiet Lam64c1b492013-07-12 13:56:44 +05307222 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007223 pMac->scan.numBGScanChannel = 0;
7224
7225 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
7226 {
7227 pMac->roam.numValidChannels = len;
7228 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05307229 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
7230 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007231 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
7232 }
7233}
7234
7235
7236//This function return TRUE if background scan channel list is adjusted.
7237//this function will only shrink the background scan channel list
7238tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
7239 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
7240{
7241 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7242 tANI_U8 i, j, count = *pNumAdjustChannels;
7243
7244 i = 0;
7245 while(i < count)
7246 {
7247 for(j = 0; j < NumChannels; j++)
7248 {
7249 if(pChannelList[j] == pAdjustChannels[i])
7250 break;
7251 }
7252 if(j == NumChannels)
7253 {
7254 //This channel is not in the list, remove it
7255 fRet = eANI_BOOLEAN_TRUE;
7256 count--;
7257 if(count - i)
7258 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307259 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07007260 }
7261 else
7262 {
7263 //already remove the last one. Done.
7264 break;
7265 }
7266 }
7267 else
7268 {
7269 i++;
7270 }
7271 }//while(i<count)
7272 *pNumAdjustChannels = count;
7273
7274 return (fRet);
7275}
7276
7277
7278//Get the list of the base channels to scan for passively 11d info
7279eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
7280{
7281 eHalStatus status = eHAL_STATUS_SUCCESS;
7282 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7283
7284 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
7285 if( HAL_STATUS_SUCCESS(status) )
7286 {
7287 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
7288 }
7289 else
7290 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007291 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007292 pMac->scan.baseChannels.numChannels = 0;
7293 }
7294
7295 return ( status );
7296}
7297
7298//This function use the input pChannelList to validate the current saved channel list
7299eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
7300{
7301 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
7302
7303 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
7304}
7305
7306
7307void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
7308{
7309 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307310 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007311
7312 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7313
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307314 if (pMac->fScanOffload)
7315 {
7316 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7317 "Scan offload is enabled, update default chan list");
7318 status = csrUpdateChannelList(&pMac->scan);
7319 if (eHAL_STATUS_SUCCESS != status)
7320 {
7321 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
7322 "failed to update the supported channel list");
7323 }
7324 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007325 return;
7326}
7327
7328
7329
7330/*
7331 * The Tx power limits are saved in the cfg for future usage.
7332 */
7333void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
7334{
7335 tListElem *pEntry;
7336 tANI_U32 cbLen = 0, dataLen;
7337 tCsrChannelPowerInfo *pChannelSet;
7338 tANI_U32 idx;
7339 tSirMacChanInfo *pChannelPowerSet;
7340 tANI_U8 *pBuf = NULL;
7341
7342 //allocate maximum space for all channels
7343 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05307344 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007345 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307346 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007347 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
7348
7349 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
7350 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
7351 while( pEntry )
7352 {
7353 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
7354 if ( 1 != pChannelSet->interChannelOffset )
7355 {
7356 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
7357 // to the right format... (inter channel offset of 1 is the only option for the triplets
7358 // that 11d advertises.
7359 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
7360 {
7361 // expanding this entry will overflow our allocation
7362 smsLog(pMac, LOGE,
7363 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007364 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007365 pChannelSet->firstChannel,
7366 pChannelSet->numChannels,
7367 pChannelSet->interChannelOffset);
7368 break;
7369 }
7370
7371 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
7372 {
7373 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007374 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007375 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007376 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007377 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07007378 cbLen += sizeof( tSirMacChanInfo );
7379 pChannelPowerSet++;
7380 }
7381 }
7382 else
7383 {
7384 if (cbLen >= dataLen)
7385 {
7386 // this entry will overflow our allocation
7387 smsLog(pMac, LOGE,
7388 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007389 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007390 pChannelSet->firstChannel,
7391 pChannelSet->numChannels,
7392 pChannelSet->interChannelOffset);
7393 break;
7394 }
7395 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007396 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007397 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07007398 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007399 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07007400
7401
7402 cbLen += sizeof( tSirMacChanInfo );
7403 pChannelPowerSet++;
7404 }
7405
7406 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
7407 }
7408
7409 if(cbLen)
7410 {
7411 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
7412 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307413 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07007414 }//Allocate memory
7415}
7416
7417
7418void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
7419{
7420 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
7421 ///v_REGDOMAIN_t DomainId;
7422
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007423 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05307424 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07007425
7426 // don't program the bogus country codes that we created for Korea in the MAC. if we see
7427 // the bogus country codes, program the MAC with the right country code.
7428 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
7429 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
7430 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
7431 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
7432 {
7433 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
7434 cc[ 1 ] = 'R';
7435 }
7436 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
7437
7438 //Need to let HALPHY know about the current domain so it can apply some
7439 //domain-specific settings (TX filter...)
7440 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
7441 {
7442 halPhySetRegDomain(pMac, DomainId);
7443 }*/
7444}
7445
7446
7447
7448eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
7449{
7450 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7451 tANI_U32 len;
7452
7453 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
7454 {
7455 len = *pbLen;
7456 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
7457 if(HAL_STATUS_SUCCESS(status))
7458 {
7459 *pbLen = (tANI_U8)len;
7460 }
7461 }
7462
7463 return (status);
7464}
7465
7466
7467void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
7468{
7469 tANI_U8 i, j;
7470 tANI_BOOLEAN found=FALSE;
7471 tANI_U8 *pControlList = NULL;
7472 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
7473
Kiet Lam64c1b492013-07-12 13:56:44 +05307474 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007475 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307476 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007477 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
7478 {
7479 for (i = 0; i < pChannelList->numChannels; i++)
7480 {
7481 for (j = 0; j < len; j += 2)
7482 {
7483 if (pControlList[j] == pChannelList->channelList[i])
7484 {
7485 found = TRUE;
7486 break;
7487 }
7488 }
7489
7490 if (found) // insert a pair(channel#, flag)
7491 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05307492 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007493 found = FALSE; // reset the flag
7494 }
7495
7496 }
7497
7498 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
7499 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05307500 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007501 }//AllocateMemory
7502}
7503
7504
7505//if bgPeriod is 0, background scan is disabled. It is in millisecond units
7506eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
7507{
7508 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
7509}
7510
7511
7512void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
7513{
7514 tListElem *pEntry = NULL;
7515 tSmeCmd *pCommand = NULL;
7516 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307517 tDblLinkList *pCmdList ;
7518
7519 if (!pMac->fScanOffload)
7520 pCmdList = &pMac->sme.smeCmdActiveList;
7521 else
7522 pCmdList = &pMac->sme.smeScanCmdActiveList;
7523
7524 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07007525 if ( pEntry )
7526 {
7527 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7528 if ( eSmeCommandScan == pCommand->command )
7529 {
7530 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
7531 csrReleaseScanCommand(pMac, pCommand, scanStatus);
7532 }
7533 else
7534 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007535 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07007536 }
7537 }
7538 smeProcessPendingQueue( pMac );
7539}
7540
7541eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
7542{
7543 eHalStatus status;
7544 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
7545 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
7546
7547 //***setcfg for background scan channel list
7548 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
7549 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
7550 //Not set the background scan interval if not connected because bd scan should not be run if not connected
7551 if(!csrIsAllSessionDisconnected(pMac))
7552 {
7553 //If disbaling BG scan here, we need to stop aging as well
7554 if(pScanReq->scanInterval == 0)
7555 {
7556 //Stop aging because no new result is coming in
7557 csrScanStopResultAgingTimer(pMac);
7558 }
7559
7560#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7561 {
7562 vos_log_scan_pkt_type *pScanLog = NULL;
7563
7564 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
7565 if(pScanLog)
7566 {
7567 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
7568 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
7569 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
7570 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
7571 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
7572 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
7573 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307574 vos_mem_copy(pScanLog->channels,
7575 pScanReq->ChannelInfo.ChannelList,
7576 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007577 }
7578 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
7579 }
7580 }
7581#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7582
7583 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
7584 }
7585 else
7586 {
7587 //No need to stop aging because IDLE scan is still running
7588 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
7589 }
7590
7591 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
7592 {
7593 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
7594 }
7595
7596 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7597 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
7598
7599
7600
7601 return (status);
7602}
7603
7604
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307605eHalStatus csrScanAbortMacScan(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007606{
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307607 eHalStatus status = eHAL_STATUS_FAILURE;
7608 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07007609 tANI_U16 msgLen;
7610 tListElem *pEntry;
7611 tSmeCmd *pCommand;
7612
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307613 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007614 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307615#ifdef WLAN_AP_STA_CONCURRENCY
7616 csrLLLock(&pMac->scan.scanCmdPendingList);
7617 while(NULL !=
7618 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
7619 LL_ACCESS_NOLOCK)))
7620 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007621
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307622 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7623 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7624 }
7625 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007626#endif
7627
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307628 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7629 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
7630 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
7631 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7632
7633 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
7634 }
7635 else
7636 {
7637 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7638 csrRemoveCmdWithSessionIdFromPendingList(pMac,
7639 sessionId,
7640 &pMac->sme.smeScanCmdPendingList,
7641 eSmeCommandScan);
7642 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7643
7644 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
7645 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007646
7647 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307648 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07007649 {
7650 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307651 if(eSmeCommandScan == pCommand->command &&
7652 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007653 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307654 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05307655 pMsg = vos_mem_malloc(msgLen);
7656 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07007657 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307658 status = eHAL_STATUS_FAILURE;
7659 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
7660 }
7661 else
7662 {
7663 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007664 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
7665 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307666 pMsg->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007667 status = palSendMBMessage(pMac->hHdd, pMsg);
7668 }
7669 }
7670 }
7671
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307672 return(status);
7673}
7674
7675void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
7676 tANI_U8 sessionId,
7677 tDblLinkList *pList,
7678 eSmeCommandType commandType)
7679{
7680 tDblLinkList localList;
7681 tListElem *pEntry;
7682 tSmeCmd *pCommand;
7683 tListElem *pEntryToRemove;
7684
7685 vos_mem_zero(&localList, sizeof(tDblLinkList));
7686 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7687 {
7688 smsLog(pMac, LOGE, FL(" failed to open list"));
7689 return;
7690 }
7691
7692 csrLLLock(pList);
7693 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
7694 {
7695
7696 /* Have to make sure we don't loop back to the head of the list,
7697 * which will happen if the entry is NOT on the list */
7698 while (pEntry)
7699 {
7700 pEntryToRemove = pEntry;
7701 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7702 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7703 if ((pCommand->command == commandType) &&
7704 (pCommand->sessionId == sessionId))
7705 {
7706 /* Remove that entry only */
7707 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7708 {
7709 csrLLInsertTail(&localList, pEntryToRemove,
7710 LL_ACCESS_NOLOCK);
7711 }
7712 }
7713 }
7714 }
7715 csrLLUnlock(pList);
7716
7717 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
7718 {
7719 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7720 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
7721 }
7722
7723 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007724}
7725
7726void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
7727 eSmeCommandType commandType )
7728{
7729 tDblLinkList localList;
7730 tListElem *pEntry;
7731 tSmeCmd *pCommand;
7732 tListElem *pEntryToRemove;
7733
7734 vos_mem_zero(&localList, sizeof(tDblLinkList));
7735 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7736 {
7737 smsLog(pMac, LOGE, FL(" failed to open list"));
7738 return;
7739 }
7740
7741 csrLLLock(pList);
7742 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
7743 {
7744 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
7745
7746 // Have to make sure we don't loop back to the head of the list, which will
7747 // happen if the entry is NOT on the list...
7748 while( pEntry )
7749 {
7750 pEntryToRemove = pEntry;
7751 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7752 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7753 if ( pCommand->command == commandType )
7754 {
7755 // Remove that entry only
7756 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7757 {
7758 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
7759 }
7760 }
7761 }
7762
7763
7764 }
7765 csrLLUnlock(pList);
7766
7767 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7768 {
7769 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7770 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7771 }
7772 csrLLClose(&localList);
7773
7774}
7775
7776
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307777eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
7778 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007779{
7780 eHalStatus status = eHAL_STATUS_SUCCESS;
7781
7782 if( !csrIsScanForRoamCommandActive( pMac ) )
7783 {
7784 //Only abort the scan if it is not used for other roam/connect purpose
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307785 status = csrScanAbortMacScan(pMac, sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007786 }
7787
7788 return (status);
7789}
7790
7791
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307792eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007793{
7794 eHalStatus status = eHAL_STATUS_SUCCESS;
7795 tSirMbMsg *pMsg;
7796 tANI_U16 msgLen;
7797
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307798 if (pMac->fScanOffload)
7799 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
7800 else
7801 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
7802
Kiet Lam64c1b492013-07-12 13:56:44 +05307803 pMsg = vos_mem_malloc(msgLen);
7804 if ( NULL == pMsg )
7805 status = eHAL_STATUS_FAILURE;
7806 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007807 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307808 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007809 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
7810 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307811 if (pMac->fScanOffload)
7812 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007813 status = palSendMBMessage(pMac->hHdd, pMsg);
7814 }
7815
7816 return( status );
7817}
7818
7819tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
7820{
7821 tANI_BOOLEAN fValid = FALSE;
7822 tANI_U32 idxValidChannels;
7823 tANI_U32 len = pMac->roam.numValidChannels;
7824
7825 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
7826 {
7827 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
7828 {
7829 fValid = TRUE;
7830 break;
7831 }
7832 }
7833
7834 return fValid;
7835}
7836
Srikant Kuppa066904f2013-05-07 13:56:02 -07007837eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
7838 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
7839{
7840 v_U32_t uLen = 0;
7841 tpSirProbeRespBeacon pParsedFrame;
7842 tCsrScanResult *pScanResult = NULL;
7843 tSirBssDescription *pBssDescr = NULL;
7844 tANI_BOOLEAN fDupBss;
7845 tDot11fBeaconIEs *pIesLocal = NULL;
7846 tAniSSID tmpSsid;
7847 v_TIME_t timer=0;
7848 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
7849
7850 pParsedFrame =
Kiet Lam64c1b492013-07-12 13:56:44 +05307851 (tpSirProbeRespBeacon)vos_mem_malloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07007852
7853 if (NULL == pParsedFrame)
7854 {
7855 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
7856 return eHAL_STATUS_RESOURCES;
7857 }
7858
7859 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
7860 {
7861 smsLog(pMac, LOGE,
7862 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
7863 pPrefNetworkFoundInd->frameLength);
7864 vos_mem_free(pParsedFrame);
7865 return eHAL_STATUS_FAILURE;
7866 }
7867
7868 if (sirConvertProbeFrame2Struct(pMac,
7869 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
7870 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
7871 pParsedFrame) != eSIR_SUCCESS ||
7872 !pParsedFrame->ssidPresent)
7873 {
7874 smsLog(pMac, LOGE,
7875 FL("Parse error ProbeResponse, length=%d"),
7876 pPrefNetworkFoundInd->frameLength);
7877 vos_mem_free(pParsedFrame);
7878 return eHAL_STATUS_FAILURE;
7879 }
7880 //24 byte MAC header and 12 byte to ssid IE
7881 if (pPrefNetworkFoundInd->frameLength >
7882 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
7883 {
7884 uLen = pPrefNetworkFoundInd->frameLength -
7885 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
7886 }
7887
Kiet Lam64c1b492013-07-12 13:56:44 +05307888 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
7889 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07007890 {
7891 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
7892 vos_mem_free(pParsedFrame);
7893 return eHAL_STATUS_RESOURCES;
7894 }
7895
Kiet Lam64c1b492013-07-12 13:56:44 +05307896 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07007897 pBssDescr = &pScanResult->Result.BssDescriptor;
7898 /**
7899 * Length of BSS desription is without length of
7900 * length itself and length of pointer
7901 * that holds the next BSS description
7902 */
7903 pBssDescr->length = (tANI_U16)(
7904 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
7905 sizeof(tANI_U32) + uLen);
7906 if (pParsedFrame->dsParamsPresent)
7907 {
7908 pBssDescr->channelId = pParsedFrame->channelNumber;
7909 }
7910 else if (pParsedFrame->HTInfo.present)
7911 {
7912 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
7913 }
7914 else
7915 {
7916 pBssDescr->channelId = pParsedFrame->channelNumber;
7917 }
7918
7919 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
7920 {
7921 int i;
7922 // 11b or 11g packet
7923 // 11g iff extended Rate IE is present or
7924 // if there is an A rate in suppRate IE
7925 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
7926 {
7927 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
7928 {
7929 pBssDescr->nwType = eSIR_11G_NW_TYPE;
7930 break;
7931 }
7932 }
7933 if (pParsedFrame->extendedRatesPresent)
7934 {
7935 pBssDescr->nwType = eSIR_11G_NW_TYPE;
7936 }
7937 }
7938 else
7939 {
7940 // 11a packet
7941 pBssDescr->nwType = eSIR_11A_NW_TYPE;
7942 }
7943
7944 pBssDescr->sinr = 0;
7945 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
7946 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
7947 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
7948 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
7949 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05307950 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Srikant Kuppa066904f2013-05-07 13:56:02 -07007951 pBssDescr->nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
7952
7953 smsLog( pMac, LOG2, "(%s):Bssid= %02x-%02x-%02x-%02x-%02x-%02x "
7954 "chan= %d, rssi = %d", __func__,
7955 pBssDescr->bssId[ 0 ], pBssDescr->bssId[ 1 ],
7956 pBssDescr->bssId[ 2 ], pBssDescr->bssId[ 3 ],
7957 pBssDescr->bssId[ 4 ], pBssDescr->bssId[ 5 ],
7958 pBssDescr->channelId,
7959 pBssDescr->rssi );
7960
7961 //IEs
7962 if (uLen)
7963 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307964 vos_mem_copy(&pBssDescr->ieFields,
7965 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
7966 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07007967 }
7968
7969 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
7970 if ( !pIesLocal &&
7971 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
7972 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
7973 {
7974 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
7975 csrFreeScanResultEntry(pMac, pScanResult);
7976 vos_mem_free(pParsedFrame);
7977 return eHAL_STATUS_RESOURCES;
7978 }
7979
7980 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307981 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07007982 //Check whether we have reach out limit
7983 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
7984 {
7985 //Limit reach
7986 smsLog(pMac, LOGE, FL(" BSS limit reached"));
7987 //Free the resources
7988 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
7989 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307990 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07007991 }
7992 csrFreeScanResultEntry(pMac, pScanResult);
7993 vos_mem_free(pParsedFrame);
7994 return eHAL_STATUS_RESOURCES;
7995 }
7996 //Add to scan cache
7997 csrScanAddResult(pMac, pScanResult, pIesLocal);
7998
Kiet Lamb537cfb2013-11-07 12:56:49 +05307999 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8000 {
8001 vos_mem_free(pIesLocal);
8002 }
8003
Srikant Kuppa066904f2013-05-07 13:56:02 -07008004 vos_mem_free(pParsedFrame);
8005
8006 return eHAL_STATUS_SUCCESS;
8007}
8008
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008009#ifdef FEATURE_WLAN_LFR
8010void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
8011{
8012 tListElem *pEntry = NULL;
8013 tCsrScanResult *pBssDesc = NULL;
8014 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08008015 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
8016
8017 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
8018 {
8019 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008020 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08008021 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
8022 return;
8023 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008024
8025 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
8026 {
8027 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008028 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008029 __func__, pMac->scan.occupiedChannels.numChannels);
8030 return;
8031 }
8032
8033 /* Empty occupied channels here */
8034 pMac->scan.occupiedChannels.numChannels = 0;
8035
8036 csrLLLock(&pMac->scan.scanResultList);
8037 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
8038 while( pEntry )
8039 {
8040 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
8041 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
8042
8043 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08008044 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008045 &pBssDesc->Result.BssDescriptor, &pIes))) )
8046 {
8047 continue;
8048 }
8049
8050 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
8051
8052 /*
8053 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
8054 */
8055 if( (pBssDesc->Result.pvIes == NULL) && pIes )
8056 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308057 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008058 }
8059
8060 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
8061 }//while
8062 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08008063
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008064}
8065#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008066
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008067eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
8068 tCsrBssid bssid, tANI_U8 channel)
8069{
8070 eHalStatus status = eHAL_STATUS_SUCCESS;
8071 tDot11fBeaconIEs *pNewIes = NULL;
8072 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07008073 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008074 tANI_U32 size = 0;
8075
8076 if(NULL == pSession)
8077 {
8078 status = eHAL_STATUS_FAILURE;
8079 return status;
8080 }
8081 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
8082 "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x"),
8083 pSession->pConnectBssDesc->bssId[0],
8084 pSession->pConnectBssDesc->bssId[1],
8085 pSession->pConnectBssDesc->bssId[2],
8086 pSession->pConnectBssDesc->bssId[3],
8087 pSession->pConnectBssDesc->bssId[4],
8088 pSession->pConnectBssDesc->bssId[5]);
8089 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
8090 "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x channel %d"),
8091 bssid[0],bssid[1],bssid[2],
8092 bssid[3],bssid[4],bssid[5],channel);
8093
8094 do
8095 {
8096 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8097 pSession->pConnectBssDesc, &pNewIes)))
8098 {
8099 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
8100 __func__);
8101 status = eHAL_STATUS_FAILURE;
8102 break;
8103 }
8104
8105 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05308106 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008107 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308108 pNewBssDescriptor = vos_mem_malloc(size);
8109 if ( NULL == pNewBssDescriptor )
8110 status = eHAL_STATUS_FAILURE;
8111 else
8112 status = eHAL_STATUS_SUCCESS;
8113 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008114 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308115 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008116 }
8117 else
8118 {
8119 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
8120 __func__);
8121 status = eHAL_STATUS_FAILURE;
8122 break;
8123 }
8124
8125 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05308126 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008127 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008128 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008129 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008130 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008131 __func__);
8132 status = eHAL_STATUS_FAILURE;
8133 break;
8134 }
8135 }
8136 else
8137 {
8138 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
8139 __func__);
8140 status = eHAL_STATUS_FAILURE;
8141 break;
8142 }
8143 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
8144 __func__);
8145 }while(0);
8146
8147 if(pNewIes)
8148 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308149 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008150 }
8151 if(pNewBssDescriptor)
8152 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308153 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008154 }
8155 return status;
8156}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07008157
8158#ifdef FEATURE_WLAN_CCX
8159// Update the TSF with the difference in system time
8160void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
8161{
8162 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
8163
8164 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
8165 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
8166 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
8167}
8168#endif