blob: 3cc5c72ff149fb4f05c7d04608d93578298abae7 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Gopichand Nakkala92f07d82013-01-08 21:16:34 -08002 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21/*
Jeff Johnson32d95a32012-09-10 13:15:23 -070022 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -070023 *
24 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
25 *
26 *
27 * Permission to use, copy, modify, and/or distribute this software for
28 * any purpose with or without fee is hereby granted, provided that the
29 * above copyright notice and this permission notice appear in all
30 * copies.
31 *
32 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
33 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
35 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
36 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
37 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
38 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
39 * PERFORMANCE OF THIS SOFTWARE.
40 */
41
Jeff Johnson40b59aa2013-03-19 14:43:18 -070042/** ------------------------------------------------------------------------- *
43 ------------------------------------------------------------------------- *
Jeff Johnson295189b2012-06-20 16:38:30 -070044
Jeff Johnson40b59aa2013-03-19 14:43:18 -070045
Jeff Johnson295189b2012-06-20 16:38:30 -070046 \file csrApiScan.c
Jeff Johnson40b59aa2013-03-19 14:43:18 -070047
Jeff Johnson295189b2012-06-20 16:38:30 -070048 Implementation for the Common Scan interfaces.
Jeff Johnson40b59aa2013-03-19 14:43:18 -070049
50 Copyright (C) 2006 Airgo Networks, Incorporated
Jeff Johnson295189b2012-06-20 16:38:30 -070051 ========================================================================== */
52
53#include "aniGlobal.h"
54
55#include "palApi.h"
56#include "csrInsideApi.h"
57#include "smeInside.h"
58#include "smsDebug.h"
59
60#include "csrSupport.h"
61#include "wlan_qct_tl.h"
62
63#include "vos_diag_core_log.h"
64#include "vos_diag_core_event.h"
65
66#include "vos_nvitem.h"
67#include "wlan_qct_wda.h"
Jeff Johnson40b59aa2013-03-19 14:43:18 -070068
Jeff Johnson295189b2012-06-20 16:38:30 -070069#define CSR_VALIDATE_LIST //This portion of code need to be removed once the issue is resolved.
70
71#ifdef CSR_VALIDATE_LIST
72tDblLinkList *g_pchannelPowerInfoList24 = NULL, * g_pchannelPowerInfoList5 = NULL;
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -070073tpAniSirGlobal g_pMac;
Jeff Johnson295189b2012-06-20 16:38:30 -070074#endif
75
76/* Purpose of HIDDEN_TIMER
77** When we remove hidden ssid from the profile i.e., forget the SSID via GUI that SSID shouldn't see in the profile
78** For above requirement we used timer limit, logic is explained below
79** Timer value is initialsed to current time when it receives corresponding probe response of hidden SSID (The probe request is
80** received regularly till SSID in the profile. Once it is removed from profile probe request is not sent.) when we receive probe response
81** for broadcast probe request, during update SSID with saved SSID we will diff current time with saved SSID time if it is greater than 1 min
82** then we are not updating with old one
83*/
84
85#define HIDDEN_TIMER (1*60*1000)
86#define CSR_SCAN_RESULT_RSSI_WEIGHT 80 // must be less than 100, represent the persentage of new RSSI
87
88/*---------------------------------------------------------------------------
89 PER filter constant fraction: it is a %
90---------------------------------------------------------------------------*/
91#define CSR_SCAN_PER_FILTER_FRAC 100
92
93/*---------------------------------------------------------------------------
94 RSSI filter constant fraction: it is a %
95---------------------------------------------------------------------------*/
96#define CSR_SCAN_RSSI_FILTER_FRAC 100
97
98/*---------------------------------------------------------------------------
99Convert RSSI into overall score: Since RSSI is in -dBm values, and the
100overall needs to be weighted inversely (where greater value means better
101system), we convert.
102RSSI *cannot* be more than 0xFF or less than 0 for meaningful WLAN operation
103---------------------------------------------------------------------------*/
104#define CSR_SCAN_MAX_SCORE_VAL 0xFF
105#define CSR_SCAN_MIN_SCORE_VAL 0x0
106#define CSR_SCAN_HANDOFF_DELTA 10
Jeff Johnson32d95a32012-09-10 13:15:23 -0700107#define MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL 140
108#define MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL 120
Madan Mohan Koyyalamudia53c4dc2012-11-13 10:35:42 -0800109#define CSR_SCAN_OVERALL_SCORE( rssi ) \
110 (( rssi < CSR_SCAN_MAX_SCORE_VAL ) \
111 ? (CSR_SCAN_MAX_SCORE_VAL-rssi) : CSR_SCAN_MIN_SCORE_VAL)
Jeff Johnson295189b2012-06-20 16:38:30 -0700112
113
114#define CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) \
115 ( (pMac)->scan.nBssLimit <= (csrLLCount(&(pMac)->scan.scanResultList)) )
116
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530117/* Maximum number of channels per country can be ignored */
118#define MAX_CHANNELS_IGNORE 10
119
120#define MAX_COUNTRY_IGNORE 3
121
122/*struct to hold the ignored channel list based on country */
123typedef struct sCsrIgnoreChannels
124{
125 tANI_U8 countryCode[NV_FIELD_COUNTRY_CODE_SIZE];
126 tANI_U16 channelList[MAX_CHANNELS_IGNORE];
127 tANI_U16 channelCount;
128}tCsrIgnoreChannels;
129
130static tCsrIgnoreChannels countryIgnoreList[MAX_COUNTRY_IGNORE] = {
131 { {'U','A'}, { 136, 140}, 2},
132 { {'T','W'}, { 36, 40, 44, 48, 52}, 5},
133 { {'I','D'}, { 165}, 1 }
134 };
135
Jeff Johnson295189b2012-06-20 16:38:30 -0700136//*** This is temporary work around. It need to call CCM api to get to CFG later
137/// Get string parameter value
138extern tSirRetStatus wlan_cfgGetStr(tpAniSirGlobal, tANI_U16, tANI_U8*, tANI_U32*);
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530139
Jeff Johnson295189b2012-06-20 16:38:30 -0700140void csrScanGetResultTimerHandler(void *);
141void csrScanResultAgingTimerHandler(void *pv);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800142static void csrScanResultCfgAgingTimerHandler(void *pv);
Jeff Johnson295189b2012-06-20 16:38:30 -0700143void csrScanIdleScanTimerHandler(void *);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700144static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest);
Jeff Johnson295189b2012-06-20 16:38:30 -0700145#ifdef WLAN_AP_STA_CONCURRENCY
146static void csrStaApConcTimerHandler(void *);
147#endif
Jeff Johnsone7245742012-09-05 17:12:55 -0700148tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -0700149eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand );
150void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels );
151void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId );
152void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode );
153void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList );
154//if bgPeriod is 0, background scan is disabled. It is in millisecond units
155eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod);
156eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand);
157void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus);
158static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
159 tANI_U8 numChn, tSirBssDescription *pBssDesc,
160 tDot11fBeaconIEs **ppIes );
161eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels);
162void csrReleaseCmdSingle(tpAniSirGlobal pMac, tSmeCmd *pCommand);
163tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel );
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700164void csrPruneChannelListForMode( tpAniSirGlobal pMac, tCsrChannel *pChannelList );
Jeff Johnson295189b2012-06-20 16:38:30 -0700165
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700166#define CSR_IS_SOCIAL_CHANNEL(channel) (((channel) == 1) || ((channel) == 6) || ((channel) == 11) )
167
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700168
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700169
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800170static void csrReleaseScanCmdPendingList(tpAniSirGlobal pMac)
171{
172 tListElem *pEntry;
173 tSmeCmd *pCommand;
174
175 while((pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK)) != NULL)
176 {
177 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
178 if ( eSmeCsrCommandMask & pCommand->command )
179 {
180 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_TRUE );
181 }
182 else
183 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800184 smsLog(pMac, LOGE, FL("Error: Received command : %d"),pCommand->command);
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800185 }
186 }
187}
Jeff Johnson295189b2012-06-20 16:38:30 -0700188//pResult is invalid calling this function.
189void csrFreeScanResultEntry( tpAniSirGlobal pMac, tCsrScanResult *pResult )
190{
191 if( NULL != pResult->Result.pvIes )
192 {
193 palFreeMemory( pMac->hHdd, pResult->Result.pvIes );
194 }
195 palFreeMemory(pMac->hHdd, pResult);
196}
197
198
199static eHalStatus csrLLScanPurgeResult(tpAniSirGlobal pMac, tDblLinkList *pList)
200{
201 eHalStatus status = eHAL_STATUS_SUCCESS;
202 tListElem *pEntry;
203 tCsrScanResult *pBssDesc;
204
205 csrLLLock(pList);
206
207 while((pEntry = csrLLRemoveHead(pList, LL_ACCESS_NOLOCK)) != NULL)
208 {
209 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
210 csrFreeScanResultEntry( pMac, pBssDesc );
211 }
212
213 csrLLUnlock(pList);
214
215 return (status);
216}
217
218
219int csrCheckValidateLists(void * dest, const void *src, v_SIZE_t num, int idx)
220{
221#ifdef CSR_VALIDATE_LIST
222
223 int ii = 1;
224
225 if( (NULL == g_pMac) || (!g_pMac->scan.fValidateList ) )
226 {
227 return ii;
228 }
229 if(g_pchannelPowerInfoList24)
230 {
231 //check 2.4 list
232 tListElem *pElem, *pHead;
233 int count;
234
235 count = (int)(g_pchannelPowerInfoList24->Count);
236 pHead = &g_pchannelPowerInfoList24->ListHead;
237 pElem = pHead->next;
238 if((tANI_U32)(pHead->next) > 0x00010000) //Assuming kernel address is not that low.
239 {
240 //this loop crashes if the pointer is not right
241 while(pElem->next != pHead)
242 {
243 if((tANI_U32)(pElem->next) > 0x00010000)
244 {
245 pElem = pElem->next;
246 VOS_ASSERT(count > 0);
247 count--;
248 }
249 else
250 {
251 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_FATAL,
252 " %d Detect 1 list(0x%X) error Head(0x%X) next(0x%X) Count %d, dest(0x%X) src(0x%X) numBytes(%d)",
253 idx, (unsigned int)g_pchannelPowerInfoList24, (unsigned int)pHead,
254 (unsigned int)(pHead->next), (int)g_pchannelPowerInfoList24->Count,
255 (unsigned int)dest, (unsigned int)src, (int)num);
256 VOS_ASSERT(0);
257 ii = 0;
258 break;
259 }
260 }
261 }
262 else
263 {
264 //Bad list
265 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)",
266 idx, (unsigned int)g_pchannelPowerInfoList24, (unsigned int)pHead,
267 (unsigned int)(pHead->next), (int)g_pchannelPowerInfoList24->Count,
268 (unsigned int)dest, (unsigned int)src, (int)num);
269 VOS_ASSERT(0);
270 ii = 0;
271 }
272 }
273 else
274 {
275 //list ok
276 ii = 1;
277 }
278
279
280 return ii;
281
282#else
283 return 1;
284#endif //#ifdef CSR_VALIDATE_LIST
285}
286
287
288eHalStatus csrScanOpen( tpAniSirGlobal pMac )
289{
290 eHalStatus status;
291
292 do
293 {
294 csrLLOpen(pMac->hHdd, &pMac->scan.scanResultList);
295 csrLLOpen(pMac->hHdd, &pMac->scan.tempScanResults);
296 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList24);
297 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList5G);
298#ifdef WLAN_AP_STA_CONCURRENCY
299 csrLLOpen(pMac->hHdd, &pMac->scan.scanCmdPendingList);
300#endif
301#ifdef CSR_VALIDATE_LIST
302 g_pchannelPowerInfoList5 = &pMac->scan.channelPowerInfoList5G;
303 g_pMac = pMac;
304 g_pchannelPowerInfoList24 = &pMac->scan.channelPowerInfoList24;
305#endif
306 pMac->scan.fFullScanIssued = eANI_BOOLEAN_FALSE;
307 pMac->scan.nBssLimit = CSR_MAX_BSS_SUPPORT;
308 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerGetResult, csrScanGetResultTimerHandler, pMac);
309 if(!HAL_STATUS_SUCCESS(status))
310 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800311 smsLog(pMac, LOGE, FL("cannot allocate memory for getResult timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700312 break;
313 }
314#ifdef WLAN_AP_STA_CONCURRENCY
315 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerStaApConcTimer, csrStaApConcTimerHandler, pMac);
316 if(!HAL_STATUS_SUCCESS(status))
317 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800318 smsLog(pMac, LOGE, FL("cannot allocate memory for hTimerStaApConcTimer timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700319 break;
320 }
321#endif
322 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerIdleScan, csrScanIdleScanTimerHandler, pMac);
323 if(!HAL_STATUS_SUCCESS(status))
324 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800325 smsLog(pMac, LOGE, FL("cannot allocate memory for idleScan timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700326 break;
327 }
328 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerResultAging, csrScanResultAgingTimerHandler, pMac);
329 if(!HAL_STATUS_SUCCESS(status))
330 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800331 smsLog(pMac, LOGE, FL("cannot allocate memory for ResultAging timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700332 break;
333 }
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800334 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerResultCfgAging,
335 csrScanResultCfgAgingTimerHandler, pMac);
336 if(!HAL_STATUS_SUCCESS(status))
337 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800338 smsLog(pMac, LOGE, FL("cannot allocate memory for CFG ResultAging timer"));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800339 break;
340 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700341 }while(0);
342
343 return (status);
344}
345
346
347eHalStatus csrScanClose( tpAniSirGlobal pMac )
348{
349#ifdef CSR_VALIDATE_LIST
350 g_pchannelPowerInfoList24 = NULL;
351 g_pchannelPowerInfoList5 = NULL;
352 g_pMac = NULL;
353#endif
354 csrLLScanPurgeResult(pMac, &pMac->scan.tempScanResults);
355 csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList);
356#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800357 csrReleaseScanCmdPendingList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700358#endif
359 csrLLClose(&pMac->scan.scanResultList);
360 csrLLClose(&pMac->scan.tempScanResults);
361#ifdef WLAN_AP_STA_CONCURRENCY
362 csrLLClose(&pMac->scan.scanCmdPendingList);
363#endif
364 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList24);
365 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList5G);
366 csrLLClose(&pMac->scan.channelPowerInfoList24);
367 csrLLClose(&pMac->scan.channelPowerInfoList5G);
368 csrScanDisable(pMac);
369 palTimerFree(pMac->hHdd, pMac->scan.hTimerResultAging);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800370 palTimerFree(pMac->hHdd, pMac->scan.hTimerResultCfgAging);
Jeff Johnson295189b2012-06-20 16:38:30 -0700371 palTimerFree(pMac->hHdd, pMac->scan.hTimerGetResult);
372#ifdef WLAN_AP_STA_CONCURRENCY
373 palTimerFree(pMac->hHdd, pMac->scan.hTimerStaApConcTimer);
374#endif
375 palTimerFree(pMac->hHdd, pMac->scan.hTimerIdleScan);
376 return eHAL_STATUS_SUCCESS;
377}
378
379
380eHalStatus csrScanEnable( tpAniSirGlobal pMac )
381{
382
383 pMac->scan.fScanEnable = eANI_BOOLEAN_TRUE;
384 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
385
386 return eHAL_STATUS_SUCCESS;
387}
388
389
390eHalStatus csrScanDisable( tpAniSirGlobal pMac )
391{
392
393 csrScanStopTimers(pMac);
394 pMac->scan.fScanEnable = eANI_BOOLEAN_FALSE;
395
396 return eHAL_STATUS_SUCCESS;
397}
398
399
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700400//Set scan timing parameters according to state of other driver sessions
401//No validation of the parameters is performed.
402static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest)
403{
404#ifdef WLAN_AP_STA_CONCURRENCY
405 if(csrIsAnySessionConnected(pMac))
406 {
407 //If multi-session, use the appropriate default scan times
408 if(scanType == eSIR_ACTIVE_SCAN)
409 {
410 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTimeConc;
411 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTimeConc;
412 }
413 else
414 {
415 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTimeConc;
416 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTimeConc;
417 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800418 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
419 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700420
421 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
422
423 //Return so that fields set above will not be overwritten.
424 return;
425 }
426#endif
427
428 //This portion of the code executed if multi-session not supported
429 //(WLAN_AP_STA_CONCURRENCY not defined) or no multi-session.
430 //Use the "regular" (non-concurrency) default scan timing.
431 if(pScanRequest->scanType == eSIR_ACTIVE_SCAN)
432 {
433 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
434 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTime;
435 }
436 else
437 {
438 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
439 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
440 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800441 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
442 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700443
444#ifdef WLAN_AP_STA_CONCURRENCY
445 //No rest time if no sessions are connected.
446 pScanRequest->restTime = 0;
447#endif
448}
449
Jeff Johnson295189b2012-06-20 16:38:30 -0700450#ifdef WLAN_AP_STA_CONCURRENCY
451//Return SUCCESS is the command is queued, else returns eHAL_STATUS_FAILURE
452eHalStatus csrQueueScanRequest( tpAniSirGlobal pMac, tSmeCmd *pScanCmd )
453{
454 eHalStatus status = eHAL_STATUS_SUCCESS;
455
456 tANI_BOOLEAN fNoCmdPending;
457 tSmeCmd *pQueueScanCmd=NULL;
458 tSmeCmd *pSendScanCmd=NULL;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700459 tANI_U8 nNumChanCombinedConc = 0;
Gopichand Nakkala114718f2013-03-25 19:19:46 -0700460 if (NULL == pScanCmd)
461 {
462 smsLog (pMac, LOGE, FL("Scan Req cmd is NULL"));
463 return eHAL_STATUS_FAILURE;
464 }
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800465 /* split scan if any one of the following:
466 * - STA session is connected and the scan is not a P2P search
467 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -0800468 * Do not split scans if no concurrent infra connections are
469 * active and if the scan is a BG scan triggered by LFR (OR)
470 * any scan if LFR is in the middle of a BG scan. Splitting
471 * the scan is delaying the time it takes for LFR to find
472 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800473 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700474
475 if(csrIsStaSessionConnected(pMac) &&
476 !csrIsP2pSessionConnected(pMac))
477 {
478 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
479 }
480 else if(csrIsP2pSessionConnected(pMac))
481 {
482 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
483 }
Srikant Kuppa866893f2012-12-27 17:28:14 -0800484 if ( (csrIsStaSessionConnected(pMac) &&
485#ifdef FEATURE_WLAN_LFR
486 (csrIsConcurrentInfraConnected(pMac) ||
487 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
488 (pMac->roam.neighborRoamInfo.neighborRoamState !=
489 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
490#endif
491 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Vinay Malekal05fdc812012-12-17 13:04:30 -0800492 (csrIsP2pSessionConnected(pMac)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700493 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700494 tCsrScanRequest scanReq;
495 tANI_U8 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
496 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
497 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Jeff Johnson295189b2012-06-20 16:38:30 -0700498 tANI_BOOLEAN bMemAlloc = eANI_BOOLEAN_FALSE;
499
500 if (numChn == 0)
501 {
502
503 numChn = pMac->scan.baseChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700504
Vinay Malekal05fdc812012-12-17 13:04:30 -0800505 status = palAllocateMemory( pMac->hHdd, (void **)&pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn );
506 if( !HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700507 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800508 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800509 return eHAL_STATUS_FAILURE;
510 }
511 bMemAlloc = eANI_BOOLEAN_TRUE;
512 status = palCopyMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
513 pMac->scan.baseChannels.channelList, numChn );
514 if( !HAL_STATUS_SUCCESS( status ) )
515 {
516 palFreeMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList );
517 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800518 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800519 return eHAL_STATUS_FAILURE;
520 }
521 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn;
522 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700523
Vinay Malekal05fdc812012-12-17 13:04:30 -0800524 //Whenever we get a scan request with multiple channels we break it up into 2 requests
525 //First request for first channel to scan and second request to scan remaining channels
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700526 if ( numChn > nNumChanCombinedConc)
Vinay Malekal05fdc812012-12-17 13:04:30 -0800527 {
528 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
529
530 pQueueScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
531 if (!pQueueScanCmd)
532 {
533 if (bMemAlloc)
Jeff Johnson295189b2012-06-20 16:38:30 -0700534 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800535 palFreeMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList );
536 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
537
Jeff Johnson295189b2012-06-20 16:38:30 -0700538 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800539 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800540 return eHAL_STATUS_FAILURE;
541 }
542 pQueueScanCmd->command = pScanCmd->command;
543 pQueueScanCmd->sessionId = pScanCmd->sessionId;
544 pQueueScanCmd->u.scanCmd.callback = pScanCmd->u.scanCmd.callback;
545 pQueueScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
546 pQueueScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
547 pQueueScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700548
Vinay Malekal05fdc812012-12-17 13:04:30 -0800549 /* First copy all the parameters to local variable of scan request */
550 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -0700551
Vinay Malekal05fdc812012-12-17 13:04:30 -0800552 /* Now modify the elements of local var scan request required to be modified for split scan */
553 if(scanReq.ChannelInfo.ChannelList != NULL)
554 {
555 palFreeMemory(pMac->hHdd, scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -0800556 scanReq.ChannelInfo.ChannelList = NULL;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800557 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700558
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700559 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700560
Vinay Malekal05fdc812012-12-17 13:04:30 -0800561 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +0530562 FL(" &channelToScan %p pScanCmd(%p) pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList(%p)numChn(%d)"),
563 &channelToScan[0], pScanCmd,
564 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700565
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700566 palCopyMemory(pMac->hHdd, &channelToScan[0], &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nNumChanCombinedConc],
Vinay Malekal05fdc812012-12-17 13:04:30 -0800567 pChnInfo->numOfChannels * sizeof(tANI_U8));
568
569 pChnInfo->ChannelList = &channelToScan[0];
570
571 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
572 //Modify callers parameters in case of concurrency
573 scanReq.scanType = eSIR_ACTIVE_SCAN;
574 //Use concurrency values for min/maxChnTime.
575 //We know csrIsAnySessionConnected(pMac) returns TRUE here
576 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
577
578 status = csrScanCopyRequest(pMac, &pQueueScanCmd->u.scanCmd.u.scanRequest, &scanReq);
579
580 if(!HAL_STATUS_SUCCESS(status))
581 {
582 if (bMemAlloc)
583 {
584 palFreeMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList );
585 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
586
587 }
588 if( scanReq.pIEField != NULL)
589 {
590 palFreeMemory(pMac->hHdd, scanReq.pIEField);
591 scanReq.pIEField = NULL;
592 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800593 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800594 return eHAL_STATUS_FAILURE;
595 }
596 /* Clean the local scan variable */
597 scanReq.ChannelInfo.ChannelList = NULL;
598 scanReq.ChannelInfo.numOfChannels = 0;
599 csrScanFreeRequest(pMac, &scanReq);
600
601 /* setup the command to scan 2 channels */
602 pSendScanCmd = pScanCmd;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700603 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nNumChanCombinedConc;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800604 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
605 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
606 //Use concurrency values for min/maxChnTime.
607 //We know csrIsAnySessionConnected(pMac) returns TRUE here
608 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
609 pSendScanCmd->u.scanCmd.callback = NULL;
610 } else {
611 pSendScanCmd = pScanCmd;
612 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
613 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
614 //Use concurrency values for min/maxChnTime.
615 //We know csrIsAnySessionConnected(pMac) returns TRUE here
616 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
617 }
618
619 fNoCmdPending = csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK );
620
621 //Logic Below is as follows
622 // If the scanCmdPendingList is empty then we directly send that command
623 // to smeCommandQueue else we buffer it in our scanCmdPendingList Queue
624 if( fNoCmdPending )
625 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700626 if (pQueueScanCmd != NULL)
627 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800628 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -0700629 }
630
631 if (pSendScanCmd != NULL)
632 {
633 return csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
634 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800635 }
636 else
637 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700638 if (pSendScanCmd != NULL)
639 {
640 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pSendScanCmd->Link, LL_ACCESS_LOCK );
641 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800642
Jeff Johnson295189b2012-06-20 16:38:30 -0700643 if (pQueueScanCmd != NULL)
644 {
645 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
646 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800647 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700648 }
649 else
650 { //No concurrency case
Srikant Kuppa866893f2012-12-27 17:28:14 -0800651 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800652 " numOfChannels=%d)"),
Srikant Kuppa866893f2012-12-27 17:28:14 -0800653 pScanCmd->u.scanCmd.reason,
654 pMac->roam.neighborRoamInfo.neighborRoamState,
655 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -0700656 return csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
657 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700658
659 return ( status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700660}
661#endif
662
Jeff Johnsone7245742012-09-05 17:12:55 -0700663/* ---------------------------------------------------------------------------
664 \fn csrScan2GOnyRequest
665 \brief This function will update the scan request with only
Jeff Johnsonb88db982012-12-10 13:34:59 -0800666 2.4GHz valid channel list.
Jeff Johnsone7245742012-09-05 17:12:55 -0700667 \param pMac
668 \param pScanCmd
669 \param pScanRequest
670 \return None
671 -------------------------------------------------------------------------------*/
672static void csrScan2GOnyRequest(tpAniSirGlobal pMac,tSmeCmd *pScanCmd,
673 tCsrScanRequest *pScanRequest)
674{
675 tANI_U8 index, channelId, channelListSize = 0;
676 tANI_U8 channelList2G[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
677 static tANI_U8 validchannelList[CSR_MAX_2_4_GHZ_SUPPORTED_CHANNELS] = {0};
678
679 VOS_ASSERT(pScanCmd && pScanRequest);
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700680 /* To silence the KW tool null check is added */
681 if((pScanCmd == NULL) || (pScanRequest == NULL))
682 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800683 smsLog( pMac, LOGE, FL(" pScanCmd or pScanRequest is NULL "));
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700684 return;
685 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700686
687 if (pScanCmd->u.scanCmd.scanID ||
688 (eCSR_SCAN_REQUEST_FULL_SCAN != pScanRequest->requestType))
689 return;
690
691 //Contsruct valid Supported 2.4 GHz Channel List
692 for( index = 0; index < ARRAY_SIZE(channelList2G); index++ )
693 {
694 channelId = channelList2G[index];
695 if ( csrIsSupportedChannel( pMac, channelId ) )
696 {
697 validchannelList[channelListSize++] = channelId;
698 }
699 }
700
701 pScanRequest->ChannelInfo.numOfChannels = channelListSize;
702 pScanRequest->ChannelInfo.ChannelList = validchannelList;
703}
704
Jeff Johnson295189b2012-06-20 16:38:30 -0700705eHalStatus csrScanRequest(tpAniSirGlobal pMac, tANI_U16 sessionId,
706 tCsrScanRequest *pScanRequest, tANI_U32 *pScanRequestID,
707 csrScanCompleteCallback callback, void *pContext)
708{
709 eHalStatus status = eHAL_STATUS_FAILURE;
710 tSmeCmd *pScanCmd = NULL;
Madan Mohan Koyyalamudicb90bb22012-10-30 18:24:43 -0700711 eCsrConnectState ConnectState;
Jeff Johnson295189b2012-06-20 16:38:30 -0700712
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800713 if(pScanRequest == NULL)
714 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800715 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800716 VOS_ASSERT(0);
717 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700718
Jeff Johnson295189b2012-06-20 16:38:30 -0700719 do
720 {
721 if(pMac->scan.fScanEnable)
722 {
723 pScanCmd = csrGetCommandBuffer(pMac);
724 if(pScanCmd)
725 {
726 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
727 pScanCmd->command = eSmeCommandScan;
728 pScanCmd->sessionId = sessionId;
729 pScanCmd->u.scanCmd.callback = callback;
730 pScanCmd->u.scanCmd.pContext = pContext;
731 if(eCSR_SCAN_REQUEST_11D_SCAN == pScanRequest->requestType)
732 {
733 pScanCmd->u.scanCmd.reason = eCsrScan11d1;
734 }
735 else if((eCSR_SCAN_REQUEST_FULL_SCAN == pScanRequest->requestType) ||
736 (eCSR_SCAN_P2P_DISCOVERY == pScanRequest->requestType)
737#ifdef SOFTAP_CHANNEL_RANGE
738 ||(eCSR_SCAN_SOFTAP_CHANNEL_RANGE == pScanRequest->requestType)
739#endif
740 )
741 {
742 pScanCmd->u.scanCmd.reason = eCsrScanUserRequest;
743 }
744 else if(eCSR_SCAN_HO_BG_SCAN == pScanRequest->requestType)
745 {
746 pScanCmd->u.scanCmd.reason = eCsrScanBgScan;
747 }
748 else if(eCSR_SCAN_HO_PROBE_SCAN == pScanRequest->requestType)
749 {
750 pScanCmd->u.scanCmd.reason = eCsrScanProbeBss;
751 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700752 else if(eCSR_SCAN_P2P_FIND_PEER == pScanRequest->requestType)
753 {
754 pScanCmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
755 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700756 else
757 {
758 pScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
759 }
760 if(pScanRequest->minChnTime == 0 && pScanRequest->maxChnTime == 0)
761 {
762 //The caller doesn't set the time correctly. Set it here
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700763 csrSetDefaultScanTiming(pMac, pScanRequest->scanType, pScanRequest);
764 }
765#ifdef WLAN_AP_STA_CONCURRENCY
766 if(pScanRequest->restTime == 0)
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800767 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700768 //Need to set restTime only if at least one session is connected
769 if(csrIsAnySessionConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700770 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700771 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700772 }
773 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700774#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -0700775 /*For Standalone wlan : channel time will remain the same.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800776 For BTC with A2DP up: Channel time = Channel time * 2 , if station is not already associated.
777 This has been done to provide a larger scan window for faster connection during btc.Else Scan is seen
778 to take a long time.
779 For BTC with A2DP up: Channel time will not be doubled, if station is already associated.
780 */
Jeff Johnson32d95a32012-09-10 13:15:23 -0700781 status = csrRoamGetConnectState(pMac,sessionId,&ConnectState);
Srinivas Girigowdac84c57c2013-02-19 17:41:56 -0800782 if (HAL_STATUS_SUCCESS(status) &&
783 pMac->btc.fA2DPUp &&
Jeff Johnson32d95a32012-09-10 13:15:23 -0700784 (eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED != ConnectState) &&
785 (eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED != ConnectState))
786 {
787 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
788 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
789 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800790
791 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
792 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700793 //Need to make the following atomic
794 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
795
796 if(pScanRequestID)
797 {
798 *pScanRequestID = pScanCmd->u.scanCmd.scanID;
799 }
800
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800801 // If it is the first scan request from HDD, CSR checks if it is for 11d.
Jeff Johnson295189b2012-06-20 16:38:30 -0700802 // If it is not, CSR will save the scan request in the pending cmd queue
803 // & issue an 11d scan request to PE.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800804 if (((0 == pScanCmd->u.scanCmd.scanID)
Jeff Johnson295189b2012-06-20 16:38:30 -0700805 && (eCSR_SCAN_REQUEST_11D_SCAN != pScanRequest->requestType))
806#ifdef SOFTAP_CHANNEL_RANGE
807 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != pScanRequest->requestType)
808#endif
809 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d)
810 )
811 {
812 tSmeCmd *p11dScanCmd;
813 tCsrScanRequest scanReq;
814 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
815
816 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
817
818 p11dScanCmd = csrGetCommandBuffer(pMac);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800819 if (p11dScanCmd)
Jeff Johnson295189b2012-06-20 16:38:30 -0700820 {
821 tANI_U32 numChn = pMac->scan.baseChannels.numChannels;
822
823 palZeroMemory(pMac->hHdd, &p11dScanCmd->u.scanCmd, sizeof(tScanCmd));
824 status = palAllocateMemory( pMac->hHdd, (void **)&pChnInfo->ChannelList, numChn );
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800825 if ( !HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700826 {
827 break;
828 }
829 status = palCopyMemory( pMac->hHdd, pChnInfo->ChannelList,
830 pMac->scan.baseChannels.channelList, numChn );
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800831 if ( !HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700832 {
833 palFreeMemory( pMac->hHdd, pChnInfo->ChannelList );
834 pChnInfo->ChannelList = NULL;
835 break;
836 }
837 pChnInfo->numOfChannels = (tANI_U8)numChn;
838 p11dScanCmd->command = eSmeCommandScan;
839 p11dScanCmd->u.scanCmd.callback = NULL;
840 p11dScanCmd->u.scanCmd.pContext = NULL;
841 p11dScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++;
842 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
843
844 if ( csrIs11dSupported(pMac) )
845 {
846 scanReq.scanType = eSIR_PASSIVE_SCAN;
847 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
848 p11dScanCmd->u.scanCmd.reason = eCsrScan11d1;
849 scanReq.maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
850 scanReq.minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
851 }
852 else
853 {
854 scanReq.scanType = eSIR_ACTIVE_SCAN;
855 scanReq.requestType = eCSR_SCAN_IDLE_MODE_SCAN;
856 p11dScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
857 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
858 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800859
860 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
861 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700862 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700863
Jeff Johnson295189b2012-06-20 16:38:30 -0700864 status = csrScanCopyRequest(pMac, &p11dScanCmd->u.scanCmd.u.scanRequest, &scanReq);
865 //Free the channel list
866 palFreeMemory( pMac->hHdd, pChnInfo->ChannelList );
James Zmuda9ea1edd2013-04-18 18:20:54 -0700867 pChnInfo->ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700868
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800869 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700870 {
871 //Start process the command
872#ifdef WLAN_AP_STA_CONCURRENCY
873 status = csrQueueScanRequest(pMac, p11dScanCmd);
874#else
875 status = csrQueueSmeCommand(pMac, p11dScanCmd, eANI_BOOLEAN_FALSE);
876#endif
877 if( !HAL_STATUS_SUCCESS( status ) )
878 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800879 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700880 break;
881 }
882 }
883 else
884 {
885 break;
886 }
887 }
888 else
889 {
890 //error
891 break;
892 }
893 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700894
895 //Scan only 2G Channels if set in ini file
896 //This is mainly to reduce the First Scan duration
897 //Once we turn on Wifi
898 if(pMac->scan.fFirstScanOnly2GChnl)
899 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800900 smsLog( pMac, LOG1, FL("Scanning only 2G Channels during first scan"));
Jeff Johnsone7245742012-09-05 17:12:55 -0700901 csrScan2GOnyRequest(pMac, pScanCmd, pScanRequest);
902 }
903
Jeff Johnson295189b2012-06-20 16:38:30 -0700904 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
905 if(HAL_STATUS_SUCCESS(status))
906 {
907 //Start process the command
908#ifdef WLAN_AP_STA_CONCURRENCY
909 status = csrQueueScanRequest(pMac,pScanCmd);
910#else
911 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
912#endif
913 if( !HAL_STATUS_SUCCESS( status ) )
914 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800915 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700916 break;
917 }
918 }
919 else
920 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800921 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700922 break;
923 }
924 }
925 else
926 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800927 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700928 break;
929 }
930 }
931 } while(0);
932 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
933 {
934 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
935 {
936 //Set the flag back for restarting idle scan
937 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
938 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800939 smsLog( pMac, LOGE, FL(" failed with status = %d, releasing scan cmd"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700940 csrReleaseCommandScan(pMac, pScanCmd);
941 }
942
943 return (status);
944}
945
946
947eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
948{
949 eHalStatus status = eHAL_STATUS_SUCCESS;
950 tSmeCmd *pScanCmd;
951
952 if(pMac->scan.fScanEnable)
953 {
954 pScanCmd = csrGetCommandBuffer(pMac);
955 if(pScanCmd)
956 {
957 pScanCmd->command = eSmeCommandScan;
958 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
959 pScanCmd->u.scanCmd.callback = NULL;
960 pScanCmd->u.scanCmd.pContext = NULL;
961 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
962 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700963 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700964 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
965 if( !HAL_STATUS_SUCCESS( status ) )
966 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800967 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700968 csrReleaseCommandScan(pMac, pScanCmd);
969 }
970 }
971 else
972 {
973 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800974 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700975 status = eHAL_STATUS_RESOURCES;
976 }
977 }
978
979 return (status);
980}
981
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -0700982#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
983eHalStatus csrScanRequestLfrResult(tpAniSirGlobal pMac, tANI_U32 sessionId,
984 csrScanCompleteCallback callback, void *pContext)
985{
986 eHalStatus status = eHAL_STATUS_SUCCESS;
987 tSmeCmd *pScanCmd;
988
989 if (pMac->scan.fScanEnable)
990 {
991 pScanCmd = csrGetCommandBuffer(pMac);
992 if (pScanCmd)
993 {
994 pScanCmd->command = eSmeCommandScan;
995 pScanCmd->sessionId = sessionId;
996 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
997 pScanCmd->u.scanCmd.callback = callback;
998 pScanCmd->u.scanCmd.pContext = pContext;
999 pScanCmd->u.scanCmd.reason = eCsrScanGetLfrResult;
1000 //Need to make the following atomic
1001 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
1002 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_TRUE);
1003 if ( !HAL_STATUS_SUCCESS( status ) )
1004 {
1005 smsLog( pMac, LOGE, FL(" fail to send message status = %d\n"), status );
1006 csrReleaseCommandScan(pMac, pScanCmd);
1007 }
1008 }
1009 else
1010 {
1011 //log error
1012 smsLog(pMac, LOGE, FL("can not obtain a common buffer\n"));
1013 status = eHAL_STATUS_RESOURCES;
1014 }
1015 }
1016
1017 return (status);
1018}
1019#endif //WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Jeff Johnson295189b2012-06-20 16:38:30 -07001020
1021eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
1022{
1023 eHalStatus status = eHAL_STATUS_SUCCESS;
1024 tANI_U32 scanId;
1025 tCsrScanRequest scanReq;
1026
1027 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
1028 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
1029 scanReq.scanType = eSIR_ACTIVE_SCAN;
1030 scanReq.requestType = reqType;
1031 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1032 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001033 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1034 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001035 //Scan with invalid sessionId.
1036 //This results in SME using the first available session to scan.
1037 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
1038 &scanId, NULL, NULL);
1039
1040 return (status);
1041}
1042
1043
1044
1045
1046eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
1047{
1048 eHalStatus status = eHAL_STATUS_FAILURE;
1049 tScanResultHandle hBSSList = NULL;
1050 tCsrScanResultFilter *pScanFilter = NULL;
1051 tANI_U32 roamId = 0;
1052 tCsrRoamProfile *pProfile = NULL;
1053 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1054
Jeff Johnson32d95a32012-09-10 13:15:23 -07001055 if(!pSession)
1056 {
1057 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1058 return eHAL_STATUS_FAILURE;
1059 }
1060
Jeff Johnson295189b2012-06-20 16:38:30 -07001061 do
1062 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001063 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -07001064 if(pSession->fCancelRoaming)
1065 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001066 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -07001067 csrScanStartIdleScan(pMac);
1068 status = eHAL_STATUS_SUCCESS;
1069 break;
1070 }
1071 //Here is the profile we need to connect to
1072 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1073 if(!HAL_STATUS_SUCCESS(status))
1074 break;
1075 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1076 if(NULL == pSession->pCurRoamProfile)
1077 {
1078 pScanFilter->EncryptionType.numEntries = 1;
1079 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1080 }
1081 else
1082 {
1083 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
1084 status = palAllocateMemory(pMac->hHdd, (void **)&pProfile, sizeof(tCsrRoamProfile));
1085 if(!HAL_STATUS_SUCCESS(status))
1086 break;
1087 palZeroMemory(pMac->hHdd, pProfile, sizeof(tCsrRoamProfile));
1088 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1089 if(!HAL_STATUS_SUCCESS(status))
1090 break;
1091 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1092 }//We have a profile
1093 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1094 if(HAL_STATUS_SUCCESS(status))
1095 {
1096 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1097 if(HAL_STATUS_SUCCESS(status))
1098 {
1099 if(eCsrLostLink1 == reason)
1100 {
1101 //we want to put the last connected BSS to the very beginning, if possible
1102 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1103 }
1104 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1105 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1106 if(!HAL_STATUS_SUCCESS(status))
1107 {
1108 csrScanResultPurge(pMac, hBSSList);
1109 }
1110 }//Have scan result
1111 }
1112 }while(0);
1113 if(pScanFilter)
1114 {
1115 //we need to free memory for filter if profile exists
1116 csrFreeScanFilter(pMac, pScanFilter);
1117 palFreeMemory(pMac->hHdd, pScanFilter);
1118 }
1119 if(NULL != pProfile)
1120 {
1121 csrReleaseProfile(pMac, pProfile);
1122 palFreeMemory(pMac->hHdd, (void *)pProfile);
1123 }
1124
1125 return (status);
1126}
1127
1128
Jeff Johnson32d95a32012-09-10 13:15:23 -07001129eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, void *callback, void *pContext)
Jeff Johnson295189b2012-06-20 16:38:30 -07001130{
1131 eHalStatus status = eHAL_STATUS_SUCCESS;
1132 tSmeCmd *pScanCmd;
1133
1134 if(pMac->scan.fScanEnable)
1135 {
1136 pScanCmd = csrGetCommandBuffer(pMac);
1137 if(pScanCmd)
1138 {
1139 pScanCmd->command = eSmeCommandScan;
1140 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
Jeff Johnson32d95a32012-09-10 13:15:23 -07001141 pScanCmd->u.scanCmd.callback = callback;
1142 pScanCmd->u.scanCmd.pContext = pContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07001143 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1144 //Need to make the following atomic
1145 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
1146 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1147 if( !HAL_STATUS_SUCCESS( status ) )
1148 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001149 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001150 csrReleaseCommandScan(pMac, pScanCmd);
1151 }
1152 }
1153 else
1154 {
1155 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001156 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001157 status = eHAL_STATUS_RESOURCES;
1158 }
1159 }
1160
1161 return (status);
1162}
1163
1164
1165eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1166{
1167 eHalStatus status = eHAL_STATUS_FAILURE;
1168 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1169
Jeff Johnson32d95a32012-09-10 13:15:23 -07001170 if(!pSession)
1171 {
1172 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1173 return eHAL_STATUS_FAILURE;
1174 }
1175
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001176 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001177 if(pSession->fCancelRoaming)
1178 {
1179 csrScanStartIdleScan(pMac);
1180 }
1181 else if(pSession->pCurRoamProfile)
1182 {
1183 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1184 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1185 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1186 {
1187 //try lostlink scan2
1188 status = csrScanRequestLostLink2(pMac, sessionId);
1189 }
1190 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1191 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1192 {
1193 //go straight to lostlink scan3
1194 status = csrScanRequestLostLink3(pMac, sessionId);
1195 }
1196 else
1197 {
1198 //we are done with lostlink
1199 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1200 {
1201 csrScanStartIdleScan(pMac);
1202 }
1203 status = eHAL_STATUS_SUCCESS;
1204 }
1205 }
1206 else
1207 {
1208 status = csrScanRequestLostLink3(pMac, sessionId);
1209 }
1210
1211 return (status);
1212}
1213
1214
1215
1216eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1217{
1218 eHalStatus status = eHAL_STATUS_FAILURE;
1219 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1220
Jeff Johnson32d95a32012-09-10 13:15:23 -07001221 if(!pSession)
1222 {
1223 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1224 return eHAL_STATUS_FAILURE;
1225 }
1226
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001227 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001228 if(pSession->fCancelRoaming)
1229 {
1230 csrScanStartIdleScan(pMac);
1231 }
1232 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1233 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1234 {
1235 //try lostlink scan3
1236 status = csrScanRequestLostLink3(pMac, sessionId);
1237 }
1238 else
1239 {
1240 //we are done with lostlink
1241 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1242 {
1243 csrScanStartIdleScan(pMac);
1244 }
1245 }
1246
1247 return (status);
1248}
1249
1250
1251
1252eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1253{
1254 eHalStatus status = eHAL_STATUS_SUCCESS;
1255
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001256 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001257 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1258 {
1259 //we are done with lostlink
1260 csrScanStartIdleScan(pMac);
1261 }
1262
1263 return (status);
1264}
1265
1266
1267
1268
1269//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1270//If no roam profile (it should not), it is like lostlinkscan3
1271eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1272{
1273 eHalStatus status = eHAL_STATUS_SUCCESS;
1274 tSmeCmd *pCommand = NULL;
1275 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1276 tCsrScanResultFilter *pScanFilter = NULL;
1277 tScanResultHandle hBSSList = NULL;
1278 tCsrScanResultInfo *pScanResult = NULL;
1279 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1280
Jeff Johnson32d95a32012-09-10 13:15:23 -07001281 if(!pSession)
1282 {
1283 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1284 return eHAL_STATUS_FAILURE;
1285 }
1286
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001287 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001288 do
1289 {
1290 pCommand = csrGetCommandBuffer(pMac);
1291 if(!pCommand)
1292 {
1293 status = eHAL_STATUS_RESOURCES;
1294 break;
1295 }
1296 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
1297 pCommand->command = eSmeCommandScan;
1298 pCommand->sessionId = (tANI_U8)sessionId;
1299 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1300 pCommand->u.scanCmd.callback = NULL;
1301 pCommand->u.scanCmd.pContext = NULL;
1302 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1303 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001304 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1305 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001306 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1307 if(pSession->connectedProfile.SSID.length)
1308 {
1309 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
1310 if(!HAL_STATUS_SUCCESS(status))
1311 {
1312 break;
1313 }
1314 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
1315 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1316 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
1317 }
1318 else
1319 {
1320 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1321 }
1322 if(pSession->pCurRoamProfile)
1323 {
1324 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1325 if(!HAL_STATUS_SUCCESS(status))
1326 {
1327 break;
1328 }
1329 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1330 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1331 if(!HAL_STATUS_SUCCESS(status))
1332 {
1333 break;
1334 }
1335 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1336 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1337 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1338 {
1339 tANI_U8 i, nChn = 0;
1340 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
1341 WNI_CFG_VALID_CHANNEL_LIST_LEN);
1342 if(!HAL_STATUS_SUCCESS(status))
1343 {
1344 break;
1345 }
1346 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1347 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1348 {
1349 for(i = 0; i < nChn; i++)
1350 {
1351 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1352 pScanResult->BssDescriptor.channelId)
1353 {
1354 break;
1355 }
1356 }
1357 if(i == nChn)
1358 {
1359 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1360 }
1361 }
1362 //Include the last connected BSS' channel
1363 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1364 {
1365 for(i = 0; i < nChn; i++)
1366 {
1367 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1368 pSession->connectedProfile.operationChannel)
1369 {
1370 break;
1371 }
1372 }
1373 if(i == nChn)
1374 {
1375 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1376 }
1377 }
1378 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1379 }
1380 else
1381 {
1382 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1383 {
1384 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
1385 1);
1386 //just try the last connected channel
1387 if(HAL_STATUS_SUCCESS(status))
1388 {
1389 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1390 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1391 }
1392 else
1393 {
1394 break;
1395 }
1396 }
1397 }
1398 }
1399 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
1400 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1401 if( !HAL_STATUS_SUCCESS( status ) )
1402 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001403 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001404 break;
1405 }
1406 } while( 0 );
1407
1408 if(!HAL_STATUS_SUCCESS(status))
1409 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001410 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001411 if(pCommand)
1412 {
1413 csrReleaseCommandScan(pMac, pCommand);
1414 }
1415 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1416 }
1417 if(pScanFilter)
1418 {
1419 csrFreeScanFilter(pMac, pScanFilter);
1420 palFreeMemory(pMac->hHdd, pScanFilter);
1421 }
1422 if(hBSSList)
1423 {
1424 csrScanResultPurge(pMac, hBSSList);
1425 }
1426
1427 return( status );
1428}
1429
1430
1431//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1432//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1433eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1434{
1435 eHalStatus status = eHAL_STATUS_SUCCESS;
1436 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1437 tCsrScanResultFilter *pScanFilter = NULL;
1438 tScanResultHandle hBSSList = NULL;
1439 tCsrScanResultInfo *pScanResult = NULL;
1440 tSmeCmd *pCommand = NULL;
1441 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1442
Jeff Johnson32d95a32012-09-10 13:15:23 -07001443 if(!pSession)
1444 {
1445 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1446 return eHAL_STATUS_FAILURE;
1447 }
1448
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001449 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001450 do
1451 {
1452 pCommand = csrGetCommandBuffer(pMac);
1453 if(!pCommand)
1454 {
1455 status = eHAL_STATUS_RESOURCES;
1456 break;
1457 }
1458 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
1459 pCommand->command = eSmeCommandScan;
1460 pCommand->sessionId = (tANI_U8)sessionId;
1461 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1462 pCommand->u.scanCmd.callback = NULL;
1463 pCommand->u.scanCmd.pContext = NULL;
1464 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1465 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001466 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1467 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001468 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1469 if(pSession->pCurRoamProfile)
1470 {
1471 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1472 if(!HAL_STATUS_SUCCESS(status))
1473 {
1474 break;
1475 }
1476 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1477 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1478 if(!HAL_STATUS_SUCCESS(status))
1479 {
1480 break;
1481 }
1482 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1483 if(!HAL_STATUS_SUCCESS(status))
1484 {
1485 break;
1486 }
1487 if(hBSSList)
1488 {
1489 tANI_U8 i, nChn = 0;
1490 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
1491 WNI_CFG_VALID_CHANNEL_LIST_LEN);
1492 if(!HAL_STATUS_SUCCESS(status))
1493 {
1494 break;
1495 }
1496 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1497 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1498 {
1499 for(i = 0; i < nChn; i++)
1500 {
1501 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1502 pScanResult->BssDescriptor.channelId)
1503 {
1504 break;
1505 }
1506 }
1507 if(i == nChn)
1508 {
1509 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1510 }
1511 }
1512 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1513 }
1514 }
1515 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
1516 //Put to the head in pending queue
1517 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1518 if( !HAL_STATUS_SUCCESS( status ) )
1519 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001520 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001521 break;
1522 }
1523 } while( 0 );
1524
1525 if(!HAL_STATUS_SUCCESS(status))
1526 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001527 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001528 if(pCommand)
1529 {
1530 csrReleaseCommandScan(pMac, pCommand);
1531 }
1532 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1533 }
1534 if(pScanFilter)
1535 {
1536 csrFreeScanFilter(pMac, pScanFilter);
1537 palFreeMemory(pMac->hHdd, pScanFilter);
1538 }
1539 if(hBSSList)
1540 {
1541 csrScanResultPurge(pMac, hBSSList);
1542 }
1543
1544 return( status );
1545}
1546
1547
1548//To actively scan all valid channels
1549eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1550{
1551 eHalStatus status = eHAL_STATUS_SUCCESS;
1552 tSmeCmd *pCommand;
1553 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1554
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001555 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001556 do
1557 {
1558 pCommand = csrGetCommandBuffer(pMac);
1559 if(!pCommand)
1560 {
1561 status = eHAL_STATUS_RESOURCES;
1562 break;
1563 }
1564 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
1565 pCommand->command = eSmeCommandScan;
1566 pCommand->sessionId = (tANI_U8)sessionId;
1567 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1568 pCommand->u.scanCmd.callback = NULL;
1569 pCommand->u.scanCmd.pContext = NULL;
1570 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1571 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001572 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1573 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001574 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1575 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
1576 //Put to the head of pending queue
1577 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1578 if( !HAL_STATUS_SUCCESS( status ) )
1579 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001580 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001581 break;
1582 }
1583 } while( 0 );
1584 if(!HAL_STATUS_SUCCESS(status))
1585 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001586 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001587 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1588 {
1589 csrScanStartIdleScan(pMac);
1590 }
1591 if(pCommand)
1592 {
1593 csrReleaseCommandScan(pMac, pCommand);
1594 }
1595 }
1596
1597 return( status );
1598}
1599
1600
1601eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1602{
1603 eHalStatus status = eHAL_STATUS_FAILURE;
1604 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1605 tCsrScanResultFilter *pScanFilter = NULL;
1606 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1607 tANI_U32 sessionId = pCommand->sessionId;
1608#ifdef FEATURE_WLAN_BTAMP_UT_RF
1609 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1610#endif
1611 do
1612 {
1613 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1614 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1615 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001616 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001617 break;
1618 }
1619 if(pProfile == NULL)
1620 break;
1621 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1622 if(!HAL_STATUS_SUCCESS(status))
1623 break;
1624 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1625 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1626 if(!HAL_STATUS_SUCCESS(status))
1627 break;
1628 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1629 if(!HAL_STATUS_SUCCESS(status))
1630 break;
1631 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1632 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1633 if(!HAL_STATUS_SUCCESS(status))
1634 {
1635 break;
1636 }
1637 }while(0);
1638 if(!HAL_STATUS_SUCCESS(status))
1639 {
1640 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1641 {
1642 csrScanResultPurge(pMac, hBSSList);
1643 }
1644 //We haven't done anything to this profile
1645 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId,
1646 eCSR_ROAM_ASSOCIATION_FAILURE, eCSR_ROAM_RESULT_FAILURE);
1647 //In case we have nothing else to do, restart idle scan
1648 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1649 {
1650 status = csrScanStartIdleScan(pMac);
1651 }
1652#ifdef FEATURE_WLAN_BTAMP_UT_RF
1653 //In case of WDS station, let it retry.
1654 if( CSR_IS_WDS_STA(pProfile) )
1655 {
1656 //Save the roma profile so we can retry
1657 csrFreeRoamProfile( pMac, sessionId );
1658 if (HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd,
1659 (void **)&pSession->pCurRoamProfile,
1660 sizeof(tCsrRoamProfile))))
1661 {
1662 palZeroMemory(pMac->hHdd, pSession->pCurRoamProfile, sizeof(tCsrRoamProfile));
1663 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1664 }
1665 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1666 }
1667#endif
1668 }
1669 if(pScanFilter)
1670 {
1671 csrFreeScanFilter(pMac, pScanFilter);
1672 palFreeMemory(pMac->hHdd, pScanFilter);
1673 }
1674
1675 return (status);
1676}
1677
1678
1679eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1680{
1681 eHalStatus status = eHAL_STATUS_SUCCESS;
1682 tANI_U32 sessionId = pCommand->sessionId;
1683 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1684 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1685
Jeff Johnson32d95a32012-09-10 13:15:23 -07001686 if(!pSession)
1687 {
1688 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1689 return eHAL_STATUS_FAILURE;
1690 }
1691
Jeff Johnson295189b2012-06-20 16:38:30 -07001692#if defined(WLAN_DEBUG)
1693 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1694 {
1695 char str[36];
1696 palCopyMemory(pMac->hHdd, str, pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1697 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
1698 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001699 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001700 }
1701#endif
1702 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1703 if(pProfile && CSR_IS_START_IBSS(pProfile))
1704 {
1705 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1706 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1707 if(!HAL_STATUS_SUCCESS(status))
1708 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001709 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001710 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1711 }
1712 }
1713 else
1714 {
1715 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1716
1717 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1718 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1719 {
1720 status = csrScanStartIdleScan(pMac);
1721 }
1722 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1723 {
1724 //Only indicate assoc_completion if we indicate assoc_start.
1725 if(pSession->bRefAssocStartCnt > 0)
1726 {
1727 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
1728 palZeroMemory(pMac->hHdd, &roamInfo, sizeof(tCsrRoamInfo));
1729 pRoamInfo = &roamInfo;
1730 if(pCommand->u.roamCmd.pRoamBssEntry)
1731 {
1732 tCsrScanResult *pScanResult =
1733 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1734 tCsrScanResult, Link);
1735 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1736 }
1737 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1738 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1739 pSession->bRefAssocStartCnt--;
1740 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1741 pCommand->u.scanCmd.roamId,
1742 eCSR_ROAM_ASSOCIATION_COMPLETION,
1743 eCSR_ROAM_RESULT_FAILURE);
1744 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001745 else
1746 {
1747 csrRoamCallCallback(pMac, sessionId, NULL,
1748 pCommand->u.scanCmd.roamId,
1749 eCSR_ROAM_ASSOCIATION_FAILURE,
1750 eCSR_ROAM_RESULT_FAILURE);
1751 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001752#ifdef FEATURE_WLAN_BTAMP_UT_RF
1753 //In case of WDS station, let it retry.
1754 if( CSR_IS_WDS_STA(pProfile) )
1755 {
1756 //Save the roma profile so we can retry
1757 csrFreeRoamProfile( pMac, sessionId );
1758 if (HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd,
1759 (void **)&pSession->pCurRoamProfile,
1760 sizeof(tCsrRoamProfile))))
1761 {
1762 palZeroMemory(pMac->hHdd, pSession->pCurRoamProfile, sizeof(tCsrRoamProfile));
1763 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1764 }
1765 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1766 }
1767#endif
1768 }
1769 else
1770 {
1771 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1772 }
1773 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1774 }
1775
1776 return (status);
1777}
1778
1779
1780//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1781eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1782{
1783 eHalStatus status = eHAL_STATUS_FAILURE;
1784 tScanResultHandle hBSSList = NULL;
1785 tCsrScanResultFilter *pScanFilter = NULL;
1786 tANI_U32 roamId = 0;
1787 tCsrRoamProfile *pProfile = NULL;
1788 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1789
1790 do
1791 {
1792 //Here is the profile we need to connect to
1793 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1794 if(!HAL_STATUS_SUCCESS(status))
1795 break;
1796 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1797 if(NULL == pSession) break;
1798 if(NULL == pSession->pCurRoamProfile)
1799 {
1800 pScanFilter->EncryptionType.numEntries = 1;
1801 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1802 }
1803 else
1804 {
1805 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
1806 status = palAllocateMemory(pMac->hHdd, (void **)&pProfile, sizeof(tCsrRoamProfile));
1807 if(!HAL_STATUS_SUCCESS(status))
1808 break;
1809 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1810 if(!HAL_STATUS_SUCCESS(status))
1811 break;
1812 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1813 }//We have a profile
1814 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1815 if(HAL_STATUS_SUCCESS(status))
1816 {
1817 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1818 if(HAL_STATUS_SUCCESS(status))
1819 {
1820 //we want to put the last connected BSS to the very beginning, if possible
1821 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1822 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1823 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1824 if(!HAL_STATUS_SUCCESS(status))
1825 {
1826 csrScanResultPurge(pMac, hBSSList);
1827 }
1828 }//Have scan result
1829 else
1830 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001831 smsLog(pMac, LOGW, FL("cannot find matching BSS of %02X-%02X-%02X-%02X-%02X-%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001832 pSession->connectedProfile.bssid[0],
1833 pSession->connectedProfile.bssid[1],
1834 pSession->connectedProfile.bssid[2],
1835 pSession->connectedProfile.bssid[3],
1836 pSession->connectedProfile.bssid[4],
1837 pSession->connectedProfile.bssid[5]);
1838 //Disconnect
1839 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1840 }
1841 }
1842 }while(0);
1843 if(pScanFilter)
1844 {
1845 csrFreeScanFilter(pMac, pScanFilter);
1846 palFreeMemory(pMac->hHdd, pScanFilter);
1847 }
1848 if(NULL != pProfile)
1849 {
1850 csrReleaseProfile(pMac, pProfile);
1851 palFreeMemory(pMac->hHdd, pProfile);
1852 }
1853
1854 return (status);
1855}
1856
1857
1858
1859eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
1860{
1861 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
1862 tScanResultList *pScanList = (tScanResultList *)hScanList;
1863
1864 if(pScanList)
1865 {
1866 status = csrLLScanPurgeResult(pMac, &pScanList->List);
1867 csrLLClose(&pScanList->List);
1868 palFreeMemory(pMac->hHdd, pScanList);
1869 }
1870 return (status);
1871}
1872
1873
1874static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
1875{
1876 tANI_U32 ret = 0;
1877 int i = CSR_NUM_RSSI_CAT - 1;
1878
1879 while(i >= 0)
1880 {
1881 if(rssi >= pMac->roam.configParam.RSSICat[i])
1882 {
1883 ret = pMac->roam.configParam.BssPreferValue[i];
1884 break;
1885 }
1886 i--;
1887 };
1888
1889 return (ret);
1890}
1891
1892
1893//Return a CapValue base on the capabilities of a BSS
1894static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
1895{
1896 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08001897#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
1898 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
1899 {
1900 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
1901 {
1902 ret += CSR_BSS_CAP_VALUE_5GHZ;
1903 }
1904 }
1905#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001906 if( pIes )
1907 {
1908 //We only care about 11N capability
1909 if(pIes->HTCaps.present)
1910 {
1911 ret += CSR_BSS_CAP_VALUE_HT;
1912 }
1913 if(CSR_IS_QOS_BSS(pIes))
1914 {
1915 ret += CSR_BSS_CAP_VALUE_WMM;
1916 //Give advantage to UAPSD
1917 if(CSR_IS_UAPSD_BSS(pIes))
1918 {
1919 ret += CSR_BSS_CAP_VALUE_UAPSD;
1920 }
1921 }
1922 }
1923
1924 return (ret);
1925}
1926
1927
1928//To check whther pBss1 is better than pBss2
1929static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
1930{
1931 tANI_BOOLEAN ret;
1932
1933 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
1934 {
1935 ret = eANI_BOOLEAN_TRUE;
1936 }
1937 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
1938 {
1939 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
1940 {
1941 ret = eANI_BOOLEAN_TRUE;
1942 }
1943 else
1944 {
1945 ret = eANI_BOOLEAN_FALSE;
1946 }
1947 }
1948 else
1949 {
1950 ret = eANI_BOOLEAN_FALSE;
1951 }
1952
1953 return (ret);
1954}
1955
1956
Srikant Kuppa866893f2012-12-27 17:28:14 -08001957#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001958//Add the channel to the occupiedChannels array
1959static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08001960 tpAniSirGlobal pMac,
1961 tCsrScanResult *pResult,
1962 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001963 tDot11fBeaconIEs *pIes)
1964{
1965 eHalStatus status;
1966 tANI_U8 channel;
1967 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
1968 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
1969
1970 channel = pResult->Result.BssDescriptor.channelId;
1971
1972 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08001973 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001974 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08001975 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001976 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08001977 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001978 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001979 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08001980 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08001981 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
1982 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
1983 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001984 }
1985}
1986#endif
1987
Jeff Johnson295189b2012-06-20 16:38:30 -07001988//Put the BSS into the scan result list
1989//pIes can not be NULL
1990static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
1991{
Srinivas28b5b4e2012-12-12 13:07:53 -08001992#ifdef FEATURE_WLAN_LFR
1993 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
1994#endif
1995
Jeff Johnson295189b2012-06-20 16:38:30 -07001996 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
1997 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
1998 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08001999#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08002000 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
2001 {
2002 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
2003 NOT set in the cfg.ini file */
2004 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
2005 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002006#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002007}
2008
2009
2010eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2011{
2012 eHalStatus status;
2013 tScanResultList *pRetList;
2014 tCsrScanResult *pResult, *pBssDesc;
2015 tANI_U32 count = 0;
2016 tListElem *pEntry;
2017 tANI_U32 bssLen, allocLen;
2018 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2019 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2020 tDot11fBeaconIEs *pIes, *pNewIes;
2021 tANI_BOOLEAN fMatch;
2022
2023 if(phResult)
2024 {
2025 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2026 }
2027 status = palAllocateMemory(pMac->hHdd, (void **)&pRetList, sizeof(tScanResultList));
2028 if(HAL_STATUS_SUCCESS(status))
2029 {
2030 palZeroMemory(pMac->hHdd, pRetList, sizeof(tScanResultList));
2031 csrLLOpen(pMac->hHdd, &pRetList->List);
2032 pRetList->pCurEntry = NULL;
2033
2034 csrLLLock(&pMac->scan.scanResultList);
2035 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2036 while( pEntry )
2037 {
2038 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2039 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2040 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2041 //for any error condition, otherwiase, it will be freed later.
2042 //reset
2043 fMatch = eANI_BOOLEAN_FALSE;
2044 pNewIes = NULL;
2045
2046 if(pFilter)
2047 {
2048 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2049 if( NULL != pIes )
2050 {
2051 //Only save it when matching
2052 if(fMatch)
2053 {
2054 if( !pBssDesc->Result.pvIes )
2055 {
2056 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2057 pNewIes = pIes;
2058 }
2059 else
2060 {
2061 //The pIes is allocated by someone else. make a copy
2062 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2063 //is using to for association, hence save the parsed IEs
2064 status = palAllocateMemory(pMac->hHdd, (void **)&pNewIes, sizeof(tDot11fBeaconIEs));
2065 if( HAL_STATUS_SUCCESS( status ) )
2066 {
2067 palCopyMemory( pMac->hHdd, pNewIes, pIes, sizeof( tDot11fBeaconIEs ) );
2068 }
2069 else
2070 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002071 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002072 //Need to free memory allocated by csrMatchBSS
2073 if( !pBssDesc->Result.pvIes )
2074 {
2075 palFreeMemory(pMac->hHdd, pIes);
2076 }
2077 break;
2078 }
2079 }
2080 }//fMatch
2081 else if( !pBssDesc->Result.pvIes )
2082 {
2083 palFreeMemory(pMac->hHdd, pIes);
2084 }
2085 }
2086 }
2087 if(NULL == pFilter || fMatch)
2088 {
2089 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2090 allocLen = sizeof( tCsrScanResult ) + bssLen;
2091 status = palAllocateMemory(pMac->hHdd, (void **)&pResult, allocLen);
2092 if(!HAL_STATUS_SUCCESS(status))
2093 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002094 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002095 if(pNewIes)
2096 {
2097 palFreeMemory(pMac->hHdd, pNewIes);
2098 }
2099 break;
2100 }
2101 palZeroMemory(pMac->hHdd, pResult, allocLen);
2102 pResult->capValue = pBssDesc->capValue;
2103 pResult->preferValue = pBssDesc->preferValue;
2104 pResult->ucEncryptionType = uc;
2105 pResult->mcEncryptionType = mc;
2106 pResult->authType = auth;
2107 pResult->Result.ssId = pBssDesc->Result.ssId;
2108 pResult->Result.timer = 0;
2109 //save the pIes for later use
2110 pResult->Result.pvIes = pNewIes;
2111 //save bss description
2112 status = palCopyMemory(pMac->hHdd, &pResult->Result.BssDescriptor, &pBssDesc->Result.BssDescriptor, bssLen);
2113 if(!HAL_STATUS_SUCCESS(status))
2114 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002115 smsLog(pMac, LOGE, FL(" fail to copy memory for scan result"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002116 palFreeMemory(pMac->hHdd, pResult);
2117 if(pNewIes)
2118 {
2119 palFreeMemory(pMac->hHdd, pNewIes);
2120 }
2121 break;
2122 }
2123 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2124 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2125 {
2126 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2127 }
2128 else
2129 {
2130 //To sort the list
2131 tListElem *pTmpEntry;
2132 tCsrScanResult *pTmpResult;
2133
2134 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2135 while(pTmpEntry)
2136 {
2137 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
2138 if(csrIsBetterBss(pResult, pTmpResult))
2139 {
2140 csrLLInsertEntry(&pRetList->List, pTmpEntry, &pResult->Link, LL_ACCESS_NOLOCK);
2141 //To indicate we are done
2142 pResult = NULL;
2143 break;
2144 }
2145 pTmpEntry = csrLLNext(&pRetList->List, pTmpEntry, LL_ACCESS_NOLOCK);
2146 }
2147 if(pResult != NULL)
2148 {
2149 //This one is not better than any one
2150 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2151 }
2152 }
2153 count++;
2154 }
2155 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2156 }//while
2157 csrLLUnlock(&pMac->scan.scanResultList);
2158
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002159 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002160
2161 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2162 {
2163 //Fail or No one wants the result.
2164 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2165 }
2166 else
2167 {
2168 if(0 == count)
2169 {
2170 //We are here meaning the there is no match
2171 csrLLClose(&pRetList->List);
2172 palFreeMemory(pMac->hHdd, pRetList);
2173 status = eHAL_STATUS_E_NULL_VALUE;
2174 }
2175 else if(phResult)
2176 {
2177 *phResult = pRetList;
2178 }
2179 }
2180 }//Allocated pRetList
2181
2182 return (status);
2183}
2184
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002185/*
2186 * NOTE: This routine is being added to make
2187 * sure that scan results are not being flushed
2188 * while roaming. If the scan results are flushed,
2189 * we are unable to recover from
2190 * csrRoamRoamingStateDisassocRspProcessor.
2191 * If it is needed to remove this routine,
2192 * first ensure that we recover gracefully from
2193 * csrRoamRoamingStateDisassocRspProcessor if
2194 * csrScanGetResult returns with a failure because
2195 * of not being able to find the roaming BSS.
2196 */
2197tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2198{
2199 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2200 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2201 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2202 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2203 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2204 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2205 default:
2206 return 0;
2207 }
2208}
2209
Jeff Johnson295189b2012-06-20 16:38:30 -07002210eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2211{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002212 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
2213 if (isFlushDenied) {
2214 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2215 __func__, isFlushDenied);
2216 return eHAL_STATUS_FAILURE;
2217 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002218 return ( csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList) );
2219}
2220
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302221eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002222{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302223 eHalStatus status = eHAL_STATUS_SUCCESS;
2224 tListElem *pEntry,*pFreeElem;
2225 tCsrScanResult *pBssDesc;
2226 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002227
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302228 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002229
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302230 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2231 while( pEntry != NULL)
2232 {
2233 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2234 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2235 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002236 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302237 pFreeElem = pEntry;
2238 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2239 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2240 csrFreeScanResultEntry( pMac, pBssDesc );
2241 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002242 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302243 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2244 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002245
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302246 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002247
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302248 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002249}
2250
Jeff Johnson295189b2012-06-20 16:38:30 -07002251/**
2252 * csrCheck11dChannel
2253 *
2254 *FUNCTION:
2255 * This function is called from csrScanFilter11dResult function and
2256 * compare channel number with given channel list.
2257 *
2258 *LOGIC:
2259 * Check Scan result channel number with CFG channel list
2260 *
2261 *ASSUMPTIONS:
2262 *
2263 *
2264 *NOTE:
2265 *
2266 * @param channelId channel number
2267 * @param pChannelList Pointer to channel list
2268 * @param numChannels Number of channel in channel list
2269 *
2270 * @return Status
2271 */
2272
2273eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2274{
2275 eHalStatus status = eHAL_STATUS_FAILURE;
2276 tANI_U8 i = 0;
2277
2278 for (i = 0; i < numChannels; i++)
2279 {
2280 if(pChannelList[ i ] == channelId)
2281 {
2282 status = eHAL_STATUS_SUCCESS;
2283 break;
2284 }
2285 }
2286 return status;
2287}
2288
2289/**
2290 * csrScanFilter11dResult
2291 *
2292 *FUNCTION:
2293 * This function is called from csrApplyCountryInformation function and
2294 * filter scan result based on valid channel list number.
2295 *
2296 *LOGIC:
2297 * Get scan result from scan list and Check Scan result channel number
2298 * with 11d channel list if channel number is found in 11d channel list
2299 * then do not remove scan result entry from scan list
2300 *
2301 *ASSUMPTIONS:
2302 *
2303 *
2304 *NOTE:
2305 *
2306 * @param pMac Pointer to Global MAC structure
2307 *
2308 * @return Status
2309 */
2310
2311eHalStatus csrScanFilter11dResult(tpAniSirGlobal pMac)
2312{
2313 eHalStatus status = eHAL_STATUS_SUCCESS;
2314 tListElem *pEntry,*pTempEntry;
2315 tCsrScanResult *pBssDesc;
2316 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2317
2318 /* Get valid channels list from CFG */
2319 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2320 pMac->roam.validChannelList, &len)))
2321 {
2322 smsLog( pMac, LOG1, "Failed to get Channel list from CFG");
2323 }
2324
2325 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2326 while( pEntry )
2327 {
2328 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2329 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
2330 LL_ACCESS_LOCK );
2331 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2332 pMac->roam.validChannelList, len))
2333 {
2334 /* Remove Scan result which does not have 11d channel */
2335 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2336 LL_ACCESS_LOCK ))
2337 {
2338 csrFreeScanResultEntry( pMac, pBssDesc );
2339 }
2340 }
2341 pEntry = pTempEntry;
2342 }
2343 return status;
2344}
2345
2346
2347eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
2348{
2349 eHalStatus status = eHAL_STATUS_SUCCESS;
2350 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
2351 tCsrScanResult *pResult, *pScanResult;
2352 tANI_U32 count = 0;
2353 tListElem *pEntry;
2354 tANI_U32 bssLen, allocLen;
2355
2356 if(phResult)
2357 {
2358 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2359 }
2360 status = palAllocateMemory(pMac->hHdd, (void **)&pRetList, sizeof(tScanResultList));
2361 if(HAL_STATUS_SUCCESS(status))
2362 {
2363 palZeroMemory(pMac->hHdd, pRetList, sizeof(tScanResultList));
2364 csrLLOpen(pMac->hHdd, &pRetList->List);
2365 pRetList->pCurEntry = NULL;
2366 csrLLLock(&pMac->scan.scanResultList);
2367 csrLLLock(&pInList->List);
2368
2369 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
2370 while( pEntry )
2371 {
2372 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2373 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
2374 allocLen = sizeof( tCsrScanResult ) + bssLen;
2375 status = palAllocateMemory(pMac->hHdd, (void **)&pResult, allocLen);
2376 if(!HAL_STATUS_SUCCESS(status))
2377 {
2378 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2379 count = 0;
2380 break;
2381 }
2382 palZeroMemory(pMac->hHdd, pResult, allocLen);
2383 status = palCopyMemory(pMac->hHdd, &pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
2384 if(!HAL_STATUS_SUCCESS(status))
2385 {
2386 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2387 count = 0;
2388 break;
2389 }
2390 if( pScanResult->Result.pvIes )
2391 {
2392 status = palAllocateMemory(pMac->hHdd, (void **)&pResult->Result.pvIes, sizeof( tDot11fBeaconIEs ));
2393 if(!HAL_STATUS_SUCCESS(status))
2394 {
2395 //Free the memory we allocate above first
2396 palFreeMemory( pMac->hHdd, pResult );
2397 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2398 count = 0;
2399 break;
2400 }
2401 status = palCopyMemory(pMac->hHdd, pResult->Result.pvIes,
2402 pScanResult->Result.pvIes, sizeof( tDot11fBeaconIEs ));
2403 if(!HAL_STATUS_SUCCESS(status))
2404 {
2405 //Free the memory we allocate above first
2406 palFreeMemory( pMac->hHdd, pResult );
2407 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2408 count = 0;
2409 break;
2410 }
2411 }
2412 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
2413 count++;
2414 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
2415 }//while
2416 csrLLUnlock(&pInList->List);
2417 csrLLUnlock(&pMac->scan.scanResultList);
2418
2419 if(HAL_STATUS_SUCCESS(status))
2420 {
2421 if(0 == count)
2422 {
2423 csrLLClose(&pRetList->List);
2424 palFreeMemory(pMac->hHdd, pRetList);
2425 status = eHAL_STATUS_E_NULL_VALUE;
2426 }
2427 else if(phResult)
2428 {
2429 *phResult = pRetList;
2430 }
2431 }
2432 }//Allocated pRetList
2433
2434 return (status);
2435}
2436
2437
2438
2439eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
2440{
2441 eHalStatus status = eHAL_STATUS_SUCCESS;
2442 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
2443
2444 if((eWNI_SME_SCAN_RSP == pMsg->type) || (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
2445 {
2446 status = csrScanSmeScanResponse( pMac, pMsgBuf );
2447 }
2448 else
2449 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002450 if(pMsg->type == eWNI_SME_UPPER_LAYER_ASSOC_CNF)
Jeff Johnson295189b2012-06-20 16:38:30 -07002451 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002452 tCsrRoamSession *pSession;
2453 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
2454 tCsrRoamInfo roamInfo;
2455 tCsrRoamInfo *pRoamInfo = NULL;
2456 tANI_U32 sessionId;
2457 eHalStatus status;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002458 smsLog( pMac, LOG1, FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002459 palZeroMemory(pMac->hHdd, &roamInfo, sizeof(tCsrRoamInfo));
2460 pRoamInfo = &roamInfo;
2461 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
2462 status = csrRoamGetSessionIdFromBSSID( pMac, (tCsrBssid *)pUpperLayerAssocCnf->bssId, &sessionId );
2463 pSession = CSR_GET_SESSION(pMac, sessionId);
2464
2465 if(!pSession)
2466 {
2467 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2468 return eHAL_STATUS_FAILURE;
2469 }
2470
2471 pRoamInfo->statusCode = eSIR_SME_SUCCESS; //send the status code as Success
2472 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
2473 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
2474 pRoamInfo->rsnIELen = (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
2475 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
2476 pRoamInfo->addIELen = (tANI_U8)pUpperLayerAssocCnf->addIE.length;
2477 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
2478 palCopyMemory(pMac->hHdd, pRoamInfo->peerMac, pUpperLayerAssocCnf->peerMacAddr, sizeof(tSirMacAddr));
2479 palCopyMemory(pMac->hHdd, &pRoamInfo->bssid, pUpperLayerAssocCnf->bssId, sizeof(tCsrBssid));
2480 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
2481 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
2482 {
2483 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
2484 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
2485 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_INFRA_IND, eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
2486 }
2487 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
2488 {
2489 vos_sleep( 100 );
2490 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
2491 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_WDS_IND, eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
2492 }
2493
Jeff Johnson295189b2012-06-20 16:38:30 -07002494 }
2495 else
2496 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002497
2498 if( csrIsAnySessionInConnectState( pMac ) )
2499 {
2500 //In case of we are connected, we need to check whether connect status changes
2501 //because scan may also run while connected.
2502 csrRoamCheckForLinkStatusChange( pMac, ( tSirSmeRsp * )pMsgBuf );
2503 }
2504 else
2505 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002506 smsLog( pMac, LOGW, "Message [0x%04x] received in state, when expecting Scan Response", pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002507 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002508 }
2509 }
2510
2511 return (status);
2512}
2513
2514
2515
2516void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
2517{
2518 int idx, len;
2519 tANI_U8 *pbIe;
2520
2521 //If failed to remove, assuming someone else got it.
2522 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
2523 (0 == pNewBssDescr->WscIeLen))
2524 {
2525 idx = 0;
2526 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
2527 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
2528 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
2529 //Save WPS IE if it exists
2530 pNewBssDescr->WscIeLen = 0;
2531 while(idx < len)
2532 {
2533 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
2534 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
2535 {
2536 //Founrd it
2537 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
2538 {
2539 palCopyMemory(pMac->hHdd, pNewBssDescr->WscIeProbeRsp,
2540 pbIe, pbIe[1] + 2);
2541 pNewBssDescr->WscIeLen = pbIe[1] + 2;
2542 }
2543 break;
2544 }
2545 idx += pbIe[1] + 2;
2546 pbIe += pbIe[1] + 2;
2547 }
2548 }
2549}
2550
2551
2552
2553//pIes may be NULL
2554tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
2555 tDot11fBeaconIEs *pIes, tAniSSID *pSsid , v_TIME_t *timer )
2556{
2557 tListElem *pEntry;
2558
2559 tCsrScanResult *pBssDesc;
2560 tANI_BOOLEAN fRC = FALSE;
2561
2562 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
2563 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
2564 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
2565 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2566
2567 while( pEntry )
2568 {
2569 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2570
2571 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
2572 // matches
2573 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
2574 pSirBssDescr, pIes ) )
2575 {
2576 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
2577 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
2578 // Remove the 'old' entry from the list....
2579 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
2580 {
2581 // !we need to free the memory associated with this node
2582 //If failed to remove, assuming someone else got it.
2583 *pSsid = pBssDesc->Result.ssId;
2584 *timer = pBssDesc->Result.timer;
2585 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
2586
2587 csrFreeScanResultEntry( pMac, pBssDesc );
2588 }
2589 else
2590 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002591 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07002592 }
2593 fRC = TRUE;
2594
2595 // If we found a match, we can stop looking through the list.
2596 break;
2597 }
2598
2599 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
2600 }
2601
2602 return fRC;
2603}
2604
2605
2606eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2607 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2608{
2609 eHalStatus status = eHAL_STATUS_FAILURE;
2610 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2611
Jeff Johnson32d95a32012-09-10 13:15:23 -07002612 if(!pSession)
2613 {
2614 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2615 return eHAL_STATUS_FAILURE;
2616 }
2617
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002618 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002619 if( pIes )
2620 {
2621 // check if this is a RSN BSS
2622 if( pIes->RSN.present )
2623 {
2624 // Check if the BSS is capable of doing pre-authentication
2625 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
2626 {
2627
2628#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2629 {
2630 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
2631 palZeroMemory(pMac->hHdd, &secEvent, sizeof(vos_event_wlan_security_payload_type));
2632 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
2633 secEvent.encryptionModeMulticast =
2634 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
2635 secEvent.encryptionModeUnicast =
2636 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
2637 palCopyMemory( pMac->hHdd, secEvent.bssid, pSession->connectedProfile.bssid, 6 );
2638 secEvent.authMode =
2639 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
2640 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
2641 }
2642#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2643
2644 // if yes, then add to PMKIDCandidateList
2645 status = palCopyMemory(pMac->hHdd, pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
2646 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2647
2648 if( HAL_STATUS_SUCCESS( status ) )
2649 {
Venkata Prathyusha Kuntupalliea7098e2013-01-31 16:08:13 -08002650 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 ) // Bit 0 offirst byte - PreAuthentication Capability
Jeff Johnson295189b2012-06-20 16:38:30 -07002651 {
2652 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported = eANI_BOOLEAN_TRUE;
2653 }
2654 else
2655 {
2656 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported = eANI_BOOLEAN_FALSE;
2657 }
2658 pSession->NumPmkidCandidate++;
2659 }
2660 }
2661 else
2662 {
2663 status = eHAL_STATUS_FAILURE;
2664 }
2665 }
2666 }
2667
2668 return (status);
2669}
2670
2671//This function checks whether new AP is found for the current connected profile
2672//If it is found, it return the sessionId, else it return invalid sessionID
2673tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
2674 tSirBssDescription *pBssDesc,
2675 tDot11fBeaconIEs *pIes)
2676{
2677 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
2678 tCsrRoamSession *pSession;
2679 tDot11fBeaconIEs *pIesLocal = pIes;
2680
2681 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2682 {
2683 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
2684 {
2685 if( CSR_IS_SESSION_VALID( pMac, i ) )
2686 {
2687 pSession = CSR_GET_SESSION( pMac, i );
2688 if( csrIsConnStateConnectedInfra( pMac, i ) &&
2689 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
2690 {
2691 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
2692 {
2693 //this new BSS fits the current profile connected
2694 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
2695 {
2696 bRet = i;
2697 }
2698 break;
2699 }
2700 }
2701 }
2702 }
2703 if( !pIes )
2704 {
2705 palFreeMemory(pMac->hHdd, pIesLocal);
2706 }
2707 }
2708
2709 return (tANI_U8)bRet;
2710}
2711
2712#ifdef FEATURE_WLAN_WAPI
2713eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2714 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2715{
2716 eHalStatus status = eHAL_STATUS_FAILURE;
2717 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2718
Jeff Johnson32d95a32012-09-10 13:15:23 -07002719 if(!pSession)
2720 {
2721 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2722 return eHAL_STATUS_FAILURE;
2723 }
2724
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002725 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002726 if( pIes )
2727 {
2728 // check if this is a WAPI BSS
2729 if( pIes->WAPI.present )
2730 {
2731 // Check if the BSS is capable of doing pre-authentication
2732 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
2733 {
2734
2735 // if yes, then add to BKIDCandidateList
2736 status = palCopyMemory(pMac->hHdd, pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
2737 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2738
2739 if( HAL_STATUS_SUCCESS( status ) )
2740 {
2741 if ( pIes->WAPI.preauth )
2742 {
2743 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported = eANI_BOOLEAN_TRUE;
2744 }
2745 else
2746 {
2747 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported = eANI_BOOLEAN_FALSE;
2748 }
2749 pSession->NumBkidCandidate++;
2750 }
2751 }
2752 else
2753 {
2754 status = eHAL_STATUS_FAILURE;
2755 }
2756 }
2757 }
2758
2759 return (status);
2760}
2761
2762//This function checks whether new AP is found for the current connected profile
2763//if so add to BKIDCandidateList
2764tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
2765 tDot11fBeaconIEs *pIes)
2766{
2767 tANI_BOOLEAN fRC = FALSE;
2768 tDot11fBeaconIEs *pIesLocal = pIes;
2769 tANI_U32 sessionId;
2770 tCsrRoamSession *pSession;
2771
2772 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2773 {
2774 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
2775 {
2776 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
2777 {
2778 pSession = CSR_GET_SESSION( pMac, sessionId );
2779 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
2780 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
2781 {
2782 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
2783 {
2784 //this new BSS fits the current profile connected
2785 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
2786 {
2787 fRC = TRUE;
2788 }
2789 }
2790 }
2791 }
2792 }
2793 if(!pIes)
2794 {
2795 palFreeMemory(pMac->hHdd, pIesLocal);
2796 }
2797
2798 }
2799 return fRC;
2800}
2801
2802#endif
2803
2804
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07002805static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07002806{
2807 tListElem *pEntry;
2808 tCsrScanResult *pBssDescription;
2809 tANI_S8 cand_Bss_rssi;
2810 tANI_BOOLEAN fDupBss;
2811#ifdef FEATURE_WLAN_WAPI
2812 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
2813#endif /* FEATURE_WLAN_WAPI */
2814 tDot11fBeaconIEs *pIesLocal = NULL;
2815 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
2816 tAniSSID tmpSsid;
2817 v_TIME_t timer=0;
2818
2819 tmpSsid.length = 0;
2820 cand_Bss_rssi = -128; // RSSI coming from PE is -ve
2821
2822 // remove the BSS descriptions from temporary list
2823 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
2824 {
2825 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2826
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002827 smsLog( pMac, LOGW, "...Bssid= %02x-%02x-%02x-%02x-%02x-%02x chan= %d, rssi = -%d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002828 pBssDescription->Result.BssDescriptor.bssId[ 0 ], pBssDescription->Result.BssDescriptor.bssId[ 1 ],
2829 pBssDescription->Result.BssDescriptor.bssId[ 2 ], pBssDescription->Result.BssDescriptor.bssId[ 3 ],
2830 pBssDescription->Result.BssDescriptor.bssId[ 4 ], pBssDescription->Result.BssDescriptor.bssId[ 5 ],
2831 pBssDescription->Result.BssDescriptor.channelId,
2832 pBssDescription->Result.BssDescriptor.rssi * (-1) );
2833
2834 //At this time, pBssDescription->Result.pvIes may be NULL
2835 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
2836 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
2837 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002838 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002839 csrFreeScanResultEntry(pMac, pBssDescription);
2840 continue;
2841 }
2842 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid , &timer );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07002843 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
2844 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
2845#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2846 && !( eCsrScanGetLfrResult == reason )
2847#endif
2848 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002849 {
2850 //Limit reach
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002851 smsLog(pMac, LOGW, FL(" BSS limit reached"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002852 //Free the resources
2853 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
2854 {
2855 palFreeMemory(pMac->hHdd, pIesLocal);
2856 }
2857 csrFreeScanResultEntry(pMac, pBssDescription);
2858 //Continue because there may be duplicated BSS
2859 continue;
2860 }
2861 // check for duplicate scan results
2862 if ( !fDupBss )
2863 {
2864 //Found a new BSS
2865 sessionId = csrProcessBSSDescForPMKIDList(pMac,
2866 &pBssDescription->Result.BssDescriptor, pIesLocal);
2867 if( CSR_SESSION_ID_INVALID != sessionId)
2868 {
2869 csrRoamCallCallback(pMac, sessionId, NULL, 0,
2870 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
2871 }
2872 }
2873 else
2874 {
2875 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
2876 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
2877 {
2878 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
2879 //if diff of saved SSID time and current time is less than 1 min to avoid
2880 //side effect of saving SSID with old one is that if AP changes its SSID while remain
2881 //hidden, we may never see it and also to address the requirement of
2882 //When we remove hidden ssid from the profile i.e., forget the SSID via
2883 // GUI that SSID shouldn't see in the profile
2884 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
2885 {
2886 pBssDescription->Result.timer = timer;
2887 pBssDescription->Result.ssId = tmpSsid;
2888 }
2889 }
2890 }
2891
2892 //Tush: find a good AP for 11d info
2893 if( csrIs11dSupported( pMac ) )
2894 {
2895 if(cand_Bss_rssi < pBssDescription->Result.BssDescriptor.rssi)
2896 {
2897 // check if country information element is present
2898 if(pIesLocal->Country.present)
2899 {
2900 cand_Bss_rssi = pBssDescription->Result.BssDescriptor.rssi;
2901 // learn country information
2902 csrLearnCountryInformation( pMac, &pBssDescription->Result.BssDescriptor,
2903 pIesLocal, eANI_BOOLEAN_FALSE );
2904 }
2905
2906 }
2907 }
2908
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08002909
Jeff Johnson295189b2012-06-20 16:38:30 -07002910 // append to main list
2911 csrScanAddResult(pMac, pBssDescription, pIesLocal);
2912 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
2913 {
2914 palFreeMemory(pMac->hHdd, pIesLocal);
2915 }
2916 }
2917
2918 //Tush: If we can find the current 11d info in any of the scan results, or
2919 // a good enough AP with the 11d info from the scan results then no need to
2920 // get into ambiguous state
2921 if(pMac->scan.fAmbiguous11dInfoFound)
2922 {
2923 if((pMac->scan.fCurrent11dInfoMatch) || (cand_Bss_rssi != -128))
2924 {
2925 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
2926 }
2927 }
2928
2929#ifdef FEATURE_WLAN_WAPI
2930 if(fNewWapiBSSForCurConnection)
2931 {
2932 //remember it first
2933 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
2934 }
2935#endif /* FEATURE_WLAN_WAPI */
2936
2937 return;
2938}
2939
2940
2941static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
2942 tDot11fBeaconIEs *pIes)
2943{
2944 tCsrScanResult *pCsrBssDescription = NULL;
2945 tANI_U32 cbBSSDesc;
2946 tANI_U32 cbAllocated;
2947 eHalStatus halStatus;
2948
2949 // figure out how big the BSS description is (the BSSDesc->length does NOT
2950 // include the size of the length field itself).
2951 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
2952
2953 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
2954
2955 halStatus = palAllocateMemory( pMac->hHdd, (void **)&pCsrBssDescription, cbAllocated );
2956 if ( HAL_STATUS_SUCCESS(halStatus) )
2957 {
2958 palZeroMemory( pMac->hHdd, pCsrBssDescription, cbAllocated );
2959 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
2960 palCopyMemory(pMac->hHdd, &pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
2961#if defined(VOSS_ENSBALED)
2962 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
2963#endif
2964 csrScanAddResult(pMac, pCsrBssDescription, pIes);
2965 }
2966
2967 return( pCsrBssDescription );
2968}
2969
2970// Append a Bss Description...
2971tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
2972 tSirBssDescription *pSirBssDescription,
2973 tDot11fBeaconIEs *pIes )
2974{
2975 tCsrScanResult *pCsrBssDescription = NULL;
2976 tAniSSID tmpSsid;
2977 v_TIME_t timer = 0;
2978 int result;
2979
2980 tmpSsid.length = 0;
2981 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer );
2982 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
2983 if (result && (pCsrBssDescription != NULL))
2984 {
2985 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
2986 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
2987 {
2988 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
2989 //if diff of saved SSID time and current time is less than 1 min to avoid
2990 //side effect of saving SSID with old one is that if AP changes its SSID while remain
2991 //hidden, we may never see it and also to address the requirement of
2992 //When we remove hidden ssid from the profile i.e., forget the SSID via
2993 // GUI that SSID shouldn't see in the profile
2994 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
2995 {
2996 pCsrBssDescription->Result.ssId = tmpSsid;
2997 pCsrBssDescription->Result.timer = timer;
2998 }
2999 }
3000 }
3001
3002
3003 return( pCsrBssDescription );
3004}
3005
3006
3007
3008void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3009{
3010 tCsrChannelPowerInfo *pChannelSet;
3011 tListElem *pEntry;
3012
3013 csrLLLock(pChannelList);
3014 // Remove the channel sets from the learned list and put them in the free list
3015 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3016 {
3017 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3018 if( pChannelSet )
3019 {
3020 palFreeMemory( pMac->hHdd, pChannelSet );
3021 }
3022 }
3023 csrLLUnlock(pChannelList);
3024 return;
3025}
3026
3027
3028/*
3029 * Save the channelList into the ultimate storage as the final stage of channel
3030 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3031 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003032eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003033{
3034 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3035 tSirMacChanInfo *pChannelInfo;
3036 tCsrChannelPowerInfo *pChannelSet;
3037 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3038 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
3039 eHalStatus halStatus;
3040
3041 pChannelInfo = channelTable;
3042 // atleast 3 bytes have to be remaining -- from "countryString"
3043 while ( i-- )
3044 {
3045 halStatus = palAllocateMemory( pMac->hHdd, (void **)&pChannelSet, sizeof(tCsrChannelPowerInfo) );
3046 if ( eHAL_STATUS_SUCCESS == halStatus )
3047 {
3048 palZeroMemory(pMac->hHdd, pChannelSet, sizeof(tCsrChannelPowerInfo));
3049 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3050 pChannelSet->numChannels = pChannelInfo->numChannels;
3051
3052 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003053 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003054 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003055
Jeff Johnson295189b2012-06-20 16:38:30 -07003056 {
3057 pChannelSet->interChannelOffset = 1;
3058 f2GHzInfoFound = TRUE;
3059 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003060 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003061 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003062 {
3063 pChannelSet->interChannelOffset = 4;
3064 f2GHzInfoFound = FALSE;
3065 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003066 else
3067 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003068 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003069 pChannelSet->firstChannel);
3070 palFreeMemory(pMac->hHdd, pChannelSet);
3071 return eHAL_STATUS_FAILURE;
3072 }
3073
Jeff Johnson295189b2012-06-20 16:38:30 -07003074 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3075
3076 if( f2GHzInfoFound )
3077 {
3078 if( !f2GListPurged )
3079 {
3080 // purge previous results if found new
3081 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3082 f2GListPurged = TRUE;
3083 }
3084
3085 if(CSR_IS_OPERATING_BG_BAND(pMac))
3086 {
3087 // add to the list of 2.4 GHz channel sets
3088 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3089 }
3090 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003091 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003092 pChannelSet->firstChannel);
3093 palFreeMemory(pMac->hHdd, pChannelSet);
3094 }
3095 }
3096 else
3097 {
3098 // 5GHz info found
3099 if( !f5GListPurged )
3100 {
3101 // purge previous results if found new
3102 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3103 f5GListPurged = TRUE;
3104 }
3105
3106 if(CSR_IS_OPERATING_A_BAND(pMac))
3107 {
3108 // add to the list of 5GHz channel sets
3109 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3110 }
3111 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003112 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003113 pChannelSet->firstChannel);
3114 palFreeMemory(pMac->hHdd, pChannelSet);
3115 }
3116 }
3117 }
3118
3119 pChannelInfo++; // move to next entry
3120 }
3121
Jeff Johnsone7245742012-09-05 17:12:55 -07003122 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003123}
3124
3125
3126
3127void csrApplyPower2Current( tpAniSirGlobal pMac )
3128{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003129 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003130 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3131 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3132}
3133
3134
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003135void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003136{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303137 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003138 eNVChannelEnabledType channelEnabledType;
3139 tANI_U8 numChannels = 0;
3140 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303141 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003142 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303143
Jeff Johnson295189b2012-06-20 16:38:30 -07003144 if( pChannelList->numChannels )
3145 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303146 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3147 {
3148 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3149 VOS_COUNTRY_CODE_LEN))
3150 {
3151 countryIndex = count;
3152 break;
3153 }
3154 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003155 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
3156 /* If user doesn't want to scan the DFS channels lets trim them from
3157 the valid channel list*/
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303158 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003159 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303160 channelIgnore = FALSE;
3161 if( FALSE == pMac->scan.fEnableDFSChnlScan )
3162 {
3163 channelEnabledType =
3164 vos_nv_getChannelEnabledState(pChannelList->channelList[i]);
3165 }
3166 else
3167 {
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003168 channelEnabledType = NV_CHANNEL_ENABLE;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303169 }
3170 if( NV_CHANNEL_ENABLE == channelEnabledType )
3171 {
3172 if( countryIndex != -1 )
3173 {
3174 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
3175 {
3176 if( pChannelList->channelList[i] ==
3177 countryIgnoreList[countryIndex].channelList[j] )
3178 {
3179 channelIgnore = TRUE;
3180 break;
3181 }
3182 }
3183 }
3184 if( FALSE == channelIgnore )
3185 {
3186 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
3187 numChannels++;
3188 }
3189 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003190 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303191 ChannelList.numChannels = numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07003192 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3193 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303194 // build a scan list based on the channel list : channel# + active/passive scan
3195 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07003196#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003197 if (updateRiva)
3198 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003199 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003200 // Send HAL UpdateScanParams message
3201 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
3202 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003203#endif // FEATURE_WLAN_SCAN_PNO
3204 }
3205 else
3206 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003207 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003208 }
3209 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
3210 csrSetCfgCountryCode(pMac, countryCode);
3211}
3212
3213
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003214void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07003215{
3216 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
3217 {
3218
3219#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3220 {
3221 vos_log_802_11d_pkt_type *p11dLog;
3222 int Index;
3223
3224 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3225 if(p11dLog)
3226 {
3227 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
3228 palCopyMemory(pMac->hHdd, p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
3229 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
3230 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3231 {
3232 palCopyMemory(pMac->hHdd, p11dLog->Channels, pMac->scan.base20MHzChannels.channelList,
3233 p11dLog->numChannel);
3234 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
3235 {
3236 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3237 }
3238 }
3239 if(!pMac->roam.configParam.Is11dSupportEnabled)
3240 {
3241 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3242 }
3243 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3244 {
3245 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3246 }
3247 else
3248 {
3249 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3250 }
3251 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3252 }
3253 }
3254#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3255
3256 // switch to passive scans only when 11d is enabled
3257 if( csrIs11dSupported( pMac ) )
3258 {
3259 pMac->scan.curScanType = eSIR_PASSIVE_SCAN;
3260 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003261
3262 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
3263 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
3264
Jeff Johnson295189b2012-06-20 16:38:30 -07003265 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
3266 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
3267 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003268 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07003269 // clear the 11d channel list
3270 palZeroMemory( pMac->hHdd, &pMac->scan.channels11d, sizeof(pMac->scan.channels11d) );
3271 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
3272 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
3273 }
3274
3275 return;
3276}
3277
3278
3279eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
3280{
3281 eHalStatus status = eHAL_STATUS_SUCCESS;
3282 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
3283
3284 //Use the Country code and domain from EEPROM
3285 palCopyMemory(pMac->hHdd, pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault, WNI_CFG_COUNTRY_CODE_LEN);
3286 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07003287 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
3288 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07003289 {
3290 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003291 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003292 }
3293 if(pfRestartNeeded)
3294 {
3295 *pfRestartNeeded = fRestart;
3296 }
3297
3298 return (status);
3299}
3300
3301
3302eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
3303{
3304 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
3305 v_REGDOMAIN_t domainId;
3306
3307 if(pCountry)
3308 {
3309 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId);
3310 if(HAL_STATUS_SUCCESS(status))
3311 {
3312 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
3313 if(HAL_STATUS_SUCCESS(status))
3314 {
3315 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
3316 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
3317 palCopyMemory(pMac->hHdd, pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
3318 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
3319 {
3320 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
3321 csrSetCfgCountryCode(pMac, pCountry);
3322 }
3323 }
3324 }
3325 }
3326
3327 return (status);
3328}
3329
3330
3331
3332//caller allocated memory for pNumChn and pChnPowerInfo
3333//As input, *pNumChn has the size of the array of pChnPowerInfo
3334//Upon return, *pNumChn has the number of channels assigned.
3335void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
3336 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
3337{
3338 tListElem *pEntry;
3339 tANI_U32 chnIdx = 0, idx;
3340 tCsrChannelPowerInfo *pChannelSet;
3341
3342 //Get 2.4Ghz first
3343 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
3344 while( pEntry && (chnIdx < *pNumChn) )
3345 {
3346 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3347 if ( 1 != pChannelSet->interChannelOffset )
3348 {
3349 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3350 {
3351 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
3352 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3353 }
3354 }
3355 else
3356 {
3357 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3358 {
3359 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
3360 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3361 }
3362 }
3363
3364 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
3365 }
3366 *pNumChn = chnIdx;
3367
3368 return ;
3369}
3370
3371
3372
3373void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
3374{
3375 v_REGDOMAIN_t domainId;
3376 eHalStatus status = eHAL_STATUS_SUCCESS;
3377
3378 do
3379 {
3380 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
3381 if( pMac->scan.fAmbiguous11dInfoFound )
3382 {
3383 // ambiguous info found
3384 //Restore te default domain as well
3385 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pMac->scan.countryCodeCurrent, &domainId )))
3386 {
3387 pMac->scan.domainIdCurrent = domainId;
3388 }
3389 else
3390 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003391 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003392 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
3393 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003394 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003395 break;
3396 }
3397 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
3398 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pMac->scan.countryCode11d, &domainId )))
3399 {
3400 //Check whether we need to enforce default domain
3401 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
3402 (pMac->scan.domainIdCurrent == domainId) )
3403 {
3404
3405#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3406 {
3407 vos_log_802_11d_pkt_type *p11dLog;
3408 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
3409 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
3410
3411 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3412 if(p11dLog)
3413 {
3414 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
3415 palCopyMemory(pMac->hHdd, p11dLog->countryCode, pMac->scan.countryCode11d, 3);
3416 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
3417 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3418 {
3419 palCopyMemory(pMac->hHdd, p11dLog->Channels, pMac->scan.channels11d.channelList,
3420 p11dLog->numChannel);
3421 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
3422 &nChnInfo, chnPwrInfo);
3423 nTmp = nChnInfo;
3424 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
3425 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
3426 &nChnInfo, &chnPwrInfo[nTmp]);
3427 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
3428 {
3429 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
3430 {
3431 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
3432 {
3433 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
3434 break;
3435 }
3436 }
3437 }
3438 }
3439 if(!pMac->roam.configParam.Is11dSupportEnabled)
3440 {
3441 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3442 }
3443 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3444 {
3445 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3446 }
3447 else
3448 {
3449 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3450 }
3451 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3452 }
3453 }
3454#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3455 if(pMac->scan.domainIdCurrent != domainId)
3456 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003457 smsLog(pMac, LOGW, FL("Domain Changed Old %d, new %d"),
3458 pMac->scan.domainIdCurrent, domainId);
Jeff Johnson295189b2012-06-20 16:38:30 -07003459 }
3460 status = WDA_SetRegDomain(pMac, domainId);
3461 if (status != eHAL_STATUS_SUCCESS)
3462 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003463 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003464 }
3465 pMac->scan.domainIdCurrent = domainId;
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003466 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.channels11d, pMac->scan.countryCode11d, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003467 // switch to active scans using this new channel list
3468 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
3469 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
3470 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
3471 }
3472 }
3473
3474 } while( 0 );
3475
3476 return;
3477}
3478
3479
3480
3481tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
3482 tANI_BOOLEAN fForce)
3483{
3484 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
3485 tANI_U32 i;
3486
3487 // convert to UPPER here so we are assured the strings are always in upper case.
3488 for( i = 0; i < 3; i++ )
3489 {
3490 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3491 }
3492
3493 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
3494 // NA is not a valid country code or domain so let's allow this by changing it to the proper
3495 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
3496 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
3497 // 11d information element, let's default to US.
3498 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pCountryCode, NULL ) ) )
3499 {
3500 // Check the enforcement first
3501 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
3502 {
3503 fUnknownCountryCode = TRUE;
3504 }
3505 else
3506 {
3507 pCountryCode[ 0 ] = 'U';
3508 pCountryCode[ 1 ] = 'S';
3509 }
3510 }
3511
3512 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
3513 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
3514 // if we see a 0 in this third character, let's change it to a ' '.
3515 if ( 0 == pCountryCode[ 2 ] )
3516 {
3517 pCountryCode[ 2 ] = ' ';
3518 }
3519
3520 if( !fUnknownCountryCode )
3521 {
3522 fCountryStringChanged = (!palEqualMemory( pMac->hHdd,
3523 pMac->scan.countryCode11d, pCountryCode, 2));
3524
3525
3526 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
3527 || (fForce))
3528 {
3529 // this is the first .11d information
3530 palCopyMemory( pMac->hHdd, pMac->scan.countryCode11d, pCountryCode, sizeof( pMac->scan.countryCode11d ) );
3531 }
3532 }
3533
3534 return( fCountryStringChanged );
3535}
3536
3537
3538void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
3539{
3540 tANI_U32 Index, count=0;
3541 tSirMacChanInfo *pChanInfo;
3542 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003543 tANI_S32 maxChannelIndex;
3544
3545 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
3546 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07003547
3548 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN)))
3549 {
3550 palZeroMemory(pMac->hHdd, pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
3551 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003552 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003553 {
3554 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
3555 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
3556 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003557 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
3558 {
3559 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
3560 break;
3561 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003562 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
3563 pChanInfo->numChannels = 1;
3564 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3565 pChanInfo++;
3566 count++;
3567 }
3568 }
3569 if(count)
3570 {
3571 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
3572 }
3573 palFreeMemory(pMac->hHdd, pChanInfoStart);
3574 }
3575}
3576
3577
3578void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
3579{
3580 tANI_BOOLEAN fPopulate5GBand = FALSE;
3581
3582 do
3583 {
3584 // if this is not a dual band product, then we don't need to set the opposite
3585 // band info. We only work in one band so no need to look in the other band.
3586 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
3587 // if we found channel info on the 5.0 band and...
3588 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
3589 {
3590 // and the 2.4 band is empty, then populate the 2.4 channel info
Jeff Johnson295189b2012-06-20 16:38:30 -07003591 fPopulate5GBand = FALSE;
3592 }
3593 else
3594 {
3595 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
3596 // set the 5.0 band info from the 2.4 country code.
Jeff Johnson295189b2012-06-20 16:38:30 -07003597 fPopulate5GBand = TRUE;
3598 }
3599 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
3600
3601 } while( 0 );
3602}
3603
3604
3605tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
3606{
3607 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3608 tANI_U32 i;
3609
3610 //Make sure it is a channel that is in our supported list.
3611 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
3612 {
3613 if ( channelId == pMac->scan.baseChannels.channelList[i] )
3614 {
3615 fRet = eANI_BOOLEAN_TRUE;
3616 break;
3617 }
3618 }
3619
3620 //If it is configured to limit a set of the channels
3621 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
3622 {
3623 fRet = eANI_BOOLEAN_FALSE;
3624 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
3625 {
3626 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
3627 {
3628 fRet = eANI_BOOLEAN_TRUE;
3629 break;
3630 }
3631 }
3632 }
3633
3634 return (fRet);
3635}
3636
3637
3638
3639//bSize specify the buffer size of pChannelList
3640tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
3641{
3642 tANI_U8 i, j = 0, chnId;
3643
3644 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
3645 for( i = 0; i < bSize; i++ )
3646 {
3647 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
3648 if ( csrIsSupportedChannel( pMac, chnId ) )
3649 {
3650 pChannelList[j++] = chnId;
3651 }
3652 }
3653
3654 return (j);
3655}
3656
3657
3658
3659//bSize -- specify the buffer size of pChannelList
3660void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
3661 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
3662{
3663 tListElem *pEntry;
3664 tCsrChannelPowerInfo *pChannelSet;
3665 tANI_U8 numChannels;
3666 tANI_U8 *pChannels;
3667
3668 if( pChannelSetList && pChannelList && pNumChannels )
3669 {
3670 pChannels = pChannelList;
3671 *pNumChannels = 0;
3672 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
3673 while( pEntry )
3674 {
3675 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3676 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
3677 pChannels += numChannels;
3678 *pNumChannels += numChannels;
3679 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
3680 }
3681 }
3682}
3683
3684
3685/*
3686 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
3687*/
3688tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
3689 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
3690{
3691 tANI_U8 Num2GChannels, bMaxNumChn;
3692 eHalStatus status;
3693 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3694 v_REGDOMAIN_t domainId;
3695 tDot11fBeaconIEs *pIesLocal = pIes;
3696
Jeff Johnson295189b2012-06-20 16:38:30 -07003697 if (VOS_STA_SAP_MODE == vos_get_conparam ())
3698 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003699
3700 do
3701 {
3702 // check if .11d support is enabled
3703 if( !csrIs11dSupported( pMac ) ) break;
3704 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc, &pIesLocal))) )
3705 {
3706 break;
3707 }
3708 // check if country information element is present
3709 if(!pIesLocal->Country.present)
3710 {
3711 //No country info
3712 break;
3713 }
3714
3715 if( csrSave11dCountryString( pMac, pIesLocal->Country.country, fForce ) )
3716 {
3717 // country string changed, this should not happen
3718 //Need to check whether we care about this BSS' domain info
3719 //If it doesn't match of the connected profile or roaming profile, let's ignore it
3720 tANI_U32 i;
3721 tCsrRoamSession *pSession;
3722
3723 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3724 {
3725 if( CSR_IS_SESSION_VALID( pMac, i ) )
3726 {
3727 pSession = CSR_GET_SESSION( pMac, i );
3728 if(pSession->pCurRoamProfile)
3729 {
3730 tCsrScanResultFilter filter;
3731
3732 palZeroMemory(pMac->hHdd, &filter, sizeof(tCsrScanResultFilter));
3733 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, &filter);
3734 if(HAL_STATUS_SUCCESS(status))
3735 {
3736 tANI_BOOLEAN fMatch = csrMatchBSS(pMac, pSirBssDesc, &filter, NULL, NULL, NULL, NULL);
3737 //Free the resource first
3738 csrFreeScanFilter( pMac, &filter );
3739 if(fMatch)
3740 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003741 smsLog(pMac, LOGW, " Matching roam profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07003742 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
3743 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
3744 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3745 break;
3746 }
3747 }
3748 }
3749 else if( csrIsConnStateConnected(pMac, i))
3750 {
3751 //Reach here only when the currention is base on no profile.
3752 //User doesn't give profile and just connect to anything.
3753 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pSirBssDesc, pIesLocal))
3754 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003755 smsLog(pMac, LOGW, " Matching connect profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07003756 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
3757 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
3758 //Tush
3759 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3760 if(csrIsBssidMatch(pMac, (tCsrBssid *)&pSirBssDesc->bssId,
3761 &pSession->connectedProfile.bssid))
3762 {
3763 //AP changed the 11d info on the fly, modify cfg
3764 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3765 fRet = eANI_BOOLEAN_TRUE;
3766 }
3767 break;
3768 }
3769 }
3770 } //valid session
3771 } //for
3772 if ( i == CSR_ROAM_SESSION_MAX )
3773 {
3774 //Check whether we can use this country's 11d information
3775 if( !pMac->roam.configParam.fEnforceDefaultDomain )
3776 {
3777 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3778 }
3779 else
3780 {
3781 VOS_ASSERT( pMac->scan.domainIdCurrent == pMac->scan.domainIdDefault );
3782 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3783 pMac, pIesLocal->Country.country, &domainId )) &&
3784 ( domainId == pMac->scan.domainIdCurrent ) )
3785 {
3786 //Two countries in the same domain
3787 }
3788 }
3789 }
3790 }
3791 else //Tush
3792 {
3793 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_TRUE;
3794 }
3795
3796 //In case that some channels in 5GHz have the same channel number as 2.4GHz (<= 14)
3797 if(CSR_IS_CHANNEL_5GHZ(pSirBssDesc->channelId))
3798 {
3799 tANI_U8 iC;
3800 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
3801
3802 for(iC = 0; iC < pIesLocal->Country.num_triplets; iC++)
3803 {
3804 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[iC].firstChanNum))
3805 {
3806 pMacChnSet[iC].firstChanNum += 200; //*** Where is this 200 defined?
3807 }
3808 }
3809 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003810 smsLog(pMac, LOG3, FL(" %d sets each one is %d"), pIesLocal->Country.num_triplets, sizeof(tSirMacChanInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07003811 // save the channel/power information from the Channel IE.
3812 //sizeof(tSirMacChanInfo) has to be 3
Jeff Johnsone7245742012-09-05 17:12:55 -07003813 if (eHAL_STATUS_SUCCESS != csrSaveToChannelPower2G_5G( pMac, pIesLocal->Country.num_triplets * sizeof(tSirMacChanInfo),
3814 (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]) ))
3815 {
3816 fRet = eANI_BOOLEAN_FALSE;
3817 return fRet;
3818 }
3819
Jeff Johnson295189b2012-06-20 16:38:30 -07003820 // set the indicator of the channel where the country IE was found...
3821 pMac->scan.channelOf11dInfo = pSirBssDesc->channelId;
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07003822 csrGetRegulatoryDomainForCountry(pMac, pIesLocal->Country.country, &domainId );
3823 // Checking for Domain Id change
3824 if ( domainId != pMac->scan.domainIdCurrent )
3825 {
3826 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
3827 WDA_SetRegDomain(pMac, domainId);
3828 // Check weather AP provided the 2.4GHZ list or 5GHZ list
3829 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[0].firstChanNum))
3830 {
3831 // AP Provided the 2.4 Channels, Update the 5GHz channels from nv.bin
3832 csrGet5GChannels(pMac );
3833 }
3834 else
3835 {
3836 // AP Provided the 5G Channels, Update the 2.4GHZ channel list from nv.bin
3837 csrGet24GChannels(pMac );
3838 }
3839 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003840 // Populate both band channel lists based on what we found in the country information...
3841 csrSetOppositeBandChannelInfo( pMac );
3842 bMaxNumChn = WNI_CFG_VALID_CHANNEL_LIST_LEN;
3843 // construct 2GHz channel list first
3844 csrConstructCurrentValidChannelList( pMac, &pMac->scan.channelPowerInfoList24, pMac->scan.channels11d.channelList,
3845 bMaxNumChn, &Num2GChannels );
3846 // construct 5GHz channel list now
3847 if(bMaxNumChn > Num2GChannels)
3848 {
3849 csrConstructCurrentValidChannelList( pMac, &pMac->scan.channelPowerInfoList5G, pMac->scan.channels11d.channelList + Num2GChannels,
3850 bMaxNumChn - Num2GChannels,
3851 &pMac->scan.channels11d.numChannels );
3852 }
3853
3854 pMac->scan.channels11d.numChannels += Num2GChannels;
3855 fRet = eANI_BOOLEAN_TRUE;
3856
3857 } while( 0 );
3858
3859 if( !pIes && pIesLocal )
3860 {
3861 //locally allocated
3862 palFreeMemory(pMac->hHdd, pIesLocal);
3863 }
3864
3865 return( fRet );
3866}
3867
3868
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003869static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07003870{
3871 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
3872 // will set this to the channel where an .11d beacon is seen
3873 pMac->scan.channelOf11dInfo = 0;
3874 // if we get any ambiguous .11d information then this will be set to TRUE
3875 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3876 //Tush
3877 // if we get any ambiguous .11d information, then this will be set to TRUE
3878 // only if the applied 11d info could be found in one of the scan results
3879 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
3880 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003881 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07003882
3883 // Now check if we gathered any domain/country specific information
3884 // If so, we should update channel list and apply Tx power settings
Jeff Johnsone7245742012-09-05 17:12:55 -07003885 if( csrIs11dSupported(pMac) )
3886 {
3887 csrApplyCountryInformation( pMac, FALSE );
3888 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003889}
3890
3891
3892void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
3893{
3894 switch (pCommand->u.scanCmd.reason)
3895 {
3896 case eCsrScanSetBGScanParam:
3897 case eCsrScanAbortBgScan:
3898 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
3899 {
3900 palFreeMemory(pMac->hHdd, pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
3901 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
3902 }
3903 break;
3904 case eCsrScanBGScanAbort:
3905 case eCsrScanBGScanEnable:
3906 case eCsrScanGetScanChnInfo:
3907 break;
3908 case eCsrScanAbortNormalScan:
3909 default:
3910 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
3911 break;
3912 }
3913 if(pCommand->u.scanCmd.pToRoamProfile)
3914 {
3915 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
3916 palFreeMemory(pMac->hHdd, pCommand->u.scanCmd.pToRoamProfile);
3917 }
3918 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
3919}
3920
3921
3922tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
3923{
3924 tANI_U32 index11dChannels, index;
3925 tANI_U32 indexCurrentChannels;
3926 tANI_BOOLEAN fChannelAlreadyScanned;
3927 tANI_U32 len = sizeof(pMac->roam.validChannelList);
3928
3929 *pcChannels = 0;
3930 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
3931 {
3932 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
3933 {
3934 //Find the channel index where we found the 11d info
3935 for(index = 0; index < len; index++)
3936 {
3937 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
3938 break;
3939 }
3940 //check whether we found the channel index
3941 if(index < len)
3942 {
3943 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
3944 // NOT in the current channel list. This gives us a list of the new channels that have not been
3945 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
3946 // initially.
3947 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
3948 {
3949 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
3950
3951 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
3952 {
3953 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
3954 {
3955 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
3956 break;
3957 }
3958 }
3959
3960 if ( !fChannelAlreadyScanned )
3961 {
3962 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
3963 ( *pcChannels )++;
3964 }
3965 }
3966 }
3967 }//GetCFG
3968 }
3969 return( *pcChannels );
3970}
3971
3972
3973eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
3974{
3975 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
3976
3977 switch( pCommand->u.scanCmd.reason )
3978 {
3979 case eCsrScan11d1:
3980 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
3981 break;
3982 case eCsrScan11d2:
3983 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
3984 break;
3985 case eCsrScan11dDone:
3986 NextCommand = eCsrNext11dScanComplete;
3987 break;
3988 case eCsrScanLostLink1:
3989 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
3990 break;
3991 case eCsrScanLostLink2:
3992 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
3993 break;
3994 case eCsrScanLostLink3:
3995 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
3996 break;
3997 case eCsrScanForSsid:
3998 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
3999 break;
4000 case eCsrScanForCapsChange:
4001 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4002 break;
4003 case eCsrScanIdleScan:
4004 NextCommand = eCsrNextIdleScanComplete;
4005 break;
4006 default:
4007 NextCommand = eCsrNextScanNothing;
4008 break;
4009 }
4010 return( NextCommand );
4011}
4012
4013
4014//Return whether the pCommand is finished.
4015tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4016{
4017 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4018
4019 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004020 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004021 pCommand->u.scanCmd.reason = eCsrScan11d2;
4022 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4023 {
4024 fRet = eANI_BOOLEAN_FALSE;
4025 }
4026
4027 return (fRet);
4028}
4029
4030
4031tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4032{
4033 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4034 tANI_U8 *pChannels;
4035 tANI_U8 cChannels;
4036
4037 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN)))
4038 {
4039 palZeroMemory(pMac->hHdd, pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
4040 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4041 {
4042 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4043 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4044 {
4045 palFreeMemory(pMac->hHdd, pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07004046 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004047 }
4048 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, cChannels)))
4049 {
4050 palCopyMemory(pMac->hHdd, pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, pChannels, cChannels);
4051 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4052 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4053 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4054 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4055 {
4056 //Reuse the same command buffer
4057 fRet = eANI_BOOLEAN_FALSE;
4058 }
4059 }
4060 }
4061 palFreeMemory(pMac->hHdd, pChannels);
4062 }
4063
4064 return (fRet);
4065}
4066
4067//Return whether the command should be removed
4068tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
4069{
4070 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4071 tListElem *pEntry;
4072 tSmeCmd *pCommand;
4073 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4074 tANI_BOOLEAN fSuccess;
4075
4076 pEntry = csrLLPeekHead( &pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK );
4077
4078 if ( pEntry )
4079 {
4080 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4081
4082 // If the head of the queue is Active and it is a SCAN command, remove
4083 // and put this on the Free queue.
4084 if ( eSmeCommandScan == pCommand->command )
4085 {
4086 tANI_U32 sessionId = pCommand->sessionId;
4087
4088 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
4089 {
4090 fSuccess = eANI_BOOLEAN_FALSE;
4091 }
4092 else
4093 {
4094 //pMac->scan.tempScanResults is not empty meaning the scan found something
4095 //This check only valid here because csrSaveScanresults is not yet called
4096 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
4097 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004098 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07004099
4100#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4101 {
4102 vos_log_scan_pkt_type *pScanLog = NULL;
4103 tScanResultHandle hScanResult;
4104 tCsrScanResultInfo *pScanResult;
4105 tDot11fBeaconIEs *pIes;
4106 int n = 0, c = 0;
4107
4108 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
4109 if(pScanLog)
4110 {
4111 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4112 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4113 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4114 {
4115 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
4116 }
4117 else
4118 {
4119 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
4120 {
4121 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
4122 }
4123 else
4124 {
4125 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
4126 }
4127 }
4128 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
4129 {
4130 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
4131 {
4132 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
4133 {
4134 if( n < VOS_LOG_MAX_NUM_BSSID )
4135 {
4136 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
4137 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004138 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004139 break;
4140 }
4141 palCopyMemory(pMac->hHdd, pScanLog->bssid[n], pScanResult->BssDescriptor.bssId, 6);
4142 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
4143 {
4144 palCopyMemory(pMac->hHdd, pScanLog->ssid[n],
4145 pIes->SSID.ssid, pIes->SSID.num_ssid);
4146 }
4147 palFreeMemory(pMac->hHdd, pIes);
4148 n++;
4149 }
4150 c++;
4151 }
4152 pScanLog->numSsid = (v_U8_t)n;
4153 pScanLog->totalSsid = (v_U8_t)c;
4154 csrScanResultPurge(pMac, hScanResult);
4155 }
4156 }
4157 else
4158 {
4159 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
4160 }
4161 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
4162 }
4163 }
4164#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4165
4166 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
4167 //We reuse the command here instead reissue a new command
4168 switch(NextCommand)
4169 {
4170 case eCsrNext11dScan1Success:
4171 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004172 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004173 // if we found country information, no need to continue scanning further, bail out
4174 fRemoveCommand = eANI_BOOLEAN_TRUE;
4175 NextCommand = eCsrNext11dScanComplete;
4176 break;
4177 case eCsrNext11dScan1Failure:
4178 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
4179 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
4180 //we clear the "old" 11d info and give it once more chance
4181 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
4182 if(fRemoveCommand)
4183 {
4184 NextCommand = eCsrNext11dScanComplete;
4185 }
4186 break;
4187 case eCsrNextLostLinkScan1Success:
4188 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
4189 {
4190 csrScanHandleFailedLostlink1(pMac, sessionId);
4191 }
4192 break;
4193 case eCsrNextLostLinkScan2Success:
4194 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
4195 {
4196 csrScanHandleFailedLostlink2(pMac, sessionId);
4197 }
4198 break;
4199 case eCsrNextLostLinkScan3Success:
4200 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
4201 {
4202 csrScanHandleFailedLostlink3(pMac, sessionId);
4203 }
4204 break;
4205 case eCsrNextLostLinkScan1Failed:
4206 csrScanHandleFailedLostlink1(pMac, sessionId);
4207 break;
4208 case eCsrNextLostLinkScan2Failed:
4209 csrScanHandleFailedLostlink2(pMac, sessionId);
4210 break;
4211 case eCsrNextLostLinkScan3Failed:
4212 csrScanHandleFailedLostlink3(pMac, sessionId);
4213 break;
4214 case eCsrNexteScanForSsidSuccess:
4215 csrScanHandleSearchForSSID(pMac, pCommand);
4216 break;
4217 case eCsrNexteScanForSsidFailure:
4218 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
4219 break;
4220 case eCsrNextIdleScanComplete:
4221 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
4222 break;
4223 case eCsrNextCapChangeScanComplete:
4224 csrScanHandleCapChangeScanComplete(pMac, sessionId);
4225 break;
4226 default:
4227
4228 break;
4229 }
4230 }
4231 else
4232 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004233 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004234 fRemoveCommand = eANI_BOOLEAN_FALSE;
4235 }
4236 }
4237 else
4238 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004239 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004240 fRemoveCommand = eANI_BOOLEAN_FALSE;
4241 }
4242
4243 return( fRemoveCommand );
4244}
4245
4246
4247
4248static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
4249 tSirBssDescription *pSirBssDescr,
4250 tDot11fBeaconIEs *pIes)
4251{
4252 tListElem *pEntry;
4253 tCsrScanResult *pCsrBssDescription;
4254
4255 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
4256 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
4257 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
4258 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
4259 while( pEntry )
4260 {
4261 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4262
4263 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
4264 // matches
4265
4266 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
4267 pSirBssDescr, pIes ) )
4268 {
4269 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
4270 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
4271
4272 // Remove the 'old' entry from the list....
4273 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
4274 {
4275 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
4276 // we need to free the memory associated with this node
4277 csrFreeScanResultEntry( pMac, pCsrBssDescription );
4278 }
4279
4280 // If we found a match, we can stop looking through the list.
4281 break;
4282 }
4283
4284 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
4285 }
4286}
4287
4288
4289
4290//Caller allocated memory pfNewBssForConn to return whether new candidate for
4291//current connection is found. Cannot be NULL
4292tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
4293 tSirBssDescription *pBSSDescription,
4294 tDot11fBeaconIEs *pIes)
4295{
4296 tCsrScanResult *pCsrBssDescription = NULL;
4297 tANI_U32 cbBSSDesc;
4298 tANI_U32 cbAllocated;
4299 eHalStatus halStatus;
4300
4301 // figure out how big the BSS description is (the BSSDesc->length does NOT
4302 // include the size of the length field itself).
4303 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
4304
4305 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
4306
4307 halStatus = palAllocateMemory( pMac->hHdd, (void **)&pCsrBssDescription, cbAllocated );
4308 if ( HAL_STATUS_SUCCESS(halStatus) )
4309 {
4310 palZeroMemory(pMac->hHdd, pCsrBssDescription, cbAllocated);
4311 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
4312 palCopyMemory(pMac->hHdd, &pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
4313 //Save SSID separately for later use
4314 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
4315 {
4316 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07004317 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07004318 if (len > SIR_MAC_MAX_SSID_LENGTH)
4319 {
4320 // truncate to fit in our struct
4321 len = SIR_MAC_MAX_SSID_LENGTH;
4322 }
4323 pCsrBssDescription->Result.ssId.length = len;
4324 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
4325 palCopyMemory(pMac->hHdd, pCsrBssDescription->Result.ssId.ssId,
4326 pIes->SSID.ssid, len );
4327 }
4328 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
4329 }
4330
4331 return( pCsrBssDescription );
4332}
4333
4334
4335
4336
4337tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
4338 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2 )
4339{
4340 tANI_BOOLEAN fMatch = FALSE;
4341 tSirMacCapabilityInfo *pCap1, *pCap2;
4342 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004343 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07004344
4345 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
4346 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
4347 if(pCap1->ess == pCap2->ess)
4348 {
4349 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07004350 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
4351 (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
Jeff Johnson295189b2012-06-20 16:38:30 -07004352 {
4353 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004354 // Check for SSID match, if exists
4355 do
4356 {
4357 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4358 {
4359 break;
4360 }
4361 if( NULL == pIesTemp )
4362 {
4363 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4364 {
4365 break;
4366 }
4367 }
4368 if(pIes1->SSID.present && pIesTemp->SSID.present)
4369 {
4370 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4371 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4372 }
4373 }while(0);
4374
Jeff Johnson295189b2012-06-20 16:38:30 -07004375 }
4376 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
4377 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004378
4379 do
4380 {
4381 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4382 {
4383 break;
4384 }
4385 if( NULL == pIesTemp )
4386 {
4387 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4388 {
4389 break;
4390 }
4391 }
4392 //Same channel cannot have same SSID for different IBSS
4393 if(pIes1->SSID.present && pIesTemp->SSID.present)
4394 {
4395 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4396 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4397 }
4398 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004399 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004400 /* In case of P2P devices, ess and ibss will be set to zero */
4401 else if (!pCap1->ess &&
4402 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
4403 {
4404 fMatch = TRUE;
4405 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004406 }
4407
4408 if(pIes1)
4409 {
4410 palFreeMemory(pMac->hHdd, pIes1);
4411 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004412
4413 if( (NULL == pIes2) && pIesTemp )
4414 {
4415 //locally allocated
4416 palFreeMemory(pMac->hHdd, pIesTemp);
4417 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004418
4419 return( fMatch );
4420}
4421
4422
4423tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
4424{
4425 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
4426}
4427
4428
4429//to check whether the BSS matches the dot11Mode
4430static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
4431 tDot11fBeaconIEs *pIes)
4432{
4433 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
4434 eCsrPhyMode phyMode;
4435
4436 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
4437 {
4438 switch(pMac->roam.configParam.phyMode)
4439 {
4440 case eCSR_DOT11_MODE_11b:
4441 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4442 break;
4443 case eCSR_DOT11_MODE_11g:
4444 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4445 break;
4446 case eCSR_DOT11_MODE_11g_ONLY:
4447 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
4448 break;
4449 case eCSR_DOT11_MODE_11a:
4450 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
4451 break;
4452 case eCSR_DOT11_MODE_11n_ONLY:
4453 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4454 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004455
4456#ifdef WLAN_FEATURE_11AC
4457 case eCSR_DOT11_MODE_11ac_ONLY:
4458 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4459 break;
4460#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004461 case eCSR_DOT11_MODE_11b_ONLY:
4462 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
4463 break;
4464 case eCSR_DOT11_MODE_11a_ONLY:
4465 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
4466 break;
4467 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07004468#ifdef WLAN_FEATURE_11AC
4469 case eCSR_DOT11_MODE_11ac:
4470#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004471 case eCSR_DOT11_MODE_TAURUS:
4472 default:
4473 fAllowed = eANI_BOOLEAN_TRUE;
4474 break;
4475 }
4476 }
4477
4478 return (fAllowed);
4479}
4480
4481
4482
4483//Return pIes to caller for future use when returning TRUE.
4484static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
4485 tANI_U8 numChn, tSirBssDescription *pBssDesc,
4486 tDot11fBeaconIEs **ppIes )
4487{
4488 tANI_BOOLEAN fValidChannel = FALSE;
4489 tDot11fBeaconIEs *pIes = NULL;
4490 tANI_U8 index;
4491
4492 for( index = 0; index < numChn; index++ )
4493 {
4494 // This check relies on the fact that a single BSS description is returned in each
4495 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
4496 // to this model when we ran with a large number of APs. If this were to change, then
4497 // this check would have to mess with removing the bssDescription from somewhere in an
4498 // arbitrary index in the bssDescription array.
4499 if ( pChannels[ index ] == pBssDesc->channelId )
4500 {
4501 fValidChannel = TRUE;
4502 break;
4503 }
4504 }
4505 *ppIes = NULL;
4506 if(fValidChannel)
4507 {
4508 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
4509 {
4510 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
4511 if( fValidChannel )
4512 {
4513 *ppIes = pIes;
4514 }
4515 else
4516 {
4517 palFreeMemory( pMac->hHdd, pIes );
4518 }
4519 }
4520 else
4521 {
4522 fValidChannel = FALSE;
4523 }
4524 }
4525
4526 return( fValidChannel );
4527}
4528
4529
4530//Return whether last scan result is received
4531static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
4532 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
4533{
4534 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
4535 tDot11fBeaconIEs *pIes = NULL;
4536 tANI_U32 cbParsed;
4537 tSirBssDescription *pSirBssDescription;
4538 tANI_U32 cbBssDesc;
4539 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
4540 + sizeof(tSirBssDescription); //We need at least one CB
4541
4542 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
4543 // is returned when the scan could not find anything. so if we get scan failure return that
4544 // the scan response is invalid. Also check the lenght in the scan result for valid scan
4545 // BssDescriptions....
4546 do
4547 {
4548 if ( ( cbScanResult <= pScanRsp->length ) &&
4549 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
4550 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
4551 {
4552 tANI_U8 *pChannelList = NULL;
4553 tANI_U8 cChannels = 0;
4554
4555 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004556#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4557 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
4558 {
4559 pChannelList = NULL;
4560 cChannels = 0;
4561 }
4562 else
4563#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004564 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
4565 {
4566 //eCsrScanSetBGScanParam uses different structure
4567 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
4568
4569 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
4570 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
4571 }
4572 else
4573 {
4574 //the rest use generic scan request
4575 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
4576 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
4577 }
4578
4579 // if the scan result is not on one of the channels in the Valid channel list, then it
4580 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
4581 // let's drop the scan result.
4582 //
4583 // The other situation is where the scan request is for a scan on a particular channel set
4584 // and the scan result is from a
4585
4586 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
4587 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
4588 // as the valid channels.
4589 if ( 0 == cChannels )
4590 {
4591 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4592
4593 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4594 {
4595 pChannelList = pMac->roam.validChannelList;
4596 cChannels = (tANI_U8)len;
4597 }
4598 else
4599 {
4600 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004601 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07004602 break;
4603 }
4604 }
4605
4606 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
4607 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
4608 pSirBssDescription = pScanRsp->bssDescription;
4609 while( cbParsed < pScanRsp->length )
4610 {
4611 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
4612 {
4613 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
4614 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
4615 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
4616 {
4617 if( csrIs11dSupported( pMac) )
4618 {
4619 //Check whether the BSS is acceptable base on 11d info and our configs.
4620 if( csrMatchCountryCode( pMac, NULL, pIes ) )
4621 {
4622 //Double check whether the channel is acceptable by us.
4623 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
4624 {
4625 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4626 }
4627 }
4628 }
4629 else
4630 {
4631 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4632 }
4633 }
4634 //Free the resource
4635 palFreeMemory( pMac->hHdd, pIes );
4636 }
4637 // skip over the BSS description to the next one...
4638 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
4639
4640 cbParsed += cbBssDesc;
4641 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
4642
4643 } //while
4644 }
4645 else
4646 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004647 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08004648 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004649 //HO bg scan/probe failed no need to try autonomously
4650 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4651 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004652#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4653 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
4654#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004655 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4656 {
4657 fRemoveCommand = eANI_BOOLEAN_TRUE;
4658 }
4659 }
4660 }while(0);
4661 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4662 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004663 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 -07004664 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
4665 fRet = eANI_BOOLEAN_TRUE;
4666 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4667 if(pfRemoveCommand)
4668 {
4669 *pfRemoveCommand = fRemoveCommand;
4670 }
4671
4672#ifdef WLAN_AP_STA_CONCURRENCY
4673 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
4674 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004675 /* Pending scan commands in the list because the previous scan command
4676 * was split into a scan command on one channel + a scan command for all
4677 * remaining channels.
4678 *
4679 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08004680 * NOTE for LFR:
4681 * Do not split scans if no concurrent infra connections are
4682 * active and if the scan is a BG scan triggered by LFR (OR)
4683 * any scan if LFR is in the middle of a BG scan. Splitting
4684 * the scan is delaying the time it takes for LFR to find
4685 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004686 */
Srikant Kuppa866893f2012-12-27 17:28:14 -08004687 if ( (csrIsStaSessionConnected(pMac) &&
4688#ifdef FEATURE_WLAN_LFR
4689 (csrIsConcurrentInfraConnected(pMac) ||
4690 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
4691 (pMac->roam.neighborRoamInfo.neighborRoamState !=
4692 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
4693#endif
4694 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004695 (csrIsP2pSessionConnected(pMac)) )
4696 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004697 /* if active connected sessions present then continue to split scan
4698 * with specified interval between consecutive scans */
4699 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Srikant Kuppa866893f2012-12-27 17:28:14 -08004700 palTimerStart(pMac->hHdd, pMac->scan.hTimerStaApConcTimer,
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004701 pCommand->u.scanCmd.u.scanRequest.restTime * PAL_TIMER_TO_MS_UNIT, eANI_BOOLEAN_FALSE);
4702 } else {
4703 /* if no connected sessions present then initiate next scan command immediately */
4704 /* minimum timer granularity is 10ms */
4705 palTimerStart(pMac->hHdd, pMac->scan.hTimerStaApConcTimer, 10 * 1000, eANI_BOOLEAN_FALSE);
4706 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004707 }
4708#endif
4709 return (fRet);
4710}
4711
4712
4713tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
4714{
4715 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
4716 tANI_BOOLEAN f = palEqualMemory( pMac->hHdd, pCommand->u.scanCmd.u.scanRequest.bssid,
4717 bssid, sizeof(tCsrBssid) );
4718
4719 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
4720 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
4721 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
4722}
4723
4724
4725eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
4726{
4727 eHalStatus status = eHAL_STATUS_SUCCESS;
4728 tListElem *pEntry;
4729 tSmeCmd *pCommand;
4730 eCsrScanStatus scanStatus;
4731 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
4732 tSmeGetScanChnRsp *pScanChnInfo;
4733 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4734 eCsrScanReason reason = eCsrScanOther;
4735
4736 pEntry = csrLLPeekHead( &pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK );
4737
4738 if ( pEntry )
4739 {
4740 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4741 if ( eSmeCommandScan == pCommand->command )
4742 {
4743 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
4744 reason = pCommand->u.scanCmd.reason;
4745 switch(pCommand->u.scanCmd.reason)
4746 {
4747 case eCsrScanAbortBgScan:
4748 case eCsrScanAbortNormalScan:
4749 case eCsrScanBGScanAbort:
4750 case eCsrScanBGScanEnable:
4751 break;
4752 case eCsrScanGetScanChnInfo:
4753 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004754 /*
4755 * status code not available in tSmeGetScanChnRsp, so
4756 * by default considereing it to be success
4757 */
4758 scanStatus = eSIR_SME_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004759 csrScanAgeResults(pMac, pScanChnInfo);
4760 break;
4761 case eCsrScanForCapsChange:
4762 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
4763 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004764 case eCsrScanP2PFindPeer:
4765 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) && (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
4766 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
4767 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004768 case eCsrScanSetBGScanParam:
4769 default:
4770 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
4771 {
4772 //Not to get channel info if the scan is not a wildcard scan because
4773 //it may cause scan results got aged out incorrectly.
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004774 if( csrScanIsWildCardScan( pMac, pCommand ) && (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
4775#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4776 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
4777#endif
4778 )
Jeff Johnson295189b2012-06-20 16:38:30 -07004779 {
4780 //Get the list of channels scanned
Jeff Johnson32d95a32012-09-10 13:15:23 -07004781 if( pCommand->u.scanCmd.reason != eCsrScanUserRequest)
4782 {
4783 csrScanGetScanChnInfo(pMac, NULL, NULL);
4784 }
4785 else
4786 {
4787 csrScanGetScanChnInfo(pMac, pCommand->u.scanCmd.callback, pCommand->u.scanCmd.pContext);
4788 pCommand->u.scanCmd.callback = NULL;
4789 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004790 }
4791 }
4792 break;
4793 }//switch
4794 if(fRemoveCommand)
4795 {
4796
4797 csrReleaseScanCommand(pMac, pCommand, scanStatus);
4798
Srikant Kuppa866893f2012-12-27 17:28:14 -08004799 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004800 smeProcessPendingQueue( pMac );
4801 }
4802 else
4803 {
4804 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
4805 status = eHAL_STATUS_FAILURE;
4806 }
4807 }
4808 else
4809 {
4810 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
4811 status = eHAL_STATUS_FAILURE;
4812 }
4813
4814 return (status);
4815}
4816
4817
4818
4819
4820tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
4821{
4822 tListElem *pEntry;
4823 tCsrScanResult *pResult;
4824 tCsrScanResultInfo *pRet = NULL;
4825 tScanResultList *pResultList = (tScanResultList *)hScanResult;
4826
4827 if(pResultList)
4828 {
4829 csrLLLock(&pResultList->List);
4830 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
4831 if(pEntry)
4832 {
4833 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
4834 pRet = &pResult->Result;
4835 }
4836 pResultList->pCurEntry = pEntry;
4837 csrLLUnlock(&pResultList->List);
4838 }
4839
4840 return pRet;
4841}
4842
4843
4844tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
4845{
4846 tListElem *pEntry = NULL;
4847 tCsrScanResult *pResult = NULL;
4848 tCsrScanResultInfo *pRet = NULL;
4849 tScanResultList *pResultList = (tScanResultList *)hScanResult;
4850
4851 if(pResultList)
4852 {
4853 csrLLLock(&pResultList->List);
4854 if(NULL == pResultList->pCurEntry)
4855 {
4856 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
4857 }
4858 else
4859 {
4860 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
4861 }
4862 if(pEntry)
4863 {
4864 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
4865 pRet = &pResult->Result;
4866 }
4867 pResultList->pCurEntry = pEntry;
4868 csrLLUnlock(&pResultList->List);
4869 }
4870
4871 return pRet;
4872}
4873
4874
4875//This function moves the first BSS that matches the bssid to the head of the result
4876eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
4877{
4878 eHalStatus status = eHAL_STATUS_FAILURE;
4879 tScanResultList *pResultList = (tScanResultList *)hScanResult;
4880 tCsrScanResult *pResult = NULL;
4881 tListElem *pEntry = NULL;
4882
4883 if(pResultList && bssid)
4884 {
4885 csrLLLock(&pResultList->List);
4886 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
4887 while(pEntry)
4888 {
4889 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
4890 if(palEqualMemory(pMac->hHdd, bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
4891 {
4892 status = eHAL_STATUS_SUCCESS;
4893 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
4894 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
4895 break;
4896 }
4897 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
4898 }
4899 csrLLUnlock(&pResultList->List);
4900 }
4901
4902 return (status);
4903}
4904
4905
4906//Remove the BSS if possible.
4907//Return -- TRUE == the BSS is remove. False == Fail to remove it
4908//This function is called when list lock is held. Be caution what functions it can call.
4909tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
4910{
4911 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4912 tANI_U32 i;
4913 tCsrRoamSession *pSession;
4914
4915 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
4916 {
4917 if( CSR_IS_SESSION_VALID( pMac, i ) )
4918 {
4919 pSession = CSR_GET_SESSION( pMac, i );
4920 //Not to remove the BSS we are connected to.
4921 if(csrIsConnStateDisconnected(pMac, i) || (NULL == pSession->pConnectBssDesc) ||
4922 (!csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
4923 pSession->pConnectBssDesc, NULL))
4924 )
4925 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004926 smsLog(pMac, LOGW, "Aging out BSS %02X-%02X-%02X-%02X-%02X-%02X Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004927 pResult->Result.BssDescriptor.bssId[0],
4928 pResult->Result.BssDescriptor.bssId[1],
4929 pResult->Result.BssDescriptor.bssId[2],
4930 pResult->Result.BssDescriptor.bssId[3],
4931 pResult->Result.BssDescriptor.bssId[4],
4932 pResult->Result.BssDescriptor.bssId[5],
4933 pResult->Result.BssDescriptor.channelId);
4934 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
4935 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
4936 {
4937 csrFreeScanResultEntry(pMac, pResult);
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07004938 fRet = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004939 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004940 break;
4941 }
4942 } //valid session
4943 } //for
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07004944 if( CSR_ROAM_SESSION_MAX == i && fRet != eANI_BOOLEAN_TRUE )
Jeff Johnson295189b2012-06-20 16:38:30 -07004945 {
4946 //reset the counter so this won't hapeen too soon
4947 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
4948 pResult->Result.BssDescriptor.nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
4949 }
4950
4951 return (fRet);
4952}
4953
4954
4955eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
4956{
4957 eHalStatus status = eHAL_STATUS_SUCCESS;
4958 tListElem *pEntry, *tmpEntry;
4959 tCsrScanResult *pResult;
4960 tLimScanChn *pChnInfo;
4961 tANI_U8 i;
4962
4963 csrLLLock(&pMac->scan.scanResultList);
4964 for(i = 0; i < pScanChnInfo->numChn; i++)
4965 {
4966 pChnInfo = &pScanChnInfo->scanChn[i];
4967 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
4968 while( pEntry )
4969 {
4970 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
4971 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4972 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
4973 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004974 if(pResult->AgingCount <= 0)
4975 {
4976 smsLog(pMac, LOGW, " age out due to ref count");
4977 csrScanAgeOutBss(pMac, pResult);
4978 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07004979 else
4980 {
4981 pResult->AgingCount--;
4982 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004983 }
4984 pEntry = tmpEntry;
4985 }
4986 }
4987 csrLLUnlock(&pMac->scan.scanResultList);
4988
4989 return (status);
4990}
4991
4992
4993eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
4994 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
4995{
4996 eHalStatus status = eHAL_STATUS_SUCCESS;
4997 tSirSmeScanReq *pMsg;
4998 tANI_U16 msgLen;
4999 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
5000 tSirScanType scanType = pScanReq->scanType;
5001 tANI_U32 minChnTime; //in units of milliseconds
5002 tANI_U32 maxChnTime; //in units of milliseconds
5003 tANI_U32 i;
5004 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
5005 tANI_U8 *pSelfMac = NULL;
5006
5007 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5008 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
5009 ( pScanReq->uIEFieldLen ) ;
5010
5011 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
5012 if(HAL_STATUS_SUCCESS(status))
5013 {
5014 do
5015 {
5016 palZeroMemory(pMac->hHdd, pMsg, msgLen);
5017 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5018 pMsg->length = pal_cpu_to_be16(msgLen);
5019 //ToDO: Fill in session info when we need to do scan base on session.
5020 pMsg->sessionId = 0;
5021 pMsg->transactionId = 0;
5022 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
5023 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
5024
5025 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
5026 {
5027 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
5028 }
5029 else
5030 {
5031 // Since we don't have session for the scanning, we find a valid session. In case we fail to
5032 // do so, get the WNI_CFG_STA_ID
5033 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5034 {
5035 if( CSR_IS_SESSION_VALID( pMac, i ) )
5036 {
5037 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
5038 break;
5039 }
5040 }
5041 if( CSR_ROAM_SESSION_MAX == i )
5042 {
5043 tANI_U32 len = WNI_CFG_BSSID_LEN;
5044 pSelfMac = selfMacAddr;
5045 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
5046 if( !HAL_STATUS_SUCCESS( status ) ||
5047 ( len < WNI_CFG_BSSID_LEN ) )
5048 {
5049 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
5050 //Force failed status
5051 status = eHAL_STATUS_FAILURE;
5052 break;
5053 }
5054 }
5055 }
5056 palCopyMemory( pMac->hHdd, (tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr) );
5057
5058 //sirCopyMacAddr
5059 palCopyMemory( pMac->hHdd, (tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr) );
5060 if( palEqualMemory( pMac->hHdd, pScanReq->bssid, bssid, sizeof(tCsrBssid) ) )
5061 {
5062 palFillMemory( pMac->hHdd, pMsg->bssId, sizeof(tSirMacAddr), 0xff );
5063 }
5064 else
5065 {
5066 palCopyMemory(pMac->hHdd, pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
5067 }
5068 minChnTime = pScanReq->minChnTime;
5069 maxChnTime = pScanReq->maxChnTime;
5070
5071 //Verify the scan type first, if the scan is active scan, we need to make sure we
5072 //are allowed to do so.
5073 /* if 11d is enabled & we don't see any beacon around, scan type falls
5074 back to passive. But in BT AMP STA mode we need to send out a
5075 directed probe*/
5076 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
5077 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
5078 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
5079 {
5080 scanType = pMac->scan.curScanType;
5081 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
5082 {
5083 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
5084 {
5085 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
5086 }
5087 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
5088 {
5089 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
5090 }
5091 }
5092 }
5093 pMsg->scanType = pal_cpu_to_be32(scanType);
5094
5095 pMsg->numSsid = (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ? pScanReq->SSIDs.numOfSSIDs :
5096 SIR_SCAN_MAX_NUM_SSID;
5097 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
5098 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005099 for (i = 0; i < pMsg->numSsid; i++)
5100 {
5101 palCopyMemory(pMac->hHdd, &pMsg->ssId[i], &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
5102 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005103 }
5104 else
5105 {
5106 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005107 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
5108 {
5109 pMsg->ssId[i].length = 0;
5110 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005111 }
5112
Jeff Johnson295189b2012-06-20 16:38:30 -07005113 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
5114 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08005115 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
5116 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07005117 //hidden SSID option
5118 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
5119 //rest time
5120 //pMsg->restTime = pScanReq->restTime;
5121 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5122 // All the scan results caching will be done by Roaming
5123 // We do not want LIM to do any caching of scan results,
5124 // so delete the LIM cache on all scan requests
5125 pMsg->returnFreshResults = pScanReqParam->freshScan;
5126 //Always ask for unique result
5127 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5128 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
5129 if(pScanReq->ChannelInfo.numOfChannels)
5130 {
5131 //Assuming the channelNumber is tANI_U8 (1 byte)
5132 status = palCopyMemory(pMac->hHdd, pMsg->channelList.channelNumber, pScanReq->ChannelInfo.ChannelList,
5133 pScanReq->ChannelInfo.numOfChannels);
5134 }
5135
5136 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
5137 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5138 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
5139 if(pScanReq->uIEFieldLen != 0)
5140 {
5141 palCopyMemory(pMac->hHdd, (tANI_U8 *)pMsg+pMsg->uIEFieldOffset,
5142 pScanReq->pIEField, pScanReq->uIEFieldLen );
5143 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005144 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005145
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07005146 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
5147 {
5148 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
5149 }
5150
Jeff Johnson295189b2012-06-20 16:38:30 -07005151 }while(0);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005152 smsLog(pMac, LOG1, FL("domainIdCurrent %d scanType %d bssType %d requestType %d numChannels %d "),
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005153 pMac->scan.domainIdCurrent, pMsg->scanType, pMsg->bssType,
5154 pScanReq->requestType, pMsg->channelList.numChannels);
5155
5156 for(i = 0; i < pMsg->channelList.numChannels; i++)
5157 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005158 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005159 }
5160
Jeff Johnson295189b2012-06-20 16:38:30 -07005161 if(HAL_STATUS_SUCCESS(status))
5162 {
5163 status = palSendMBMessage(pMac->hHdd, pMsg);
5164 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005165 else
5166 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005167 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005168 palFreeMemory(pMac->hHdd, pMsg);
5169 }
5170 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005171 else
5172 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005173 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005174 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005175
5176 return( status );
5177}
5178
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005179eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07005180{
5181 eHalStatus status = eHAL_STATUS_SUCCESS;
5182 tSirSmeScanReq *pMsg;
5183 tANI_U16 msgLen;
5184
5185 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
5186 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
5187 if(HAL_STATUS_SUCCESS(status))
5188 {
5189 palZeroMemory(pMac->hHdd, pMsg, msgLen);
5190 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5191 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005192 pMsg->sessionId = sessionId;
5193 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005194 pMsg->returnFreshResults = pScanReqParam->freshScan;
5195 //Always ask for unique result
5196 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5197 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5198 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005199 if (!HAL_STATUS_SUCCESS(status))
5200 {
5201 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
5202 }
5203
Jeff Johnson295189b2012-06-20 16:38:30 -07005204 }
5205
5206 return( status );
5207}
5208
5209
5210
5211eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5212{
5213 eHalStatus status = eHAL_STATUS_FAILURE;
5214 tScanReqParam scanReq;
5215
5216 do
5217 {
5218 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
5219 scanReq.fUniqueResult = TRUE;
5220 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
5221 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
5222 {
5223 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
5224 }
5225 else
5226 {
5227 // Basically do scan on all channels even for 11D 1st scan case.
5228 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5229 }
5230 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
5231 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
5232 {
5233 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
5234 }
5235
5236#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5237 {
5238 vos_log_scan_pkt_type *pScanLog = NULL;
5239
5240 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5241 if(pScanLog)
5242 {
5243 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5244 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
5245 {
5246 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
5247 }
5248 else
5249 {
5250 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
5251 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
5252 {
5253 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
5254 }
5255 else
5256 {
5257 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
5258 }
5259 }
5260 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
5261 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
5262 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5263 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
5264 {
5265 palCopyMemory(pMac->hHdd, pScanLog->channels,
5266 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5267 pScanLog->numChannel);
5268 }
5269 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5270 }
5271 }
5272#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5273
5274
5275 status = csrSendMBScanReq(pMac, pCommand->sessionId,
5276 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
5277 }while(0);
5278
5279 return( status );
5280}
5281
5282
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005283eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07005284{
5285 eHalStatus status = eHAL_STATUS_FAILURE;
5286 tScanReqParam scanReq;
5287
5288 do
5289 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005290#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5291 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
5292 {
5293 //to get the LFR candidates from PE cache
5294 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
5295 scanReq.fUniqueResult = TRUE;
5296 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5297 }
5298 else
5299#endif
5300 {
5301 //not a fresh scan
5302 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
5303 scanReq.fUniqueResult = TRUE;
5304 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5305 }
5306 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005307 }while(0);
5308
5309 return (status);
5310}
5311
5312
5313
5314eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5315{
5316 eHalStatus status = eHAL_STATUS_SUCCESS;
5317 tCsrChannelInfo newChannelInfo = {0, NULL};
5318 int i, j;
5319 tANI_U8 *pChannel = NULL;
5320 tANI_U32 len = 0;
5321
5322 // Transition to Scanning state...
5323 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5324 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005325 pCommand->u.scanCmd.lastRoamState[i] = csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005326 smsLog( pMac, LOG3, "starting SCAN command from %d state.... reason is %d", pCommand->u.scanCmd.lastRoamState[i], pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07005327 }
5328
5329 switch(pCommand->u.scanCmd.reason)
5330 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005331#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5332 case eCsrScanGetLfrResult:
5333#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005334 case eCsrScanGetResult:
5335 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005336 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005337 break;
5338 case eCsrScanSetBGScanParam:
5339 status = csrProcessSetBGScanParam(pMac, pCommand);
5340 break;
5341 case eCsrScanBGScanAbort:
5342 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
5343 break;
5344 case eCsrScanBGScanEnable:
5345 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
5346 break;
5347 case eCsrScanGetScanChnInfo:
5348 status = csrScanGetScanChannelInfo(pMac);
5349 break;
5350 case eCsrScanUserRequest:
5351 if(pMac->roam.configParam.fScanTwice)
5352 {
5353 //We scan 2.4 channel twice
5354 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
5355 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
5356 {
5357 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5358 //allocate twice the channel
5359 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(newChannelInfo.numOfChannels * 2);
5360 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5361 }
5362 else
5363 {
5364 //get the valid channel list to scan all.
5365 len = sizeof(pMac->roam.validChannelList);
5366
5367 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5368 {
5369 //allocate twice the channel
5370 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
5371 pChannel = pMac->roam.validChannelList;
5372 }
5373 }
5374 if(NULL == newChannelInfo.ChannelList)
5375 {
5376 newChannelInfo.numOfChannels = 0;
5377 }
5378 else
5379 {
5380 j = 0;
5381 for(i = 0; i < len; i++)
5382 {
5383 newChannelInfo.ChannelList[j++] = pChannel[i];
5384 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
5385 {
5386 newChannelInfo.ChannelList[j++] = pChannel[i];
5387 }
5388 }
5389 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5390 {
5391 //pChannel points to the channellist from the command, free it.
5392 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07005393 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005394 }
5395 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
5396 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
5397 }
5398 } //if(pMac->roam.configParam.fScanTwice)
5399
5400 status = csrScanChannels(pMac, pCommand);
5401
5402 break;
5403 default:
5404 status = csrScanChannels(pMac, pCommand);
5405 break;
5406 }
5407
5408 if(!HAL_STATUS_SUCCESS(status))
5409 {
5410 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
5411 }
5412
5413 return (status);
5414}
5415
5416
5417eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
5418{
5419 eHalStatus status = eHAL_STATUS_SUCCESS;
5420 tSmeCmd *pCommand = NULL;
5421
5422 if(pScanReq)
5423 {
5424 do
5425 {
5426 pCommand = csrGetCommandBuffer(pMac);
5427 if(!pCommand)
5428 {
5429 status = eHAL_STATUS_RESOURCES;
5430 break;
5431 }
5432 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
5433 pCommand->command = eSmeCommandScan;
5434 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
5435 pCommand->u.scanCmd.callback = NULL;
5436 pCommand->u.scanCmd.pContext = NULL;
5437 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
5438 //we have to do the follow
5439 if(pScanReq->ChannelInfo.numOfChannels == 0)
5440 {
5441 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
5442 }
5443 else
5444 {
5445 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5446 pScanReq->ChannelInfo.numOfChannels);
5447 if(HAL_STATUS_SUCCESS(status))
5448 {
5449 palCopyMemory(pMac->hHdd, pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5450 pScanReq->ChannelInfo.ChannelList, pScanReq->ChannelInfo.numOfChannels);
5451 }
5452 else
5453 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005454 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005455 csrReleaseCommandScan(pMac, pCommand);
5456 break;
5457 }
5458 }
5459
5460 //scan req for SSID
5461 if(pScanReq->SSID.length)
5462 {
5463 palCopyMemory(pMac->hHdd,
5464 pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
5465 pScanReq->SSID.ssId,
5466 pScanReq->SSID.length);
5467 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
5468
5469 }
5470 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
5471 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
5472 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
5473
5474
5475 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5476 if( !HAL_STATUS_SUCCESS( status ) )
5477 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005478 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005479 csrReleaseCommandScan( pMac, pCommand );
5480 break;
5481 }
5482 }while(0);
5483 }
5484
5485 return (status);
5486}
5487
5488eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
5489{
5490 eHalStatus status = eHAL_STATUS_SUCCESS;
5491 tSmeCmd *pCommand = NULL;
5492
5493 do
5494 {
5495 pCommand = csrGetCommandBuffer(pMac);
5496 if(!pCommand)
5497 {
5498 status = eHAL_STATUS_RESOURCES;
5499 break;
5500 }
5501 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
5502 pCommand->command = eSmeCommandScan;
5503 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
5504 pCommand->u.scanCmd.callback = NULL;
5505 pCommand->u.scanCmd.pContext = NULL;
5506 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5507 if( !HAL_STATUS_SUCCESS( status ) )
5508 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005509 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005510 csrReleaseCommandScan( pMac, pCommand );
5511 break;
5512 }
5513 }while(0);
5514
5515 return (status);
5516}
5517
5518
5519//This will enable the background scan with the non-zero interval
5520eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
5521{
5522 eHalStatus status = eHAL_STATUS_SUCCESS;
5523 tSmeCmd *pCommand = NULL;
5524
5525 if(pMac->roam.configParam.bgScanInterval)
5526 {
5527 do
5528 {
5529 pCommand = csrGetCommandBuffer(pMac);
5530 if(!pCommand)
5531 {
5532 status = eHAL_STATUS_RESOURCES;
5533 break;
5534 }
5535 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
5536 pCommand->command = eSmeCommandScan;
5537 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
5538 pCommand->u.scanCmd.callback = NULL;
5539 pCommand->u.scanCmd.pContext = NULL;
5540 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5541 if( !HAL_STATUS_SUCCESS( status ) )
5542 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005543 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005544 csrReleaseCommandScan( pMac, pCommand );
5545 break;
5546 }
5547 }while(0);
5548 //BG scan results are reported automatically by PE to SME once the scan is done.
5549 //No need to fetch the results explicitly.
5550 //csrScanStartGetResultTimer(pMac);
5551 csrScanStartResultAgingTimer(pMac);
5552 }
5553 else
5554 {
5555 //We don't have BG scan so stop the aging timer
5556 csrScanStopResultAgingTimer(pMac);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005557 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005558 status = eHAL_STATUS_INVALID_PARAMETER;
5559 }
5560
5561 return (status);
5562}
5563
5564
5565eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
5566{
5567 eHalStatus status = eHAL_STATUS_SUCCESS;
5568 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5569 tANI_U32 index = 0;
5570 tANI_U32 new_index = 0;
5571
5572 do
5573 {
5574 status = csrScanFreeRequest(pMac, pDstReq);
5575 if(HAL_STATUS_SUCCESS(status))
5576 {
5577 status = palCopyMemory(pMac->hHdd, pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08005578 /* Re-initialize the pointers to NULL since we did a copy */
5579 pDstReq->pIEField = NULL;
5580 pDstReq->ChannelInfo.ChannelList = NULL;
5581 pDstReq->SSIDs.SSIDList = NULL;
5582
Jeff Johnson295189b2012-06-20 16:38:30 -07005583 if(pSrcReq->uIEFieldLen == 0)
5584 {
5585 pDstReq->pIEField = NULL;
5586 }
5587 else
5588 {
5589 status = palAllocateMemory(pMac->hHdd, (void **)&pDstReq->pIEField, pSrcReq->uIEFieldLen);
5590 if(HAL_STATUS_SUCCESS(status))
5591 {
5592 palCopyMemory(pMac->hHdd, pDstReq->pIEField, pSrcReq->pIEField, pSrcReq->uIEFieldLen);
5593 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
5594 }
5595 else
5596 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005597 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnson295189b2012-06-20 16:38:30 -07005598 break;
5599 }
5600 }//Allocate memory for IE field
5601 {
5602 if(pSrcReq->ChannelInfo.numOfChannels == 0)
5603 {
5604 pDstReq->ChannelInfo.ChannelList = NULL;
5605 pDstReq->ChannelInfo.numOfChannels = 0;
5606 }
5607 else
5608 {
5609 status = palAllocateMemory(pMac->hHdd, (void **)&pDstReq->ChannelInfo.ChannelList,
5610 pSrcReq->ChannelInfo.numOfChannels * sizeof(*pDstReq->ChannelInfo.ChannelList));
5611 if(!HAL_STATUS_SUCCESS(status))
5612 {
5613 pDstReq->ChannelInfo.numOfChannels = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005614 smsLog(pMac, LOGE, "No memory for scanning Channel List");
Jeff Johnson295189b2012-06-20 16:38:30 -07005615 break;
5616 }
5617
5618 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
5619 {
5620 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5621 {
5622 pDstReq->ChannelInfo.ChannelList[new_index] =
5623 pSrcReq->ChannelInfo.ChannelList[index];
5624 new_index++;
5625 }
5626 pDstReq->ChannelInfo.numOfChannels = new_index;
5627 }
5628 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
5629 {
5630 new_index = 0;
5631 pMac->roam.numValidChannels = len;
5632 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5633 {
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005634 /* Allow scan on valid channels only.
5635 * If it is p2p scan and valid channel list doesnt contain
5636 * social channels, enforce scan on social channels because
5637 * that is the only way to find p2p peers.
5638 * This can happen only if band is set to 5Ghz mode.
5639 */
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005640 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index])) ||
5641 ((eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType) &&
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005642 CSR_IS_SOCIAL_CHANNEL(pSrcReq->ChannelInfo.ChannelList[index])))
Jeff Johnson295189b2012-06-20 16:38:30 -07005643 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08005644 if( (pSrcReq->skipDfsChnlInP2pSearch &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005645 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08005646#ifdef FEATURE_WLAN_LFR
5647 /*
5648 * If LFR is requesting a contiguous scan
5649 * (i.e. numOfChannels > 1), then ignore
5650 * DFS channels.
5651 * TODO: vos_nv_getChannelEnabledState is returning
5652 * 120, 124 and 128 as non-DFS channels. Hence, the
5653 * use of direct check for channels below.
5654 */
5655 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
5656 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Srinivas Girigowdade697412013-02-14 16:31:48 -08005657 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])))
Srikant Kuppa866893f2012-12-27 17:28:14 -08005658#endif
5659 )
5660 {
5661#ifdef FEATURE_WLAN_LFR
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005662 smsLog(pMac, LOG2,
Srikant Kuppa866893f2012-12-27 17:28:14 -08005663 "%s: reqType=%d, numOfChannels=%d,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005664 " ignoring DFS channel %d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005665 __func__, pSrcReq->requestType,
5666 pSrcReq->ChannelInfo.numOfChannels,
5667 pSrcReq->ChannelInfo.ChannelList[index]);
5668#endif
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005669 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08005670 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005671
Jeff Johnson295189b2012-06-20 16:38:30 -07005672 pDstReq->ChannelInfo.ChannelList[new_index] =
5673 pSrcReq->ChannelInfo.ChannelList[index];
5674 new_index++;
5675 }
5676 }
5677 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08005678#ifdef FEATURE_WLAN_LFR
5679 if ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
5680 (0 == pDstReq->ChannelInfo.numOfChannels))
5681 {
5682 /*
5683 * No valid channels found in the request.
5684 * Only perform scan on the channels passed
5685 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN.
5686 * Passing 0 to LIM will trigger a scan on
5687 * all valid channels which is not desirable.
5688 */
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005689 smsLog(pMac, LOGE, "%s: no valid channels found (request=%d)",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005690 __func__, pSrcReq->requestType);
5691 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5692 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005693 smsLog(pMac, LOGE, "pSrcReq index=%d channel=%d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005694 index, pSrcReq->ChannelInfo.ChannelList[index]);
5695 }
5696 status = eHAL_STATUS_FAILURE;
5697 break;
5698 }
5699#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005700 }
5701 else
5702 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005703 smsLog(pMac, LOGE, "Couldn't get the valid Channel List, keeping requester's list");
Jeff Johnson295189b2012-06-20 16:38:30 -07005704 palCopyMemory(pMac->hHdd, pDstReq->ChannelInfo.ChannelList, pSrcReq->ChannelInfo.ChannelList,
5705 pSrcReq->ChannelInfo.numOfChannels * sizeof(*pDstReq->ChannelInfo.ChannelList));
5706 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
5707 }
5708 }//Allocate memory for Channel List
5709 }
5710 if(pSrcReq->SSIDs.numOfSSIDs == 0)
5711 {
5712 pDstReq->SSIDs.numOfSSIDs = 0;
5713 pDstReq->SSIDs.SSIDList = NULL;
5714 }
5715 else
5716 {
5717 status = palAllocateMemory(pMac->hHdd, (void **)&pDstReq->SSIDs.SSIDList,
5718 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
5719 if(HAL_STATUS_SUCCESS(status))
5720 {
5721 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
5722 palCopyMemory(pMac->hHdd, pDstReq->SSIDs.SSIDList, pSrcReq->SSIDs.SSIDList,
5723 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
5724 }
5725 else
5726 {
5727 pDstReq->SSIDs.numOfSSIDs = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005728 smsLog(pMac, LOGE, "No memory for scanning SSID List");
Jeff Johnson295189b2012-06-20 16:38:30 -07005729 break;
5730 }
5731 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07005732 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07005733 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005734
5735 }
5736 }while(0);
5737
5738 if(!HAL_STATUS_SUCCESS(status))
5739 {
5740 csrScanFreeRequest(pMac, pDstReq);
5741 }
5742
5743 return (status);
5744}
5745
5746
5747eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
5748{
5749 eHalStatus status = eHAL_STATUS_SUCCESS;
5750
5751 if(pReq->ChannelInfo.ChannelList)
5752 {
5753 status = palFreeMemory(pMac->hHdd, pReq->ChannelInfo.ChannelList);
5754 pReq->ChannelInfo.ChannelList = NULL;
5755 }
5756 pReq->ChannelInfo.numOfChannels = 0;
5757 if(pReq->pIEField)
5758 {
5759 status = palFreeMemory(pMac->hHdd, pReq->pIEField);
5760 pReq->pIEField = NULL;
5761 }
5762 pReq->uIEFieldLen = 0;
5763 if(pReq->SSIDs.SSIDList)
5764 {
5765 palFreeMemory(pMac->hHdd, pReq->SSIDs.SSIDList);
5766 pReq->SSIDs.SSIDList = NULL;
5767 }
5768 pReq->SSIDs.numOfSSIDs = 0;
5769
5770 return (status);
5771}
5772
5773
5774void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
5775{
5776 if(pCommand->u.scanCmd.callback)
5777 {
5778// sme_ReleaseGlobalLock( &pMac->sme );
5779 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
5780// sme_AcquireGlobalLock( &pMac->sme );
5781 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005782 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005783 }
5784}
5785
5786
5787void csrScanStopTimers(tpAniSirGlobal pMac)
5788{
5789 csrScanStopResultAgingTimer(pMac);
5790 csrScanStopIdleScanTimer(pMac);
5791 csrScanStopGetResultTimer(pMac);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005792 if(0 != pMac->scan.scanResultCfgAgingTime )
5793 {
5794 csrScanStopResultCfgAgingTimer(pMac);
5795 }
5796
Jeff Johnson295189b2012-06-20 16:38:30 -07005797}
5798
5799
5800eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
5801{
5802 eHalStatus status;
5803
5804 if(pMac->scan.fScanEnable)
5805 {
5806 status = palTimerStart(pMac->hHdd, pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL, eANI_BOOLEAN_TRUE);
5807 }
5808 else
5809 {
5810 status = eHAL_STATUS_FAILURE;
5811 }
5812
5813 return (status);
5814}
5815
5816
5817eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
5818{
5819 return (palTimerStop(pMac->hHdd, pMac->scan.hTimerGetResult));
5820}
5821
5822
5823void csrScanGetResultTimerHandler(void *pv)
5824{
5825 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
5826
5827 csrScanRequestResult(pMac);
5828}
5829
5830#ifdef WLAN_AP_STA_CONCURRENCY
5831static void csrStaApConcTimerHandler(void *pv)
5832{
5833 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
5834 tListElem *pEntry;
5835 tSmeCmd *pScanCmd;
5836
5837 csrLLLock(&pMac->scan.scanCmdPendingList);
5838
5839 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
5840 {
5841 tCsrScanRequest scanReq;
5842 tSmeCmd *pSendScanCmd = NULL;
5843 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07005844 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08005845 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07005846 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
5847 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
5848 eHalStatus status;
5849
Jeff Johnson295189b2012-06-20 16:38:30 -07005850 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5851 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005852
5853 /* if any session is connected and the number of channels to scan is
5854 * greater than 1 then split the scan into multiple scan operations
5855 * on each individual channel else continue to perform scan on all
5856 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005857
5858 /* split scan if number of channels to scan is greater than 1 and
5859 * any one of the following:
5860 * - STA session is connected and the scan is not a P2P search
5861 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08005862 * Do not split scans if no concurrent infra connections are
5863 * active and if the scan is a BG scan triggered by LFR (OR)
5864 * any scan if LFR is in the middle of a BG scan. Splitting
5865 * the scan is delaying the time it takes for LFR to find
5866 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005867 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07005868
5869 if((csrIsStaSessionConnected(pMac) &&
5870 !csrIsP2pSessionConnected(pMac)))
5871 {
5872 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
5873 }
5874 else if(csrIsP2pSessionConnected(pMac))
5875 {
5876 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
5877 }
5878
5879 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005880 ((csrIsStaSessionConnected(pMac) &&
5881#ifdef FEATURE_WLAN_LFR
5882 (csrIsConcurrentInfraConnected(pMac) ||
5883 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
5884 (pMac->roam.neighborRoamInfo.neighborRoamState !=
5885 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5886#endif
5887 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005888 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07005889 {
5890 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
5891
5892 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
5893 if (!pSendScanCmd)
5894 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005895 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07005896 csrLLUnlock(&pMac->scan.scanCmdPendingList);
5897 return;
5898 }
5899 pSendScanCmd->command = pScanCmd->command;
5900 pSendScanCmd->sessionId = pScanCmd->sessionId;
5901 pSendScanCmd->u.scanCmd.callback = NULL;
5902 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
5903 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
5904 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
5905
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07005906 /* First copy all the parameters to local variable of scan request */
5907 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
5908
5909 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08005910 if(scanReq.ChannelInfo.ChannelList != NULL)
5911 {
5912 palFreeMemory(pMac->hHdd,scanReq.ChannelInfo.ChannelList);
5913 scanReq.ChannelInfo.ChannelList = NULL;
5914 }
5915
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07005916 pChnInfo->numOfChannels = nNumChanCombinedConc;
Vinay Malekal05fdc812012-12-17 13:04:30 -08005917 palCopyMemory(pMac->hHdd, &channelToScan[0], &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
5918 pChnInfo->numOfChannels * sizeof(tANI_U8)); //just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07005919 pChnInfo->ChannelList = &channelToScan[0];
5920
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07005921 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07005922 {
5923 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08005924 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07005925 }
5926
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07005927 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07005928
5929 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
5930 //Modify callers parameters in case of concurrency
5931 scanReq.scanType = eSIR_ACTIVE_SCAN;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07005932 //Use concurrency values for min/maxChnTime.
5933 //We know csrIsAnySessionConnected(pMac) returns TRUE here
5934 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005935
5936 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
5937 if(!HAL_STATUS_SUCCESS(status))
5938 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005939 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005940 csrLLUnlock(&pMac->scan.scanCmdPendingList);
5941 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08005942 }
5943 /* Clean the local scan variable */
5944 scanReq.ChannelInfo.ChannelList = NULL;
5945 scanReq.ChannelInfo.numOfChannels = 0;
5946 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005947 }
5948 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005949 {
5950 /* no active connected session present or numChn == 1
5951 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07005952 pSendScanCmd = pScanCmd;
5953 //remove this command from pending list
5954 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
5955 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005956 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005957 }
5958
5959 }
5960 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
5961
5962 }
5963
Jeff Johnson295189b2012-06-20 16:38:30 -07005964 csrLLUnlock(&pMac->scan.scanCmdPendingList);
5965
5966}
5967#endif
5968
5969eHalStatus csrScanStartResultAgingTimer(tpAniSirGlobal pMac)
5970{
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005971 eHalStatus status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005972
5973 if(pMac->scan.fScanEnable)
5974 {
5975 status = palTimerStart(pMac->hHdd, pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL, eANI_BOOLEAN_TRUE);
5976 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005977 return (status);
5978}
5979
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005980eHalStatus csrScanStartResultCfgAgingTimer(tpAniSirGlobal pMac)
5981{
5982 eHalStatus status = eHAL_STATUS_FAILURE;
5983
5984 if(pMac->scan.fScanEnable)
5985 {
5986 status = palTimerStart(pMac->hHdd, pMac->scan.hTimerResultCfgAging,
5987 CSR_SCAN_RESULT_CFG_AGING_INTERVAL, eANI_BOOLEAN_TRUE);
5988 }
5989 return (status);
5990}
Jeff Johnson295189b2012-06-20 16:38:30 -07005991
5992eHalStatus csrScanStopResultAgingTimer(tpAniSirGlobal pMac)
5993{
5994 return (palTimerStop(pMac->hHdd, pMac->scan.hTimerResultAging));
5995}
5996
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005997eHalStatus csrScanStopResultCfgAgingTimer(tpAniSirGlobal pMac)
5998{
5999 return (palTimerStop(pMac->hHdd, pMac->scan.hTimerResultCfgAging));
6000}
Jeff Johnson295189b2012-06-20 16:38:30 -07006001
6002//This function returns the maximum time a BSS is allowed in the scan result.
6003//The time varies base on connection and power saving factors.
6004//Not connected, No PS
6005//Not connected, with PS
6006//Connected w/o traffic, No PS
6007//Connected w/o traffic, with PS
6008//Connected w/ traffic, no PS -- Not supported
6009//Connected w/ traffic, with PS -- Not supported
6010//the return unit is in seconds.
6011tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
6012{
6013 tANI_U32 nRet;
6014
6015 if(pMac->scan.nAgingCountDown)
6016 {
6017 //Calculate what should be the timeout value for this
6018 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
6019 pMac->scan.nAgingCountDown--;
6020 }
6021 else
6022 {
6023 if( csrIsAllSessionDisconnected( pMac ) )
6024 {
6025 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
6026 {
6027 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
6028 }
6029 else
6030 {
6031 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
6032 }
6033 }
6034 else
6035 {
6036 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
6037 {
6038 nRet = pMac->roam.configParam.scanAgeTimeCPS;
6039 }
6040 else
6041 {
6042 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
6043 }
6044 }
6045 //If state-change causing aging time out change, we want to delay it somewhat to avoid
6046 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
6047 if(pMac->scan.nLastAgeTimeOut > nRet)
6048 {
6049 if(nRet)
6050 {
6051 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
6052 }
6053 pMac->scan.nLastAgeTimeOut = nRet;
6054 nRet *= pMac->scan.nAgingCountDown;
6055 }
6056 else
6057 {
6058 pMac->scan.nLastAgeTimeOut = nRet;
6059 }
6060 }
6061
6062 return (nRet);
6063}
6064
6065
6066void csrScanResultAgingTimerHandler(void *pv)
6067{
6068 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6069 tANI_BOOLEAN fDisconnected = csrIsAllSessionDisconnected(pMac);
6070
6071 //no scan, no aging
6072 if(pMac->scan.fScanEnable &&
6073 (((eANI_BOOLEAN_FALSE == fDisconnected) && pMac->roam.configParam.bgScanInterval)
6074 || (fDisconnected && (pMac->scan.fCancelIdleScan == eANI_BOOLEAN_FALSE)))
6075 )
6076 {
6077 tListElem *pEntry, *tmpEntry;
6078 tCsrScanResult *pResult;
6079 tANI_TIMESTAMP ageOutTime = (tANI_TIMESTAMP)(csrScanGetAgeOutTime(pMac) * PAL_TICKS_PER_SECOND); //turn it into 10ms units
6080 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6081
6082 csrLLLock(&pMac->scan.scanResultList);
6083 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6084 while( pEntry )
6085 {
6086 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6087 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6088 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6089 {
6090 smsLog(pMac, LOGW, " age out due to time out");
6091 csrScanAgeOutBss(pMac, pResult);
6092 }
6093 pEntry = tmpEntry;
6094 }
6095 csrLLUnlock(&pMac->scan.scanResultList);
6096 }
6097}
6098
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006099static void csrScanResultCfgAgingTimerHandler(void *pv)
6100{
6101 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6102 tListElem *pEntry, *tmpEntry;
6103 tCsrScanResult *pResult;
6104 tANI_TIMESTAMP ageOutTime = pMac->scan.scanResultCfgAgingTime * PAL_TICKS_PER_SECOND;
6105 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6106
6107 csrLLLock(&pMac->scan.scanResultList);
6108 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6109 while( pEntry )
6110 {
6111 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6112 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6113 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6114 {
6115 smsLog(pMac, LOGW, " age out due to time out");
6116 csrScanAgeOutBss(pMac, pResult);
6117 }
6118 pEntry = tmpEntry;
6119 }
6120 csrLLUnlock(&pMac->scan.scanResultList);
6121}
Jeff Johnson295189b2012-06-20 16:38:30 -07006122
6123eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
6124{
6125 eHalStatus status;
6126
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006127 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07006128 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
6129 {
6130 pMac->scan.nIdleScanTimeGap += interval;
6131 palTimerStop(pMac->hHdd, pMac->scan.hTimerIdleScan);
6132 status = palTimerStart(pMac->hHdd, pMac->scan.hTimerIdleScan, interval, eANI_BOOLEAN_FALSE);
6133 if( !HAL_STATUS_SUCCESS(status) )
6134 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006135 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07006136 //This should not happen but set the flag to restart when ready
6137 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6138 }
6139 }
6140 else
6141 {
6142 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
6143 {
6144 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6145 }
6146 status = eHAL_STATUS_FAILURE;
6147 }
6148
6149 return (status);
6150}
6151
6152
6153eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
6154{
6155 return (palTimerStop(pMac->hHdd, pMac->scan.hTimerIdleScan));
6156}
6157
6158
6159//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
6160void csrScanSuspendIMPS( tpAniSirGlobal pMac )
6161{
6162 csrScanCancelIdleScan(pMac);
6163}
6164
6165
6166//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
6167//because IMPS maybe disabled.
6168void csrScanResumeIMPS( tpAniSirGlobal pMac )
6169{
6170 csrScanStartIdleScan( pMac );
6171}
6172
6173
6174void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
6175{
6176 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
6177
6178 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6179 {
6180 if(pMac->roam.configParam.IsIdleScanEnabled)
6181 {
6182 if(HAL_STATUS_SUCCESS(status))
6183 {
6184 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
6185 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006186 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006187 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
6188 }
6189 else
6190 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006191 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006192 //even though we are in timer handle, calling stop timer will make sure the timer
6193 //doesn't get to restart.
6194 csrScanStopIdleScanTimer(pMac);
6195 }
6196 }
6197 else
6198 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006199 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006200 }
6201 }
6202 else
6203 {//we might need another flag to check if CSR needs to request imps at all
6204
6205 tANI_U32 nTime = 0;
6206
6207 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
6208 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
6209 {
6210 csrScanStartIdleScanTimer(pMac, nTime);
6211 }
6212 }
6213 }
6214}
6215
6216
6217//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
6218//idle scan timer interval
6219//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
6220eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
6221{
6222 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6223
6224 //Do not trigger IMPS in case of concurrency
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006225 if (vos_concurrent_sessions_running() && csrIsAnySessionInConnectState(pMac))
6226 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006227 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006228 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006229 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006230
6231 if(pTimeInterval)
6232 {
6233 *pTimeInterval = 0;
6234 }
6235
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006236 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006237 if( smeCommandPending( pMac ) )
6238 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006239 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006240 //Not to enter IMPS because more work to do
6241 if(pTimeInterval)
6242 {
6243 *pTimeInterval = 0;
6244 }
6245 //restart when ready
6246 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6247
6248 return (status);
6249 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006250 if (IsPmcImpsReqFailed (pMac))
6251 {
6252 if(pTimeInterval)
6253 {
6254 *pTimeInterval = 1000000; //usec
6255 }
6256 //restart when ready
6257 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006258
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006259 return status;
6260 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006261 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6262 /*&& pMac->roam.configParam.impsSleepTime*/)
6263 {
6264 //Stop get result timer because idle scan gets scan result out of PE
6265 csrScanStopGetResultTimer(pMac);
6266 if(pTimeInterval)
6267 {
6268 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
6269 }
6270 //pmcRequestImps take a period in millisecond unit.
6271 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
6272 if(!HAL_STATUS_SUCCESS(status))
6273 {
6274 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
6275 {
6276 //Do restart the timer if CSR thinks it cannot do IMPS
6277 if( !csrCheckPSReady( pMac ) )
6278 {
6279 if(pTimeInterval)
6280 {
6281 *pTimeInterval = 0;
6282 }
6283 //Set the restart flag to true because that idle scan
6284 //can be restarted even though the timer will not be running
6285 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6286 }
6287 else
6288 {
6289 //For not now, we do a quicker retry
6290 if(pTimeInterval)
6291 {
6292 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
6293 }
6294 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006295 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006296 }
6297 else
6298 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006299 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006300 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
6301 //the callback will be called in the future. Should not happen though.
6302 status = eHAL_STATUS_SUCCESS;
6303 pMac->scan.nIdleScanTimeGap = 0;
6304 }
6305 }
6306 else
6307 {
6308 //requested so let's reset the value
6309 pMac->scan.nIdleScanTimeGap = 0;
6310 }
6311 }
6312
6313 return (status);
6314}
6315
6316
6317eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
6318{
6319 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6320 tANI_U32 nTime = 0;
6321
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006322 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006323 if(pMac->roam.configParam.IsIdleScanEnabled)
6324 {
6325 //stop bg scan first
6326 csrScanBGScanAbort(pMac);
6327 //Stop get result timer because idle scan gets scan result out of PE
6328 csrScanStopGetResultTimer(pMac);
6329 //Enable aging timer since idle scan is going on
6330 csrScanStartResultAgingTimer(pMac);
6331 }
6332 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
6333 status = csrScanTriggerIdleScan(pMac, &nTime);
6334 if(!HAL_STATUS_SUCCESS(status))
6335 {
6336 csrScanStartIdleScanTimer(pMac, nTime);
6337 }
6338
6339 return (status);
6340}
6341
6342
6343void csrScanCancelIdleScan(tpAniSirGlobal pMac)
6344{
6345 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6346 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006347 if (vos_concurrent_sessions_running()) {
6348 return;
6349 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006350 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07006351 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
6352 //Set the restart flag in case later on it is uncancelled
6353 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6354 csrScanStopIdleScanTimer(pMac);
6355 csrScanRemoveNotRoamingScanCommand(pMac);
6356 }
6357}
6358
6359
6360void csrScanIdleScanTimerHandler(void *pv)
6361{
6362 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6363 eHalStatus status;
6364 tANI_U32 nTime = 0;
6365
6366 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006367 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006368 status = csrScanTriggerIdleScan(pMac, &nTime);
6369 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
6370 {
6371 //Check whether it is time to actually do an idle scan
6372 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
6373 {
6374 pMac->scan.nIdleScanTimeGap = 0;
6375 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
6376 }
6377 else
6378 {
6379 csrScanStartIdleScanTimer(pMac, nTime);
6380 }
6381 }
6382}
6383
6384
6385
6386
6387tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
6388{
6389 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6390 tListElem *pEntry, *pEntryTmp;
6391 tSmeCmd *pCommand;
6392 tDblLinkList localList;
6393
6394 vos_mem_zero(&localList, sizeof(tDblLinkList));
6395 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6396 {
6397 smsLog(pMac, LOGE, FL(" failed to open list"));
6398 return fRet;
6399 }
6400
6401 csrLLLock(&pMac->sme.smeCmdPendingList);
6402 pEntry = csrLLPeekHead(&pMac->sme.smeCmdPendingList, LL_ACCESS_NOLOCK);
6403 while(pEntry)
6404 {
6405 pEntryTmp = csrLLNext(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK);
6406 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6407 if( eSmeCommandScan == pCommand->command )
6408 {
6409 switch( pCommand->u.scanCmd.reason )
6410 {
6411 case eCsrScanIdleScan:
6412 if( csrLLRemoveEntry(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK) )
6413 {
6414 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6415 }
6416 fRet = eANI_BOOLEAN_TRUE;
6417 break;
6418
6419 default:
6420 break;
6421 } //switch
6422 }
6423 pEntry = pEntryTmp;
6424 }
6425
6426 csrLLUnlock(&pMac->sme.smeCmdPendingList);
6427
6428 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6429 {
6430 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6431 csrReleaseCommandScan( pMac, pCommand );
6432 }
6433
6434 csrLLClose(&localList);
6435
6436 return (fRet);
6437}
6438
6439
6440tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
6441{
6442 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6443 tListElem *pEntry, *pEntryTmp;
6444 tSmeCmd *pCommand;
6445 tDblLinkList localList;
6446
6447 vos_mem_zero(&localList, sizeof(tDblLinkList));
6448 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6449 {
6450 smsLog(pMac, LOGE, FL(" failed to open list"));
6451 return fRet;
6452 }
6453
6454 csrLLLock(&pMac->sme.smeCmdPendingList);
6455 pEntry = csrLLPeekHead(&pMac->sme.smeCmdPendingList, LL_ACCESS_NOLOCK);
6456 while(pEntry)
6457 {
6458 pEntryTmp = csrLLNext(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK);
6459 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6460 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
6461 {
6462 switch(pCommand->u.scanCmd.reason)
6463 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006464#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6465 case eCsrScanGetLfrResult:
6466#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006467 case eCsrScanGetResult:
6468 case eCsrScanSetBGScanParam:
6469 case eCsrScanBGScanAbort:
6470 case eCsrScanBGScanEnable:
6471 case eCsrScanGetScanChnInfo:
6472 break;
6473 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006474 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006475 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006476 //The rest are fresh scan requests
6477 if( csrLLRemoveEntry(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK) )
6478 {
6479 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6480 }
6481 fRet = eANI_BOOLEAN_TRUE;
6482 break;
6483 }
6484 }
6485 pEntry = pEntryTmp;
6486 }
6487
6488 csrLLUnlock(&pMac->sme.smeCmdPendingList);
6489
6490 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6491 {
6492 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6493 if (pCommand->u.scanCmd.callback)
6494 {
6495 /* User scan request is pending,
6496 * send response with status eCSR_SCAN_ABORT*/
6497 pCommand->u.scanCmd.callback(pMac,
6498 pCommand->u.scanCmd.pContext,
6499 pCommand->u.scanCmd.scanID,
6500 eCSR_SCAN_ABORT);
6501 }
6502 csrReleaseCommandScan( pMac, pCommand );
6503 }
6504 csrLLClose(&localList);
6505
6506 return (fRet);
6507}
6508
6509
6510void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6511{
6512 eCsrScanReason reason = pCommand->u.scanCmd.reason;
6513 tANI_U32 i;
6514 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6515 {
Jeff Johnson43971f52012-07-17 12:26:56 -07006516 csrRoamStateChange( pMac, pCommand->u.scanCmd.lastRoamState[i], i);
Jeff Johnson295189b2012-06-20 16:38:30 -07006517 }
6518
6519 csrScanCallCallback(pMac, pCommand, scanStatus);
6520
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006521 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006522 if( csrLLRemoveEntry( &pMac->sme.smeCmdActiveList, &pCommand->Link, LL_ACCESS_LOCK ) )
6523 {
6524 csrReleaseCommandScan( pMac, pCommand );
6525 }
6526 else
6527 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006528 smsLog(pMac, LOGE, " ********csrReleaseScanCommand cannot release command reason %d", pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006529 }
6530}
6531
6532
6533eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6534 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
6535{
6536 eHalStatus status = eHAL_STATUS_SUCCESS;
6537 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6538
Jeff Johnson32d95a32012-09-10 13:15:23 -07006539 if(!pSession)
6540 {
6541 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6542 return eHAL_STATUS_FAILURE;
6543 }
6544
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006545 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006546 csrResetPMKIDCandidateList(pMac, sessionId);
6547 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6548 {
6549 tCsrScanResultFilter *pScanFilter;
6550 tCsrScanResultInfo *pScanResult;
6551 tScanResultHandle hBSSList;
6552 tANI_U32 nItems = *pNumItems;
6553
6554 *pNumItems = 0;
6555 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
6556 if(HAL_STATUS_SUCCESS(status))
6557 {
6558 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
6559 //Here is the profile we need to connect to
6560 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
6561 if(HAL_STATUS_SUCCESS(status))
6562 {
6563 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
6564 if(HAL_STATUS_SUCCESS(status))
6565 {
6566 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
6567 {
6568 //NumPmkidCandidate adds up here
6569 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
6570 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
6571 }
6572 if(pSession->NumPmkidCandidate)
6573 {
6574 *pNumItems = pSession->NumPmkidCandidate;
6575 palCopyMemory(pMac->hHdd, pPmkidList, pSession->PmkidCandidateInfo,
6576 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
6577 }
6578 csrScanResultPurge(pMac, hBSSList);
6579 }//Have scan result
6580 csrFreeScanFilter(pMac, pScanFilter);
6581 }
6582 palFreeMemory(pMac->hHdd, pScanFilter);
6583 }
6584 }
6585
6586 return (status);
6587}
6588
6589
6590
6591#ifdef FEATURE_WLAN_WAPI
6592eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6593 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
6594{
6595 eHalStatus status = eHAL_STATUS_SUCCESS;
6596 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6597
Jeff Johnson32d95a32012-09-10 13:15:23 -07006598 if(!pSession)
6599 {
6600 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6601 return eHAL_STATUS_FAILURE;
6602 }
6603
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006604 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006605 csrResetBKIDCandidateList(pMac, sessionId);
6606 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6607 {
6608 tCsrScanResultFilter *pScanFilter;
6609 tCsrScanResultInfo *pScanResult;
6610 tScanResultHandle hBSSList;
6611 tANI_U32 nItems = *pNumItems;
6612 *pNumItems = 0;
6613 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
6614 if(HAL_STATUS_SUCCESS(status))
6615 {
6616 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
6617 //Here is the profile we need to connect to
6618 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
6619 if(HAL_STATUS_SUCCESS(status))
6620 {
6621 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
6622 if(HAL_STATUS_SUCCESS(status))
6623 {
6624 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
6625 {
6626 //pMac->scan.NumBkidCandidate adds up here
6627 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
6628 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
6629
6630 }
6631 if(pSession->NumBkidCandidate)
6632 {
6633 *pNumItems = pSession->NumBkidCandidate;
6634 palCopyMemory(pMac->hHdd, pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
6635 }
6636 csrScanResultPurge(pMac, hBSSList);
6637 }//Have scan result
6638 }
6639 palFreeMemory(pMac->hHdd, pScanFilter);
6640 }
6641 }
6642
6643 return (status);
6644}
6645#endif /* FEATURE_WLAN_WAPI */
6646
6647
6648
6649//This function is usually used for BSSs that suppresses SSID so the profile
6650//shall have one and only one SSID
6651eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId)
6652{
6653 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
6654 tSmeCmd *pScanCmd = NULL;
6655 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
6656 tANI_U8 index = 0;
6657 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
6658
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006659 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006660 //For WDS, we use the index 0. There must be at least one in there
6661 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
6662 {
6663 numSsid = 1;
6664 }
6665 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
6666 {
6667 do
6668 {
6669 pScanCmd = csrGetCommandBuffer(pMac);
6670 if(!pScanCmd)
6671 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006672 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006673 break;
6674 }
6675 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
6676 status = palAllocateMemory(pMac->hHdd, (void **)&pScanCmd->u.scanCmd.pToRoamProfile, sizeof(tCsrRoamProfile));
6677 if(!HAL_STATUS_SUCCESS(status))
6678 break;
6679 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
6680 if(!HAL_STATUS_SUCCESS(status))
6681 break;
6682 pScanCmd->u.scanCmd.roamId = roamId;
6683 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07006684 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07006685 pScanCmd->u.scanCmd.callback = NULL;
6686 pScanCmd->u.scanCmd.pContext = NULL;
6687 pScanCmd->u.scanCmd.reason = eCsrScanForSsid;
6688 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6689 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest));
6690 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07006691 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07006692 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
6693 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
6694 {
6695 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
6696 }
6697 if(pProfile->pAddIEScan)
6698 {
6699 status = palAllocateMemory(pMac->hHdd,
6700 (void **)&pScanCmd->u.scanCmd.u.scanRequest.pIEField,
6701 pProfile->nAddIEScanLength);
6702 palZeroMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.pIEField, pProfile->nAddIEScanLength);
6703 if(HAL_STATUS_SUCCESS(status))
6704 {
6705 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.pIEField, pProfile->pAddIEScan, pProfile->nAddIEScanLength);
6706 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
6707 }
6708 else
6709 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006710 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07006711 }
6712 } //Allocate memory for IE field
6713 else
6714 {
6715 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
6716 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07006717 /* For one channel be good enpugh time to receive beacon atleast */
6718 if( 1 == pProfile->ChannelInfo.numOfChannels )
6719 {
6720 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
6721 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
6722 }
6723 else
6724 {
6725 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
6726 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
6727 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08006728 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
6729 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07006730 if(pProfile->BSSIDs.numOfBSSIDs == 1)
6731 {
6732 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.bssid, pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
6733 }
6734 else
6735 {
6736 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
6737 }
6738 if(pProfile->ChannelInfo.numOfChannels)
6739 {
6740 status = palAllocateMemory(pMac->hHdd, (void **)&pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList) * pProfile->ChannelInfo.numOfChannels);
6741 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
6742 if(HAL_STATUS_SUCCESS(status))
6743 {
6744 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
6745 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
6746 {
6747 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
6748 {
6749 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
6750 = pProfile->ChannelInfo.ChannelList[index];
6751 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
6752 }
6753 else
6754 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006755 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07006756 }
6757
6758 }
6759 }
6760 else
6761 {
6762 break;
6763 }
6764
6765 }
6766 else
6767 {
6768 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
6769 }
6770 if(pProfile->SSIDs.numOfSSIDs)
6771 {
6772 status = palAllocateMemory(pMac->hHdd, (void **)&pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
6773 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
6774 if(!HAL_STATUS_SUCCESS(status))
6775 {
6776 break;
6777 }
6778 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
6779 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList, pProfile->SSIDs.SSIDList,
6780 sizeof(tCsrSSIDInfo));
6781 }
6782 //Start process the command
6783 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
6784 if( !HAL_STATUS_SUCCESS( status ) )
6785 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006786 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006787 break;
6788 }
6789 }while(0);
6790 if(!HAL_STATUS_SUCCESS(status))
6791 {
6792 if(pScanCmd)
6793 {
6794 csrReleaseCommandScan(pMac, pScanCmd);
6795 //TODO:free the memory that is allocated in this function
6796 }
6797 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
6798 }
6799 }//valid
6800 else
6801 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006802 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07006803 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
6804 }
6805
6806 return (status);
6807}
6808
6809
6810//Issue a scan base on the new capability infomation
6811//This should only happen when the associated AP changes its capability.
6812//After this scan is done, CSR reroams base on the new scan results
6813eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
6814{
6815 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
6816 tSmeCmd *pScanCmd = NULL;
6817
6818 if(pNewCaps)
6819 {
6820 do
6821 {
6822 pScanCmd = csrGetCommandBuffer(pMac);
6823 if(!pScanCmd)
6824 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006825 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006826 status = eHAL_STATUS_RESOURCES;
6827 break;
6828 }
6829 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
6830 status = eHAL_STATUS_SUCCESS;
6831 pScanCmd->u.scanCmd.roamId = 0;
6832 pScanCmd->command = eSmeCommandScan;
6833 pScanCmd->u.scanCmd.callback = NULL;
6834 pScanCmd->u.scanCmd.pContext = NULL;
6835 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
6836 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6837 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
6838 if( !HAL_STATUS_SUCCESS( status ) )
6839 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006840 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006841 break;
6842 }
6843 }while(0);
6844 if(!HAL_STATUS_SUCCESS(status))
6845 {
6846 if(pScanCmd)
6847 {
6848 csrReleaseCommandScan(pMac, pScanCmd);
6849 }
6850 }
6851 }
6852
6853 return (status);
6854}
6855
6856
6857
6858void csrInitBGScanChannelList(tpAniSirGlobal pMac)
6859{
6860 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
6861
6862 palZeroMemory(pMac->hHdd, pMac->scan.bgScanChannelList, len);
6863 pMac->scan.numBGScanChannel = 0;
6864
6865 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6866 {
6867 pMac->roam.numValidChannels = len;
6868 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
6869 palCopyMemory(pMac->hHdd, pMac->scan.bgScanChannelList, pMac->roam.validChannelList, pMac->scan.numBGScanChannel);
6870 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
6871 }
6872}
6873
6874
6875//This function return TRUE if background scan channel list is adjusted.
6876//this function will only shrink the background scan channel list
6877tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
6878 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
6879{
6880 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6881 tANI_U8 i, j, count = *pNumAdjustChannels;
6882
6883 i = 0;
6884 while(i < count)
6885 {
6886 for(j = 0; j < NumChannels; j++)
6887 {
6888 if(pChannelList[j] == pAdjustChannels[i])
6889 break;
6890 }
6891 if(j == NumChannels)
6892 {
6893 //This channel is not in the list, remove it
6894 fRet = eANI_BOOLEAN_TRUE;
6895 count--;
6896 if(count - i)
6897 {
6898 palCopyMemory(pMac->hHdd, &pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
6899 }
6900 else
6901 {
6902 //already remove the last one. Done.
6903 break;
6904 }
6905 }
6906 else
6907 {
6908 i++;
6909 }
6910 }//while(i<count)
6911 *pNumAdjustChannels = count;
6912
6913 return (fRet);
6914}
6915
6916
6917//Get the list of the base channels to scan for passively 11d info
6918eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
6919{
6920 eHalStatus status = eHAL_STATUS_SUCCESS;
6921 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
6922
6923 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
6924 if( HAL_STATUS_SUCCESS(status) )
6925 {
6926 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
6927 }
6928 else
6929 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006930 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006931 pMac->scan.baseChannels.numChannels = 0;
6932 }
6933
6934 return ( status );
6935}
6936
6937//This function use the input pChannelList to validate the current saved channel list
6938eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
6939{
6940 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
6941
6942 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
6943}
6944
6945
6946void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
6947{
6948 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
6949
6950
6951 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
6952
6953 return;
6954}
6955
6956
6957
6958/*
6959 * The Tx power limits are saved in the cfg for future usage.
6960 */
6961void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
6962{
6963 tListElem *pEntry;
6964 tANI_U32 cbLen = 0, dataLen;
6965 tCsrChannelPowerInfo *pChannelSet;
6966 tANI_U32 idx;
6967 tSirMacChanInfo *pChannelPowerSet;
6968 tANI_U8 *pBuf = NULL;
6969
6970 //allocate maximum space for all channels
6971 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
6972 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pBuf, dataLen)))
6973 {
6974 palZeroMemory(pMac->hHdd, pBuf, dataLen);
6975 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
6976
6977 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
6978 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
6979 while( pEntry )
6980 {
6981 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
6982 if ( 1 != pChannelSet->interChannelOffset )
6983 {
6984 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
6985 // to the right format... (inter channel offset of 1 is the only option for the triplets
6986 // that 11d advertises.
6987 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
6988 {
6989 // expanding this entry will overflow our allocation
6990 smsLog(pMac, LOGE,
6991 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006992 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006993 pChannelSet->firstChannel,
6994 pChannelSet->numChannels,
6995 pChannelSet->interChannelOffset);
6996 break;
6997 }
6998
6999 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
7000 {
7001 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007002 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007003 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007004 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007005 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07007006 cbLen += sizeof( tSirMacChanInfo );
7007 pChannelPowerSet++;
7008 }
7009 }
7010 else
7011 {
7012 if (cbLen >= dataLen)
7013 {
7014 // this entry will overflow our allocation
7015 smsLog(pMac, LOGE,
7016 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007017 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007018 pChannelSet->firstChannel,
7019 pChannelSet->numChannels,
7020 pChannelSet->interChannelOffset);
7021 break;
7022 }
7023 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007024 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007025 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07007026 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007027 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07007028
7029
7030 cbLen += sizeof( tSirMacChanInfo );
7031 pChannelPowerSet++;
7032 }
7033
7034 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
7035 }
7036
7037 if(cbLen)
7038 {
7039 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
7040 }
7041 palFreeMemory( pMac->hHdd, pBuf );
7042 }//Allocate memory
7043}
7044
7045
7046void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
7047{
7048 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
7049 ///v_REGDOMAIN_t DomainId;
7050
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007051 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Jeff Johnson295189b2012-06-20 16:38:30 -07007052 palCopyMemory( pMac->hHdd, cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN );
7053
7054 // don't program the bogus country codes that we created for Korea in the MAC. if we see
7055 // the bogus country codes, program the MAC with the right country code.
7056 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
7057 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
7058 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
7059 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
7060 {
7061 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
7062 cc[ 1 ] = 'R';
7063 }
7064 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
7065
7066 //Need to let HALPHY know about the current domain so it can apply some
7067 //domain-specific settings (TX filter...)
7068 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
7069 {
7070 halPhySetRegDomain(pMac, DomainId);
7071 }*/
7072}
7073
7074
7075
7076eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
7077{
7078 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7079 tANI_U32 len;
7080
7081 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
7082 {
7083 len = *pbLen;
7084 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
7085 if(HAL_STATUS_SUCCESS(status))
7086 {
7087 *pbLen = (tANI_U8)len;
7088 }
7089 }
7090
7091 return (status);
7092}
7093
7094
7095void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
7096{
7097 tANI_U8 i, j;
7098 tANI_BOOLEAN found=FALSE;
7099 tANI_U8 *pControlList = NULL;
7100 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
7101
7102 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN)))
7103 {
7104 palZeroMemory(pMac->hHdd, (void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN);
7105 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
7106 {
7107 for (i = 0; i < pChannelList->numChannels; i++)
7108 {
7109 for (j = 0; j < len; j += 2)
7110 {
7111 if (pControlList[j] == pChannelList->channelList[i])
7112 {
7113 found = TRUE;
7114 break;
7115 }
7116 }
7117
7118 if (found) // insert a pair(channel#, flag)
7119 {
7120 if (CSR_IS_CHANNEL_5GHZ(pControlList[j]))
7121 {
7122 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
7123 }
7124 else
7125 {
7126 pControlList[j+1] = eSIR_ACTIVE_SCAN;
7127 }
7128
7129 found = FALSE; // reset the flag
7130 }
7131
7132 }
7133
7134 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
7135 }//Successfully getting scan control list
7136 palFreeMemory(pMac->hHdd, pControlList);
7137 }//AllocateMemory
7138}
7139
7140
7141//if bgPeriod is 0, background scan is disabled. It is in millisecond units
7142eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
7143{
7144 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
7145}
7146
7147
7148void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
7149{
7150 tListElem *pEntry = NULL;
7151 tSmeCmd *pCommand = NULL;
7152 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
7153
7154 pEntry = csrLLPeekHead( &pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK );
7155 if ( pEntry )
7156 {
7157 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7158 if ( eSmeCommandScan == pCommand->command )
7159 {
7160 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
7161 csrReleaseScanCommand(pMac, pCommand, scanStatus);
7162 }
7163 else
7164 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007165 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07007166 }
7167 }
7168 smeProcessPendingQueue( pMac );
7169}
7170
7171eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
7172{
7173 eHalStatus status;
7174 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
7175 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
7176
7177 //***setcfg for background scan channel list
7178 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
7179 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
7180 //Not set the background scan interval if not connected because bd scan should not be run if not connected
7181 if(!csrIsAllSessionDisconnected(pMac))
7182 {
7183 //If disbaling BG scan here, we need to stop aging as well
7184 if(pScanReq->scanInterval == 0)
7185 {
7186 //Stop aging because no new result is coming in
7187 csrScanStopResultAgingTimer(pMac);
7188 }
7189
7190#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7191 {
7192 vos_log_scan_pkt_type *pScanLog = NULL;
7193
7194 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
7195 if(pScanLog)
7196 {
7197 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
7198 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
7199 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
7200 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
7201 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
7202 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
7203 {
7204 palCopyMemory(pMac->hHdd, pScanLog->channels, pScanReq->ChannelInfo.ChannelList,
7205 pScanLog->numChannel);
7206 }
7207 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
7208 }
7209 }
7210#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7211
7212 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
7213 }
7214 else
7215 {
7216 //No need to stop aging because IDLE scan is still running
7217 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
7218 }
7219
7220 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
7221 {
7222 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
7223 }
7224
7225 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7226 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
7227
7228
7229
7230 return (status);
7231}
7232
7233
7234eHalStatus csrScanAbortMacScan(tpAniSirGlobal pMac)
7235{
7236 eHalStatus status = eHAL_STATUS_SUCCESS;
7237 tSirMbMsg *pMsg;
7238 tANI_U16 msgLen;
7239 tListElem *pEntry;
7240 tSmeCmd *pCommand;
7241
7242#ifdef WLAN_AP_STA_CONCURRENCY
7243 csrLLLock(&pMac->scan.scanCmdPendingList);
7244 while( NULL != ( pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
7245 {
7246
7247 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7248 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7249 }
7250 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7251#endif
7252
7253 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7254 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
7255 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
7256 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7257
7258 //We need to abort scan only if we are scanning
7259 if(NULL != (pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK)))
7260 {
7261 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7262 if(eSmeCommandScan == pCommand->command)
7263 {
7264 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
7265 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
7266 if(HAL_STATUS_SUCCESS(status))
7267 {
7268 palZeroMemory(pMac->hHdd, (void *)pMsg, msgLen);
7269 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
7270 pMsg->msgLen = pal_cpu_to_be16(msgLen);
7271 status = palSendMBMessage(pMac->hHdd, pMsg);
7272 }
7273 }
7274 }
7275
7276 return( status );
7277}
7278
7279void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
7280 eSmeCommandType commandType )
7281{
7282 tDblLinkList localList;
7283 tListElem *pEntry;
7284 tSmeCmd *pCommand;
7285 tListElem *pEntryToRemove;
7286
7287 vos_mem_zero(&localList, sizeof(tDblLinkList));
7288 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7289 {
7290 smsLog(pMac, LOGE, FL(" failed to open list"));
7291 return;
7292 }
7293
7294 csrLLLock(pList);
7295 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
7296 {
7297 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
7298
7299 // Have to make sure we don't loop back to the head of the list, which will
7300 // happen if the entry is NOT on the list...
7301 while( pEntry )
7302 {
7303 pEntryToRemove = pEntry;
7304 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7305 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7306 if ( pCommand->command == commandType )
7307 {
7308 // Remove that entry only
7309 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7310 {
7311 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
7312 }
7313 }
7314 }
7315
7316
7317 }
7318 csrLLUnlock(pList);
7319
7320 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7321 {
7322 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7323 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7324 }
7325 csrLLClose(&localList);
7326
7327}
7328
7329
7330eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac)
7331{
7332 eHalStatus status = eHAL_STATUS_SUCCESS;
7333
7334 if( !csrIsScanForRoamCommandActive( pMac ) )
7335 {
7336 //Only abort the scan if it is not used for other roam/connect purpose
7337 status = csrScanAbortMacScan(pMac);
7338 }
7339
7340 return (status);
7341}
7342
7343
7344eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac)
7345{
7346 eHalStatus status = eHAL_STATUS_SUCCESS;
7347 tSirMbMsg *pMsg;
7348 tANI_U16 msgLen;
7349
7350 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
7351 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
7352 if(HAL_STATUS_SUCCESS(status))
7353 {
7354 palZeroMemory(pMac->hHdd, pMsg, msgLen);
7355 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
7356 pMsg->msgLen = msgLen;
7357 status = palSendMBMessage(pMac->hHdd, pMsg);
7358 }
7359
7360 return( status );
7361}
7362
7363tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
7364{
7365 tANI_BOOLEAN fValid = FALSE;
7366 tANI_U32 idxValidChannels;
7367 tANI_U32 len = pMac->roam.numValidChannels;
7368
7369 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
7370 {
7371 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
7372 {
7373 fValid = TRUE;
7374 break;
7375 }
7376 }
7377
7378 return fValid;
7379}
7380
Srikant Kuppa066904f2013-05-07 13:56:02 -07007381eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
7382 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
7383{
7384 v_U32_t uLen = 0;
7385 tpSirProbeRespBeacon pParsedFrame;
7386 tCsrScanResult *pScanResult = NULL;
7387 tSirBssDescription *pBssDescr = NULL;
7388 tANI_BOOLEAN fDupBss;
7389 tDot11fBeaconIEs *pIesLocal = NULL;
7390 tAniSSID tmpSsid;
7391 v_TIME_t timer=0;
7392 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
7393
7394 pParsedFrame =
7395 (tpSirProbeRespBeacon) vos_mem_malloc(sizeof(tSirProbeRespBeacon));
7396
7397 if (NULL == pParsedFrame)
7398 {
7399 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
7400 return eHAL_STATUS_RESOURCES;
7401 }
7402
7403 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
7404 {
7405 smsLog(pMac, LOGE,
7406 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
7407 pPrefNetworkFoundInd->frameLength);
7408 vos_mem_free(pParsedFrame);
7409 return eHAL_STATUS_FAILURE;
7410 }
7411
7412 if (sirConvertProbeFrame2Struct(pMac,
7413 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
7414 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
7415 pParsedFrame) != eSIR_SUCCESS ||
7416 !pParsedFrame->ssidPresent)
7417 {
7418 smsLog(pMac, LOGE,
7419 FL("Parse error ProbeResponse, length=%d"),
7420 pPrefNetworkFoundInd->frameLength);
7421 vos_mem_free(pParsedFrame);
7422 return eHAL_STATUS_FAILURE;
7423 }
7424 //24 byte MAC header and 12 byte to ssid IE
7425 if (pPrefNetworkFoundInd->frameLength >
7426 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
7427 {
7428 uLen = pPrefNetworkFoundInd->frameLength -
7429 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
7430 }
7431
7432 if ( !HAL_STATUS_SUCCESS(palAllocateMemory( pMac->hHdd,
7433 (void **)&pScanResult, sizeof(tCsrScanResult) + uLen )) )
7434 {
7435 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
7436 vos_mem_free(pParsedFrame);
7437 return eHAL_STATUS_RESOURCES;
7438 }
7439
7440 palZeroMemory( pMac->hHdd, pScanResult, sizeof(tCsrScanResult) + uLen );
7441 pBssDescr = &pScanResult->Result.BssDescriptor;
7442 /**
7443 * Length of BSS desription is without length of
7444 * length itself and length of pointer
7445 * that holds the next BSS description
7446 */
7447 pBssDescr->length = (tANI_U16)(
7448 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
7449 sizeof(tANI_U32) + uLen);
7450 if (pParsedFrame->dsParamsPresent)
7451 {
7452 pBssDescr->channelId = pParsedFrame->channelNumber;
7453 }
7454 else if (pParsedFrame->HTInfo.present)
7455 {
7456 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
7457 }
7458 else
7459 {
7460 pBssDescr->channelId = pParsedFrame->channelNumber;
7461 }
7462
7463 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
7464 {
7465 int i;
7466 // 11b or 11g packet
7467 // 11g iff extended Rate IE is present or
7468 // if there is an A rate in suppRate IE
7469 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
7470 {
7471 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
7472 {
7473 pBssDescr->nwType = eSIR_11G_NW_TYPE;
7474 break;
7475 }
7476 }
7477 if (pParsedFrame->extendedRatesPresent)
7478 {
7479 pBssDescr->nwType = eSIR_11G_NW_TYPE;
7480 }
7481 }
7482 else
7483 {
7484 // 11a packet
7485 pBssDescr->nwType = eSIR_11A_NW_TYPE;
7486 }
7487
7488 pBssDescr->sinr = 0;
7489 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
7490 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
7491 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
7492 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
7493 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
7494 palCopyMemory( pMac->hHdd, (tANI_U8 *) &pBssDescr->bssId,
7495 (tANI_U8 *) macHeader->bssId,
7496 sizeof(tSirMacAddr));
7497 pBssDescr->nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
7498
7499 smsLog( pMac, LOG2, "(%s):Bssid= %02x-%02x-%02x-%02x-%02x-%02x "
7500 "chan= %d, rssi = %d", __func__,
7501 pBssDescr->bssId[ 0 ], pBssDescr->bssId[ 1 ],
7502 pBssDescr->bssId[ 2 ], pBssDescr->bssId[ 3 ],
7503 pBssDescr->bssId[ 4 ], pBssDescr->bssId[ 5 ],
7504 pBssDescr->channelId,
7505 pBssDescr->rssi );
7506
7507 //IEs
7508 if (uLen)
7509 {
7510 vos_mem_copy( &pBssDescr->ieFields,
7511 pPrefNetworkFoundInd->data +
7512 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
7513 uLen);
7514 }
7515
7516 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
7517 if ( !pIesLocal &&
7518 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
7519 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
7520 {
7521 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
7522 csrFreeScanResultEntry(pMac, pScanResult);
7523 vos_mem_free(pParsedFrame);
7524 return eHAL_STATUS_RESOURCES;
7525 }
7526
7527 fDupBss = csrRemoveDupBssDescription( pMac,
7528 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid , &timer);
7529 //Check whether we have reach out limit
7530 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
7531 {
7532 //Limit reach
7533 smsLog(pMac, LOGE, FL(" BSS limit reached"));
7534 //Free the resources
7535 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
7536 {
7537 palFreeMemory(pMac->hHdd, pIesLocal);
7538 }
7539 csrFreeScanResultEntry(pMac, pScanResult);
7540 vos_mem_free(pParsedFrame);
7541 return eHAL_STATUS_RESOURCES;
7542 }
7543 //Add to scan cache
7544 csrScanAddResult(pMac, pScanResult, pIesLocal);
7545
7546 vos_mem_free(pParsedFrame);
7547
7548 return eHAL_STATUS_SUCCESS;
7549}
7550
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007551#ifdef FEATURE_WLAN_LFR
7552void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
7553{
7554 tListElem *pEntry = NULL;
7555 tCsrScanResult *pBssDesc = NULL;
7556 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08007557 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
7558
7559 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
7560 {
7561 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007562 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08007563 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
7564 return;
7565 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007566
7567 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
7568 {
7569 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007570 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007571 __func__, pMac->scan.occupiedChannels.numChannels);
7572 return;
7573 }
7574
7575 /* Empty occupied channels here */
7576 pMac->scan.occupiedChannels.numChannels = 0;
7577
7578 csrLLLock(&pMac->scan.scanResultList);
7579 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
7580 while( pEntry )
7581 {
7582 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
7583 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
7584
7585 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08007586 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007587 &pBssDesc->Result.BssDescriptor, &pIes))) )
7588 {
7589 continue;
7590 }
7591
7592 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
7593
7594 /*
7595 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
7596 */
7597 if( (pBssDesc->Result.pvIes == NULL) && pIes )
7598 {
7599 palFreeMemory(pMac->hHdd, pIes);
7600 }
7601
7602 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
7603 }//while
7604 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08007605
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007606}
7607#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007608