blob: 71c61f3ebb218b9f0395ddc1b2089f4373a02ce6 [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
117//*** This is temporary work around. It need to call CCM api to get to CFG later
118/// Get string parameter value
119extern tSirRetStatus wlan_cfgGetStr(tpAniSirGlobal, tANI_U16, tANI_U8*, tANI_U32*);
120
121void csrScanGetResultTimerHandler(void *);
122void csrScanResultAgingTimerHandler(void *pv);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800123static void csrScanResultCfgAgingTimerHandler(void *pv);
Jeff Johnson295189b2012-06-20 16:38:30 -0700124void csrScanIdleScanTimerHandler(void *);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700125static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest);
Jeff Johnson295189b2012-06-20 16:38:30 -0700126#ifdef WLAN_AP_STA_CONCURRENCY
127static void csrStaApConcTimerHandler(void *);
128#endif
Jeff Johnsone7245742012-09-05 17:12:55 -0700129tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -0700130eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand );
131void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels );
132void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId );
133void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode );
134void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList );
135//if bgPeriod is 0, background scan is disabled. It is in millisecond units
136eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod);
137eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand);
138void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus);
139static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
140 tANI_U8 numChn, tSirBssDescription *pBssDesc,
141 tDot11fBeaconIEs **ppIes );
142eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels);
143void csrReleaseCmdSingle(tpAniSirGlobal pMac, tSmeCmd *pCommand);
144tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel );
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700145void csrPruneChannelListForMode( tpAniSirGlobal pMac, tCsrChannel *pChannelList );
Jeff Johnson295189b2012-06-20 16:38:30 -0700146
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700147#define CSR_IS_SOCIAL_CHANNEL(channel) (((channel) == 1) || ((channel) == 6) || ((channel) == 11) )
148
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700149
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700150
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800151static void csrReleaseScanCmdPendingList(tpAniSirGlobal pMac)
152{
153 tListElem *pEntry;
154 tSmeCmd *pCommand;
155
156 while((pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK)) != NULL)
157 {
158 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
159 if ( eSmeCsrCommandMask & pCommand->command )
160 {
161 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_TRUE );
162 }
163 else
164 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800165 smsLog(pMac, LOGE, FL("Error: Received command : %d"),pCommand->command);
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800166 }
167 }
168}
Jeff Johnson295189b2012-06-20 16:38:30 -0700169//pResult is invalid calling this function.
170void csrFreeScanResultEntry( tpAniSirGlobal pMac, tCsrScanResult *pResult )
171{
172 if( NULL != pResult->Result.pvIes )
173 {
174 palFreeMemory( pMac->hHdd, pResult->Result.pvIes );
175 }
176 palFreeMemory(pMac->hHdd, pResult);
177}
178
179
180static eHalStatus csrLLScanPurgeResult(tpAniSirGlobal pMac, tDblLinkList *pList)
181{
182 eHalStatus status = eHAL_STATUS_SUCCESS;
183 tListElem *pEntry;
184 tCsrScanResult *pBssDesc;
185
186 csrLLLock(pList);
187
188 while((pEntry = csrLLRemoveHead(pList, LL_ACCESS_NOLOCK)) != NULL)
189 {
190 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
191 csrFreeScanResultEntry( pMac, pBssDesc );
192 }
193
194 csrLLUnlock(pList);
195
196 return (status);
197}
198
199
200int csrCheckValidateLists(void * dest, const void *src, v_SIZE_t num, int idx)
201{
202#ifdef CSR_VALIDATE_LIST
203
204 int ii = 1;
205
206 if( (NULL == g_pMac) || (!g_pMac->scan.fValidateList ) )
207 {
208 return ii;
209 }
210 if(g_pchannelPowerInfoList24)
211 {
212 //check 2.4 list
213 tListElem *pElem, *pHead;
214 int count;
215
216 count = (int)(g_pchannelPowerInfoList24->Count);
217 pHead = &g_pchannelPowerInfoList24->ListHead;
218 pElem = pHead->next;
219 if((tANI_U32)(pHead->next) > 0x00010000) //Assuming kernel address is not that low.
220 {
221 //this loop crashes if the pointer is not right
222 while(pElem->next != pHead)
223 {
224 if((tANI_U32)(pElem->next) > 0x00010000)
225 {
226 pElem = pElem->next;
227 VOS_ASSERT(count > 0);
228 count--;
229 }
230 else
231 {
232 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_FATAL,
233 " %d Detect 1 list(0x%X) error Head(0x%X) next(0x%X) Count %d, dest(0x%X) src(0x%X) numBytes(%d)",
234 idx, (unsigned int)g_pchannelPowerInfoList24, (unsigned int)pHead,
235 (unsigned int)(pHead->next), (int)g_pchannelPowerInfoList24->Count,
236 (unsigned int)dest, (unsigned int)src, (int)num);
237 VOS_ASSERT(0);
238 ii = 0;
239 break;
240 }
241 }
242 }
243 else
244 {
245 //Bad list
246 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)",
247 idx, (unsigned int)g_pchannelPowerInfoList24, (unsigned int)pHead,
248 (unsigned int)(pHead->next), (int)g_pchannelPowerInfoList24->Count,
249 (unsigned int)dest, (unsigned int)src, (int)num);
250 VOS_ASSERT(0);
251 ii = 0;
252 }
253 }
254 else
255 {
256 //list ok
257 ii = 1;
258 }
259
260
261 return ii;
262
263#else
264 return 1;
265#endif //#ifdef CSR_VALIDATE_LIST
266}
267
268
269eHalStatus csrScanOpen( tpAniSirGlobal pMac )
270{
271 eHalStatus status;
272
273 do
274 {
275 csrLLOpen(pMac->hHdd, &pMac->scan.scanResultList);
276 csrLLOpen(pMac->hHdd, &pMac->scan.tempScanResults);
277 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList24);
278 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList5G);
279#ifdef WLAN_AP_STA_CONCURRENCY
280 csrLLOpen(pMac->hHdd, &pMac->scan.scanCmdPendingList);
281#endif
282#ifdef CSR_VALIDATE_LIST
283 g_pchannelPowerInfoList5 = &pMac->scan.channelPowerInfoList5G;
284 g_pMac = pMac;
285 g_pchannelPowerInfoList24 = &pMac->scan.channelPowerInfoList24;
286#endif
287 pMac->scan.fFullScanIssued = eANI_BOOLEAN_FALSE;
288 pMac->scan.nBssLimit = CSR_MAX_BSS_SUPPORT;
289 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerGetResult, csrScanGetResultTimerHandler, pMac);
290 if(!HAL_STATUS_SUCCESS(status))
291 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800292 smsLog(pMac, LOGE, FL("cannot allocate memory for getResult timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700293 break;
294 }
295#ifdef WLAN_AP_STA_CONCURRENCY
296 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerStaApConcTimer, csrStaApConcTimerHandler, pMac);
297 if(!HAL_STATUS_SUCCESS(status))
298 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800299 smsLog(pMac, LOGE, FL("cannot allocate memory for hTimerStaApConcTimer timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700300 break;
301 }
302#endif
303 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerIdleScan, csrScanIdleScanTimerHandler, pMac);
304 if(!HAL_STATUS_SUCCESS(status))
305 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800306 smsLog(pMac, LOGE, FL("cannot allocate memory for idleScan timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700307 break;
308 }
309 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerResultAging, csrScanResultAgingTimerHandler, pMac);
310 if(!HAL_STATUS_SUCCESS(status))
311 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800312 smsLog(pMac, LOGE, FL("cannot allocate memory for ResultAging timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700313 break;
314 }
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800315 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerResultCfgAging,
316 csrScanResultCfgAgingTimerHandler, pMac);
317 if(!HAL_STATUS_SUCCESS(status))
318 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800319 smsLog(pMac, LOGE, FL("cannot allocate memory for CFG ResultAging timer"));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800320 break;
321 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700322 }while(0);
323
324 return (status);
325}
326
327
328eHalStatus csrScanClose( tpAniSirGlobal pMac )
329{
330#ifdef CSR_VALIDATE_LIST
331 g_pchannelPowerInfoList24 = NULL;
332 g_pchannelPowerInfoList5 = NULL;
333 g_pMac = NULL;
334#endif
335 csrLLScanPurgeResult(pMac, &pMac->scan.tempScanResults);
336 csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList);
337#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800338 csrReleaseScanCmdPendingList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700339#endif
340 csrLLClose(&pMac->scan.scanResultList);
341 csrLLClose(&pMac->scan.tempScanResults);
342#ifdef WLAN_AP_STA_CONCURRENCY
343 csrLLClose(&pMac->scan.scanCmdPendingList);
344#endif
345 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList24);
346 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList5G);
347 csrLLClose(&pMac->scan.channelPowerInfoList24);
348 csrLLClose(&pMac->scan.channelPowerInfoList5G);
349 csrScanDisable(pMac);
350 palTimerFree(pMac->hHdd, pMac->scan.hTimerResultAging);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800351 palTimerFree(pMac->hHdd, pMac->scan.hTimerResultCfgAging);
Jeff Johnson295189b2012-06-20 16:38:30 -0700352 palTimerFree(pMac->hHdd, pMac->scan.hTimerGetResult);
353#ifdef WLAN_AP_STA_CONCURRENCY
354 palTimerFree(pMac->hHdd, pMac->scan.hTimerStaApConcTimer);
355#endif
356 palTimerFree(pMac->hHdd, pMac->scan.hTimerIdleScan);
357 return eHAL_STATUS_SUCCESS;
358}
359
360
361eHalStatus csrScanEnable( tpAniSirGlobal pMac )
362{
363
364 pMac->scan.fScanEnable = eANI_BOOLEAN_TRUE;
365 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
366
367 return eHAL_STATUS_SUCCESS;
368}
369
370
371eHalStatus csrScanDisable( tpAniSirGlobal pMac )
372{
373
374 csrScanStopTimers(pMac);
375 pMac->scan.fScanEnable = eANI_BOOLEAN_FALSE;
376
377 return eHAL_STATUS_SUCCESS;
378}
379
380
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700381//Set scan timing parameters according to state of other driver sessions
382//No validation of the parameters is performed.
383static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest)
384{
385#ifdef WLAN_AP_STA_CONCURRENCY
386 if(csrIsAnySessionConnected(pMac))
387 {
388 //If multi-session, use the appropriate default scan times
389 if(scanType == eSIR_ACTIVE_SCAN)
390 {
391 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTimeConc;
392 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTimeConc;
393 }
394 else
395 {
396 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTimeConc;
397 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTimeConc;
398 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800399 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
400 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700401
402 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
403
404 //Return so that fields set above will not be overwritten.
405 return;
406 }
407#endif
408
409 //This portion of the code executed if multi-session not supported
410 //(WLAN_AP_STA_CONCURRENCY not defined) or no multi-session.
411 //Use the "regular" (non-concurrency) default scan timing.
412 if(pScanRequest->scanType == eSIR_ACTIVE_SCAN)
413 {
414 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
415 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTime;
416 }
417 else
418 {
419 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
420 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
421 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800422 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
423 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700424
425#ifdef WLAN_AP_STA_CONCURRENCY
426 //No rest time if no sessions are connected.
427 pScanRequest->restTime = 0;
428#endif
429}
430
Jeff Johnson295189b2012-06-20 16:38:30 -0700431#ifdef WLAN_AP_STA_CONCURRENCY
432//Return SUCCESS is the command is queued, else returns eHAL_STATUS_FAILURE
433eHalStatus csrQueueScanRequest( tpAniSirGlobal pMac, tSmeCmd *pScanCmd )
434{
435 eHalStatus status = eHAL_STATUS_SUCCESS;
436
437 tANI_BOOLEAN fNoCmdPending;
438 tSmeCmd *pQueueScanCmd=NULL;
439 tSmeCmd *pSendScanCmd=NULL;
440
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800441 /* split scan if any one of the following:
442 * - STA session is connected and the scan is not a P2P search
443 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -0800444 * Do not split scans if no concurrent infra connections are
445 * active and if the scan is a BG scan triggered by LFR (OR)
446 * any scan if LFR is in the middle of a BG scan. Splitting
447 * the scan is delaying the time it takes for LFR to find
448 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800449 */
Srikant Kuppa866893f2012-12-27 17:28:14 -0800450 if ( (csrIsStaSessionConnected(pMac) &&
451#ifdef FEATURE_WLAN_LFR
452 (csrIsConcurrentInfraConnected(pMac) ||
453 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
454 (pMac->roam.neighborRoamInfo.neighborRoamState !=
455 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
456#endif
457 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Vinay Malekal05fdc812012-12-17 13:04:30 -0800458 (csrIsP2pSessionConnected(pMac)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700459 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700460 tCsrScanRequest scanReq;
461 tANI_U8 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
462 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
463 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Jeff Johnson295189b2012-06-20 16:38:30 -0700464 tANI_BOOLEAN bMemAlloc = eANI_BOOLEAN_FALSE;
465
466 if (numChn == 0)
467 {
468
469 numChn = pMac->scan.baseChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700470
Vinay Malekal05fdc812012-12-17 13:04:30 -0800471 status = palAllocateMemory( pMac->hHdd, (void **)&pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn );
472 if( !HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700473 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800474 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800475 return eHAL_STATUS_FAILURE;
476 }
477 bMemAlloc = eANI_BOOLEAN_TRUE;
478 status = palCopyMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
479 pMac->scan.baseChannels.channelList, numChn );
480 if( !HAL_STATUS_SUCCESS( status ) )
481 {
482 palFreeMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList );
483 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800484 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800485 return eHAL_STATUS_FAILURE;
486 }
487 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn;
488 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700489
Vinay Malekal05fdc812012-12-17 13:04:30 -0800490 //Whenever we get a scan request with multiple channels we break it up into 2 requests
491 //First request for first channel to scan and second request to scan remaining channels
492 if (numChn > pMac->roam.configParam.nNumChanCombinedConc)
493 {
494 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
495
496 pQueueScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
497 if (!pQueueScanCmd)
498 {
499 if (bMemAlloc)
Jeff Johnson295189b2012-06-20 16:38:30 -0700500 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800501 palFreeMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList );
502 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
503
Jeff Johnson295189b2012-06-20 16:38:30 -0700504 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800505 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800506 return eHAL_STATUS_FAILURE;
507 }
508 pQueueScanCmd->command = pScanCmd->command;
509 pQueueScanCmd->sessionId = pScanCmd->sessionId;
510 pQueueScanCmd->u.scanCmd.callback = pScanCmd->u.scanCmd.callback;
511 pQueueScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
512 pQueueScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
513 pQueueScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700514
Vinay Malekal05fdc812012-12-17 13:04:30 -0800515 /* First copy all the parameters to local variable of scan request */
516 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -0700517
Vinay Malekal05fdc812012-12-17 13:04:30 -0800518 /* Now modify the elements of local var scan request required to be modified for split scan */
519 if(scanReq.ChannelInfo.ChannelList != NULL)
520 {
521 palFreeMemory(pMac->hHdd, scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -0800522 scanReq.ChannelInfo.ChannelList = NULL;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800523 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700524
Vinay Malekal05fdc812012-12-17 13:04:30 -0800525 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - pMac->roam.configParam.nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700526
Vinay Malekal05fdc812012-12-17 13:04:30 -0800527 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
528 FL(" &channelToScan %0x pScanCmd(0x%X) pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList(0x%X)numChn(%d)"),
529 &channelToScan[0], (unsigned int)pScanCmd,
530 (unsigned int)pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700531
Vinay Malekal05fdc812012-12-17 13:04:30 -0800532 palCopyMemory(pMac->hHdd, &channelToScan[0], &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pMac->roam.configParam.nNumChanCombinedConc],
533 pChnInfo->numOfChannels * sizeof(tANI_U8));
534
535 pChnInfo->ChannelList = &channelToScan[0];
536
537 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
538 //Modify callers parameters in case of concurrency
539 scanReq.scanType = eSIR_ACTIVE_SCAN;
540 //Use concurrency values for min/maxChnTime.
541 //We know csrIsAnySessionConnected(pMac) returns TRUE here
542 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
543
544 status = csrScanCopyRequest(pMac, &pQueueScanCmd->u.scanCmd.u.scanRequest, &scanReq);
545
546 if(!HAL_STATUS_SUCCESS(status))
547 {
548 if (bMemAlloc)
549 {
550 palFreeMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList );
551 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
552
553 }
554 if( scanReq.pIEField != NULL)
555 {
556 palFreeMemory(pMac->hHdd, scanReq.pIEField);
557 scanReq.pIEField = NULL;
558 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800559 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800560 return eHAL_STATUS_FAILURE;
561 }
562 /* Clean the local scan variable */
563 scanReq.ChannelInfo.ChannelList = NULL;
564 scanReq.ChannelInfo.numOfChannels = 0;
565 csrScanFreeRequest(pMac, &scanReq);
566
567 /* setup the command to scan 2 channels */
568 pSendScanCmd = pScanCmd;
569 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = pMac->roam.configParam.nNumChanCombinedConc;
570 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
571 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
572 //Use concurrency values for min/maxChnTime.
573 //We know csrIsAnySessionConnected(pMac) returns TRUE here
574 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
575 pSendScanCmd->u.scanCmd.callback = NULL;
576 } else {
577 pSendScanCmd = pScanCmd;
578 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
579 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
580 //Use concurrency values for min/maxChnTime.
581 //We know csrIsAnySessionConnected(pMac) returns TRUE here
582 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
583 }
584
585 fNoCmdPending = csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK );
586
587 //Logic Below is as follows
588 // If the scanCmdPendingList is empty then we directly send that command
589 // to smeCommandQueue else we buffer it in our scanCmdPendingList Queue
590 if( fNoCmdPending )
591 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700592 if (pQueueScanCmd != NULL)
593 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800594 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -0700595 }
596
597 if (pSendScanCmd != NULL)
598 {
599 return csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
600 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800601 }
602 else
603 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700604 if (pSendScanCmd != NULL)
605 {
606 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pSendScanCmd->Link, LL_ACCESS_LOCK );
607 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800608
Jeff Johnson295189b2012-06-20 16:38:30 -0700609 if (pQueueScanCmd != NULL)
610 {
611 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
612 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800613 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700614 }
615 else
616 { //No concurrency case
Srikant Kuppa866893f2012-12-27 17:28:14 -0800617 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800618 " numOfChannels=%d)"),
Srikant Kuppa866893f2012-12-27 17:28:14 -0800619 pScanCmd->u.scanCmd.reason,
620 pMac->roam.neighborRoamInfo.neighborRoamState,
621 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -0700622 return csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
623 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700624
625 return ( status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700626}
627#endif
628
Jeff Johnsone7245742012-09-05 17:12:55 -0700629/* ---------------------------------------------------------------------------
630 \fn csrScan2GOnyRequest
631 \brief This function will update the scan request with only
Jeff Johnsonb88db982012-12-10 13:34:59 -0800632 2.4GHz valid channel list.
Jeff Johnsone7245742012-09-05 17:12:55 -0700633 \param pMac
634 \param pScanCmd
635 \param pScanRequest
636 \return None
637 -------------------------------------------------------------------------------*/
638static void csrScan2GOnyRequest(tpAniSirGlobal pMac,tSmeCmd *pScanCmd,
639 tCsrScanRequest *pScanRequest)
640{
641 tANI_U8 index, channelId, channelListSize = 0;
642 tANI_U8 channelList2G[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
643 static tANI_U8 validchannelList[CSR_MAX_2_4_GHZ_SUPPORTED_CHANNELS] = {0};
644
645 VOS_ASSERT(pScanCmd && pScanRequest);
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700646 /* To silence the KW tool null check is added */
647 if((pScanCmd == NULL) || (pScanRequest == NULL))
648 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800649 smsLog( pMac, LOGE, FL(" pScanCmd or pScanRequest is NULL "));
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700650 return;
651 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700652
653 if (pScanCmd->u.scanCmd.scanID ||
654 (eCSR_SCAN_REQUEST_FULL_SCAN != pScanRequest->requestType))
655 return;
656
657 //Contsruct valid Supported 2.4 GHz Channel List
658 for( index = 0; index < ARRAY_SIZE(channelList2G); index++ )
659 {
660 channelId = channelList2G[index];
661 if ( csrIsSupportedChannel( pMac, channelId ) )
662 {
663 validchannelList[channelListSize++] = channelId;
664 }
665 }
666
667 pScanRequest->ChannelInfo.numOfChannels = channelListSize;
668 pScanRequest->ChannelInfo.ChannelList = validchannelList;
669}
670
Jeff Johnson295189b2012-06-20 16:38:30 -0700671eHalStatus csrScanRequest(tpAniSirGlobal pMac, tANI_U16 sessionId,
672 tCsrScanRequest *pScanRequest, tANI_U32 *pScanRequestID,
673 csrScanCompleteCallback callback, void *pContext)
674{
675 eHalStatus status = eHAL_STATUS_FAILURE;
676 tSmeCmd *pScanCmd = NULL;
Madan Mohan Koyyalamudicb90bb22012-10-30 18:24:43 -0700677 eCsrConnectState ConnectState;
Jeff Johnson295189b2012-06-20 16:38:30 -0700678
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800679 if(pScanRequest == NULL)
680 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800681 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800682 VOS_ASSERT(0);
683 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700684
Jeff Johnson295189b2012-06-20 16:38:30 -0700685 do
686 {
687 if(pMac->scan.fScanEnable)
688 {
689 pScanCmd = csrGetCommandBuffer(pMac);
690 if(pScanCmd)
691 {
692 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
693 pScanCmd->command = eSmeCommandScan;
694 pScanCmd->sessionId = sessionId;
695 pScanCmd->u.scanCmd.callback = callback;
696 pScanCmd->u.scanCmd.pContext = pContext;
697 if(eCSR_SCAN_REQUEST_11D_SCAN == pScanRequest->requestType)
698 {
699 pScanCmd->u.scanCmd.reason = eCsrScan11d1;
700 }
701 else if((eCSR_SCAN_REQUEST_FULL_SCAN == pScanRequest->requestType) ||
702 (eCSR_SCAN_P2P_DISCOVERY == pScanRequest->requestType)
703#ifdef SOFTAP_CHANNEL_RANGE
704 ||(eCSR_SCAN_SOFTAP_CHANNEL_RANGE == pScanRequest->requestType)
705#endif
706 )
707 {
708 pScanCmd->u.scanCmd.reason = eCsrScanUserRequest;
709 }
710 else if(eCSR_SCAN_HO_BG_SCAN == pScanRequest->requestType)
711 {
712 pScanCmd->u.scanCmd.reason = eCsrScanBgScan;
713 }
714 else if(eCSR_SCAN_HO_PROBE_SCAN == pScanRequest->requestType)
715 {
716 pScanCmd->u.scanCmd.reason = eCsrScanProbeBss;
717 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700718 else if(eCSR_SCAN_P2P_FIND_PEER == pScanRequest->requestType)
719 {
720 pScanCmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
721 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700722 else
723 {
724 pScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
725 }
726 if(pScanRequest->minChnTime == 0 && pScanRequest->maxChnTime == 0)
727 {
728 //The caller doesn't set the time correctly. Set it here
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700729 csrSetDefaultScanTiming(pMac, pScanRequest->scanType, pScanRequest);
730 }
731#ifdef WLAN_AP_STA_CONCURRENCY
732 if(pScanRequest->restTime == 0)
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800733 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700734 //Need to set restTime only if at least one session is connected
735 if(csrIsAnySessionConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700736 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700737 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700738 }
739 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700740#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -0700741 /*For Standalone wlan : channel time will remain the same.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800742 For BTC with A2DP up: Channel time = Channel time * 2 , if station is not already associated.
743 This has been done to provide a larger scan window for faster connection during btc.Else Scan is seen
744 to take a long time.
745 For BTC with A2DP up: Channel time will not be doubled, if station is already associated.
746 */
Jeff Johnson32d95a32012-09-10 13:15:23 -0700747 status = csrRoamGetConnectState(pMac,sessionId,&ConnectState);
Srinivas Girigowdac84c57c2013-02-19 17:41:56 -0800748 if (HAL_STATUS_SUCCESS(status) &&
749 pMac->btc.fA2DPUp &&
Jeff Johnson32d95a32012-09-10 13:15:23 -0700750 (eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED != ConnectState) &&
751 (eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED != ConnectState))
752 {
753 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
754 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
755 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800756
757 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
758 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700759 //Need to make the following atomic
760 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
761
762 if(pScanRequestID)
763 {
764 *pScanRequestID = pScanCmd->u.scanCmd.scanID;
765 }
766
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800767 // If it is the first scan request from HDD, CSR checks if it is for 11d.
Jeff Johnson295189b2012-06-20 16:38:30 -0700768 // If it is not, CSR will save the scan request in the pending cmd queue
769 // & issue an 11d scan request to PE.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800770 if (((0 == pScanCmd->u.scanCmd.scanID)
Jeff Johnson295189b2012-06-20 16:38:30 -0700771 && (eCSR_SCAN_REQUEST_11D_SCAN != pScanRequest->requestType))
772#ifdef SOFTAP_CHANNEL_RANGE
773 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != pScanRequest->requestType)
774#endif
775 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d)
776 )
777 {
778 tSmeCmd *p11dScanCmd;
779 tCsrScanRequest scanReq;
780 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
781
782 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
783
784 p11dScanCmd = csrGetCommandBuffer(pMac);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800785 if (p11dScanCmd)
Jeff Johnson295189b2012-06-20 16:38:30 -0700786 {
787 tANI_U32 numChn = pMac->scan.baseChannels.numChannels;
788
789 palZeroMemory(pMac->hHdd, &p11dScanCmd->u.scanCmd, sizeof(tScanCmd));
790 status = palAllocateMemory( pMac->hHdd, (void **)&pChnInfo->ChannelList, numChn );
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800791 if ( !HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700792 {
793 break;
794 }
795 status = palCopyMemory( pMac->hHdd, pChnInfo->ChannelList,
796 pMac->scan.baseChannels.channelList, numChn );
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800797 if ( !HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700798 {
799 palFreeMemory( pMac->hHdd, pChnInfo->ChannelList );
800 pChnInfo->ChannelList = NULL;
801 break;
802 }
803 pChnInfo->numOfChannels = (tANI_U8)numChn;
804 p11dScanCmd->command = eSmeCommandScan;
805 p11dScanCmd->u.scanCmd.callback = NULL;
806 p11dScanCmd->u.scanCmd.pContext = NULL;
807 p11dScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++;
808 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
809
810 if ( csrIs11dSupported(pMac) )
811 {
812 scanReq.scanType = eSIR_PASSIVE_SCAN;
813 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
814 p11dScanCmd->u.scanCmd.reason = eCsrScan11d1;
815 scanReq.maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
816 scanReq.minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
817 }
818 else
819 {
820 scanReq.scanType = eSIR_ACTIVE_SCAN;
821 scanReq.requestType = eCSR_SCAN_IDLE_MODE_SCAN;
822 p11dScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
823 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
824 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800825
826 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
827 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700828 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700829
Jeff Johnson295189b2012-06-20 16:38:30 -0700830 status = csrScanCopyRequest(pMac, &p11dScanCmd->u.scanCmd.u.scanRequest, &scanReq);
831 //Free the channel list
832 palFreeMemory( pMac->hHdd, pChnInfo->ChannelList );
833
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800834 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700835 {
836 //Start process the command
837#ifdef WLAN_AP_STA_CONCURRENCY
838 status = csrQueueScanRequest(pMac, p11dScanCmd);
839#else
840 status = csrQueueSmeCommand(pMac, p11dScanCmd, eANI_BOOLEAN_FALSE);
841#endif
842 if( !HAL_STATUS_SUCCESS( status ) )
843 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800844 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700845 break;
846 }
847 }
848 else
849 {
850 break;
851 }
852 }
853 else
854 {
855 //error
856 break;
857 }
858 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700859
860 //Scan only 2G Channels if set in ini file
861 //This is mainly to reduce the First Scan duration
862 //Once we turn on Wifi
863 if(pMac->scan.fFirstScanOnly2GChnl)
864 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800865 smsLog( pMac, LOG1, FL("Scanning only 2G Channels during first scan"));
Jeff Johnsone7245742012-09-05 17:12:55 -0700866 csrScan2GOnyRequest(pMac, pScanCmd, pScanRequest);
867 }
868
Jeff Johnson295189b2012-06-20 16:38:30 -0700869 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
870 if(HAL_STATUS_SUCCESS(status))
871 {
872 //Start process the command
873#ifdef WLAN_AP_STA_CONCURRENCY
874 status = csrQueueScanRequest(pMac,pScanCmd);
875#else
876 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
877#endif
878 if( !HAL_STATUS_SUCCESS( status ) )
879 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800880 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700881 break;
882 }
883 }
884 else
885 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800886 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700887 break;
888 }
889 }
890 else
891 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800892 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700893 break;
894 }
895 }
896 } while(0);
897 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
898 {
899 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
900 {
901 //Set the flag back for restarting idle scan
902 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
903 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800904 smsLog( pMac, LOGE, FL(" failed with status = %d, releasing scan cmd"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700905 csrReleaseCommandScan(pMac, pScanCmd);
906 }
907
908 return (status);
909}
910
911
912eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
913{
914 eHalStatus status = eHAL_STATUS_SUCCESS;
915 tSmeCmd *pScanCmd;
916
917 if(pMac->scan.fScanEnable)
918 {
919 pScanCmd = csrGetCommandBuffer(pMac);
920 if(pScanCmd)
921 {
922 pScanCmd->command = eSmeCommandScan;
923 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
924 pScanCmd->u.scanCmd.callback = NULL;
925 pScanCmd->u.scanCmd.pContext = NULL;
926 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
927 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700928 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700929 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
930 if( !HAL_STATUS_SUCCESS( status ) )
931 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800932 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700933 csrReleaseCommandScan(pMac, pScanCmd);
934 }
935 }
936 else
937 {
938 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800939 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700940 status = eHAL_STATUS_RESOURCES;
941 }
942 }
943
944 return (status);
945}
946
947
948eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
949{
950 eHalStatus status = eHAL_STATUS_SUCCESS;
951 tANI_U32 scanId;
952 tCsrScanRequest scanReq;
953
954 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
955 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
956 scanReq.scanType = eSIR_ACTIVE_SCAN;
957 scanReq.requestType = reqType;
958 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
959 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800960 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
961 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700962 //Scan with invalid sessionId.
963 //This results in SME using the first available session to scan.
964 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
965 &scanId, NULL, NULL);
966
967 return (status);
968}
969
970
971
972
973eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
974{
975 eHalStatus status = eHAL_STATUS_FAILURE;
976 tScanResultHandle hBSSList = NULL;
977 tCsrScanResultFilter *pScanFilter = NULL;
978 tANI_U32 roamId = 0;
979 tCsrRoamProfile *pProfile = NULL;
980 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
981
Jeff Johnson32d95a32012-09-10 13:15:23 -0700982 if(!pSession)
983 {
984 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
985 return eHAL_STATUS_FAILURE;
986 }
987
Jeff Johnson295189b2012-06-20 16:38:30 -0700988 do
989 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800990 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -0700991 if(pSession->fCancelRoaming)
992 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800993 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -0700994 csrScanStartIdleScan(pMac);
995 status = eHAL_STATUS_SUCCESS;
996 break;
997 }
998 //Here is the profile we need to connect to
999 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1000 if(!HAL_STATUS_SUCCESS(status))
1001 break;
1002 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1003 if(NULL == pSession->pCurRoamProfile)
1004 {
1005 pScanFilter->EncryptionType.numEntries = 1;
1006 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1007 }
1008 else
1009 {
1010 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
1011 status = palAllocateMemory(pMac->hHdd, (void **)&pProfile, sizeof(tCsrRoamProfile));
1012 if(!HAL_STATUS_SUCCESS(status))
1013 break;
1014 palZeroMemory(pMac->hHdd, pProfile, sizeof(tCsrRoamProfile));
1015 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1016 if(!HAL_STATUS_SUCCESS(status))
1017 break;
1018 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1019 }//We have a profile
1020 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1021 if(HAL_STATUS_SUCCESS(status))
1022 {
1023 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1024 if(HAL_STATUS_SUCCESS(status))
1025 {
1026 if(eCsrLostLink1 == reason)
1027 {
1028 //we want to put the last connected BSS to the very beginning, if possible
1029 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1030 }
1031 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1032 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1033 if(!HAL_STATUS_SUCCESS(status))
1034 {
1035 csrScanResultPurge(pMac, hBSSList);
1036 }
1037 }//Have scan result
1038 }
1039 }while(0);
1040 if(pScanFilter)
1041 {
1042 //we need to free memory for filter if profile exists
1043 csrFreeScanFilter(pMac, pScanFilter);
1044 palFreeMemory(pMac->hHdd, pScanFilter);
1045 }
1046 if(NULL != pProfile)
1047 {
1048 csrReleaseProfile(pMac, pProfile);
1049 palFreeMemory(pMac->hHdd, (void *)pProfile);
1050 }
1051
1052 return (status);
1053}
1054
1055
Jeff Johnson32d95a32012-09-10 13:15:23 -07001056eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, void *callback, void *pContext)
Jeff Johnson295189b2012-06-20 16:38:30 -07001057{
1058 eHalStatus status = eHAL_STATUS_SUCCESS;
1059 tSmeCmd *pScanCmd;
1060
1061 if(pMac->scan.fScanEnable)
1062 {
1063 pScanCmd = csrGetCommandBuffer(pMac);
1064 if(pScanCmd)
1065 {
1066 pScanCmd->command = eSmeCommandScan;
1067 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
Jeff Johnson32d95a32012-09-10 13:15:23 -07001068 pScanCmd->u.scanCmd.callback = callback;
1069 pScanCmd->u.scanCmd.pContext = pContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07001070 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1071 //Need to make the following atomic
1072 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
1073 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1074 if( !HAL_STATUS_SUCCESS( status ) )
1075 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001076 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001077 csrReleaseCommandScan(pMac, pScanCmd);
1078 }
1079 }
1080 else
1081 {
1082 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001083 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001084 status = eHAL_STATUS_RESOURCES;
1085 }
1086 }
1087
1088 return (status);
1089}
1090
1091
1092eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1093{
1094 eHalStatus status = eHAL_STATUS_FAILURE;
1095 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1096
Jeff Johnson32d95a32012-09-10 13:15:23 -07001097 if(!pSession)
1098 {
1099 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1100 return eHAL_STATUS_FAILURE;
1101 }
1102
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001103 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001104 if(pSession->fCancelRoaming)
1105 {
1106 csrScanStartIdleScan(pMac);
1107 }
1108 else if(pSession->pCurRoamProfile)
1109 {
1110 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1111 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1112 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1113 {
1114 //try lostlink scan2
1115 status = csrScanRequestLostLink2(pMac, sessionId);
1116 }
1117 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1118 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1119 {
1120 //go straight to lostlink scan3
1121 status = csrScanRequestLostLink3(pMac, sessionId);
1122 }
1123 else
1124 {
1125 //we are done with lostlink
1126 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1127 {
1128 csrScanStartIdleScan(pMac);
1129 }
1130 status = eHAL_STATUS_SUCCESS;
1131 }
1132 }
1133 else
1134 {
1135 status = csrScanRequestLostLink3(pMac, sessionId);
1136 }
1137
1138 return (status);
1139}
1140
1141
1142
1143eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1144{
1145 eHalStatus status = eHAL_STATUS_FAILURE;
1146 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1147
Jeff Johnson32d95a32012-09-10 13:15:23 -07001148 if(!pSession)
1149 {
1150 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1151 return eHAL_STATUS_FAILURE;
1152 }
1153
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001154 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001155 if(pSession->fCancelRoaming)
1156 {
1157 csrScanStartIdleScan(pMac);
1158 }
1159 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1160 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1161 {
1162 //try lostlink scan3
1163 status = csrScanRequestLostLink3(pMac, sessionId);
1164 }
1165 else
1166 {
1167 //we are done with lostlink
1168 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1169 {
1170 csrScanStartIdleScan(pMac);
1171 }
1172 }
1173
1174 return (status);
1175}
1176
1177
1178
1179eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1180{
1181 eHalStatus status = eHAL_STATUS_SUCCESS;
1182
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001183 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001184 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1185 {
1186 //we are done with lostlink
1187 csrScanStartIdleScan(pMac);
1188 }
1189
1190 return (status);
1191}
1192
1193
1194
1195
1196//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1197//If no roam profile (it should not), it is like lostlinkscan3
1198eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1199{
1200 eHalStatus status = eHAL_STATUS_SUCCESS;
1201 tSmeCmd *pCommand = NULL;
1202 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1203 tCsrScanResultFilter *pScanFilter = NULL;
1204 tScanResultHandle hBSSList = NULL;
1205 tCsrScanResultInfo *pScanResult = NULL;
1206 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1207
Jeff Johnson32d95a32012-09-10 13:15:23 -07001208 if(!pSession)
1209 {
1210 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1211 return eHAL_STATUS_FAILURE;
1212 }
1213
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001214 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001215 do
1216 {
1217 pCommand = csrGetCommandBuffer(pMac);
1218 if(!pCommand)
1219 {
1220 status = eHAL_STATUS_RESOURCES;
1221 break;
1222 }
1223 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
1224 pCommand->command = eSmeCommandScan;
1225 pCommand->sessionId = (tANI_U8)sessionId;
1226 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1227 pCommand->u.scanCmd.callback = NULL;
1228 pCommand->u.scanCmd.pContext = NULL;
1229 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1230 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001231 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1232 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001233 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1234 if(pSession->connectedProfile.SSID.length)
1235 {
1236 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
1237 if(!HAL_STATUS_SUCCESS(status))
1238 {
1239 break;
1240 }
1241 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
1242 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1243 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
1244 }
1245 else
1246 {
1247 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1248 }
1249 if(pSession->pCurRoamProfile)
1250 {
1251 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1252 if(!HAL_STATUS_SUCCESS(status))
1253 {
1254 break;
1255 }
1256 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1257 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1258 if(!HAL_STATUS_SUCCESS(status))
1259 {
1260 break;
1261 }
1262 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1263 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1264 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1265 {
1266 tANI_U8 i, nChn = 0;
1267 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
1268 WNI_CFG_VALID_CHANNEL_LIST_LEN);
1269 if(!HAL_STATUS_SUCCESS(status))
1270 {
1271 break;
1272 }
1273 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1274 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1275 {
1276 for(i = 0; i < nChn; i++)
1277 {
1278 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1279 pScanResult->BssDescriptor.channelId)
1280 {
1281 break;
1282 }
1283 }
1284 if(i == nChn)
1285 {
1286 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1287 }
1288 }
1289 //Include the last connected BSS' channel
1290 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1291 {
1292 for(i = 0; i < nChn; i++)
1293 {
1294 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1295 pSession->connectedProfile.operationChannel)
1296 {
1297 break;
1298 }
1299 }
1300 if(i == nChn)
1301 {
1302 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1303 }
1304 }
1305 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1306 }
1307 else
1308 {
1309 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1310 {
1311 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
1312 1);
1313 //just try the last connected channel
1314 if(HAL_STATUS_SUCCESS(status))
1315 {
1316 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1317 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1318 }
1319 else
1320 {
1321 break;
1322 }
1323 }
1324 }
1325 }
1326 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
1327 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1328 if( !HAL_STATUS_SUCCESS( status ) )
1329 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001330 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001331 break;
1332 }
1333 } while( 0 );
1334
1335 if(!HAL_STATUS_SUCCESS(status))
1336 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001337 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001338 if(pCommand)
1339 {
1340 csrReleaseCommandScan(pMac, pCommand);
1341 }
1342 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1343 }
1344 if(pScanFilter)
1345 {
1346 csrFreeScanFilter(pMac, pScanFilter);
1347 palFreeMemory(pMac->hHdd, pScanFilter);
1348 }
1349 if(hBSSList)
1350 {
1351 csrScanResultPurge(pMac, hBSSList);
1352 }
1353
1354 return( status );
1355}
1356
1357
1358//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1359//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1360eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1361{
1362 eHalStatus status = eHAL_STATUS_SUCCESS;
1363 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1364 tCsrScanResultFilter *pScanFilter = NULL;
1365 tScanResultHandle hBSSList = NULL;
1366 tCsrScanResultInfo *pScanResult = NULL;
1367 tSmeCmd *pCommand = NULL;
1368 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1369
Jeff Johnson32d95a32012-09-10 13:15:23 -07001370 if(!pSession)
1371 {
1372 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1373 return eHAL_STATUS_FAILURE;
1374 }
1375
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001376 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001377 do
1378 {
1379 pCommand = csrGetCommandBuffer(pMac);
1380 if(!pCommand)
1381 {
1382 status = eHAL_STATUS_RESOURCES;
1383 break;
1384 }
1385 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
1386 pCommand->command = eSmeCommandScan;
1387 pCommand->sessionId = (tANI_U8)sessionId;
1388 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1389 pCommand->u.scanCmd.callback = NULL;
1390 pCommand->u.scanCmd.pContext = NULL;
1391 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1392 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001393 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1394 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001395 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1396 if(pSession->pCurRoamProfile)
1397 {
1398 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1399 if(!HAL_STATUS_SUCCESS(status))
1400 {
1401 break;
1402 }
1403 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1404 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1405 if(!HAL_STATUS_SUCCESS(status))
1406 {
1407 break;
1408 }
1409 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1410 if(!HAL_STATUS_SUCCESS(status))
1411 {
1412 break;
1413 }
1414 if(hBSSList)
1415 {
1416 tANI_U8 i, nChn = 0;
1417 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
1418 WNI_CFG_VALID_CHANNEL_LIST_LEN);
1419 if(!HAL_STATUS_SUCCESS(status))
1420 {
1421 break;
1422 }
1423 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1424 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1425 {
1426 for(i = 0; i < nChn; i++)
1427 {
1428 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1429 pScanResult->BssDescriptor.channelId)
1430 {
1431 break;
1432 }
1433 }
1434 if(i == nChn)
1435 {
1436 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1437 }
1438 }
1439 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1440 }
1441 }
1442 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
1443 //Put to the head in pending queue
1444 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1445 if( !HAL_STATUS_SUCCESS( status ) )
1446 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001447 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001448 break;
1449 }
1450 } while( 0 );
1451
1452 if(!HAL_STATUS_SUCCESS(status))
1453 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001454 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001455 if(pCommand)
1456 {
1457 csrReleaseCommandScan(pMac, pCommand);
1458 }
1459 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1460 }
1461 if(pScanFilter)
1462 {
1463 csrFreeScanFilter(pMac, pScanFilter);
1464 palFreeMemory(pMac->hHdd, pScanFilter);
1465 }
1466 if(hBSSList)
1467 {
1468 csrScanResultPurge(pMac, hBSSList);
1469 }
1470
1471 return( status );
1472}
1473
1474
1475//To actively scan all valid channels
1476eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1477{
1478 eHalStatus status = eHAL_STATUS_SUCCESS;
1479 tSmeCmd *pCommand;
1480 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1481
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001482 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001483 do
1484 {
1485 pCommand = csrGetCommandBuffer(pMac);
1486 if(!pCommand)
1487 {
1488 status = eHAL_STATUS_RESOURCES;
1489 break;
1490 }
1491 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
1492 pCommand->command = eSmeCommandScan;
1493 pCommand->sessionId = (tANI_U8)sessionId;
1494 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1495 pCommand->u.scanCmd.callback = NULL;
1496 pCommand->u.scanCmd.pContext = NULL;
1497 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1498 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001499 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1500 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001501 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1502 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
1503 //Put to the head of pending queue
1504 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1505 if( !HAL_STATUS_SUCCESS( status ) )
1506 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001507 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001508 break;
1509 }
1510 } while( 0 );
1511 if(!HAL_STATUS_SUCCESS(status))
1512 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001513 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001514 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1515 {
1516 csrScanStartIdleScan(pMac);
1517 }
1518 if(pCommand)
1519 {
1520 csrReleaseCommandScan(pMac, pCommand);
1521 }
1522 }
1523
1524 return( status );
1525}
1526
1527
1528eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1529{
1530 eHalStatus status = eHAL_STATUS_FAILURE;
1531 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1532 tCsrScanResultFilter *pScanFilter = NULL;
1533 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1534 tANI_U32 sessionId = pCommand->sessionId;
1535#ifdef FEATURE_WLAN_BTAMP_UT_RF
1536 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1537#endif
1538 do
1539 {
1540 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1541 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1542 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001543 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001544 break;
1545 }
1546 if(pProfile == NULL)
1547 break;
1548 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1549 if(!HAL_STATUS_SUCCESS(status))
1550 break;
1551 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1552 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1553 if(!HAL_STATUS_SUCCESS(status))
1554 break;
1555 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1556 if(!HAL_STATUS_SUCCESS(status))
1557 break;
1558 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1559 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1560 if(!HAL_STATUS_SUCCESS(status))
1561 {
1562 break;
1563 }
1564 }while(0);
1565 if(!HAL_STATUS_SUCCESS(status))
1566 {
1567 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1568 {
1569 csrScanResultPurge(pMac, hBSSList);
1570 }
1571 //We haven't done anything to this profile
1572 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId,
1573 eCSR_ROAM_ASSOCIATION_FAILURE, eCSR_ROAM_RESULT_FAILURE);
1574 //In case we have nothing else to do, restart idle scan
1575 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1576 {
1577 status = csrScanStartIdleScan(pMac);
1578 }
1579#ifdef FEATURE_WLAN_BTAMP_UT_RF
1580 //In case of WDS station, let it retry.
1581 if( CSR_IS_WDS_STA(pProfile) )
1582 {
1583 //Save the roma profile so we can retry
1584 csrFreeRoamProfile( pMac, sessionId );
1585 if (HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd,
1586 (void **)&pSession->pCurRoamProfile,
1587 sizeof(tCsrRoamProfile))))
1588 {
1589 palZeroMemory(pMac->hHdd, pSession->pCurRoamProfile, sizeof(tCsrRoamProfile));
1590 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1591 }
1592 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1593 }
1594#endif
1595 }
1596 if(pScanFilter)
1597 {
1598 csrFreeScanFilter(pMac, pScanFilter);
1599 palFreeMemory(pMac->hHdd, pScanFilter);
1600 }
1601
1602 return (status);
1603}
1604
1605
1606eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1607{
1608 eHalStatus status = eHAL_STATUS_SUCCESS;
1609 tANI_U32 sessionId = pCommand->sessionId;
1610 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1611 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1612
Jeff Johnson32d95a32012-09-10 13:15:23 -07001613 if(!pSession)
1614 {
1615 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1616 return eHAL_STATUS_FAILURE;
1617 }
1618
Jeff Johnson295189b2012-06-20 16:38:30 -07001619#if defined(WLAN_DEBUG)
1620 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1621 {
1622 char str[36];
1623 palCopyMemory(pMac->hHdd, str, pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1624 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
1625 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001626 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001627 }
1628#endif
1629 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1630 if(pProfile && CSR_IS_START_IBSS(pProfile))
1631 {
1632 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1633 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1634 if(!HAL_STATUS_SUCCESS(status))
1635 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001636 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001637 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1638 }
1639 }
1640 else
1641 {
1642 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1643
1644 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1645 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1646 {
1647 status = csrScanStartIdleScan(pMac);
1648 }
1649 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1650 {
1651 //Only indicate assoc_completion if we indicate assoc_start.
1652 if(pSession->bRefAssocStartCnt > 0)
1653 {
1654 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
1655 palZeroMemory(pMac->hHdd, &roamInfo, sizeof(tCsrRoamInfo));
1656 pRoamInfo = &roamInfo;
1657 if(pCommand->u.roamCmd.pRoamBssEntry)
1658 {
1659 tCsrScanResult *pScanResult =
1660 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1661 tCsrScanResult, Link);
1662 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1663 }
1664 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1665 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1666 pSession->bRefAssocStartCnt--;
1667 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1668 pCommand->u.scanCmd.roamId,
1669 eCSR_ROAM_ASSOCIATION_COMPLETION,
1670 eCSR_ROAM_RESULT_FAILURE);
1671 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001672 else
1673 {
1674 csrRoamCallCallback(pMac, sessionId, NULL,
1675 pCommand->u.scanCmd.roamId,
1676 eCSR_ROAM_ASSOCIATION_FAILURE,
1677 eCSR_ROAM_RESULT_FAILURE);
1678 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001679#ifdef FEATURE_WLAN_BTAMP_UT_RF
1680 //In case of WDS station, let it retry.
1681 if( CSR_IS_WDS_STA(pProfile) )
1682 {
1683 //Save the roma profile so we can retry
1684 csrFreeRoamProfile( pMac, sessionId );
1685 if (HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd,
1686 (void **)&pSession->pCurRoamProfile,
1687 sizeof(tCsrRoamProfile))))
1688 {
1689 palZeroMemory(pMac->hHdd, pSession->pCurRoamProfile, sizeof(tCsrRoamProfile));
1690 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1691 }
1692 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1693 }
1694#endif
1695 }
1696 else
1697 {
1698 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1699 }
1700 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1701 }
1702
1703 return (status);
1704}
1705
1706
1707//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1708eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1709{
1710 eHalStatus status = eHAL_STATUS_FAILURE;
1711 tScanResultHandle hBSSList = NULL;
1712 tCsrScanResultFilter *pScanFilter = NULL;
1713 tANI_U32 roamId = 0;
1714 tCsrRoamProfile *pProfile = NULL;
1715 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1716
1717 do
1718 {
1719 //Here is the profile we need to connect to
1720 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1721 if(!HAL_STATUS_SUCCESS(status))
1722 break;
1723 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1724 if(NULL == pSession) break;
1725 if(NULL == pSession->pCurRoamProfile)
1726 {
1727 pScanFilter->EncryptionType.numEntries = 1;
1728 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1729 }
1730 else
1731 {
1732 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
1733 status = palAllocateMemory(pMac->hHdd, (void **)&pProfile, sizeof(tCsrRoamProfile));
1734 if(!HAL_STATUS_SUCCESS(status))
1735 break;
1736 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1737 if(!HAL_STATUS_SUCCESS(status))
1738 break;
1739 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1740 }//We have a profile
1741 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1742 if(HAL_STATUS_SUCCESS(status))
1743 {
1744 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1745 if(HAL_STATUS_SUCCESS(status))
1746 {
1747 //we want to put the last connected BSS to the very beginning, if possible
1748 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1749 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1750 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1751 if(!HAL_STATUS_SUCCESS(status))
1752 {
1753 csrScanResultPurge(pMac, hBSSList);
1754 }
1755 }//Have scan result
1756 else
1757 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001758 smsLog(pMac, LOGW, FL("cannot find matching BSS of %02X-%02X-%02X-%02X-%02X-%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001759 pSession->connectedProfile.bssid[0],
1760 pSession->connectedProfile.bssid[1],
1761 pSession->connectedProfile.bssid[2],
1762 pSession->connectedProfile.bssid[3],
1763 pSession->connectedProfile.bssid[4],
1764 pSession->connectedProfile.bssid[5]);
1765 //Disconnect
1766 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1767 }
1768 }
1769 }while(0);
1770 if(pScanFilter)
1771 {
1772 csrFreeScanFilter(pMac, pScanFilter);
1773 palFreeMemory(pMac->hHdd, pScanFilter);
1774 }
1775 if(NULL != pProfile)
1776 {
1777 csrReleaseProfile(pMac, pProfile);
1778 palFreeMemory(pMac->hHdd, pProfile);
1779 }
1780
1781 return (status);
1782}
1783
1784
1785
1786eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
1787{
1788 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
1789 tScanResultList *pScanList = (tScanResultList *)hScanList;
1790
1791 if(pScanList)
1792 {
1793 status = csrLLScanPurgeResult(pMac, &pScanList->List);
1794 csrLLClose(&pScanList->List);
1795 palFreeMemory(pMac->hHdd, pScanList);
1796 }
1797 return (status);
1798}
1799
1800
1801static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
1802{
1803 tANI_U32 ret = 0;
1804 int i = CSR_NUM_RSSI_CAT - 1;
1805
1806 while(i >= 0)
1807 {
1808 if(rssi >= pMac->roam.configParam.RSSICat[i])
1809 {
1810 ret = pMac->roam.configParam.BssPreferValue[i];
1811 break;
1812 }
1813 i--;
1814 };
1815
1816 return (ret);
1817}
1818
1819
1820//Return a CapValue base on the capabilities of a BSS
1821static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
1822{
1823 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08001824#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
1825 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
1826 {
1827 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
1828 {
1829 ret += CSR_BSS_CAP_VALUE_5GHZ;
1830 }
1831 }
1832#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001833 if( pIes )
1834 {
1835 //We only care about 11N capability
1836 if(pIes->HTCaps.present)
1837 {
1838 ret += CSR_BSS_CAP_VALUE_HT;
1839 }
1840 if(CSR_IS_QOS_BSS(pIes))
1841 {
1842 ret += CSR_BSS_CAP_VALUE_WMM;
1843 //Give advantage to UAPSD
1844 if(CSR_IS_UAPSD_BSS(pIes))
1845 {
1846 ret += CSR_BSS_CAP_VALUE_UAPSD;
1847 }
1848 }
1849 }
1850
1851 return (ret);
1852}
1853
1854
1855//To check whther pBss1 is better than pBss2
1856static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
1857{
1858 tANI_BOOLEAN ret;
1859
1860 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
1861 {
1862 ret = eANI_BOOLEAN_TRUE;
1863 }
1864 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
1865 {
1866 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
1867 {
1868 ret = eANI_BOOLEAN_TRUE;
1869 }
1870 else
1871 {
1872 ret = eANI_BOOLEAN_FALSE;
1873 }
1874 }
1875 else
1876 {
1877 ret = eANI_BOOLEAN_FALSE;
1878 }
1879
1880 return (ret);
1881}
1882
1883
Srikant Kuppa866893f2012-12-27 17:28:14 -08001884#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001885//Add the channel to the occupiedChannels array
1886static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08001887 tpAniSirGlobal pMac,
1888 tCsrScanResult *pResult,
1889 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001890 tDot11fBeaconIEs *pIes)
1891{
1892 eHalStatus status;
1893 tANI_U8 channel;
1894 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
1895 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
1896
1897 channel = pResult->Result.BssDescriptor.channelId;
1898
1899 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08001900 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001901 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08001902 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001903 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08001904 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001905 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001906 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08001907 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08001908 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
1909 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
1910 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001911 }
1912}
1913#endif
1914
Jeff Johnson295189b2012-06-20 16:38:30 -07001915//Put the BSS into the scan result list
1916//pIes can not be NULL
1917static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
1918{
Srinivas28b5b4e2012-12-12 13:07:53 -08001919#ifdef FEATURE_WLAN_LFR
1920 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
1921#endif
1922
Jeff Johnson295189b2012-06-20 16:38:30 -07001923 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
1924 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
1925 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08001926#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08001927 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
1928 {
1929 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
1930 NOT set in the cfg.ini file */
1931 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
1932 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001933#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001934}
1935
1936
1937eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
1938{
1939 eHalStatus status;
1940 tScanResultList *pRetList;
1941 tCsrScanResult *pResult, *pBssDesc;
1942 tANI_U32 count = 0;
1943 tListElem *pEntry;
1944 tANI_U32 bssLen, allocLen;
1945 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
1946 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
1947 tDot11fBeaconIEs *pIes, *pNewIes;
1948 tANI_BOOLEAN fMatch;
1949
1950 if(phResult)
1951 {
1952 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
1953 }
1954 status = palAllocateMemory(pMac->hHdd, (void **)&pRetList, sizeof(tScanResultList));
1955 if(HAL_STATUS_SUCCESS(status))
1956 {
1957 palZeroMemory(pMac->hHdd, pRetList, sizeof(tScanResultList));
1958 csrLLOpen(pMac->hHdd, &pRetList->List);
1959 pRetList->pCurEntry = NULL;
1960
1961 csrLLLock(&pMac->scan.scanResultList);
1962 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
1963 while( pEntry )
1964 {
1965 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
1966 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
1967 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
1968 //for any error condition, otherwiase, it will be freed later.
1969 //reset
1970 fMatch = eANI_BOOLEAN_FALSE;
1971 pNewIes = NULL;
1972
1973 if(pFilter)
1974 {
1975 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
1976 if( NULL != pIes )
1977 {
1978 //Only save it when matching
1979 if(fMatch)
1980 {
1981 if( !pBssDesc->Result.pvIes )
1982 {
1983 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
1984 pNewIes = pIes;
1985 }
1986 else
1987 {
1988 //The pIes is allocated by someone else. make a copy
1989 //Only to save parsed IEs if caller provides a filter. Most likely the caller
1990 //is using to for association, hence save the parsed IEs
1991 status = palAllocateMemory(pMac->hHdd, (void **)&pNewIes, sizeof(tDot11fBeaconIEs));
1992 if( HAL_STATUS_SUCCESS( status ) )
1993 {
1994 palCopyMemory( pMac->hHdd, pNewIes, pIes, sizeof( tDot11fBeaconIEs ) );
1995 }
1996 else
1997 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001998 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001999 //Need to free memory allocated by csrMatchBSS
2000 if( !pBssDesc->Result.pvIes )
2001 {
2002 palFreeMemory(pMac->hHdd, pIes);
2003 }
2004 break;
2005 }
2006 }
2007 }//fMatch
2008 else if( !pBssDesc->Result.pvIes )
2009 {
2010 palFreeMemory(pMac->hHdd, pIes);
2011 }
2012 }
2013 }
2014 if(NULL == pFilter || fMatch)
2015 {
2016 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2017 allocLen = sizeof( tCsrScanResult ) + bssLen;
2018 status = palAllocateMemory(pMac->hHdd, (void **)&pResult, allocLen);
2019 if(!HAL_STATUS_SUCCESS(status))
2020 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002021 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002022 if(pNewIes)
2023 {
2024 palFreeMemory(pMac->hHdd, pNewIes);
2025 }
2026 break;
2027 }
2028 palZeroMemory(pMac->hHdd, pResult, allocLen);
2029 pResult->capValue = pBssDesc->capValue;
2030 pResult->preferValue = pBssDesc->preferValue;
2031 pResult->ucEncryptionType = uc;
2032 pResult->mcEncryptionType = mc;
2033 pResult->authType = auth;
2034 pResult->Result.ssId = pBssDesc->Result.ssId;
2035 pResult->Result.timer = 0;
2036 //save the pIes for later use
2037 pResult->Result.pvIes = pNewIes;
2038 //save bss description
2039 status = palCopyMemory(pMac->hHdd, &pResult->Result.BssDescriptor, &pBssDesc->Result.BssDescriptor, bssLen);
2040 if(!HAL_STATUS_SUCCESS(status))
2041 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002042 smsLog(pMac, LOGE, FL(" fail to copy memory for scan result"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002043 palFreeMemory(pMac->hHdd, pResult);
2044 if(pNewIes)
2045 {
2046 palFreeMemory(pMac->hHdd, pNewIes);
2047 }
2048 break;
2049 }
2050 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2051 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2052 {
2053 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2054 }
2055 else
2056 {
2057 //To sort the list
2058 tListElem *pTmpEntry;
2059 tCsrScanResult *pTmpResult;
2060
2061 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2062 while(pTmpEntry)
2063 {
2064 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
2065 if(csrIsBetterBss(pResult, pTmpResult))
2066 {
2067 csrLLInsertEntry(&pRetList->List, pTmpEntry, &pResult->Link, LL_ACCESS_NOLOCK);
2068 //To indicate we are done
2069 pResult = NULL;
2070 break;
2071 }
2072 pTmpEntry = csrLLNext(&pRetList->List, pTmpEntry, LL_ACCESS_NOLOCK);
2073 }
2074 if(pResult != NULL)
2075 {
2076 //This one is not better than any one
2077 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2078 }
2079 }
2080 count++;
2081 }
2082 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2083 }//while
2084 csrLLUnlock(&pMac->scan.scanResultList);
2085
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002086 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002087
2088 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2089 {
2090 //Fail or No one wants the result.
2091 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2092 }
2093 else
2094 {
2095 if(0 == count)
2096 {
2097 //We are here meaning the there is no match
2098 csrLLClose(&pRetList->List);
2099 palFreeMemory(pMac->hHdd, pRetList);
2100 status = eHAL_STATUS_E_NULL_VALUE;
2101 }
2102 else if(phResult)
2103 {
2104 *phResult = pRetList;
2105 }
2106 }
2107 }//Allocated pRetList
2108
2109 return (status);
2110}
2111
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002112/*
2113 * NOTE: This routine is being added to make
2114 * sure that scan results are not being flushed
2115 * while roaming. If the scan results are flushed,
2116 * we are unable to recover from
2117 * csrRoamRoamingStateDisassocRspProcessor.
2118 * If it is needed to remove this routine,
2119 * first ensure that we recover gracefully from
2120 * csrRoamRoamingStateDisassocRspProcessor if
2121 * csrScanGetResult returns with a failure because
2122 * of not being able to find the roaming BSS.
2123 */
2124tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2125{
2126 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2127 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2128 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2129 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2130 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2131 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2132 default:
2133 return 0;
2134 }
2135}
2136
Jeff Johnson295189b2012-06-20 16:38:30 -07002137eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2138{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002139 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
2140 if (isFlushDenied) {
2141 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2142 __func__, isFlushDenied);
2143 return eHAL_STATUS_FAILURE;
2144 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002145 return ( csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList) );
2146}
2147
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302148eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002149{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302150 eHalStatus status = eHAL_STATUS_SUCCESS;
2151 tListElem *pEntry,*pFreeElem;
2152 tCsrScanResult *pBssDesc;
2153 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002154
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302155 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002156
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302157 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2158 while( pEntry != NULL)
2159 {
2160 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2161 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2162 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002163 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302164 pFreeElem = pEntry;
2165 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2166 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2167 csrFreeScanResultEntry( pMac, pBssDesc );
2168 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002169 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302170 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2171 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002172
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302173 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002174
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302175 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002176}
2177
Jeff Johnson295189b2012-06-20 16:38:30 -07002178/**
2179 * csrCheck11dChannel
2180 *
2181 *FUNCTION:
2182 * This function is called from csrScanFilter11dResult function and
2183 * compare channel number with given channel list.
2184 *
2185 *LOGIC:
2186 * Check Scan result channel number with CFG channel list
2187 *
2188 *ASSUMPTIONS:
2189 *
2190 *
2191 *NOTE:
2192 *
2193 * @param channelId channel number
2194 * @param pChannelList Pointer to channel list
2195 * @param numChannels Number of channel in channel list
2196 *
2197 * @return Status
2198 */
2199
2200eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2201{
2202 eHalStatus status = eHAL_STATUS_FAILURE;
2203 tANI_U8 i = 0;
2204
2205 for (i = 0; i < numChannels; i++)
2206 {
2207 if(pChannelList[ i ] == channelId)
2208 {
2209 status = eHAL_STATUS_SUCCESS;
2210 break;
2211 }
2212 }
2213 return status;
2214}
2215
2216/**
2217 * csrScanFilter11dResult
2218 *
2219 *FUNCTION:
2220 * This function is called from csrApplyCountryInformation function and
2221 * filter scan result based on valid channel list number.
2222 *
2223 *LOGIC:
2224 * Get scan result from scan list and Check Scan result channel number
2225 * with 11d channel list if channel number is found in 11d channel list
2226 * then do not remove scan result entry from scan list
2227 *
2228 *ASSUMPTIONS:
2229 *
2230 *
2231 *NOTE:
2232 *
2233 * @param pMac Pointer to Global MAC structure
2234 *
2235 * @return Status
2236 */
2237
2238eHalStatus csrScanFilter11dResult(tpAniSirGlobal pMac)
2239{
2240 eHalStatus status = eHAL_STATUS_SUCCESS;
2241 tListElem *pEntry,*pTempEntry;
2242 tCsrScanResult *pBssDesc;
2243 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2244
2245 /* Get valid channels list from CFG */
2246 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2247 pMac->roam.validChannelList, &len)))
2248 {
2249 smsLog( pMac, LOG1, "Failed to get Channel list from CFG");
2250 }
2251
2252 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2253 while( pEntry )
2254 {
2255 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2256 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
2257 LL_ACCESS_LOCK );
2258 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2259 pMac->roam.validChannelList, len))
2260 {
2261 /* Remove Scan result which does not have 11d channel */
2262 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2263 LL_ACCESS_LOCK ))
2264 {
2265 csrFreeScanResultEntry( pMac, pBssDesc );
2266 }
2267 }
2268 pEntry = pTempEntry;
2269 }
2270 return status;
2271}
2272
2273
2274eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
2275{
2276 eHalStatus status = eHAL_STATUS_SUCCESS;
2277 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
2278 tCsrScanResult *pResult, *pScanResult;
2279 tANI_U32 count = 0;
2280 tListElem *pEntry;
2281 tANI_U32 bssLen, allocLen;
2282
2283 if(phResult)
2284 {
2285 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2286 }
2287 status = palAllocateMemory(pMac->hHdd, (void **)&pRetList, sizeof(tScanResultList));
2288 if(HAL_STATUS_SUCCESS(status))
2289 {
2290 palZeroMemory(pMac->hHdd, pRetList, sizeof(tScanResultList));
2291 csrLLOpen(pMac->hHdd, &pRetList->List);
2292 pRetList->pCurEntry = NULL;
2293 csrLLLock(&pMac->scan.scanResultList);
2294 csrLLLock(&pInList->List);
2295
2296 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
2297 while( pEntry )
2298 {
2299 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2300 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
2301 allocLen = sizeof( tCsrScanResult ) + bssLen;
2302 status = palAllocateMemory(pMac->hHdd, (void **)&pResult, allocLen);
2303 if(!HAL_STATUS_SUCCESS(status))
2304 {
2305 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2306 count = 0;
2307 break;
2308 }
2309 palZeroMemory(pMac->hHdd, pResult, allocLen);
2310 status = palCopyMemory(pMac->hHdd, &pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
2311 if(!HAL_STATUS_SUCCESS(status))
2312 {
2313 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2314 count = 0;
2315 break;
2316 }
2317 if( pScanResult->Result.pvIes )
2318 {
2319 status = palAllocateMemory(pMac->hHdd, (void **)&pResult->Result.pvIes, sizeof( tDot11fBeaconIEs ));
2320 if(!HAL_STATUS_SUCCESS(status))
2321 {
2322 //Free the memory we allocate above first
2323 palFreeMemory( pMac->hHdd, pResult );
2324 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2325 count = 0;
2326 break;
2327 }
2328 status = palCopyMemory(pMac->hHdd, pResult->Result.pvIes,
2329 pScanResult->Result.pvIes, sizeof( tDot11fBeaconIEs ));
2330 if(!HAL_STATUS_SUCCESS(status))
2331 {
2332 //Free the memory we allocate above first
2333 palFreeMemory( pMac->hHdd, pResult );
2334 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2335 count = 0;
2336 break;
2337 }
2338 }
2339 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
2340 count++;
2341 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
2342 }//while
2343 csrLLUnlock(&pInList->List);
2344 csrLLUnlock(&pMac->scan.scanResultList);
2345
2346 if(HAL_STATUS_SUCCESS(status))
2347 {
2348 if(0 == count)
2349 {
2350 csrLLClose(&pRetList->List);
2351 palFreeMemory(pMac->hHdd, pRetList);
2352 status = eHAL_STATUS_E_NULL_VALUE;
2353 }
2354 else if(phResult)
2355 {
2356 *phResult = pRetList;
2357 }
2358 }
2359 }//Allocated pRetList
2360
2361 return (status);
2362}
2363
2364
2365
2366eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
2367{
2368 eHalStatus status = eHAL_STATUS_SUCCESS;
2369 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
2370
2371 if((eWNI_SME_SCAN_RSP == pMsg->type) || (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
2372 {
2373 status = csrScanSmeScanResponse( pMac, pMsgBuf );
2374 }
2375 else
2376 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002377 if(pMsg->type == eWNI_SME_UPPER_LAYER_ASSOC_CNF)
Jeff Johnson295189b2012-06-20 16:38:30 -07002378 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002379 tCsrRoamSession *pSession;
2380 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
2381 tCsrRoamInfo roamInfo;
2382 tCsrRoamInfo *pRoamInfo = NULL;
2383 tANI_U32 sessionId;
2384 eHalStatus status;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002385 smsLog( pMac, LOG1, FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002386 palZeroMemory(pMac->hHdd, &roamInfo, sizeof(tCsrRoamInfo));
2387 pRoamInfo = &roamInfo;
2388 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
2389 status = csrRoamGetSessionIdFromBSSID( pMac, (tCsrBssid *)pUpperLayerAssocCnf->bssId, &sessionId );
2390 pSession = CSR_GET_SESSION(pMac, sessionId);
2391
2392 if(!pSession)
2393 {
2394 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2395 return eHAL_STATUS_FAILURE;
2396 }
2397
2398 pRoamInfo->statusCode = eSIR_SME_SUCCESS; //send the status code as Success
2399 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
2400 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
2401 pRoamInfo->rsnIELen = (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
2402 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
2403 pRoamInfo->addIELen = (tANI_U8)pUpperLayerAssocCnf->addIE.length;
2404 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
2405 palCopyMemory(pMac->hHdd, pRoamInfo->peerMac, pUpperLayerAssocCnf->peerMacAddr, sizeof(tSirMacAddr));
2406 palCopyMemory(pMac->hHdd, &pRoamInfo->bssid, pUpperLayerAssocCnf->bssId, sizeof(tCsrBssid));
2407 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
2408 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
2409 {
2410 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
2411 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
2412 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_INFRA_IND, eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
2413 }
2414 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
2415 {
2416 vos_sleep( 100 );
2417 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
2418 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_WDS_IND, eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
2419 }
2420
Jeff Johnson295189b2012-06-20 16:38:30 -07002421 }
2422 else
2423 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002424
2425 if( csrIsAnySessionInConnectState( pMac ) )
2426 {
2427 //In case of we are connected, we need to check whether connect status changes
2428 //because scan may also run while connected.
2429 csrRoamCheckForLinkStatusChange( pMac, ( tSirSmeRsp * )pMsgBuf );
2430 }
2431 else
2432 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002433 smsLog( pMac, LOGW, "Message [0x%04x] received in state, when expecting Scan Response", pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002434 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002435 }
2436 }
2437
2438 return (status);
2439}
2440
2441
2442
2443void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
2444{
2445 int idx, len;
2446 tANI_U8 *pbIe;
2447
2448 //If failed to remove, assuming someone else got it.
2449 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
2450 (0 == pNewBssDescr->WscIeLen))
2451 {
2452 idx = 0;
2453 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
2454 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
2455 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
2456 //Save WPS IE if it exists
2457 pNewBssDescr->WscIeLen = 0;
2458 while(idx < len)
2459 {
2460 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
2461 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
2462 {
2463 //Founrd it
2464 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
2465 {
2466 palCopyMemory(pMac->hHdd, pNewBssDescr->WscIeProbeRsp,
2467 pbIe, pbIe[1] + 2);
2468 pNewBssDescr->WscIeLen = pbIe[1] + 2;
2469 }
2470 break;
2471 }
2472 idx += pbIe[1] + 2;
2473 pbIe += pbIe[1] + 2;
2474 }
2475 }
2476}
2477
2478
2479
2480//pIes may be NULL
2481tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
2482 tDot11fBeaconIEs *pIes, tAniSSID *pSsid , v_TIME_t *timer )
2483{
2484 tListElem *pEntry;
2485
2486 tCsrScanResult *pBssDesc;
2487 tANI_BOOLEAN fRC = FALSE;
2488
2489 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
2490 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
2491 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
2492 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2493
2494 while( pEntry )
2495 {
2496 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2497
2498 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
2499 // matches
2500 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
2501 pSirBssDescr, pIes ) )
2502 {
2503 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
2504 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
2505 // Remove the 'old' entry from the list....
2506 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
2507 {
2508 // !we need to free the memory associated with this node
2509 //If failed to remove, assuming someone else got it.
2510 *pSsid = pBssDesc->Result.ssId;
2511 *timer = pBssDesc->Result.timer;
2512 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
2513
2514 csrFreeScanResultEntry( pMac, pBssDesc );
2515 }
2516 else
2517 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002518 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07002519 }
2520 fRC = TRUE;
2521
2522 // If we found a match, we can stop looking through the list.
2523 break;
2524 }
2525
2526 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
2527 }
2528
2529 return fRC;
2530}
2531
2532
2533eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2534 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2535{
2536 eHalStatus status = eHAL_STATUS_FAILURE;
2537 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2538
Jeff Johnson32d95a32012-09-10 13:15:23 -07002539 if(!pSession)
2540 {
2541 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2542 return eHAL_STATUS_FAILURE;
2543 }
2544
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002545 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002546 if( pIes )
2547 {
2548 // check if this is a RSN BSS
2549 if( pIes->RSN.present )
2550 {
2551 // Check if the BSS is capable of doing pre-authentication
2552 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
2553 {
2554
2555#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2556 {
2557 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
2558 palZeroMemory(pMac->hHdd, &secEvent, sizeof(vos_event_wlan_security_payload_type));
2559 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
2560 secEvent.encryptionModeMulticast =
2561 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
2562 secEvent.encryptionModeUnicast =
2563 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
2564 palCopyMemory( pMac->hHdd, secEvent.bssid, pSession->connectedProfile.bssid, 6 );
2565 secEvent.authMode =
2566 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
2567 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
2568 }
2569#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2570
2571 // if yes, then add to PMKIDCandidateList
2572 status = palCopyMemory(pMac->hHdd, pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
2573 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2574
2575 if( HAL_STATUS_SUCCESS( status ) )
2576 {
Venkata Prathyusha Kuntupalliea7098e2013-01-31 16:08:13 -08002577 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 ) // Bit 0 offirst byte - PreAuthentication Capability
Jeff Johnson295189b2012-06-20 16:38:30 -07002578 {
2579 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported = eANI_BOOLEAN_TRUE;
2580 }
2581 else
2582 {
2583 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported = eANI_BOOLEAN_FALSE;
2584 }
2585 pSession->NumPmkidCandidate++;
2586 }
2587 }
2588 else
2589 {
2590 status = eHAL_STATUS_FAILURE;
2591 }
2592 }
2593 }
2594
2595 return (status);
2596}
2597
2598//This function checks whether new AP is found for the current connected profile
2599//If it is found, it return the sessionId, else it return invalid sessionID
2600tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
2601 tSirBssDescription *pBssDesc,
2602 tDot11fBeaconIEs *pIes)
2603{
2604 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
2605 tCsrRoamSession *pSession;
2606 tDot11fBeaconIEs *pIesLocal = pIes;
2607
2608 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2609 {
2610 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
2611 {
2612 if( CSR_IS_SESSION_VALID( pMac, i ) )
2613 {
2614 pSession = CSR_GET_SESSION( pMac, i );
2615 if( csrIsConnStateConnectedInfra( pMac, i ) &&
2616 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
2617 {
2618 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
2619 {
2620 //this new BSS fits the current profile connected
2621 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
2622 {
2623 bRet = i;
2624 }
2625 break;
2626 }
2627 }
2628 }
2629 }
2630 if( !pIes )
2631 {
2632 palFreeMemory(pMac->hHdd, pIesLocal);
2633 }
2634 }
2635
2636 return (tANI_U8)bRet;
2637}
2638
2639#ifdef FEATURE_WLAN_WAPI
2640eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2641 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2642{
2643 eHalStatus status = eHAL_STATUS_FAILURE;
2644 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2645
Jeff Johnson32d95a32012-09-10 13:15:23 -07002646 if(!pSession)
2647 {
2648 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2649 return eHAL_STATUS_FAILURE;
2650 }
2651
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002652 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002653 if( pIes )
2654 {
2655 // check if this is a WAPI BSS
2656 if( pIes->WAPI.present )
2657 {
2658 // Check if the BSS is capable of doing pre-authentication
2659 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
2660 {
2661
2662 // if yes, then add to BKIDCandidateList
2663 status = palCopyMemory(pMac->hHdd, pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
2664 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2665
2666 if( HAL_STATUS_SUCCESS( status ) )
2667 {
2668 if ( pIes->WAPI.preauth )
2669 {
2670 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported = eANI_BOOLEAN_TRUE;
2671 }
2672 else
2673 {
2674 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported = eANI_BOOLEAN_FALSE;
2675 }
2676 pSession->NumBkidCandidate++;
2677 }
2678 }
2679 else
2680 {
2681 status = eHAL_STATUS_FAILURE;
2682 }
2683 }
2684 }
2685
2686 return (status);
2687}
2688
2689//This function checks whether new AP is found for the current connected profile
2690//if so add to BKIDCandidateList
2691tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
2692 tDot11fBeaconIEs *pIes)
2693{
2694 tANI_BOOLEAN fRC = FALSE;
2695 tDot11fBeaconIEs *pIesLocal = pIes;
2696 tANI_U32 sessionId;
2697 tCsrRoamSession *pSession;
2698
2699 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2700 {
2701 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
2702 {
2703 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
2704 {
2705 pSession = CSR_GET_SESSION( pMac, sessionId );
2706 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
2707 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
2708 {
2709 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
2710 {
2711 //this new BSS fits the current profile connected
2712 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
2713 {
2714 fRC = TRUE;
2715 }
2716 }
2717 }
2718 }
2719 }
2720 if(!pIes)
2721 {
2722 palFreeMemory(pMac->hHdd, pIesLocal);
2723 }
2724
2725 }
2726 return fRC;
2727}
2728
2729#endif
2730
2731
2732static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac )
2733{
2734 tListElem *pEntry;
2735 tCsrScanResult *pBssDescription;
2736 tANI_S8 cand_Bss_rssi;
2737 tANI_BOOLEAN fDupBss;
2738#ifdef FEATURE_WLAN_WAPI
2739 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
2740#endif /* FEATURE_WLAN_WAPI */
2741 tDot11fBeaconIEs *pIesLocal = NULL;
2742 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
2743 tAniSSID tmpSsid;
2744 v_TIME_t timer=0;
2745
2746 tmpSsid.length = 0;
2747 cand_Bss_rssi = -128; // RSSI coming from PE is -ve
2748
2749 // remove the BSS descriptions from temporary list
2750 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
2751 {
2752 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2753
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002754 smsLog( pMac, LOGW, "...Bssid= %02x-%02x-%02x-%02x-%02x-%02x chan= %d, rssi = -%d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002755 pBssDescription->Result.BssDescriptor.bssId[ 0 ], pBssDescription->Result.BssDescriptor.bssId[ 1 ],
2756 pBssDescription->Result.BssDescriptor.bssId[ 2 ], pBssDescription->Result.BssDescriptor.bssId[ 3 ],
2757 pBssDescription->Result.BssDescriptor.bssId[ 4 ], pBssDescription->Result.BssDescriptor.bssId[ 5 ],
2758 pBssDescription->Result.BssDescriptor.channelId,
2759 pBssDescription->Result.BssDescriptor.rssi * (-1) );
2760
2761 //At this time, pBssDescription->Result.pvIes may be NULL
2762 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
2763 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
2764 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002765 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002766 csrFreeScanResultEntry(pMac, pBssDescription);
2767 continue;
2768 }
2769 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid , &timer );
2770 //Check whether we have reach out limit
2771 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
2772 {
2773 //Limit reach
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002774 smsLog(pMac, LOGW, FL(" BSS limit reached"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002775 //Free the resources
2776 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
2777 {
2778 palFreeMemory(pMac->hHdd, pIesLocal);
2779 }
2780 csrFreeScanResultEntry(pMac, pBssDescription);
2781 //Continue because there may be duplicated BSS
2782 continue;
2783 }
2784 // check for duplicate scan results
2785 if ( !fDupBss )
2786 {
2787 //Found a new BSS
2788 sessionId = csrProcessBSSDescForPMKIDList(pMac,
2789 &pBssDescription->Result.BssDescriptor, pIesLocal);
2790 if( CSR_SESSION_ID_INVALID != sessionId)
2791 {
2792 csrRoamCallCallback(pMac, sessionId, NULL, 0,
2793 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
2794 }
2795 }
2796 else
2797 {
2798 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
2799 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
2800 {
2801 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
2802 //if diff of saved SSID time and current time is less than 1 min to avoid
2803 //side effect of saving SSID with old one is that if AP changes its SSID while remain
2804 //hidden, we may never see it and also to address the requirement of
2805 //When we remove hidden ssid from the profile i.e., forget the SSID via
2806 // GUI that SSID shouldn't see in the profile
2807 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
2808 {
2809 pBssDescription->Result.timer = timer;
2810 pBssDescription->Result.ssId = tmpSsid;
2811 }
2812 }
2813 }
2814
2815 //Tush: find a good AP for 11d info
2816 if( csrIs11dSupported( pMac ) )
2817 {
2818 if(cand_Bss_rssi < pBssDescription->Result.BssDescriptor.rssi)
2819 {
2820 // check if country information element is present
2821 if(pIesLocal->Country.present)
2822 {
2823 cand_Bss_rssi = pBssDescription->Result.BssDescriptor.rssi;
2824 // learn country information
2825 csrLearnCountryInformation( pMac, &pBssDescription->Result.BssDescriptor,
2826 pIesLocal, eANI_BOOLEAN_FALSE );
2827 }
2828
2829 }
2830 }
2831
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08002832
Jeff Johnson295189b2012-06-20 16:38:30 -07002833 // append to main list
2834 csrScanAddResult(pMac, pBssDescription, pIesLocal);
2835 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
2836 {
2837 palFreeMemory(pMac->hHdd, pIesLocal);
2838 }
2839 }
2840
2841 //Tush: If we can find the current 11d info in any of the scan results, or
2842 // a good enough AP with the 11d info from the scan results then no need to
2843 // get into ambiguous state
2844 if(pMac->scan.fAmbiguous11dInfoFound)
2845 {
2846 if((pMac->scan.fCurrent11dInfoMatch) || (cand_Bss_rssi != -128))
2847 {
2848 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
2849 }
2850 }
2851
2852#ifdef FEATURE_WLAN_WAPI
2853 if(fNewWapiBSSForCurConnection)
2854 {
2855 //remember it first
2856 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
2857 }
2858#endif /* FEATURE_WLAN_WAPI */
2859
2860 return;
2861}
2862
2863
2864static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
2865 tDot11fBeaconIEs *pIes)
2866{
2867 tCsrScanResult *pCsrBssDescription = NULL;
2868 tANI_U32 cbBSSDesc;
2869 tANI_U32 cbAllocated;
2870 eHalStatus halStatus;
2871
2872 // figure out how big the BSS description is (the BSSDesc->length does NOT
2873 // include the size of the length field itself).
2874 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
2875
2876 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
2877
2878 halStatus = palAllocateMemory( pMac->hHdd, (void **)&pCsrBssDescription, cbAllocated );
2879 if ( HAL_STATUS_SUCCESS(halStatus) )
2880 {
2881 palZeroMemory( pMac->hHdd, pCsrBssDescription, cbAllocated );
2882 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
2883 palCopyMemory(pMac->hHdd, &pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
2884#if defined(VOSS_ENSBALED)
2885 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
2886#endif
2887 csrScanAddResult(pMac, pCsrBssDescription, pIes);
2888 }
2889
2890 return( pCsrBssDescription );
2891}
2892
2893// Append a Bss Description...
2894tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
2895 tSirBssDescription *pSirBssDescription,
2896 tDot11fBeaconIEs *pIes )
2897{
2898 tCsrScanResult *pCsrBssDescription = NULL;
2899 tAniSSID tmpSsid;
2900 v_TIME_t timer = 0;
2901 int result;
2902
2903 tmpSsid.length = 0;
2904 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer );
2905 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
2906 if (result && (pCsrBssDescription != NULL))
2907 {
2908 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
2909 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
2910 {
2911 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
2912 //if diff of saved SSID time and current time is less than 1 min to avoid
2913 //side effect of saving SSID with old one is that if AP changes its SSID while remain
2914 //hidden, we may never see it and also to address the requirement of
2915 //When we remove hidden ssid from the profile i.e., forget the SSID via
2916 // GUI that SSID shouldn't see in the profile
2917 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
2918 {
2919 pCsrBssDescription->Result.ssId = tmpSsid;
2920 pCsrBssDescription->Result.timer = timer;
2921 }
2922 }
2923 }
2924
2925
2926 return( pCsrBssDescription );
2927}
2928
2929
2930
2931void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
2932{
2933 tCsrChannelPowerInfo *pChannelSet;
2934 tListElem *pEntry;
2935
2936 csrLLLock(pChannelList);
2937 // Remove the channel sets from the learned list and put them in the free list
2938 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
2939 {
2940 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
2941 if( pChannelSet )
2942 {
2943 palFreeMemory( pMac->hHdd, pChannelSet );
2944 }
2945 }
2946 csrLLUnlock(pChannelList);
2947 return;
2948}
2949
2950
2951/*
2952 * Save the channelList into the ultimate storage as the final stage of channel
2953 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
2954 */
Jeff Johnsone7245742012-09-05 17:12:55 -07002955eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07002956{
2957 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
2958 tSirMacChanInfo *pChannelInfo;
2959 tCsrChannelPowerInfo *pChannelSet;
2960 tANI_BOOLEAN f2GHzInfoFound = FALSE;
2961 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
2962 eHalStatus halStatus;
2963
2964 pChannelInfo = channelTable;
2965 // atleast 3 bytes have to be remaining -- from "countryString"
2966 while ( i-- )
2967 {
2968 halStatus = palAllocateMemory( pMac->hHdd, (void **)&pChannelSet, sizeof(tCsrChannelPowerInfo) );
2969 if ( eHAL_STATUS_SUCCESS == halStatus )
2970 {
2971 palZeroMemory(pMac->hHdd, pChannelSet, sizeof(tCsrChannelPowerInfo));
2972 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
2973 pChannelSet->numChannels = pChannelInfo->numChannels;
2974
2975 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07002976 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07002977 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07002978
Jeff Johnson295189b2012-06-20 16:38:30 -07002979 {
2980 pChannelSet->interChannelOffset = 1;
2981 f2GHzInfoFound = TRUE;
2982 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002983 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07002984 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002985 {
2986 pChannelSet->interChannelOffset = 4;
2987 f2GHzInfoFound = FALSE;
2988 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002989 else
2990 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07002991 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07002992 pChannelSet->firstChannel);
2993 palFreeMemory(pMac->hHdd, pChannelSet);
2994 return eHAL_STATUS_FAILURE;
2995 }
2996
Jeff Johnson295189b2012-06-20 16:38:30 -07002997 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
2998
2999 if( f2GHzInfoFound )
3000 {
3001 if( !f2GListPurged )
3002 {
3003 // purge previous results if found new
3004 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3005 f2GListPurged = TRUE;
3006 }
3007
3008 if(CSR_IS_OPERATING_BG_BAND(pMac))
3009 {
3010 // add to the list of 2.4 GHz channel sets
3011 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3012 }
3013 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003014 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003015 pChannelSet->firstChannel);
3016 palFreeMemory(pMac->hHdd, pChannelSet);
3017 }
3018 }
3019 else
3020 {
3021 // 5GHz info found
3022 if( !f5GListPurged )
3023 {
3024 // purge previous results if found new
3025 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3026 f5GListPurged = TRUE;
3027 }
3028
3029 if(CSR_IS_OPERATING_A_BAND(pMac))
3030 {
3031 // add to the list of 5GHz channel sets
3032 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3033 }
3034 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003035 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003036 pChannelSet->firstChannel);
3037 palFreeMemory(pMac->hHdd, pChannelSet);
3038 }
3039 }
3040 }
3041
3042 pChannelInfo++; // move to next entry
3043 }
3044
Jeff Johnsone7245742012-09-05 17:12:55 -07003045 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003046}
3047
3048
3049
3050void csrApplyPower2Current( tpAniSirGlobal pMac )
3051{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003052 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003053 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3054 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3055}
3056
3057
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003058void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003059{
3060 int i;
3061 eNVChannelEnabledType channelEnabledType;
3062 tANI_U8 numChannels = 0;
3063 tANI_U8 tempNumChannels = 0;
3064 tCsrChannel ChannelList;
3065 if( pChannelList->numChannels )
3066 {
3067 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
3068 /* If user doesn't want to scan the DFS channels lets trim them from
3069 the valid channel list*/
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003070 for(i = 0; i< tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003071 {
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003072 if(FALSE == pMac->scan.fEnableDFSChnlScan)
3073 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003074 channelEnabledType =
3075 vos_nv_getChannelEnabledState(pChannelList->channelList[i]);
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003076 }
3077 else
3078 {
3079 channelEnabledType = NV_CHANNEL_ENABLE;
3080 }
3081 if( NV_CHANNEL_ENABLE == channelEnabledType)
3082 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08003083 // Ignore the channel 165 for the country INDONESIA
Madan Mohan Koyyalamudi895cdee2012-11-06 19:13:19 -08003084 if (( pChannelList->channelList[i] == 165 )
3085 && ( pMac->scan.fIgnore_chan165 == VOS_TRUE )
3086 && vos_mem_compare(countryCode, "ID", VOS_COUNTRY_CODE_LEN ))
Jeff Johnson295189b2012-06-20 16:38:30 -07003087 {
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003088 continue;
3089 }
3090 else
3091 {
3092 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
Jeff Johnson295189b2012-06-20 16:38:30 -07003093 numChannels++;
3094 }
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003095 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003096 }
Srikant Kuppa866893f2012-12-27 17:28:14 -08003097 ChannelList.numChannels = numChannels;
3098
Jeff Johnson295189b2012-06-20 16:38:30 -07003099 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3100 // extend scan capability
3101 csrSetCfgScanControlList(pMac, countryCode, &ChannelList); // build a scan list based on the channel list : channel# + active/passive scan
3102#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003103 if (updateRiva)
3104 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003105 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003106 // Send HAL UpdateScanParams message
3107 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
3108 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003109#endif // FEATURE_WLAN_SCAN_PNO
3110 }
3111 else
3112 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003113 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003114 }
3115 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
3116 csrSetCfgCountryCode(pMac, countryCode);
3117}
3118
3119
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003120void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07003121{
3122 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
3123 {
3124
3125#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3126 {
3127 vos_log_802_11d_pkt_type *p11dLog;
3128 int Index;
3129
3130 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3131 if(p11dLog)
3132 {
3133 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
3134 palCopyMemory(pMac->hHdd, p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
3135 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
3136 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3137 {
3138 palCopyMemory(pMac->hHdd, p11dLog->Channels, pMac->scan.base20MHzChannels.channelList,
3139 p11dLog->numChannel);
3140 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
3141 {
3142 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3143 }
3144 }
3145 if(!pMac->roam.configParam.Is11dSupportEnabled)
3146 {
3147 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3148 }
3149 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3150 {
3151 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3152 }
3153 else
3154 {
3155 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3156 }
3157 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3158 }
3159 }
3160#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3161
3162 // switch to passive scans only when 11d is enabled
3163 if( csrIs11dSupported( pMac ) )
3164 {
3165 pMac->scan.curScanType = eSIR_PASSIVE_SCAN;
3166 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003167
3168 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
3169 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
3170
Jeff Johnson295189b2012-06-20 16:38:30 -07003171 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
3172 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
3173 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003174 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07003175 // clear the 11d channel list
3176 palZeroMemory( pMac->hHdd, &pMac->scan.channels11d, sizeof(pMac->scan.channels11d) );
3177 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
3178 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
3179 }
3180
3181 return;
3182}
3183
3184
3185eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
3186{
3187 eHalStatus status = eHAL_STATUS_SUCCESS;
3188 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
3189
3190 //Use the Country code and domain from EEPROM
3191 palCopyMemory(pMac->hHdd, pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault, WNI_CFG_COUNTRY_CODE_LEN);
3192 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07003193 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
3194 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07003195 {
3196 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003197 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003198 }
3199 if(pfRestartNeeded)
3200 {
3201 *pfRestartNeeded = fRestart;
3202 }
3203
3204 return (status);
3205}
3206
3207
3208eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
3209{
3210 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
3211 v_REGDOMAIN_t domainId;
3212
3213 if(pCountry)
3214 {
3215 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId);
3216 if(HAL_STATUS_SUCCESS(status))
3217 {
3218 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
3219 if(HAL_STATUS_SUCCESS(status))
3220 {
3221 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
3222 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
3223 palCopyMemory(pMac->hHdd, pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
3224 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
3225 {
3226 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
3227 csrSetCfgCountryCode(pMac, pCountry);
3228 }
3229 }
3230 }
3231 }
3232
3233 return (status);
3234}
3235
3236
3237
3238//caller allocated memory for pNumChn and pChnPowerInfo
3239//As input, *pNumChn has the size of the array of pChnPowerInfo
3240//Upon return, *pNumChn has the number of channels assigned.
3241void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
3242 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
3243{
3244 tListElem *pEntry;
3245 tANI_U32 chnIdx = 0, idx;
3246 tCsrChannelPowerInfo *pChannelSet;
3247
3248 //Get 2.4Ghz first
3249 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
3250 while( pEntry && (chnIdx < *pNumChn) )
3251 {
3252 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3253 if ( 1 != pChannelSet->interChannelOffset )
3254 {
3255 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3256 {
3257 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
3258 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3259 }
3260 }
3261 else
3262 {
3263 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3264 {
3265 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
3266 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3267 }
3268 }
3269
3270 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
3271 }
3272 *pNumChn = chnIdx;
3273
3274 return ;
3275}
3276
3277
3278
3279void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
3280{
3281 v_REGDOMAIN_t domainId;
3282 eHalStatus status = eHAL_STATUS_SUCCESS;
3283
3284 do
3285 {
3286 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
3287 if( pMac->scan.fAmbiguous11dInfoFound )
3288 {
3289 // ambiguous info found
3290 //Restore te default domain as well
3291 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pMac->scan.countryCodeCurrent, &domainId )))
3292 {
3293 pMac->scan.domainIdCurrent = domainId;
3294 }
3295 else
3296 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003297 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003298 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
3299 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003300 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003301 break;
3302 }
3303 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
3304 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pMac->scan.countryCode11d, &domainId )))
3305 {
3306 //Check whether we need to enforce default domain
3307 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
3308 (pMac->scan.domainIdCurrent == domainId) )
3309 {
3310
3311#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3312 {
3313 vos_log_802_11d_pkt_type *p11dLog;
3314 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
3315 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
3316
3317 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3318 if(p11dLog)
3319 {
3320 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
3321 palCopyMemory(pMac->hHdd, p11dLog->countryCode, pMac->scan.countryCode11d, 3);
3322 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
3323 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3324 {
3325 palCopyMemory(pMac->hHdd, p11dLog->Channels, pMac->scan.channels11d.channelList,
3326 p11dLog->numChannel);
3327 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
3328 &nChnInfo, chnPwrInfo);
3329 nTmp = nChnInfo;
3330 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
3331 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
3332 &nChnInfo, &chnPwrInfo[nTmp]);
3333 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
3334 {
3335 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
3336 {
3337 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
3338 {
3339 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
3340 break;
3341 }
3342 }
3343 }
3344 }
3345 if(!pMac->roam.configParam.Is11dSupportEnabled)
3346 {
3347 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3348 }
3349 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3350 {
3351 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3352 }
3353 else
3354 {
3355 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3356 }
3357 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3358 }
3359 }
3360#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3361 if(pMac->scan.domainIdCurrent != domainId)
3362 {
3363 /* Regulatory Domain Changed, Purge Only scan result
3364 * which does not have channel number belong to 11d
3365 * channel list
3366 * */
3367 smsLog(pMac, LOGW, FL("Domain Changed Old %d, new %d"),
3368 pMac->scan.domainIdCurrent, domainId);
3369 csrScanFilter11dResult(pMac);
3370 }
3371 status = WDA_SetRegDomain(pMac, domainId);
3372 if (status != eHAL_STATUS_SUCCESS)
3373 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003374 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003375 }
3376 pMac->scan.domainIdCurrent = domainId;
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003377 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.channels11d, pMac->scan.countryCode11d, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003378 // switch to active scans using this new channel list
3379 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
3380 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
3381 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
3382 }
3383 }
3384
3385 } while( 0 );
3386
3387 return;
3388}
3389
3390
3391
3392tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
3393 tANI_BOOLEAN fForce)
3394{
3395 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
3396 tANI_U32 i;
3397
3398 // convert to UPPER here so we are assured the strings are always in upper case.
3399 for( i = 0; i < 3; i++ )
3400 {
3401 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3402 }
3403
3404 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
3405 // NA is not a valid country code or domain so let's allow this by changing it to the proper
3406 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
3407 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
3408 // 11d information element, let's default to US.
3409 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pCountryCode, NULL ) ) )
3410 {
3411 // Check the enforcement first
3412 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
3413 {
3414 fUnknownCountryCode = TRUE;
3415 }
3416 else
3417 {
3418 pCountryCode[ 0 ] = 'U';
3419 pCountryCode[ 1 ] = 'S';
3420 }
3421 }
3422
3423 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
3424 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
3425 // if we see a 0 in this third character, let's change it to a ' '.
3426 if ( 0 == pCountryCode[ 2 ] )
3427 {
3428 pCountryCode[ 2 ] = ' ';
3429 }
3430
3431 if( !fUnknownCountryCode )
3432 {
3433 fCountryStringChanged = (!palEqualMemory( pMac->hHdd,
3434 pMac->scan.countryCode11d, pCountryCode, 2));
3435
3436
3437 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
3438 || (fForce))
3439 {
3440 // this is the first .11d information
3441 palCopyMemory( pMac->hHdd, pMac->scan.countryCode11d, pCountryCode, sizeof( pMac->scan.countryCode11d ) );
3442 }
3443 }
3444
3445 return( fCountryStringChanged );
3446}
3447
3448
3449void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
3450{
3451 tANI_U32 Index, count=0;
3452 tSirMacChanInfo *pChanInfo;
3453 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003454 tANI_S32 maxChannelIndex;
3455
3456 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
3457 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07003458
3459 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN)))
3460 {
3461 palZeroMemory(pMac->hHdd, pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
3462 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003463 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003464 {
3465 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
3466 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
3467 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003468 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
3469 {
3470 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
3471 break;
3472 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003473 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
3474 pChanInfo->numChannels = 1;
3475 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3476 pChanInfo++;
3477 count++;
3478 }
3479 }
3480 if(count)
3481 {
3482 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
3483 }
3484 palFreeMemory(pMac->hHdd, pChanInfoStart);
3485 }
3486}
3487
3488
3489void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
3490{
3491 tANI_BOOLEAN fPopulate5GBand = FALSE;
3492
3493 do
3494 {
3495 // if this is not a dual band product, then we don't need to set the opposite
3496 // band info. We only work in one band so no need to look in the other band.
3497 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
3498 // if we found channel info on the 5.0 band and...
3499 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
3500 {
3501 // and the 2.4 band is empty, then populate the 2.4 channel info
3502 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
3503 fPopulate5GBand = FALSE;
3504 }
3505 else
3506 {
3507 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
3508 // set the 5.0 band info from the 2.4 country code.
Venkata Prathyusha Kuntupalli884ab982013-03-13 15:28:50 -07003509 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003510 fPopulate5GBand = TRUE;
3511 }
3512 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
3513
3514 } while( 0 );
3515}
3516
3517
3518tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
3519{
3520 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3521 tANI_U32 i;
3522
3523 //Make sure it is a channel that is in our supported list.
3524 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
3525 {
3526 if ( channelId == pMac->scan.baseChannels.channelList[i] )
3527 {
3528 fRet = eANI_BOOLEAN_TRUE;
3529 break;
3530 }
3531 }
3532
3533 //If it is configured to limit a set of the channels
3534 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
3535 {
3536 fRet = eANI_BOOLEAN_FALSE;
3537 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
3538 {
3539 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
3540 {
3541 fRet = eANI_BOOLEAN_TRUE;
3542 break;
3543 }
3544 }
3545 }
3546
3547 return (fRet);
3548}
3549
3550
3551
3552//bSize specify the buffer size of pChannelList
3553tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
3554{
3555 tANI_U8 i, j = 0, chnId;
3556
3557 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
3558 for( i = 0; i < bSize; i++ )
3559 {
3560 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
3561 if ( csrIsSupportedChannel( pMac, chnId ) )
3562 {
3563 pChannelList[j++] = chnId;
3564 }
3565 }
3566
3567 return (j);
3568}
3569
3570
3571
3572//bSize -- specify the buffer size of pChannelList
3573void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
3574 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
3575{
3576 tListElem *pEntry;
3577 tCsrChannelPowerInfo *pChannelSet;
3578 tANI_U8 numChannels;
3579 tANI_U8 *pChannels;
3580
3581 if( pChannelSetList && pChannelList && pNumChannels )
3582 {
3583 pChannels = pChannelList;
3584 *pNumChannels = 0;
3585 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
3586 while( pEntry )
3587 {
3588 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3589 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
3590 pChannels += numChannels;
3591 *pNumChannels += numChannels;
3592 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
3593 }
3594 }
3595}
3596
3597
3598/*
3599 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
3600*/
3601tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
3602 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
3603{
3604 tANI_U8 Num2GChannels, bMaxNumChn;
3605 eHalStatus status;
3606 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3607 v_REGDOMAIN_t domainId;
3608 tDot11fBeaconIEs *pIesLocal = pIes;
3609
Jeff Johnson295189b2012-06-20 16:38:30 -07003610 if (VOS_STA_SAP_MODE == vos_get_conparam ())
3611 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003612
3613 do
3614 {
3615 // check if .11d support is enabled
3616 if( !csrIs11dSupported( pMac ) ) break;
3617 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc, &pIesLocal))) )
3618 {
3619 break;
3620 }
3621 // check if country information element is present
3622 if(!pIesLocal->Country.present)
3623 {
3624 //No country info
3625 break;
3626 }
3627
3628 if( csrSave11dCountryString( pMac, pIesLocal->Country.country, fForce ) )
3629 {
3630 // country string changed, this should not happen
3631 //Need to check whether we care about this BSS' domain info
3632 //If it doesn't match of the connected profile or roaming profile, let's ignore it
3633 tANI_U32 i;
3634 tCsrRoamSession *pSession;
3635
3636 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3637 {
3638 if( CSR_IS_SESSION_VALID( pMac, i ) )
3639 {
3640 pSession = CSR_GET_SESSION( pMac, i );
3641 if(pSession->pCurRoamProfile)
3642 {
3643 tCsrScanResultFilter filter;
3644
3645 palZeroMemory(pMac->hHdd, &filter, sizeof(tCsrScanResultFilter));
3646 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, &filter);
3647 if(HAL_STATUS_SUCCESS(status))
3648 {
3649 tANI_BOOLEAN fMatch = csrMatchBSS(pMac, pSirBssDesc, &filter, NULL, NULL, NULL, NULL);
3650 //Free the resource first
3651 csrFreeScanFilter( pMac, &filter );
3652 if(fMatch)
3653 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003654 smsLog(pMac, LOGW, " Matching roam profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07003655 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
3656 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
3657 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3658 break;
3659 }
3660 }
3661 }
3662 else if( csrIsConnStateConnected(pMac, i))
3663 {
3664 //Reach here only when the currention is base on no profile.
3665 //User doesn't give profile and just connect to anything.
3666 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pSirBssDesc, pIesLocal))
3667 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003668 smsLog(pMac, LOGW, " Matching connect profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07003669 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
3670 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
3671 //Tush
3672 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3673 if(csrIsBssidMatch(pMac, (tCsrBssid *)&pSirBssDesc->bssId,
3674 &pSession->connectedProfile.bssid))
3675 {
3676 //AP changed the 11d info on the fly, modify cfg
3677 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3678 fRet = eANI_BOOLEAN_TRUE;
3679 }
3680 break;
3681 }
3682 }
3683 } //valid session
3684 } //for
3685 if ( i == CSR_ROAM_SESSION_MAX )
3686 {
3687 //Check whether we can use this country's 11d information
3688 if( !pMac->roam.configParam.fEnforceDefaultDomain )
3689 {
3690 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3691 }
3692 else
3693 {
3694 VOS_ASSERT( pMac->scan.domainIdCurrent == pMac->scan.domainIdDefault );
3695 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3696 pMac, pIesLocal->Country.country, &domainId )) &&
3697 ( domainId == pMac->scan.domainIdCurrent ) )
3698 {
3699 //Two countries in the same domain
3700 }
3701 }
3702 }
3703 }
3704 else //Tush
3705 {
3706 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_TRUE;
3707 }
3708
3709 //In case that some channels in 5GHz have the same channel number as 2.4GHz (<= 14)
3710 if(CSR_IS_CHANNEL_5GHZ(pSirBssDesc->channelId))
3711 {
3712 tANI_U8 iC;
3713 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
3714
3715 for(iC = 0; iC < pIesLocal->Country.num_triplets; iC++)
3716 {
3717 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[iC].firstChanNum))
3718 {
3719 pMacChnSet[iC].firstChanNum += 200; //*** Where is this 200 defined?
3720 }
3721 }
3722 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003723 smsLog(pMac, LOG3, FL(" %d sets each one is %d"), pIesLocal->Country.num_triplets, sizeof(tSirMacChanInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07003724 // save the channel/power information from the Channel IE.
3725 //sizeof(tSirMacChanInfo) has to be 3
Jeff Johnsone7245742012-09-05 17:12:55 -07003726 if (eHAL_STATUS_SUCCESS != csrSaveToChannelPower2G_5G( pMac, pIesLocal->Country.num_triplets * sizeof(tSirMacChanInfo),
3727 (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]) ))
3728 {
3729 fRet = eANI_BOOLEAN_FALSE;
3730 return fRet;
3731 }
3732
Jeff Johnson295189b2012-06-20 16:38:30 -07003733 // set the indicator of the channel where the country IE was found...
3734 pMac->scan.channelOf11dInfo = pSirBssDesc->channelId;
3735 // Populate both band channel lists based on what we found in the country information...
3736 csrSetOppositeBandChannelInfo( pMac );
3737 bMaxNumChn = WNI_CFG_VALID_CHANNEL_LIST_LEN;
3738 // construct 2GHz channel list first
3739 csrConstructCurrentValidChannelList( pMac, &pMac->scan.channelPowerInfoList24, pMac->scan.channels11d.channelList,
3740 bMaxNumChn, &Num2GChannels );
3741 // construct 5GHz channel list now
3742 if(bMaxNumChn > Num2GChannels)
3743 {
3744 csrConstructCurrentValidChannelList( pMac, &pMac->scan.channelPowerInfoList5G, pMac->scan.channels11d.channelList + Num2GChannels,
3745 bMaxNumChn - Num2GChannels,
3746 &pMac->scan.channels11d.numChannels );
3747 }
3748
3749 pMac->scan.channels11d.numChannels += Num2GChannels;
3750 fRet = eANI_BOOLEAN_TRUE;
3751
3752 } while( 0 );
3753
3754 if( !pIes && pIesLocal )
3755 {
3756 //locally allocated
3757 palFreeMemory(pMac->hHdd, pIesLocal);
3758 }
3759
3760 return( fRet );
3761}
3762
3763
3764static void csrSaveScanResults( tpAniSirGlobal pMac )
3765{
3766 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
3767 // will set this to the channel where an .11d beacon is seen
3768 pMac->scan.channelOf11dInfo = 0;
3769 // if we get any ambiguous .11d information then this will be set to TRUE
3770 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3771 //Tush
3772 // if we get any ambiguous .11d information, then this will be set to TRUE
3773 // only if the applied 11d info could be found in one of the scan results
3774 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
3775 // move the scan results from interim list to the main scan list
3776 csrMoveTempScanResultsToMainList( pMac );
3777
3778 // Now check if we gathered any domain/country specific information
3779 // If so, we should update channel list and apply Tx power settings
Jeff Johnsone7245742012-09-05 17:12:55 -07003780 if( csrIs11dSupported(pMac) )
3781 {
3782 csrApplyCountryInformation( pMac, FALSE );
3783 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003784}
3785
3786
3787void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
3788{
3789 switch (pCommand->u.scanCmd.reason)
3790 {
3791 case eCsrScanSetBGScanParam:
3792 case eCsrScanAbortBgScan:
3793 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
3794 {
3795 palFreeMemory(pMac->hHdd, pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
3796 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
3797 }
3798 break;
3799 case eCsrScanBGScanAbort:
3800 case eCsrScanBGScanEnable:
3801 case eCsrScanGetScanChnInfo:
3802 break;
3803 case eCsrScanAbortNormalScan:
3804 default:
3805 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
3806 break;
3807 }
3808 if(pCommand->u.scanCmd.pToRoamProfile)
3809 {
3810 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
3811 palFreeMemory(pMac->hHdd, pCommand->u.scanCmd.pToRoamProfile);
3812 }
3813 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
3814}
3815
3816
3817tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
3818{
3819 tANI_U32 index11dChannels, index;
3820 tANI_U32 indexCurrentChannels;
3821 tANI_BOOLEAN fChannelAlreadyScanned;
3822 tANI_U32 len = sizeof(pMac->roam.validChannelList);
3823
3824 *pcChannels = 0;
3825 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
3826 {
3827 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
3828 {
3829 //Find the channel index where we found the 11d info
3830 for(index = 0; index < len; index++)
3831 {
3832 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
3833 break;
3834 }
3835 //check whether we found the channel index
3836 if(index < len)
3837 {
3838 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
3839 // NOT in the current channel list. This gives us a list of the new channels that have not been
3840 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
3841 // initially.
3842 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
3843 {
3844 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
3845
3846 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
3847 {
3848 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
3849 {
3850 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
3851 break;
3852 }
3853 }
3854
3855 if ( !fChannelAlreadyScanned )
3856 {
3857 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
3858 ( *pcChannels )++;
3859 }
3860 }
3861 }
3862 }//GetCFG
3863 }
3864 return( *pcChannels );
3865}
3866
3867
3868eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
3869{
3870 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
3871
3872 switch( pCommand->u.scanCmd.reason )
3873 {
3874 case eCsrScan11d1:
3875 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
3876 break;
3877 case eCsrScan11d2:
3878 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
3879 break;
3880 case eCsrScan11dDone:
3881 NextCommand = eCsrNext11dScanComplete;
3882 break;
3883 case eCsrScanLostLink1:
3884 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
3885 break;
3886 case eCsrScanLostLink2:
3887 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
3888 break;
3889 case eCsrScanLostLink3:
3890 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
3891 break;
3892 case eCsrScanForSsid:
3893 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
3894 break;
3895 case eCsrScanForCapsChange:
3896 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
3897 break;
3898 case eCsrScanIdleScan:
3899 NextCommand = eCsrNextIdleScanComplete;
3900 break;
3901 default:
3902 NextCommand = eCsrNextScanNothing;
3903 break;
3904 }
3905 return( NextCommand );
3906}
3907
3908
3909//Return whether the pCommand is finished.
3910tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
3911{
3912 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
3913
3914 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003915 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003916 pCommand->u.scanCmd.reason = eCsrScan11d2;
3917 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
3918 {
3919 fRet = eANI_BOOLEAN_FALSE;
3920 }
3921
3922 return (fRet);
3923}
3924
3925
3926tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
3927{
3928 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
3929 tANI_U8 *pChannels;
3930 tANI_U8 cChannels;
3931
3932 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN)))
3933 {
3934 palZeroMemory(pMac->hHdd, pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
3935 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
3936 {
3937 pCommand->u.scanCmd.reason = eCsrScan11dDone;
3938 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
3939 {
3940 palFreeMemory(pMac->hHdd, pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
3941 }
3942 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, cChannels)))
3943 {
3944 palCopyMemory(pMac->hHdd, pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, pChannels, cChannels);
3945 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
3946 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
3947 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
3948 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
3949 {
3950 //Reuse the same command buffer
3951 fRet = eANI_BOOLEAN_FALSE;
3952 }
3953 }
3954 }
3955 palFreeMemory(pMac->hHdd, pChannels);
3956 }
3957
3958 return (fRet);
3959}
3960
3961//Return whether the command should be removed
3962tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
3963{
3964 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
3965 tListElem *pEntry;
3966 tSmeCmd *pCommand;
3967 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
3968 tANI_BOOLEAN fSuccess;
3969
3970 pEntry = csrLLPeekHead( &pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK );
3971
3972 if ( pEntry )
3973 {
3974 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
3975
3976 // If the head of the queue is Active and it is a SCAN command, remove
3977 // and put this on the Free queue.
3978 if ( eSmeCommandScan == pCommand->command )
3979 {
3980 tANI_U32 sessionId = pCommand->sessionId;
3981
3982 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
3983 {
3984 fSuccess = eANI_BOOLEAN_FALSE;
3985 }
3986 else
3987 {
3988 //pMac->scan.tempScanResults is not empty meaning the scan found something
3989 //This check only valid here because csrSaveScanresults is not yet called
3990 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
3991 }
3992 csrSaveScanResults(pMac);
3993
3994#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3995 {
3996 vos_log_scan_pkt_type *pScanLog = NULL;
3997 tScanResultHandle hScanResult;
3998 tCsrScanResultInfo *pScanResult;
3999 tDot11fBeaconIEs *pIes;
4000 int n = 0, c = 0;
4001
4002 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
4003 if(pScanLog)
4004 {
4005 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4006 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4007 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4008 {
4009 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
4010 }
4011 else
4012 {
4013 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
4014 {
4015 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
4016 }
4017 else
4018 {
4019 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
4020 }
4021 }
4022 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
4023 {
4024 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
4025 {
4026 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
4027 {
4028 if( n < VOS_LOG_MAX_NUM_BSSID )
4029 {
4030 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
4031 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004032 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004033 break;
4034 }
4035 palCopyMemory(pMac->hHdd, pScanLog->bssid[n], pScanResult->BssDescriptor.bssId, 6);
4036 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
4037 {
4038 palCopyMemory(pMac->hHdd, pScanLog->ssid[n],
4039 pIes->SSID.ssid, pIes->SSID.num_ssid);
4040 }
4041 palFreeMemory(pMac->hHdd, pIes);
4042 n++;
4043 }
4044 c++;
4045 }
4046 pScanLog->numSsid = (v_U8_t)n;
4047 pScanLog->totalSsid = (v_U8_t)c;
4048 csrScanResultPurge(pMac, hScanResult);
4049 }
4050 }
4051 else
4052 {
4053 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
4054 }
4055 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
4056 }
4057 }
4058#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4059
4060 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
4061 //We reuse the command here instead reissue a new command
4062 switch(NextCommand)
4063 {
4064 case eCsrNext11dScan1Success:
4065 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004066 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004067 // if we found country information, no need to continue scanning further, bail out
4068 fRemoveCommand = eANI_BOOLEAN_TRUE;
4069 NextCommand = eCsrNext11dScanComplete;
4070 break;
4071 case eCsrNext11dScan1Failure:
4072 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
4073 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
4074 //we clear the "old" 11d info and give it once more chance
4075 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
4076 if(fRemoveCommand)
4077 {
4078 NextCommand = eCsrNext11dScanComplete;
4079 }
4080 break;
4081 case eCsrNextLostLinkScan1Success:
4082 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
4083 {
4084 csrScanHandleFailedLostlink1(pMac, sessionId);
4085 }
4086 break;
4087 case eCsrNextLostLinkScan2Success:
4088 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
4089 {
4090 csrScanHandleFailedLostlink2(pMac, sessionId);
4091 }
4092 break;
4093 case eCsrNextLostLinkScan3Success:
4094 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
4095 {
4096 csrScanHandleFailedLostlink3(pMac, sessionId);
4097 }
4098 break;
4099 case eCsrNextLostLinkScan1Failed:
4100 csrScanHandleFailedLostlink1(pMac, sessionId);
4101 break;
4102 case eCsrNextLostLinkScan2Failed:
4103 csrScanHandleFailedLostlink2(pMac, sessionId);
4104 break;
4105 case eCsrNextLostLinkScan3Failed:
4106 csrScanHandleFailedLostlink3(pMac, sessionId);
4107 break;
4108 case eCsrNexteScanForSsidSuccess:
4109 csrScanHandleSearchForSSID(pMac, pCommand);
4110 break;
4111 case eCsrNexteScanForSsidFailure:
4112 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
4113 break;
4114 case eCsrNextIdleScanComplete:
4115 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
4116 break;
4117 case eCsrNextCapChangeScanComplete:
4118 csrScanHandleCapChangeScanComplete(pMac, sessionId);
4119 break;
4120 default:
4121
4122 break;
4123 }
4124 }
4125 else
4126 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004127 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004128 fRemoveCommand = eANI_BOOLEAN_FALSE;
4129 }
4130 }
4131 else
4132 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004133 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004134 fRemoveCommand = eANI_BOOLEAN_FALSE;
4135 }
4136
4137 return( fRemoveCommand );
4138}
4139
4140
4141
4142static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
4143 tSirBssDescription *pSirBssDescr,
4144 tDot11fBeaconIEs *pIes)
4145{
4146 tListElem *pEntry;
4147 tCsrScanResult *pCsrBssDescription;
4148
4149 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
4150 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
4151 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
4152 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
4153 while( pEntry )
4154 {
4155 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4156
4157 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
4158 // matches
4159
4160 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
4161 pSirBssDescr, pIes ) )
4162 {
4163 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
4164 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
4165
4166 // Remove the 'old' entry from the list....
4167 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
4168 {
4169 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
4170 // we need to free the memory associated with this node
4171 csrFreeScanResultEntry( pMac, pCsrBssDescription );
4172 }
4173
4174 // If we found a match, we can stop looking through the list.
4175 break;
4176 }
4177
4178 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
4179 }
4180}
4181
4182
4183
4184//Caller allocated memory pfNewBssForConn to return whether new candidate for
4185//current connection is found. Cannot be NULL
4186tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
4187 tSirBssDescription *pBSSDescription,
4188 tDot11fBeaconIEs *pIes)
4189{
4190 tCsrScanResult *pCsrBssDescription = NULL;
4191 tANI_U32 cbBSSDesc;
4192 tANI_U32 cbAllocated;
4193 eHalStatus halStatus;
4194
4195 // figure out how big the BSS description is (the BSSDesc->length does NOT
4196 // include the size of the length field itself).
4197 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
4198
4199 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
4200
4201 halStatus = palAllocateMemory( pMac->hHdd, (void **)&pCsrBssDescription, cbAllocated );
4202 if ( HAL_STATUS_SUCCESS(halStatus) )
4203 {
4204 palZeroMemory(pMac->hHdd, pCsrBssDescription, cbAllocated);
4205 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
4206 palCopyMemory(pMac->hHdd, &pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
4207 //Save SSID separately for later use
4208 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
4209 {
4210 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07004211 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07004212 if (len > SIR_MAC_MAX_SSID_LENGTH)
4213 {
4214 // truncate to fit in our struct
4215 len = SIR_MAC_MAX_SSID_LENGTH;
4216 }
4217 pCsrBssDescription->Result.ssId.length = len;
4218 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
4219 palCopyMemory(pMac->hHdd, pCsrBssDescription->Result.ssId.ssId,
4220 pIes->SSID.ssid, len );
4221 }
4222 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
4223 }
4224
4225 return( pCsrBssDescription );
4226}
4227
4228
4229
4230
4231tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
4232 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2 )
4233{
4234 tANI_BOOLEAN fMatch = FALSE;
4235 tSirMacCapabilityInfo *pCap1, *pCap2;
4236 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004237 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07004238
4239 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
4240 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
4241 if(pCap1->ess == pCap2->ess)
4242 {
4243 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07004244 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
4245 (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
Jeff Johnson295189b2012-06-20 16:38:30 -07004246 {
4247 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004248 // Check for SSID match, if exists
4249 do
4250 {
4251 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4252 {
4253 break;
4254 }
4255 if( NULL == pIesTemp )
4256 {
4257 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4258 {
4259 break;
4260 }
4261 }
4262 if(pIes1->SSID.present && pIesTemp->SSID.present)
4263 {
4264 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4265 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4266 }
4267 }while(0);
4268
Jeff Johnson295189b2012-06-20 16:38:30 -07004269 }
4270 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
4271 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004272
4273 do
4274 {
4275 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4276 {
4277 break;
4278 }
4279 if( NULL == pIesTemp )
4280 {
4281 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4282 {
4283 break;
4284 }
4285 }
4286 //Same channel cannot have same SSID for different IBSS
4287 if(pIes1->SSID.present && pIesTemp->SSID.present)
4288 {
4289 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4290 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4291 }
4292 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004293 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004294 /* In case of P2P devices, ess and ibss will be set to zero */
4295 else if (!pCap1->ess &&
4296 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
4297 {
4298 fMatch = TRUE;
4299 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004300 }
4301
4302 if(pIes1)
4303 {
4304 palFreeMemory(pMac->hHdd, pIes1);
4305 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004306
4307 if( (NULL == pIes2) && pIesTemp )
4308 {
4309 //locally allocated
4310 palFreeMemory(pMac->hHdd, pIesTemp);
4311 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004312
4313 return( fMatch );
4314}
4315
4316
4317tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
4318{
4319 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
4320}
4321
4322
4323//to check whether the BSS matches the dot11Mode
4324static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
4325 tDot11fBeaconIEs *pIes)
4326{
4327 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
4328 eCsrPhyMode phyMode;
4329
4330 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
4331 {
4332 switch(pMac->roam.configParam.phyMode)
4333 {
4334 case eCSR_DOT11_MODE_11b:
4335 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4336 break;
4337 case eCSR_DOT11_MODE_11g:
4338 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4339 break;
4340 case eCSR_DOT11_MODE_11g_ONLY:
4341 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
4342 break;
4343 case eCSR_DOT11_MODE_11a:
4344 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
4345 break;
4346 case eCSR_DOT11_MODE_11n_ONLY:
4347 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4348 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004349
4350#ifdef WLAN_FEATURE_11AC
4351 case eCSR_DOT11_MODE_11ac_ONLY:
4352 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4353 break;
4354#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004355 case eCSR_DOT11_MODE_11b_ONLY:
4356 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
4357 break;
4358 case eCSR_DOT11_MODE_11a_ONLY:
4359 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
4360 break;
4361 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07004362#ifdef WLAN_FEATURE_11AC
4363 case eCSR_DOT11_MODE_11ac:
4364#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004365 case eCSR_DOT11_MODE_TAURUS:
4366 default:
4367 fAllowed = eANI_BOOLEAN_TRUE;
4368 break;
4369 }
4370 }
4371
4372 return (fAllowed);
4373}
4374
4375
4376
4377//Return pIes to caller for future use when returning TRUE.
4378static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
4379 tANI_U8 numChn, tSirBssDescription *pBssDesc,
4380 tDot11fBeaconIEs **ppIes )
4381{
4382 tANI_BOOLEAN fValidChannel = FALSE;
4383 tDot11fBeaconIEs *pIes = NULL;
4384 tANI_U8 index;
4385
4386 for( index = 0; index < numChn; index++ )
4387 {
4388 // This check relies on the fact that a single BSS description is returned in each
4389 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
4390 // to this model when we ran with a large number of APs. If this were to change, then
4391 // this check would have to mess with removing the bssDescription from somewhere in an
4392 // arbitrary index in the bssDescription array.
4393 if ( pChannels[ index ] == pBssDesc->channelId )
4394 {
4395 fValidChannel = TRUE;
4396 break;
4397 }
4398 }
4399 *ppIes = NULL;
4400 if(fValidChannel)
4401 {
4402 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
4403 {
4404 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
4405 if( fValidChannel )
4406 {
4407 *ppIes = pIes;
4408 }
4409 else
4410 {
4411 palFreeMemory( pMac->hHdd, pIes );
4412 }
4413 }
4414 else
4415 {
4416 fValidChannel = FALSE;
4417 }
4418 }
4419
4420 return( fValidChannel );
4421}
4422
4423
4424//Return whether last scan result is received
4425static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
4426 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
4427{
4428 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
4429 tDot11fBeaconIEs *pIes = NULL;
4430 tANI_U32 cbParsed;
4431 tSirBssDescription *pSirBssDescription;
4432 tANI_U32 cbBssDesc;
4433 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
4434 + sizeof(tSirBssDescription); //We need at least one CB
4435
4436 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
4437 // is returned when the scan could not find anything. so if we get scan failure return that
4438 // the scan response is invalid. Also check the lenght in the scan result for valid scan
4439 // BssDescriptions....
4440 do
4441 {
4442 if ( ( cbScanResult <= pScanRsp->length ) &&
4443 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
4444 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
4445 {
4446 tANI_U8 *pChannelList = NULL;
4447 tANI_U8 cChannels = 0;
4448
4449 //Different scan type can reach this point, we need to distinguish it
4450 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
4451 {
4452 //eCsrScanSetBGScanParam uses different structure
4453 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
4454
4455 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
4456 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
4457 }
4458 else
4459 {
4460 //the rest use generic scan request
4461 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
4462 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
4463 }
4464
4465 // if the scan result is not on one of the channels in the Valid channel list, then it
4466 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
4467 // let's drop the scan result.
4468 //
4469 // The other situation is where the scan request is for a scan on a particular channel set
4470 // and the scan result is from a
4471
4472 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
4473 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
4474 // as the valid channels.
4475 if ( 0 == cChannels )
4476 {
4477 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4478
4479 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4480 {
4481 pChannelList = pMac->roam.validChannelList;
4482 cChannels = (tANI_U8)len;
4483 }
4484 else
4485 {
4486 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004487 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07004488 break;
4489 }
4490 }
4491
4492 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
4493 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
4494 pSirBssDescription = pScanRsp->bssDescription;
4495 while( cbParsed < pScanRsp->length )
4496 {
4497 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
4498 {
4499 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
4500 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
4501 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
4502 {
4503 if( csrIs11dSupported( pMac) )
4504 {
4505 //Check whether the BSS is acceptable base on 11d info and our configs.
4506 if( csrMatchCountryCode( pMac, NULL, pIes ) )
4507 {
4508 //Double check whether the channel is acceptable by us.
4509 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
4510 {
4511 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4512 }
4513 }
4514 }
4515 else
4516 {
4517 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4518 }
4519 }
4520 //Free the resource
4521 palFreeMemory( pMac->hHdd, pIes );
4522 }
4523 // skip over the BSS description to the next one...
4524 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
4525
4526 cbParsed += cbBssDesc;
4527 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
4528
4529 } //while
4530 }
4531 else
4532 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004533 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08004534 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004535 //HO bg scan/probe failed no need to try autonomously
4536 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4537 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4538 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4539 {
4540 fRemoveCommand = eANI_BOOLEAN_TRUE;
4541 }
4542 }
4543 }while(0);
4544 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4545 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004546 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 -07004547 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
4548 fRet = eANI_BOOLEAN_TRUE;
4549 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4550 if(pfRemoveCommand)
4551 {
4552 *pfRemoveCommand = fRemoveCommand;
4553 }
4554
4555#ifdef WLAN_AP_STA_CONCURRENCY
4556 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
4557 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004558 /* Pending scan commands in the list because the previous scan command
4559 * was split into a scan command on one channel + a scan command for all
4560 * remaining channels.
4561 *
4562 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08004563 * NOTE for LFR:
4564 * Do not split scans if no concurrent infra connections are
4565 * active and if the scan is a BG scan triggered by LFR (OR)
4566 * any scan if LFR is in the middle of a BG scan. Splitting
4567 * the scan is delaying the time it takes for LFR to find
4568 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004569 */
Srikant Kuppa866893f2012-12-27 17:28:14 -08004570 if ( (csrIsStaSessionConnected(pMac) &&
4571#ifdef FEATURE_WLAN_LFR
4572 (csrIsConcurrentInfraConnected(pMac) ||
4573 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
4574 (pMac->roam.neighborRoamInfo.neighborRoamState !=
4575 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
4576#endif
4577 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004578 (csrIsP2pSessionConnected(pMac)) )
4579 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004580 /* if active connected sessions present then continue to split scan
4581 * with specified interval between consecutive scans */
4582 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Srikant Kuppa866893f2012-12-27 17:28:14 -08004583 palTimerStart(pMac->hHdd, pMac->scan.hTimerStaApConcTimer,
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004584 pCommand->u.scanCmd.u.scanRequest.restTime * PAL_TIMER_TO_MS_UNIT, eANI_BOOLEAN_FALSE);
4585 } else {
4586 /* if no connected sessions present then initiate next scan command immediately */
4587 /* minimum timer granularity is 10ms */
4588 palTimerStart(pMac->hHdd, pMac->scan.hTimerStaApConcTimer, 10 * 1000, eANI_BOOLEAN_FALSE);
4589 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004590 }
4591#endif
4592 return (fRet);
4593}
4594
4595
4596tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
4597{
4598 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
4599 tANI_BOOLEAN f = palEqualMemory( pMac->hHdd, pCommand->u.scanCmd.u.scanRequest.bssid,
4600 bssid, sizeof(tCsrBssid) );
4601
4602 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
4603 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
4604 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
4605}
4606
4607
4608eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
4609{
4610 eHalStatus status = eHAL_STATUS_SUCCESS;
4611 tListElem *pEntry;
4612 tSmeCmd *pCommand;
4613 eCsrScanStatus scanStatus;
4614 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
4615 tSmeGetScanChnRsp *pScanChnInfo;
4616 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4617 eCsrScanReason reason = eCsrScanOther;
4618
4619 pEntry = csrLLPeekHead( &pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK );
4620
4621 if ( pEntry )
4622 {
4623 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4624 if ( eSmeCommandScan == pCommand->command )
4625 {
4626 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
4627 reason = pCommand->u.scanCmd.reason;
4628 switch(pCommand->u.scanCmd.reason)
4629 {
4630 case eCsrScanAbortBgScan:
4631 case eCsrScanAbortNormalScan:
4632 case eCsrScanBGScanAbort:
4633 case eCsrScanBGScanEnable:
4634 break;
4635 case eCsrScanGetScanChnInfo:
4636 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004637 /*
4638 * status code not available in tSmeGetScanChnRsp, so
4639 * by default considereing it to be success
4640 */
4641 scanStatus = eSIR_SME_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004642 csrScanAgeResults(pMac, pScanChnInfo);
4643 break;
4644 case eCsrScanForCapsChange:
4645 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
4646 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004647 case eCsrScanP2PFindPeer:
4648 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) && (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
4649 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
4650 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004651 case eCsrScanSetBGScanParam:
4652 default:
4653 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
4654 {
4655 //Not to get channel info if the scan is not a wildcard scan because
4656 //it may cause scan results got aged out incorrectly.
4657 if( csrScanIsWildCardScan( pMac, pCommand ) && (!pCommand->u.scanCmd.u.scanRequest.p2pSearch) )
4658 {
4659 //Get the list of channels scanned
Jeff Johnson32d95a32012-09-10 13:15:23 -07004660 if( pCommand->u.scanCmd.reason != eCsrScanUserRequest)
4661 {
4662 csrScanGetScanChnInfo(pMac, NULL, NULL);
4663 }
4664 else
4665 {
4666 csrScanGetScanChnInfo(pMac, pCommand->u.scanCmd.callback, pCommand->u.scanCmd.pContext);
4667 pCommand->u.scanCmd.callback = NULL;
4668 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004669 }
4670 }
4671 break;
4672 }//switch
4673 if(fRemoveCommand)
4674 {
4675
4676 csrReleaseScanCommand(pMac, pCommand, scanStatus);
4677
Srikant Kuppa866893f2012-12-27 17:28:14 -08004678 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004679 smeProcessPendingQueue( pMac );
4680 }
4681 else
4682 {
4683 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
4684 status = eHAL_STATUS_FAILURE;
4685 }
4686 }
4687 else
4688 {
4689 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
4690 status = eHAL_STATUS_FAILURE;
4691 }
4692
4693 return (status);
4694}
4695
4696
4697
4698
4699tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
4700{
4701 tListElem *pEntry;
4702 tCsrScanResult *pResult;
4703 tCsrScanResultInfo *pRet = NULL;
4704 tScanResultList *pResultList = (tScanResultList *)hScanResult;
4705
4706 if(pResultList)
4707 {
4708 csrLLLock(&pResultList->List);
4709 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
4710 if(pEntry)
4711 {
4712 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
4713 pRet = &pResult->Result;
4714 }
4715 pResultList->pCurEntry = pEntry;
4716 csrLLUnlock(&pResultList->List);
4717 }
4718
4719 return pRet;
4720}
4721
4722
4723tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
4724{
4725 tListElem *pEntry = NULL;
4726 tCsrScanResult *pResult = NULL;
4727 tCsrScanResultInfo *pRet = NULL;
4728 tScanResultList *pResultList = (tScanResultList *)hScanResult;
4729
4730 if(pResultList)
4731 {
4732 csrLLLock(&pResultList->List);
4733 if(NULL == pResultList->pCurEntry)
4734 {
4735 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
4736 }
4737 else
4738 {
4739 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
4740 }
4741 if(pEntry)
4742 {
4743 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
4744 pRet = &pResult->Result;
4745 }
4746 pResultList->pCurEntry = pEntry;
4747 csrLLUnlock(&pResultList->List);
4748 }
4749
4750 return pRet;
4751}
4752
4753
4754//This function moves the first BSS that matches the bssid to the head of the result
4755eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
4756{
4757 eHalStatus status = eHAL_STATUS_FAILURE;
4758 tScanResultList *pResultList = (tScanResultList *)hScanResult;
4759 tCsrScanResult *pResult = NULL;
4760 tListElem *pEntry = NULL;
4761
4762 if(pResultList && bssid)
4763 {
4764 csrLLLock(&pResultList->List);
4765 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
4766 while(pEntry)
4767 {
4768 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
4769 if(palEqualMemory(pMac->hHdd, bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
4770 {
4771 status = eHAL_STATUS_SUCCESS;
4772 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
4773 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
4774 break;
4775 }
4776 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
4777 }
4778 csrLLUnlock(&pResultList->List);
4779 }
4780
4781 return (status);
4782}
4783
4784
4785//Remove the BSS if possible.
4786//Return -- TRUE == the BSS is remove. False == Fail to remove it
4787//This function is called when list lock is held. Be caution what functions it can call.
4788tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
4789{
4790 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4791 tANI_U32 i;
4792 tCsrRoamSession *pSession;
4793
4794 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
4795 {
4796 if( CSR_IS_SESSION_VALID( pMac, i ) )
4797 {
4798 pSession = CSR_GET_SESSION( pMac, i );
4799 //Not to remove the BSS we are connected to.
4800 if(csrIsConnStateDisconnected(pMac, i) || (NULL == pSession->pConnectBssDesc) ||
4801 (!csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
4802 pSession->pConnectBssDesc, NULL))
4803 )
4804 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004805 smsLog(pMac, LOGW, "Aging out BSS %02X-%02X-%02X-%02X-%02X-%02X Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004806 pResult->Result.BssDescriptor.bssId[0],
4807 pResult->Result.BssDescriptor.bssId[1],
4808 pResult->Result.BssDescriptor.bssId[2],
4809 pResult->Result.BssDescriptor.bssId[3],
4810 pResult->Result.BssDescriptor.bssId[4],
4811 pResult->Result.BssDescriptor.bssId[5],
4812 pResult->Result.BssDescriptor.channelId);
4813 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
4814 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
4815 {
4816 csrFreeScanResultEntry(pMac, pResult);
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07004817 fRet = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004818 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004819 break;
4820 }
4821 } //valid session
4822 } //for
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07004823 if( CSR_ROAM_SESSION_MAX == i && fRet != eANI_BOOLEAN_TRUE )
Jeff Johnson295189b2012-06-20 16:38:30 -07004824 {
4825 //reset the counter so this won't hapeen too soon
4826 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
4827 pResult->Result.BssDescriptor.nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
4828 }
4829
4830 return (fRet);
4831}
4832
4833
4834eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
4835{
4836 eHalStatus status = eHAL_STATUS_SUCCESS;
4837 tListElem *pEntry, *tmpEntry;
4838 tCsrScanResult *pResult;
4839 tLimScanChn *pChnInfo;
4840 tANI_U8 i;
4841
4842 csrLLLock(&pMac->scan.scanResultList);
4843 for(i = 0; i < pScanChnInfo->numChn; i++)
4844 {
4845 pChnInfo = &pScanChnInfo->scanChn[i];
4846 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
4847 while( pEntry )
4848 {
4849 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
4850 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4851 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
4852 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004853 if(pResult->AgingCount <= 0)
4854 {
4855 smsLog(pMac, LOGW, " age out due to ref count");
4856 csrScanAgeOutBss(pMac, pResult);
4857 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07004858 else
4859 {
4860 pResult->AgingCount--;
4861 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004862 }
4863 pEntry = tmpEntry;
4864 }
4865 }
4866 csrLLUnlock(&pMac->scan.scanResultList);
4867
4868 return (status);
4869}
4870
4871
4872eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
4873 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
4874{
4875 eHalStatus status = eHAL_STATUS_SUCCESS;
4876 tSirSmeScanReq *pMsg;
4877 tANI_U16 msgLen;
4878 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
4879 tSirScanType scanType = pScanReq->scanType;
4880 tANI_U32 minChnTime; //in units of milliseconds
4881 tANI_U32 maxChnTime; //in units of milliseconds
4882 tANI_U32 i;
4883 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
4884 tANI_U8 *pSelfMac = NULL;
4885
4886 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
4887 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
4888 ( pScanReq->uIEFieldLen ) ;
4889
4890 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
4891 if(HAL_STATUS_SUCCESS(status))
4892 {
4893 do
4894 {
4895 palZeroMemory(pMac->hHdd, pMsg, msgLen);
4896 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
4897 pMsg->length = pal_cpu_to_be16(msgLen);
4898 //ToDO: Fill in session info when we need to do scan base on session.
4899 pMsg->sessionId = 0;
4900 pMsg->transactionId = 0;
4901 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
4902 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
4903
4904 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
4905 {
4906 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
4907 }
4908 else
4909 {
4910 // Since we don't have session for the scanning, we find a valid session. In case we fail to
4911 // do so, get the WNI_CFG_STA_ID
4912 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
4913 {
4914 if( CSR_IS_SESSION_VALID( pMac, i ) )
4915 {
4916 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
4917 break;
4918 }
4919 }
4920 if( CSR_ROAM_SESSION_MAX == i )
4921 {
4922 tANI_U32 len = WNI_CFG_BSSID_LEN;
4923 pSelfMac = selfMacAddr;
4924 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
4925 if( !HAL_STATUS_SUCCESS( status ) ||
4926 ( len < WNI_CFG_BSSID_LEN ) )
4927 {
4928 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
4929 //Force failed status
4930 status = eHAL_STATUS_FAILURE;
4931 break;
4932 }
4933 }
4934 }
4935 palCopyMemory( pMac->hHdd, (tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr) );
4936
4937 //sirCopyMacAddr
4938 palCopyMemory( pMac->hHdd, (tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr) );
4939 if( palEqualMemory( pMac->hHdd, pScanReq->bssid, bssid, sizeof(tCsrBssid) ) )
4940 {
4941 palFillMemory( pMac->hHdd, pMsg->bssId, sizeof(tSirMacAddr), 0xff );
4942 }
4943 else
4944 {
4945 palCopyMemory(pMac->hHdd, pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
4946 }
4947 minChnTime = pScanReq->minChnTime;
4948 maxChnTime = pScanReq->maxChnTime;
4949
4950 //Verify the scan type first, if the scan is active scan, we need to make sure we
4951 //are allowed to do so.
4952 /* if 11d is enabled & we don't see any beacon around, scan type falls
4953 back to passive. But in BT AMP STA mode we need to send out a
4954 directed probe*/
4955 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
4956 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
4957 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
4958 {
4959 scanType = pMac->scan.curScanType;
4960 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
4961 {
4962 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
4963 {
4964 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
4965 }
4966 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
4967 {
4968 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
4969 }
4970 }
4971 }
4972 pMsg->scanType = pal_cpu_to_be32(scanType);
4973
4974 pMsg->numSsid = (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ? pScanReq->SSIDs.numOfSSIDs :
4975 SIR_SCAN_MAX_NUM_SSID;
4976 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
4977 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07004978 for (i = 0; i < pMsg->numSsid; i++)
4979 {
4980 palCopyMemory(pMac->hHdd, &pMsg->ssId[i], &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
4981 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004982 }
4983 else
4984 {
4985 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07004986 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
4987 {
4988 pMsg->ssId[i].length = 0;
4989 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004990 }
4991
Jeff Johnson295189b2012-06-20 16:38:30 -07004992 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
4993 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08004994 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
4995 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07004996 //hidden SSID option
4997 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
4998 //rest time
4999 //pMsg->restTime = pScanReq->restTime;
5000 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5001 // All the scan results caching will be done by Roaming
5002 // We do not want LIM to do any caching of scan results,
5003 // so delete the LIM cache on all scan requests
5004 pMsg->returnFreshResults = pScanReqParam->freshScan;
5005 //Always ask for unique result
5006 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5007 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
5008 if(pScanReq->ChannelInfo.numOfChannels)
5009 {
5010 //Assuming the channelNumber is tANI_U8 (1 byte)
5011 status = palCopyMemory(pMac->hHdd, pMsg->channelList.channelNumber, pScanReq->ChannelInfo.ChannelList,
5012 pScanReq->ChannelInfo.numOfChannels);
5013 }
5014
5015 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
5016 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5017 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
5018 if(pScanReq->uIEFieldLen != 0)
5019 {
5020 palCopyMemory(pMac->hHdd, (tANI_U8 *)pMsg+pMsg->uIEFieldOffset,
5021 pScanReq->pIEField, pScanReq->uIEFieldLen );
5022 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005023 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005024
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07005025 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
5026 {
5027 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
5028 }
5029
Jeff Johnson295189b2012-06-20 16:38:30 -07005030 }while(0);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005031 smsLog(pMac, LOG1, FL("domainIdCurrent %d scanType %d bssType %d requestType %d numChannels %d "),
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005032 pMac->scan.domainIdCurrent, pMsg->scanType, pMsg->bssType,
5033 pScanReq->requestType, pMsg->channelList.numChannels);
5034
5035 for(i = 0; i < pMsg->channelList.numChannels; i++)
5036 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005037 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005038 }
5039
Jeff Johnson295189b2012-06-20 16:38:30 -07005040 if(HAL_STATUS_SUCCESS(status))
5041 {
5042 status = palSendMBMessage(pMac->hHdd, pMsg);
5043 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005044 else
5045 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005046 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005047 palFreeMemory(pMac->hHdd, pMsg);
5048 }
5049 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005050 else
5051 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005052 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005053 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005054
5055 return( status );
5056}
5057
5058eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tScanReqParam *pScanReqParam )
5059{
5060 eHalStatus status = eHAL_STATUS_SUCCESS;
5061 tSirSmeScanReq *pMsg;
5062 tANI_U16 msgLen;
5063
5064 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
5065 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
5066 if(HAL_STATUS_SUCCESS(status))
5067 {
5068 palZeroMemory(pMac->hHdd, pMsg, msgLen);
5069 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5070 pMsg->length = pal_cpu_to_be16(msgLen);
5071 pMsg->sessionId = 0;
5072 pMsg->returnFreshResults = pScanReqParam->freshScan;
5073 //Always ask for unique result
5074 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5075 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5076 status = palSendMBMessage(pMac->hHdd, pMsg);
5077 }
5078
5079 return( status );
5080}
5081
5082
5083
5084eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5085{
5086 eHalStatus status = eHAL_STATUS_FAILURE;
5087 tScanReqParam scanReq;
5088
5089 do
5090 {
5091 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
5092 scanReq.fUniqueResult = TRUE;
5093 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
5094 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
5095 {
5096 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
5097 }
5098 else
5099 {
5100 // Basically do scan on all channels even for 11D 1st scan case.
5101 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5102 }
5103 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
5104 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
5105 {
5106 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
5107 }
5108
5109#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5110 {
5111 vos_log_scan_pkt_type *pScanLog = NULL;
5112
5113 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5114 if(pScanLog)
5115 {
5116 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5117 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
5118 {
5119 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
5120 }
5121 else
5122 {
5123 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
5124 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
5125 {
5126 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
5127 }
5128 else
5129 {
5130 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
5131 }
5132 }
5133 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
5134 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
5135 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5136 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
5137 {
5138 palCopyMemory(pMac->hHdd, pScanLog->channels,
5139 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5140 pScanLog->numChannel);
5141 }
5142 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5143 }
5144 }
5145#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5146
5147
5148 status = csrSendMBScanReq(pMac, pCommand->sessionId,
5149 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
5150 }while(0);
5151
5152 return( status );
5153}
5154
5155
5156eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac)
5157{
5158 eHalStatus status = eHAL_STATUS_FAILURE;
5159 tScanReqParam scanReq;
5160
5161 do
5162 {
5163 //not a fresh scan
5164 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
5165 scanReq.fUniqueResult = TRUE;
5166 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5167 status = csrSendMBScanResultReq(pMac, &scanReq);
5168 }while(0);
5169
5170 return (status);
5171}
5172
5173
5174
5175eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5176{
5177 eHalStatus status = eHAL_STATUS_SUCCESS;
5178 tCsrChannelInfo newChannelInfo = {0, NULL};
5179 int i, j;
5180 tANI_U8 *pChannel = NULL;
5181 tANI_U32 len = 0;
5182
5183 // Transition to Scanning state...
5184 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5185 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005186 pCommand->u.scanCmd.lastRoamState[i] = csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005187 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 -07005188 }
5189
5190 switch(pCommand->u.scanCmd.reason)
5191 {
5192 case eCsrScanGetResult:
5193 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
5194 status = csrScanRetrieveResult(pMac);
5195 break;
5196 case eCsrScanSetBGScanParam:
5197 status = csrProcessSetBGScanParam(pMac, pCommand);
5198 break;
5199 case eCsrScanBGScanAbort:
5200 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
5201 break;
5202 case eCsrScanBGScanEnable:
5203 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
5204 break;
5205 case eCsrScanGetScanChnInfo:
5206 status = csrScanGetScanChannelInfo(pMac);
5207 break;
5208 case eCsrScanUserRequest:
5209 if(pMac->roam.configParam.fScanTwice)
5210 {
5211 //We scan 2.4 channel twice
5212 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
5213 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
5214 {
5215 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5216 //allocate twice the channel
5217 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(newChannelInfo.numOfChannels * 2);
5218 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5219 }
5220 else
5221 {
5222 //get the valid channel list to scan all.
5223 len = sizeof(pMac->roam.validChannelList);
5224
5225 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5226 {
5227 //allocate twice the channel
5228 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
5229 pChannel = pMac->roam.validChannelList;
5230 }
5231 }
5232 if(NULL == newChannelInfo.ChannelList)
5233 {
5234 newChannelInfo.numOfChannels = 0;
5235 }
5236 else
5237 {
5238 j = 0;
5239 for(i = 0; i < len; i++)
5240 {
5241 newChannelInfo.ChannelList[j++] = pChannel[i];
5242 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
5243 {
5244 newChannelInfo.ChannelList[j++] = pChannel[i];
5245 }
5246 }
5247 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5248 {
5249 //pChannel points to the channellist from the command, free it.
5250 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
5251 }
5252 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
5253 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
5254 }
5255 } //if(pMac->roam.configParam.fScanTwice)
5256
5257 status = csrScanChannels(pMac, pCommand);
5258
5259 break;
5260 default:
5261 status = csrScanChannels(pMac, pCommand);
5262 break;
5263 }
5264
5265 if(!HAL_STATUS_SUCCESS(status))
5266 {
5267 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
5268 }
5269
5270 return (status);
5271}
5272
5273
5274eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
5275{
5276 eHalStatus status = eHAL_STATUS_SUCCESS;
5277 tSmeCmd *pCommand = NULL;
5278
5279 if(pScanReq)
5280 {
5281 do
5282 {
5283 pCommand = csrGetCommandBuffer(pMac);
5284 if(!pCommand)
5285 {
5286 status = eHAL_STATUS_RESOURCES;
5287 break;
5288 }
5289 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
5290 pCommand->command = eSmeCommandScan;
5291 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
5292 pCommand->u.scanCmd.callback = NULL;
5293 pCommand->u.scanCmd.pContext = NULL;
5294 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
5295 //we have to do the follow
5296 if(pScanReq->ChannelInfo.numOfChannels == 0)
5297 {
5298 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
5299 }
5300 else
5301 {
5302 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5303 pScanReq->ChannelInfo.numOfChannels);
5304 if(HAL_STATUS_SUCCESS(status))
5305 {
5306 palCopyMemory(pMac->hHdd, pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5307 pScanReq->ChannelInfo.ChannelList, pScanReq->ChannelInfo.numOfChannels);
5308 }
5309 else
5310 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005311 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005312 csrReleaseCommandScan(pMac, pCommand);
5313 break;
5314 }
5315 }
5316
5317 //scan req for SSID
5318 if(pScanReq->SSID.length)
5319 {
5320 palCopyMemory(pMac->hHdd,
5321 pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
5322 pScanReq->SSID.ssId,
5323 pScanReq->SSID.length);
5324 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
5325
5326 }
5327 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
5328 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
5329 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
5330
5331
5332 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5333 if( !HAL_STATUS_SUCCESS( status ) )
5334 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005335 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005336 csrReleaseCommandScan( pMac, pCommand );
5337 break;
5338 }
5339 }while(0);
5340 }
5341
5342 return (status);
5343}
5344
5345eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
5346{
5347 eHalStatus status = eHAL_STATUS_SUCCESS;
5348 tSmeCmd *pCommand = NULL;
5349
5350 do
5351 {
5352 pCommand = csrGetCommandBuffer(pMac);
5353 if(!pCommand)
5354 {
5355 status = eHAL_STATUS_RESOURCES;
5356 break;
5357 }
5358 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
5359 pCommand->command = eSmeCommandScan;
5360 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
5361 pCommand->u.scanCmd.callback = NULL;
5362 pCommand->u.scanCmd.pContext = NULL;
5363 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5364 if( !HAL_STATUS_SUCCESS( status ) )
5365 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005366 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005367 csrReleaseCommandScan( pMac, pCommand );
5368 break;
5369 }
5370 }while(0);
5371
5372 return (status);
5373}
5374
5375
5376//This will enable the background scan with the non-zero interval
5377eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
5378{
5379 eHalStatus status = eHAL_STATUS_SUCCESS;
5380 tSmeCmd *pCommand = NULL;
5381
5382 if(pMac->roam.configParam.bgScanInterval)
5383 {
5384 do
5385 {
5386 pCommand = csrGetCommandBuffer(pMac);
5387 if(!pCommand)
5388 {
5389 status = eHAL_STATUS_RESOURCES;
5390 break;
5391 }
5392 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
5393 pCommand->command = eSmeCommandScan;
5394 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
5395 pCommand->u.scanCmd.callback = NULL;
5396 pCommand->u.scanCmd.pContext = NULL;
5397 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5398 if( !HAL_STATUS_SUCCESS( status ) )
5399 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005400 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005401 csrReleaseCommandScan( pMac, pCommand );
5402 break;
5403 }
5404 }while(0);
5405 //BG scan results are reported automatically by PE to SME once the scan is done.
5406 //No need to fetch the results explicitly.
5407 //csrScanStartGetResultTimer(pMac);
5408 csrScanStartResultAgingTimer(pMac);
5409 }
5410 else
5411 {
5412 //We don't have BG scan so stop the aging timer
5413 csrScanStopResultAgingTimer(pMac);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005414 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005415 status = eHAL_STATUS_INVALID_PARAMETER;
5416 }
5417
5418 return (status);
5419}
5420
5421
5422eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
5423{
5424 eHalStatus status = eHAL_STATUS_SUCCESS;
5425 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5426 tANI_U32 index = 0;
5427 tANI_U32 new_index = 0;
5428
5429 do
5430 {
5431 status = csrScanFreeRequest(pMac, pDstReq);
5432 if(HAL_STATUS_SUCCESS(status))
5433 {
5434 status = palCopyMemory(pMac->hHdd, pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08005435 /* Re-initialize the pointers to NULL since we did a copy */
5436 pDstReq->pIEField = NULL;
5437 pDstReq->ChannelInfo.ChannelList = NULL;
5438 pDstReq->SSIDs.SSIDList = NULL;
5439
Jeff Johnson295189b2012-06-20 16:38:30 -07005440 if(pSrcReq->uIEFieldLen == 0)
5441 {
5442 pDstReq->pIEField = NULL;
5443 }
5444 else
5445 {
5446 status = palAllocateMemory(pMac->hHdd, (void **)&pDstReq->pIEField, pSrcReq->uIEFieldLen);
5447 if(HAL_STATUS_SUCCESS(status))
5448 {
5449 palCopyMemory(pMac->hHdd, pDstReq->pIEField, pSrcReq->pIEField, pSrcReq->uIEFieldLen);
5450 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
5451 }
5452 else
5453 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005454 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnson295189b2012-06-20 16:38:30 -07005455 break;
5456 }
5457 }//Allocate memory for IE field
5458 {
5459 if(pSrcReq->ChannelInfo.numOfChannels == 0)
5460 {
5461 pDstReq->ChannelInfo.ChannelList = NULL;
5462 pDstReq->ChannelInfo.numOfChannels = 0;
5463 }
5464 else
5465 {
5466 status = palAllocateMemory(pMac->hHdd, (void **)&pDstReq->ChannelInfo.ChannelList,
5467 pSrcReq->ChannelInfo.numOfChannels * sizeof(*pDstReq->ChannelInfo.ChannelList));
5468 if(!HAL_STATUS_SUCCESS(status))
5469 {
5470 pDstReq->ChannelInfo.numOfChannels = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005471 smsLog(pMac, LOGE, "No memory for scanning Channel List");
Jeff Johnson295189b2012-06-20 16:38:30 -07005472 break;
5473 }
5474
5475 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
5476 {
5477 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5478 {
5479 pDstReq->ChannelInfo.ChannelList[new_index] =
5480 pSrcReq->ChannelInfo.ChannelList[index];
5481 new_index++;
5482 }
5483 pDstReq->ChannelInfo.numOfChannels = new_index;
5484 }
5485 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
5486 {
5487 new_index = 0;
5488 pMac->roam.numValidChannels = len;
5489 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5490 {
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005491 /* Allow scan on valid channels only.
5492 * If it is p2p scan and valid channel list doesnt contain
5493 * social channels, enforce scan on social channels because
5494 * that is the only way to find p2p peers.
5495 * This can happen only if band is set to 5Ghz mode.
5496 */
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005497 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index])) ||
5498 ((eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType) &&
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005499 CSR_IS_SOCIAL_CHANNEL(pSrcReq->ChannelInfo.ChannelList[index])))
Jeff Johnson295189b2012-06-20 16:38:30 -07005500 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08005501 if( (pSrcReq->skipDfsChnlInP2pSearch &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005502 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08005503#ifdef FEATURE_WLAN_LFR
5504 /*
5505 * If LFR is requesting a contiguous scan
5506 * (i.e. numOfChannels > 1), then ignore
5507 * DFS channels.
5508 * TODO: vos_nv_getChannelEnabledState is returning
5509 * 120, 124 and 128 as non-DFS channels. Hence, the
5510 * use of direct check for channels below.
5511 */
5512 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
5513 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Srinivas Girigowdade697412013-02-14 16:31:48 -08005514 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])))
Srikant Kuppa866893f2012-12-27 17:28:14 -08005515#endif
5516 )
5517 {
5518#ifdef FEATURE_WLAN_LFR
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005519 smsLog(pMac, LOG2,
Srikant Kuppa866893f2012-12-27 17:28:14 -08005520 "%s: reqType=%d, numOfChannels=%d,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005521 " ignoring DFS channel %d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005522 __func__, pSrcReq->requestType,
5523 pSrcReq->ChannelInfo.numOfChannels,
5524 pSrcReq->ChannelInfo.ChannelList[index]);
5525#endif
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005526 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08005527 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005528
Jeff Johnson295189b2012-06-20 16:38:30 -07005529 pDstReq->ChannelInfo.ChannelList[new_index] =
5530 pSrcReq->ChannelInfo.ChannelList[index];
5531 new_index++;
5532 }
5533 }
5534 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08005535#ifdef FEATURE_WLAN_LFR
5536 if ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
5537 (0 == pDstReq->ChannelInfo.numOfChannels))
5538 {
5539 /*
5540 * No valid channels found in the request.
5541 * Only perform scan on the channels passed
5542 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN.
5543 * Passing 0 to LIM will trigger a scan on
5544 * all valid channels which is not desirable.
5545 */
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005546 smsLog(pMac, LOGE, "%s: no valid channels found (request=%d)",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005547 __func__, pSrcReq->requestType);
5548 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5549 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005550 smsLog(pMac, LOGE, "pSrcReq index=%d channel=%d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005551 index, pSrcReq->ChannelInfo.ChannelList[index]);
5552 }
5553 status = eHAL_STATUS_FAILURE;
5554 break;
5555 }
5556#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005557 }
5558 else
5559 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005560 smsLog(pMac, LOGE, "Couldn't get the valid Channel List, keeping requester's list");
Jeff Johnson295189b2012-06-20 16:38:30 -07005561 palCopyMemory(pMac->hHdd, pDstReq->ChannelInfo.ChannelList, pSrcReq->ChannelInfo.ChannelList,
5562 pSrcReq->ChannelInfo.numOfChannels * sizeof(*pDstReq->ChannelInfo.ChannelList));
5563 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
5564 }
5565 }//Allocate memory for Channel List
5566 }
5567 if(pSrcReq->SSIDs.numOfSSIDs == 0)
5568 {
5569 pDstReq->SSIDs.numOfSSIDs = 0;
5570 pDstReq->SSIDs.SSIDList = NULL;
5571 }
5572 else
5573 {
5574 status = palAllocateMemory(pMac->hHdd, (void **)&pDstReq->SSIDs.SSIDList,
5575 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
5576 if(HAL_STATUS_SUCCESS(status))
5577 {
5578 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
5579 palCopyMemory(pMac->hHdd, pDstReq->SSIDs.SSIDList, pSrcReq->SSIDs.SSIDList,
5580 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
5581 }
5582 else
5583 {
5584 pDstReq->SSIDs.numOfSSIDs = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005585 smsLog(pMac, LOGE, "No memory for scanning SSID List");
Jeff Johnson295189b2012-06-20 16:38:30 -07005586 break;
5587 }
5588 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07005589 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07005590 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005591
5592 }
5593 }while(0);
5594
5595 if(!HAL_STATUS_SUCCESS(status))
5596 {
5597 csrScanFreeRequest(pMac, pDstReq);
5598 }
5599
5600 return (status);
5601}
5602
5603
5604eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
5605{
5606 eHalStatus status = eHAL_STATUS_SUCCESS;
5607
5608 if(pReq->ChannelInfo.ChannelList)
5609 {
5610 status = palFreeMemory(pMac->hHdd, pReq->ChannelInfo.ChannelList);
5611 pReq->ChannelInfo.ChannelList = NULL;
5612 }
5613 pReq->ChannelInfo.numOfChannels = 0;
5614 if(pReq->pIEField)
5615 {
5616 status = palFreeMemory(pMac->hHdd, pReq->pIEField);
5617 pReq->pIEField = NULL;
5618 }
5619 pReq->uIEFieldLen = 0;
5620 if(pReq->SSIDs.SSIDList)
5621 {
5622 palFreeMemory(pMac->hHdd, pReq->SSIDs.SSIDList);
5623 pReq->SSIDs.SSIDList = NULL;
5624 }
5625 pReq->SSIDs.numOfSSIDs = 0;
5626
5627 return (status);
5628}
5629
5630
5631void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
5632{
5633 if(pCommand->u.scanCmd.callback)
5634 {
5635// sme_ReleaseGlobalLock( &pMac->sme );
5636 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
5637// sme_AcquireGlobalLock( &pMac->sme );
5638 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005639 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005640 }
5641}
5642
5643
5644void csrScanStopTimers(tpAniSirGlobal pMac)
5645{
5646 csrScanStopResultAgingTimer(pMac);
5647 csrScanStopIdleScanTimer(pMac);
5648 csrScanStopGetResultTimer(pMac);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005649 if(0 != pMac->scan.scanResultCfgAgingTime )
5650 {
5651 csrScanStopResultCfgAgingTimer(pMac);
5652 }
5653
Jeff Johnson295189b2012-06-20 16:38:30 -07005654}
5655
5656
5657eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
5658{
5659 eHalStatus status;
5660
5661 if(pMac->scan.fScanEnable)
5662 {
5663 status = palTimerStart(pMac->hHdd, pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL, eANI_BOOLEAN_TRUE);
5664 }
5665 else
5666 {
5667 status = eHAL_STATUS_FAILURE;
5668 }
5669
5670 return (status);
5671}
5672
5673
5674eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
5675{
5676 return (palTimerStop(pMac->hHdd, pMac->scan.hTimerGetResult));
5677}
5678
5679
5680void csrScanGetResultTimerHandler(void *pv)
5681{
5682 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
5683
5684 csrScanRequestResult(pMac);
5685}
5686
5687#ifdef WLAN_AP_STA_CONCURRENCY
5688static void csrStaApConcTimerHandler(void *pv)
5689{
5690 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
5691 tListElem *pEntry;
5692 tSmeCmd *pScanCmd;
5693
5694 csrLLLock(&pMac->scan.scanCmdPendingList);
5695
5696 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
5697 {
5698 tCsrScanRequest scanReq;
5699 tSmeCmd *pSendScanCmd = NULL;
5700 tANI_U8 numChn = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08005701 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07005702 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
5703 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
5704 eHalStatus status;
5705
Jeff Johnson295189b2012-06-20 16:38:30 -07005706 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5707 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005708
5709 /* if any session is connected and the number of channels to scan is
5710 * greater than 1 then split the scan into multiple scan operations
5711 * on each individual channel else continue to perform scan on all
5712 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005713
5714 /* split scan if number of channels to scan is greater than 1 and
5715 * any one of the following:
5716 * - STA session is connected and the scan is not a P2P search
5717 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08005718 * Do not split scans if no concurrent infra connections are
5719 * active and if the scan is a BG scan triggered by LFR (OR)
5720 * any scan if LFR is in the middle of a BG scan. Splitting
5721 * the scan is delaying the time it takes for LFR to find
5722 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005723 */
Vinay Malekal05fdc812012-12-17 13:04:30 -08005724 if ( (numChn > pMac->roam.configParam.nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005725 ((csrIsStaSessionConnected(pMac) &&
5726#ifdef FEATURE_WLAN_LFR
5727 (csrIsConcurrentInfraConnected(pMac) ||
5728 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
5729 (pMac->roam.neighborRoamInfo.neighborRoamState !=
5730 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5731#endif
5732 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005733 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07005734 {
5735 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
5736
5737 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
5738 if (!pSendScanCmd)
5739 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005740 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07005741 csrLLUnlock(&pMac->scan.scanCmdPendingList);
5742 return;
5743 }
5744 pSendScanCmd->command = pScanCmd->command;
5745 pSendScanCmd->sessionId = pScanCmd->sessionId;
5746 pSendScanCmd->u.scanCmd.callback = NULL;
5747 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
5748 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
5749 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
5750
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07005751 /* First copy all the parameters to local variable of scan request */
5752 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
5753
5754 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08005755 if(scanReq.ChannelInfo.ChannelList != NULL)
5756 {
5757 palFreeMemory(pMac->hHdd,scanReq.ChannelInfo.ChannelList);
5758 scanReq.ChannelInfo.ChannelList = NULL;
5759 }
5760
Vinay Malekal05fdc812012-12-17 13:04:30 -08005761 pChnInfo->numOfChannels = pMac->roam.configParam.nNumChanCombinedConc;
5762 palCopyMemory(pMac->hHdd, &channelToScan[0], &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
5763 pChnInfo->numOfChannels * sizeof(tANI_U8)); //just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07005764 pChnInfo->ChannelList = &channelToScan[0];
5765
Vinay Malekal05fdc812012-12-17 13:04:30 -08005766 for (i = 0, j = pMac->roam.configParam.nNumChanCombinedConc; i < (numChn-pMac->roam.configParam.nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07005767 {
5768 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08005769 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07005770 }
5771
Vinay Malekal05fdc812012-12-17 13:04:30 -08005772 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - pMac->roam.configParam.nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07005773
5774 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
5775 //Modify callers parameters in case of concurrency
5776 scanReq.scanType = eSIR_ACTIVE_SCAN;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07005777 //Use concurrency values for min/maxChnTime.
5778 //We know csrIsAnySessionConnected(pMac) returns TRUE here
5779 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005780
5781 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
5782 if(!HAL_STATUS_SUCCESS(status))
5783 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005784 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005785 csrLLUnlock(&pMac->scan.scanCmdPendingList);
5786 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08005787 }
5788 /* Clean the local scan variable */
5789 scanReq.ChannelInfo.ChannelList = NULL;
5790 scanReq.ChannelInfo.numOfChannels = 0;
5791 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005792 }
5793 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005794 {
5795 /* no active connected session present or numChn == 1
5796 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07005797 pSendScanCmd = pScanCmd;
5798 //remove this command from pending list
5799 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
5800 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005801 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005802 }
5803
5804 }
5805 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
5806
5807 }
5808
Jeff Johnson295189b2012-06-20 16:38:30 -07005809 csrLLUnlock(&pMac->scan.scanCmdPendingList);
5810
5811}
5812#endif
5813
5814eHalStatus csrScanStartResultAgingTimer(tpAniSirGlobal pMac)
5815{
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005816 eHalStatus status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005817
5818 if(pMac->scan.fScanEnable)
5819 {
5820 status = palTimerStart(pMac->hHdd, pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL, eANI_BOOLEAN_TRUE);
5821 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005822 return (status);
5823}
5824
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005825eHalStatus csrScanStartResultCfgAgingTimer(tpAniSirGlobal pMac)
5826{
5827 eHalStatus status = eHAL_STATUS_FAILURE;
5828
5829 if(pMac->scan.fScanEnable)
5830 {
5831 status = palTimerStart(pMac->hHdd, pMac->scan.hTimerResultCfgAging,
5832 CSR_SCAN_RESULT_CFG_AGING_INTERVAL, eANI_BOOLEAN_TRUE);
5833 }
5834 return (status);
5835}
Jeff Johnson295189b2012-06-20 16:38:30 -07005836
5837eHalStatus csrScanStopResultAgingTimer(tpAniSirGlobal pMac)
5838{
5839 return (palTimerStop(pMac->hHdd, pMac->scan.hTimerResultAging));
5840}
5841
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005842eHalStatus csrScanStopResultCfgAgingTimer(tpAniSirGlobal pMac)
5843{
5844 return (palTimerStop(pMac->hHdd, pMac->scan.hTimerResultCfgAging));
5845}
Jeff Johnson295189b2012-06-20 16:38:30 -07005846
5847//This function returns the maximum time a BSS is allowed in the scan result.
5848//The time varies base on connection and power saving factors.
5849//Not connected, No PS
5850//Not connected, with PS
5851//Connected w/o traffic, No PS
5852//Connected w/o traffic, with PS
5853//Connected w/ traffic, no PS -- Not supported
5854//Connected w/ traffic, with PS -- Not supported
5855//the return unit is in seconds.
5856tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
5857{
5858 tANI_U32 nRet;
5859
5860 if(pMac->scan.nAgingCountDown)
5861 {
5862 //Calculate what should be the timeout value for this
5863 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
5864 pMac->scan.nAgingCountDown--;
5865 }
5866 else
5867 {
5868 if( csrIsAllSessionDisconnected( pMac ) )
5869 {
5870 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
5871 {
5872 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
5873 }
5874 else
5875 {
5876 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
5877 }
5878 }
5879 else
5880 {
5881 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
5882 {
5883 nRet = pMac->roam.configParam.scanAgeTimeCPS;
5884 }
5885 else
5886 {
5887 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
5888 }
5889 }
5890 //If state-change causing aging time out change, we want to delay it somewhat to avoid
5891 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
5892 if(pMac->scan.nLastAgeTimeOut > nRet)
5893 {
5894 if(nRet)
5895 {
5896 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
5897 }
5898 pMac->scan.nLastAgeTimeOut = nRet;
5899 nRet *= pMac->scan.nAgingCountDown;
5900 }
5901 else
5902 {
5903 pMac->scan.nLastAgeTimeOut = nRet;
5904 }
5905 }
5906
5907 return (nRet);
5908}
5909
5910
5911void csrScanResultAgingTimerHandler(void *pv)
5912{
5913 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
5914 tANI_BOOLEAN fDisconnected = csrIsAllSessionDisconnected(pMac);
5915
5916 //no scan, no aging
5917 if(pMac->scan.fScanEnable &&
5918 (((eANI_BOOLEAN_FALSE == fDisconnected) && pMac->roam.configParam.bgScanInterval)
5919 || (fDisconnected && (pMac->scan.fCancelIdleScan == eANI_BOOLEAN_FALSE)))
5920 )
5921 {
5922 tListElem *pEntry, *tmpEntry;
5923 tCsrScanResult *pResult;
5924 tANI_TIMESTAMP ageOutTime = (tANI_TIMESTAMP)(csrScanGetAgeOutTime(pMac) * PAL_TICKS_PER_SECOND); //turn it into 10ms units
5925 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
5926
5927 csrLLLock(&pMac->scan.scanResultList);
5928 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5929 while( pEntry )
5930 {
5931 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5932 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5933 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
5934 {
5935 smsLog(pMac, LOGW, " age out due to time out");
5936 csrScanAgeOutBss(pMac, pResult);
5937 }
5938 pEntry = tmpEntry;
5939 }
5940 csrLLUnlock(&pMac->scan.scanResultList);
5941 }
5942}
5943
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005944static void csrScanResultCfgAgingTimerHandler(void *pv)
5945{
5946 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
5947 tListElem *pEntry, *tmpEntry;
5948 tCsrScanResult *pResult;
5949 tANI_TIMESTAMP ageOutTime = pMac->scan.scanResultCfgAgingTime * PAL_TICKS_PER_SECOND;
5950 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
5951
5952 csrLLLock(&pMac->scan.scanResultList);
5953 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5954 while( pEntry )
5955 {
5956 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5957 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5958 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
5959 {
5960 smsLog(pMac, LOGW, " age out due to time out");
5961 csrScanAgeOutBss(pMac, pResult);
5962 }
5963 pEntry = tmpEntry;
5964 }
5965 csrLLUnlock(&pMac->scan.scanResultList);
5966}
Jeff Johnson295189b2012-06-20 16:38:30 -07005967
5968eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
5969{
5970 eHalStatus status;
5971
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005972 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07005973 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
5974 {
5975 pMac->scan.nIdleScanTimeGap += interval;
5976 palTimerStop(pMac->hHdd, pMac->scan.hTimerIdleScan);
5977 status = palTimerStart(pMac->hHdd, pMac->scan.hTimerIdleScan, interval, eANI_BOOLEAN_FALSE);
5978 if( !HAL_STATUS_SUCCESS(status) )
5979 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005980 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07005981 //This should not happen but set the flag to restart when ready
5982 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
5983 }
5984 }
5985 else
5986 {
5987 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
5988 {
5989 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
5990 }
5991 status = eHAL_STATUS_FAILURE;
5992 }
5993
5994 return (status);
5995}
5996
5997
5998eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
5999{
6000 return (palTimerStop(pMac->hHdd, pMac->scan.hTimerIdleScan));
6001}
6002
6003
6004//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
6005void csrScanSuspendIMPS( tpAniSirGlobal pMac )
6006{
6007 csrScanCancelIdleScan(pMac);
6008}
6009
6010
6011//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
6012//because IMPS maybe disabled.
6013void csrScanResumeIMPS( tpAniSirGlobal pMac )
6014{
6015 csrScanStartIdleScan( pMac );
6016}
6017
6018
6019void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
6020{
6021 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
6022
6023 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6024 {
6025 if(pMac->roam.configParam.IsIdleScanEnabled)
6026 {
6027 if(HAL_STATUS_SUCCESS(status))
6028 {
6029 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
6030 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006031 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006032 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
6033 }
6034 else
6035 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006036 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006037 //even though we are in timer handle, calling stop timer will make sure the timer
6038 //doesn't get to restart.
6039 csrScanStopIdleScanTimer(pMac);
6040 }
6041 }
6042 else
6043 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006044 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006045 }
6046 }
6047 else
6048 {//we might need another flag to check if CSR needs to request imps at all
6049
6050 tANI_U32 nTime = 0;
6051
6052 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
6053 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
6054 {
6055 csrScanStartIdleScanTimer(pMac, nTime);
6056 }
6057 }
6058 }
6059}
6060
6061
6062//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
6063//idle scan timer interval
6064//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
6065eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
6066{
6067 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6068
6069 //Do not trigger IMPS in case of concurrency
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006070 if (vos_concurrent_sessions_running() && csrIsAnySessionInConnectState(pMac))
6071 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006072 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006073 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006074 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006075
6076 if(pTimeInterval)
6077 {
6078 *pTimeInterval = 0;
6079 }
6080
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006081 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006082 if( smeCommandPending( pMac ) )
6083 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006084 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006085 //Not to enter IMPS because more work to do
6086 if(pTimeInterval)
6087 {
6088 *pTimeInterval = 0;
6089 }
6090 //restart when ready
6091 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6092
6093 return (status);
6094 }
6095
6096 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6097 /*&& pMac->roam.configParam.impsSleepTime*/)
6098 {
6099 //Stop get result timer because idle scan gets scan result out of PE
6100 csrScanStopGetResultTimer(pMac);
6101 if(pTimeInterval)
6102 {
6103 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
6104 }
6105 //pmcRequestImps take a period in millisecond unit.
6106 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
6107 if(!HAL_STATUS_SUCCESS(status))
6108 {
6109 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
6110 {
6111 //Do restart the timer if CSR thinks it cannot do IMPS
6112 if( !csrCheckPSReady( pMac ) )
6113 {
6114 if(pTimeInterval)
6115 {
6116 *pTimeInterval = 0;
6117 }
6118 //Set the restart flag to true because that idle scan
6119 //can be restarted even though the timer will not be running
6120 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6121 }
6122 else
6123 {
6124 //For not now, we do a quicker retry
6125 if(pTimeInterval)
6126 {
6127 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
6128 }
6129 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006130 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006131 }
6132 else
6133 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006134 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006135 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
6136 //the callback will be called in the future. Should not happen though.
6137 status = eHAL_STATUS_SUCCESS;
6138 pMac->scan.nIdleScanTimeGap = 0;
6139 }
6140 }
6141 else
6142 {
6143 //requested so let's reset the value
6144 pMac->scan.nIdleScanTimeGap = 0;
6145 }
6146 }
6147
6148 return (status);
6149}
6150
6151
6152eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
6153{
6154 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6155 tANI_U32 nTime = 0;
6156
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006157 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006158 if(pMac->roam.configParam.IsIdleScanEnabled)
6159 {
6160 //stop bg scan first
6161 csrScanBGScanAbort(pMac);
6162 //Stop get result timer because idle scan gets scan result out of PE
6163 csrScanStopGetResultTimer(pMac);
6164 //Enable aging timer since idle scan is going on
6165 csrScanStartResultAgingTimer(pMac);
6166 }
6167 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
6168 status = csrScanTriggerIdleScan(pMac, &nTime);
6169 if(!HAL_STATUS_SUCCESS(status))
6170 {
6171 csrScanStartIdleScanTimer(pMac, nTime);
6172 }
6173
6174 return (status);
6175}
6176
6177
6178void csrScanCancelIdleScan(tpAniSirGlobal pMac)
6179{
6180 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6181 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006182 if (vos_concurrent_sessions_running()) {
6183 return;
6184 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006185 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07006186 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
6187 //Set the restart flag in case later on it is uncancelled
6188 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6189 csrScanStopIdleScanTimer(pMac);
6190 csrScanRemoveNotRoamingScanCommand(pMac);
6191 }
6192}
6193
6194
6195void csrScanIdleScanTimerHandler(void *pv)
6196{
6197 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6198 eHalStatus status;
6199 tANI_U32 nTime = 0;
6200
6201 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
6202 status = csrScanTriggerIdleScan(pMac, &nTime);
6203 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
6204 {
6205 //Check whether it is time to actually do an idle scan
6206 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
6207 {
6208 pMac->scan.nIdleScanTimeGap = 0;
6209 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
6210 }
6211 else
6212 {
6213 csrScanStartIdleScanTimer(pMac, nTime);
6214 }
6215 }
6216}
6217
6218
6219
6220
6221tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
6222{
6223 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6224 tListElem *pEntry, *pEntryTmp;
6225 tSmeCmd *pCommand;
6226 tDblLinkList localList;
6227
6228 vos_mem_zero(&localList, sizeof(tDblLinkList));
6229 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6230 {
6231 smsLog(pMac, LOGE, FL(" failed to open list"));
6232 return fRet;
6233 }
6234
6235 csrLLLock(&pMac->sme.smeCmdPendingList);
6236 pEntry = csrLLPeekHead(&pMac->sme.smeCmdPendingList, LL_ACCESS_NOLOCK);
6237 while(pEntry)
6238 {
6239 pEntryTmp = csrLLNext(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK);
6240 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6241 if( eSmeCommandScan == pCommand->command )
6242 {
6243 switch( pCommand->u.scanCmd.reason )
6244 {
6245 case eCsrScanIdleScan:
6246 if( csrLLRemoveEntry(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK) )
6247 {
6248 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6249 }
6250 fRet = eANI_BOOLEAN_TRUE;
6251 break;
6252
6253 default:
6254 break;
6255 } //switch
6256 }
6257 pEntry = pEntryTmp;
6258 }
6259
6260 csrLLUnlock(&pMac->sme.smeCmdPendingList);
6261
6262 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6263 {
6264 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6265 csrReleaseCommandScan( pMac, pCommand );
6266 }
6267
6268 csrLLClose(&localList);
6269
6270 return (fRet);
6271}
6272
6273
6274tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
6275{
6276 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6277 tListElem *pEntry, *pEntryTmp;
6278 tSmeCmd *pCommand;
6279 tDblLinkList localList;
6280
6281 vos_mem_zero(&localList, sizeof(tDblLinkList));
6282 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6283 {
6284 smsLog(pMac, LOGE, FL(" failed to open list"));
6285 return fRet;
6286 }
6287
6288 csrLLLock(&pMac->sme.smeCmdPendingList);
6289 pEntry = csrLLPeekHead(&pMac->sme.smeCmdPendingList, LL_ACCESS_NOLOCK);
6290 while(pEntry)
6291 {
6292 pEntryTmp = csrLLNext(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK);
6293 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6294 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
6295 {
6296 switch(pCommand->u.scanCmd.reason)
6297 {
6298 case eCsrScanGetResult:
6299 case eCsrScanSetBGScanParam:
6300 case eCsrScanBGScanAbort:
6301 case eCsrScanBGScanEnable:
6302 case eCsrScanGetScanChnInfo:
6303 break;
6304 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006305 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006306 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006307 //The rest are fresh scan requests
6308 if( csrLLRemoveEntry(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK) )
6309 {
6310 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6311 }
6312 fRet = eANI_BOOLEAN_TRUE;
6313 break;
6314 }
6315 }
6316 pEntry = pEntryTmp;
6317 }
6318
6319 csrLLUnlock(&pMac->sme.smeCmdPendingList);
6320
6321 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6322 {
6323 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6324 if (pCommand->u.scanCmd.callback)
6325 {
6326 /* User scan request is pending,
6327 * send response with status eCSR_SCAN_ABORT*/
6328 pCommand->u.scanCmd.callback(pMac,
6329 pCommand->u.scanCmd.pContext,
6330 pCommand->u.scanCmd.scanID,
6331 eCSR_SCAN_ABORT);
6332 }
6333 csrReleaseCommandScan( pMac, pCommand );
6334 }
6335 csrLLClose(&localList);
6336
6337 return (fRet);
6338}
6339
6340
6341void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6342{
6343 eCsrScanReason reason = pCommand->u.scanCmd.reason;
6344 tANI_U32 i;
6345 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6346 {
Jeff Johnson43971f52012-07-17 12:26:56 -07006347 csrRoamStateChange( pMac, pCommand->u.scanCmd.lastRoamState[i], i);
Jeff Johnson295189b2012-06-20 16:38:30 -07006348 }
6349
6350 csrScanCallCallback(pMac, pCommand, scanStatus);
6351
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006352 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006353 if( csrLLRemoveEntry( &pMac->sme.smeCmdActiveList, &pCommand->Link, LL_ACCESS_LOCK ) )
6354 {
6355 csrReleaseCommandScan( pMac, pCommand );
6356 }
6357 else
6358 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006359 smsLog(pMac, LOGE, " ********csrReleaseScanCommand cannot release command reason %d", pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006360 }
6361}
6362
6363
6364eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6365 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
6366{
6367 eHalStatus status = eHAL_STATUS_SUCCESS;
6368 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6369
Jeff Johnson32d95a32012-09-10 13:15:23 -07006370 if(!pSession)
6371 {
6372 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6373 return eHAL_STATUS_FAILURE;
6374 }
6375
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006376 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006377 csrResetPMKIDCandidateList(pMac, sessionId);
6378 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6379 {
6380 tCsrScanResultFilter *pScanFilter;
6381 tCsrScanResultInfo *pScanResult;
6382 tScanResultHandle hBSSList;
6383 tANI_U32 nItems = *pNumItems;
6384
6385 *pNumItems = 0;
6386 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
6387 if(HAL_STATUS_SUCCESS(status))
6388 {
6389 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
6390 //Here is the profile we need to connect to
6391 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
6392 if(HAL_STATUS_SUCCESS(status))
6393 {
6394 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
6395 if(HAL_STATUS_SUCCESS(status))
6396 {
6397 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
6398 {
6399 //NumPmkidCandidate adds up here
6400 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
6401 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
6402 }
6403 if(pSession->NumPmkidCandidate)
6404 {
6405 *pNumItems = pSession->NumPmkidCandidate;
6406 palCopyMemory(pMac->hHdd, pPmkidList, pSession->PmkidCandidateInfo,
6407 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
6408 }
6409 csrScanResultPurge(pMac, hBSSList);
6410 }//Have scan result
6411 csrFreeScanFilter(pMac, pScanFilter);
6412 }
6413 palFreeMemory(pMac->hHdd, pScanFilter);
6414 }
6415 }
6416
6417 return (status);
6418}
6419
6420
6421
6422#ifdef FEATURE_WLAN_WAPI
6423eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6424 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
6425{
6426 eHalStatus status = eHAL_STATUS_SUCCESS;
6427 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6428
Jeff Johnson32d95a32012-09-10 13:15:23 -07006429 if(!pSession)
6430 {
6431 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6432 return eHAL_STATUS_FAILURE;
6433 }
6434
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006435 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006436 csrResetBKIDCandidateList(pMac, sessionId);
6437 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6438 {
6439 tCsrScanResultFilter *pScanFilter;
6440 tCsrScanResultInfo *pScanResult;
6441 tScanResultHandle hBSSList;
6442 tANI_U32 nItems = *pNumItems;
6443 *pNumItems = 0;
6444 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
6445 if(HAL_STATUS_SUCCESS(status))
6446 {
6447 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
6448 //Here is the profile we need to connect to
6449 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
6450 if(HAL_STATUS_SUCCESS(status))
6451 {
6452 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
6453 if(HAL_STATUS_SUCCESS(status))
6454 {
6455 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
6456 {
6457 //pMac->scan.NumBkidCandidate adds up here
6458 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
6459 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
6460
6461 }
6462 if(pSession->NumBkidCandidate)
6463 {
6464 *pNumItems = pSession->NumBkidCandidate;
6465 palCopyMemory(pMac->hHdd, pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
6466 }
6467 csrScanResultPurge(pMac, hBSSList);
6468 }//Have scan result
6469 }
6470 palFreeMemory(pMac->hHdd, pScanFilter);
6471 }
6472 }
6473
6474 return (status);
6475}
6476#endif /* FEATURE_WLAN_WAPI */
6477
6478
6479
6480//This function is usually used for BSSs that suppresses SSID so the profile
6481//shall have one and only one SSID
6482eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId)
6483{
6484 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
6485 tSmeCmd *pScanCmd = NULL;
6486 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
6487 tANI_U8 index = 0;
6488 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
6489
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006490 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006491 //For WDS, we use the index 0. There must be at least one in there
6492 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
6493 {
6494 numSsid = 1;
6495 }
6496 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
6497 {
6498 do
6499 {
6500 pScanCmd = csrGetCommandBuffer(pMac);
6501 if(!pScanCmd)
6502 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006503 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006504 break;
6505 }
6506 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
6507 status = palAllocateMemory(pMac->hHdd, (void **)&pScanCmd->u.scanCmd.pToRoamProfile, sizeof(tCsrRoamProfile));
6508 if(!HAL_STATUS_SUCCESS(status))
6509 break;
6510 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
6511 if(!HAL_STATUS_SUCCESS(status))
6512 break;
6513 pScanCmd->u.scanCmd.roamId = roamId;
6514 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07006515 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07006516 pScanCmd->u.scanCmd.callback = NULL;
6517 pScanCmd->u.scanCmd.pContext = NULL;
6518 pScanCmd->u.scanCmd.reason = eCsrScanForSsid;
6519 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6520 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest));
6521 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07006522 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07006523 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
6524 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
6525 {
6526 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
6527 }
6528 if(pProfile->pAddIEScan)
6529 {
6530 status = palAllocateMemory(pMac->hHdd,
6531 (void **)&pScanCmd->u.scanCmd.u.scanRequest.pIEField,
6532 pProfile->nAddIEScanLength);
6533 palZeroMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.pIEField, pProfile->nAddIEScanLength);
6534 if(HAL_STATUS_SUCCESS(status))
6535 {
6536 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.pIEField, pProfile->pAddIEScan, pProfile->nAddIEScanLength);
6537 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
6538 }
6539 else
6540 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006541 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07006542 }
6543 } //Allocate memory for IE field
6544 else
6545 {
6546 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
6547 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07006548 /* For one channel be good enpugh time to receive beacon atleast */
6549 if( 1 == pProfile->ChannelInfo.numOfChannels )
6550 {
6551 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
6552 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
6553 }
6554 else
6555 {
6556 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
6557 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
6558 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08006559 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
6560 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07006561 if(pProfile->BSSIDs.numOfBSSIDs == 1)
6562 {
6563 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.bssid, pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
6564 }
6565 else
6566 {
6567 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
6568 }
6569 if(pProfile->ChannelInfo.numOfChannels)
6570 {
6571 status = palAllocateMemory(pMac->hHdd, (void **)&pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList) * pProfile->ChannelInfo.numOfChannels);
6572 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
6573 if(HAL_STATUS_SUCCESS(status))
6574 {
6575 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
6576 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
6577 {
6578 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
6579 {
6580 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
6581 = pProfile->ChannelInfo.ChannelList[index];
6582 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
6583 }
6584 else
6585 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006586 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07006587 }
6588
6589 }
6590 }
6591 else
6592 {
6593 break;
6594 }
6595
6596 }
6597 else
6598 {
6599 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
6600 }
6601 if(pProfile->SSIDs.numOfSSIDs)
6602 {
6603 status = palAllocateMemory(pMac->hHdd, (void **)&pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
6604 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
6605 if(!HAL_STATUS_SUCCESS(status))
6606 {
6607 break;
6608 }
6609 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
6610 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList, pProfile->SSIDs.SSIDList,
6611 sizeof(tCsrSSIDInfo));
6612 }
6613 //Start process the command
6614 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
6615 if( !HAL_STATUS_SUCCESS( status ) )
6616 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006617 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006618 break;
6619 }
6620 }while(0);
6621 if(!HAL_STATUS_SUCCESS(status))
6622 {
6623 if(pScanCmd)
6624 {
6625 csrReleaseCommandScan(pMac, pScanCmd);
6626 //TODO:free the memory that is allocated in this function
6627 }
6628 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
6629 }
6630 }//valid
6631 else
6632 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006633 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07006634 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
6635 }
6636
6637 return (status);
6638}
6639
6640
6641//Issue a scan base on the new capability infomation
6642//This should only happen when the associated AP changes its capability.
6643//After this scan is done, CSR reroams base on the new scan results
6644eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
6645{
6646 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
6647 tSmeCmd *pScanCmd = NULL;
6648
6649 if(pNewCaps)
6650 {
6651 do
6652 {
6653 pScanCmd = csrGetCommandBuffer(pMac);
6654 if(!pScanCmd)
6655 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006656 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006657 status = eHAL_STATUS_RESOURCES;
6658 break;
6659 }
6660 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
6661 status = eHAL_STATUS_SUCCESS;
6662 pScanCmd->u.scanCmd.roamId = 0;
6663 pScanCmd->command = eSmeCommandScan;
6664 pScanCmd->u.scanCmd.callback = NULL;
6665 pScanCmd->u.scanCmd.pContext = NULL;
6666 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
6667 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6668 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
6669 if( !HAL_STATUS_SUCCESS( status ) )
6670 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006671 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006672 break;
6673 }
6674 }while(0);
6675 if(!HAL_STATUS_SUCCESS(status))
6676 {
6677 if(pScanCmd)
6678 {
6679 csrReleaseCommandScan(pMac, pScanCmd);
6680 }
6681 }
6682 }
6683
6684 return (status);
6685}
6686
6687
6688
6689void csrInitBGScanChannelList(tpAniSirGlobal pMac)
6690{
6691 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
6692
6693 palZeroMemory(pMac->hHdd, pMac->scan.bgScanChannelList, len);
6694 pMac->scan.numBGScanChannel = 0;
6695
6696 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6697 {
6698 pMac->roam.numValidChannels = len;
6699 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
6700 palCopyMemory(pMac->hHdd, pMac->scan.bgScanChannelList, pMac->roam.validChannelList, pMac->scan.numBGScanChannel);
6701 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
6702 }
6703}
6704
6705
6706//This function return TRUE if background scan channel list is adjusted.
6707//this function will only shrink the background scan channel list
6708tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
6709 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
6710{
6711 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6712 tANI_U8 i, j, count = *pNumAdjustChannels;
6713
6714 i = 0;
6715 while(i < count)
6716 {
6717 for(j = 0; j < NumChannels; j++)
6718 {
6719 if(pChannelList[j] == pAdjustChannels[i])
6720 break;
6721 }
6722 if(j == NumChannels)
6723 {
6724 //This channel is not in the list, remove it
6725 fRet = eANI_BOOLEAN_TRUE;
6726 count--;
6727 if(count - i)
6728 {
6729 palCopyMemory(pMac->hHdd, &pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
6730 }
6731 else
6732 {
6733 //already remove the last one. Done.
6734 break;
6735 }
6736 }
6737 else
6738 {
6739 i++;
6740 }
6741 }//while(i<count)
6742 *pNumAdjustChannels = count;
6743
6744 return (fRet);
6745}
6746
6747
6748//Get the list of the base channels to scan for passively 11d info
6749eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
6750{
6751 eHalStatus status = eHAL_STATUS_SUCCESS;
6752 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
6753
6754 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
6755 if( HAL_STATUS_SUCCESS(status) )
6756 {
6757 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
6758 }
6759 else
6760 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006761 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006762 pMac->scan.baseChannels.numChannels = 0;
6763 }
6764
6765 return ( status );
6766}
6767
6768//This function use the input pChannelList to validate the current saved channel list
6769eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
6770{
6771 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
6772
6773 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
6774}
6775
6776
6777void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
6778{
6779 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
6780
6781
6782 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
6783
6784 return;
6785}
6786
6787
6788
6789/*
6790 * The Tx power limits are saved in the cfg for future usage.
6791 */
6792void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
6793{
6794 tListElem *pEntry;
6795 tANI_U32 cbLen = 0, dataLen;
6796 tCsrChannelPowerInfo *pChannelSet;
6797 tANI_U32 idx;
6798 tSirMacChanInfo *pChannelPowerSet;
6799 tANI_U8 *pBuf = NULL;
6800
6801 //allocate maximum space for all channels
6802 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
6803 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pBuf, dataLen)))
6804 {
6805 palZeroMemory(pMac->hHdd, pBuf, dataLen);
6806 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
6807
6808 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
6809 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
6810 while( pEntry )
6811 {
6812 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
6813 if ( 1 != pChannelSet->interChannelOffset )
6814 {
6815 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
6816 // to the right format... (inter channel offset of 1 is the only option for the triplets
6817 // that 11d advertises.
6818 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
6819 {
6820 // expanding this entry will overflow our allocation
6821 smsLog(pMac, LOGE,
6822 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006823 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006824 pChannelSet->firstChannel,
6825 pChannelSet->numChannels,
6826 pChannelSet->interChannelOffset);
6827 break;
6828 }
6829
6830 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
6831 {
6832 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006833 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07006834 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07006835 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006836 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07006837 cbLen += sizeof( tSirMacChanInfo );
6838 pChannelPowerSet++;
6839 }
6840 }
6841 else
6842 {
6843 if (cbLen >= dataLen)
6844 {
6845 // this entry will overflow our allocation
6846 smsLog(pMac, LOGE,
6847 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006848 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006849 pChannelSet->firstChannel,
6850 pChannelSet->numChannels,
6851 pChannelSet->interChannelOffset);
6852 break;
6853 }
6854 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006855 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07006856 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07006857 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006858 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07006859
6860
6861 cbLen += sizeof( tSirMacChanInfo );
6862 pChannelPowerSet++;
6863 }
6864
6865 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
6866 }
6867
6868 if(cbLen)
6869 {
6870 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
6871 }
6872 palFreeMemory( pMac->hHdd, pBuf );
6873 }//Allocate memory
6874}
6875
6876
6877void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
6878{
6879 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
6880 ///v_REGDOMAIN_t DomainId;
6881
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006882 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Jeff Johnson295189b2012-06-20 16:38:30 -07006883 palCopyMemory( pMac->hHdd, cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN );
6884
6885 // don't program the bogus country codes that we created for Korea in the MAC. if we see
6886 // the bogus country codes, program the MAC with the right country code.
6887 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
6888 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
6889 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
6890 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
6891 {
6892 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
6893 cc[ 1 ] = 'R';
6894 }
6895 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
6896
6897 //Need to let HALPHY know about the current domain so it can apply some
6898 //domain-specific settings (TX filter...)
6899 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
6900 {
6901 halPhySetRegDomain(pMac, DomainId);
6902 }*/
6903}
6904
6905
6906
6907eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
6908{
6909 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
6910 tANI_U32 len;
6911
6912 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
6913 {
6914 len = *pbLen;
6915 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
6916 if(HAL_STATUS_SUCCESS(status))
6917 {
6918 *pbLen = (tANI_U8)len;
6919 }
6920 }
6921
6922 return (status);
6923}
6924
6925
6926void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
6927{
6928 tANI_U8 i, j;
6929 tANI_BOOLEAN found=FALSE;
6930 tANI_U8 *pControlList = NULL;
6931 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
6932
6933 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN)))
6934 {
6935 palZeroMemory(pMac->hHdd, (void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN);
6936 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
6937 {
6938 for (i = 0; i < pChannelList->numChannels; i++)
6939 {
6940 for (j = 0; j < len; j += 2)
6941 {
6942 if (pControlList[j] == pChannelList->channelList[i])
6943 {
6944 found = TRUE;
6945 break;
6946 }
6947 }
6948
6949 if (found) // insert a pair(channel#, flag)
6950 {
6951 if (CSR_IS_CHANNEL_5GHZ(pControlList[j]))
6952 {
6953 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
6954 }
6955 else
6956 {
6957 pControlList[j+1] = eSIR_ACTIVE_SCAN;
6958 }
6959
6960 found = FALSE; // reset the flag
6961 }
6962
6963 }
6964
6965 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
6966 }//Successfully getting scan control list
6967 palFreeMemory(pMac->hHdd, pControlList);
6968 }//AllocateMemory
6969}
6970
6971
6972//if bgPeriod is 0, background scan is disabled. It is in millisecond units
6973eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
6974{
6975 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
6976}
6977
6978
6979void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
6980{
6981 tListElem *pEntry = NULL;
6982 tSmeCmd *pCommand = NULL;
6983 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
6984
6985 pEntry = csrLLPeekHead( &pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK );
6986 if ( pEntry )
6987 {
6988 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
6989 if ( eSmeCommandScan == pCommand->command )
6990 {
6991 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
6992 csrReleaseScanCommand(pMac, pCommand, scanStatus);
6993 }
6994 else
6995 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006996 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07006997 }
6998 }
6999 smeProcessPendingQueue( pMac );
7000}
7001
7002eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
7003{
7004 eHalStatus status;
7005 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
7006 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
7007
7008 //***setcfg for background scan channel list
7009 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
7010 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
7011 //Not set the background scan interval if not connected because bd scan should not be run if not connected
7012 if(!csrIsAllSessionDisconnected(pMac))
7013 {
7014 //If disbaling BG scan here, we need to stop aging as well
7015 if(pScanReq->scanInterval == 0)
7016 {
7017 //Stop aging because no new result is coming in
7018 csrScanStopResultAgingTimer(pMac);
7019 }
7020
7021#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7022 {
7023 vos_log_scan_pkt_type *pScanLog = NULL;
7024
7025 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
7026 if(pScanLog)
7027 {
7028 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
7029 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
7030 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
7031 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
7032 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
7033 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
7034 {
7035 palCopyMemory(pMac->hHdd, pScanLog->channels, pScanReq->ChannelInfo.ChannelList,
7036 pScanLog->numChannel);
7037 }
7038 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
7039 }
7040 }
7041#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7042
7043 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
7044 }
7045 else
7046 {
7047 //No need to stop aging because IDLE scan is still running
7048 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
7049 }
7050
7051 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
7052 {
7053 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
7054 }
7055
7056 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7057 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
7058
7059
7060
7061 return (status);
7062}
7063
7064
7065eHalStatus csrScanAbortMacScan(tpAniSirGlobal pMac)
7066{
7067 eHalStatus status = eHAL_STATUS_SUCCESS;
7068 tSirMbMsg *pMsg;
7069 tANI_U16 msgLen;
7070 tListElem *pEntry;
7071 tSmeCmd *pCommand;
7072
7073#ifdef WLAN_AP_STA_CONCURRENCY
7074 csrLLLock(&pMac->scan.scanCmdPendingList);
7075 while( NULL != ( pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
7076 {
7077
7078 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7079 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7080 }
7081 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7082#endif
7083
7084 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7085 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
7086 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
7087 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7088
7089 //We need to abort scan only if we are scanning
7090 if(NULL != (pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK)))
7091 {
7092 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7093 if(eSmeCommandScan == pCommand->command)
7094 {
7095 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
7096 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
7097 if(HAL_STATUS_SUCCESS(status))
7098 {
7099 palZeroMemory(pMac->hHdd, (void *)pMsg, msgLen);
7100 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
7101 pMsg->msgLen = pal_cpu_to_be16(msgLen);
7102 status = palSendMBMessage(pMac->hHdd, pMsg);
7103 }
7104 }
7105 }
7106
7107 return( status );
7108}
7109
7110void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
7111 eSmeCommandType commandType )
7112{
7113 tDblLinkList localList;
7114 tListElem *pEntry;
7115 tSmeCmd *pCommand;
7116 tListElem *pEntryToRemove;
7117
7118 vos_mem_zero(&localList, sizeof(tDblLinkList));
7119 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7120 {
7121 smsLog(pMac, LOGE, FL(" failed to open list"));
7122 return;
7123 }
7124
7125 csrLLLock(pList);
7126 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
7127 {
7128 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
7129
7130 // Have to make sure we don't loop back to the head of the list, which will
7131 // happen if the entry is NOT on the list...
7132 while( pEntry )
7133 {
7134 pEntryToRemove = pEntry;
7135 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7136 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7137 if ( pCommand->command == commandType )
7138 {
7139 // Remove that entry only
7140 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7141 {
7142 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
7143 }
7144 }
7145 }
7146
7147
7148 }
7149 csrLLUnlock(pList);
7150
7151 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7152 {
7153 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7154 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7155 }
7156 csrLLClose(&localList);
7157
7158}
7159
7160
7161eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac)
7162{
7163 eHalStatus status = eHAL_STATUS_SUCCESS;
7164
7165 if( !csrIsScanForRoamCommandActive( pMac ) )
7166 {
7167 //Only abort the scan if it is not used for other roam/connect purpose
7168 status = csrScanAbortMacScan(pMac);
7169 }
7170
7171 return (status);
7172}
7173
7174
7175eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac)
7176{
7177 eHalStatus status = eHAL_STATUS_SUCCESS;
7178 tSirMbMsg *pMsg;
7179 tANI_U16 msgLen;
7180
7181 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
7182 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
7183 if(HAL_STATUS_SUCCESS(status))
7184 {
7185 palZeroMemory(pMac->hHdd, pMsg, msgLen);
7186 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
7187 pMsg->msgLen = msgLen;
7188 status = palSendMBMessage(pMac->hHdd, pMsg);
7189 }
7190
7191 return( status );
7192}
7193
7194tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
7195{
7196 tANI_BOOLEAN fValid = FALSE;
7197 tANI_U32 idxValidChannels;
7198 tANI_U32 len = pMac->roam.numValidChannels;
7199
7200 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
7201 {
7202 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
7203 {
7204 fValid = TRUE;
7205 break;
7206 }
7207 }
7208
7209 return fValid;
7210}
7211
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007212#ifdef FEATURE_WLAN_LFR
7213void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
7214{
7215 tListElem *pEntry = NULL;
7216 tCsrScanResult *pBssDesc = NULL;
7217 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08007218 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
7219
7220 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
7221 {
7222 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007223 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08007224 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
7225 return;
7226 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007227
7228 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
7229 {
7230 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007231 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007232 __func__, pMac->scan.occupiedChannels.numChannels);
7233 return;
7234 }
7235
7236 /* Empty occupied channels here */
7237 pMac->scan.occupiedChannels.numChannels = 0;
7238
7239 csrLLLock(&pMac->scan.scanResultList);
7240 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
7241 while( pEntry )
7242 {
7243 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
7244 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
7245
7246 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08007247 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007248 &pBssDesc->Result.BssDescriptor, &pIes))) )
7249 {
7250 continue;
7251 }
7252
7253 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
7254
7255 /*
7256 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
7257 */
7258 if( (pBssDesc->Result.pvIes == NULL) && pIes )
7259 {
7260 palFreeMemory(pMac->hHdd, pIes);
7261 }
7262
7263 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
7264 }//while
7265 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08007266
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007267}
7268#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007269