blob: 914962bf51d39566b6695736e556d2fc472b9162 [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
42/*===========================================================================
43
44 s a p C h S e l e c t . C
45
46 OVERVIEW:
47
48 This software unit holds the implementation of the WLAN SAP modules
49 functions for channel selection.
50
51 DEPENDENCIES:
52
53 Are listed for each API below.
54
55
56 Copyright (c) 2010 QUALCOMM Incorporated.
57 All Rights Reserved.
58 Qualcomm Confidential and Proprietary
59===========================================================================*/
60
61/*===========================================================================
62
63 EDIT HISTORY FOR FILE
64
65
66 This section contains comments describing changes made to the module.
67 Notice that changes are listed in reverse chronological order.
68
69
70
71 when who what, where, why
72---------- --- --------------------------------------------------------
732010-03-15 SOFTAP Created module
74
75===========================================================================*/
76
77
78/*--------------------------------------------------------------------------
79 Include Files
80------------------------------------------------------------------------*/
81#include "vos_trace.h"
82#include "csrApi.h"
83#include "sme_Api.h"
84#include "sapChSelect.h"
85#include "sapInternal.h"
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -080086#ifdef ANI_OS_TYPE_QNX
87#include "stdio.h"
88#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070089
90/*--------------------------------------------------------------------------
91 Function definitions
92--------------------------------------------------------------------------*/
93
94/*--------------------------------------------------------------------------
95 Defines
96--------------------------------------------------------------------------*/
97#define SAP_DEBUG
98
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -070099#define IS_RSSI_VALID( extRssi, rssi ) \
100( \
101 ((extRssi < rssi)?eANI_BOOLEAN_TRUE:eANI_BOOLEAN_FALSE) \
102)
103
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700104/*==========================================================================
105 FUNCTION sapCleanupChannelList
106
107 DESCRIPTION
108 Function sapCleanupChannelList frees up the memory allocated to the channel list.
109
110 DEPENDENCIES
111 NA.
112
113 PARAMETERS
114
115 IN
116 NULL
117
118 RETURN VALUE
119 NULL
120============================================================================*/
121
122void sapCleanupChannelList(void)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700123{
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700124 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_SAP, NULL);
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530125 ptSapContext pSapCtx;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700126
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700127 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO,
128 "Cleaning up the channel list structure");
129
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530130 if (NULL == pvosGCtx)
131 {
132 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
133 "SAP Global Context is NULL");
134 return ;
135 }
136
137 pSapCtx = VOS_GET_SAP_CB(pvosGCtx);
138 if (NULL == pSapCtx)
139 {
140 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
141 "SAP Context is NULL");
142 return ;
143 }
144
145 pSapCtx->SapChnlList.numChannel = 0;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700146 vos_mem_free(pSapCtx->SapChnlList.channelList);
147 pSapCtx->SapChnlList.channelList = NULL;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700148}
149
150/*==========================================================================
151 FUNCTION sapSetPreferredChannel
152
153 DESCRIPTION
154 Function sapSetPreferredChannel sets the channel list which has been configured
155 into sap context (pSapCtx) which will be used at the time of best channel selection.
156
157 DEPENDENCIES
158 NA.
159
160 PARAMETERS
161
162 IN
163 *ptr: pointer having the command followed by the arguments in string format
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700164
165 RETURN VALUE
166 int: return 0 when success else returns error code.
167============================================================================*/
168
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800169int sapSetPreferredChannel(tANI_U8* ptr)
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700170{
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700171
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700172 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_SAP, NULL);
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530173 ptSapContext pSapCtx;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700174 tANI_U8* param;
175 int tempInt;
176 int j;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700177
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700178 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700179 "Enter: %s", __func__);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700180
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530181 if (NULL == pvosGCtx)
182 {
183 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
184 "SAP Global Context is NULL");
185 return -EINVAL;
186 }
187
188 pSapCtx = VOS_GET_SAP_CB(pvosGCtx);
189 if (NULL == pSapCtx)
190 {
191 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
192 "SAP Context is NULL");
193 return -EINVAL;
194 }
195
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700196 if (NULL != pSapCtx->SapChnlList.channelList)
197 {
198 sapCleanupChannelList();
199 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700200
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800201 param = strchr(ptr, ' ');
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700202 /*no argument after the command*/
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800203 if (NULL == param)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700204 {
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800205 return -EINVAL;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700206 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700207
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700208 /*no space after the command*/
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800209 else if (SPACE_ASCII_VALUE != *param)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700210 {
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800211 return -EINVAL;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700212 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700213
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700214 param++;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700215
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700216 /*removing empty spaces*/
217 while((SPACE_ASCII_VALUE == *param)&& ('\0' != *param) ) param++;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700218
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700219 /*no argument followed by spaces*/
220 if('\0' == *param)
221 {
222 return -EINVAL;
223 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700224
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700225 /*getting the first argument ie the number of channels*/
226 sscanf(param, "%d ", &tempInt);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700227
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700228 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530229 "Number of channel added are: %d", tempInt);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700230
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700231 /*allocating space for the desired number of channels*/
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530232 pSapCtx->SapChnlList.channelList = (v_U8_t *)vos_mem_malloc(tempInt);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700233
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530234 if (NULL == pSapCtx->SapChnlList.channelList)
235 {
236 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
237 "In %s, VOS_MALLOC_ERR", __func__);
238 return -EINVAL;
239 }
240
241 pSapCtx->SapChnlList.numChannel = tempInt;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700242 for(j=0;j<pSapCtx->SapChnlList.numChannel;j++)
243 {
244
245 /*param pointing to the beginning of first space after number of channels*/
246 param = strpbrk( param, " " );
247 /*no channel list after the number of channels argument*/
248 if (NULL == param)
249 {
250 sapCleanupChannelList();
251 return -EINVAL;
252 }
253
254 param++;
255
256 /*removing empty space*/
257 while((SPACE_ASCII_VALUE == *param) && ('\0' != *param) ) param++;
258
259 /*no channel list after the number of channels argument and spaces*/
260 if( '\0' == *param )
261 {
262 sapCleanupChannelList();
263 return -EINVAL;
264 }
265
266 sscanf(param, "%d ", &tempInt);
267 pSapCtx->SapChnlList.channelList[j] = tempInt;
268
269 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
270 "Channel %d added to preferred channel list",
271 pSapCtx->SapChnlList.channelList[j] );
272
273 }
274
275 /*extra arguments check*/
276 param = strpbrk( param, " " );
277 if (NULL != param)
278 {
279 while((SPACE_ASCII_VALUE == *param) && ('\0' != *param) ) param++;
280
281 if('\0' != *param)
282 {
283 sapCleanupChannelList();
284 return -EINVAL;
285 }
286 }
287
288 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700289 "Exit: %s", __func__);
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700290
291 return 0;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700292}
293
294/*==========================================================================
295 FUNCTION sapSelectPreferredChannelFromChannelList
296
297 DESCRIPTION
298 Function sapSelectPreferredChannelFromChannelList calculates the best channel
299 among the configured channel list. If channel list not configured then returns
300 the best channel calculated among all the channel list.
301
302 DEPENDENCIES
303 NA.
304
305 PARAMETERS
306
307 IN
308 *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure
309 bestChNum: best channel already calculated among all the chanels
310 pSapCtx: having info of channel list from which best channel is selected
311
312 RETURN VALUE
313 v_U8_t: best channel
314============================================================================*/
315v_U8_t sapSelectPreferredChannelFromChannelList(v_U8_t bestChNum,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700316 ptSapContext pSapCtx,
317 tSapChSelSpectInfo *pSpectInfoParams)
318{
319 v_U8_t j = 0;
320 v_U8_t count = 0;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700321
322 //If Channel List is not Configured don't do anything
323 //Else return the Best Channel from the Channel List
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700324 if((NULL == pSapCtx->SapChnlList.channelList) ||
325 (NULL == pSpectInfoParams) ||
326 (0 == pSapCtx->SapChnlList.numChannel))
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700327 {
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700328 return bestChNum;
329 }
330
331 if (bestChNum > 0 && bestChNum <= 252)
332 {
333 for(count=0; count < pSpectInfoParams->numSpectChans ; count++)
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700334 {
335 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[count].chNum;
336 // Select the best channel from allowed list
337 for(j=0;j< pSapCtx->SapChnlList.numChannel;j++)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700338 {
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700339 if( (pSapCtx->SapChnlList.channelList[j]) == bestChNum)
340 {
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700341 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
342 "Best channel computed from Channel List is: %d",
343 bestChNum);
344 return bestChNum;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700345 }
346 }
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700347 }
348
349 return SAP_CHANNEL_NOT_SELECTED;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700350 }
351 else
352 return SAP_CHANNEL_NOT_SELECTED;
353}
354
355
Jeff Johnson295189b2012-06-20 16:38:30 -0700356/*==========================================================================
357 FUNCTION sapChanSelInit
358
359 DESCRIPTION
360 Function sapChanSelInit allocates the memory, intializes the
361 structures used by the channel selection algorithm
362
363 DEPENDENCIES
364 NA.
365
366 PARAMETERS
367
368 IN
369 *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure
370
371 RETURN VALUE
372 v_BOOL_t: Success or FAIL
373
374 SIDE EFFECTS
375============================================================================*/
376v_BOOL_t sapChanSelInit(tHalHandle halHandle, tSapChSelSpectInfo *pSpectInfoParams)
377{
378 tSapSpectChInfo *pSpectCh = NULL;
379 v_U8_t *pChans = NULL;
380 v_U16_t channelnum = 0;
381 tpAniSirGlobal pMac = PMAC_STRUCT(halHandle);
382
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700383 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700384
385 // Channels for that 2.4GHz band
386 //Considered only for 2.4GHz need to change in future to support 5GHz support
387 pSpectInfoParams->numSpectChans = pMac->scan.base20MHzChannels.numChannels;
388
389 // Allocate memory for weight computation of 2.4GHz
390 pSpectCh = (tSapSpectChInfo *)vos_mem_malloc((pSpectInfoParams->numSpectChans) * sizeof(*pSpectCh));
391
392 if(pSpectCh == NULL) {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700393 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "In %s, VOS_MALLOC_ERR", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700394 return eSAP_FALSE;
395 }
396
397 vos_mem_zero(pSpectCh, (pSpectInfoParams->numSpectChans) * sizeof(*pSpectCh));
398
399 // Initialize the pointers in the DfsParams to the allocated memory
400 pSpectInfoParams->pSpectCh = pSpectCh;
401
402 pChans = pMac->scan.base20MHzChannels.channelList;
403
404 // Fill the channel number in the spectrum in the operating freq band
405 for (channelnum = 0; channelnum < pSpectInfoParams->numSpectChans; channelnum++) {
406
407 if(*pChans == 14 ) //OFDM rates are not supported on channel 14
408 continue;
409 pSpectCh->chNum = *pChans;
410 pSpectCh->valid = eSAP_TRUE;
411 pSpectCh->rssiAgr = SOFTAP_MIN_RSSI;// Initialise for all channels
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800412 pSpectCh->channelWidth = SOFTAP_HT20_CHANNELWIDTH; // Initialise 20MHz for all the Channels
Jeff Johnson295189b2012-06-20 16:38:30 -0700413 pSpectCh++;
414 pChans++;
415 }
416 return eSAP_TRUE;
417}
418
419/*==========================================================================
420 FUNCTION sapweightRssiCount
421
422 DESCRIPTION
423 Function weightRssiCount calculates the channel weight due to rssi
424 and data count(here number of BSS observed)
425
426 DEPENDENCIES
427 NA.
428
429 PARAMETERS
430
431 IN
432 rssi : Max signal strength receieved from a BSS for the channel
433 count : Number of BSS observed in the channel
434
435 RETURN VALUE
436 v_U32_t : Calculated channel weight based on above two
437
438 SIDE EFFECTS
439============================================================================*/
440v_U32_t sapweightRssiCount(v_S7_t rssi, v_U16_t count)
441{
442 v_S31_t rssiWeight=0;
443 v_S31_t countWeight=0;
444 v_U32_t rssicountWeight=0;
445
446 // Weight from RSSI
447 rssiWeight = SOFTAP_RSSI_WEIGHT * (rssi - SOFTAP_MIN_RSSI)
448 /(SOFTAP_MAX_RSSI - SOFTAP_MIN_RSSI);
449
450 if(rssiWeight > SOFTAP_RSSI_WEIGHT)
451 rssiWeight = SOFTAP_RSSI_WEIGHT;
452 else if (rssiWeight < 0)
453 rssiWeight = 0;
454
455 // Weight from data count
456 countWeight = SOFTAP_COUNT_WEIGHT * (count - SOFTAP_MIN_COUNT)
457 /(SOFTAP_MAX_COUNT - SOFTAP_MIN_COUNT);
458
459 if(countWeight > SOFTAP_COUNT_WEIGHT)
460 countWeight = SOFTAP_COUNT_WEIGHT;
461 else if (countWeight < 0)
462 countWeight = 0;
463
464 rssicountWeight = rssiWeight + countWeight;
465
466 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, rssiWeight=%d, countWeight=%d, rssicountWeight=%d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700467 __func__, rssiWeight, countWeight, rssicountWeight);
Jeff Johnson295189b2012-06-20 16:38:30 -0700468
469 return(rssicountWeight);
470}
471
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800472
473/*==========================================================================
474 FUNCTION sapInterferenceRssiCount
475
476 DESCRIPTION
477 Function sapInterferenceRssiCount Considers the Adjacent channel rssi
478 and data count(here number of BSS observed)
479
480 DEPENDENCIES
481 NA.
482
483 PARAMETERS
484
485 pSpectCh : Channel Information
486
487 RETURN VALUE
488 NA.
489
490 SIDE EFFECTS
491============================================================================*/
492void sapInterferenceRssiCount(tSapSpectChInfo *pSpectCh)
493{
494 tSapSpectChInfo *pExtSpectCh = NULL;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700495 v_S31_t rssi;
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800496 switch(pSpectCh->chNum)
497 {
498 case CHANNEL_1:
499 pExtSpectCh = (pSpectCh + 1);
500 if(pExtSpectCh != NULL)
501 {
502 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700503 rssi = pSpectCh->rssiAgr + SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
504 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
505 {
506 pExtSpectCh->rssiAgr = rssi;
507 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800508 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
509 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
510 }
511 pExtSpectCh = (pSpectCh + 2);
512 if(pExtSpectCh != NULL)
513 {
514 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700515 rssi = pSpectCh->rssiAgr + SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
516 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
517 {
518 pExtSpectCh->rssiAgr = rssi;
519 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800520 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
521 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
522 }
523 pExtSpectCh = (pSpectCh + 3);
524 if(pExtSpectCh != NULL)
525 {
526 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700527 rssi = pSpectCh->rssiAgr + SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
528 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
529 {
530 pExtSpectCh->rssiAgr = rssi;
531 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800532 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
533 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
534 }
535 pExtSpectCh = (pSpectCh + 4);
536 if(pExtSpectCh != NULL)
537 {
538 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700539 rssi = pSpectCh->rssiAgr + SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
540 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
541 {
542 pExtSpectCh->rssiAgr = rssi;
543 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800544 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
545 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
546 }
547 break;
548 case CHANNEL_2:
549 pExtSpectCh = (pSpectCh - 1);
550 if(pExtSpectCh != NULL)
551 {
552 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700553 rssi = pSpectCh->rssiAgr + SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
554 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
555 {
556 pExtSpectCh->rssiAgr = rssi;
557 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800558 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
559 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
560 }
561 pExtSpectCh = (pSpectCh + 1);
562 if(pExtSpectCh != NULL)
563 {
564 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700565 rssi = pSpectCh->rssiAgr + SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
566 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
567 {
568 pExtSpectCh->rssiAgr = rssi;
569 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800570 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
571 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
572 }
573 pExtSpectCh = (pSpectCh + 2);
574 if(pExtSpectCh != NULL)
575 {
576 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700577 rssi = pSpectCh->rssiAgr + SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
578 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
579 {
580 pExtSpectCh->rssiAgr = rssi;
581 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800582 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
583 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
584 }
585 pExtSpectCh = (pSpectCh + 3);
586 if(pExtSpectCh != NULL)
587 {
588 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700589 rssi = pSpectCh->rssiAgr + SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
590 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
591 {
592 pExtSpectCh->rssiAgr = rssi;
593 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800594 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
595 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
596 }
597 break;
598 case CHANNEL_3:
599 case CHANNEL_4:
600 case CHANNEL_5:
601 case CHANNEL_6:
602 case CHANNEL_7:
603 case CHANNEL_8:
604 case CHANNEL_9:
605 pExtSpectCh = (pSpectCh - 1);
606 if(pExtSpectCh != NULL)
607 {
608 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700609 rssi = pSpectCh->rssiAgr + SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
610 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
611 {
612 pExtSpectCh->rssiAgr = rssi;
613 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800614 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
615 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
616 }
617 pExtSpectCh = (pSpectCh + 1);
618 if(pExtSpectCh != NULL)
619 {
620 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700621 rssi = pSpectCh->rssiAgr + SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
622 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
623 {
624 pExtSpectCh->rssiAgr = rssi;
625 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800626 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
627 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
628 }
629 pExtSpectCh = (pSpectCh - 2);
630 if(pExtSpectCh != NULL)
631 {
632 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700633 rssi = pSpectCh->rssiAgr + SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
634 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
635 {
636 pExtSpectCh->rssiAgr = rssi;
637 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800638 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
639 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
640 }
641 pExtSpectCh = (pSpectCh + 2);
642 if(pExtSpectCh != NULL)
643 {
644 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700645 rssi = pSpectCh->rssiAgr + SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
646 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
647 {
648 pExtSpectCh->rssiAgr = rssi;
649 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800650 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
651 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
652 }
653 break;
654 case CHANNEL_10:
655 pExtSpectCh = (pSpectCh - 1);
656 if(pExtSpectCh != NULL)
657 {
658 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700659 rssi = pSpectCh->rssiAgr + SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
660 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
661 {
662 pExtSpectCh->rssiAgr = rssi;
663 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800664 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
665 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
666 }
667 pExtSpectCh = (pSpectCh + 1);
668 if(pExtSpectCh != NULL)
669 {
670 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700671 rssi = pSpectCh->rssiAgr + SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
672 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
673 {
674 pExtSpectCh->rssiAgr = rssi;
675 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800676 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
677 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
678 }
679 pExtSpectCh = (pSpectCh - 2);
680 if(pExtSpectCh != NULL)
681 {
682 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700683 rssi = pSpectCh->rssiAgr + SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
684 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
685 {
686 pExtSpectCh->rssiAgr = rssi;
687 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800688 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
689 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
690 }
691 pExtSpectCh = (pSpectCh - 3);
692 if(pExtSpectCh != NULL)
693 {
694 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700695 rssi = pSpectCh->rssiAgr + SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
696 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
697 {
698 pExtSpectCh->rssiAgr = rssi;
699 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800700 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
701 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
702 }
703 break;
704 case CHANNEL_11:
705 pExtSpectCh = (pSpectCh - 1);
706 if(pExtSpectCh != NULL)
707 {
708 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700709 rssi = pSpectCh->rssiAgr + SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
710 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
711 {
712 pExtSpectCh->rssiAgr = rssi;
713 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800714 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
715 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
716 }
717 pExtSpectCh = (pSpectCh - 2);
718 if(pExtSpectCh != NULL)
719 {
720 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700721 rssi = pSpectCh->rssiAgr + SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
722 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
723 {
724 pExtSpectCh->rssiAgr = rssi;
725 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800726 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
727 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
728 }
729 pExtSpectCh = (pSpectCh - 3);
730 if(pExtSpectCh != NULL)
731 {
732 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700733 rssi = pSpectCh->rssiAgr + SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
734 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
735 {
736 pExtSpectCh->rssiAgr = rssi;
737 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800738 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
739 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
740 }
741 pExtSpectCh = (pSpectCh - 4);
742 if(pExtSpectCh != NULL)
743 {
744 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700745 rssi = pSpectCh->rssiAgr + SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
746 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
747 {
748 pExtSpectCh->rssiAgr = rssi;
749 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800750 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
751 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
752 }
753 break;
754 default:
755 break;
756 }
757}
758
Jeff Johnson295189b2012-06-20 16:38:30 -0700759/*==========================================================================
760 FUNCTION sapComputeSpectWeight
761
762 DESCRIPTION
763 Main function for computing the weight of each channel in the
764 spectrum based on the RSSI value of the BSSes on the channel
765 and number of BSS
766
767 DEPENDENCIES
768 NA.
769
770 PARAMETERS
771
772 IN
773 pSpectInfoParams : Pointer to the tSpectInfoParams structure
774 halHandle : Pointer to HAL handle
775 pResult : Pointer to tScanResultHandle
776
777 RETURN VALUE
778 void : NULL
779
780 SIDE EFFECTS
781============================================================================*/
782void sapComputeSpectWeight( tSapChSelSpectInfo* pSpectInfoParams,
783 tHalHandle halHandle, tScanResultHandle pResult)
784{
785 v_S7_t rssi = 0;
786 v_U8_t chn_num = 0;
787 v_U8_t channel_id = 0;
788
789 tCsrScanResultInfo *pScanResult;
790 tSapSpectChInfo *pSpectCh = pSpectInfoParams->pSpectCh;
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800791 v_U32_t operatingBand;
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -0800792 v_U16_t channelWidth;
793 v_U16_t secondaryChannelOffset;
794 v_U16_t centerFreq;
795 v_U16_t vhtSupport;
796 v_U32_t ieLen = 0;
797 tSirProbeRespBeacon *pBeaconStruct;
798 tpAniSirGlobal pMac = (tpAniSirGlobal) halHandle;
Jeff Johnson295189b2012-06-20 16:38:30 -0700799
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -0800800 if(eHAL_STATUS_SUCCESS != palAllocateMemory(pMac->hHdd,
801 (void **)&pBeaconStruct, sizeof(tSirProbeRespBeacon)))
802 {
803 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,"Unable to PAL allocate memory in sapComputeSpectWeight\n");
804 return;
805 }
806
807
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700808 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Computing spectral weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700809
810 /**
811 * Soft AP specific channel weight calculation using DFS formula
812 */
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800813 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_OPERATING_BAND, &operatingBand);
Jeff Johnson295189b2012-06-20 16:38:30 -0700814
815 pScanResult = sme_ScanResultGetFirst(halHandle, pResult);
816
817 while (pScanResult) {
818 pSpectCh = pSpectInfoParams->pSpectCh;
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -0800819 // Defining the default values, so that any value will hold the default values
820 channelWidth = eHT_CHANNEL_WIDTH_20MHZ;
821 secondaryChannelOffset = PHY_SINGLE_CHANNEL_CENTERED;
822 vhtSupport = 0;
823 centerFreq = 0;
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800824
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -0800825 if(pScanResult->BssDescriptor.ieFields != NULL)
826 {
827 ieLen = (pScanResult->BssDescriptor.length + sizeof(tANI_U16) + sizeof(tANI_U32) - sizeof(tSirBssDescription));
828 palZeroMemory(pMac->hHdd, (tANI_U8 *) pBeaconStruct, sizeof(tSirProbeRespBeacon));
829
830 if ((sirParseBeaconIE(pMac, pBeaconStruct,(tANI_U8 *)( pScanResult->BssDescriptor.ieFields), ieLen)) == eSIR_SUCCESS)
831 {
832 if(pBeaconStruct->HTCaps.present && pBeaconStruct->HTInfo.present)
833 {
834 channelWidth = pBeaconStruct->HTCaps.supportedChannelWidthSet;
835 secondaryChannelOffset = pBeaconStruct->HTInfo.secondaryChannelOffset;
836 if(pBeaconStruct->VHTOperation.present)
837 {
838 vhtSupport = pBeaconStruct->VHTOperation.present;
839 if(pBeaconStruct->VHTOperation.chanWidth > WNI_CFG_VHT_CHANNEL_WIDTH_20_40MHZ)
840 {
841 channelWidth = eHT_CHANNEL_WIDTH_80MHZ;
842 centerFreq = pBeaconStruct->VHTOperation.chanCenterFreqSeg1;
843 }
844 }
845 }
846 }
847 }
Madan Mohan Koyyalamudi1e02f7f2012-12-04 16:46:45 -0800848 // Processing for each tCsrScanResultInfo in the tCsrScanResult DLink list
Jeff Johnson295189b2012-06-20 16:38:30 -0700849 for (chn_num = 0; chn_num < pSpectInfoParams->numSpectChans; chn_num++) {
850
851 /*
852 * if the Beacon has channel ID, use it other wise we will
853 * rely on the channelIdSelf
854 */
855 if(pScanResult->BssDescriptor.channelId == 0)
856 channel_id = pScanResult->BssDescriptor.channelIdSelf;
857 else
858 channel_id = pScanResult->BssDescriptor.channelId;
859
860 if (channel_id == pSpectCh->chNum) {
861 if (pSpectCh->rssiAgr < pScanResult->BssDescriptor.rssi)
862 pSpectCh->rssiAgr = pScanResult->BssDescriptor.rssi;
863
864 ++pSpectCh->bssCount; // Increment the count of BSS
865
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800866 if(operatingBand) // Connsidering the Extension Channel only in a channels
867 {
868 /* Updating the received ChannelWidth */
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -0800869 if (pSpectCh->channelWidth != channelWidth)
Prathyusha Kuntupalli9466ba82012-12-10 13:20:32 -0800870 pSpectCh->channelWidth = channelWidth;
Madan Mohan Koyyalamudi1e02f7f2012-12-04 16:46:45 -0800871 /* If received ChannelWidth is other than HT20, we need to update the extension channel Params as well */
872 /* channelWidth == 0, HT20 */
873 /* channelWidth == 1, HT40 */
874 /* channelWidth == 2, VHT80*/
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800875 switch(pSpectCh->channelWidth)
876 {
877 case eHT_CHANNEL_WIDTH_40MHZ: //HT40
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -0800878 switch( secondaryChannelOffset)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800879 {
880 tSapSpectChInfo *pExtSpectCh = NULL;
881 case PHY_DOUBLE_CHANNEL_LOW_PRIMARY: // Above the Primary Channel
882 pExtSpectCh = (pSpectCh + 1);
883 if(pExtSpectCh != NULL)
884 {
885 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700886 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800887 // REducing the rssi by -20 and assigning it to Extension channel
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700888 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
889 {
890 pExtSpectCh->rssiAgr = rssi;
891 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800892 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
893 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
894 }
895 break;
896 case PHY_DOUBLE_CHANNEL_HIGH_PRIMARY: // Below the Primary channel
897 pExtSpectCh = (pSpectCh - 1);
898 if(pExtSpectCh != NULL)
899 {
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700900 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
901 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
902 {
903 pExtSpectCh->rssiAgr = rssi;
904 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800905 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
906 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
907 ++pExtSpectCh->bssCount;
908 }
909 break;
910 }
911 break;
912 case eHT_CHANNEL_WIDTH_80MHZ: // VHT80
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -0800913 if((centerFreq - channel_id) == 6)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800914 {
915 tSapSpectChInfo *pExtSpectCh = NULL;
916 pExtSpectCh = (pSpectCh + 1);
917 if(pExtSpectCh != NULL)
918 {
919 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700920 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
921 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
922 {
923 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -20 and assigning it to Subband 1
924 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800925 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
926 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
927 }
928 pExtSpectCh = (pSpectCh + 2);
929 if(pExtSpectCh != NULL)
930 {
931 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700932 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
933 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
934 {
935 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -30 and assigning it to Subband 2
936 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800937 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
938 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
939 }
940 pExtSpectCh = (pSpectCh + 3);
941 if(pExtSpectCh != NULL)
942 {
943 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700944 rssi = pSpectCh->rssiAgr + SAP_SUBBAND3_RSSI_EFFECT_PRIMARY;
945 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
946 {
947 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -40 and assigning it to Subband 3
948 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800949 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
950 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
951 }
952 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -0800953 else if((centerFreq - channel_id) == 2)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800954 {
955 tSapSpectChInfo *pExtSpectCh = NULL;
956 pExtSpectCh = (pSpectCh - 1 );
957 if(pExtSpectCh != NULL)
958 {
959 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700960 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
961 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
962 {
963 pExtSpectCh->rssiAgr = rssi;
964 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800965 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
966 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
967 }
968 pExtSpectCh = (pSpectCh + 1);
969 if(pExtSpectCh != NULL)
970 {
971 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700972 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
973 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
974 {
975 pExtSpectCh->rssiAgr = rssi;
976 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800977 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
978 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
979 }
980 pExtSpectCh = (pSpectCh + 2);
981 if(pExtSpectCh != NULL)
982 {
983 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700984 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
985 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
986 {
987 pExtSpectCh->rssiAgr = rssi;
988 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800989 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
990 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
991 }
992 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -0800993 else if((centerFreq - channel_id) == -2)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800994 {
995 tSapSpectChInfo *pExtSpectCh = NULL;
996 pExtSpectCh = (pSpectCh - 1 );
997 if(pExtSpectCh != NULL)
998 {
999 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001000 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1001 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1002 {
1003 pExtSpectCh->rssiAgr = rssi;
1004 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001005 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1006 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1007 }
1008 pExtSpectCh = (pSpectCh - 2);
1009 if(pExtSpectCh != NULL)
1010 {
1011 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001012 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1013 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1014 {
1015 pExtSpectCh->rssiAgr = rssi;
1016 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001017 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1018 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1019 }
1020 pExtSpectCh = (pSpectCh + 1);
1021 if(pExtSpectCh != NULL)
1022 {
1023 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001024 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1025 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1026 {
1027 pExtSpectCh->rssiAgr = rssi;
1028 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001029 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1030 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1031 }
1032 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001033 else if((centerFreq - channel_id) == -6)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001034 {
1035 tSapSpectChInfo *pExtSpectCh = NULL;
1036 pExtSpectCh = (pSpectCh - 1 );
1037 if(pExtSpectCh != NULL)
1038 {
1039 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001040 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1041 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1042 {
1043 pExtSpectCh->rssiAgr = rssi;
1044 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001045 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1046 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1047 }
1048 pExtSpectCh = (pSpectCh - 2);
1049 if(pExtSpectCh != NULL)
1050 {
1051 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001052 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1053 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1054 {
1055 pExtSpectCh->rssiAgr = rssi;
1056 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001057 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1058 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1059 }
1060 pExtSpectCh = (pSpectCh - 3);
1061 if(pExtSpectCh != NULL)
1062 {
1063 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001064 rssi = pSpectCh->rssiAgr + SAP_SUBBAND3_RSSI_EFFECT_PRIMARY;
1065 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1066 {
1067 pExtSpectCh->rssiAgr = rssi;
1068 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001069 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1070 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1071 }
1072 }
1073 break;
1074 }
1075 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001076 else if(operatingBand == RF_SUBBAND_2_4_GHZ)
1077 {
1078 sapInterferenceRssiCount(pSpectCh);
1079 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001080
Jeff Johnson295189b2012-06-20 16:38:30 -07001081 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301082 "In %s, bssdes.ch_self=%d, bssdes.ch_ID=%d, bssdes.rssi=%d, SpectCh.bssCount=%d, pScanResult=%p, ChannelWidth %d, secondaryChanOffset %d, center frequency %d \n",
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001083 __func__, pScanResult->BssDescriptor.channelIdSelf, pScanResult->BssDescriptor.channelId, pScanResult->BssDescriptor.rssi, pSpectCh->bssCount, pScanResult,pSpectCh->channelWidth,secondaryChannelOffset,centerFreq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001084 pSpectCh++;
1085 break;
1086 } else {
1087 pSpectCh++;
1088 }
1089 }
1090
1091 pScanResult = sme_ScanResultGetNext(halHandle, pResult);
1092 }
1093
1094 // Calculate the weights for all channels in the spectrum pSpectCh
1095 pSpectCh = pSpectInfoParams->pSpectCh;
1096
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001097 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Spectrum Channels Weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001098
1099 for (chn_num = 0; chn_num < (pSpectInfoParams->numSpectChans); chn_num++) {
1100
1101 /*
1102 rssi : Maximum received signal strength among all BSS on that channel
1103 bssCount : Number of BSS on that channel
1104 */
1105
1106 rssi = (v_S7_t)pSpectCh->rssiAgr;
1107
1108 pSpectCh->weight = SAPDFS_NORMALISE_1000 * sapweightRssiCount(rssi, pSpectCh->bssCount);
1109
1110 //------ Debug Info ------
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001111 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Chan=%d Weight= %d rssiAgr=%d bssCount=%d", __func__, pSpectCh->chNum,
Jeff Johnson295189b2012-06-20 16:38:30 -07001112 pSpectCh->weight, pSpectCh->rssiAgr, pSpectCh->bssCount);
1113 //------ Debug Info ------
1114 pSpectCh++;
1115 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001116 palFreeMemory(pMac->hHdd, pBeaconStruct);
Jeff Johnson295189b2012-06-20 16:38:30 -07001117}
1118
1119/*==========================================================================
1120 FUNCTION sapChanSelExit
1121
1122 DESCRIPTION
1123 Exit function for free out the allocated memory, to be called
1124 at the end of the dfsSelectChannel function
1125
1126 DEPENDENCIES
1127 NA.
1128
1129 PARAMETERS
1130
1131 IN
1132 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1133
1134 RETURN VALUE
1135 void : NULL
1136
1137 SIDE EFFECTS
1138============================================================================*/
1139void sapChanSelExit( tSapChSelSpectInfo *pSpectInfoParams )
1140{
1141 // Free all the allocated memory
1142 vos_mem_free(pSpectInfoParams->pSpectCh);
1143}
1144
1145/*==========================================================================
1146 FUNCTION sapSortChlWeight
1147
1148 DESCRIPTION
1149 Funtion to sort the channels with the least weight first
1150
1151 DEPENDENCIES
1152 NA.
1153
1154 PARAMETERS
1155
1156 IN
1157 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1158
1159 RETURN VALUE
1160 void : NULL
1161
1162 SIDE EFFECTS
1163============================================================================*/
1164void sapSortChlWeight(tSapChSelSpectInfo *pSpectInfoParams)
1165{
1166 tSapSpectChInfo temp;
1167
1168 tSapSpectChInfo *pSpectCh = NULL;
1169 v_U32_t i = 0, j = 0, minWeightIndex = 0;
1170
1171 pSpectCh = pSpectInfoParams->pSpectCh;
1172#ifdef SOFTAP_CHANNEL_RANGE
1173 // Sorting the channels as per weights
1174 for (i = 0; i < pSpectInfoParams->numSpectChans; i++) {
1175 minWeightIndex = i;
1176 for( j = i + 1; j < pSpectInfoParams->numSpectChans; j++) {
1177 if(pSpectCh[j].weight < pSpectCh[minWeightIndex].weight) {
1178 minWeightIndex = j;
1179 }
1180 }
1181 if(minWeightIndex != i) {
1182 vos_mem_copy(&temp, &pSpectCh[minWeightIndex], sizeof(*pSpectCh));
1183 vos_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], sizeof(*pSpectCh));
1184 vos_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
1185 }
1186 }
1187#else
1188 // Sorting the channels as per weights
1189 for (i = 0; i < SPECT_24GHZ_CH_COUNT; i++) {
1190 minWeightIndex = i;
1191 for( j = i + 1; j < SPECT_24GHZ_CH_COUNT; j++) {
1192 if(pSpectCh[j].weight < pSpectCh[minWeightIndex].weight) {
1193 minWeightIndex = j;
1194 }
1195 }
1196 if(minWeightIndex != i) {
1197 vos_mem_copy(&temp, &pSpectCh[minWeightIndex], sizeof(*pSpectCh));
1198 vos_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], sizeof(*pSpectCh));
1199 vos_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
1200 }
1201 }
1202#endif
1203
1204 /* For testing */
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001205 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Sorted Spectrum Channels Weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001206 pSpectCh = pSpectInfoParams->pSpectCh;
1207 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
1208 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001209 __func__, pSpectCh->chNum, pSpectCh->weight, pSpectCh->rssiAgr, pSpectCh->bssCount);
Jeff Johnson295189b2012-06-20 16:38:30 -07001210 pSpectCh++;
1211 }
1212
1213}
1214
1215/*==========================================================================
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001216 FUNCTION sapComputeNonOverlapChannel
1217
1218 DESCRIPTION
1219 Checking for the Free Non Overlapping Channel
1220
1221 DEPENDENCIES
1222 NA.
1223
1224 PARAMETERS
1225
1226 IN
1227 pSpectInfoParams: Spectrum Info params
1228
1229 RETURN VALUE
1230 v_U8_t : Success - Bit mask
1231
1232 SIDE EFFECTS
1233============================================================================*/
1234v_U8_t sapComputeNonOverlapChannel(tSapChSelSpectInfo* pSpectInfoParams)
1235{
1236 v_U8_t nonOverlap = 0;
1237 tSapSpectChInfo *pSpectCh = NULL;
1238 v_U8_t chn_num = 0;
1239 pSpectCh = pSpectInfoParams->pSpectCh;
1240 for (chn_num = 0; chn_num < (pSpectInfoParams->numSpectChans); chn_num++) {
1241 if(pSpectCh->chNum == CHANNEL_1 || pSpectCh->chNum == CHANNEL_6 || pSpectCh->chNum == CHANNEL_11)
1242 {
1243 switch(pSpectCh->chNum)
1244 {
1245 case 1:
1246 if(pSpectCh->weight == 0)
1247 nonOverlap |= 0x1; //Bit 0 For channel 1
1248 break;
1249 case 6:
1250 if(pSpectCh->weight == 0)
1251 nonOverlap |= 0x2; // Bit 1 For Channel 6
1252 break;
1253 case 11:
1254 if(pSpectCh->weight == 0)
1255 nonOverlap |= 0x4; // Bit 2 for Channel 11
1256 break;
1257 default:
1258 break;
1259 }
1260 }
1261 pSpectCh++;
1262 }
1263 return nonOverlap;
1264}
1265
1266/*==========================================================================
Jeff Johnson295189b2012-06-20 16:38:30 -07001267 FUNCTION sapSelectChannel
1268
1269 DESCRIPTION
1270 Runs a algorithm to select the best channel to operate in based on BSS
1271 rssi and bss count on each channel
1272
1273 DEPENDENCIES
1274 NA.
1275
1276 PARAMETERS
1277
1278 IN
1279 halHandle : Pointer to HAL handle
1280 pResult : Pointer to tScanResultHandle
1281
1282 RETURN VALUE
1283 v_U8_t : Success - channel number, Fail - zero
1284
1285 SIDE EFFECTS
1286============================================================================*/
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07001287v_U8_t sapSelectChannel(tHalHandle halHandle, ptSapContext pSapCtx, tScanResultHandle pScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07001288{
1289 // DFS param object holding all the data req by the algo
1290 tSapChSelSpectInfo oSpectInfoParams = {NULL,0};
1291 tSapChSelSpectInfo *pSpectInfoParams = &oSpectInfoParams; // Memory? NB
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001292 v_U8_t nonOverlap = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001293 v_U8_t bestChNum = 0;
1294#ifdef SOFTAP_CHANNEL_RANGE
1295 v_U32_t startChannelNum;
1296 v_U32_t endChannelNum;
Gopichand Nakkala936715f2013-03-18 19:48:10 +05301297 v_U32_t operatingBand = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001298 v_U8_t count = 0;
1299#endif
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001300 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Running SAP Ch Select", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001301
1302 // Set to zero tSapChSelParams
1303 //vos_mem_zero(&sapChSelParams, sizeof(sapChSelParams));
1304
1305 // Initialize the structure pointed by pSpectInfoParams
1306 if(sapChanSelInit( halHandle, pSpectInfoParams) != eSAP_TRUE ) {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001307 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "In %s, Ch Select initialization failed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001308 return SAP_CHANNEL_NOT_SELECTED;
1309 }
1310
1311 // Compute the weight of the entire spectrum in the operating band
1312 sapComputeSpectWeight( pSpectInfoParams, halHandle, pScanResult);
1313
1314 // Sort the 20M channel list as per the computed weights, lesser weight first.
1315 sapSortChlWeight(pSpectInfoParams);
1316
1317#ifdef SOFTAP_CHANNEL_RANGE
1318 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_START_CHANNEL, &startChannelNum);
1319 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_END_CHANNEL, &endChannelNum);
1320 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_OPERATING_BAND, &operatingBand);
1321
Gopichand Nakkala936715f2013-03-18 19:48:10 +05301322 // Calculating the Non overlapping Channel Availability */
1323 if(operatingBand == RF_SUBBAND_2_4_GHZ)
1324 nonOverlap = sapComputeNonOverlapChannel(pSpectInfoParams);
1325
Jeff Johnson295189b2012-06-20 16:38:30 -07001326 /*Loop till get the best channel in the given range */
1327 for(count=0; count < pSpectInfoParams->numSpectChans ; count++)
1328 {
1329 if((startChannelNum <= pSpectInfoParams->pSpectCh[count].chNum)&&
1330 ( endChannelNum >= pSpectInfoParams->pSpectCh[count].chNum))
1331 {
1332 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[count].chNum;
1333 break;
1334 }
1335 }
1336
1337#else
1338 // Get the first channel in sorted array as best 20M Channel
1339 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[0].chNum;
Jeff Johnson295189b2012-06-20 16:38:30 -07001340#endif
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001341
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07001342 //Select Best Channel from Channel List if Configured
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07001343 bestChNum = sapSelectPreferredChannelFromChannelList(bestChNum, pSapCtx, pSpectInfoParams);
Jeff Johnson295189b2012-06-20 16:38:30 -07001344
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001345 if(operatingBand == RF_SUBBAND_2_4_GHZ)
1346 {
1347 if(nonOverlap)
1348 {
1349 switch(nonOverlap)
1350 {
1351 case 0x1:
1352 bestChNum = CHANNEL_1;
1353 break;
1354 case 0x2:
1355 bestChNum = CHANNEL_6;
1356 break;
1357 case 0x4:
1358 bestChNum = CHANNEL_11;
1359 break;
1360 default:
1361 break;
1362 }
1363 }
1364 }
1365
Jeff Johnson295189b2012-06-20 16:38:30 -07001366 // Free all the allocated memory
1367 sapChanSelExit(pSpectInfoParams);
1368
1369 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Running SAP Ch select Completed, Ch=%d",
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001370 __func__, bestChNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07001371 if (bestChNum > 0 && bestChNum <= 252)
1372 return bestChNum;
1373 else
1374 return SAP_CHANNEL_NOT_SELECTED;
1375}
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001376