blob: b787352c0289954f682e13b0df3dfc57aae1f8d1 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Jeff Johnson32d95a32012-09-10 13:15:23 -07002 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -07003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*===========================================================================
23
24 s a p C h S e l e c t . C
25
26 OVERVIEW:
27
28 This software unit holds the implementation of the WLAN SAP modules
29 functions for channel selection.
30
31 DEPENDENCIES:
32
33 Are listed for each API below.
34
35
36 Copyright (c) 2010 QUALCOMM Incorporated.
37 All Rights Reserved.
38 Qualcomm Confidential and Proprietary
39===========================================================================*/
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"
66
67/*--------------------------------------------------------------------------
68 Function definitions
69--------------------------------------------------------------------------*/
70
71/*--------------------------------------------------------------------------
72 Defines
73--------------------------------------------------------------------------*/
74#define SAP_DEBUG
75
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070076
77/*==========================================================================
78 FUNCTION sapCleanupChannelList
79
80 DESCRIPTION
81 Function sapCleanupChannelList frees up the memory allocated to the channel list.
82
83 DEPENDENCIES
84 NA.
85
86 PARAMETERS
87
88 IN
89 NULL
90
91 RETURN VALUE
92 NULL
93============================================================================*/
94
95void sapCleanupChannelList(void)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -070096{
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070097 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_SAP, NULL);
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -070098 ptSapContext pSapCtx = VOS_GET_SAP_CB(pvosGCtx);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070099
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700100 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO,
101 "Cleaning up the channel list structure");
102
103 pSapCtx->SapChnlList.numChannel =0;
104 vos_mem_free(pSapCtx->SapChnlList.channelList);
105 pSapCtx->SapChnlList.channelList = NULL;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700106}
107
108/*==========================================================================
109 FUNCTION sapSetPreferredChannel
110
111 DESCRIPTION
112 Function sapSetPreferredChannel sets the channel list which has been configured
113 into sap context (pSapCtx) which will be used at the time of best channel selection.
114
115 DEPENDENCIES
116 NA.
117
118 PARAMETERS
119
120 IN
121 *ptr: pointer having the command followed by the arguments in string format
122 *dev: not used.
123
124 RETURN VALUE
125 int: return 0 when success else returns error code.
126============================================================================*/
127
128int sapSetPreferredChannel(struct net_device *dev, tANI_U8* ptr)
129{
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700130
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700131 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_SAP, NULL);
132 ptSapContext pSapCtx = VOS_GET_SAP_CB(pvosGCtx);
133 tANI_U8* param;
134 int tempInt;
135 int j;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700136
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700137 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700138 "Enter: %s", __func__);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700139
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700140 if (NULL != pSapCtx->SapChnlList.channelList)
141 {
142 sapCleanupChannelList();
143 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700144
Madan Mohan Koyyalamudid8ac8662012-11-06 19:04:56 -0800145 param = strnchr(ptr, strlen(ptr), ' ');
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700146 /*no argument after the command*/
147 if (NULL == param)
148 {
149 return -EINVAL;
150 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700151
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700152 /*no space after the command*/
153 else if (SPACE_ASCII_VALUE != *param)
154 {
155 return -EINVAL;
156 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700157
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700158 param++;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700159
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700160 /*removing empty spaces*/
161 while((SPACE_ASCII_VALUE == *param)&& ('\0' != *param) ) param++;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700162
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700163 /*no argument followed by spaces*/
164 if('\0' == *param)
165 {
166 return -EINVAL;
167 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700168
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700169 /*getting the first argument ie the number of channels*/
170 sscanf(param, "%d ", &tempInt);
171 pSapCtx->SapChnlList.numChannel = tempInt;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700172
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700173 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
174 "Number of channel added are: %d",
175 pSapCtx->SapChnlList.numChannel);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700176
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700177 /*allocating space for the desired number of channels*/
178 pSapCtx->SapChnlList.channelList =
179 (v_U8_t *)vos_mem_malloc(pSapCtx->SapChnlList.numChannel);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700180
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700181 for(j=0;j<pSapCtx->SapChnlList.numChannel;j++)
182 {
183
184 /*param pointing to the beginning of first space after number of channels*/
185 param = strpbrk( param, " " );
186 /*no channel list after the number of channels argument*/
187 if (NULL == param)
188 {
189 sapCleanupChannelList();
190 return -EINVAL;
191 }
192
193 param++;
194
195 /*removing empty space*/
196 while((SPACE_ASCII_VALUE == *param) && ('\0' != *param) ) param++;
197
198 /*no channel list after the number of channels argument and spaces*/
199 if( '\0' == *param )
200 {
201 sapCleanupChannelList();
202 return -EINVAL;
203 }
204
205 sscanf(param, "%d ", &tempInt);
206 pSapCtx->SapChnlList.channelList[j] = tempInt;
207
208 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
209 "Channel %d added to preferred channel list",
210 pSapCtx->SapChnlList.channelList[j] );
211
212 }
213
214 /*extra arguments check*/
215 param = strpbrk( param, " " );
216 if (NULL != param)
217 {
218 while((SPACE_ASCII_VALUE == *param) && ('\0' != *param) ) param++;
219
220 if('\0' != *param)
221 {
222 sapCleanupChannelList();
223 return -EINVAL;
224 }
225 }
226
227 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700228 "Exit: %s", __func__);
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700229
230 return 0;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700231}
232
233/*==========================================================================
234 FUNCTION sapSelectPreferredChannelFromChannelList
235
236 DESCRIPTION
237 Function sapSelectPreferredChannelFromChannelList calculates the best channel
238 among the configured channel list. If channel list not configured then returns
239 the best channel calculated among all the channel list.
240
241 DEPENDENCIES
242 NA.
243
244 PARAMETERS
245
246 IN
247 *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure
248 bestChNum: best channel already calculated among all the chanels
249 pSapCtx: having info of channel list from which best channel is selected
250
251 RETURN VALUE
252 v_U8_t: best channel
253============================================================================*/
254v_U8_t sapSelectPreferredChannelFromChannelList(v_U8_t bestChNum,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700255 ptSapContext pSapCtx,
256 tSapChSelSpectInfo *pSpectInfoParams)
257{
258 v_U8_t j = 0;
259 v_U8_t count = 0;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700260
261 //If Channel List is not Configured don't do anything
262 //Else return the Best Channel from the Channel List
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700263 if((NULL == pSapCtx->SapChnlList.channelList) ||
264 (NULL == pSpectInfoParams) ||
265 (0 == pSapCtx->SapChnlList.numChannel))
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700266 {
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700267 return bestChNum;
268 }
269
270 if (bestChNum > 0 && bestChNum <= 252)
271 {
272 for(count=0; count < pSpectInfoParams->numSpectChans ; count++)
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700273 {
274 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[count].chNum;
275 // Select the best channel from allowed list
276 for(j=0;j< pSapCtx->SapChnlList.numChannel;j++)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700277 {
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700278 if( (pSapCtx->SapChnlList.channelList[j]) == bestChNum)
279 {
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700280 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
281 "Best channel computed from Channel List is: %d",
282 bestChNum);
283 return bestChNum;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700284 }
285 }
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700286 }
287
288 return SAP_CHANNEL_NOT_SELECTED;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700289 }
290 else
291 return SAP_CHANNEL_NOT_SELECTED;
292}
293
294
Jeff Johnson295189b2012-06-20 16:38:30 -0700295/*==========================================================================
296 FUNCTION sapChanSelInit
297
298 DESCRIPTION
299 Function sapChanSelInit allocates the memory, intializes the
300 structures used by the channel selection algorithm
301
302 DEPENDENCIES
303 NA.
304
305 PARAMETERS
306
307 IN
308 *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure
309
310 RETURN VALUE
311 v_BOOL_t: Success or FAIL
312
313 SIDE EFFECTS
314============================================================================*/
315v_BOOL_t sapChanSelInit(tHalHandle halHandle, tSapChSelSpectInfo *pSpectInfoParams)
316{
317 tSapSpectChInfo *pSpectCh = NULL;
318 v_U8_t *pChans = NULL;
319 v_U16_t channelnum = 0;
320 tpAniSirGlobal pMac = PMAC_STRUCT(halHandle);
321
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700322 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700323
324 // Channels for that 2.4GHz band
325 //Considered only for 2.4GHz need to change in future to support 5GHz support
326 pSpectInfoParams->numSpectChans = pMac->scan.base20MHzChannels.numChannels;
327
328 // Allocate memory for weight computation of 2.4GHz
329 pSpectCh = (tSapSpectChInfo *)vos_mem_malloc((pSpectInfoParams->numSpectChans) * sizeof(*pSpectCh));
330
331 if(pSpectCh == NULL) {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700332 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "In %s, VOS_MALLOC_ERR", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700333 return eSAP_FALSE;
334 }
335
336 vos_mem_zero(pSpectCh, (pSpectInfoParams->numSpectChans) * sizeof(*pSpectCh));
337
338 // Initialize the pointers in the DfsParams to the allocated memory
339 pSpectInfoParams->pSpectCh = pSpectCh;
340
341 pChans = pMac->scan.base20MHzChannels.channelList;
342
343 // Fill the channel number in the spectrum in the operating freq band
344 for (channelnum = 0; channelnum < pSpectInfoParams->numSpectChans; channelnum++) {
345
346 if(*pChans == 14 ) //OFDM rates are not supported on channel 14
347 continue;
348 pSpectCh->chNum = *pChans;
349 pSpectCh->valid = eSAP_TRUE;
350 pSpectCh->rssiAgr = SOFTAP_MIN_RSSI;// Initialise for all channels
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800351 pSpectCh->channelWidth = SOFTAP_HT20_CHANNELWIDTH; // Initialise 20MHz for all the Channels
Jeff Johnson295189b2012-06-20 16:38:30 -0700352 pSpectCh++;
353 pChans++;
354 }
355 return eSAP_TRUE;
356}
357
358/*==========================================================================
359 FUNCTION sapweightRssiCount
360
361 DESCRIPTION
362 Function weightRssiCount calculates the channel weight due to rssi
363 and data count(here number of BSS observed)
364
365 DEPENDENCIES
366 NA.
367
368 PARAMETERS
369
370 IN
371 rssi : Max signal strength receieved from a BSS for the channel
372 count : Number of BSS observed in the channel
373
374 RETURN VALUE
375 v_U32_t : Calculated channel weight based on above two
376
377 SIDE EFFECTS
378============================================================================*/
379v_U32_t sapweightRssiCount(v_S7_t rssi, v_U16_t count)
380{
381 v_S31_t rssiWeight=0;
382 v_S31_t countWeight=0;
383 v_U32_t rssicountWeight=0;
384
385 // Weight from RSSI
386 rssiWeight = SOFTAP_RSSI_WEIGHT * (rssi - SOFTAP_MIN_RSSI)
387 /(SOFTAP_MAX_RSSI - SOFTAP_MIN_RSSI);
388
389 if(rssiWeight > SOFTAP_RSSI_WEIGHT)
390 rssiWeight = SOFTAP_RSSI_WEIGHT;
391 else if (rssiWeight < 0)
392 rssiWeight = 0;
393
394 // Weight from data count
395 countWeight = SOFTAP_COUNT_WEIGHT * (count - SOFTAP_MIN_COUNT)
396 /(SOFTAP_MAX_COUNT - SOFTAP_MIN_COUNT);
397
398 if(countWeight > SOFTAP_COUNT_WEIGHT)
399 countWeight = SOFTAP_COUNT_WEIGHT;
400 else if (countWeight < 0)
401 countWeight = 0;
402
403 rssicountWeight = rssiWeight + countWeight;
404
405 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 -0700406 __func__, rssiWeight, countWeight, rssicountWeight);
Jeff Johnson295189b2012-06-20 16:38:30 -0700407
408 return(rssicountWeight);
409}
410
411/*==========================================================================
412 FUNCTION sapComputeSpectWeight
413
414 DESCRIPTION
415 Main function for computing the weight of each channel in the
416 spectrum based on the RSSI value of the BSSes on the channel
417 and number of BSS
418
419 DEPENDENCIES
420 NA.
421
422 PARAMETERS
423
424 IN
425 pSpectInfoParams : Pointer to the tSpectInfoParams structure
426 halHandle : Pointer to HAL handle
427 pResult : Pointer to tScanResultHandle
428
429 RETURN VALUE
430 void : NULL
431
432 SIDE EFFECTS
433============================================================================*/
434void sapComputeSpectWeight( tSapChSelSpectInfo* pSpectInfoParams,
435 tHalHandle halHandle, tScanResultHandle pResult)
436{
437 v_S7_t rssi = 0;
438 v_U8_t chn_num = 0;
439 v_U8_t channel_id = 0;
440
441 tCsrScanResultInfo *pScanResult;
442 tSapSpectChInfo *pSpectCh = pSpectInfoParams->pSpectCh;
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800443 v_U32_t operatingBand;
Jeff Johnson295189b2012-06-20 16:38:30 -0700444
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700445 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Computing spectral weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700446
447 /**
448 * Soft AP specific channel weight calculation using DFS formula
449 */
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800450 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_OPERATING_BAND, &operatingBand);
Jeff Johnson295189b2012-06-20 16:38:30 -0700451
452 pScanResult = sme_ScanResultGetFirst(halHandle, pResult);
453
454 while (pScanResult) {
455 pSpectCh = pSpectInfoParams->pSpectCh;
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800456
Madan Mohan Koyyalamudi1e02f7f2012-12-04 16:46:45 -0800457 // Processing for each tCsrScanResultInfo in the tCsrScanResult DLink list
Jeff Johnson295189b2012-06-20 16:38:30 -0700458 for (chn_num = 0; chn_num < pSpectInfoParams->numSpectChans; chn_num++) {
459
460 /*
461 * if the Beacon has channel ID, use it other wise we will
462 * rely on the channelIdSelf
463 */
464 if(pScanResult->BssDescriptor.channelId == 0)
465 channel_id = pScanResult->BssDescriptor.channelIdSelf;
466 else
467 channel_id = pScanResult->BssDescriptor.channelId;
468
469 if (channel_id == pSpectCh->chNum) {
470 if (pSpectCh->rssiAgr < pScanResult->BssDescriptor.rssi)
471 pSpectCh->rssiAgr = pScanResult->BssDescriptor.rssi;
472
473 ++pSpectCh->bssCount; // Increment the count of BSS
474
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800475 if(operatingBand) // Connsidering the Extension Channel only in a channels
476 {
477 /* Updating the received ChannelWidth */
478 if (pSpectCh->channelWidth != pScanResult->BssDescriptor.channelWidth)
479 pSpectCh->channelWidth = pScanResult->BssDescriptor.channelWidth;
480
Madan Mohan Koyyalamudi1e02f7f2012-12-04 16:46:45 -0800481 /* If received ChannelWidth is other than HT20, we need to update the extension channel Params as well */
482 /* channelWidth == 0, HT20 */
483 /* channelWidth == 1, HT40 */
484 /* channelWidth == 2, VHT80*/
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800485 switch(pSpectCh->channelWidth)
486 {
487 case eHT_CHANNEL_WIDTH_40MHZ: //HT40
488 switch( pScanResult->BssDescriptor.secondaryChannelOffset)
489 {
490 tSapSpectChInfo *pExtSpectCh = NULL;
491 case PHY_DOUBLE_CHANNEL_LOW_PRIMARY: // Above the Primary Channel
492 pExtSpectCh = (pSpectCh + 1);
493 if(pExtSpectCh != NULL)
494 {
495 ++pExtSpectCh->bssCount;
496 // REducing the rssi by -20 and assigning it to Extension channel
497 pExtSpectCh->rssiAgr = (pSpectCh->rssiAgr + SAP_EXT_CHAN_RSSI);
498 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
499 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
500 }
501 break;
502 case PHY_DOUBLE_CHANNEL_HIGH_PRIMARY: // Below the Primary channel
503 pExtSpectCh = (pSpectCh - 1);
504 if(pExtSpectCh != NULL)
505 {
506 pExtSpectCh->rssiAgr = (pSpectCh->rssiAgr + SAP_EXT_CHAN_RSSI);
507 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
508 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
509 ++pExtSpectCh->bssCount;
510 }
511 break;
512 }
513 break;
514 case eHT_CHANNEL_WIDTH_80MHZ: // VHT80
515 if((pScanResult->BssDescriptor.centerFreq - channel_id) == 6)
516 {
517 tSapSpectChInfo *pExtSpectCh = NULL;
518 pExtSpectCh = (pSpectCh + 1);
519 if(pExtSpectCh != NULL)
520 {
521 ++pExtSpectCh->bssCount;
522 pExtSpectCh->rssiAgr = (pSpectCh->rssiAgr + SAP_EXT_CHAN_RSSI); // Reducing the rssi by -20 and assigning it to Subband 1
523 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
524 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
525 }
526 pExtSpectCh = (pSpectCh + 2);
527 if(pExtSpectCh != NULL)
528 {
529 ++pExtSpectCh->bssCount;
530 pExtSpectCh->rssiAgr = (pSpectCh->rssiAgr + SAP_EXT_SUBBAND2_RSSI); // Reducing the rssi by -30 and assigning it to Subband 2
531 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
532 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
533 }
534 pExtSpectCh = (pSpectCh + 3);
535 if(pExtSpectCh != NULL)
536 {
537 ++pExtSpectCh->bssCount;
538 pExtSpectCh->rssiAgr = (pSpectCh->rssiAgr + SAP_EXT_SUBBAND3_RSSI); // Reducing the rssi by -40 and assigning it to Subband 3
539 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
540 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
541 }
542 }
543 else if((pScanResult->BssDescriptor.centerFreq - channel_id) == 2)
544 {
545 tSapSpectChInfo *pExtSpectCh = NULL;
546 pExtSpectCh = (pSpectCh - 1 );
547 if(pExtSpectCh != NULL)
548 {
549 ++pExtSpectCh->bssCount;
550 pExtSpectCh->rssiAgr = (pSpectCh->rssiAgr + SAP_EXT_CHAN_RSSI);
551 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
552 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
553 }
554 pExtSpectCh = (pSpectCh + 1);
555 if(pExtSpectCh != NULL)
556 {
557 ++pExtSpectCh->bssCount;
558 pExtSpectCh->rssiAgr = (pSpectCh->rssiAgr + SAP_EXT_CHAN_RSSI);
559 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
560 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
561 }
562 pExtSpectCh = (pSpectCh + 2);
563 if(pExtSpectCh != NULL)
564 {
565 ++pExtSpectCh->bssCount;
566 pExtSpectCh->rssiAgr = (pSpectCh->rssiAgr + SAP_EXT_SUBBAND2_RSSI);
567 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
568 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
569 }
570 }
571 else if((pScanResult->BssDescriptor.centerFreq - channel_id) == -2)
572 {
573 tSapSpectChInfo *pExtSpectCh = NULL;
574 pExtSpectCh = (pSpectCh - 1 );
575 if(pExtSpectCh != NULL)
576 {
577 ++pExtSpectCh->bssCount;
578 pExtSpectCh->rssiAgr = (pSpectCh->rssiAgr + SAP_EXT_CHAN_RSSI);
579 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
580 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
581 }
582 pExtSpectCh = (pSpectCh - 2);
583 if(pExtSpectCh != NULL)
584 {
585 ++pExtSpectCh->bssCount;
586 pExtSpectCh->rssiAgr = (pSpectCh->rssiAgr + SAP_EXT_SUBBAND2_RSSI);
587 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
588 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
589 }
590 pExtSpectCh = (pSpectCh + 1);
591 if(pExtSpectCh != NULL)
592 {
593 ++pExtSpectCh->bssCount;
594 pExtSpectCh->rssiAgr = (pSpectCh->rssiAgr + SAP_EXT_CHAN_RSSI);
595 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
596 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
597 }
598 }
599 else if((pScanResult->BssDescriptor.centerFreq - channel_id) == -6)
600 {
601 tSapSpectChInfo *pExtSpectCh = NULL;
602 pExtSpectCh = (pSpectCh - 1 );
603 if(pExtSpectCh != NULL)
604 {
605 ++pExtSpectCh->bssCount;
606 pExtSpectCh->rssiAgr = (pSpectCh->rssiAgr + SAP_EXT_CHAN_RSSI);
607 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
608 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
609 }
610 pExtSpectCh = (pSpectCh - 2);
611 if(pExtSpectCh != NULL)
612 {
613 ++pExtSpectCh->bssCount;
614 pExtSpectCh->rssiAgr = (pSpectCh->rssiAgr + SAP_EXT_SUBBAND2_RSSI);
615 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
616 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
617 }
618 pExtSpectCh = (pSpectCh - 3);
619 if(pExtSpectCh != NULL)
620 {
621 ++pExtSpectCh->bssCount;
622 pExtSpectCh->rssiAgr = (pSpectCh->rssiAgr + SAP_EXT_SUBBAND3_RSSI);
623 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
624 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
625 }
626 }
627 break;
628 }
629 }
630
Jeff Johnson295189b2012-06-20 16:38:30 -0700631 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -0800632 "In %s, bssdes.ch_self=%d, bssdes.ch_ID=%d, bssdes.rssi=%d, SpectCh.bssCount=%d, pScanResult=0x%x, ChannelWidth %d, secondaryChanOffset %d, center frequency %d \n",
633 __func__, pScanResult->BssDescriptor.channelIdSelf, pScanResult->BssDescriptor.channelId, pScanResult->BssDescriptor.rssi, pSpectCh->bssCount, pScanResult,pSpectCh->channelWidth,pScanResult->BssDescriptor.secondaryChannelOffset,pScanResult->BssDescriptor.centerFreq);
Jeff Johnson295189b2012-06-20 16:38:30 -0700634 pSpectCh++;
635 break;
636 } else {
637 pSpectCh++;
638 }
639 }
640
641 pScanResult = sme_ScanResultGetNext(halHandle, pResult);
642 }
643
644 // Calculate the weights for all channels in the spectrum pSpectCh
645 pSpectCh = pSpectInfoParams->pSpectCh;
646
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700647 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Spectrum Channels Weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700648
649 for (chn_num = 0; chn_num < (pSpectInfoParams->numSpectChans); chn_num++) {
650
651 /*
652 rssi : Maximum received signal strength among all BSS on that channel
653 bssCount : Number of BSS on that channel
654 */
655
656 rssi = (v_S7_t)pSpectCh->rssiAgr;
657
658 pSpectCh->weight = SAPDFS_NORMALISE_1000 * sapweightRssiCount(rssi, pSpectCh->bssCount);
659
660 //------ Debug Info ------
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700661 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Chan=%d Weight= %d rssiAgr=%d bssCount=%d", __func__, pSpectCh->chNum,
Jeff Johnson295189b2012-06-20 16:38:30 -0700662 pSpectCh->weight, pSpectCh->rssiAgr, pSpectCh->bssCount);
663 //------ Debug Info ------
664 pSpectCh++;
665 }
666}
667
668/*==========================================================================
669 FUNCTION sapChanSelExit
670
671 DESCRIPTION
672 Exit function for free out the allocated memory, to be called
673 at the end of the dfsSelectChannel function
674
675 DEPENDENCIES
676 NA.
677
678 PARAMETERS
679
680 IN
681 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
682
683 RETURN VALUE
684 void : NULL
685
686 SIDE EFFECTS
687============================================================================*/
688void sapChanSelExit( tSapChSelSpectInfo *pSpectInfoParams )
689{
690 // Free all the allocated memory
691 vos_mem_free(pSpectInfoParams->pSpectCh);
692}
693
694/*==========================================================================
695 FUNCTION sapSortChlWeight
696
697 DESCRIPTION
698 Funtion to sort the channels with the least weight first
699
700 DEPENDENCIES
701 NA.
702
703 PARAMETERS
704
705 IN
706 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
707
708 RETURN VALUE
709 void : NULL
710
711 SIDE EFFECTS
712============================================================================*/
713void sapSortChlWeight(tSapChSelSpectInfo *pSpectInfoParams)
714{
715 tSapSpectChInfo temp;
716
717 tSapSpectChInfo *pSpectCh = NULL;
718 v_U32_t i = 0, j = 0, minWeightIndex = 0;
719
720 pSpectCh = pSpectInfoParams->pSpectCh;
721#ifdef SOFTAP_CHANNEL_RANGE
722 // Sorting the channels as per weights
723 for (i = 0; i < pSpectInfoParams->numSpectChans; i++) {
724 minWeightIndex = i;
725 for( j = i + 1; j < pSpectInfoParams->numSpectChans; j++) {
726 if(pSpectCh[j].weight < pSpectCh[minWeightIndex].weight) {
727 minWeightIndex = j;
728 }
729 }
730 if(minWeightIndex != i) {
731 vos_mem_copy(&temp, &pSpectCh[minWeightIndex], sizeof(*pSpectCh));
732 vos_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], sizeof(*pSpectCh));
733 vos_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
734 }
735 }
736#else
737 // Sorting the channels as per weights
738 for (i = 0; i < SPECT_24GHZ_CH_COUNT; i++) {
739 minWeightIndex = i;
740 for( j = i + 1; j < SPECT_24GHZ_CH_COUNT; j++) {
741 if(pSpectCh[j].weight < pSpectCh[minWeightIndex].weight) {
742 minWeightIndex = j;
743 }
744 }
745 if(minWeightIndex != i) {
746 vos_mem_copy(&temp, &pSpectCh[minWeightIndex], sizeof(*pSpectCh));
747 vos_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], sizeof(*pSpectCh));
748 vos_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
749 }
750 }
751#endif
752
753 /* For testing */
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700754 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Sorted Spectrum Channels Weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700755 pSpectCh = pSpectInfoParams->pSpectCh;
756 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
757 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700758 __func__, pSpectCh->chNum, pSpectCh->weight, pSpectCh->rssiAgr, pSpectCh->bssCount);
Jeff Johnson295189b2012-06-20 16:38:30 -0700759 pSpectCh++;
760 }
761
762}
763
764/*==========================================================================
765 FUNCTION sapSelectChannel
766
767 DESCRIPTION
768 Runs a algorithm to select the best channel to operate in based on BSS
769 rssi and bss count on each channel
770
771 DEPENDENCIES
772 NA.
773
774 PARAMETERS
775
776 IN
777 halHandle : Pointer to HAL handle
778 pResult : Pointer to tScanResultHandle
779
780 RETURN VALUE
781 v_U8_t : Success - channel number, Fail - zero
782
783 SIDE EFFECTS
784============================================================================*/
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700785v_U8_t sapSelectChannel(tHalHandle halHandle, ptSapContext pSapCtx, tScanResultHandle pScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -0700786{
787 // DFS param object holding all the data req by the algo
788 tSapChSelSpectInfo oSpectInfoParams = {NULL,0};
789 tSapChSelSpectInfo *pSpectInfoParams = &oSpectInfoParams; // Memory? NB
790
791 v_U8_t bestChNum = 0;
792#ifdef SOFTAP_CHANNEL_RANGE
793 v_U32_t startChannelNum;
794 v_U32_t endChannelNum;
795 v_U32_t operatingBand;
796 v_U8_t count = 0;
797#endif
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700798 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 -0700799
800 // Set to zero tSapChSelParams
801 //vos_mem_zero(&sapChSelParams, sizeof(sapChSelParams));
802
803 // Initialize the structure pointed by pSpectInfoParams
804 if(sapChanSelInit( halHandle, pSpectInfoParams) != eSAP_TRUE ) {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700805 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "In %s, Ch Select initialization failed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700806 return SAP_CHANNEL_NOT_SELECTED;
807 }
808
809 // Compute the weight of the entire spectrum in the operating band
810 sapComputeSpectWeight( pSpectInfoParams, halHandle, pScanResult);
811
812 // Sort the 20M channel list as per the computed weights, lesser weight first.
813 sapSortChlWeight(pSpectInfoParams);
814
815#ifdef SOFTAP_CHANNEL_RANGE
816 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_START_CHANNEL, &startChannelNum);
817 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_END_CHANNEL, &endChannelNum);
818 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_OPERATING_BAND, &operatingBand);
819
820 /*Loop till get the best channel in the given range */
821 for(count=0; count < pSpectInfoParams->numSpectChans ; count++)
822 {
823 if((startChannelNum <= pSpectInfoParams->pSpectCh[count].chNum)&&
824 ( endChannelNum >= pSpectInfoParams->pSpectCh[count].chNum))
825 {
826 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[count].chNum;
827 break;
828 }
829 }
830
831#else
832 // Get the first channel in sorted array as best 20M Channel
833 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[0].chNum;
834
835#endif
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700836
837 //Select Best Channel from Channel List if Configured
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700838 bestChNum = sapSelectPreferredChannelFromChannelList(bestChNum, pSapCtx, pSpectInfoParams);
Jeff Johnson295189b2012-06-20 16:38:30 -0700839
840 // Free all the allocated memory
841 sapChanSelExit(pSpectInfoParams);
842
843 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Running SAP Ch select Completed, Ch=%d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700844 __func__, bestChNum);
Jeff Johnson295189b2012-06-20 16:38:30 -0700845
846 if (bestChNum > 0 && bestChNum <= 252)
847 return bestChNum;
848 else
849 return SAP_CHANNEL_NOT_SELECTED;
850}