blob: 9c51f803f2a9bd23d66ce0e0d5b233ac1060d5b6 [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
Jeff Johnson295189b2012-06-20 16:38:30 -070045 OVERVIEW:
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053046
Jeff Johnson295189b2012-06-20 16:38:30 -070047 This software unit holds the implementation of the WLAN SAP modules
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053048 functions for channel selection.
Jeff Johnson295189b2012-06-20 16:38:30 -070049
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053050 DEPENDENCIES:
Jeff Johnson295189b2012-06-20 16:38:30 -070051
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053052 Are listed for each API below.
Jeff Johnson295189b2012-06-20 16:38:30 -070053===========================================================================*/
54
55/*===========================================================================
56
57 EDIT HISTORY FOR FILE
58
59
60 This section contains comments describing changes made to the module.
61 Notice that changes are listed in reverse chronological order.
62
63
64
65 when who what, where, why
66---------- --- --------------------------------------------------------
672010-03-15 SOFTAP Created module
68
69===========================================================================*/
70
71
72/*--------------------------------------------------------------------------
73 Include Files
74------------------------------------------------------------------------*/
75#include "vos_trace.h"
76#include "csrApi.h"
77#include "sme_Api.h"
78#include "sapChSelect.h"
79#include "sapInternal.h"
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -080080#ifdef ANI_OS_TYPE_QNX
81#include "stdio.h"
82#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070083
84/*--------------------------------------------------------------------------
85 Function definitions
86--------------------------------------------------------------------------*/
87
88/*--------------------------------------------------------------------------
89 Defines
90--------------------------------------------------------------------------*/
91#define SAP_DEBUG
92
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -070093#define IS_RSSI_VALID( extRssi, rssi ) \
94( \
95 ((extRssi < rssi)?eANI_BOOLEAN_TRUE:eANI_BOOLEAN_FALSE) \
96)
97
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070098/*==========================================================================
99 FUNCTION sapCleanupChannelList
100
101 DESCRIPTION
102 Function sapCleanupChannelList frees up the memory allocated to the channel list.
103
104 DEPENDENCIES
105 NA.
106
107 PARAMETERS
108
109 IN
110 NULL
111
112 RETURN VALUE
113 NULL
114============================================================================*/
115
116void sapCleanupChannelList(void)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700117{
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700118 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_SAP, NULL);
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530119 ptSapContext pSapCtx;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700120
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700121 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO,
122 "Cleaning up the channel list structure");
123
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530124 if (NULL == pvosGCtx)
125 {
126 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
127 "SAP Global Context is NULL");
128 return ;
129 }
130
131 pSapCtx = VOS_GET_SAP_CB(pvosGCtx);
132 if (NULL == pSapCtx)
133 {
134 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
135 "SAP Context is NULL");
136 return ;
137 }
138
139 pSapCtx->SapChnlList.numChannel = 0;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700140 vos_mem_free(pSapCtx->SapChnlList.channelList);
141 pSapCtx->SapChnlList.channelList = NULL;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700142}
143
144/*==========================================================================
145 FUNCTION sapSetPreferredChannel
146
147 DESCRIPTION
148 Function sapSetPreferredChannel sets the channel list which has been configured
149 into sap context (pSapCtx) which will be used at the time of best channel selection.
150
151 DEPENDENCIES
152 NA.
153
154 PARAMETERS
155
156 IN
157 *ptr: pointer having the command followed by the arguments in string format
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700158
159 RETURN VALUE
160 int: return 0 when success else returns error code.
161============================================================================*/
162
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800163int sapSetPreferredChannel(tANI_U8* ptr)
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700164{
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700165
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700166 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_SAP, NULL);
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530167 ptSapContext pSapCtx;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700168 tANI_U8* param;
169 int tempInt;
170 int j;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700171
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700172 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700173 "Enter: %s", __func__);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700174
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530175 if (NULL == pvosGCtx)
176 {
177 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
178 "SAP Global Context is NULL");
179 return -EINVAL;
180 }
181
182 pSapCtx = VOS_GET_SAP_CB(pvosGCtx);
183 if (NULL == pSapCtx)
184 {
185 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
186 "SAP Context is NULL");
187 return -EINVAL;
188 }
189
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700190 if (NULL != pSapCtx->SapChnlList.channelList)
191 {
192 sapCleanupChannelList();
193 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700194
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800195 param = strchr(ptr, ' ');
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700196 /*no argument after the command*/
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800197 if (NULL == param)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700198 {
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800199 return -EINVAL;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700200 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700201
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700202 /*no space after the command*/
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800203 else if (SPACE_ASCII_VALUE != *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 param++;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700209
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700210 /*removing empty spaces*/
211 while((SPACE_ASCII_VALUE == *param)&& ('\0' != *param) ) param++;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700212
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700213 /*no argument followed by spaces*/
214 if('\0' == *param)
215 {
216 return -EINVAL;
217 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700218
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700219 /*getting the first argument ie the number of channels*/
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800220 if (sscanf(param, "%d ", &tempInt) != 1)
221 {
222 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800223 "%s: Cannot get number of channels from input", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800224 return -EINVAL;
225 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700226
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700227 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800228 "%s: Number of channel added are: %d", __func__, tempInt);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700229
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800230 if (tempInt <= 0 || tempInt > 255)
231 {
232 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800233 "%s: Invalid Number of channel received", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800234 return -EINVAL;
235 }
236
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700237 /*allocating space for the desired number of channels*/
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530238 pSapCtx->SapChnlList.channelList = (v_U8_t *)vos_mem_malloc(tempInt);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700239
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530240 if (NULL == pSapCtx->SapChnlList.channelList)
241 {
242 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
243 "In %s, VOS_MALLOC_ERR", __func__);
244 return -EINVAL;
245 }
246
247 pSapCtx->SapChnlList.numChannel = tempInt;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700248 for(j=0;j<pSapCtx->SapChnlList.numChannel;j++)
249 {
250
251 /*param pointing to the beginning of first space after number of channels*/
252 param = strpbrk( param, " " );
253 /*no channel list after the number of channels argument*/
254 if (NULL == param)
255 {
256 sapCleanupChannelList();
257 return -EINVAL;
258 }
259
260 param++;
261
262 /*removing empty space*/
263 while((SPACE_ASCII_VALUE == *param) && ('\0' != *param) ) param++;
264
265 /*no channel list after the number of channels argument and spaces*/
266 if( '\0' == *param )
267 {
268 sapCleanupChannelList();
269 return -EINVAL;
270 }
271
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800272 if (sscanf(param, "%d ", &tempInt) != 1)
273 {
274 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800275 "%s: Cannot read channel number", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800276 sapCleanupChannelList();
277 return -EINVAL;
278 }
279 if (tempInt < 0 || tempInt > 255)
280 {
281 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800282 "%s: Invalid channel number received", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800283 sapCleanupChannelList();
284 return -EINVAL;
285 }
286
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700287 pSapCtx->SapChnlList.channelList[j] = tempInt;
288
289 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800290 "%s: Channel %d added to preferred channel list",
291 __func__, pSapCtx->SapChnlList.channelList[j] );
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700292
293 }
294
295 /*extra arguments check*/
296 param = strpbrk( param, " " );
297 if (NULL != param)
298 {
299 while((SPACE_ASCII_VALUE == *param) && ('\0' != *param) ) param++;
300
301 if('\0' != *param)
302 {
303 sapCleanupChannelList();
304 return -EINVAL;
305 }
306 }
307
308 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700309 "Exit: %s", __func__);
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700310
311 return 0;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700312}
313
314/*==========================================================================
315 FUNCTION sapSelectPreferredChannelFromChannelList
316
317 DESCRIPTION
318 Function sapSelectPreferredChannelFromChannelList calculates the best channel
319 among the configured channel list. If channel list not configured then returns
320 the best channel calculated among all the channel list.
321
322 DEPENDENCIES
323 NA.
324
325 PARAMETERS
326
327 IN
328 *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure
329 bestChNum: best channel already calculated among all the chanels
330 pSapCtx: having info of channel list from which best channel is selected
331
332 RETURN VALUE
333 v_U8_t: best channel
334============================================================================*/
335v_U8_t sapSelectPreferredChannelFromChannelList(v_U8_t bestChNum,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700336 ptSapContext pSapCtx,
337 tSapChSelSpectInfo *pSpectInfoParams)
338{
339 v_U8_t j = 0;
340 v_U8_t count = 0;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700341
342 //If Channel List is not Configured don't do anything
343 //Else return the Best Channel from the Channel List
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700344 if((NULL == pSapCtx->SapChnlList.channelList) ||
345 (NULL == pSpectInfoParams) ||
346 (0 == pSapCtx->SapChnlList.numChannel))
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700347 {
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700348 return bestChNum;
349 }
350
351 if (bestChNum > 0 && bestChNum <= 252)
352 {
353 for(count=0; count < pSpectInfoParams->numSpectChans ; count++)
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700354 {
355 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[count].chNum;
356 // Select the best channel from allowed list
357 for(j=0;j< pSapCtx->SapChnlList.numChannel;j++)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700358 {
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700359 if( (pSapCtx->SapChnlList.channelList[j]) == bestChNum)
360 {
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700361 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
362 "Best channel computed from Channel List is: %d",
363 bestChNum);
364 return bestChNum;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700365 }
366 }
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700367 }
368
369 return SAP_CHANNEL_NOT_SELECTED;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700370 }
371 else
372 return SAP_CHANNEL_NOT_SELECTED;
373}
374
375
Jeff Johnson295189b2012-06-20 16:38:30 -0700376/*==========================================================================
377 FUNCTION sapChanSelInit
378
379 DESCRIPTION
380 Function sapChanSelInit allocates the memory, intializes the
381 structures used by the channel selection algorithm
382
383 DEPENDENCIES
384 NA.
385
386 PARAMETERS
387
388 IN
389 *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure
390
391 RETURN VALUE
392 v_BOOL_t: Success or FAIL
393
394 SIDE EFFECTS
395============================================================================*/
396v_BOOL_t sapChanSelInit(tHalHandle halHandle, tSapChSelSpectInfo *pSpectInfoParams)
397{
398 tSapSpectChInfo *pSpectCh = NULL;
399 v_U8_t *pChans = NULL;
400 v_U16_t channelnum = 0;
401 tpAniSirGlobal pMac = PMAC_STRUCT(halHandle);
402
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700403 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700404
405 // Channels for that 2.4GHz band
406 //Considered only for 2.4GHz need to change in future to support 5GHz support
407 pSpectInfoParams->numSpectChans = pMac->scan.base20MHzChannels.numChannels;
408
409 // Allocate memory for weight computation of 2.4GHz
410 pSpectCh = (tSapSpectChInfo *)vos_mem_malloc((pSpectInfoParams->numSpectChans) * sizeof(*pSpectCh));
411
412 if(pSpectCh == NULL) {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700413 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "In %s, VOS_MALLOC_ERR", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700414 return eSAP_FALSE;
415 }
416
417 vos_mem_zero(pSpectCh, (pSpectInfoParams->numSpectChans) * sizeof(*pSpectCh));
418
419 // Initialize the pointers in the DfsParams to the allocated memory
420 pSpectInfoParams->pSpectCh = pSpectCh;
421
422 pChans = pMac->scan.base20MHzChannels.channelList;
423
424 // Fill the channel number in the spectrum in the operating freq band
425 for (channelnum = 0; channelnum < pSpectInfoParams->numSpectChans; channelnum++) {
426
427 if(*pChans == 14 ) //OFDM rates are not supported on channel 14
428 continue;
429 pSpectCh->chNum = *pChans;
430 pSpectCh->valid = eSAP_TRUE;
431 pSpectCh->rssiAgr = SOFTAP_MIN_RSSI;// Initialise for all channels
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800432 pSpectCh->channelWidth = SOFTAP_HT20_CHANNELWIDTH; // Initialise 20MHz for all the Channels
Jeff Johnson295189b2012-06-20 16:38:30 -0700433 pSpectCh++;
434 pChans++;
435 }
436 return eSAP_TRUE;
437}
438
439/*==========================================================================
440 FUNCTION sapweightRssiCount
441
442 DESCRIPTION
443 Function weightRssiCount calculates the channel weight due to rssi
444 and data count(here number of BSS observed)
445
446 DEPENDENCIES
447 NA.
448
449 PARAMETERS
450
451 IN
452 rssi : Max signal strength receieved from a BSS for the channel
453 count : Number of BSS observed in the channel
454
455 RETURN VALUE
456 v_U32_t : Calculated channel weight based on above two
457
458 SIDE EFFECTS
459============================================================================*/
460v_U32_t sapweightRssiCount(v_S7_t rssi, v_U16_t count)
461{
462 v_S31_t rssiWeight=0;
463 v_S31_t countWeight=0;
464 v_U32_t rssicountWeight=0;
465
466 // Weight from RSSI
467 rssiWeight = SOFTAP_RSSI_WEIGHT * (rssi - SOFTAP_MIN_RSSI)
468 /(SOFTAP_MAX_RSSI - SOFTAP_MIN_RSSI);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530469
Jeff Johnson295189b2012-06-20 16:38:30 -0700470 if(rssiWeight > SOFTAP_RSSI_WEIGHT)
471 rssiWeight = SOFTAP_RSSI_WEIGHT;
472 else if (rssiWeight < 0)
473 rssiWeight = 0;
474
475 // Weight from data count
476 countWeight = SOFTAP_COUNT_WEIGHT * (count - SOFTAP_MIN_COUNT)
477 /(SOFTAP_MAX_COUNT - SOFTAP_MIN_COUNT);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530478
Jeff Johnson295189b2012-06-20 16:38:30 -0700479 if(countWeight > SOFTAP_COUNT_WEIGHT)
480 countWeight = SOFTAP_COUNT_WEIGHT;
481 else if (countWeight < 0)
482 countWeight = 0;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530483
Jeff Johnson295189b2012-06-20 16:38:30 -0700484 rssicountWeight = rssiWeight + countWeight;
485
486 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 -0700487 __func__, rssiWeight, countWeight, rssicountWeight);
Jeff Johnson295189b2012-06-20 16:38:30 -0700488
489 return(rssicountWeight);
490}
491
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800492
493/*==========================================================================
494 FUNCTION sapInterferenceRssiCount
495
496 DESCRIPTION
497 Function sapInterferenceRssiCount Considers the Adjacent channel rssi
498 and data count(here number of BSS observed)
499
500 DEPENDENCIES
501 NA.
502
503 PARAMETERS
504
505 pSpectCh : Channel Information
506
507 RETURN VALUE
508 NA.
509
510 SIDE EFFECTS
511============================================================================*/
512void sapInterferenceRssiCount(tSapSpectChInfo *pSpectCh)
513{
514 tSapSpectChInfo *pExtSpectCh = NULL;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700515 v_S31_t rssi;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530516
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800517 switch(pSpectCh->chNum)
518 {
519 case CHANNEL_1:
520 pExtSpectCh = (pSpectCh + 1);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530521 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800522 {
523 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530524 rssi = pSpectCh->rssiAgr +
525 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700526 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
527 {
528 pExtSpectCh->rssiAgr = rssi;
529 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530530 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800531 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
532 }
533 pExtSpectCh = (pSpectCh + 2);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530534 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800535 {
536 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530537 rssi = pSpectCh->rssiAgr +
538 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700539 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
540 {
541 pExtSpectCh->rssiAgr = rssi;
542 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800543 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
544 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
545 }
546 pExtSpectCh = (pSpectCh + 3);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530547 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800548 {
549 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530550 rssi = pSpectCh->rssiAgr +
551 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700552 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
553 {
554 pExtSpectCh->rssiAgr = rssi;
555 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800556 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
557 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
558 }
559 pExtSpectCh = (pSpectCh + 4);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530560 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800561 {
562 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530563 rssi = pSpectCh->rssiAgr +
564 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700565 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
566 {
567 pExtSpectCh->rssiAgr = rssi;
568 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530569 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800570 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
571 }
572 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530573
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800574 case CHANNEL_2:
575 pExtSpectCh = (pSpectCh - 1);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530576 if (pExtSpectCh != NULL)
577 {
578 ++pExtSpectCh->bssCount;
579 rssi = pSpectCh->rssiAgr +
580 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
581 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
582 {
583 pExtSpectCh->rssiAgr = rssi;
584 }
585 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
586 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
587 }
588 pExtSpectCh = (pSpectCh + 1);
589 if (pExtSpectCh != NULL)
590 {
591 ++pExtSpectCh->bssCount;
592 rssi = pSpectCh->rssiAgr +
593 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
594 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
595 {
596 pExtSpectCh->rssiAgr = rssi;
597 }
598 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
599 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
600 }
601 pExtSpectCh = (pSpectCh + 2);
602 if (pExtSpectCh != NULL)
603 {
604 ++pExtSpectCh->bssCount;
605 rssi = pSpectCh->rssiAgr +
606 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
607 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
608 {
609 pExtSpectCh->rssiAgr = rssi;
610 }
611 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
612 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
613 }
614 pExtSpectCh = (pSpectCh + 3);
615 if (pExtSpectCh != NULL)
616 {
617 ++pExtSpectCh->bssCount;
618 rssi = pSpectCh->rssiAgr +
619 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
620 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
621 {
622 pExtSpectCh->rssiAgr = rssi;
623 }
624 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
625 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
626 }
627 pExtSpectCh = (pSpectCh + 4);
628 if (pExtSpectCh != NULL)
629 {
630 ++pExtSpectCh->bssCount;
631 rssi = pSpectCh->rssiAgr +
632 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
633 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
634 {
635 pExtSpectCh->rssiAgr = rssi;
636 }
637 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
638 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
639 }
640 break;
641 case CHANNEL_3:
642 pExtSpectCh = (pSpectCh - 2);
643 if (pExtSpectCh != NULL)
644 {
645 ++pExtSpectCh->bssCount;
646 rssi = pSpectCh->rssiAgr +
647 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
648 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
649 {
650 pExtSpectCh->rssiAgr = rssi;
651 }
652 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
653 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
654 }
655 pExtSpectCh = (pSpectCh - 1);
656 if (pExtSpectCh != NULL)
657 {
658 ++pExtSpectCh->bssCount;
659 rssi = pSpectCh->rssiAgr +
660 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
661 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
662 {
663 pExtSpectCh->rssiAgr = rssi;
664 }
665 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
666 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
667 }
668 pExtSpectCh = (pSpectCh + 1);
669 if (pExtSpectCh != NULL)
670 {
671 ++pExtSpectCh->bssCount;
672 rssi = pSpectCh->rssiAgr +
673 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
674 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
675 {
676 pExtSpectCh->rssiAgr = rssi;
677 }
678 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
679 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
680 }
681 pExtSpectCh = (pSpectCh + 2);
682 if (pExtSpectCh != NULL)
683 {
684 ++pExtSpectCh->bssCount;
685 rssi = pSpectCh->rssiAgr +
686 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
687 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
688 {
689 pExtSpectCh->rssiAgr = rssi;
690 }
691 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
692 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
693 }
694 pExtSpectCh = (pSpectCh + 3);
695 if (pExtSpectCh != NULL)
696 {
697 ++pExtSpectCh->bssCount;
698 rssi = pSpectCh->rssiAgr +
699 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
700 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
701 {
702 pExtSpectCh->rssiAgr = rssi;
703 }
704 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
705 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
706 }
707 pExtSpectCh = (pSpectCh + 4);
708 if (pExtSpectCh != NULL)
709 {
710 ++pExtSpectCh->bssCount;
711 rssi = pSpectCh->rssiAgr +
712 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
713 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
714 {
715 pExtSpectCh->rssiAgr = rssi;
716 }
717 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
718 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
719 }
720 break;
721 case CHANNEL_4:
722 pExtSpectCh = (pSpectCh - 3);
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800723 if(pExtSpectCh != NULL)
724 {
725 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530726 rssi = pSpectCh->rssiAgr +
727 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
728 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
729 {
730 pExtSpectCh->rssiAgr = rssi;
731 }
732 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
733 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
734 }
735 pExtSpectCh = (pSpectCh - 2);
736 if (pExtSpectCh != NULL)
737 {
738 ++pExtSpectCh->bssCount;
739 rssi = pSpectCh->rssiAgr +
740 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
741 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
742 {
743 pExtSpectCh->rssiAgr = rssi;
744 }
745 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
746 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
747 }
748 pExtSpectCh = (pSpectCh - 1);
749 if (pExtSpectCh != NULL)
750 {
751 ++pExtSpectCh->bssCount;
752 rssi = pSpectCh->rssiAgr +
753 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700754 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
755 {
756 pExtSpectCh->rssiAgr = rssi;
757 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800758 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
759 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
760 }
761 pExtSpectCh = (pSpectCh + 1);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530762 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800763 {
764 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530765 rssi = pSpectCh->rssiAgr +
766 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
767 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
768 {
769 pExtSpectCh->rssiAgr = rssi;
770 }
771 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
772 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
773 }
774 pExtSpectCh = (pSpectCh + 2);
775 if (pExtSpectCh != NULL)
776 {
777 ++pExtSpectCh->bssCount;
778 rssi = pSpectCh->rssiAgr +
779 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
780 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
781 {
782 pExtSpectCh->rssiAgr = rssi;
783 }
784 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
785 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
786 }
787 pExtSpectCh = (pSpectCh + 3);
788 if (pExtSpectCh != NULL)
789 {
790 ++pExtSpectCh->bssCount;
791 rssi = pSpectCh->rssiAgr +
792 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
793 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
794 {
795 pExtSpectCh->rssiAgr = rssi;
796 }
797 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
798 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
799 }
800 pExtSpectCh = (pSpectCh + 4);
801 if (pExtSpectCh != NULL)
802 {
803 ++pExtSpectCh->bssCount;
804 rssi = pSpectCh->rssiAgr +
805 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
806 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
807 {
808 pExtSpectCh->rssiAgr = rssi;
809 }
810 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
811 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
812 }
813 break;
814
815 case CHANNEL_5:
816 case CHANNEL_6:
817 case CHANNEL_7:
818 pExtSpectCh = (pSpectCh - 4);
819 if (pExtSpectCh != NULL)
820 {
821 ++pExtSpectCh->bssCount;
822 rssi = pSpectCh->rssiAgr +
823 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700824 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
825 {
826 pExtSpectCh->rssiAgr = rssi;
827 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800828 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
829 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
830 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530831 pExtSpectCh = (pSpectCh - 3);
832 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800833 {
834 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530835 rssi = pSpectCh->rssiAgr +
836 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700837 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
838 {
839 pExtSpectCh->rssiAgr = rssi;
840 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800841 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
842 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
843 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530844 pExtSpectCh = (pSpectCh - 2);
845 if (pExtSpectCh != NULL)
846 {
847 ++pExtSpectCh->bssCount;
848 rssi = pSpectCh->rssiAgr +
849 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
850 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
851 {
852 pExtSpectCh->rssiAgr = rssi;
853 }
854 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
855 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
856 }
857 pExtSpectCh = (pSpectCh - 1);
858 if(pExtSpectCh != NULL)
859 {
860 ++pExtSpectCh->bssCount;
861 rssi = pSpectCh->rssiAgr +
862 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
863 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
864 {
865 pExtSpectCh->rssiAgr = rssi;
866 }
867 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
868 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
869 }
870 pExtSpectCh = (pSpectCh + 1);
871 if (pExtSpectCh != NULL)
872 {
873 ++pExtSpectCh->bssCount;
874 rssi = pSpectCh->rssiAgr +
875 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
876 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
877 {
878 pExtSpectCh->rssiAgr = rssi;
879 }
880 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
881 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
882 }
883 pExtSpectCh = (pSpectCh + 2);
884 if(pExtSpectCh != NULL)
885 {
886 ++pExtSpectCh->bssCount;
887 rssi = pSpectCh->rssiAgr +
888 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
889 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
890 {
891 pExtSpectCh->rssiAgr = rssi;
892 }
893 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
894 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
895 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800896 pExtSpectCh = (pSpectCh + 3);
897 if(pExtSpectCh != NULL)
898 {
899 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530900 rssi = pSpectCh->rssiAgr +
901 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
902 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
903 {
904 pExtSpectCh->rssiAgr = rssi;
905 }
906 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
907 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
908 }
909 pExtSpectCh = (pSpectCh + 4);
910 if (pExtSpectCh != NULL)
911 {
912 ++pExtSpectCh->bssCount;
913 rssi = pSpectCh->rssiAgr +
914 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700915 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
916 {
917 pExtSpectCh->rssiAgr = rssi;
918 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800919 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
920 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
921 }
922 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530923
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800924 case CHANNEL_8:
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800925 pExtSpectCh = (pSpectCh - 4);
926 if(pExtSpectCh != NULL)
927 {
928 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530929 rssi = pSpectCh->rssiAgr +
930 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
931 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
932 {
933 pExtSpectCh->rssiAgr = rssi;
934 }
935 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
936 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
937 }
938
939 pExtSpectCh = (pSpectCh - 3);
940 if (pExtSpectCh != NULL)
941 {
942 ++pExtSpectCh->bssCount;
943 rssi = pSpectCh->rssiAgr +
944 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
945 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
946 {
947 pExtSpectCh->rssiAgr = rssi;
948 }
949 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
950 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
951 }
952 pExtSpectCh = (pSpectCh - 2);
953 if (pExtSpectCh != NULL)
954 {
955 ++pExtSpectCh->bssCount;
956 rssi = pSpectCh->rssiAgr +
957 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
958 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
959 {
960 pExtSpectCh->rssiAgr = rssi;
961 }
962 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
963 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
964 }
965 pExtSpectCh = (pSpectCh - 1);
966 if (pExtSpectCh != NULL)
967 {
968 ++pExtSpectCh->bssCount;
969 rssi = pSpectCh->rssiAgr +
970 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
971 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
972 {
973 pExtSpectCh->rssiAgr = rssi;
974 }
975 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
976 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
977 }
978 pExtSpectCh = (pSpectCh + 1);
979 if (pExtSpectCh != NULL)
980 {
981 ++pExtSpectCh->bssCount;
982 rssi = pSpectCh->rssiAgr +
983 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
984 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
985 {
986 pExtSpectCh->rssiAgr = rssi;
987 }
988 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
989 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
990 }
991 pExtSpectCh = (pSpectCh + 2);
992 if (pExtSpectCh != NULL)
993 {
994 ++pExtSpectCh->bssCount;
995 rssi = pSpectCh->rssiAgr +
996 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
997 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
998 {
999 pExtSpectCh->rssiAgr = rssi;
1000 }
1001 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1002 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1003 }
1004 pExtSpectCh = (pSpectCh + 3);
1005 if (pExtSpectCh != NULL)
1006 {
1007 ++pExtSpectCh->bssCount;
1008 rssi = pSpectCh->rssiAgr +
1009 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1010 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1011 {
1012 pExtSpectCh->rssiAgr = rssi;
1013 }
1014 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1015 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1016 }
1017 break;
1018
1019 case CHANNEL_9:
1020 pExtSpectCh = (pSpectCh - 4);
1021 if (pExtSpectCh != NULL)
1022 {
1023 ++pExtSpectCh->bssCount;
1024 rssi = pSpectCh->rssiAgr +
1025 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001026 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1027 {
1028 pExtSpectCh->rssiAgr = rssi;
1029 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001030 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1031 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1032 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301033
1034 pExtSpectCh = (pSpectCh - 3);
1035 if (pExtSpectCh != NULL)
1036 {
1037 ++pExtSpectCh->bssCount;
1038 rssi = pSpectCh->rssiAgr +
1039 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1040 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1041 {
1042 pExtSpectCh->rssiAgr = rssi;
1043 }
1044 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1045 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1046 }
1047 pExtSpectCh = (pSpectCh - 2);
1048 if (pExtSpectCh != NULL)
1049 {
1050 ++pExtSpectCh->bssCount;
1051 rssi = pSpectCh->rssiAgr +
1052 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1053 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1054 {
1055 pExtSpectCh->rssiAgr = rssi;
1056 }
1057 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1058 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1059 }
1060 pExtSpectCh = (pSpectCh - 1);
1061 if (pExtSpectCh != NULL)
1062 {
1063 ++pExtSpectCh->bssCount;
1064 rssi = pSpectCh->rssiAgr +
1065 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1066 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1067 {
1068 pExtSpectCh->rssiAgr = rssi;
1069 }
1070 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1071 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1072 }
1073 pExtSpectCh = (pSpectCh + 1);
1074 if (pExtSpectCh != NULL)
1075 {
1076 ++pExtSpectCh->bssCount;
1077 rssi = pSpectCh->rssiAgr +
1078 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1079 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1080 {
1081 pExtSpectCh->rssiAgr = rssi;
1082 }
1083 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1084 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1085 }
1086 pExtSpectCh = (pSpectCh + 2);
1087 if (pExtSpectCh != NULL)
1088 {
1089 ++pExtSpectCh->bssCount;
1090 rssi = pSpectCh->rssiAgr +
1091 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1092 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1093 {
1094 pExtSpectCh->rssiAgr = rssi;
1095 }
1096 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1097 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1098 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001099 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301100
1101 case CHANNEL_10:
1102 pExtSpectCh = (pSpectCh - 4);
1103 if (pExtSpectCh != NULL)
1104 {
1105 ++pExtSpectCh->bssCount;
1106 rssi = pSpectCh->rssiAgr +
1107 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1108 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1109 {
1110 pExtSpectCh->rssiAgr = rssi;
1111 }
1112 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1113 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1114 }
1115
1116 pExtSpectCh = (pSpectCh - 3);
1117 if (pExtSpectCh != NULL)
1118 {
1119 ++pExtSpectCh->bssCount;
1120 rssi = pSpectCh->rssiAgr +
1121 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1122 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1123 {
1124 pExtSpectCh->rssiAgr = rssi;
1125 }
1126 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1127 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1128 }
1129 pExtSpectCh = (pSpectCh - 2);
1130 if(pExtSpectCh != NULL)
1131 {
1132 ++pExtSpectCh->bssCount;
1133 rssi = pSpectCh->rssiAgr +
1134 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1135 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1136 {
1137 pExtSpectCh->rssiAgr = rssi;
1138 }
1139 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1140 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1141 }
1142 pExtSpectCh = (pSpectCh - 1);
1143 if (pExtSpectCh != NULL)
1144 {
1145 ++pExtSpectCh->bssCount;
1146 rssi = pSpectCh->rssiAgr +
1147 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1148 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1149 {
1150 pExtSpectCh->rssiAgr = rssi;
1151 }
1152 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1153 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1154 }
1155 pExtSpectCh = (pSpectCh + 1);
1156 if (pExtSpectCh != NULL)
1157 {
1158 ++pExtSpectCh->bssCount;
1159 rssi = pSpectCh->rssiAgr +
1160 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1161 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1162 {
1163 pExtSpectCh->rssiAgr = rssi;
1164 }
1165 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1166 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1167 }
1168 break;
1169
1170 case CHANNEL_11:
1171 pExtSpectCh = (pSpectCh - 1);
1172 if (pExtSpectCh != NULL)
1173 {
1174 ++pExtSpectCh->bssCount;
1175 rssi = pSpectCh->rssiAgr +
1176 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1177 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1178 {
1179 pExtSpectCh->rssiAgr = rssi;
1180 }
1181 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1182 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1183 }
1184 pExtSpectCh = (pSpectCh - 2);
1185 if (pExtSpectCh != NULL)
1186 {
1187 ++pExtSpectCh->bssCount;
1188 rssi = pSpectCh->rssiAgr +
1189 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1190 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1191 {
1192 pExtSpectCh->rssiAgr = rssi;
1193 }
1194 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1195 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1196 }
1197 pExtSpectCh = (pSpectCh - 3);
1198 if (pExtSpectCh != NULL)
1199 {
1200 ++pExtSpectCh->bssCount;
1201 rssi = pSpectCh->rssiAgr +
1202 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1203 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1204 {
1205 pExtSpectCh->rssiAgr = rssi;
1206 }
1207 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1208 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1209 }
1210 pExtSpectCh = (pSpectCh - 4);
1211 if (pExtSpectCh != NULL)
1212 {
1213 ++pExtSpectCh->bssCount;
1214 rssi = pSpectCh->rssiAgr +
1215 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1216 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1217 {
1218 pExtSpectCh->rssiAgr = rssi;
1219 }
1220 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1221 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1222 }
1223 break;
1224
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001225 default:
1226 break;
1227 }
1228}
1229
Jeff Johnson295189b2012-06-20 16:38:30 -07001230/*==========================================================================
1231 FUNCTION sapComputeSpectWeight
1232
1233 DESCRIPTION
1234 Main function for computing the weight of each channel in the
1235 spectrum based on the RSSI value of the BSSes on the channel
1236 and number of BSS
1237
1238 DEPENDENCIES
1239 NA.
1240
1241 PARAMETERS
1242
1243 IN
1244 pSpectInfoParams : Pointer to the tSpectInfoParams structure
1245 halHandle : Pointer to HAL handle
1246 pResult : Pointer to tScanResultHandle
1247
1248 RETURN VALUE
1249 void : NULL
1250
1251 SIDE EFFECTS
1252============================================================================*/
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301253void sapComputeSpectWeight( tSapChSelSpectInfo* pSpectInfoParams,
1254 tHalHandle halHandle, tScanResultHandle pResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07001255{
1256 v_S7_t rssi = 0;
1257 v_U8_t chn_num = 0;
1258 v_U8_t channel_id = 0;
1259
1260 tCsrScanResultInfo *pScanResult;
1261 tSapSpectChInfo *pSpectCh = pSpectInfoParams->pSpectCh;
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001262 v_U32_t operatingBand;
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001263 v_U16_t channelWidth;
1264 v_U16_t secondaryChannelOffset;
1265 v_U16_t centerFreq;
1266 v_U16_t vhtSupport;
1267 v_U32_t ieLen = 0;
1268 tSirProbeRespBeacon *pBeaconStruct;
1269 tpAniSirGlobal pMac = (tpAniSirGlobal) halHandle;
Jeff Johnson295189b2012-06-20 16:38:30 -07001270
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +05301271 pBeaconStruct = vos_mem_malloc(sizeof(tSirProbeRespBeacon));
1272 if ( NULL == pBeaconStruct )
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001273 {
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301274 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
1275 "Unable to allocate memory in sapComputeSpectWeight\n");
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001276 return;
1277 }
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001278 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Computing spectral weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001279
1280 /**
1281 * Soft AP specific channel weight calculation using DFS formula
1282 */
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001283 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_OPERATING_BAND, &operatingBand);
Jeff Johnson295189b2012-06-20 16:38:30 -07001284
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301285 pScanResult = sme_ScanResultGetFirst(halHandle, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07001286
1287 while (pScanResult) {
1288 pSpectCh = pSpectInfoParams->pSpectCh;
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001289 // Defining the default values, so that any value will hold the default values
1290 channelWidth = eHT_CHANNEL_WIDTH_20MHZ;
1291 secondaryChannelOffset = PHY_SINGLE_CHANNEL_CENTERED;
1292 vhtSupport = 0;
1293 centerFreq = 0;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301294
1295 if (pScanResult->BssDescriptor.ieFields != NULL)
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001296 {
1297 ieLen = (pScanResult->BssDescriptor.length + sizeof(tANI_U16) + sizeof(tANI_U32) - sizeof(tSirBssDescription));
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +05301298 vos_mem_set((tANI_U8 *) pBeaconStruct, sizeof(tSirProbeRespBeacon), 0);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301299
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001300 if ((sirParseBeaconIE(pMac, pBeaconStruct,(tANI_U8 *)( pScanResult->BssDescriptor.ieFields), ieLen)) == eSIR_SUCCESS)
1301 {
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301302 if (pBeaconStruct->HTCaps.present && pBeaconStruct->HTInfo.present)
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001303 {
1304 channelWidth = pBeaconStruct->HTCaps.supportedChannelWidthSet;
1305 secondaryChannelOffset = pBeaconStruct->HTInfo.secondaryChannelOffset;
1306 if(pBeaconStruct->VHTOperation.present)
1307 {
1308 vhtSupport = pBeaconStruct->VHTOperation.present;
1309 if(pBeaconStruct->VHTOperation.chanWidth > WNI_CFG_VHT_CHANNEL_WIDTH_20_40MHZ)
1310 {
1311 channelWidth = eHT_CHANNEL_WIDTH_80MHZ;
1312 centerFreq = pBeaconStruct->VHTOperation.chanCenterFreqSeg1;
1313 }
1314 }
1315 }
1316 }
1317 }
Madan Mohan Koyyalamudi1e02f7f2012-12-04 16:46:45 -08001318 // Processing for each tCsrScanResultInfo in the tCsrScanResult DLink list
Jeff Johnson295189b2012-06-20 16:38:30 -07001319 for (chn_num = 0; chn_num < pSpectInfoParams->numSpectChans; chn_num++) {
1320
1321 /*
1322 * if the Beacon has channel ID, use it other wise we will
1323 * rely on the channelIdSelf
1324 */
1325 if(pScanResult->BssDescriptor.channelId == 0)
1326 channel_id = pScanResult->BssDescriptor.channelIdSelf;
1327 else
1328 channel_id = pScanResult->BssDescriptor.channelId;
1329
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301330 if (channel_id == pSpectCh->chNum) {
Jeff Johnson295189b2012-06-20 16:38:30 -07001331 if (pSpectCh->rssiAgr < pScanResult->BssDescriptor.rssi)
1332 pSpectCh->rssiAgr = pScanResult->BssDescriptor.rssi;
1333
1334 ++pSpectCh->bssCount; // Increment the count of BSS
1335
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001336 if(operatingBand) // Connsidering the Extension Channel only in a channels
1337 {
1338 /* Updating the received ChannelWidth */
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301339 if (pSpectCh->channelWidth != channelWidth)
1340 pSpectCh->channelWidth = channelWidth;
Madan Mohan Koyyalamudi1e02f7f2012-12-04 16:46:45 -08001341 /* If received ChannelWidth is other than HT20, we need to update the extension channel Params as well */
1342 /* channelWidth == 0, HT20 */
1343 /* channelWidth == 1, HT40 */
1344 /* channelWidth == 2, VHT80*/
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001345 switch(pSpectCh->channelWidth)
1346 {
1347 case eHT_CHANNEL_WIDTH_40MHZ: //HT40
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001348 switch( secondaryChannelOffset)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001349 {
1350 tSapSpectChInfo *pExtSpectCh = NULL;
1351 case PHY_DOUBLE_CHANNEL_LOW_PRIMARY: // Above the Primary Channel
1352 pExtSpectCh = (pSpectCh + 1);
1353 if(pExtSpectCh != NULL)
1354 {
1355 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001356 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001357 // REducing the rssi by -20 and assigning it to Extension channel
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001358 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1359 {
1360 pExtSpectCh->rssiAgr = rssi;
1361 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001362 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1363 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1364 }
1365 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301366
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001367 case PHY_DOUBLE_CHANNEL_HIGH_PRIMARY: // Below the Primary channel
1368 pExtSpectCh = (pSpectCh - 1);
1369 if(pExtSpectCh != NULL)
1370 {
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001371 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1372 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1373 {
1374 pExtSpectCh->rssiAgr = rssi;
1375 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001376 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1377 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1378 ++pExtSpectCh->bssCount;
1379 }
1380 break;
1381 }
1382 break;
1383 case eHT_CHANNEL_WIDTH_80MHZ: // VHT80
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001384 if((centerFreq - channel_id) == 6)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001385 {
1386 tSapSpectChInfo *pExtSpectCh = NULL;
1387 pExtSpectCh = (pSpectCh + 1);
1388 if(pExtSpectCh != NULL)
1389 {
1390 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001391 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1392 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1393 {
1394 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -20 and assigning it to Subband 1
1395 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001396 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1397 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1398 }
1399 pExtSpectCh = (pSpectCh + 2);
1400 if(pExtSpectCh != NULL)
1401 {
1402 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001403 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1404 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1405 {
1406 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -30 and assigning it to Subband 2
1407 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001408 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1409 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1410 }
1411 pExtSpectCh = (pSpectCh + 3);
1412 if(pExtSpectCh != NULL)
1413 {
1414 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001415 rssi = pSpectCh->rssiAgr + SAP_SUBBAND3_RSSI_EFFECT_PRIMARY;
1416 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1417 {
1418 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -40 and assigning it to Subband 3
1419 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001420 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1421 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301422 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001423 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001424 else if((centerFreq - channel_id) == 2)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001425 {
1426 tSapSpectChInfo *pExtSpectCh = NULL;
1427 pExtSpectCh = (pSpectCh - 1 );
1428 if(pExtSpectCh != NULL)
1429 {
1430 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001431 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1432 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1433 {
1434 pExtSpectCh->rssiAgr = rssi;
1435 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001436 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1437 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1438 }
1439 pExtSpectCh = (pSpectCh + 1);
1440 if(pExtSpectCh != NULL)
1441 {
1442 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001443 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1444 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1445 {
1446 pExtSpectCh->rssiAgr = rssi;
1447 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001448 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1449 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1450 }
1451 pExtSpectCh = (pSpectCh + 2);
1452 if(pExtSpectCh != NULL)
1453 {
1454 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001455 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1456 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1457 {
1458 pExtSpectCh->rssiAgr = rssi;
1459 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001460 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1461 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1462 }
1463 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001464 else if((centerFreq - channel_id) == -2)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001465 {
1466 tSapSpectChInfo *pExtSpectCh = NULL;
1467 pExtSpectCh = (pSpectCh - 1 );
1468 if(pExtSpectCh != NULL)
1469 {
1470 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001471 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1472 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1473 {
1474 pExtSpectCh->rssiAgr = rssi;
1475 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001476 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1477 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1478 }
1479 pExtSpectCh = (pSpectCh - 2);
1480 if(pExtSpectCh != NULL)
1481 {
1482 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001483 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1484 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1485 {
1486 pExtSpectCh->rssiAgr = rssi;
1487 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001488 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1489 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1490 }
1491 pExtSpectCh = (pSpectCh + 1);
1492 if(pExtSpectCh != NULL)
1493 {
1494 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001495 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1496 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1497 {
1498 pExtSpectCh->rssiAgr = rssi;
1499 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001500 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1501 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1502 }
1503 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001504 else if((centerFreq - channel_id) == -6)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001505 {
1506 tSapSpectChInfo *pExtSpectCh = NULL;
1507 pExtSpectCh = (pSpectCh - 1 );
1508 if(pExtSpectCh != NULL)
1509 {
1510 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001511 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1512 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1513 {
1514 pExtSpectCh->rssiAgr = rssi;
1515 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001516 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1517 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1518 }
1519 pExtSpectCh = (pSpectCh - 2);
1520 if(pExtSpectCh != NULL)
1521 {
1522 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001523 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1524 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1525 {
1526 pExtSpectCh->rssiAgr = rssi;
1527 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001528 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1529 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1530 }
1531 pExtSpectCh = (pSpectCh - 3);
1532 if(pExtSpectCh != NULL)
1533 {
1534 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001535 rssi = pSpectCh->rssiAgr + SAP_SUBBAND3_RSSI_EFFECT_PRIMARY;
1536 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1537 {
1538 pExtSpectCh->rssiAgr = rssi;
1539 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001540 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1541 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1542 }
1543 }
1544 break;
1545 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301546 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001547 else if(operatingBand == RF_SUBBAND_2_4_GHZ)
1548 {
1549 sapInterferenceRssiCount(pSpectCh);
1550 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001551
Jeff Johnson295189b2012-06-20 16:38:30 -07001552 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301553 "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 -08001554 __func__, pScanResult->BssDescriptor.channelIdSelf, pScanResult->BssDescriptor.channelId, pScanResult->BssDescriptor.rssi, pSpectCh->bssCount, pScanResult,pSpectCh->channelWidth,secondaryChannelOffset,centerFreq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001555 pSpectCh++;
1556 break;
1557 } else {
1558 pSpectCh++;
1559 }
1560 }
1561
1562 pScanResult = sme_ScanResultGetNext(halHandle, pResult);
1563 }
1564
1565 // Calculate the weights for all channels in the spectrum pSpectCh
1566 pSpectCh = pSpectInfoParams->pSpectCh;
1567
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001568 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Spectrum Channels Weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001569
1570 for (chn_num = 0; chn_num < (pSpectInfoParams->numSpectChans); chn_num++) {
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301571
Jeff Johnson295189b2012-06-20 16:38:30 -07001572 /*
1573 rssi : Maximum received signal strength among all BSS on that channel
1574 bssCount : Number of BSS on that channel
1575 */
1576
1577 rssi = (v_S7_t)pSpectCh->rssiAgr;
1578
1579 pSpectCh->weight = SAPDFS_NORMALISE_1000 * sapweightRssiCount(rssi, pSpectCh->bssCount);
1580
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301581 //------ Debug Info ------
1582 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
1583 "In %s, Chan=%d Weight= %d rssiAgr=%d bssCount=%d", __func__,
1584 pSpectCh->chNum, pSpectCh->weight,
1585 pSpectCh->rssiAgr, pSpectCh->bssCount);
1586 //------ Debug Info ------
Jeff Johnson295189b2012-06-20 16:38:30 -07001587 pSpectCh++;
1588 }
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +05301589 vos_mem_free(pBeaconStruct);
Jeff Johnson295189b2012-06-20 16:38:30 -07001590}
1591
1592/*==========================================================================
1593 FUNCTION sapChanSelExit
1594
1595 DESCRIPTION
1596 Exit function for free out the allocated memory, to be called
1597 at the end of the dfsSelectChannel function
1598
1599 DEPENDENCIES
1600 NA.
1601
1602 PARAMETERS
1603
1604 IN
1605 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1606
1607 RETURN VALUE
1608 void : NULL
1609
1610 SIDE EFFECTS
1611============================================================================*/
1612void sapChanSelExit( tSapChSelSpectInfo *pSpectInfoParams )
1613{
1614 // Free all the allocated memory
1615 vos_mem_free(pSpectInfoParams->pSpectCh);
1616}
1617
1618/*==========================================================================
1619 FUNCTION sapSortChlWeight
1620
1621 DESCRIPTION
1622 Funtion to sort the channels with the least weight first
1623
1624 DEPENDENCIES
1625 NA.
1626
1627 PARAMETERS
1628
1629 IN
1630 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1631
1632 RETURN VALUE
1633 void : NULL
1634
1635 SIDE EFFECTS
1636============================================================================*/
1637void sapSortChlWeight(tSapChSelSpectInfo *pSpectInfoParams)
1638{
1639 tSapSpectChInfo temp;
1640
1641 tSapSpectChInfo *pSpectCh = NULL;
1642 v_U32_t i = 0, j = 0, minWeightIndex = 0;
1643
1644 pSpectCh = pSpectInfoParams->pSpectCh;
1645#ifdef SOFTAP_CHANNEL_RANGE
1646 // Sorting the channels as per weights
1647 for (i = 0; i < pSpectInfoParams->numSpectChans; i++) {
1648 minWeightIndex = i;
1649 for( j = i + 1; j < pSpectInfoParams->numSpectChans; j++) {
1650 if(pSpectCh[j].weight < pSpectCh[minWeightIndex].weight) {
1651 minWeightIndex = j;
1652 }
1653 }
1654 if(minWeightIndex != i) {
1655 vos_mem_copy(&temp, &pSpectCh[minWeightIndex], sizeof(*pSpectCh));
1656 vos_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], sizeof(*pSpectCh));
1657 vos_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
1658 }
1659 }
1660#else
1661 // Sorting the channels as per weights
1662 for (i = 0; i < SPECT_24GHZ_CH_COUNT; i++) {
1663 minWeightIndex = i;
1664 for( j = i + 1; j < SPECT_24GHZ_CH_COUNT; j++) {
1665 if(pSpectCh[j].weight < pSpectCh[minWeightIndex].weight) {
1666 minWeightIndex = j;
1667 }
1668 }
1669 if(minWeightIndex != i) {
1670 vos_mem_copy(&temp, &pSpectCh[minWeightIndex], sizeof(*pSpectCh));
1671 vos_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], sizeof(*pSpectCh));
1672 vos_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
1673 }
1674 }
1675#endif
1676
1677 /* For testing */
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001678 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 -07001679 pSpectCh = pSpectInfoParams->pSpectCh;
1680 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
1681 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 -07001682 __func__, pSpectCh->chNum, pSpectCh->weight, pSpectCh->rssiAgr, pSpectCh->bssCount);
Jeff Johnson295189b2012-06-20 16:38:30 -07001683 pSpectCh++;
1684 }
1685
1686}
1687
1688/*==========================================================================
1689 FUNCTION sapSelectChannel
1690
1691 DESCRIPTION
1692 Runs a algorithm to select the best channel to operate in based on BSS
1693 rssi and bss count on each channel
1694
1695 DEPENDENCIES
1696 NA.
1697
1698 PARAMETERS
1699
1700 IN
1701 halHandle : Pointer to HAL handle
1702 pResult : Pointer to tScanResultHandle
1703
1704 RETURN VALUE
1705 v_U8_t : Success - channel number, Fail - zero
1706
1707 SIDE EFFECTS
1708============================================================================*/
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07001709v_U8_t sapSelectChannel(tHalHandle halHandle, ptSapContext pSapCtx, tScanResultHandle pScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07001710{
1711 // DFS param object holding all the data req by the algo
1712 tSapChSelSpectInfo oSpectInfoParams = {NULL,0};
1713 tSapChSelSpectInfo *pSpectInfoParams = &oSpectInfoParams; // Memory? NB
Jeff Johnson295189b2012-06-20 16:38:30 -07001714 v_U8_t bestChNum = 0;
1715#ifdef SOFTAP_CHANNEL_RANGE
1716 v_U32_t startChannelNum;
1717 v_U32_t endChannelNum;
Gopichand Nakkala936715f2013-03-18 19:48:10 +05301718 v_U32_t operatingBand = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001719 v_U8_t count = 0;
1720#endif
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001721 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 -07001722
1723 // Set to zero tSapChSelParams
1724 //vos_mem_zero(&sapChSelParams, sizeof(sapChSelParams));
1725
1726 // Initialize the structure pointed by pSpectInfoParams
1727 if(sapChanSelInit( halHandle, pSpectInfoParams) != eSAP_TRUE ) {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001728 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "In %s, Ch Select initialization failed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001729 return SAP_CHANNEL_NOT_SELECTED;
1730 }
1731
1732 // Compute the weight of the entire spectrum in the operating band
1733 sapComputeSpectWeight( pSpectInfoParams, halHandle, pScanResult);
1734
1735 // Sort the 20M channel list as per the computed weights, lesser weight first.
1736 sapSortChlWeight(pSpectInfoParams);
1737
1738#ifdef SOFTAP_CHANNEL_RANGE
1739 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_START_CHANNEL, &startChannelNum);
1740 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_END_CHANNEL, &endChannelNum);
1741 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_OPERATING_BAND, &operatingBand);
1742
1743 /*Loop till get the best channel in the given range */
1744 for(count=0; count < pSpectInfoParams->numSpectChans ; count++)
1745 {
1746 if((startChannelNum <= pSpectInfoParams->pSpectCh[count].chNum)&&
1747 ( endChannelNum >= pSpectInfoParams->pSpectCh[count].chNum))
1748 {
Bansidhar Gopalachari1e56faa2013-07-25 19:30:20 +05301749 if(bestChNum == 0)
1750 {
1751 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[count].chNum;
1752 }
1753 else
1754 {
1755 if(operatingBand == RF_SUBBAND_2_4_GHZ)
1756 {
1757 /* Give preference to Non-overlap channels */
1758 if(((pSpectInfoParams->pSpectCh[count].chNum == CHANNEL_1) ||
1759 (pSpectInfoParams->pSpectCh[count].chNum == CHANNEL_6) ||
1760 (pSpectInfoParams->pSpectCh[count].chNum == CHANNEL_11))&&
1761 (pSpectInfoParams->pSpectCh[count].weight == 0))
1762 {
1763 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[count].chNum;
1764 break;
1765 }
1766 }
1767 }
1768 }
1769 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001770#else
1771 // Get the first channel in sorted array as best 20M Channel
1772 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[0].chNum;
Jeff Johnson295189b2012-06-20 16:38:30 -07001773#endif
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001774
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07001775 //Select Best Channel from Channel List if Configured
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07001776 bestChNum = sapSelectPreferredChannelFromChannelList(bestChNum, pSapCtx, pSpectInfoParams);
Jeff Johnson295189b2012-06-20 16:38:30 -07001777
1778 // Free all the allocated memory
1779 sapChanSelExit(pSpectInfoParams);
1780
1781 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 -07001782 __func__, bestChNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07001783 if (bestChNum > 0 && bestChNum <= 252)
1784 return bestChNum;
1785 else
1786 return SAP_CHANNEL_NOT_SELECTED;
1787}
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001788