blob: 1d9abc89e90f0daecb58400308e1c8ad510a0772 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Tang Yingying523322d2017-01-17 23:28:43 +08002 * Copyright (c) 2012-2017 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -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.
20 */
21
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
28/*===========================================================================
29
Anurag Chouhan6d760662016-02-20 16:05:43 +053030 s a p C h S e l e c t . C
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080031 OVERVIEW:
32
33 This software unit holds the implementation of the WLAN SAP modules
34 functions for channel selection.
35
36 DEPENDENCIES:
37
38 Are listed for each API below.
39 ===========================================================================*/
40
41/*--------------------------------------------------------------------------
42 Include Files
43 ------------------------------------------------------------------------*/
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053044#include "qdf_trace.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080045#include "csr_api.h"
46#include "sme_api.h"
47#include "sap_ch_select.h"
48#include "sap_internal.h"
49#ifdef ANI_OS_TYPE_QNX
50#include "stdio.h"
51#endif
52#ifdef FEATURE_AP_MCC_CH_AVOIDANCE
53#include "lim_utils.h"
54#include "parser_api.h"
55#endif /* FEATURE_AP_MCC_CH_AVOIDANCE */
Deepthi Gowri48b89332016-08-30 18:43:05 +053056#include "cds_utils.h"
Yuanyuan Liu0e0aa932016-05-12 10:17:58 -070057#include "pld_common.h"
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070058#include "wlan_reg_services_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080059
60/*--------------------------------------------------------------------------
61 Function definitions
62 --------------------------------------------------------------------------*/
63
64/*--------------------------------------------------------------------------
65 Defines
66 --------------------------------------------------------------------------*/
67#define SAP_DEBUG
68
69#define IS_RSSI_VALID(extRssi, rssi) \
70 ( \
71 ((extRssi < rssi) ? true : false) \
72 )
73
74#define SET_ACS_BAND(acs_band, pSapCtx) \
75{ \
76 if (pSapCtx->acs_cfg->start_ch <= 14 && \
77 pSapCtx->acs_cfg->end_ch <= 14) \
78 acs_band = eCSR_DOT11_MODE_11g; \
79 else if (pSapCtx->acs_cfg->start_ch >= 14)\
80 acs_band = eCSR_DOT11_MODE_11a; \
81 else \
82 acs_band = eCSR_DOT11_MODE_abg; \
83}
84
Tang Yingying523322d2017-01-17 23:28:43 +080085#define GET_IE_LEN_IN_BSS_DESC(lenInBss) (lenInBss + sizeof(lenInBss) - \
86 ((uintptr_t)OFFSET_OF(tSirBssDescription, ieFields)))
87
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080088#ifdef FEATURE_WLAN_CH_AVOID
Amar Singhalb8d4f152016-02-10 10:21:43 -080089sapSafeChannelType safe_channels[NUM_CHANNELS] = {
90 {1, true},
91 {2, true},
92 {3, true},
93 {4, true},
94 {5, true},
95 {6, true},
96 {7, true},
97 {8, true},
98 {9, true},
99 {10, true},
100 {11, true},
101 {12, true},
102 {13, true},
103 {14, true},
104 {36, true},
105 {40, true},
106 {44, true},
107 {48, true},
108 {52, true},
109 {56, true},
110 {60, true},
111 {64, true},
112 {100, true},
113 {104, true},
114 {108, true},
115 {112, true},
116 {116, true},
117 {120, true},
118 {124, true},
119 {128, true},
120 {132, true},
121 {136, true},
122 {140, true},
123 {144, true},
124 {149, true},
125 {153, true},
126 {157, true},
127 {161, true},
128 {165, true},
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800129};
130#endif
131
132typedef struct {
133 uint16_t chStartNum;
134 uint32_t weight;
135} sapAcsChannelInfo;
136
137sapAcsChannelInfo acs_ht40_channels5_g[] = {
138 {36, SAP_ACS_WEIGHT_MAX},
139 {44, SAP_ACS_WEIGHT_MAX},
140 {52, SAP_ACS_WEIGHT_MAX},
141 {60, SAP_ACS_WEIGHT_MAX},
142 {100, SAP_ACS_WEIGHT_MAX},
143 {108, SAP_ACS_WEIGHT_MAX},
144 {116, SAP_ACS_WEIGHT_MAX},
145 {124, SAP_ACS_WEIGHT_MAX},
146 {132, SAP_ACS_WEIGHT_MAX},
147 {140, SAP_ACS_WEIGHT_MAX},
148 {149, SAP_ACS_WEIGHT_MAX},
149 {157, SAP_ACS_WEIGHT_MAX},
150};
151
152sapAcsChannelInfo acs_ht80_channels[] = {
153 {36, SAP_ACS_WEIGHT_MAX},
154 {52, SAP_ACS_WEIGHT_MAX},
155 {100, SAP_ACS_WEIGHT_MAX},
156 {116, SAP_ACS_WEIGHT_MAX},
157 {132, SAP_ACS_WEIGHT_MAX},
158 {149, SAP_ACS_WEIGHT_MAX},
159};
160
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -0700161sapAcsChannelInfo acs_vht160_channels[] = {
162 {36, SAP_ACS_WEIGHT_MAX},
163 {100, SAP_ACS_WEIGHT_MAX},
164};
165
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800166sapAcsChannelInfo acs_ht40_channels24_g[] = {
167 {1, SAP_ACS_WEIGHT_MAX},
168 {2, SAP_ACS_WEIGHT_MAX},
169 {3, SAP_ACS_WEIGHT_MAX},
170 {4, SAP_ACS_WEIGHT_MAX},
171 {9, SAP_ACS_WEIGHT_MAX},
172};
173
174#define CHANNEL_165 165
175
176/* rssi discount for channels in PCL */
177#define PCL_RSSI_DISCOUNT 10
178
179#ifdef FEATURE_AP_MCC_CH_AVOIDANCE
180/**
181 * sap_check_n_add_channel() - checks and add given channel in sap context's
182 * avoid_channels_info struct
183 * @sap_ctx: sap context.
184 * @new_channel: channel to be added to sap_ctx's avoid ch info
185 *
186 * sap_ctx contains sap_avoid_ch_info strcut containing the list of channels on
187 * which MDM device's AP with MCC was detected. This function will add channels
188 * to that list after checking for duplicates.
189 *
190 * Return: true: if channel was added or already present
191 * else false: if channel list was already full.
192 */
Tang Yingying523322d2017-01-17 23:28:43 +0800193static bool
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800194sap_check_n_add_channel(ptSapContext sap_ctx,
195 uint8_t new_channel)
196{
197 uint8_t i = 0;
198 struct sap_avoid_channels_info *ie_info =
199 &sap_ctx->sap_detected_avoid_ch_ie;
200
201 for (i = 0; i < sizeof(ie_info->channels); i++) {
202 if (ie_info->channels[i] == new_channel)
203 break;
204
205 if (ie_info->channels[i] == 0) {
206 ie_info->channels[i] = new_channel;
207 break;
208 }
209 }
210 if (i == sizeof(ie_info->channels))
211 return false;
212 else
213 return true;
214}
215/**
216 * sap_check_n_add_overlapped_chnls() - checks & add overlapped channels
217 * to primary channel in 2.4Ghz band.
218 * @sap_ctx: sap context.
219 * @primary_chnl: primary channel to be avoided.
220 *
221 * sap_ctx contains sap_avoid_ch_info struct containing the list of channels on
222 * which MDM device's AP with MCC was detected. This function will add channels
223 * to that list after checking for duplicates.
224 *
225 * Return: true: if channel was added or already present
226 * else false: if channel list was already full.
227 */
228static bool
229sap_check_n_add_overlapped_chnls(ptSapContext sap_ctx, uint8_t primary_channel)
230{
231 uint8_t i = 0, j = 0, upper_chnl = 0, lower_chnl = 0;
232 struct sap_avoid_channels_info *ie_info =
233 &sap_ctx->sap_detected_avoid_ch_ie;
234 /*
235 * if primary channel less than channel 1 or out of 2g band then
236 * no further process is required. return true in this case.
237 */
238 if (primary_channel < CHANNEL_1 || primary_channel > CHANNEL_14)
239 return true;
240
241 /* lower channel is one channel right before primary channel */
242 lower_chnl = primary_channel - 1;
243 /* upper channel is one channel right after primary channel */
244 upper_chnl = primary_channel + 1;
245
246 /* lower channel needs to be non-zero, zero is not valid channel */
247 if (lower_chnl > (CHANNEL_1 - 1)) {
248 for (i = 0; i < sizeof(ie_info->channels); i++) {
249 if (ie_info->channels[i] == lower_chnl)
250 break;
251 if (ie_info->channels[i] == 0) {
252 ie_info->channels[i] = lower_chnl;
253 break;
254 }
255 }
256 }
257 /* upper channel needs to be atleast last channel in 2.4Ghz band */
258 if (upper_chnl < (CHANNEL_14 + 1)) {
259 for (j = 0; j < sizeof(ie_info->channels); j++) {
260 if (ie_info->channels[j] == upper_chnl)
261 break;
262 if (ie_info->channels[j] == 0) {
263 ie_info->channels[j] = upper_chnl;
264 break;
265 }
266 }
267 }
268 if (i == sizeof(ie_info->channels) || j == sizeof(ie_info->channels))
269 return false;
270 else
271 return true;
272}
273
274/**
275 * sap_process_avoid_ie() - processes the detected Q2Q IE
276 * context's avoid_channels_info struct
277 * @hal: hal handle
278 * @sap_ctx: sap context.
279 * @scan_result: scan results for ACS scan.
280 * @spect_info: spectrum weights array to update
281 *
282 * Detection of Q2Q IE indicates presence of another MDM device with its AP
283 * operating in MCC mode. This function parses the scan results and processes
284 * the Q2Q IE if found. It then extracts the channels and populates them in
285 * sap_ctx struct. It also increases the weights of those channels so that
286 * ACS logic will avoid those channels in its selection algorithm.
287 *
288 * Return: void
289 */
Tang Yingying523322d2017-01-17 23:28:43 +0800290static void sap_process_avoid_ie(tHalHandle hal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800291 ptSapContext sap_ctx,
292 tScanResultHandle scan_result,
293 tSapChSelSpectInfo *spect_info)
294{
295 uint32_t total_ie_len = 0;
296 uint8_t *temp_ptr = NULL;
297 uint8_t i = 0;
298 struct sAvoidChannelIE *avoid_ch_ie;
299 tCsrScanResultInfo *node = NULL;
300 tpAniSirGlobal mac_ctx = NULL;
301 tSapSpectChInfo *spect_ch = NULL;
302
303 mac_ctx = PMAC_STRUCT(hal);
304 spect_ch = spect_info->pSpectCh;
305 node = sme_scan_result_get_first(hal, scan_result);
306
307 while (node) {
Abhishek Singh34a4d862016-10-26 16:01:51 +0530308 total_ie_len =
309 GET_IE_LEN_IN_BSS_DESC(node->BssDescriptor.length);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800310 temp_ptr = cfg_get_vendor_ie_ptr_from_oui(mac_ctx,
311 SIR_MAC_QCOM_VENDOR_OUI,
312 SIR_MAC_QCOM_VENDOR_SIZE,
313 ((uint8_t *)&node->BssDescriptor.ieFields),
314 total_ie_len);
315
316 if (temp_ptr) {
317 avoid_ch_ie = (struct sAvoidChannelIE *)temp_ptr;
Will Huang55ba1042017-03-22 10:43:30 +0800318 if (avoid_ch_ie->type !=
319 QCOM_VENDOR_IE_MCC_AVOID_CH) {
320 node = sme_scan_result_get_next(hal,
321 scan_result);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800322 continue;
Will Huang55ba1042017-03-22 10:43:30 +0800323 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800324
325 sap_ctx->sap_detected_avoid_ch_ie.present = 1;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530326 QDF_TRACE(QDF_MODULE_ID_SAP,
327 QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800328 "Q2Q IE - avoid ch %d",
329 avoid_ch_ie->channel);
330 /* add this channel to to_avoid channel list */
331 sap_check_n_add_channel(sap_ctx,
332 avoid_ch_ie->channel);
333 sap_check_n_add_overlapped_chnls(sap_ctx,
334 avoid_ch_ie->channel);
335 /*
336 * Mark weight of these channel present in IE to MAX
337 * so that ACS logic will to avoid thse channels
338 */
339 for (i = 0; i < spect_info->numSpectChans; i++)
340 if (spect_ch[i].chNum == avoid_ch_ie->channel) {
341 /*
342 * weight is set more than max so that,
343 * in the case of other channels being
344 * assigned max weight due to noise,
345 * they may be preferred over channels
346 * with Q2Q IE.
347 */
348 spect_ch[i].weight = SAP_ACS_WEIGHT_MAX + 1;
349 spect_ch[i].weight_copy =
350 SAP_ACS_WEIGHT_MAX + 1;
351 break;
352 }
353 } /* if (temp_ptr) */
354 node = sme_scan_result_get_next(hal, scan_result);
355 }
356}
357#endif /* FEATURE_AP_MCC_CH_AVOIDANCE */
358
359#ifdef FEATURE_WLAN_CH_AVOID
360/*==========================================================================
361 FUNCTION sap_update_unsafe_channel_list
362
363 DESCRIPTION
364 Function Undate unsafe channel list table
365
366 DEPENDENCIES
367 NA.
368
369 IN
370 SapContext pointer
371
372 RETURN VALUE
373 NULL
374 ============================================================================*/
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700375void sap_update_unsafe_channel_list(tHalHandle hal, ptSapContext pSapCtx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800376{
377 uint16_t i, j;
Amar Singhalb8d4f152016-02-10 10:21:43 -0800378 uint16_t unsafe_channel_list[NUM_CHANNELS];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800379 uint16_t unsafe_channel_count = 0;
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700380 tpAniSirGlobal mac_ctx = NULL;
381
Yuanyuan Liu0e0aa932016-05-12 10:17:58 -0700382 qdf_device_t qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800383
Yuanyuan Liu97361182016-06-06 09:38:04 -0700384 if (!qdf_ctx) {
385 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_FATAL,
386 "qdf_ctx is NULL");
387 return;
388 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700389 mac_ctx = PMAC_STRUCT(hal);
390 if (!mac_ctx) {
391 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_FATAL,
392 "mac_ctx is NULL");
393 return;
394 }
Yuanyuan Liu97361182016-06-06 09:38:04 -0700395
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800396 /* Flush, default set all channel safe */
Amar Singhalb8d4f152016-02-10 10:21:43 -0800397 for (i = 0; i < NUM_CHANNELS; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800398 safe_channels[i].isSafe = true;
399 }
400
401 /* Try to find unsafe channel */
Ryan Hsu4252a2f2016-01-05 11:18:24 -0800402#if defined(FEATURE_WLAN_STA_AP_MODE_DFS_DISABLE)
Amar Singhalb8d4f152016-02-10 10:21:43 -0800403 for (i = 0; i < NUM_CHANNELS; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800404 if (pSapCtx->dfs_ch_disable == true) {
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700405 if (wlan_reg_is_dfs_ch(mac_ctx->pdev,
406 safe_channels[i].channelNumber)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800407 safe_channels[i].isSafe = false;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530408 QDF_TRACE(QDF_MODULE_ID_SAP,
409 QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800410 "%s: DFS Ch %d is not safe in"
411 " Concurrent mode",
412 __func__,
413 safe_channels[i].channelNumber);
414 }
415 }
416 }
417#endif
Yuanyuan Liu0e0aa932016-05-12 10:17:58 -0700418 pld_get_wlan_unsafe_channel(qdf_ctx->dev,
419 unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800420 &unsafe_channel_count,
421 sizeof(unsafe_channel_list));
422
423 for (i = 0; i < unsafe_channel_count; i++) {
Amar Singhalb8d4f152016-02-10 10:21:43 -0800424 for (j = 0; j < NUM_CHANNELS; j++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800425 if (safe_channels[j].channelNumber ==
426 unsafe_channel_list[i]) {
427 /* Found unsafe channel, update it */
428 safe_channels[j].isSafe = false;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530429 QDF_TRACE(QDF_MODULE_ID_SAP,
430 QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800431 FL("CH %d is not safe"),
432 unsafe_channel_list[i]);
433 break;
434 }
435 }
436 }
437
438 return;
439}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800440
441#endif /* FEATURE_WLAN_CH_AVOID */
442
443/*==========================================================================
444 FUNCTION sap_cleanup_channel_list
445
446 DESCRIPTION
447 Function sap_cleanup_channel_list frees up the memory allocated to the channel list.
448
449 DEPENDENCIES
450 NA.
451
452 PARAMETERS
453
454 IN
455 NULL
456
457 RETURN VALUE
458 NULL
459 ============================================================================*/
460
Ryan Hsu4252a2f2016-01-05 11:18:24 -0800461void sap_cleanup_channel_list(void *p_cds_gctx)
462{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800463 ptSapContext pSapCtx;
464
Srinivas Girigowda678586c2017-03-10 00:13:58 -0800465 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800466 "Cleaning up the channel list structure");
467
468 if (NULL == p_cds_gctx) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530469 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800470 "SAP Global Context is NULL");
471 return;
472 }
473
474 pSapCtx = CDS_GET_SAP_CB(p_cds_gctx);
475 if (NULL == pSapCtx) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530476 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800477 "SAP Context is NULL");
478 return;
479 }
480
481 pSapCtx->SapChnlList.numChannel = 0;
482 if (pSapCtx->SapChnlList.channelList) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530483 qdf_mem_free(pSapCtx->SapChnlList.channelList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800484 pSapCtx->SapChnlList.channelList = NULL;
485 }
486
487 pSapCtx->SapAllChnlList.numChannel = 0;
488 if (pSapCtx->SapAllChnlList.channelList) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530489 qdf_mem_free(pSapCtx->SapAllChnlList.channelList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800490 pSapCtx->SapAllChnlList.channelList = NULL;
491 }
492}
493
494/**
495 * sap_select_preferred_channel_from_channel_list() - to calc best cahnnel
496 * @best_chnl: best channel already calculated among all the chanels
497 * @sap_ctx: sap context
498 * @spectinfo_param: Pointer to tSapChSelSpectInfo structure
499 *
500 * This function calculates the best channel among the configured channel list.
501 * If channel list not configured then returns the best channel calculated
502 * among all the channel list.
503 *
504 * Return: uint8_t best channel
505 */
Jeff Johnson464f7ea2016-10-07 10:21:26 -0700506static
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800507uint8_t sap_select_preferred_channel_from_channel_list(uint8_t best_chnl,
508 ptSapContext sap_ctx,
509 tSapChSelSpectInfo *spectinfo_param)
510{
511 uint8_t i = 0;
Tushnim Bhattacharyya518e80f2017-08-30 17:35:33 -0700512 tpAniSirGlobal mac_ctx = sme_get_mac_context();
513
514 if (NULL == mac_ctx) {
515 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR,
516 "pmac Global Context is NULL");
517 return SAP_CHANNEL_NOT_SELECTED;
518 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800519
520 /*
521 * If Channel List is not Configured don't do anything
522 * Else return the Best Channel from the Channel List
523 */
524 if ((NULL == sap_ctx->acs_cfg->ch_list) ||
525 (NULL == spectinfo_param) ||
526 (0 == sap_ctx->acs_cfg->ch_list_count))
527 return best_chnl;
528
529 if (best_chnl <= 0 || best_chnl > 252)
530 return SAP_CHANNEL_NOT_SELECTED;
531
532 /* Select the best channel from allowed list */
533 for (i = 0; i < sap_ctx->acs_cfg->ch_list_count; i++) {
Tushnim Bhattacharyya518e80f2017-08-30 17:35:33 -0700534 if ((sap_ctx->acs_cfg->ch_list[i] == best_chnl) &&
535 !(wlan_reg_is_dfs_ch(mac_ctx->pdev, best_chnl) &&
536 policy_mgr_disallow_mcc(mac_ctx->psoc, best_chnl))) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530537 QDF_TRACE(QDF_MODULE_ID_SAP,
538 QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800539 "Best channel is: %d",
540 best_chnl);
541 return best_chnl;
542 }
543 }
544
545 return SAP_CHANNEL_NOT_SELECTED;
546}
547
548/*==========================================================================
549 FUNCTION sap_chan_sel_init
550
551 DESCRIPTION
552 Function sap_chan_sel_init allocates the memory, intializes the
Anurag Chouhan6d760662016-02-20 16:05:43 +0530553 structures used by the channel selection algorithm
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800554
555 DEPENDENCIES
556 NA.
557
558 PARAMETERS
559
560 IN
561 halHandle : Pointer to tHalHandle
562 *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure
563 pSapCtx : Pointer to SAP Context
564
565 RETURN VALUE
566 bool: Success or FAIL
567
568 SIDE EFFECTS
569 ============================================================================*/
Jeff Johnson464f7ea2016-10-07 10:21:26 -0700570static bool sap_chan_sel_init(tHalHandle halHandle,
571 tSapChSelSpectInfo *pSpectInfoParams,
572 ptSapContext pSapCtx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800573{
574 tSapSpectChInfo *pSpectCh = NULL;
575 uint8_t *pChans = NULL;
576 uint16_t channelnum = 0;
577 tpAniSirGlobal pMac = PMAC_STRUCT(halHandle);
578 bool chSafe = true;
579#ifdef FEATURE_WLAN_CH_AVOID
580 uint16_t i;
581#endif
582 uint32_t dfs_master_cap_enabled;
583 bool include_dfs_ch = true;
584
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530585 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, "In %s",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800586 __func__);
587
588 pSpectInfoParams->numSpectChans =
589 pMac->scan.base_channels.numChannels;
590
591 /* Allocate memory for weight computation of 2.4GHz */
592 pSpectCh =
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530593 (tSapSpectChInfo *) qdf_mem_malloc((pSpectInfoParams->numSpectChans)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800594 * sizeof(*pSpectCh));
595
596 if (pSpectCh == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530597 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR,
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530598 "In %s, QDF_MALLOC_ERR", __func__);
Srinivas Girigowda74a66d62017-06-21 23:28:25 -0700599 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800600 }
601
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800602 /* Initialize the pointers in the DfsParams to the allocated memory */
603 pSpectInfoParams->pSpectCh = pSpectCh;
604
605 pChans = pMac->scan.base_channels.channelList;
606
Ryan Hsu4252a2f2016-01-05 11:18:24 -0800607#if defined(FEATURE_WLAN_STA_AP_MODE_DFS_DISABLE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800608 if (pSapCtx->dfs_ch_disable == true)
609 include_dfs_ch = false;
610#endif
611 sme_cfg_get_int(halHandle, WNI_CFG_DFS_MASTER_ENABLED,
612 &dfs_master_cap_enabled);
Agrawal Ashish65634612016-08-18 13:24:32 +0530613 if (dfs_master_cap_enabled == 0 ||
614 ACS_DFS_MODE_DISABLE == pSapCtx->dfs_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800615 include_dfs_ch = false;
616
617 /* Fill the channel number in the spectrum in the operating freq band */
618 for (channelnum = 0;
619 channelnum < pSpectInfoParams->numSpectChans;
Edhar, Mahesh Kumar4f660672015-10-30 11:53:26 +0530620 channelnum++, pChans++, pSpectCh++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800621 chSafe = true;
622
623 /* check if the channel is in NOL blacklist */
624 if (sap_dfs_is_channel_in_nol_list(pSapCtx, *pChans,
625 PHY_SINGLE_CHANNEL_CENTERED)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530626 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800627 "In %s, Ch %d is in NOL list", __func__,
628 *pChans);
629 chSafe = false;
630 continue;
631 }
632
633 if (include_dfs_ch == false) {
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700634 if (wlan_reg_is_dfs_ch(pMac->pdev, *pChans)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800635 chSafe = false;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530636 QDF_TRACE(QDF_MODULE_ID_SAP,
637 QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800638 "In %s, DFS Ch %d not considered for ACS",
639 __func__, *pChans);
640 continue;
641 }
642 }
643
644#ifdef FEATURE_WLAN_CH_AVOID
Amar Singhalb8d4f152016-02-10 10:21:43 -0800645 for (i = 0; i < NUM_CHANNELS; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800646 if ((safe_channels[i].channelNumber == *pChans) &&
647 (false == safe_channels[i].isSafe)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530648 QDF_TRACE(QDF_MODULE_ID_SAP,
649 QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800650 "In %s, Ch %d is not safe", __func__,
651 *pChans);
652 chSafe = false;
653 break;
654 }
655 }
656#endif /* FEATURE_WLAN_CH_AVOID */
657
658 /* OFDM rates are not supported on channel 14 */
659 if (*pChans == 14 &&
660 eCSR_DOT11_MODE_11b != pSapCtx->csr_roamProfile.phyMode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800661 continue;
662 }
663
Deepthi Gowri48b89332016-08-30 18:43:05 +0530664 /* Skip DSRC channels */
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700665 if (WLAN_REG_IS_11P_CH(*pChans))
Deepthi Gowri48b89332016-08-30 18:43:05 +0530666 continue;
667
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800668 if (true == chSafe) {
669 pSpectCh->chNum = *pChans;
Srinivas Girigowda74a66d62017-06-21 23:28:25 -0700670 pSpectCh->valid = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800671 pSpectCh->rssiAgr = SOFTAP_MIN_RSSI; /* Initialise for all channels */
672 pSpectCh->channelWidth = SOFTAP_HT20_CHANNELWIDTH; /* Initialise 20MHz for all the Channels */
673 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800674 }
Srinivas Girigowda74a66d62017-06-21 23:28:25 -0700675 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800676}
677
678/*==========================================================================
679 FUNCTION sapweight_rssi_count
680
681 DESCRIPTION
682 Function weightRssiCount calculates the channel weight due to rssi
Anurag Chouhan6d760662016-02-20 16:05:43 +0530683 and data count(here number of BSS observed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800684
685 DEPENDENCIES
686 NA.
687
688 PARAMETERS
689
690 IN
691 rssi : Max signal strength receieved from a BSS for the channel
692 count : Number of BSS observed in the channel
693
694 RETURN VALUE
695 uint32_t : Calculated channel weight based on above two
696
697 SIDE EFFECTS
698 ============================================================================*/
Jeff Johnson464f7ea2016-10-07 10:21:26 -0700699static uint32_t sapweight_rssi_count(int8_t rssi, uint16_t count)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800700{
701 int32_t rssiWeight = 0;
702 int32_t countWeight = 0;
703 uint32_t rssicountWeight = 0;
704
705 /* Weight from RSSI */
706 rssiWeight = SOFTAP_RSSI_WEIGHT * (rssi - SOFTAP_MIN_RSSI)
707 / (SOFTAP_MAX_RSSI - SOFTAP_MIN_RSSI);
708
709 if (rssiWeight > SOFTAP_RSSI_WEIGHT)
710 rssiWeight = SOFTAP_RSSI_WEIGHT;
711 else if (rssiWeight < 0)
712 rssiWeight = 0;
713
714 /* Weight from data count */
715 countWeight = SOFTAP_COUNT_WEIGHT * (count - SOFTAP_MIN_COUNT)
716 / (SOFTAP_MAX_COUNT - SOFTAP_MIN_COUNT);
717
718 if (countWeight > SOFTAP_COUNT_WEIGHT)
719 countWeight = SOFTAP_COUNT_WEIGHT;
720
721 rssicountWeight = rssiWeight + countWeight;
722
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530723 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800724 "In %s, rssiWeight=%d, countWeight=%d, rssicountWeight=%d",
725 __func__, rssiWeight, countWeight, rssicountWeight);
726
727 return rssicountWeight;
728}
729
730/**
731 * sap_update_rssi_bsscount() - updates bss count and rssi effect.
732 *
733 * @pSpectCh: Channel Information
734 * @offset: Channel Offset
735 * @sap_24g: Channel is in 2.4G or 5G
Liangwei Dong71ed6502016-10-20 03:40:45 -0400736 * @spectch_start: the start of spect ch array
737 * @spectch_end: the end of spect ch array
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800738 *
739 * sap_update_rssi_bsscount updates bss count and rssi effect based
740 * on the channel offset.
741 *
742 * Return: None.
743 */
744
Jeff Johnson464f7ea2016-10-07 10:21:26 -0700745static void sap_update_rssi_bsscount(tSapSpectChInfo *pSpectCh, int32_t offset,
Liangwei Dong71ed6502016-10-20 03:40:45 -0400746 bool sap_24g, tSapSpectChInfo *spectch_start,
747 tSapSpectChInfo *spectch_end)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800748{
749 tSapSpectChInfo *pExtSpectCh = NULL;
750 int32_t rssi, rsssi_effect;
751
752 pExtSpectCh = (pSpectCh + offset);
Liangwei Dong71ed6502016-10-20 03:40:45 -0400753 if (pExtSpectCh != NULL &&
754 pExtSpectCh >= spectch_start &&
755 pExtSpectCh < spectch_end) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800756 ++pExtSpectCh->bssCount;
757 switch (offset) {
758 case -1:
759 case 1:
760 rsssi_effect = sap_24g ?
761 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY :
762 SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
763 break;
764 case -2:
765 case 2:
766 rsssi_effect = sap_24g ?
767 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY :
768 SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
769 break;
770 case -3:
771 case 3:
772 rsssi_effect = sap_24g ?
773 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY :
774 SAP_SUBBAND3_RSSI_EFFECT_PRIMARY;
775 break;
776 case -4:
777 case 4:
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -0700778 rsssi_effect = sap_24g ?
779 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY :
780 SAP_SUBBAND4_RSSI_EFFECT_PRIMARY;
781 break;
782 case -5:
783 case 5:
784 rsssi_effect = SAP_SUBBAND5_RSSI_EFFECT_PRIMARY;
785 break;
786 case -6:
787 case 6:
788 rsssi_effect = SAP_SUBBAND6_RSSI_EFFECT_PRIMARY;
789 break;
790 case -7:
791 case 7:
792 rsssi_effect = SAP_SUBBAND7_RSSI_EFFECT_PRIMARY;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800793 break;
794 default:
795 rsssi_effect = 0;
796 break;
797 }
798
799 rssi = pSpectCh->rssiAgr + rsssi_effect;
800 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
801 pExtSpectCh->rssiAgr = rssi;
802 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
803 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
804 }
805}
806
807/**
808 * sap_upd_chan_spec_params() - sap_upd_chan_spec_params
809 * updates channel parameters obtained from Beacon
810 * @pBeaconStruct Beacon strucutre populated by parse_beacon function
811 * @channelWidth Channel width
812 * @secondaryChannelOffset Secondary Channel Offset
813 * @vhtSupport If channel supports VHT
814 * @centerFreq Central frequency for the given channel.
815 *
816 * sap_upd_chan_spec_params updates the spectrum channels based on the
817 * pBeaconStruct obtained from Beacon IE
818 *
819 * Return: NA.
820 */
821
Jeff Johnson464f7ea2016-10-07 10:21:26 -0700822static void sap_upd_chan_spec_params(tSirProbeRespBeacon *pBeaconStruct,
823 uint16_t *channelWidth,
824 uint16_t *secondaryChannelOffset,
825 uint16_t *vhtSupport,
826 uint16_t *centerFreq,
827 uint16_t *centerFreq_2)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800828{
829 if (NULL == pBeaconStruct) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530830 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800831 FL("pBeaconStruct is NULL"));
832 return;
833 }
834
835 if (pBeaconStruct->HTCaps.present && pBeaconStruct->HTInfo.present) {
836 *channelWidth = pBeaconStruct->HTCaps.supportedChannelWidthSet;
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -0700837 *secondaryChannelOffset =
838 pBeaconStruct->HTInfo.secondaryChannelOffset;
839 if (!pBeaconStruct->VHTOperation.present)
840 return;
841 *vhtSupport = pBeaconStruct->VHTOperation.present;
842 if (pBeaconStruct->VHTOperation.chanWidth) {
843 *centerFreq =
844 pBeaconStruct->VHTOperation.chanCenterFreqSeg1;
845 *centerFreq_2 =
846 pBeaconStruct->VHTOperation.chanCenterFreqSeg2;
847 /*
848 * LHS follows tSirMacHTChannelWidth, while RHS follows
849 * WNI_CFG_VHT_CHANNEL_WIDTH_X format hence following
850 * adjustment
851 */
852 *channelWidth =
853 pBeaconStruct->VHTOperation.chanWidth + 1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800854
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800855 }
856 }
857}
858
859/**
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -0700860 * sap_update_rssi_bsscount_vht_5G() - updates bss count and rssi effect.
861 *
Jeff Johnson464f7ea2016-10-07 10:21:26 -0700862 * @spect_ch: Channel Information
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -0700863 * @offset: Channel Offset
864 * @num_ch: no.of channels
Liangwei Dong71ed6502016-10-20 03:40:45 -0400865 * @spectch_start: the start of spect ch array
866 * @spectch_end: the end of spect ch array
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -0700867 *
868 * sap_update_rssi_bsscount_vht_5G updates bss count and rssi effect based
869 * on the channel offset.
870 *
871 * Return: None.
872 */
873
Jeff Johnson464f7ea2016-10-07 10:21:26 -0700874static void sap_update_rssi_bsscount_vht_5G(tSapSpectChInfo *spect_ch,
875 int32_t offset,
Liangwei Dong71ed6502016-10-20 03:40:45 -0400876 uint16_t num_ch,
877 tSapSpectChInfo *spectch_start,
878 tSapSpectChInfo *spectch_end)
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -0700879{
880 int32_t ch_offset;
881 uint16_t i, cnt;
882
883 if (!offset)
884 return;
885 if (offset > 0)
886 cnt = num_ch;
887 else
888 cnt = num_ch + 1;
889 for (i = 0; i < cnt; i++) {
890 ch_offset = offset + i;
891 if (ch_offset == 0)
892 continue;
Liangwei Dong71ed6502016-10-20 03:40:45 -0400893 sap_update_rssi_bsscount(spect_ch, ch_offset, false,
894 spectch_start, spectch_end);
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -0700895 }
896}
897/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800898 * sap_interference_rssi_count_5G() - sap_interference_rssi_count
899 * considers the Adjacent channel rssi and
900 * data count(here number of BSS observed)
901 * @spect_ch: Channel Information
902 * @chan_width: Channel width parsed from beacon IE
903 * @sec_chan_offset: Secondary Channel Offset
904 * @center_freq: Central frequency for the given channel.
905 * @channel_id: channel_id
Liangwei Dong71ed6502016-10-20 03:40:45 -0400906 * @spectch_start: the start of spect ch array
907 * @spectch_end: the end of spect ch array
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800908 *
909 * sap_interference_rssi_count_5G considers the Adjacent channel rssi
910 * and data count(here number of BSS observed)
911 *
912 * Return: NA.
913 */
914
Jeff Johnson464f7ea2016-10-07 10:21:26 -0700915static void sap_interference_rssi_count_5G(tSapSpectChInfo *spect_ch,
916 uint16_t chan_width,
917 uint16_t sec_chan_offset,
918 uint16_t center_freq,
919 uint16_t center_freq_2,
Liangwei Dong71ed6502016-10-20 03:40:45 -0400920 uint8_t channel_id,
921 tSapSpectChInfo *spectch_start,
922 tSapSpectChInfo *spectch_end)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800923{
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -0700924 uint16_t num_ch;
925 int32_t offset = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800926 if (NULL == spect_ch) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530927 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800928 FL("spect_ch is NULL"));
929 return;
930 }
931
932 /* Updating the received ChannelWidth */
933 if (spect_ch->channelWidth != chan_width)
934 spect_ch->channelWidth = chan_width;
935 /* If received ChannelWidth is other than HT20,
936 * we need to update the extension channel Params as well
937 * chan_width == 0, HT20
938 * chan_width == 1, HT40
939 * chan_width == 2, VHT80
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -0700940 * chan_width == 3, VHT160
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800941 */
942
943 switch (spect_ch->channelWidth) {
944 case eHT_CHANNEL_WIDTH_40MHZ: /* HT40 */
945 switch (sec_chan_offset) {
946 /* Above the Primary Channel */
947 case PHY_DOUBLE_CHANNEL_LOW_PRIMARY:
Liangwei Dong71ed6502016-10-20 03:40:45 -0400948 sap_update_rssi_bsscount(spect_ch, 1, false,
949 spectch_start, spectch_end);
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -0700950 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800951
952 /* Below the Primary channel */
953 case PHY_DOUBLE_CHANNEL_HIGH_PRIMARY:
Liangwei Dong71ed6502016-10-20 03:40:45 -0400954 sap_update_rssi_bsscount(spect_ch, -1, false,
955 spectch_start, spectch_end);
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -0700956 return;
957 }
958 return;
959 case eHT_CHANNEL_WIDTH_80MHZ: /* VHT80 */
960 num_ch = 3;
961 if ((center_freq - channel_id) == 6) {
962 offset = 1;
963 } else if ((center_freq - channel_id) == 2) {
964 offset = -1;
965 } else if ((center_freq - channel_id) == -2) {
966 offset = -2;
967 } else if ((center_freq - channel_id) == -6) {
968 offset = -3;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800969 }
970 break;
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -0700971 case eHT_CHANNEL_WIDTH_160MHZ: /* VHT160 */
972 num_ch = 7;
973 if ((center_freq - channel_id) == 14)
974 offset = 1;
975 else if ((center_freq - channel_id) == 10)
976 offset = -1;
977 else if ((center_freq - channel_id) == 6)
978 offset = -2;
979 else if ((center_freq - channel_id) == 2)
980 offset = -3;
981 else if ((center_freq - channel_id) == -2)
982 offset = -4;
983 else if ((center_freq - channel_id) == -6)
984 offset = -5;
985 else if ((center_freq - channel_id) == -10)
986 offset = -6;
987 else if ((center_freq - channel_id) == -14)
988 offset = -7;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800989 break;
990 default:
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -0700991 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800992 }
Liangwei Dong71ed6502016-10-20 03:40:45 -0400993 sap_update_rssi_bsscount_vht_5G(spect_ch, offset, num_ch,
994 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800995}
996
997/**
998 * sap_interference_rssi_count() - sap_interference_rssi_count
999 * considers the Adjacent channel rssi
1000 * and data count(here number of BSS observed)
1001 * @spect_ch Channel Information
Liangwei Dong71ed6502016-10-20 03:40:45 -04001002 * @spectch_start: the start of spect ch array
1003 * @spectch_end: the end of spect ch array
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001004 *
1005 * sap_interference_rssi_count considers the Adjacent channel rssi
1006 * and data count(here number of BSS observed)
1007 *
1008 * Return: None.
1009 */
1010
Liangwei Dong71ed6502016-10-20 03:40:45 -04001011static void sap_interference_rssi_count(tSapSpectChInfo *spect_ch,
1012 tSapSpectChInfo *spectch_start,
1013 tSapSpectChInfo *spectch_end)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001014{
1015 if (NULL == spect_ch) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301016 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001017 "%s: spect_ch is NULL", __func__);
1018 return;
1019 }
1020
1021 switch (spect_ch->chNum) {
1022 case CHANNEL_1:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001023 sap_update_rssi_bsscount(spect_ch, 1, true,
1024 spectch_start, spectch_end);
1025 sap_update_rssi_bsscount(spect_ch, 2, true,
1026 spectch_start, spectch_end);
1027 sap_update_rssi_bsscount(spect_ch, 3, true,
1028 spectch_start, spectch_end);
1029 sap_update_rssi_bsscount(spect_ch, 4, true,
1030 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001031 break;
1032
1033 case CHANNEL_2:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001034 sap_update_rssi_bsscount(spect_ch, -1, true,
1035 spectch_start, spectch_end);
1036 sap_update_rssi_bsscount(spect_ch, 1, true,
1037 spectch_start, spectch_end);
1038 sap_update_rssi_bsscount(spect_ch, 2, true,
1039 spectch_start, spectch_end);
1040 sap_update_rssi_bsscount(spect_ch, 3, true,
1041 spectch_start, spectch_end);
1042 sap_update_rssi_bsscount(spect_ch, 4, true,
1043 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001044 break;
1045 case CHANNEL_3:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001046 sap_update_rssi_bsscount(spect_ch, -2, true,
1047 spectch_start, spectch_end);
1048 sap_update_rssi_bsscount(spect_ch, -1, true,
1049 spectch_start, spectch_end);
1050 sap_update_rssi_bsscount(spect_ch, 1, true,
1051 spectch_start, spectch_end);
1052 sap_update_rssi_bsscount(spect_ch, 2, true,
1053 spectch_start, spectch_end);
1054 sap_update_rssi_bsscount(spect_ch, 3, true,
1055 spectch_start, spectch_end);
1056 sap_update_rssi_bsscount(spect_ch, 4, true,
1057 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001058 break;
1059 case CHANNEL_4:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001060 sap_update_rssi_bsscount(spect_ch, -3, true,
1061 spectch_start, spectch_end);
1062 sap_update_rssi_bsscount(spect_ch, -2, true,
1063 spectch_start, spectch_end);
1064 sap_update_rssi_bsscount(spect_ch, -1, true,
1065 spectch_start, spectch_end);
1066 sap_update_rssi_bsscount(spect_ch, 1, true,
1067 spectch_start, spectch_end);
1068 sap_update_rssi_bsscount(spect_ch, 2, true,
1069 spectch_start, spectch_end);
1070 sap_update_rssi_bsscount(spect_ch, 3, true,
1071 spectch_start, spectch_end);
1072 sap_update_rssi_bsscount(spect_ch, 4, true,
1073 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001074 break;
1075
1076 case CHANNEL_5:
1077 case CHANNEL_6:
1078 case CHANNEL_7:
1079 case CHANNEL_8:
1080 case CHANNEL_9:
1081 case CHANNEL_10:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001082 sap_update_rssi_bsscount(spect_ch, -4, true,
1083 spectch_start, spectch_end);
1084 sap_update_rssi_bsscount(spect_ch, -3, true,
1085 spectch_start, spectch_end);
1086 sap_update_rssi_bsscount(spect_ch, -2, true,
1087 spectch_start, spectch_end);
1088 sap_update_rssi_bsscount(spect_ch, -1, true,
1089 spectch_start, spectch_end);
1090 sap_update_rssi_bsscount(spect_ch, 1, true,
1091 spectch_start, spectch_end);
1092 sap_update_rssi_bsscount(spect_ch, 2, true,
1093 spectch_start, spectch_end);
1094 sap_update_rssi_bsscount(spect_ch, 3, true,
1095 spectch_start, spectch_end);
1096 sap_update_rssi_bsscount(spect_ch, 4, true,
1097 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001098 break;
1099
1100 case CHANNEL_11:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001101 sap_update_rssi_bsscount(spect_ch, -4, true,
1102 spectch_start, spectch_end);
1103 sap_update_rssi_bsscount(spect_ch, -3, true,
1104 spectch_start, spectch_end);
1105 sap_update_rssi_bsscount(spect_ch, -2, true,
1106 spectch_start, spectch_end);
1107 sap_update_rssi_bsscount(spect_ch, -1, true,
1108 spectch_start, spectch_end);
1109 sap_update_rssi_bsscount(spect_ch, 1, true,
1110 spectch_start, spectch_end);
1111 sap_update_rssi_bsscount(spect_ch, 2, true,
1112 spectch_start, spectch_end);
1113 sap_update_rssi_bsscount(spect_ch, 3, true,
1114 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001115 break;
1116
1117 case CHANNEL_12:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001118 sap_update_rssi_bsscount(spect_ch, -4, true,
1119 spectch_start, spectch_end);
1120 sap_update_rssi_bsscount(spect_ch, -3, true,
1121 spectch_start, spectch_end);
1122 sap_update_rssi_bsscount(spect_ch, -2, true,
1123 spectch_start, spectch_end);
1124 sap_update_rssi_bsscount(spect_ch, -1, true,
1125 spectch_start, spectch_end);
1126 sap_update_rssi_bsscount(spect_ch, 1, true,
1127 spectch_start, spectch_end);
1128 sap_update_rssi_bsscount(spect_ch, 2, true,
1129 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001130 break;
1131
1132 case CHANNEL_13:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001133 sap_update_rssi_bsscount(spect_ch, -4, true,
1134 spectch_start, spectch_end);
1135 sap_update_rssi_bsscount(spect_ch, -3, true,
1136 spectch_start, spectch_end);
1137 sap_update_rssi_bsscount(spect_ch, -2, true,
1138 spectch_start, spectch_end);
1139 sap_update_rssi_bsscount(spect_ch, -1, true,
1140 spectch_start, spectch_end);
1141 sap_update_rssi_bsscount(spect_ch, 1, true,
1142 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001143 break;
1144
1145 case CHANNEL_14:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001146 sap_update_rssi_bsscount(spect_ch, -4, true,
1147 spectch_start, spectch_end);
1148 sap_update_rssi_bsscount(spect_ch, -3, true,
1149 spectch_start, spectch_end);
1150 sap_update_rssi_bsscount(spect_ch, -2, true,
1151 spectch_start, spectch_end);
1152 sap_update_rssi_bsscount(spect_ch, -1, true,
1153 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001154 break;
1155
1156 default:
1157 break;
1158 }
1159}
1160
Jeff Johnson464f7ea2016-10-07 10:21:26 -07001161/**
1162 * ch_in_pcl() - Is channel in the Preferred Channel List (PCL)
1163 * @sap_ctx: SAP context which contains the current PCL
1164 * @channel: Input channel number to be checked
1165 *
1166 * Check if a channel is in the preferred channel list
1167 *
1168 * Return:
1169 * true: channel is in PCL,
1170 * false: channel is not in PCL
1171 */
1172static bool ch_in_pcl(ptSapContext sap_ctx, uint8_t channel)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001173{
1174 uint32_t i;
1175
1176 for (i = 0; i < sap_ctx->acs_cfg->pcl_ch_count; i++) {
1177 if (channel == sap_ctx->acs_cfg->pcl_channels[i])
1178 return true;
1179 }
1180
1181 return false;
1182}
1183
Jeff Johnson464f7ea2016-10-07 10:21:26 -07001184/**
1185 * sap_compute_spect_weight() - Compute spectrum weight
1186 * @pSpectInfoParams: Pointer to the tSpectInfoParams structure
1187 * @halHandle: Pointer to HAL handle
1188 * @pResult: Pointer to tScanResultHandle
1189 * @sap_ctx: Context of the SAP
1190 *
1191 * Main function for computing the weight of each channel in the
1192 * spectrum based on the RSSI value of the BSSes on the channel
1193 * and number of BSS
1194 */
1195static void sap_compute_spect_weight(tSapChSelSpectInfo *pSpectInfoParams,
1196 tHalHandle halHandle,
1197 tScanResultHandle pResult,
1198 ptSapContext sap_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001199{
1200 int8_t rssi = 0;
1201 uint8_t chn_num = 0;
1202 uint8_t channel_id = 0;
1203
1204 tCsrScanResultInfo *pScanResult;
1205 tSapSpectChInfo *pSpectCh = pSpectInfoParams->pSpectCh;
1206 uint32_t operatingBand;
1207 uint16_t channelWidth;
1208 uint16_t secondaryChannelOffset;
1209 uint16_t centerFreq;
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001210 uint16_t centerFreq_2 = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001211 uint16_t vhtSupport;
1212 uint32_t ieLen = 0;
1213 tSirProbeRespBeacon *pBeaconStruct;
1214 tpAniSirGlobal pMac = (tpAniSirGlobal) halHandle;
Liangwei Dong71ed6502016-10-20 03:40:45 -04001215 tSapSpectChInfo *spectch_start = pSpectInfoParams->pSpectCh;
1216 tSapSpectChInfo *spectch_end = pSpectInfoParams->pSpectCh +
1217 pSpectInfoParams->numSpectChans;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001218
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301219 pBeaconStruct = qdf_mem_malloc(sizeof(tSirProbeRespBeacon));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001220 if (NULL == pBeaconStruct) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301221 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Kaushik, Sushantee3ed032016-08-04 16:40:46 +05301222 "Unable to allocate memory in sap_compute_spect_weight");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001223 return;
1224 }
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301225 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001226 "In %s, Computing spectral weight", __func__);
1227
1228 /**
1229 * Soft AP specific channel weight calculation using DFS formula
1230 */
1231 SET_ACS_BAND(operatingBand, sap_ctx);
1232
1233 pScanResult = sme_scan_result_get_first(halHandle, pResult);
1234
1235 while (pScanResult) {
1236 pSpectCh = pSpectInfoParams->pSpectCh;
1237 /* Defining the default values, so that any value will hold the default values */
1238 channelWidth = eHT_CHANNEL_WIDTH_20MHZ;
1239 secondaryChannelOffset = PHY_SINGLE_CHANNEL_CENTERED;
1240 vhtSupport = 0;
1241 centerFreq = 0;
1242
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001243
Yingying Tang22facc12016-10-20 17:43:59 +08001244 ieLen = GET_IE_LEN_IN_BSS(
1245 pScanResult->BssDescriptor.length);
1246 qdf_mem_set((uint8_t *) pBeaconStruct,
1247 sizeof(tSirProbeRespBeacon), 0);
1248
1249
1250 if ((sir_parse_beacon_ie
1251 (pMac, pBeaconStruct, (uint8_t *)
1252 (pScanResult->BssDescriptor.ieFields),
1253 ieLen)) == eSIR_SUCCESS)
1254 sap_upd_chan_spec_params(
1255 pBeaconStruct,
1256 &channelWidth,
1257 &secondaryChannelOffset,
1258 &vhtSupport, &centerFreq,
1259 &centerFreq_2);
1260
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001261 /* Processing for each tCsrScanResultInfo in the tCsrScanResult DLink list */
1262 for (chn_num = 0; chn_num < pSpectInfoParams->numSpectChans;
1263 chn_num++) {
1264
1265 /*
1266 * if the Beacon has channel ID, use it other wise we will
1267 * rely on the channelIdSelf
1268 */
1269 if (pScanResult->BssDescriptor.channelId == 0)
1270 channel_id =
1271 pScanResult->BssDescriptor.channelIdSelf;
1272 else
1273 channel_id =
1274 pScanResult->BssDescriptor.channelId;
1275
1276 if (pSpectCh && (channel_id == pSpectCh->chNum)) {
1277 if (pSpectCh->rssiAgr <
1278 pScanResult->BssDescriptor.rssi)
1279 pSpectCh->rssiAgr =
1280 pScanResult->BssDescriptor.rssi;
1281
1282 ++pSpectCh->bssCount; /* Increment the count of BSS */
1283
1284 /*
1285 * Connsidering the Extension Channel
1286 * only in a channels
1287 */
1288 switch (operatingBand) {
1289 case eCSR_DOT11_MODE_11a:
1290 sap_interference_rssi_count_5G(
1291 pSpectCh, channelWidth,
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001292 secondaryChannelOffset,
1293 centerFreq,
1294 centerFreq_2,
Liangwei Dong71ed6502016-10-20 03:40:45 -04001295 channel_id,
1296 spectch_start,
1297 spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001298 break;
1299
1300 case eCSR_DOT11_MODE_11g:
Liangwei Dong71ed6502016-10-20 03:40:45 -04001301 sap_interference_rssi_count(pSpectCh,
1302 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001303 break;
1304
1305 case eCSR_DOT11_MODE_abg:
1306 sap_interference_rssi_count_5G(
1307 pSpectCh, channelWidth,
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001308 secondaryChannelOffset,
1309 centerFreq,
1310 centerFreq_2,
Liangwei Dong71ed6502016-10-20 03:40:45 -04001311 channel_id,
1312 spectch_start,
1313 spectch_end);
1314 sap_interference_rssi_count(pSpectCh,
1315 spectch_start, spectch_end);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001316 break;
1317 }
1318
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301319 QDF_TRACE(QDF_MODULE_ID_SAP,
1320 QDF_TRACE_LEVEL_INFO_HIGH,
Kaushik, Sushantee3ed032016-08-04 16:40:46 +05301321 "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",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001322 __func__,
1323 pScanResult->BssDescriptor.
1324 channelIdSelf,
1325 pScanResult->BssDescriptor.channelId,
1326 pScanResult->BssDescriptor.rssi,
1327 pSpectCh->bssCount, pScanResult,
1328 pSpectCh->channelWidth,
1329 secondaryChannelOffset, centerFreq);
1330 pSpectCh++;
1331 break;
1332 } else {
1333 pSpectCh++;
1334 }
1335 }
1336
1337 pScanResult = sme_scan_result_get_next(halHandle, pResult);
1338 }
1339
1340 /* Calculate the weights for all channels in the spectrum pSpectCh */
1341 pSpectCh = pSpectInfoParams->pSpectCh;
1342
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301343 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001344 "In %s, Spectrum Channels Weight", __func__);
1345
1346 for (chn_num = 0; chn_num < (pSpectInfoParams->numSpectChans);
1347 chn_num++) {
1348
1349 /*
1350 rssi : Maximum received signal strength among all BSS on that channel
1351 bssCount : Number of BSS on that channel
1352 */
1353
1354 rssi = (int8_t) pSpectCh->rssiAgr;
1355 if (ch_in_pcl(sap_ctx, chn_num))
1356 rssi -= PCL_RSSI_DISCOUNT;
1357
1358 pSpectCh->weight =
1359 SAPDFS_NORMALISE_1000 * sapweight_rssi_count(rssi,
1360 pSpectCh->
1361 bssCount);
1362 pSpectCh->weight_copy = pSpectCh->weight;
1363
1364 /* ------ Debug Info ------ */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301365 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001366 "In %s, Chan=%d Weight= %d rssiAgr=%d bssCount=%d",
1367 __func__, pSpectCh->chNum, pSpectCh->weight,
1368 pSpectCh->rssiAgr, pSpectCh->bssCount);
1369 /* ------ Debug Info ------ */
1370 pSpectCh++;
1371 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301372 qdf_mem_free(pBeaconStruct);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001373}
1374
1375/*==========================================================================
1376 FUNCTION sap_chan_sel_exit
1377
1378 DESCRIPTION
1379 Exit function for free out the allocated memory, to be called
1380 at the end of the dfsSelectChannel function
1381
1382 DEPENDENCIES
1383 NA.
1384
1385 PARAMETERS
1386
1387 IN
1388 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1389
1390 RETURN VALUE
1391 void : NULL
1392
1393 SIDE EFFECTS
1394 ============================================================================*/
Jeff Johnson464f7ea2016-10-07 10:21:26 -07001395static void sap_chan_sel_exit(tSapChSelSpectInfo *pSpectInfoParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001396{
1397 /* Free all the allocated memory */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301398 qdf_mem_free(pSpectInfoParams->pSpectCh);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001399}
1400
1401/*==========================================================================
1402 FUNCTION sap_sort_chl_weight
1403
1404 DESCRIPTION
1405 Funtion to sort the channels with the least weight first for 20MHz channels
1406
1407 DEPENDENCIES
1408 NA.
1409
1410 PARAMETERS
1411
1412 IN
1413 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1414
1415 RETURN VALUE
1416 void : NULL
1417
1418 SIDE EFFECTS
1419 ============================================================================*/
Jeff Johnson464f7ea2016-10-07 10:21:26 -07001420static void sap_sort_chl_weight(tSapChSelSpectInfo *pSpectInfoParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001421{
1422 tSapSpectChInfo temp;
1423
1424 tSapSpectChInfo *pSpectCh = NULL;
1425 uint32_t i = 0, j = 0, minWeightIndex = 0;
1426
1427 pSpectCh = pSpectInfoParams->pSpectCh;
1428 for (i = 0; i < pSpectInfoParams->numSpectChans; i++) {
1429 minWeightIndex = i;
1430 for (j = i + 1; j < pSpectInfoParams->numSpectChans; j++) {
1431 if (pSpectCh[j].weight <
1432 pSpectCh[minWeightIndex].weight) {
1433 minWeightIndex = j;
1434 }
1435 }
1436 if (minWeightIndex != i) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301437 qdf_mem_copy(&temp, &pSpectCh[minWeightIndex],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001438 sizeof(*pSpectCh));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301439 qdf_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001440 sizeof(*pSpectCh));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301441 qdf_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001442 }
1443 }
1444}
1445
1446/**
bingse2782382017-03-23 10:34:52 +08001447 * set_ht80_chl_bit() - to set availabe channel to ht80 channel bitmap
1448 * @channel_bitmap: Pointer to the chan_bonding_bitmap structure
1449 * @spect_info_params: Pointer to the tSapChSelSpectInfo structure
1450 *
1451 * Return: none
1452 */
1453static void set_ht80_chl_bit(chan_bonding_bitmap *channel_bitmap,
1454 tSapChSelSpectInfo *spec_info_params)
1455{
1456 uint8_t i, j;
1457 tSapSpectChInfo *spec_info;
1458 int start_channel = 0;
1459
1460 channel_bitmap->chanBondingSet[0].startChannel =
1461 acs_ht80_channels[0].chStartNum;
1462 channel_bitmap->chanBondingSet[1].startChannel =
1463 acs_ht80_channels[1].chStartNum;
1464 channel_bitmap->chanBondingSet[2].startChannel =
1465 acs_ht80_channels[2].chStartNum;
1466 channel_bitmap->chanBondingSet[3].startChannel =
1467 acs_ht80_channels[3].chStartNum;
1468 channel_bitmap->chanBondingSet[4].startChannel =
1469 acs_ht80_channels[4].chStartNum;
1470 channel_bitmap->chanBondingSet[5].startChannel =
1471 acs_ht80_channels[5].chStartNum;
1472
1473 spec_info = spec_info_params->pSpectCh;
1474 for (j = 0; j < spec_info_params->numSpectChans; j++) {
1475 for (i = 0; i < MAX_80MHZ_BANDS; i++) {
1476 start_channel =
1477 channel_bitmap->chanBondingSet[i].startChannel;
1478 if (spec_info[j].chNum >= start_channel &&
1479 (spec_info[j].chNum <= start_channel + 12)) {
1480 channel_bitmap->chanBondingSet[i].channelMap |=
1481 1 << ((spec_info[j].chNum -
1482 start_channel)/4);
1483 break;
1484 }
1485 }
1486 }
1487}
1488
1489/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001490 * sap_sort_chl_weight_ht80() - to sort the channels with the least weight
1491 * @pSpectInfoParams: Pointer to the tSapChSelSpectInfo structure
1492 *
1493 * Funtion to sort the channels with the least weight first for HT80 channels
1494 *
1495 * Return: none
1496 */
Jeff Johnson464f7ea2016-10-07 10:21:26 -07001497static void sap_sort_chl_weight_ht80(tSapChSelSpectInfo *pSpectInfoParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001498{
1499 uint8_t i, j, n;
1500 tSapSpectChInfo *pSpectInfo;
1501 uint8_t minIdx;
bingse2782382017-03-23 10:34:52 +08001502 int start_channel = 0;
1503 chan_bonding_bitmap *channel_bitmap;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001504
bingse2782382017-03-23 10:34:52 +08001505 channel_bitmap = qdf_mem_malloc(sizeof(chan_bonding_bitmap));
1506 if (NULL == channel_bitmap) {
1507 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_DEBUG,
1508 "%s: Failed to allocate memory", __func__);
1509 return;
1510 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001511 pSpectInfo = pSpectInfoParams->pSpectCh;
1512 /* for each HT80 channel, calculate the combined weight of the
1513 four 20MHz weight */
1514 for (i = 0; i < ARRAY_SIZE(acs_ht80_channels); i++) {
1515 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
1516 if (pSpectInfo[j].chNum ==
1517 acs_ht80_channels[i].chStartNum)
1518 break;
1519 }
1520 if (j == pSpectInfoParams->numSpectChans)
1521 continue;
1522
1523 if (!(((pSpectInfo[j].chNum + 4) == pSpectInfo[j + 1].chNum) &&
1524 ((pSpectInfo[j].chNum + 8) ==
1525 pSpectInfo[j + 2].chNum) &&
1526 ((pSpectInfo[j].chNum + 12) ==
1527 pSpectInfo[j + 3].chNum))) {
1528 /*
1529 * some channels does not exist in pSectInfo array,
1530 * skip this channel and those in the same HT80 width
1531 */
1532 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 4;
1533 if ((pSpectInfo[j].chNum + 4) ==
1534 pSpectInfo[j + 1].chNum)
1535 pSpectInfo[j + 1].weight =
1536 SAP_ACS_WEIGHT_MAX * 4;
1537 if ((pSpectInfo[j].chNum + 8) ==
1538 pSpectInfo[j + 2].chNum)
1539 pSpectInfo[j + 2].weight =
1540 SAP_ACS_WEIGHT_MAX * 4;
1541 if ((pSpectInfo[j].chNum + 12) ==
1542 pSpectInfo[j + 3].chNum)
1543 pSpectInfo[j + 3].weight =
1544 SAP_ACS_WEIGHT_MAX * 4;
1545 continue;
1546 }
1547 /*found the channel, add the 4 adjacent channels' weight */
1548 acs_ht80_channels[i].weight = pSpectInfo[j].weight +
1549 pSpectInfo[j + 1].weight + pSpectInfo[j + 2].weight +
1550 pSpectInfo[j + 3].weight;
1551 /* find best channel among 4 channels as the primary channel */
1552 if ((pSpectInfo[j].weight + pSpectInfo[j + 1].weight) <
1553 (pSpectInfo[j + 2].weight + pSpectInfo[j + 3].weight)) {
1554 /* lower 2 channels are better choice */
1555 if (pSpectInfo[j].weight < pSpectInfo[j + 1].weight)
1556 minIdx = 0;
1557 else
1558 minIdx = 1;
1559 } else if (pSpectInfo[j + 2].weight <=
1560 pSpectInfo[j + 3].weight) {
1561 /* upper 2 channels are better choice */
1562 minIdx = 2;
1563 } else {
1564 minIdx = 3;
1565 }
1566
1567 /*
1568 * set all 4 channels to max value first, then reset the
1569 * best channel as the selected primary channel, update its
1570 * weightage with the combined weight value
1571 */
1572 for (n = 0; n < 4; n++)
1573 pSpectInfo[j + n].weight = SAP_ACS_WEIGHT_MAX * 4;
1574
1575 pSpectInfo[j + minIdx].weight = acs_ht80_channels[i].weight;
1576 }
1577
bingse2782382017-03-23 10:34:52 +08001578 /*
1579 * mark the weight of the channel that can't satisfy 80MHZ
1580 * as max value, so that it will be sorted to the bottom
1581 */
1582 set_ht80_chl_bit(channel_bitmap, pSpectInfoParams);
1583 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
1584 for (i = 0; i < MAX_80MHZ_BANDS; i++) {
1585 start_channel =
1586 channel_bitmap->chanBondingSet[i].startChannel;
1587 if (pSpectInfo[j].chNum >= start_channel &&
1588 (pSpectInfo[j].chNum <=
1589 start_channel + 12) &&
1590 channel_bitmap->chanBondingSet[i].channelMap !=
1591 SAP_80MHZ_MASK)
1592 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 4;
1593 }
1594 }
1595
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001596 pSpectInfo = pSpectInfoParams->pSpectCh;
1597 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
1598 if (CHANNEL_165 == pSpectInfo[j].chNum) {
1599 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 4;
1600 break;
1601 }
1602 }
1603
Manishekar Chandrasekaran44e334f2016-05-30 16:42:50 +05301604 sap_sort_chl_weight(pSpectInfoParams);
1605
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001606 pSpectInfo = pSpectInfoParams->pSpectCh;
1607 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301608 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001609 FL("Channel=%d Weight= %d rssi=%d bssCount=%d"),
1610 pSpectInfo->chNum, pSpectInfo->weight,
1611 pSpectInfo->rssiAgr, pSpectInfo->bssCount);
1612 pSpectInfo++;
1613 }
bingse2782382017-03-23 10:34:52 +08001614 qdf_mem_free(channel_bitmap);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001615}
1616
1617/**
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001618 * sap_sort_chl_weight_vht160() - to sort the channels with the least weight
1619 * @pSpectInfoParams: Pointer to the tSapChSelSpectInfo structure
1620 *
1621 * Funtion to sort the channels with the least weight first for VHT160 channels
1622 *
1623 * Return: none
1624 */
Jeff Johnson464f7ea2016-10-07 10:21:26 -07001625static void sap_sort_chl_weight_vht160(tSapChSelSpectInfo *pSpectInfoParams)
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001626{
1627 uint8_t i, j, n, idx;
1628 tSapSpectChInfo *pSpectInfo;
1629 uint8_t minIdx;
1630
1631 pSpectInfo = pSpectInfoParams->pSpectCh;
1632 /* for each VHT160 channel, calculate the combined weight of the
1633 8 20MHz weight */
1634 for (i = 0; i < ARRAY_SIZE(acs_vht160_channels); i++) {
1635 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
1636 if (pSpectInfo[j].chNum ==
1637 acs_vht160_channels[i].chStartNum)
1638 break;
1639 }
1640 if (j == pSpectInfoParams->numSpectChans)
1641 continue;
1642
1643 if (!(((pSpectInfo[j].chNum + 4) == pSpectInfo[j + 1].chNum) &&
1644 ((pSpectInfo[j].chNum + 8) ==
1645 pSpectInfo[j + 2].chNum) &&
1646 ((pSpectInfo[j].chNum + 12) ==
1647 pSpectInfo[j + 3].chNum) &&
1648 ((pSpectInfo[j].chNum + 16) ==
1649 pSpectInfo[j + 4].chNum) &&
1650 ((pSpectInfo[j].chNum + 20) ==
1651 pSpectInfo[j + 5].chNum) &&
1652 ((pSpectInfo[j].chNum + 24) ==
1653 pSpectInfo[j + 6].chNum) &&
1654 ((pSpectInfo[j].chNum + 28) ==
1655 pSpectInfo[j + 7].chNum))) {
1656 /*
1657 * some channels does not exist in pSectInfo array,
1658 * skip this channel and those in the same VHT160 width
1659 */
1660 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 8;
1661 if ((pSpectInfo[j].chNum + 4) ==
1662 pSpectInfo[j + 1].chNum)
1663 pSpectInfo[j + 1].weight =
1664 SAP_ACS_WEIGHT_MAX * 8;
1665 if ((pSpectInfo[j].chNum + 8) ==
1666 pSpectInfo[j + 2].chNum)
1667 pSpectInfo[j + 2].weight =
1668 SAP_ACS_WEIGHT_MAX * 8;
1669 if ((pSpectInfo[j].chNum + 12) ==
1670 pSpectInfo[j + 3].chNum)
1671 pSpectInfo[j + 3].weight =
1672 SAP_ACS_WEIGHT_MAX * 8;
1673 if ((pSpectInfo[j].chNum + 16) ==
1674 pSpectInfo[j + 4].chNum)
1675 pSpectInfo[j + 4].weight =
1676 SAP_ACS_WEIGHT_MAX * 8;
1677 if ((pSpectInfo[j].chNum + 20) ==
1678 pSpectInfo[j + 5].chNum)
1679 pSpectInfo[j + 5].weight =
1680 SAP_ACS_WEIGHT_MAX * 8;
1681 if ((pSpectInfo[j].chNum + 24) ==
1682 pSpectInfo[j + 6].chNum)
1683 pSpectInfo[j + 6].weight =
1684 SAP_ACS_WEIGHT_MAX * 8;
1685 if ((pSpectInfo[j].chNum + 28) ==
1686 pSpectInfo[j + 7].chNum)
1687 pSpectInfo[j + 7].weight =
1688 SAP_ACS_WEIGHT_MAX * 8;
1689 continue;
1690 }
1691 /*found the channel, add the 7 adjacent channels' weight */
1692 acs_vht160_channels[i].weight = pSpectInfo[j].weight +
1693 pSpectInfo[j + 1].weight + pSpectInfo[j + 2].weight +
1694 pSpectInfo[j + 3].weight + pSpectInfo[j + 4].weight +
1695 pSpectInfo[j + 5].weight + pSpectInfo[j + 6].weight +
1696 pSpectInfo[j + 7].weight;
1697
1698 /* find best channel among 8 channels as the primary channel */
1699 if ((pSpectInfo[j].weight + pSpectInfo[j + 1].weight +
1700 pSpectInfo[j + 2].weight + pSpectInfo[j + 3].weight) >
1701 (pSpectInfo[j + 4].weight + pSpectInfo[j + 5].weight +
1702 pSpectInfo[j + 6].weight + pSpectInfo[j + 7].weight))
1703 idx = 4;
1704 else
1705 idx = 0;
1706 /* find best channel among 4 channels as the primary channel */
1707 if ((pSpectInfo[j + idx].weight +
1708 pSpectInfo[j + idx + 1].weight) <
1709 (pSpectInfo[j + idx + 2].weight +
1710 pSpectInfo[j + idx + 3].weight)) {
1711 /* lower 2 channels are better choice */
1712 if (pSpectInfo[j + idx].weight <
1713 pSpectInfo[j + idx + 1].weight)
1714 minIdx = 0 + idx;
1715 else
1716 minIdx = 1 + idx;
1717 } else if (pSpectInfo[j + idx + 2].weight <=
1718 pSpectInfo[j + idx + 3].weight) {
1719 /* upper 2 channels are better choice */
1720 minIdx = 2 + idx;
1721 } else {
1722 minIdx = 3 + idx;
1723 }
1724
1725 /*
1726 * set all 8 channels to max value first, then reset the
1727 * best channel as the selected primary channel, update its
1728 * weightage with the combined weight value
1729 */
1730 for (n = 0; n < 8; n++)
1731 pSpectInfo[j + n].weight = SAP_ACS_WEIGHT_MAX * 8;
1732
1733 pSpectInfo[j + minIdx].weight = acs_vht160_channels[i].weight;
1734 }
1735
1736 pSpectInfo = pSpectInfoParams->pSpectCh;
1737 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
1738 if (CHANNEL_165 == pSpectInfo[j].chNum) {
1739 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 8;
1740 break;
1741 }
1742 }
1743
Manishekar Chandrasekaran44e334f2016-05-30 16:42:50 +05301744 sap_sort_chl_weight(pSpectInfoParams);
1745
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001746 pSpectInfo = pSpectInfoParams->pSpectCh;
1747 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301748 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07001749 FL("Channel=%d Weight= %d rssi=%d bssCount=%d"),
1750 pSpectInfo->chNum, pSpectInfo->weight,
1751 pSpectInfo->rssiAgr, pSpectInfo->bssCount);
1752 pSpectInfo++;
1753 }
1754}
1755
1756/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001757 * sap_sort_chl_weight_ht40_24_g() - to sort channel with the least weight
1758 * @pSpectInfoParams: Pointer to the tSapChSelSpectInfo structure
1759 *
1760 * Funtion to sort the channels with the least weight first for HT40 channels
1761 *
1762 * Return: none
1763 */
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001764static void sap_sort_chl_weight_ht40_24_g(tSapChSelSpectInfo *pSpectInfoParams,
1765 v_REGDOMAIN_t domain)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001766{
1767 uint8_t i, j;
1768 tSapSpectChInfo *pSpectInfo;
1769 uint32_t tmpWeight1, tmpWeight2;
bingse2782382017-03-23 10:34:52 +08001770 uint32_t ht40plus2gendch = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001771
1772 pSpectInfo = pSpectInfoParams->pSpectCh;
1773 /*
1774 * for each HT40 channel, calculate the combined weight of the
1775 * two 20MHz weight
1776 */
1777 for (i = 0; i < ARRAY_SIZE(acs_ht40_channels24_g); i++) {
1778 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
1779 if (pSpectInfo[j].chNum ==
1780 acs_ht40_channels24_g[i].chStartNum)
1781 break;
1782 }
1783 if (j == pSpectInfoParams->numSpectChans)
1784 continue;
1785
1786 if (!((pSpectInfo[j].chNum + 4) == pSpectInfo[j + 4].chNum)) {
1787 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2;
1788 continue;
1789 }
1790 /*
1791 * check if there is another channel combination possiblity
1792 * e.g., {1, 5} & {5, 9}
1793 */
1794 if ((pSpectInfo[j + 4].chNum + 4) == pSpectInfo[j + 8].chNum) {
1795 /* need to compare two channel pairs */
1796 tmpWeight1 = pSpectInfo[j].weight +
1797 pSpectInfo[j + 4].weight;
1798 tmpWeight2 = pSpectInfo[j + 4].weight +
1799 pSpectInfo[j + 8].weight;
1800 if (tmpWeight1 <= tmpWeight2) {
1801 if (pSpectInfo[j].weight <=
1802 pSpectInfo[j + 4].weight) {
1803 pSpectInfo[j].weight =
1804 tmpWeight1;
1805 pSpectInfo[j + 4].weight =
1806 SAP_ACS_WEIGHT_MAX * 2;
1807 pSpectInfo[j + 8].weight =
1808 SAP_ACS_WEIGHT_MAX * 2;
1809 } else {
1810 pSpectInfo[j + 4].weight =
1811 tmpWeight1;
1812 /* for secondary channel selection */
1813 pSpectInfo[j].weight =
1814 SAP_ACS_WEIGHT_MAX * 2
1815 - 1;
1816 pSpectInfo[j + 8].weight =
1817 SAP_ACS_WEIGHT_MAX * 2;
1818 }
1819 } else {
1820 if (pSpectInfo[j + 4].weight <=
1821 pSpectInfo[j + 8].weight) {
1822 pSpectInfo[j + 4].weight =
1823 tmpWeight2;
1824 pSpectInfo[j].weight =
1825 SAP_ACS_WEIGHT_MAX * 2;
1826 /* for secondary channel selection */
1827 pSpectInfo[j + 8].weight =
1828 SAP_ACS_WEIGHT_MAX * 2
1829 - 1;
1830 } else {
1831 pSpectInfo[j + 8].weight =
1832 tmpWeight2;
1833 pSpectInfo[j].weight =
1834 SAP_ACS_WEIGHT_MAX * 2;
1835 pSpectInfo[j + 4].weight =
1836 SAP_ACS_WEIGHT_MAX * 2;
1837 }
1838 }
1839 } else {
1840 tmpWeight1 = pSpectInfo[j].weight +
1841 pSpectInfo[j + 4].weight;
1842 if (pSpectInfo[j].weight <=
1843 pSpectInfo[j + 4].weight) {
1844 pSpectInfo[j].weight = tmpWeight1;
1845 pSpectInfo[j + 4].weight =
1846 SAP_ACS_WEIGHT_MAX * 2;
1847 } else {
1848 pSpectInfo[j + 4].weight = tmpWeight1;
1849 pSpectInfo[j].weight =
1850 SAP_ACS_WEIGHT_MAX * 2;
1851 }
1852 }
1853 }
bingse2782382017-03-23 10:34:52 +08001854 /*
1855 * Every channel should be checked. Add the check for the omissive
1856 * channel. Mark the channel whose combination can't satisfy 40MHZ
1857 * as max value, so that it will be sorted to the bottom.
1858 */
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001859 if (REGDOMAIN_FCC == domain)
bingse2782382017-03-23 10:34:52 +08001860 ht40plus2gendch = HT40PLUS_2G_FCC_CH_END;
1861 else
1862 ht40plus2gendch = HT40PLUS_2G_EURJAP_CH_END;
1863 for (i = HT40MINUS_2G_CH_START; i <= ht40plus2gendch; i++) {
1864 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
1865 if (pSpectInfo[j].chNum == i &&
1866 ((pSpectInfo[j].chNum + 4) !=
1867 pSpectInfo[j+4].chNum) &&
1868 ((pSpectInfo[j].chNum - 4) !=
1869 pSpectInfo[j-4].chNum))
1870 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2;
1871 }
1872 }
1873 for (i = ht40plus2gendch + 1; i <= HT40MINUS_2G_CH_END; i++) {
1874 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
1875 if (pSpectInfo[j].chNum == i &&
1876 (pSpectInfo[j].chNum - 4) !=
1877 pSpectInfo[j-4].chNum)
1878 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2;
1879 }
1880 }
Manishekar Chandrasekaran44e334f2016-05-30 16:42:50 +05301881 sap_sort_chl_weight(pSpectInfoParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001882}
1883
1884/*==========================================================================
1885 FUNCTION sap_sort_chl_weight_ht40_5_g
1886
1887 DESCRIPTION
1888 Funtion to sort the channels with the least weight first for HT40 channels
1889
1890 DEPENDENCIES
1891 NA.
1892
1893 PARAMETERS
1894
1895 IN
1896 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1897
1898 RETURN VALUE
1899 void : NULL
1900
1901 SIDE EFFECTS
1902 ============================================================================*/
Jeff Johnson464f7ea2016-10-07 10:21:26 -07001903static void sap_sort_chl_weight_ht40_5_g(tSapChSelSpectInfo *pSpectInfoParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001904{
1905 uint8_t i, j;
1906 tSapSpectChInfo *pSpectInfo;
1907
1908 pSpectInfo = pSpectInfoParams->pSpectCh;
1909 /*for each HT40 channel, calculate the combined weight of the
1910 two 20MHz weight */
1911 for (i = 0; i < ARRAY_SIZE(acs_ht40_channels5_g); i++) {
1912 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
1913 if (pSpectInfo[j].chNum ==
1914 acs_ht40_channels5_g[i].chStartNum)
1915 break;
1916 }
1917 if (j == pSpectInfoParams->numSpectChans)
1918 continue;
1919
1920 /* found the channel, add the two adjacent channels' weight */
1921 if ((pSpectInfo[j].chNum + 4) == pSpectInfo[j + 1].chNum) {
1922 acs_ht40_channels5_g[i].weight = pSpectInfo[j].weight +
1923 pSpectInfo[j + 1].weight;
1924 /* select better of the adjact channel as the primary channel */
1925 if (pSpectInfo[j].weight <= pSpectInfo[j + 1].weight) {
1926 pSpectInfo[j].weight =
1927 acs_ht40_channels5_g[i].weight;
1928 /* mark the adjacent channel's weight as max value so
1929 that it will be sorted to the bottom */
1930 pSpectInfo[j + 1].weight =
1931 SAP_ACS_WEIGHT_MAX * 2;
1932 } else {
1933 pSpectInfo[j + 1].weight =
1934 acs_ht40_channels5_g[i].weight;
1935 /* mark the adjacent channel's weight as max value so
1936 that it will be sorted to the bottom */
1937 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2;
1938 }
1939
1940 } else
1941 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2;
1942 }
1943
bingse2782382017-03-23 10:34:52 +08001944 /*
1945 *Every channel should be checked. Add the check for the omissive
1946 * channel. Mark the channel whose combination can't satisfy 40MHZ
1947 * as max value, so that it will be sorted to the bottom
1948 */
1949 for (j = 1; j < pSpectInfoParams->numSpectChans; j++) {
1950 for (i = 0; i < ARRAY_SIZE(acs_ht40_channels5_g); i++) {
1951 if (pSpectInfo[j].chNum ==
1952 (acs_ht40_channels5_g[i].chStartNum +
1953 4) &&
1954 pSpectInfo[j - 1].chNum !=
1955 acs_ht40_channels5_g[i].chStartNum) {
1956 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2;
1957 break;
1958 }
1959 }
1960 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001961 /* avoid channel 165 by setting its weight to max */
1962 pSpectInfo = pSpectInfoParams->pSpectCh;
1963 for (j = 0; j < pSpectInfoParams->numSpectChans; j++) {
1964 if (CHANNEL_165 == pSpectInfo[j].chNum) {
1965 pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2;
1966 break;
1967 }
1968 }
1969
1970 pSpectInfo = pSpectInfoParams->pSpectCh;
1971 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301972 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001973 "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d",
1974 __func__, pSpectInfo->chNum, pSpectInfo->weight,
1975 pSpectInfo->rssiAgr, pSpectInfo->bssCount);
1976 pSpectInfo++;
1977 }
1978
1979 sap_sort_chl_weight(pSpectInfoParams);
1980}
1981
1982/*==========================================================================
1983 FUNCTION sap_sort_chl_weight_all
1984
1985 DESCRIPTION
1986 Funtion to sort the channels with the least weight first
1987
1988 DEPENDENCIES
1989 NA.
1990
1991 PARAMETERS
1992
1993 IN
1994 ptSapContext : Pointer to the ptSapContext structure
1995 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1996
1997 RETURN VALUE
1998 void : NULL
1999
2000 SIDE EFFECTS
2001 ============================================================================*/
Jeff Johnson464f7ea2016-10-07 10:21:26 -07002002static void sap_sort_chl_weight_all(ptSapContext pSapCtx,
2003 tSapChSelSpectInfo *pSpectInfoParams,
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002004 uint32_t operatingBand,
2005 v_REGDOMAIN_t domain)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002006{
2007 tSapSpectChInfo *pSpectCh = NULL;
2008 uint32_t j = 0;
2009#ifndef SOFTAP_CHANNEL_RANGE
2010 uint32_t i = 0;
2011#endif
2012
2013 pSpectCh = pSpectInfoParams->pSpectCh;
2014#ifdef SOFTAP_CHANNEL_RANGE
2015
2016 switch (pSapCtx->acs_cfg->ch_width) {
2017 case CH_WIDTH_40MHZ:
2018 if (eCSR_DOT11_MODE_11g == operatingBand)
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002019 sap_sort_chl_weight_ht40_24_g(pSpectInfoParams, domain);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002020 else if (eCSR_DOT11_MODE_11a == operatingBand)
2021 sap_sort_chl_weight_ht40_5_g(pSpectInfoParams);
2022 else {
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002023 sap_sort_chl_weight_ht40_24_g(pSpectInfoParams, domain);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002024 sap_sort_chl_weight_ht40_5_g(pSpectInfoParams);
2025 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002026 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002027 case CH_WIDTH_80MHZ:
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07002028 case CH_WIDTH_80P80MHZ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002029 sap_sort_chl_weight_ht80(pSpectInfoParams);
2030 break;
Kiran Kumar Lokereb3d8b5b2015-10-06 19:33:42 -07002031 case CH_WIDTH_160MHZ:
2032 sap_sort_chl_weight_vht160(pSpectInfoParams);
2033 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002034 case CH_WIDTH_20MHZ:
2035 default:
2036 /* Sorting the channels as per weights as 20MHz channels */
2037 sap_sort_chl_weight(pSpectInfoParams);
2038 }
2039
2040#else
2041 /* Sorting the channels as per weights */
2042 for (i = 0; i < SPECT_24GHZ_CH_COUNT; i++) {
2043 minWeightIndex = i;
2044 for (j = i + 1; j < SPECT_24GHZ_CH_COUNT; j++) {
2045 if (pSpectCh[j].weight <
2046 pSpectCh[minWeightIndex].weight) {
2047 minWeightIndex = j;
2048 }
2049 }
2050 if (minWeightIndex != i) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302051 qdf_mem_copy(&temp, &pSpectCh[minWeightIndex],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002052 sizeof(*pSpectCh));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302053 qdf_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002054 sizeof(*pSpectCh));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302055 qdf_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002056 }
2057 }
2058#endif
2059
2060 /* For testing */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302061 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002062 "In %s, Sorted Spectrum Channels Weight", __func__);
2063 pSpectCh = pSpectInfoParams->pSpectCh;
2064 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302065 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002066 "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d",
2067 __func__, pSpectCh->chNum, pSpectCh->weight,
2068 pSpectCh->rssiAgr, pSpectCh->bssCount);
2069 pSpectCh++;
2070 }
2071
2072}
2073
2074/*==========================================================================
2075 FUNCTION sap_filter_over_lap_ch
2076
2077 DESCRIPTION
2078 return true if ch is acceptable.
2079 This function will decide if we will filter over lap channel or not.
2080
2081 DEPENDENCIES
2082 shall called after ap start.
2083
2084 PARAMETERS
2085
2086 IN
2087 pSapCtx : Pointer to ptSapContext.
2088 chNum : Filter channel number.
2089
2090 RETURN VALUE
2091 bool : true if channel is accepted.
2092
2093 SIDE EFFECTS
2094 ============================================================================*/
Jeff Johnson464f7ea2016-10-07 10:21:26 -07002095static bool sap_filter_over_lap_ch(ptSapContext pSapCtx, uint16_t chNum)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002096{
2097 if (pSapCtx->enableOverLapCh)
Srinivas Girigowda74a66d62017-06-21 23:28:25 -07002098 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002099 else if ((chNum == CHANNEL_1) ||
2100 (chNum == CHANNEL_6) || (chNum == CHANNEL_11))
Srinivas Girigowda74a66d62017-06-21 23:28:25 -07002101 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002102
Srinivas Girigowda74a66d62017-06-21 23:28:25 -07002103 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002104}
2105
Dustin Brown0ce56d32016-10-17 16:18:03 -07002106#ifdef FEATURE_WLAN_CH_AVOID
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002107/**
2108 * sap_select_channel_no_scan_result() - select SAP channel when no scan results
2109 * are available.
2110 * @sap_ctx: Sap context
2111 *
2112 * Returns: channel number if success, 0 otherwise
2113 */
Kondabattini, Ganesh13bb4b12016-09-04 16:16:53 +05302114static uint8_t sap_select_channel_no_scan_result(tHalHandle hal,
Dustin Brown0ce56d32016-10-17 16:18:03 -07002115 ptSapContext sap_ctx)
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002116{
Mohit Khanna841044f2016-03-25 16:16:24 -07002117 enum channel_state ch_type;
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002118 uint8_t i, first_safe_ch_in_range = SAP_CHANNEL_NOT_SELECTED;
Kondabattini, Ganesh13bb4b12016-09-04 16:16:53 +05302119 uint32_t dfs_master_cap_enabled;
Dustin Brown0ce56d32016-10-17 16:18:03 -07002120 uint32_t start_ch_num = sap_ctx->acs_cfg->start_ch;
2121 uint32_t end_ch_num = sap_ctx->acs_cfg->end_ch;
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002122 tpAniSirGlobal mac_ctx = NULL;
2123
2124 mac_ctx = PMAC_STRUCT(hal);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002125
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002126 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
2127 FL("start - end: %d - %d"), start_ch_num, end_ch_num);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002128
Kondabattini, Ganesh13bb4b12016-09-04 16:16:53 +05302129 sme_cfg_get_int(hal, WNI_CFG_DFS_MASTER_ENABLED,
2130 &dfs_master_cap_enabled);
2131
2132 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
2133 "%s: dfs_master %x", __func__, dfs_master_cap_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002134
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002135 /* get a channel in PCL and within the range */
2136 for (i = 0; i < sap_ctx->acs_cfg->pcl_ch_count; i++) {
2137 if ((sap_ctx->acs_cfg->pcl_channels[i] < start_ch_num) ||
2138 (sap_ctx->acs_cfg->pcl_channels[i] > end_ch_num))
2139 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002140
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002141 first_safe_ch_in_range = sap_ctx->acs_cfg->pcl_channels[i];
2142 break;
2143 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002144
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002145 if (SAP_CHANNEL_NOT_SELECTED != first_safe_ch_in_range)
2146 return first_safe_ch_in_range;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002147
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002148 for (i = 0; i < NUM_CHANNELS; i++) {
2149 if ((safe_channels[i].channelNumber < start_ch_num) ||
2150 (safe_channels[i].channelNumber > end_ch_num))
2151 continue;
2152
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002153 ch_type = wlan_reg_get_channel_state(mac_ctx->pdev,
2154 safe_channels[i].channelNumber);
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002155
2156 if ((ch_type == CHANNEL_STATE_DISABLE) ||
2157 (ch_type == CHANNEL_STATE_INVALID))
2158 continue;
Kondabattini, Ganesh13bb4b12016-09-04 16:16:53 +05302159 if ((!dfs_master_cap_enabled) &&
2160 (CHANNEL_STATE_DFS == ch_type)) {
2161 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
2162 "%s: DFS master mode disabled. Skip DFS channel %d",
2163 __func__, safe_channels[i].channelNumber);
2164 continue;
2165 }
Agrawal Ashish65634612016-08-18 13:24:32 +05302166 if ((sap_ctx->dfs_mode == ACS_DFS_MODE_DISABLE) &&
2167 (CHANNEL_STATE_DFS == ch_type))
2168 continue;
Kondabattini, Ganesh13bb4b12016-09-04 16:16:53 +05302169
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002170 if (safe_channels[i].isSafe == true) {
2171 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
2172 FL("channel %d in the configuration is safe"),
2173 safe_channels[i].channelNumber);
2174 first_safe_ch_in_range = safe_channels[i].channelNumber;
2175 break;
2176 }
2177
2178 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
2179 FL("channel %d in the configuration is unsafe"),
2180 safe_channels[i].channelNumber);
2181 }
2182
2183 /* if no channel selected return SAP_CHANNEL_NOT_SELECTED */
2184 return first_safe_ch_in_range;
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002185}
Dustin Brown0ce56d32016-10-17 16:18:03 -07002186#else
2187static uint8_t sap_select_channel_no_scan_result(tHalHandle hal,
2188 ptSapContext sap_ctx)
2189{
2190 uint32_t start_ch_num = sap_ctx->acs_cfg->start_ch;
2191
2192 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
2193 FL("start - end: %d - %d"),
2194 start_ch_num,
2195 sap_ctx->acs_cfg->end_ch);
2196
2197 sap_ctx->acs_cfg->pri_ch = start_ch_num;
2198 sap_ctx->acs_cfg->ht_sec_ch = 0;
2199
2200 /* pick the first channel in configured range */
2201 return start_ch_num;
2202}
2203#endif /* FEATURE_WLAN_CH_AVOID */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002204
2205/**
2206 * sap_select_channel() - select SAP channel
2207 * @hal: Pointer to HAL handle
2208 * @sap_ctx: Sap context
2209 * @scan_result: Pointer to tScanResultHandle
2210 *
2211 * Runs a algorithm to select the best channel to operate in based on BSS
2212 * rssi and bss count on each channel
2213 *
2214 * Returns: channel number if success, 0 otherwise
2215 */
2216uint8_t sap_select_channel(tHalHandle hal, ptSapContext sap_ctx,
2217 tScanResultHandle scan_result)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002218{
2219 /* DFS param object holding all the data req by the algo */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002220 tSapChSelSpectInfo spect_info_obj = { NULL, 0 };
2221 tSapChSelSpectInfo *spect_info = &spect_info_obj;
2222 uint8_t best_ch_num = SAP_CHANNEL_NOT_SELECTED;
bingse2782382017-03-23 10:34:52 +08002223 uint32_t ht40plus2gendch = 0;
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002224 v_REGDOMAIN_t domain;
2225 uint8_t country[CDS_COUNTRY_CODE_LEN];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002226#ifdef SOFTAP_CHANNEL_RANGE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002227 uint8_t count;
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002228 uint32_t start_ch_num, end_ch_num, tmp_ch_num, operating_band = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002229#endif
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002230 tpAniSirGlobal mac_ctx;
2231
2232 mac_ctx = PMAC_STRUCT(hal);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302233 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002234 "In %s, Running SAP Ch Select", __func__);
2235
2236#ifdef FEATURE_WLAN_CH_AVOID
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002237 sap_update_unsafe_channel_list(hal, sap_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002238#endif
2239
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002240 if (NULL == scan_result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302241 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002242 FL("No external AP present"));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002243
2244#ifndef SOFTAP_CHANNEL_RANGE
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002245 return SAP_CHANNEL_NOT_SELECTED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002246#else
Kondabattini, Ganesh13bb4b12016-09-04 16:16:53 +05302247 return sap_select_channel_no_scan_result(hal, sap_ctx);
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002248#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002249 }
2250
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002251 /* Initialize the structure pointed by spect_info */
Srinivas Girigowda74a66d62017-06-21 23:28:25 -07002252 if (sap_chan_sel_init(hal, spect_info, sap_ctx) != true) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302253 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR,
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002254 FL("Ch Select initialization failed"));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002255 return SAP_CHANNEL_NOT_SELECTED;
2256 }
2257 /* Compute the weight of the entire spectrum in the operating band */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002258 sap_compute_spect_weight(spect_info, hal, scan_result, sap_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002259
2260#ifdef FEATURE_AP_MCC_CH_AVOIDANCE
2261 /* process avoid channel IE to collect all channels to avoid */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002262 sap_process_avoid_ie(hal, sap_ctx, scan_result, spect_info);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002263#endif /* FEATURE_AP_MCC_CH_AVOIDANCE */
2264
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002265 wlan_reg_read_default_country(mac_ctx->psoc, country);
2266 wlan_reg_get_domain_from_country_code(&domain, country, SOURCE_DRIVER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002267#ifdef SOFTAP_CHANNEL_RANGE
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002268 start_ch_num = sap_ctx->acs_cfg->start_ch;
2269 end_ch_num = sap_ctx->acs_cfg->end_ch;
2270 SET_ACS_BAND(operating_band, sap_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002271
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002272 sap_ctx->acsBestChannelInfo.channelNum = 0;
2273 sap_ctx->acsBestChannelInfo.weight = SAP_ACS_WEIGHT_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002274
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002275 /* Sort the ch lst as per the computed weights, lesser weight first. */
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002276 sap_sort_chl_weight_all(sap_ctx, spect_info, operating_band, domain);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002277
2278 /*Loop till get the best channel in the given range */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002279 for (count = 0; count < spect_info->numSpectChans; count++) {
2280 if ((start_ch_num > spect_info->pSpectCh[count].chNum) ||
2281 (end_ch_num < spect_info->pSpectCh[count].chNum))
2282 continue;
2283
2284 if (best_ch_num == SAP_CHANNEL_NOT_SELECTED) {
2285 best_ch_num = spect_info->pSpectCh[count].chNum;
2286 /* check if best_ch_num is in preferred channel list */
2287 best_ch_num =
2288 sap_select_preferred_channel_from_channel_list(
2289 best_ch_num, sap_ctx, spect_info);
2290 /* if not in preferred ch lst, go to nxt best ch */
2291 if (best_ch_num == SAP_CHANNEL_NOT_SELECTED)
2292 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002293
2294#ifdef FEATURE_AP_MCC_CH_AVOIDANCE
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002295 /*
2296 * Weight of the channels(device's AP is operating)
2297 * increased to MAX+1 so that they will be choosen only
2298 * when there is no other best channel to choose
2299 */
2300 if (sap_check_in_avoid_ch_list(sap_ctx, best_ch_num)) {
2301 best_ch_num = SAP_CHANNEL_NOT_SELECTED;
2302 continue;
2303 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002304#endif
2305
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002306 sap_ctx->acsBestChannelInfo.channelNum = best_ch_num;
2307 sap_ctx->acsBestChannelInfo.weight =
2308 spect_info->pSpectCh[count].weight_copy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002309 }
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002310
2311 if (best_ch_num == SAP_CHANNEL_NOT_SELECTED)
2312 continue;
2313
Tushnim Bhattacharyya03103fd2017-06-23 10:48:52 -07002314 if (operating_band != eCSR_DOT11_MODE_11g) {
2315 QDF_TRACE(QDF_MODULE_ID_SAP,
2316 QDF_TRACE_LEVEL_INFO_HIGH,
2317 "operating_band %d", operating_band);
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002318 continue;
Tushnim Bhattacharyya03103fd2017-06-23 10:48:52 -07002319 }
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002320
2321 /* Give preference to Non-overlap channels */
2322 if (false == sap_filter_over_lap_ch(sap_ctx,
Tushnim Bhattacharyya03103fd2017-06-23 10:48:52 -07002323 spect_info->pSpectCh[count].chNum)) {
2324 QDF_TRACE(QDF_MODULE_ID_SAP,
2325 QDF_TRACE_LEVEL_INFO_HIGH,
2326 "sap_filter_over_lap_ch is false");
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002327 continue;
Tushnim Bhattacharyya03103fd2017-06-23 10:48:52 -07002328 }
2329
2330 if (wlan_reg_is_dfs_ch(mac_ctx->pdev,
2331 spect_info->pSpectCh[count].chNum) &&
2332 policy_mgr_disallow_mcc(mac_ctx->psoc,
2333 spect_info->pSpectCh[count].chNum)) {
2334 QDF_TRACE(QDF_MODULE_ID_SAP,
2335 QDF_TRACE_LEVEL_INFO_HIGH,
2336 "No DFS MCC");
2337 continue;
2338 }
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002339
bings14d1d3b2017-08-03 11:14:29 +08002340 if (spect_info->pSpectCh[count].weight_copy >
2341 sap_ctx->acsBestChannelInfo.weight)
2342 continue;
2343
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002344 tmp_ch_num = spect_info->pSpectCh[count].chNum;
2345 tmp_ch_num = sap_select_preferred_channel_from_channel_list(
2346 tmp_ch_num, sap_ctx, spect_info);
2347 if (tmp_ch_num == SAP_CHANNEL_NOT_SELECTED)
2348 continue;
2349
2350 best_ch_num = tmp_ch_num;
2351 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002352 }
2353#else
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002354 /* Sort the ch lst as per the computed weights, lesser weight first. */
2355 sap_sort_chl_weight_all(sap_ctx, hal, spect_info);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002356 /* Get the first channel in sorted array as best 20M Channel */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002357 best_ch_num = (uint8_t) spect_info->pSpectCh[0].chNum;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002358 /* Select Best Channel from Channel List if Configured */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002359 best_ch_num = sap_select_preferred_channel_from_channel_list(
2360 best_ch_num, sap_ctx, spect_info);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002361#endif
2362
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002363 /*
2364 * in case the best channel seleted is not in PCL and there is another
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002365 * channel which has same weightage and is in PCL, choose the one in
2366 * PCL
2367 */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002368 for (count = 0; count < spect_info->numSpectChans; count++) {
2369 if (!ch_in_pcl(sap_ctx, spect_info->pSpectCh[count].chNum) ||
2370 (spect_info->pSpectCh[count].weight !=
2371 sap_ctx->acsBestChannelInfo.weight))
2372 continue;
2373
2374 if (sap_select_preferred_channel_from_channel_list(
2375 spect_info->pSpectCh[count].chNum, sap_ctx, spect_info)
2376 == SAP_CHANNEL_NOT_SELECTED)
2377 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002378
2379#ifdef FEATURE_AP_MCC_CH_AVOIDANCE
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002380 if (sap_check_in_avoid_ch_list(sap_ctx, best_ch_num))
2381 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002382#endif
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002383 best_ch_num = spect_info->pSpectCh[count].chNum;
2384 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
2385 FL("change best channel to %d in PCL"), best_ch_num);
2386 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002387 }
2388
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002389 sap_ctx->acs_cfg->pri_ch = best_ch_num;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002390 /* determine secondary channel for 2.4G channel 5, 6, 7 in HT40 */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002391 if ((operating_band != eCSR_DOT11_MODE_11g) ||
2392 (sap_ctx->acs_cfg->ch_width != CH_WIDTH_40MHZ))
2393 goto sap_ch_sel_end;
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002394 if (REGDOMAIN_FCC == domain)
bingse2782382017-03-23 10:34:52 +08002395 ht40plus2gendch = HT40PLUS_2G_FCC_CH_END;
2396 else
2397 ht40plus2gendch = HT40PLUS_2G_EURJAP_CH_END;
2398 if ((best_ch_num >= HT40MINUS_2G_CH_START) &&
2399 (best_ch_num <= ht40plus2gendch)) {
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002400 int weight_below, weight_above, i;
2401 tSapSpectChInfo *pspect_info;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002402
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002403 weight_below = weight_above = SAP_ACS_WEIGHT_MAX;
2404 pspect_info = spect_info->pSpectCh;
2405 for (i = 0; i < spect_info->numSpectChans; i++) {
2406 if (pspect_info[i].chNum == (best_ch_num - 4))
2407 weight_below = pspect_info[i].weight;
2408 if (pspect_info[i].chNum == (best_ch_num + 4))
2409 weight_above = pspect_info[i].weight;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002410 }
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002411
2412 if (weight_below < weight_above)
2413 sap_ctx->acs_cfg->ht_sec_ch =
2414 sap_ctx->acs_cfg->pri_ch - 4;
2415 else
2416 sap_ctx->acs_cfg->ht_sec_ch =
2417 sap_ctx->acs_cfg->pri_ch + 4;
2418 } else if (best_ch_num >= 1 && best_ch_num <= 4) {
2419 sap_ctx->acs_cfg->ht_sec_ch = sap_ctx->acs_cfg->pri_ch + 4;
bingse2782382017-03-23 10:34:52 +08002420 } else if (best_ch_num >= ht40plus2gendch && best_ch_num <=
2421 HT40MINUS_2G_CH_END) {
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002422 sap_ctx->acs_cfg->ht_sec_ch = sap_ctx->acs_cfg->pri_ch - 4;
2423 } else if (best_ch_num == 14) {
2424 sap_ctx->acs_cfg->ht_sec_ch = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002425 }
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002426 sap_ctx->secondary_ch = sap_ctx->acs_cfg->ht_sec_ch;
2427
2428sap_ch_sel_end:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002429 /* Free all the allocated memory */
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002430 sap_chan_sel_exit(spect_info);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002431
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302432 QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
Naveen Rawat365d1cb2016-02-05 12:10:43 -08002433 FL("Running SAP Ch select Completed, Ch=%d"), best_ch_num);
2434 if (best_ch_num > 0 && best_ch_num <= 252)
2435 return best_ch_num;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002436 else
2437 return SAP_CHANNEL_NOT_SELECTED;
2438}