blob: aa4c7462c60552dfeb6273fc1007794ef50a1782 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Peng Xu2446a892014-09-05 17:21:18 +05302 * Copyright (c) 2012-2014 The Linux Foundation. All rights reserved.
Kiet Lam0fb93dd2014-02-19 00:32:59 -08003 *
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.
Gopichand Nakkala92f07d82013-01-08 21:16:34 -080020 */
Kiet Lam0fb93dd2014-02-19 00:32:59 -080021
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
Jeff Johnson295189b2012-06-20 16:38:30 -070028/*===========================================================================
29
30 s a p C h S e l e c t . C
Jeff Johnson295189b2012-06-20 16:38:30 -070031 OVERVIEW:
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053032
Jeff Johnson295189b2012-06-20 16:38:30 -070033 This software unit holds the implementation of the WLAN SAP modules
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053034 functions for channel selection.
Jeff Johnson295189b2012-06-20 16:38:30 -070035
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053036 DEPENDENCIES:
Jeff Johnson295189b2012-06-20 16:38:30 -070037
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053038 Are listed for each API below.
Jeff Johnson295189b2012-06-20 16:38:30 -070039===========================================================================*/
40
41/*===========================================================================
42
43 EDIT HISTORY FOR FILE
44
45
46 This section contains comments describing changes made to the module.
47 Notice that changes are listed in reverse chronological order.
48
49
50
51 when who what, where, why
52---------- --- --------------------------------------------------------
532010-03-15 SOFTAP Created module
54
55===========================================================================*/
56
57
58/*--------------------------------------------------------------------------
59 Include Files
60------------------------------------------------------------------------*/
61#include "vos_trace.h"
62#include "csrApi.h"
63#include "sme_Api.h"
64#include "sapChSelect.h"
65#include "sapInternal.h"
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -080066#ifdef ANI_OS_TYPE_QNX
67#include "stdio.h"
68#endif
Peng Xuafc34e32014-09-25 13:23:55 +053069#include "wlan_hdd_main.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070070
71/*--------------------------------------------------------------------------
72 Function definitions
73--------------------------------------------------------------------------*/
74
75/*--------------------------------------------------------------------------
76 Defines
77--------------------------------------------------------------------------*/
78#define SAP_DEBUG
79
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -070080#define IS_RSSI_VALID( extRssi, rssi ) \
81( \
82 ((extRssi < rssi)?eANI_BOOLEAN_TRUE:eANI_BOOLEAN_FALSE) \
83)
84
Leo Chang0b0e45a2013-12-15 15:18:55 -080085#ifdef FEATURE_WLAN_CH_AVOID
86extern safeChannelType safeChannels[];
87#endif /* FEATURE_WLAN_CH_AVOID */
88
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070089/*==========================================================================
90 FUNCTION sapCleanupChannelList
91
92 DESCRIPTION
93 Function sapCleanupChannelList frees up the memory allocated to the channel list.
94
95 DEPENDENCIES
96 NA.
97
98 PARAMETERS
99
100 IN
101 NULL
102
103 RETURN VALUE
104 NULL
105============================================================================*/
106
107void sapCleanupChannelList(void)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700108{
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700109 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_SAP, NULL);
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530110 ptSapContext pSapCtx;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700111
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700112 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO,
113 "Cleaning up the channel list structure");
114
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530115 if (NULL == pvosGCtx)
116 {
117 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
118 "SAP Global Context is NULL");
119 return ;
120 }
121
122 pSapCtx = VOS_GET_SAP_CB(pvosGCtx);
123 if (NULL == pSapCtx)
124 {
125 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
126 "SAP Context is NULL");
127 return ;
128 }
129
130 pSapCtx->SapChnlList.numChannel = 0;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700131 vos_mem_free(pSapCtx->SapChnlList.channelList);
132 pSapCtx->SapChnlList.channelList = NULL;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700133}
134
Peng Xu7d410f42014-09-09 12:15:47 +0530135typedef struct
136{
137 v_U16_t chStartNum;
138 v_U32_t weight;
139} sapAcsChannelInfo;
140
141#define ACS_WEIGHT_MAX 4444
142
Peng Xu117eab42014-09-25 13:33:27 +0530143sapAcsChannelInfo acsHT40Channels5G[ ] = {
Peng Xu7d410f42014-09-09 12:15:47 +0530144 {36, ACS_WEIGHT_MAX},
145 {44, ACS_WEIGHT_MAX},
146 {52, ACS_WEIGHT_MAX},
147 {60, ACS_WEIGHT_MAX},
148 {100, ACS_WEIGHT_MAX},
149 {108, ACS_WEIGHT_MAX},
150 {116, ACS_WEIGHT_MAX},
151 {124, ACS_WEIGHT_MAX},
152 {132, ACS_WEIGHT_MAX},
153 {140, ACS_WEIGHT_MAX},
154 {149, ACS_WEIGHT_MAX},
155 {157, ACS_WEIGHT_MAX},
156};
157
158sapAcsChannelInfo acsHT80Channels[ ] = {
159 {36, ACS_WEIGHT_MAX},
160 {52, ACS_WEIGHT_MAX},
161 {100, ACS_WEIGHT_MAX},
162 {116, ACS_WEIGHT_MAX},
163 {132, ACS_WEIGHT_MAX},
164 {149, ACS_WEIGHT_MAX},
165};
166
Rajesh Babu Prathipatiff748c02014-09-09 13:19:57 +0530167sapAcsChannelInfo acsHT40Channels24G[ ] = {
168 {1, ACS_WEIGHT_MAX},
169 {2, ACS_WEIGHT_MAX},
170 {3, ACS_WEIGHT_MAX},
171 {4, ACS_WEIGHT_MAX},
172 {9, ACS_WEIGHT_MAX},
173};
174
Peng Xu117eab42014-09-25 13:33:27 +0530175typedef enum {
176 CHWIDTH_HT20,
177 CHWIDTH_HT40,
178 CHWIDTH_HT80,
179} eChannelWidthInfo;
180
181#define CHANNEL_165 165
182
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700183/*==========================================================================
184 FUNCTION sapSetPreferredChannel
185
186 DESCRIPTION
187 Function sapSetPreferredChannel sets the channel list which has been configured
188 into sap context (pSapCtx) which will be used at the time of best channel selection.
189
190 DEPENDENCIES
191 NA.
192
193 PARAMETERS
194
195 IN
196 *ptr: pointer having the command followed by the arguments in string format
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700197
198 RETURN VALUE
199 int: return 0 when success else returns error code.
200============================================================================*/
201
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800202int sapSetPreferredChannel(tANI_U8* ptr)
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700203{
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700204
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700205 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_SAP, NULL);
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530206 ptSapContext pSapCtx;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700207 tANI_U8* param;
208 int tempInt;
209 int j;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700210
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700211 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700212 "Enter: %s", __func__);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700213
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530214 if (NULL == pvosGCtx)
215 {
216 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
217 "SAP Global Context is NULL");
218 return -EINVAL;
219 }
220
221 pSapCtx = VOS_GET_SAP_CB(pvosGCtx);
222 if (NULL == pSapCtx)
223 {
224 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
225 "SAP Context is NULL");
226 return -EINVAL;
227 }
228
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700229 if (NULL != pSapCtx->SapChnlList.channelList)
230 {
231 sapCleanupChannelList();
232 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700233
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800234 param = strchr(ptr, ' ');
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700235 /*no argument after the command*/
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800236 if (NULL == param)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700237 {
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800238 return -EINVAL;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700239 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700240
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700241 /*no space after the command*/
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800242 else if (SPACE_ASCII_VALUE != *param)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700243 {
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800244 return -EINVAL;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700245 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700246
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700247 param++;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700248
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700249 /*removing empty spaces*/
250 while((SPACE_ASCII_VALUE == *param)&& ('\0' != *param) ) param++;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700251
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700252 /*no argument followed by spaces*/
253 if('\0' == *param)
254 {
255 return -EINVAL;
256 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700257
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700258 /*getting the first argument ie the number of channels*/
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800259 if (sscanf(param, "%d ", &tempInt) != 1)
260 {
261 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800262 "%s: Cannot get number of channels from input", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800263 return -EINVAL;
264 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700265
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700266 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800267 "%s: Number of channel added are: %d", __func__, tempInt);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700268
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800269 if (tempInt <= 0 || tempInt > 255)
270 {
271 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800272 "%s: Invalid Number of channel received", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800273 return -EINVAL;
274 }
275
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700276 /*allocating space for the desired number of channels*/
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530277 pSapCtx->SapChnlList.channelList = (v_U8_t *)vos_mem_malloc(tempInt);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700278
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530279 if (NULL == pSapCtx->SapChnlList.channelList)
280 {
281 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
282 "In %s, VOS_MALLOC_ERR", __func__);
283 return -EINVAL;
284 }
285
286 pSapCtx->SapChnlList.numChannel = tempInt;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700287 for(j=0;j<pSapCtx->SapChnlList.numChannel;j++)
288 {
289
290 /*param pointing to the beginning of first space after number of channels*/
291 param = strpbrk( param, " " );
292 /*no channel list after the number of channels argument*/
293 if (NULL == param)
294 {
295 sapCleanupChannelList();
296 return -EINVAL;
297 }
298
299 param++;
300
301 /*removing empty space*/
302 while((SPACE_ASCII_VALUE == *param) && ('\0' != *param) ) param++;
303
304 /*no channel list after the number of channels argument and spaces*/
305 if( '\0' == *param )
306 {
307 sapCleanupChannelList();
308 return -EINVAL;
309 }
310
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800311 if (sscanf(param, "%d ", &tempInt) != 1)
312 {
313 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800314 "%s: Cannot read channel number", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800315 sapCleanupChannelList();
316 return -EINVAL;
317 }
318 if (tempInt < 0 || tempInt > 255)
319 {
320 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800321 "%s: Invalid channel number received", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800322 sapCleanupChannelList();
323 return -EINVAL;
324 }
325
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700326 pSapCtx->SapChnlList.channelList[j] = tempInt;
327
328 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800329 "%s: Channel %d added to preferred channel list",
330 __func__, pSapCtx->SapChnlList.channelList[j] );
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700331
332 }
333
334 /*extra arguments check*/
335 param = strpbrk( param, " " );
336 if (NULL != param)
337 {
338 while((SPACE_ASCII_VALUE == *param) && ('\0' != *param) ) param++;
339
340 if('\0' != *param)
341 {
342 sapCleanupChannelList();
343 return -EINVAL;
344 }
345 }
346
347 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700348 "Exit: %s", __func__);
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700349
350 return 0;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700351}
352
353/*==========================================================================
354 FUNCTION sapSelectPreferredChannelFromChannelList
355
356 DESCRIPTION
357 Function sapSelectPreferredChannelFromChannelList calculates the best channel
358 among the configured channel list. If channel list not configured then returns
359 the best channel calculated among all the channel list.
360
361 DEPENDENCIES
362 NA.
363
364 PARAMETERS
365
366 IN
367 *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure
368 bestChNum: best channel already calculated among all the chanels
369 pSapCtx: having info of channel list from which best channel is selected
370
371 RETURN VALUE
372 v_U8_t: best channel
373============================================================================*/
374v_U8_t sapSelectPreferredChannelFromChannelList(v_U8_t bestChNum,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700375 ptSapContext pSapCtx,
376 tSapChSelSpectInfo *pSpectInfoParams)
377{
378 v_U8_t j = 0;
379 v_U8_t count = 0;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700380
381 //If Channel List is not Configured don't do anything
382 //Else return the Best Channel from the Channel List
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700383 if((NULL == pSapCtx->SapChnlList.channelList) ||
384 (NULL == pSpectInfoParams) ||
385 (0 == pSapCtx->SapChnlList.numChannel))
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700386 {
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700387 return bestChNum;
388 }
389
390 if (bestChNum > 0 && bestChNum <= 252)
391 {
392 for(count=0; count < pSpectInfoParams->numSpectChans ; count++)
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700393 {
394 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[count].chNum;
395 // Select the best channel from allowed list
396 for(j=0;j< pSapCtx->SapChnlList.numChannel;j++)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700397 {
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700398 if( (pSapCtx->SapChnlList.channelList[j]) == bestChNum)
399 {
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700400 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
401 "Best channel computed from Channel List is: %d",
402 bestChNum);
403 return bestChNum;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700404 }
405 }
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700406 }
407
408 return SAP_CHANNEL_NOT_SELECTED;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700409 }
410 else
411 return SAP_CHANNEL_NOT_SELECTED;
412}
413
414
Jeff Johnson295189b2012-06-20 16:38:30 -0700415/*==========================================================================
416 FUNCTION sapChanSelInit
417
418 DESCRIPTION
419 Function sapChanSelInit allocates the memory, intializes the
420 structures used by the channel selection algorithm
421
422 DEPENDENCIES
423 NA.
424
425 PARAMETERS
426
427 IN
428 *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure
429
430 RETURN VALUE
431 v_BOOL_t: Success or FAIL
432
433 SIDE EFFECTS
434============================================================================*/
435v_BOOL_t sapChanSelInit(tHalHandle halHandle, tSapChSelSpectInfo *pSpectInfoParams)
436{
437 tSapSpectChInfo *pSpectCh = NULL;
438 v_U8_t *pChans = NULL;
439 v_U16_t channelnum = 0;
440 tpAniSirGlobal pMac = PMAC_STRUCT(halHandle);
Leo Chang0b0e45a2013-12-15 15:18:55 -0800441#ifdef FEATURE_WLAN_CH_AVOID
442 v_U16_t i;
443 v_BOOL_t chSafe = VOS_TRUE;
444#endif /* FEATURE_WLAN_CH_AVOID */
Jeff Johnson295189b2012-06-20 16:38:30 -0700445
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700446 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700447
448 // Channels for that 2.4GHz band
449 //Considered only for 2.4GHz need to change in future to support 5GHz support
450 pSpectInfoParams->numSpectChans = pMac->scan.base20MHzChannels.numChannels;
451
452 // Allocate memory for weight computation of 2.4GHz
453 pSpectCh = (tSapSpectChInfo *)vos_mem_malloc((pSpectInfoParams->numSpectChans) * sizeof(*pSpectCh));
454
455 if(pSpectCh == NULL) {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700456 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "In %s, VOS_MALLOC_ERR", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700457 return eSAP_FALSE;
458 }
459
460 vos_mem_zero(pSpectCh, (pSpectInfoParams->numSpectChans) * sizeof(*pSpectCh));
461
462 // Initialize the pointers in the DfsParams to the allocated memory
463 pSpectInfoParams->pSpectCh = pSpectCh;
464
465 pChans = pMac->scan.base20MHzChannels.channelList;
466
467 // Fill the channel number in the spectrum in the operating freq band
468 for (channelnum = 0; channelnum < pSpectInfoParams->numSpectChans; channelnum++) {
Leo Chang0b0e45a2013-12-15 15:18:55 -0800469#ifdef FEATURE_WLAN_CH_AVOID
470 chSafe = VOS_TRUE;
471 for(i = 0; i < NUM_20MHZ_RF_CHANNELS; i++)
472 {
473 if((safeChannels[i].channelNumber == *pChans) &&
474 (VOS_FALSE == safeChannels[i].isSafe))
475 {
476 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO,
477 "%s : CH %d is not safe", __func__, *pChans);
478 chSafe = VOS_FALSE;
479 break;
480 }
481 }
482#endif /* FEATURE_WLAN_CH_AVOID */
Jeff Johnson295189b2012-06-20 16:38:30 -0700483
484 if(*pChans == 14 ) //OFDM rates are not supported on channel 14
Abhishek Singhb51853c2014-03-13 18:26:41 +0530485 {
486 pChans++;
Kaushik, Sushante054e472014-09-26 19:45:48 +0530487 pSpectCh++;
Jeff Johnson295189b2012-06-20 16:38:30 -0700488 continue;
Abhishek Singhb51853c2014-03-13 18:26:41 +0530489 }
Leo Chang0b0e45a2013-12-15 15:18:55 -0800490#ifdef FEATURE_WLAN_CH_AVOID
491 if (VOS_TRUE == chSafe)
492 {
493#endif /* FEATURE_WLAN_CH_AVOID */
494 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_DEBUG,
495 "%s : Available Ch %d",
496 __func__, *pChans);
497 pSpectCh->chNum = *pChans;
498 pSpectCh->valid = eSAP_TRUE;
499 // Initialise for all channels
500 pSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
501 // Initialise 20MHz for all the Channels
502 pSpectCh->channelWidth = SOFTAP_HT20_CHANNELWIDTH;
Leo Chang0b0e45a2013-12-15 15:18:55 -0800503#ifdef FEATURE_WLAN_CH_AVOID
504 }
505#endif /* FEATURE_WLAN_CH_AVOID */
Kaushik, Sushante054e472014-09-26 19:45:48 +0530506 pSpectCh++;
Jeff Johnson295189b2012-06-20 16:38:30 -0700507 pChans++;
508 }
509 return eSAP_TRUE;
510}
511
512/*==========================================================================
513 FUNCTION sapweightRssiCount
514
515 DESCRIPTION
516 Function weightRssiCount calculates the channel weight due to rssi
517 and data count(here number of BSS observed)
518
519 DEPENDENCIES
520 NA.
521
522 PARAMETERS
523
524 IN
525 rssi : Max signal strength receieved from a BSS for the channel
526 count : Number of BSS observed in the channel
527
528 RETURN VALUE
529 v_U32_t : Calculated channel weight based on above two
530
531 SIDE EFFECTS
532============================================================================*/
533v_U32_t sapweightRssiCount(v_S7_t rssi, v_U16_t count)
534{
535 v_S31_t rssiWeight=0;
536 v_S31_t countWeight=0;
537 v_U32_t rssicountWeight=0;
538
539 // Weight from RSSI
540 rssiWeight = SOFTAP_RSSI_WEIGHT * (rssi - SOFTAP_MIN_RSSI)
541 /(SOFTAP_MAX_RSSI - SOFTAP_MIN_RSSI);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530542
Jeff Johnson295189b2012-06-20 16:38:30 -0700543 if(rssiWeight > SOFTAP_RSSI_WEIGHT)
544 rssiWeight = SOFTAP_RSSI_WEIGHT;
545 else if (rssiWeight < 0)
546 rssiWeight = 0;
547
548 // Weight from data count
549 countWeight = SOFTAP_COUNT_WEIGHT * (count - SOFTAP_MIN_COUNT)
550 /(SOFTAP_MAX_COUNT - SOFTAP_MIN_COUNT);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530551
Jeff Johnson295189b2012-06-20 16:38:30 -0700552 if(countWeight > SOFTAP_COUNT_WEIGHT)
553 countWeight = SOFTAP_COUNT_WEIGHT;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530554
Jeff Johnson295189b2012-06-20 16:38:30 -0700555 rssicountWeight = rssiWeight + countWeight;
556
557 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 -0700558 __func__, rssiWeight, countWeight, rssicountWeight);
Jeff Johnson295189b2012-06-20 16:38:30 -0700559
560 return(rssicountWeight);
561}
562
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800563
564/*==========================================================================
565 FUNCTION sapInterferenceRssiCount
566
567 DESCRIPTION
568 Function sapInterferenceRssiCount Considers the Adjacent channel rssi
569 and data count(here number of BSS observed)
570
571 DEPENDENCIES
572 NA.
573
574 PARAMETERS
575
576 pSpectCh : Channel Information
577
578 RETURN VALUE
579 NA.
580
581 SIDE EFFECTS
582============================================================================*/
583void sapInterferenceRssiCount(tSapSpectChInfo *pSpectCh)
584{
585 tSapSpectChInfo *pExtSpectCh = NULL;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700586 v_S31_t rssi;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530587
Abhishek Singh4eb79062014-04-10 14:48:14 +0530588 if (NULL == pSpectCh)
589 {
590 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
591 "%s: pSpectCh is NULL", __func__);
592 return;
593 }
594
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800595 switch(pSpectCh->chNum)
596 {
597 case CHANNEL_1:
598 pExtSpectCh = (pSpectCh + 1);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530599 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800600 {
601 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530602 rssi = pSpectCh->rssiAgr +
603 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700604 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
605 {
606 pExtSpectCh->rssiAgr = rssi;
607 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530608 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800609 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
610 }
611 pExtSpectCh = (pSpectCh + 2);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530612 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800613 {
614 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530615 rssi = pSpectCh->rssiAgr +
616 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700617 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
618 {
619 pExtSpectCh->rssiAgr = rssi;
620 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800621 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
622 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
623 }
624 pExtSpectCh = (pSpectCh + 3);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530625 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800626 {
627 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530628 rssi = pSpectCh->rssiAgr +
629 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700630 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
631 {
632 pExtSpectCh->rssiAgr = rssi;
633 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800634 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
635 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
636 }
637 pExtSpectCh = (pSpectCh + 4);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530638 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800639 {
640 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530641 rssi = pSpectCh->rssiAgr +
642 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700643 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
644 {
645 pExtSpectCh->rssiAgr = rssi;
646 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530647 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800648 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
649 }
650 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530651
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800652 case CHANNEL_2:
653 pExtSpectCh = (pSpectCh - 1);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530654 if (pExtSpectCh != NULL)
655 {
656 ++pExtSpectCh->bssCount;
657 rssi = pSpectCh->rssiAgr +
658 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
659 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
660 {
661 pExtSpectCh->rssiAgr = rssi;
662 }
663 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
664 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
665 }
666 pExtSpectCh = (pSpectCh + 1);
667 if (pExtSpectCh != NULL)
668 {
669 ++pExtSpectCh->bssCount;
670 rssi = pSpectCh->rssiAgr +
671 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
672 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
673 {
674 pExtSpectCh->rssiAgr = rssi;
675 }
676 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;
683 rssi = pSpectCh->rssiAgr +
684 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
685 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
686 {
687 pExtSpectCh->rssiAgr = rssi;
688 }
689 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
690 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
691 }
692 pExtSpectCh = (pSpectCh + 3);
693 if (pExtSpectCh != NULL)
694 {
695 ++pExtSpectCh->bssCount;
696 rssi = pSpectCh->rssiAgr +
697 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
698 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
699 {
700 pExtSpectCh->rssiAgr = rssi;
701 }
702 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
703 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
704 }
705 pExtSpectCh = (pSpectCh + 4);
706 if (pExtSpectCh != NULL)
707 {
708 ++pExtSpectCh->bssCount;
709 rssi = pSpectCh->rssiAgr +
710 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
711 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
712 {
713 pExtSpectCh->rssiAgr = rssi;
714 }
715 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
716 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
717 }
718 break;
719 case CHANNEL_3:
720 pExtSpectCh = (pSpectCh - 2);
721 if (pExtSpectCh != NULL)
722 {
723 ++pExtSpectCh->bssCount;
724 rssi = pSpectCh->rssiAgr +
725 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
726 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
727 {
728 pExtSpectCh->rssiAgr = rssi;
729 }
730 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
731 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
732 }
733 pExtSpectCh = (pSpectCh - 1);
734 if (pExtSpectCh != NULL)
735 {
736 ++pExtSpectCh->bssCount;
737 rssi = pSpectCh->rssiAgr +
738 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
739 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
740 {
741 pExtSpectCh->rssiAgr = rssi;
742 }
743 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
744 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
745 }
746 pExtSpectCh = (pSpectCh + 1);
747 if (pExtSpectCh != NULL)
748 {
749 ++pExtSpectCh->bssCount;
750 rssi = pSpectCh->rssiAgr +
751 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
752 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
753 {
754 pExtSpectCh->rssiAgr = rssi;
755 }
756 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
757 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
758 }
759 pExtSpectCh = (pSpectCh + 2);
760 if (pExtSpectCh != NULL)
761 {
762 ++pExtSpectCh->bssCount;
763 rssi = pSpectCh->rssiAgr +
764 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
765 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
766 {
767 pExtSpectCh->rssiAgr = rssi;
768 }
769 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
770 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
771 }
772 pExtSpectCh = (pSpectCh + 3);
773 if (pExtSpectCh != NULL)
774 {
775 ++pExtSpectCh->bssCount;
776 rssi = pSpectCh->rssiAgr +
777 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
778 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
779 {
780 pExtSpectCh->rssiAgr = rssi;
781 }
782 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
783 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
784 }
785 pExtSpectCh = (pSpectCh + 4);
786 if (pExtSpectCh != NULL)
787 {
788 ++pExtSpectCh->bssCount;
789 rssi = pSpectCh->rssiAgr +
790 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
791 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
792 {
793 pExtSpectCh->rssiAgr = rssi;
794 }
795 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
796 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
797 }
798 break;
799 case CHANNEL_4:
800 pExtSpectCh = (pSpectCh - 3);
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800801 if(pExtSpectCh != NULL)
802 {
803 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530804 rssi = pSpectCh->rssiAgr +
805 SAP_24GHZ_THIRD_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 pExtSpectCh = (pSpectCh - 2);
814 if (pExtSpectCh != NULL)
815 {
816 ++pExtSpectCh->bssCount;
817 rssi = pSpectCh->rssiAgr +
818 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
819 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
820 {
821 pExtSpectCh->rssiAgr = rssi;
822 }
823 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
824 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
825 }
826 pExtSpectCh = (pSpectCh - 1);
827 if (pExtSpectCh != NULL)
828 {
829 ++pExtSpectCh->bssCount;
830 rssi = pSpectCh->rssiAgr +
831 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700832 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
833 {
834 pExtSpectCh->rssiAgr = rssi;
835 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800836 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
837 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
838 }
839 pExtSpectCh = (pSpectCh + 1);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530840 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800841 {
842 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530843 rssi = pSpectCh->rssiAgr +
844 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
845 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
846 {
847 pExtSpectCh->rssiAgr = rssi;
848 }
849 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
850 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
851 }
852 pExtSpectCh = (pSpectCh + 2);
853 if (pExtSpectCh != NULL)
854 {
855 ++pExtSpectCh->bssCount;
856 rssi = pSpectCh->rssiAgr +
857 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
858 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
859 {
860 pExtSpectCh->rssiAgr = rssi;
861 }
862 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
863 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
864 }
865 pExtSpectCh = (pSpectCh + 3);
866 if (pExtSpectCh != NULL)
867 {
868 ++pExtSpectCh->bssCount;
869 rssi = pSpectCh->rssiAgr +
870 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
871 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
872 {
873 pExtSpectCh->rssiAgr = rssi;
874 }
875 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
876 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
877 }
878 pExtSpectCh = (pSpectCh + 4);
879 if (pExtSpectCh != NULL)
880 {
881 ++pExtSpectCh->bssCount;
882 rssi = pSpectCh->rssiAgr +
883 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
884 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
885 {
886 pExtSpectCh->rssiAgr = rssi;
887 }
888 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
889 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
890 }
891 break;
892
893 case CHANNEL_5:
894 case CHANNEL_6:
895 case CHANNEL_7:
896 pExtSpectCh = (pSpectCh - 4);
897 if (pExtSpectCh != NULL)
898 {
899 ++pExtSpectCh->bssCount;
900 rssi = pSpectCh->rssiAgr +
901 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700902 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
903 {
904 pExtSpectCh->rssiAgr = rssi;
905 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800906 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
907 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
908 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530909 pExtSpectCh = (pSpectCh - 3);
910 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800911 {
912 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530913 rssi = pSpectCh->rssiAgr +
914 SAP_24GHZ_THIRD_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 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530922 pExtSpectCh = (pSpectCh - 2);
923 if (pExtSpectCh != NULL)
924 {
925 ++pExtSpectCh->bssCount;
926 rssi = pSpectCh->rssiAgr +
927 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
928 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
929 {
930 pExtSpectCh->rssiAgr = rssi;
931 }
932 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
933 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
934 }
935 pExtSpectCh = (pSpectCh - 1);
936 if(pExtSpectCh != NULL)
937 {
938 ++pExtSpectCh->bssCount;
939 rssi = pSpectCh->rssiAgr +
940 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
941 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
942 {
943 pExtSpectCh->rssiAgr = rssi;
944 }
945 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
946 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
947 }
948 pExtSpectCh = (pSpectCh + 1);
949 if (pExtSpectCh != NULL)
950 {
951 ++pExtSpectCh->bssCount;
952 rssi = pSpectCh->rssiAgr +
953 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
954 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
955 {
956 pExtSpectCh->rssiAgr = rssi;
957 }
958 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
959 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
960 }
961 pExtSpectCh = (pSpectCh + 2);
962 if(pExtSpectCh != NULL)
963 {
964 ++pExtSpectCh->bssCount;
965 rssi = pSpectCh->rssiAgr +
966 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
967 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
968 {
969 pExtSpectCh->rssiAgr = rssi;
970 }
971 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
972 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
973 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800974 pExtSpectCh = (pSpectCh + 3);
975 if(pExtSpectCh != NULL)
976 {
977 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530978 rssi = pSpectCh->rssiAgr +
979 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
980 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
981 {
982 pExtSpectCh->rssiAgr = rssi;
983 }
984 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
985 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
986 }
987 pExtSpectCh = (pSpectCh + 4);
988 if (pExtSpectCh != NULL)
989 {
990 ++pExtSpectCh->bssCount;
991 rssi = pSpectCh->rssiAgr +
992 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700993 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
994 {
995 pExtSpectCh->rssiAgr = rssi;
996 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800997 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
998 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
999 }
1000 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301001
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001002 case CHANNEL_8:
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001003 pExtSpectCh = (pSpectCh - 4);
1004 if(pExtSpectCh != NULL)
1005 {
1006 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301007 rssi = pSpectCh->rssiAgr +
1008 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1009 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1010 {
1011 pExtSpectCh->rssiAgr = rssi;
1012 }
1013 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1014 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1015 }
1016
1017 pExtSpectCh = (pSpectCh - 3);
1018 if (pExtSpectCh != NULL)
1019 {
1020 ++pExtSpectCh->bssCount;
1021 rssi = pSpectCh->rssiAgr +
1022 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1023 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1024 {
1025 pExtSpectCh->rssiAgr = rssi;
1026 }
1027 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1028 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1029 }
1030 pExtSpectCh = (pSpectCh - 2);
1031 if (pExtSpectCh != NULL)
1032 {
1033 ++pExtSpectCh->bssCount;
1034 rssi = pSpectCh->rssiAgr +
1035 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1036 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1037 {
1038 pExtSpectCh->rssiAgr = rssi;
1039 }
1040 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1041 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1042 }
1043 pExtSpectCh = (pSpectCh - 1);
1044 if (pExtSpectCh != NULL)
1045 {
1046 ++pExtSpectCh->bssCount;
1047 rssi = pSpectCh->rssiAgr +
1048 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1049 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1050 {
1051 pExtSpectCh->rssiAgr = rssi;
1052 }
1053 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1054 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1055 }
1056 pExtSpectCh = (pSpectCh + 1);
1057 if (pExtSpectCh != NULL)
1058 {
1059 ++pExtSpectCh->bssCount;
1060 rssi = pSpectCh->rssiAgr +
1061 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1062 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1063 {
1064 pExtSpectCh->rssiAgr = rssi;
1065 }
1066 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1067 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1068 }
1069 pExtSpectCh = (pSpectCh + 2);
1070 if (pExtSpectCh != NULL)
1071 {
1072 ++pExtSpectCh->bssCount;
1073 rssi = pSpectCh->rssiAgr +
1074 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1075 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1076 {
1077 pExtSpectCh->rssiAgr = rssi;
1078 }
1079 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1080 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1081 }
1082 pExtSpectCh = (pSpectCh + 3);
1083 if (pExtSpectCh != NULL)
1084 {
1085 ++pExtSpectCh->bssCount;
1086 rssi = pSpectCh->rssiAgr +
1087 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1088 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1089 {
1090 pExtSpectCh->rssiAgr = rssi;
1091 }
1092 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1093 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1094 }
1095 break;
1096
1097 case CHANNEL_9:
1098 pExtSpectCh = (pSpectCh - 4);
1099 if (pExtSpectCh != NULL)
1100 {
1101 ++pExtSpectCh->bssCount;
1102 rssi = pSpectCh->rssiAgr +
1103 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001104 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1105 {
1106 pExtSpectCh->rssiAgr = rssi;
1107 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001108 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1109 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1110 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301111
1112 pExtSpectCh = (pSpectCh - 3);
1113 if (pExtSpectCh != NULL)
1114 {
1115 ++pExtSpectCh->bssCount;
1116 rssi = pSpectCh->rssiAgr +
1117 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1118 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1119 {
1120 pExtSpectCh->rssiAgr = rssi;
1121 }
1122 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1123 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1124 }
1125 pExtSpectCh = (pSpectCh - 2);
1126 if (pExtSpectCh != NULL)
1127 {
1128 ++pExtSpectCh->bssCount;
1129 rssi = pSpectCh->rssiAgr +
1130 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1131 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1132 {
1133 pExtSpectCh->rssiAgr = rssi;
1134 }
1135 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1136 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1137 }
1138 pExtSpectCh = (pSpectCh - 1);
1139 if (pExtSpectCh != NULL)
1140 {
1141 ++pExtSpectCh->bssCount;
1142 rssi = pSpectCh->rssiAgr +
1143 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1144 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1145 {
1146 pExtSpectCh->rssiAgr = rssi;
1147 }
1148 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1149 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1150 }
1151 pExtSpectCh = (pSpectCh + 1);
1152 if (pExtSpectCh != NULL)
1153 {
1154 ++pExtSpectCh->bssCount;
1155 rssi = pSpectCh->rssiAgr +
1156 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1157 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1158 {
1159 pExtSpectCh->rssiAgr = rssi;
1160 }
1161 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1162 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1163 }
1164 pExtSpectCh = (pSpectCh + 2);
1165 if (pExtSpectCh != NULL)
1166 {
1167 ++pExtSpectCh->bssCount;
1168 rssi = pSpectCh->rssiAgr +
1169 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1170 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1171 {
1172 pExtSpectCh->rssiAgr = rssi;
1173 }
1174 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1175 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1176 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001177 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301178
1179 case CHANNEL_10:
1180 pExtSpectCh = (pSpectCh - 4);
1181 if (pExtSpectCh != NULL)
1182 {
1183 ++pExtSpectCh->bssCount;
1184 rssi = pSpectCh->rssiAgr +
1185 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1186 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1187 {
1188 pExtSpectCh->rssiAgr = rssi;
1189 }
1190 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1191 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1192 }
1193
1194 pExtSpectCh = (pSpectCh - 3);
1195 if (pExtSpectCh != NULL)
1196 {
1197 ++pExtSpectCh->bssCount;
1198 rssi = pSpectCh->rssiAgr +
1199 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1200 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1201 {
1202 pExtSpectCh->rssiAgr = rssi;
1203 }
1204 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1205 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1206 }
1207 pExtSpectCh = (pSpectCh - 2);
1208 if(pExtSpectCh != NULL)
1209 {
1210 ++pExtSpectCh->bssCount;
1211 rssi = pSpectCh->rssiAgr +
1212 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1213 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1214 {
1215 pExtSpectCh->rssiAgr = rssi;
1216 }
1217 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1218 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1219 }
1220 pExtSpectCh = (pSpectCh - 1);
1221 if (pExtSpectCh != NULL)
1222 {
1223 ++pExtSpectCh->bssCount;
1224 rssi = pSpectCh->rssiAgr +
1225 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1226 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1227 {
1228 pExtSpectCh->rssiAgr = rssi;
1229 }
1230 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1231 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1232 }
1233 pExtSpectCh = (pSpectCh + 1);
1234 if (pExtSpectCh != NULL)
1235 {
1236 ++pExtSpectCh->bssCount;
1237 rssi = pSpectCh->rssiAgr +
1238 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1239 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1240 {
1241 pExtSpectCh->rssiAgr = rssi;
1242 }
1243 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1244 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1245 }
1246 break;
1247
1248 case CHANNEL_11:
1249 pExtSpectCh = (pSpectCh - 1);
1250 if (pExtSpectCh != NULL)
1251 {
1252 ++pExtSpectCh->bssCount;
1253 rssi = pSpectCh->rssiAgr +
1254 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1255 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1256 {
1257 pExtSpectCh->rssiAgr = rssi;
1258 }
1259 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1260 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1261 }
1262 pExtSpectCh = (pSpectCh - 2);
1263 if (pExtSpectCh != NULL)
1264 {
1265 ++pExtSpectCh->bssCount;
1266 rssi = pSpectCh->rssiAgr +
1267 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1268 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1269 {
1270 pExtSpectCh->rssiAgr = rssi;
1271 }
1272 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1273 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1274 }
1275 pExtSpectCh = (pSpectCh - 3);
1276 if (pExtSpectCh != NULL)
1277 {
1278 ++pExtSpectCh->bssCount;
1279 rssi = pSpectCh->rssiAgr +
1280 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1281 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1282 {
1283 pExtSpectCh->rssiAgr = rssi;
1284 }
1285 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1286 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1287 }
1288 pExtSpectCh = (pSpectCh - 4);
1289 if (pExtSpectCh != NULL)
1290 {
1291 ++pExtSpectCh->bssCount;
1292 rssi = pSpectCh->rssiAgr +
1293 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1294 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1295 {
1296 pExtSpectCh->rssiAgr = rssi;
1297 }
1298 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1299 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1300 }
1301 break;
1302
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001303 default:
1304 break;
1305 }
1306}
1307
Jeff Johnson295189b2012-06-20 16:38:30 -07001308/*==========================================================================
1309 FUNCTION sapComputeSpectWeight
1310
1311 DESCRIPTION
1312 Main function for computing the weight of each channel in the
1313 spectrum based on the RSSI value of the BSSes on the channel
1314 and number of BSS
1315
1316 DEPENDENCIES
1317 NA.
1318
1319 PARAMETERS
1320
1321 IN
1322 pSpectInfoParams : Pointer to the tSpectInfoParams structure
1323 halHandle : Pointer to HAL handle
1324 pResult : Pointer to tScanResultHandle
1325
1326 RETURN VALUE
1327 void : NULL
1328
1329 SIDE EFFECTS
1330============================================================================*/
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301331void sapComputeSpectWeight( tSapChSelSpectInfo* pSpectInfoParams,
1332 tHalHandle halHandle, tScanResultHandle pResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07001333{
1334 v_S7_t rssi = 0;
1335 v_U8_t chn_num = 0;
1336 v_U8_t channel_id = 0;
1337
1338 tCsrScanResultInfo *pScanResult;
1339 tSapSpectChInfo *pSpectCh = pSpectInfoParams->pSpectCh;
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001340 v_U32_t operatingBand;
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001341 v_U16_t channelWidth;
1342 v_U16_t secondaryChannelOffset;
1343 v_U16_t centerFreq;
1344 v_U16_t vhtSupport;
1345 v_U32_t ieLen = 0;
1346 tSirProbeRespBeacon *pBeaconStruct;
1347 tpAniSirGlobal pMac = (tpAniSirGlobal) halHandle;
Jeff Johnson295189b2012-06-20 16:38:30 -07001348
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +05301349 pBeaconStruct = vos_mem_malloc(sizeof(tSirProbeRespBeacon));
1350 if ( NULL == pBeaconStruct )
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001351 {
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301352 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Sushant Kaushik87787972015-09-11 16:05:00 +05301353 "Unable to allocate memory in sapComputeSpectWeight");
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001354 return;
1355 }
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001356 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Computing spectral weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001357
1358 /**
1359 * Soft AP specific channel weight calculation using DFS formula
1360 */
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001361 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_OPERATING_BAND, &operatingBand);
Jeff Johnson295189b2012-06-20 16:38:30 -07001362
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301363 pScanResult = sme_ScanResultGetFirst(halHandle, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07001364
1365 while (pScanResult) {
1366 pSpectCh = pSpectInfoParams->pSpectCh;
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001367 // Defining the default values, so that any value will hold the default values
1368 channelWidth = eHT_CHANNEL_WIDTH_20MHZ;
1369 secondaryChannelOffset = PHY_SINGLE_CHANNEL_CENTERED;
1370 vhtSupport = 0;
1371 centerFreq = 0;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301372
1373 if (pScanResult->BssDescriptor.ieFields != NULL)
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001374 {
1375 ieLen = (pScanResult->BssDescriptor.length + sizeof(tANI_U16) + sizeof(tANI_U32) - sizeof(tSirBssDescription));
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +05301376 vos_mem_set((tANI_U8 *) pBeaconStruct, sizeof(tSirProbeRespBeacon), 0);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301377
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001378 if ((sirParseBeaconIE(pMac, pBeaconStruct,(tANI_U8 *)( pScanResult->BssDescriptor.ieFields), ieLen)) == eSIR_SUCCESS)
1379 {
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301380 if (pBeaconStruct->HTCaps.present && pBeaconStruct->HTInfo.present)
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001381 {
1382 channelWidth = pBeaconStruct->HTCaps.supportedChannelWidthSet;
1383 secondaryChannelOffset = pBeaconStruct->HTInfo.secondaryChannelOffset;
1384 if(pBeaconStruct->VHTOperation.present)
1385 {
1386 vhtSupport = pBeaconStruct->VHTOperation.present;
1387 if(pBeaconStruct->VHTOperation.chanWidth > WNI_CFG_VHT_CHANNEL_WIDTH_20_40MHZ)
1388 {
1389 channelWidth = eHT_CHANNEL_WIDTH_80MHZ;
1390 centerFreq = pBeaconStruct->VHTOperation.chanCenterFreqSeg1;
1391 }
1392 }
1393 }
1394 }
1395 }
Madan Mohan Koyyalamudi1e02f7f2012-12-04 16:46:45 -08001396 // Processing for each tCsrScanResultInfo in the tCsrScanResult DLink list
Jeff Johnson295189b2012-06-20 16:38:30 -07001397 for (chn_num = 0; chn_num < pSpectInfoParams->numSpectChans; chn_num++) {
1398
1399 /*
1400 * if the Beacon has channel ID, use it other wise we will
1401 * rely on the channelIdSelf
1402 */
1403 if(pScanResult->BssDescriptor.channelId == 0)
1404 channel_id = pScanResult->BssDescriptor.channelIdSelf;
1405 else
1406 channel_id = pScanResult->BssDescriptor.channelId;
1407
krunal sonic39d9592014-02-04 11:54:24 -08001408 if (pSpectCh && (channel_id == pSpectCh->chNum)) {
Jeff Johnson295189b2012-06-20 16:38:30 -07001409 if (pSpectCh->rssiAgr < pScanResult->BssDescriptor.rssi)
1410 pSpectCh->rssiAgr = pScanResult->BssDescriptor.rssi;
1411
1412 ++pSpectCh->bssCount; // Increment the count of BSS
1413
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001414 if(operatingBand) // Connsidering the Extension Channel only in a channels
1415 {
1416 /* Updating the received ChannelWidth */
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301417 if (pSpectCh->channelWidth != channelWidth)
1418 pSpectCh->channelWidth = channelWidth;
Madan Mohan Koyyalamudi1e02f7f2012-12-04 16:46:45 -08001419 /* If received ChannelWidth is other than HT20, we need to update the extension channel Params as well */
1420 /* channelWidth == 0, HT20 */
1421 /* channelWidth == 1, HT40 */
1422 /* channelWidth == 2, VHT80*/
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001423 switch(pSpectCh->channelWidth)
1424 {
1425 case eHT_CHANNEL_WIDTH_40MHZ: //HT40
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001426 switch( secondaryChannelOffset)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001427 {
1428 tSapSpectChInfo *pExtSpectCh = NULL;
1429 case PHY_DOUBLE_CHANNEL_LOW_PRIMARY: // Above the Primary Channel
1430 pExtSpectCh = (pSpectCh + 1);
1431 if(pExtSpectCh != NULL)
1432 {
1433 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001434 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001435 // REducing the rssi by -20 and assigning it to Extension channel
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001436 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1437 {
1438 pExtSpectCh->rssiAgr = rssi;
1439 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001440 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1441 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1442 }
1443 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301444
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001445 case PHY_DOUBLE_CHANNEL_HIGH_PRIMARY: // Below the Primary channel
1446 pExtSpectCh = (pSpectCh - 1);
1447 if(pExtSpectCh != NULL)
1448 {
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001449 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1450 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1451 {
1452 pExtSpectCh->rssiAgr = rssi;
1453 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001454 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1455 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1456 ++pExtSpectCh->bssCount;
1457 }
1458 break;
1459 }
1460 break;
1461 case eHT_CHANNEL_WIDTH_80MHZ: // VHT80
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001462 if((centerFreq - channel_id) == 6)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001463 {
1464 tSapSpectChInfo *pExtSpectCh = NULL;
1465 pExtSpectCh = (pSpectCh + 1);
1466 if(pExtSpectCh != NULL)
1467 {
1468 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001469 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1470 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1471 {
1472 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -20 and assigning it to Subband 1
1473 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001474 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1475 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1476 }
1477 pExtSpectCh = (pSpectCh + 2);
1478 if(pExtSpectCh != NULL)
1479 {
1480 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001481 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1482 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1483 {
1484 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -30 and assigning it to Subband 2
1485 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001486 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1487 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1488 }
1489 pExtSpectCh = (pSpectCh + 3);
1490 if(pExtSpectCh != NULL)
1491 {
1492 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001493 rssi = pSpectCh->rssiAgr + SAP_SUBBAND3_RSSI_EFFECT_PRIMARY;
1494 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1495 {
1496 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -40 and assigning it to Subband 3
1497 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001498 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1499 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301500 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001501 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001502 else if((centerFreq - channel_id) == 2)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001503 {
1504 tSapSpectChInfo *pExtSpectCh = NULL;
1505 pExtSpectCh = (pSpectCh - 1 );
1506 if(pExtSpectCh != NULL)
1507 {
1508 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001509 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1510 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1511 {
1512 pExtSpectCh->rssiAgr = rssi;
1513 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001514 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1515 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1516 }
1517 pExtSpectCh = (pSpectCh + 1);
1518 if(pExtSpectCh != NULL)
1519 {
1520 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001521 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1522 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1523 {
1524 pExtSpectCh->rssiAgr = rssi;
1525 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001526 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1527 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1528 }
1529 pExtSpectCh = (pSpectCh + 2);
1530 if(pExtSpectCh != NULL)
1531 {
1532 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001533 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1534 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1535 {
1536 pExtSpectCh->rssiAgr = rssi;
1537 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001538 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1539 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1540 }
1541 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001542 else if((centerFreq - channel_id) == -2)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001543 {
1544 tSapSpectChInfo *pExtSpectCh = NULL;
1545 pExtSpectCh = (pSpectCh - 1 );
1546 if(pExtSpectCh != NULL)
1547 {
1548 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001549 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1550 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1551 {
1552 pExtSpectCh->rssiAgr = rssi;
1553 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001554 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1555 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1556 }
1557 pExtSpectCh = (pSpectCh - 2);
1558 if(pExtSpectCh != NULL)
1559 {
1560 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001561 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1562 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1563 {
1564 pExtSpectCh->rssiAgr = rssi;
1565 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001566 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1567 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1568 }
1569 pExtSpectCh = (pSpectCh + 1);
1570 if(pExtSpectCh != NULL)
1571 {
1572 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001573 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1574 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1575 {
1576 pExtSpectCh->rssiAgr = rssi;
1577 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001578 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1579 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1580 }
1581 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001582 else if((centerFreq - channel_id) == -6)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001583 {
1584 tSapSpectChInfo *pExtSpectCh = NULL;
1585 pExtSpectCh = (pSpectCh - 1 );
1586 if(pExtSpectCh != NULL)
1587 {
1588 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001589 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1590 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1591 {
1592 pExtSpectCh->rssiAgr = rssi;
1593 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001594 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1595 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1596 }
1597 pExtSpectCh = (pSpectCh - 2);
1598 if(pExtSpectCh != NULL)
1599 {
1600 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001601 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1602 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1603 {
1604 pExtSpectCh->rssiAgr = rssi;
1605 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001606 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1607 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1608 }
1609 pExtSpectCh = (pSpectCh - 3);
1610 if(pExtSpectCh != NULL)
1611 {
1612 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001613 rssi = pSpectCh->rssiAgr + SAP_SUBBAND3_RSSI_EFFECT_PRIMARY;
1614 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1615 {
1616 pExtSpectCh->rssiAgr = rssi;
1617 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001618 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1619 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1620 }
1621 }
1622 break;
1623 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301624 }
Leela Venkata Kiran Kumar Reddy Chirala9f6566c2014-09-05 19:06:58 +05301625 else if(operatingBand == eSAP_RF_SUBBAND_2_4_GHZ)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001626 {
1627 sapInterferenceRssiCount(pSpectCh);
1628 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001629
Jeff Johnson295189b2012-06-20 16:38:30 -07001630 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Sushant Kaushik87787972015-09-11 16:05:00 +05301631 "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 ",
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001632 __func__, pScanResult->BssDescriptor.channelIdSelf, pScanResult->BssDescriptor.channelId, pScanResult->BssDescriptor.rssi, pSpectCh->bssCount, pScanResult,pSpectCh->channelWidth,secondaryChannelOffset,centerFreq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001633 pSpectCh++;
1634 break;
1635 } else {
1636 pSpectCh++;
1637 }
1638 }
1639
1640 pScanResult = sme_ScanResultGetNext(halHandle, pResult);
1641 }
1642
1643 // Calculate the weights for all channels in the spectrum pSpectCh
1644 pSpectCh = pSpectInfoParams->pSpectCh;
1645
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001646 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Spectrum Channels Weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001647
1648 for (chn_num = 0; chn_num < (pSpectInfoParams->numSpectChans); chn_num++) {
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301649
Jeff Johnson295189b2012-06-20 16:38:30 -07001650 /*
1651 rssi : Maximum received signal strength among all BSS on that channel
1652 bssCount : Number of BSS on that channel
1653 */
1654
1655 rssi = (v_S7_t)pSpectCh->rssiAgr;
1656
Abhishek Singh906b91f2015-07-02 12:25:52 +05301657 pSpectCh->weight =
1658 SAPDFS_NORMALISE_1000 * sapweightRssiCount(rssi, pSpectCh->bssCount);
1659 pSpectCh->weight_copy = pSpectCh->weight;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301660 //------ Debug Info ------
1661 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
1662 "In %s, Chan=%d Weight= %d rssiAgr=%d bssCount=%d", __func__,
1663 pSpectCh->chNum, pSpectCh->weight,
1664 pSpectCh->rssiAgr, pSpectCh->bssCount);
1665 //------ Debug Info ------
Jeff Johnson295189b2012-06-20 16:38:30 -07001666 pSpectCh++;
1667 }
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +05301668 vos_mem_free(pBeaconStruct);
Jeff Johnson295189b2012-06-20 16:38:30 -07001669}
1670
1671/*==========================================================================
1672 FUNCTION sapChanSelExit
1673
1674 DESCRIPTION
1675 Exit function for free out the allocated memory, to be called
1676 at the end of the dfsSelectChannel function
1677
1678 DEPENDENCIES
1679 NA.
1680
1681 PARAMETERS
1682
1683 IN
1684 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1685
1686 RETURN VALUE
1687 void : NULL
1688
1689 SIDE EFFECTS
1690============================================================================*/
1691void sapChanSelExit( tSapChSelSpectInfo *pSpectInfoParams )
1692{
1693 // Free all the allocated memory
1694 vos_mem_free(pSpectInfoParams->pSpectCh);
1695}
1696
1697/*==========================================================================
1698 FUNCTION sapSortChlWeight
1699
1700 DESCRIPTION
1701 Funtion to sort the channels with the least weight first
1702
1703 DEPENDENCIES
1704 NA.
1705
1706 PARAMETERS
1707
1708 IN
1709 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1710
1711 RETURN VALUE
1712 void : NULL
1713
1714 SIDE EFFECTS
1715============================================================================*/
1716void sapSortChlWeight(tSapChSelSpectInfo *pSpectInfoParams)
1717{
1718 tSapSpectChInfo temp;
1719
1720 tSapSpectChInfo *pSpectCh = NULL;
1721 v_U32_t i = 0, j = 0, minWeightIndex = 0;
1722
1723 pSpectCh = pSpectInfoParams->pSpectCh;
Jeff Johnson295189b2012-06-20 16:38:30 -07001724 for (i = 0; i < pSpectInfoParams->numSpectChans; i++) {
1725 minWeightIndex = i;
1726 for( j = i + 1; j < pSpectInfoParams->numSpectChans; j++) {
1727 if(pSpectCh[j].weight < pSpectCh[minWeightIndex].weight) {
1728 minWeightIndex = j;
1729 }
1730 }
1731 if(minWeightIndex != i) {
1732 vos_mem_copy(&temp, &pSpectCh[minWeightIndex], sizeof(*pSpectCh));
1733 vos_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], sizeof(*pSpectCh));
1734 vos_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
1735 }
1736 }
Peng Xu7d410f42014-09-09 12:15:47 +05301737}
1738
1739/*==========================================================================
1740 FUNCTION sapSortChlWeightHT80
1741
1742 DESCRIPTION
1743 Funtion to sort the channels with the least weight first for HT80 channels
1744
1745 DEPENDENCIES
1746 NA.
1747
1748 PARAMETERS
1749
1750 IN
1751 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1752
1753 RETURN VALUE
1754 void : NULL
1755
1756 SIDE EFFECTS
1757============================================================================*/
1758void sapSortChlWeightHT80(tSapChSelSpectInfo *pSpectInfoParams)
1759{
Rajesh Babu Prathipatiaf5ceac2014-09-09 13:10:25 +05301760 v_U8_t i, j, n;
Peng Xu7d410f42014-09-09 12:15:47 +05301761 tSapSpectChInfo *pSpectInfo;
Rajesh Babu Prathipatiaf5ceac2014-09-09 13:10:25 +05301762 v_U8_t minIdx;
Peng Xu7d410f42014-09-09 12:15:47 +05301763
1764 pSpectInfo = pSpectInfoParams->pSpectCh;
Rajesh Babu Prathipatiaf5ceac2014-09-09 13:10:25 +05301765 /* for each HT80 channel, calculate the combined weight of the
1766 four 20MHz weight */
Peng Xu7d410f42014-09-09 12:15:47 +05301767 for (i = 0; i < ARRAY_SIZE(acsHT80Channels); i++)
1768 {
1769 for (j = 0; j < pSpectInfoParams->numSpectChans; j++)
1770 {
1771 if ( pSpectInfo[j].chNum == acsHT80Channels[i].chStartNum )
1772 break;
1773 }
Peng Xu117eab42014-09-25 13:33:27 +05301774 if (j == pSpectInfoParams->numSpectChans)
1775 continue;
Peng Xu7d410f42014-09-09 12:15:47 +05301776
1777 /*found the channel, add the 4 adjacent channels' weight*/
1778 if (((pSpectInfo[j].chNum +4) == pSpectInfo[j+1].chNum) &&
1779 ((pSpectInfo[j].chNum +8) == pSpectInfo[j+2].chNum) &&
1780 ((pSpectInfo[j].chNum +12) == pSpectInfo[j+3].chNum))
1781 {
1782 acsHT80Channels[i].weight = pSpectInfo[j].weight +
1783 pSpectInfo[j+1].weight +
1784 pSpectInfo[j+2].weight +
1785 pSpectInfo[j+3].weight;
Rajesh Babu Prathipatiaf5ceac2014-09-09 13:10:25 +05301786 /* find best channel among 4 channels as the primary channel */
Rajesh Babu Prathipati32ddabf2014-09-11 16:08:59 +05301787 if ((pSpectInfo[j].weight + pSpectInfo[j+1].weight) <
1788 (pSpectInfo[j+2].weight + pSpectInfo[j+3].weight))
Rajesh Babu Prathipatiaf5ceac2014-09-09 13:10:25 +05301789 {
Rajesh Babu Prathipati32ddabf2014-09-11 16:08:59 +05301790 /* lower 2 channels are better choice */
1791 if (pSpectInfo[j].weight < pSpectInfo[j+1].weight)
1792 minIdx = 0;
1793 else
1794 minIdx = 1;
1795 }
1796 else
1797 {
1798 /* upper 2 channels are better choice */
1799 if (pSpectInfo[j+2].weight <= pSpectInfo[j+3].weight)
1800 minIdx = 2;
1801 else
1802 minIdx = 3;
Rajesh Babu Prathipatiaf5ceac2014-09-09 13:10:25 +05301803 }
1804
1805 /* set all 4 channels to max value first, then reset the
1806 best channel as the selected primary channel, update its
1807 weightage with the combined weight value */
1808 for (n=0; n<4; n++)
Abhishek Singh906b91f2015-07-02 12:25:52 +05301809 pSpectInfo[j+n].weight = ACS_WEIGHT_MAX * 4;
Rajesh Babu Prathipatiaf5ceac2014-09-09 13:10:25 +05301810
1811 pSpectInfo[j+minIdx].weight = acsHT80Channels[i].weight;
Peng Xu7d410f42014-09-09 12:15:47 +05301812 }
Rajesh Babu Prathipati2bc30592014-09-09 13:05:26 +05301813 else
1814 {
1815 /* some channels does not exist in pSectInfo array,
1816 skip this channel and those in the same HT80 width*/
Abhishek Singh906b91f2015-07-02 12:25:52 +05301817 pSpectInfo[j].weight = ACS_WEIGHT_MAX * 4;
Rajesh Babu Prathipati2bc30592014-09-09 13:05:26 +05301818 if ((pSpectInfo[j].chNum +4) == pSpectInfo[j+1].chNum)
Abhishek Singh906b91f2015-07-02 12:25:52 +05301819 pSpectInfo[j+1].weight = ACS_WEIGHT_MAX * 4;
Rajesh Babu Prathipati2bc30592014-09-09 13:05:26 +05301820 if ((pSpectInfo[j].chNum +8) == pSpectInfo[j+2].chNum)
Abhishek Singh906b91f2015-07-02 12:25:52 +05301821 pSpectInfo[j+2].weight = ACS_WEIGHT_MAX * 4;
Rajesh Babu Prathipati2bc30592014-09-09 13:05:26 +05301822 if ((pSpectInfo[j].chNum +12) == pSpectInfo[j+3].chNum)
Abhishek Singh906b91f2015-07-02 12:25:52 +05301823 pSpectInfo[j+3].weight = ACS_WEIGHT_MAX * 4;
Rajesh Babu Prathipati2bc30592014-09-09 13:05:26 +05301824 }
Peng Xu7d410f42014-09-09 12:15:47 +05301825 }
1826
1827 pSpectInfo = pSpectInfoParams->pSpectCh;
1828 for (j = 0; j < pSpectInfoParams->numSpectChans; j++)
1829 {
Peng Xu117eab42014-09-25 13:33:27 +05301830 if ( CHANNEL_165 == pSpectInfo[j].chNum )
Peng Xu7d410f42014-09-09 12:15:47 +05301831 {
Abhishek Singh906b91f2015-07-02 12:25:52 +05301832 pSpectInfo[j].weight = ACS_WEIGHT_MAX * 4;
Peng Xu7d410f42014-09-09 12:15:47 +05301833 break;
1834 }
1835 }
1836
Rajesh Babu Prathipati2bc30592014-09-09 13:05:26 +05301837 pSpectInfo = pSpectInfoParams->pSpectCh;
1838 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
1839 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
1840 "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d",
1841 __func__, pSpectInfo->chNum, pSpectInfo->weight,
1842 pSpectInfo->rssiAgr, pSpectInfo->bssCount);
1843 pSpectInfo++;
1844 }
1845
Peng Xu7d410f42014-09-09 12:15:47 +05301846 sapSortChlWeight(pSpectInfoParams);
1847}
1848
1849/*==========================================================================
Rajesh Babu Prathipatiff748c02014-09-09 13:19:57 +05301850 FUNCTION sapSortChlWeightHT40_24G
Peng Xu7d410f42014-09-09 12:15:47 +05301851
1852 DESCRIPTION
1853 Funtion to sort the channels with the least weight first for 20MHz channels
1854
1855 DEPENDENCIES
1856 NA.
1857
1858 PARAMETERS
1859
1860 IN
1861 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1862
1863 RETURN VALUE
1864 void : NULL
1865
1866 SIDE EFFECTS
1867============================================================================*/
Rajesh Babu Prathipatiff748c02014-09-09 13:19:57 +05301868void sapSortChlWeightHT40_24G(tSapChSelSpectInfo *pSpectInfoParams)
1869{
1870 v_U8_t i, j;
1871 tSapSpectChInfo *pSpectInfo;
1872 v_U32_t tmpWeight1, tmpWeight2;
1873
1874 pSpectInfo = pSpectInfoParams->pSpectCh;
1875 /*for each HT40 channel, calculate the combined weight of the
1876 two 20MHz weight */
1877 for (i = 0; i < ARRAY_SIZE(acsHT40Channels24G); i++)
1878 {
1879 for (j = 0; j < pSpectInfoParams->numSpectChans; j++)
1880 {
1881 if (pSpectInfo[j].chNum == acsHT40Channels24G[i].chStartNum)
1882 break;
1883 }
1884 if (j == pSpectInfoParams->numSpectChans)
1885 continue;
1886
1887 if ((pSpectInfo[j].chNum +4) == pSpectInfo[j+4].chNum)
1888 {
1889 /* check if there is another channel combination possiblity
1890 e.g., {1, 5} & {5, 9} */
1891 if ((pSpectInfo[j+4].chNum + 4)== pSpectInfo[j+8].chNum)
1892 {
1893 /* need to compare two channel pairs */
1894 tmpWeight1 = pSpectInfo[j].weight + pSpectInfo[j+4].weight;
1895 tmpWeight2 = pSpectInfo[j+4].weight + pSpectInfo[j+8].weight;
1896 if (tmpWeight1 <= tmpWeight2)
1897 {
1898 if (pSpectInfo[j].weight <= pSpectInfo[j+4].weight)
1899 {
1900 pSpectInfo[j].weight = tmpWeight1;
Abhishek Singh906b91f2015-07-02 12:25:52 +05301901 pSpectInfo[j+4].weight = ACS_WEIGHT_MAX * 2;
1902 pSpectInfo[j+8].weight = ACS_WEIGHT_MAX * 2;
Rajesh Babu Prathipatiff748c02014-09-09 13:19:57 +05301903 }
1904 else
1905 {
1906 pSpectInfo[j+4].weight = tmpWeight1;
Abhishek Singh906b91f2015-07-02 12:25:52 +05301907 pSpectInfo[j].weight = ACS_WEIGHT_MAX * 2;
1908 pSpectInfo[j+8].weight = ACS_WEIGHT_MAX * 2;
Rajesh Babu Prathipatiff748c02014-09-09 13:19:57 +05301909 }
1910 }
1911 else
1912 {
1913 if (pSpectInfo[j+4].weight <= pSpectInfo[j+8].weight)
1914 {
1915 pSpectInfo[j+4].weight = tmpWeight2;
Abhishek Singh906b91f2015-07-02 12:25:52 +05301916 pSpectInfo[j].weight = ACS_WEIGHT_MAX * 2;
1917 pSpectInfo[j+8].weight = ACS_WEIGHT_MAX * 2;
Rajesh Babu Prathipatiff748c02014-09-09 13:19:57 +05301918 }
1919 else
1920 {
1921 pSpectInfo[j+8].weight = tmpWeight2;
Abhishek Singh906b91f2015-07-02 12:25:52 +05301922 pSpectInfo[j].weight = ACS_WEIGHT_MAX * 2;
1923 pSpectInfo[j+4].weight = ACS_WEIGHT_MAX * 2;
Rajesh Babu Prathipatiff748c02014-09-09 13:19:57 +05301924 }
1925 }
1926 }
1927 else
1928 {
1929 tmpWeight1 = pSpectInfo[j].weight + pSpectInfo[j+4].weight;
1930 if (pSpectInfo[j].weight <= pSpectInfo[j+4].weight)
1931 {
1932 pSpectInfo[j].weight = tmpWeight1;
Abhishek Singh906b91f2015-07-02 12:25:52 +05301933 pSpectInfo[j+4].weight = ACS_WEIGHT_MAX * 2;
Rajesh Babu Prathipatiff748c02014-09-09 13:19:57 +05301934 }
1935 else
1936 {
1937 pSpectInfo[j+4].weight = tmpWeight1;
Abhishek Singh906b91f2015-07-02 12:25:52 +05301938 pSpectInfo[j].weight = ACS_WEIGHT_MAX * 2;
Rajesh Babu Prathipatiff748c02014-09-09 13:19:57 +05301939 }
1940 }
1941 }
1942 else
Abhishek Singh906b91f2015-07-02 12:25:52 +05301943 pSpectInfo[j].weight = ACS_WEIGHT_MAX * 2;
Rajesh Babu Prathipatiff748c02014-09-09 13:19:57 +05301944 }
Rajesh Babu Prathipati684ad722014-09-11 16:14:05 +05301945
1946 sapSortChlWeight(pSpectInfoParams);
Rajesh Babu Prathipatiff748c02014-09-09 13:19:57 +05301947}
1948
1949
1950/*==========================================================================
1951 FUNCTION sapSortChlWeightHT40_5G
1952
1953 DESCRIPTION
1954 Funtion to sort the channels with the least weight first for HT40 channels
1955
1956 DEPENDENCIES
1957 NA.
1958
1959 PARAMETERS
1960
1961 IN
1962 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1963
1964 RETURN VALUE
1965 void : NULL
1966
1967 SIDE EFFECTS
1968============================================================================*/
1969void sapSortChlWeightHT40_5G(tSapChSelSpectInfo *pSpectInfoParams)
Peng Xu7d410f42014-09-09 12:15:47 +05301970{
1971 v_U8_t i, j;
1972 tSapSpectChInfo *pSpectInfo;
1973
1974 pSpectInfo = pSpectInfoParams->pSpectCh;
1975 /*for each HT40 channel, calculate the combined weight of the
1976 two 20MHz weight */
Peng Xu117eab42014-09-25 13:33:27 +05301977 for (i = 0; i < ARRAY_SIZE(acsHT40Channels5G); i++)
Peng Xu7d410f42014-09-09 12:15:47 +05301978 {
1979 for (j = 0; j < pSpectInfoParams->numSpectChans; j++)
1980 {
Peng Xu117eab42014-09-25 13:33:27 +05301981 if (pSpectInfo[j].chNum == acsHT40Channels5G[i].chStartNum)
Peng Xu7d410f42014-09-09 12:15:47 +05301982 break;
1983 }
Peng Xu117eab42014-09-25 13:33:27 +05301984 if (j == pSpectInfoParams->numSpectChans)
1985 continue;
Peng Xu7d410f42014-09-09 12:15:47 +05301986
1987 /* found the channel, add the two adjacent channels' weight */
1988 if ( (pSpectInfo[j].chNum +4) == pSpectInfo[j+1].chNum)
1989 {
Peng Xu117eab42014-09-25 13:33:27 +05301990 acsHT40Channels5G[i].weight = pSpectInfo[j].weight +
Peng Xu7d410f42014-09-09 12:15:47 +05301991 pSpectInfo[j+1].weight;
Rajesh Babu Prathipatiaf5ceac2014-09-09 13:10:25 +05301992 /* select better of the adjact channel as the primary channel */
1993 if (pSpectInfo[j].weight <= pSpectInfo[j+1].weight)
1994 {
1995 pSpectInfo[j].weight = acsHT40Channels5G[i].weight;
1996 /* mark the adjacent channel's weight as max value so
1997 that it will be sorted to the bottom */
Abhishek Singh906b91f2015-07-02 12:25:52 +05301998 pSpectInfo[j+1].weight = ACS_WEIGHT_MAX * 2;
Rajesh Babu Prathipatiaf5ceac2014-09-09 13:10:25 +05301999 }
2000 else
2001 {
2002 pSpectInfo[j+1].weight = acsHT40Channels5G[i].weight;
2003 /* mark the adjacent channel's weight as max value so
2004 that it will be sorted to the bottom */
Abhishek Singh906b91f2015-07-02 12:25:52 +05302005 pSpectInfo[j].weight = ACS_WEIGHT_MAX * 2;
Rajesh Babu Prathipatiaf5ceac2014-09-09 13:10:25 +05302006 }
2007
Peng Xu7d410f42014-09-09 12:15:47 +05302008 }
Rajesh Babu Prathipati2bc30592014-09-09 13:05:26 +05302009 else
Abhishek Singh906b91f2015-07-02 12:25:52 +05302010 pSpectInfo[j].weight = ACS_WEIGHT_MAX * 2;
Peng Xu7d410f42014-09-09 12:15:47 +05302011 }
2012
2013 /* avoid channel 165 by setting its weight to max */
2014 pSpectInfo = pSpectInfoParams->pSpectCh;
2015 for (j = 0; j < pSpectInfoParams->numSpectChans; j++)
2016 {
Peng Xu117eab42014-09-25 13:33:27 +05302017 if ( CHANNEL_165 == pSpectInfo[j].chNum )
Peng Xu7d410f42014-09-09 12:15:47 +05302018 {
Abhishek Singh906b91f2015-07-02 12:25:52 +05302019 pSpectInfo[j].weight = ACS_WEIGHT_MAX * 2;
Peng Xu7d410f42014-09-09 12:15:47 +05302020 break;
2021 }
2022 }
2023
Peng Xu117eab42014-09-25 13:33:27 +05302024 pSpectInfo = pSpectInfoParams->pSpectCh;
2025 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
2026 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
2027 "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d",
2028 __func__, pSpectInfo->chNum, pSpectInfo->weight,
2029 pSpectInfo->rssiAgr, pSpectInfo->bssCount);
2030 pSpectInfo++;
2031 }
2032
Peng Xu7d410f42014-09-09 12:15:47 +05302033 sapSortChlWeight(pSpectInfoParams);
2034}
2035
2036/*==========================================================================
2037 FUNCTION sapSortChlWeightAll
2038
2039 DESCRIPTION
2040 Funtion to sort the channels with the least weight first
2041
2042 DEPENDENCIES
2043 NA.
2044
2045 PARAMETERS
2046
2047 IN
2048 ptSapContext : Pointer to the ptSapContext structure
2049 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
2050
2051 RETURN VALUE
2052 void : NULL
2053
2054 SIDE EFFECTS
2055============================================================================*/
2056void sapSortChlWeightAll(ptSapContext pSapCtx,
Peng Xu117eab42014-09-25 13:33:27 +05302057 tSapChSelSpectInfo *pSpectInfoParams,
2058 eChannelWidthInfo chWidth,
2059 v_U32_t operatingBand)
Peng Xu7d410f42014-09-09 12:15:47 +05302060{
2061 tSapSpectChInfo *pSpectCh = NULL;
2062 v_U32_t j = 0;
2063#ifndef SOFTAP_CHANNEL_RANGE
2064 v_U32_t i = 0;
2065#endif
2066
2067 pSpectCh = pSpectInfoParams->pSpectCh;
2068#ifdef SOFTAP_CHANNEL_RANGE
2069
Peng Xu117eab42014-09-25 13:33:27 +05302070 switch (chWidth)
2071 {
2072 case CHWIDTH_HT40:
Rajesh Babu Prathipatiff748c02014-09-09 13:19:57 +05302073 if (eSAP_RF_SUBBAND_2_4_GHZ == operatingBand)
2074 sapSortChlWeightHT40_24G(pSpectInfoParams);
2075 else
2076 sapSortChlWeightHT40_5G(pSpectInfoParams);
Peng Xu117eab42014-09-25 13:33:27 +05302077 break;
2078
2079 case CHWIDTH_HT80:
Peng Xu7d410f42014-09-09 12:15:47 +05302080 sapSortChlWeightHT80(pSpectInfoParams);
Peng Xu117eab42014-09-25 13:33:27 +05302081 break;
2082
2083 case CHWIDTH_HT20:
2084 default:
Peng Xu7d410f42014-09-09 12:15:47 +05302085 /* Sorting the channels as per weights as 20MHz channels */
2086 sapSortChlWeight(pSpectInfoParams);
2087 }
Peng Xu117eab42014-09-25 13:33:27 +05302088
Jeff Johnson295189b2012-06-20 16:38:30 -07002089#else
Peng Xu7d410f42014-09-09 12:15:47 +05302090 /* Sorting the channels as per weights */
Jeff Johnson295189b2012-06-20 16:38:30 -07002091 for (i = 0; i < SPECT_24GHZ_CH_COUNT; i++) {
2092 minWeightIndex = i;
2093 for( j = i + 1; j < SPECT_24GHZ_CH_COUNT; j++) {
2094 if(pSpectCh[j].weight < pSpectCh[minWeightIndex].weight) {
2095 minWeightIndex = j;
2096 }
2097 }
2098 if(minWeightIndex != i) {
2099 vos_mem_copy(&temp, &pSpectCh[minWeightIndex], sizeof(*pSpectCh));
Peng Xu7d410f42014-09-09 12:15:47 +05302100 vos_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i],
2101 sizeof(*pSpectCh));
Jeff Johnson295189b2012-06-20 16:38:30 -07002102 vos_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
2103 }
2104 }
2105#endif
2106
2107 /* For testing */
Peng Xu7d410f42014-09-09 12:15:47 +05302108 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
2109 "In %s, Sorted Spectrum Channels Weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002110 pSpectCh = pSpectInfoParams->pSpectCh;
2111 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
Peng Xu7d410f42014-09-09 12:15:47 +05302112 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
2113 "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d",
2114 __func__, pSpectCh->chNum, pSpectCh->weight,
2115 pSpectCh->rssiAgr, pSpectCh->bssCount);
Jeff Johnson295189b2012-06-20 16:38:30 -07002116 pSpectCh++;
2117 }
2118
2119}
2120
Peng Xu117eab42014-09-25 13:33:27 +05302121eChannelWidthInfo sapGetChannelWidthInfo(tHalHandle halHandle, ptSapContext pSapCtx,
2122 v_U32_t operatingBand, eSapPhyMode phyMode)
2123{
2124 v_U32_t cbMode;
2125 eChannelWidthInfo chWidth = CHWIDTH_HT20;
2126
Hardik Kantilal Pateldd107952014-11-20 15:24:52 +05302127#ifdef WLAN_FEATURE_AP_HT40_24G
Peng Xu117eab42014-09-25 13:33:27 +05302128 if (eSAP_RF_SUBBAND_2_4_GHZ == operatingBand)
2129 cbMode = sme_GetChannelBondingMode24G(halHandle);
2130 else
Hardik Kantilal Pateldd107952014-11-20 15:24:52 +05302131#endif
Peng Xu117eab42014-09-25 13:33:27 +05302132 cbMode = sme_GetChannelBondingMode5G(halHandle);
2133
2134 if (phyMode == eSAP_DOT11_MODE_11n ||
2135 phyMode == eSAP_DOT11_MODE_11n_ONLY)
2136 {
2137 if (cbMode)
2138 chWidth = CHWIDTH_HT40;
2139 else
2140 chWidth = CHWIDTH_HT20;
2141 }
2142 else if (pSapCtx->csrRoamProfile.phyMode == eSAP_DOT11_MODE_11ac ||
2143 pSapCtx->csrRoamProfile.phyMode == eSAP_DOT11_MODE_11ac_ONLY) {
2144 chWidth = CHWIDTH_HT80;
2145 }
2146 else {
2147 /* Sorting the channels as per weights as 20MHz channels */
2148 chWidth = CHWIDTH_HT20;
2149 }
2150
2151 return chWidth;
2152}
Jeff Johnson295189b2012-06-20 16:38:30 -07002153/*==========================================================================
2154 FUNCTION sapSelectChannel
2155
2156 DESCRIPTION
2157 Runs a algorithm to select the best channel to operate in based on BSS
2158 rssi and bss count on each channel
2159
2160 DEPENDENCIES
2161 NA.
2162
2163 PARAMETERS
2164
2165 IN
2166 halHandle : Pointer to HAL handle
2167 pResult : Pointer to tScanResultHandle
2168
2169 RETURN VALUE
2170 v_U8_t : Success - channel number, Fail - zero
2171
2172 SIDE EFFECTS
2173============================================================================*/
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07002174v_U8_t sapSelectChannel(tHalHandle halHandle, ptSapContext pSapCtx, tScanResultHandle pScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07002175{
2176 // DFS param object holding all the data req by the algo
2177 tSapChSelSpectInfo oSpectInfoParams = {NULL,0};
2178 tSapChSelSpectInfo *pSpectInfoParams = &oSpectInfoParams; // Memory? NB
Peng Xuafc34e32014-09-25 13:23:55 +05302179 v_U8_t bestChNum = SAP_CHANNEL_NOT_SELECTED;
Jeff Johnson295189b2012-06-20 16:38:30 -07002180#ifdef SOFTAP_CHANNEL_RANGE
2181 v_U32_t startChannelNum;
2182 v_U32_t endChannelNum;
Gopichand Nakkala936715f2013-03-18 19:48:10 +05302183 v_U32_t operatingBand = 0;
Peng Xuafc34e32014-09-25 13:23:55 +05302184 v_U32_t tmpChNum;
2185 v_U8_t count;
Peng Xu117eab42014-09-25 13:33:27 +05302186 eChannelWidthInfo chWidth;
Peng Xuafc34e32014-09-25 13:23:55 +05302187#endif
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002188 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 -07002189
Jeff Johnson295189b2012-06-20 16:38:30 -07002190 // Initialize the structure pointed by pSpectInfoParams
2191 if(sapChanSelInit( halHandle, pSpectInfoParams) != eSAP_TRUE ) {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002192 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "In %s, Ch Select initialization failed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002193 return SAP_CHANNEL_NOT_SELECTED;
2194 }
2195
2196 // Compute the weight of the entire spectrum in the operating band
2197 sapComputeSpectWeight( pSpectInfoParams, halHandle, pScanResult);
2198
Jeff Johnson295189b2012-06-20 16:38:30 -07002199#ifdef SOFTAP_CHANNEL_RANGE
Peng Xufc6ad8e2014-09-25 13:16:43 +05302200 if (eCSR_BAND_ALL == pSapCtx->scanBandPreference)
Peng Xu2446a892014-09-05 17:21:18 +05302201 {
Peng Xuafc34e32014-09-25 13:23:55 +05302202 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_START_CHANNEL,
2203 &startChannelNum);
2204 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_END_CHANNEL,
2205 &endChannelNum);
2206 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_OPERATING_BAND,
2207 &operatingBand);
Peng Xufc6ad8e2014-09-25 13:16:43 +05302208 }
2209 else
2210 {
2211 if (eCSR_BAND_24 == pSapCtx->currentPreferredBand)
2212 {
Peng Xu2446a892014-09-05 17:21:18 +05302213 startChannelNum = rfChannels[RF_CHAN_1].channelNum;
2214 endChannelNum = rfChannels[RF_CHAN_14].channelNum;
Leela Venkata Kiran Kumar Reddy Chirala9f6566c2014-09-05 19:06:58 +05302215 operatingBand = eSAP_RF_SUBBAND_2_4_GHZ;
Peng Xufc6ad8e2014-09-25 13:16:43 +05302216 }
2217 else
2218 {
Peng Xu2446a892014-09-05 17:21:18 +05302219 startChannelNum = rfChannels[RF_CHAN_36].channelNum;
2220 endChannelNum = rfChannels[RF_CHAN_165].channelNum;
Deepthi Gowri7db41f32014-10-13 17:02:29 +05302221 operatingBand = eSAP_RF_SUBBAND_5_ALL_GHZ;
Peng Xufc6ad8e2014-09-25 13:16:43 +05302222 }
2223 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002224
Peng Xuafc34e32014-09-25 13:23:55 +05302225 pSapCtx->acsBestChannelInfo.channelNum = 0;
2226 pSapCtx->acsBestChannelInfo.weight = CFG_ACS_BAND_SWITCH_THRESHOLD_MAX;
Peng Xu117eab42014-09-25 13:33:27 +05302227 /* find the channel width info */
2228 chWidth = sapGetChannelWidthInfo(halHandle, pSapCtx, operatingBand, pSapCtx->csrRoamProfile.phyMode);
2229 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
2230 "In %s, chWidth=%u", __func__, chWidth);
2231
2232 /* Sort the channel list as per the computed weights, lesser weight first.*/
2233 sapSortChlWeightAll(pSapCtx, pSpectInfoParams, chWidth, operatingBand);
Peng Xuafc34e32014-09-25 13:23:55 +05302234
Jeff Johnson295189b2012-06-20 16:38:30 -07002235 /*Loop till get the best channel in the given range */
2236 for(count=0; count < pSpectInfoParams->numSpectChans ; count++)
2237 {
2238 if((startChannelNum <= pSpectInfoParams->pSpectCh[count].chNum)&&
2239 ( endChannelNum >= pSpectInfoParams->pSpectCh[count].chNum))
2240 {
Deepthi Gowri38c219d2014-08-05 19:34:08 +05302241 if (NV_CHANNEL_ENABLE !=
2242 vos_nv_getChannelEnabledState(pSpectInfoParams->pSpectCh[count].chNum))
2243 {
2244 continue; //skip this channel, continue to next channel
2245 }
Peng Xuafc34e32014-09-25 13:23:55 +05302246 if(bestChNum == SAP_CHANNEL_NOT_SELECTED)
Bansidhar Gopalachari1e56faa2013-07-25 19:30:20 +05302247 {
Peng Xuafc34e32014-09-25 13:23:55 +05302248 bestChNum = pSpectInfoParams->pSpectCh[count].chNum;
2249 /* check if bestChNum is in preferred channel list */
2250 bestChNum = sapSelectPreferredChannelFromChannelList(
2251 bestChNum, pSapCtx, pSpectInfoParams);
2252 if (bestChNum == SAP_CHANNEL_NOT_SELECTED)
2253 {
2254 /* not in preferred channel list, go to next best channel*/
2255 continue;
2256 }
2257
Abhishek Singh906b91f2015-07-02 12:25:52 +05302258 if (pSpectInfoParams->pSpectCh[count].weight_copy >
Peng Xuafc34e32014-09-25 13:23:55 +05302259 pSapCtx->acsBandSwitchThreshold)
2260 {
2261 /* the best channel exceeds the threshold
2262 check if need to scan next band */
2263 if ((eCSR_BAND_ALL != pSapCtx->scanBandPreference) &&
2264 !pSapCtx->allBandScanned)
2265 {
2266 /* store best channel for later comparison */
2267 pSapCtx->acsBestChannelInfo.channelNum = bestChNum;
2268 pSapCtx->acsBestChannelInfo.weight =
2269 pSpectInfoParams->pSpectCh[count].weight;
2270 bestChNum = SAP_CHANNEL_NOT_SELECTED;
2271 break;
2272 }
2273 else
2274 {
2275 /* all bands are scanned, compare current best channel
2276 with channel scanned previously */
Abhishek Singh906b91f2015-07-02 12:25:52 +05302277 if ( pSpectInfoParams->pSpectCh[count].weight_copy >
Peng Xuafc34e32014-09-25 13:23:55 +05302278 pSapCtx->acsBestChannelInfo.weight)
2279 {
2280 /* previous stored channel is better */
2281 bestChNum = pSapCtx->acsBestChannelInfo.channelNum;
2282 }
2283 else
2284 {
2285 pSapCtx->acsBestChannelInfo.channelNum = bestChNum;
2286 pSapCtx->acsBestChannelInfo.weight =
Abhishek Singh906b91f2015-07-02 12:25:52 +05302287 pSpectInfoParams->pSpectCh[count].weight_copy;
Peng Xuafc34e32014-09-25 13:23:55 +05302288 }
2289 }
2290 }
Bansidhar Gopalachari1e56faa2013-07-25 19:30:20 +05302291 }
2292 else
2293 {
2294 if(operatingBand == RF_SUBBAND_2_4_GHZ)
2295 {
2296 /* Give preference to Non-overlap channels */
2297 if(((pSpectInfoParams->pSpectCh[count].chNum == CHANNEL_1) ||
Peng Xuafc34e32014-09-25 13:23:55 +05302298 (pSpectInfoParams->pSpectCh[count].chNum == CHANNEL_6) ||
2299 (pSpectInfoParams->pSpectCh[count].chNum == CHANNEL_11))&&
Abhishek Singh906b91f2015-07-02 12:25:52 +05302300 (pSpectInfoParams->pSpectCh[count].weight_copy ==
Peng Xuafc34e32014-09-25 13:23:55 +05302301 pSapCtx->acsBestChannelInfo.weight))
2302 {
2303 tmpChNum = pSpectInfoParams->pSpectCh[count].chNum;
2304 tmpChNum =
2305 sapSelectPreferredChannelFromChannelList(tmpChNum,
2306 pSapCtx, pSpectInfoParams);
2307 if ( tmpChNum != SAP_CHANNEL_NOT_SELECTED)
2308 {
2309 bestChNum = tmpChNum;
2310 break;
2311 }
2312
2313 }
Bansidhar Gopalachari1e56faa2013-07-25 19:30:20 +05302314 }
2315 }
2316 }
2317 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002318#else
Peng Xu117eab42014-09-25 13:33:27 +05302319 // Sort the channel list as per the computed weights, lesser weight first.
2320 sapSortChlWeightAll(pSapCtx, halHandle, pSpectInfoParams);
Jeff Johnson295189b2012-06-20 16:38:30 -07002321 // Get the first channel in sorted array as best 20M Channel
2322 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[0].chNum;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07002323 //Select Best Channel from Channel List if Configured
Peng Xuafc34e32014-09-25 13:23:55 +05302324 bestChNum = sapSelectPreferredChannelFromChannelList(bestChNum,
2325 pSapCtx, pSpectInfoParams);
2326#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002327
2328 // Free all the allocated memory
2329 sapChanSelExit(pSpectInfoParams);
2330
2331 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 -07002332 __func__, bestChNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07002333 if (bestChNum > 0 && bestChNum <= 252)
2334 return bestChNum;
2335 else
2336 return SAP_CHANNEL_NOT_SELECTED;
2337}
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07002338