Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1 | /* |
Himanshu Agarwal | fee2e36 | 2018-01-18 20:26:35 +0530 | [diff] [blame] | 2 | * Copyright (c) 2012-2018 The Linux Foundation. All rights reserved. |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
| 20 | */ |
| 21 | |
| 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 Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 30 | s a p C h S e l e c t . C |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 31 | 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 Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 44 | #include "qdf_trace.h" |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 45 | #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 Gowri | 48b8933 | 2016-08-30 18:43:05 +0530 | [diff] [blame] | 56 | #include "cds_utils.h" |
Yuanyuan Liu | 0e0aa93 | 2016-05-12 10:17:58 -0700 | [diff] [blame] | 57 | #include "pld_common.h" |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 58 | #include "wlan_reg_services_api.h" |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 59 | |
| 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 | |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 74 | #define SET_ACS_BAND(acs_band, sap_ctx) \ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 75 | { \ |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 76 | if (sap_ctx->acs_cfg->start_ch <= 14 && \ |
| 77 | sap_ctx->acs_cfg->end_ch <= 14) \ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 78 | acs_band = eCSR_DOT11_MODE_11g; \ |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 79 | else if (sap_ctx->acs_cfg->start_ch >= 14)\ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 80 | acs_band = eCSR_DOT11_MODE_11a; \ |
| 81 | else \ |
| 82 | acs_band = eCSR_DOT11_MODE_abg; \ |
| 83 | } |
| 84 | |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 85 | #define ACS_WEIGHT_AMOUNT_LOCAL 240 |
| 86 | |
| 87 | #define ACS_WEIGHT_AMOUNT_CONFIG(weights) \ |
| 88 | (((weights) & 0xf) + \ |
| 89 | (((weights) & 0xf0) >> 4) + \ |
| 90 | (((weights) & 0xf00) >> 8) + \ |
| 91 | (((weights) & 0xf000) >> 12) + \ |
| 92 | (((weights) & 0xf0000) >> 16) + \ |
| 93 | (((weights) & 0xf00000) >> 20)) |
| 94 | |
| 95 | /* |
| 96 | * LSH/RSH 4 to enhance the accurate since |
| 97 | * need to do modulation to ACS_WEIGHT_AMOUNT_LOCAL. |
| 98 | */ |
| 99 | #define ACS_WEIGHT_COMPUTE(weights, weight, factor, base) \ |
| 100 | (((((((((weight) << 4) * ACS_WEIGHT_AMOUNT_LOCAL * (factor)) + \ |
| 101 | (ACS_WEIGHT_AMOUNT_CONFIG((weights)) >> 1)) / \ |
| 102 | ACS_WEIGHT_AMOUNT_CONFIG((weights))) + \ |
| 103 | ((base) >> 1)) / (base)) + 8) >> 4) |
| 104 | |
| 105 | #define ACS_WEIGHT_CFG_TO_LOCAL(weights, weight) \ |
| 106 | (((((((weight) << 4) * ACS_WEIGHT_AMOUNT_LOCAL) + \ |
| 107 | (ACS_WEIGHT_AMOUNT_CONFIG((weights)) >> 1)) / \ |
| 108 | ACS_WEIGHT_AMOUNT_CONFIG((weights))) + 8) >> 4) |
| 109 | |
| 110 | #define ACS_WEIGHT_SOFTAP_RSSI_CFG(weights) \ |
| 111 | ((weights) & 0xf) |
| 112 | |
| 113 | #define ACS_WEIGHT_SOFTAP_COUNT_CFG(weights) \ |
| 114 | (((weights) & 0xf0) >> 4) |
| 115 | |
| 116 | #define ACS_WEIGHT_SOFTAP_NOISE_FLOOR_CFG(weights) \ |
| 117 | (((weights) & 0xf00) >> 8) |
| 118 | |
| 119 | #define ACS_WEIGHT_SOFTAP_CHANNEL_FREE_CFG(weights) \ |
| 120 | (((weights) & 0xf000) >> 12) |
| 121 | |
| 122 | #define ACS_WEIGHT_SOFTAP_TX_POWER_RANGE_CFG(weights) \ |
| 123 | (((weights) & 0xf0000) >> 16) |
| 124 | |
| 125 | #define ACS_WEIGHT_SOFTAP_TX_POWER_THROUGHPUT_CFG(weights) \ |
| 126 | (((weights) & 0xf00000) >> 20) |
| 127 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 128 | #ifdef FEATURE_WLAN_CH_AVOID |
Amar Singhal | b8d4f15 | 2016-02-10 10:21:43 -0800 | [diff] [blame] | 129 | sapSafeChannelType safe_channels[NUM_CHANNELS] = { |
| 130 | {1, true}, |
| 131 | {2, true}, |
| 132 | {3, true}, |
| 133 | {4, true}, |
| 134 | {5, true}, |
| 135 | {6, true}, |
| 136 | {7, true}, |
| 137 | {8, true}, |
| 138 | {9, true}, |
| 139 | {10, true}, |
| 140 | {11, true}, |
| 141 | {12, true}, |
| 142 | {13, true}, |
| 143 | {14, true}, |
| 144 | {36, true}, |
| 145 | {40, true}, |
| 146 | {44, true}, |
| 147 | {48, true}, |
| 148 | {52, true}, |
| 149 | {56, true}, |
| 150 | {60, true}, |
| 151 | {64, true}, |
| 152 | {100, true}, |
| 153 | {104, true}, |
| 154 | {108, true}, |
| 155 | {112, true}, |
| 156 | {116, true}, |
| 157 | {120, true}, |
| 158 | {124, true}, |
| 159 | {128, true}, |
| 160 | {132, true}, |
| 161 | {136, true}, |
| 162 | {140, true}, |
| 163 | {144, true}, |
| 164 | {149, true}, |
| 165 | {153, true}, |
| 166 | {157, true}, |
| 167 | {161, true}, |
| 168 | {165, true}, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 169 | }; |
| 170 | #endif |
| 171 | |
| 172 | typedef struct { |
| 173 | uint16_t chStartNum; |
| 174 | uint32_t weight; |
| 175 | } sapAcsChannelInfo; |
| 176 | |
| 177 | sapAcsChannelInfo acs_ht40_channels5_g[] = { |
| 178 | {36, SAP_ACS_WEIGHT_MAX}, |
| 179 | {44, SAP_ACS_WEIGHT_MAX}, |
| 180 | {52, SAP_ACS_WEIGHT_MAX}, |
| 181 | {60, SAP_ACS_WEIGHT_MAX}, |
| 182 | {100, SAP_ACS_WEIGHT_MAX}, |
| 183 | {108, SAP_ACS_WEIGHT_MAX}, |
| 184 | {116, SAP_ACS_WEIGHT_MAX}, |
| 185 | {124, SAP_ACS_WEIGHT_MAX}, |
| 186 | {132, SAP_ACS_WEIGHT_MAX}, |
| 187 | {140, SAP_ACS_WEIGHT_MAX}, |
| 188 | {149, SAP_ACS_WEIGHT_MAX}, |
| 189 | {157, SAP_ACS_WEIGHT_MAX}, |
| 190 | }; |
| 191 | |
| 192 | sapAcsChannelInfo acs_ht80_channels[] = { |
| 193 | {36, SAP_ACS_WEIGHT_MAX}, |
| 194 | {52, SAP_ACS_WEIGHT_MAX}, |
| 195 | {100, SAP_ACS_WEIGHT_MAX}, |
| 196 | {116, SAP_ACS_WEIGHT_MAX}, |
| 197 | {132, SAP_ACS_WEIGHT_MAX}, |
| 198 | {149, SAP_ACS_WEIGHT_MAX}, |
| 199 | }; |
| 200 | |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 201 | sapAcsChannelInfo acs_vht160_channels[] = { |
| 202 | {36, SAP_ACS_WEIGHT_MAX}, |
| 203 | {100, SAP_ACS_WEIGHT_MAX}, |
| 204 | }; |
| 205 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 206 | sapAcsChannelInfo acs_ht40_channels24_g[] = { |
| 207 | {1, SAP_ACS_WEIGHT_MAX}, |
| 208 | {2, SAP_ACS_WEIGHT_MAX}, |
| 209 | {3, SAP_ACS_WEIGHT_MAX}, |
| 210 | {4, SAP_ACS_WEIGHT_MAX}, |
| 211 | {9, SAP_ACS_WEIGHT_MAX}, |
| 212 | }; |
| 213 | |
| 214 | #define CHANNEL_165 165 |
| 215 | |
| 216 | /* rssi discount for channels in PCL */ |
| 217 | #define PCL_RSSI_DISCOUNT 10 |
| 218 | |
| 219 | #ifdef FEATURE_AP_MCC_CH_AVOIDANCE |
| 220 | /** |
| 221 | * sap_check_n_add_channel() - checks and add given channel in sap context's |
| 222 | * avoid_channels_info struct |
| 223 | * @sap_ctx: sap context. |
| 224 | * @new_channel: channel to be added to sap_ctx's avoid ch info |
| 225 | * |
| 226 | * sap_ctx contains sap_avoid_ch_info strcut containing the list of channels on |
| 227 | * which MDM device's AP with MCC was detected. This function will add channels |
| 228 | * to that list after checking for duplicates. |
| 229 | * |
| 230 | * Return: true: if channel was added or already present |
| 231 | * else false: if channel list was already full. |
| 232 | */ |
Tang Yingying | 523322d | 2017-01-17 23:28:43 +0800 | [diff] [blame] | 233 | static bool |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 234 | sap_check_n_add_channel(struct sap_context *sap_ctx, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 235 | uint8_t new_channel) |
| 236 | { |
| 237 | uint8_t i = 0; |
| 238 | struct sap_avoid_channels_info *ie_info = |
| 239 | &sap_ctx->sap_detected_avoid_ch_ie; |
| 240 | |
| 241 | for (i = 0; i < sizeof(ie_info->channels); i++) { |
| 242 | if (ie_info->channels[i] == new_channel) |
| 243 | break; |
| 244 | |
| 245 | if (ie_info->channels[i] == 0) { |
| 246 | ie_info->channels[i] = new_channel; |
| 247 | break; |
| 248 | } |
| 249 | } |
| 250 | if (i == sizeof(ie_info->channels)) |
| 251 | return false; |
| 252 | else |
| 253 | return true; |
| 254 | } |
| 255 | /** |
| 256 | * sap_check_n_add_overlapped_chnls() - checks & add overlapped channels |
| 257 | * to primary channel in 2.4Ghz band. |
| 258 | * @sap_ctx: sap context. |
| 259 | * @primary_chnl: primary channel to be avoided. |
| 260 | * |
| 261 | * sap_ctx contains sap_avoid_ch_info struct containing the list of channels on |
| 262 | * which MDM device's AP with MCC was detected. This function will add channels |
| 263 | * to that list after checking for duplicates. |
| 264 | * |
| 265 | * Return: true: if channel was added or already present |
| 266 | * else false: if channel list was already full. |
| 267 | */ |
| 268 | static bool |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 269 | sap_check_n_add_overlapped_chnls(struct sap_context *sap_ctx, |
| 270 | uint8_t primary_channel) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 271 | { |
| 272 | uint8_t i = 0, j = 0, upper_chnl = 0, lower_chnl = 0; |
| 273 | struct sap_avoid_channels_info *ie_info = |
| 274 | &sap_ctx->sap_detected_avoid_ch_ie; |
| 275 | /* |
| 276 | * if primary channel less than channel 1 or out of 2g band then |
| 277 | * no further process is required. return true in this case. |
| 278 | */ |
| 279 | if (primary_channel < CHANNEL_1 || primary_channel > CHANNEL_14) |
| 280 | return true; |
| 281 | |
| 282 | /* lower channel is one channel right before primary channel */ |
| 283 | lower_chnl = primary_channel - 1; |
| 284 | /* upper channel is one channel right after primary channel */ |
| 285 | upper_chnl = primary_channel + 1; |
| 286 | |
| 287 | /* lower channel needs to be non-zero, zero is not valid channel */ |
| 288 | if (lower_chnl > (CHANNEL_1 - 1)) { |
| 289 | for (i = 0; i < sizeof(ie_info->channels); i++) { |
| 290 | if (ie_info->channels[i] == lower_chnl) |
| 291 | break; |
| 292 | if (ie_info->channels[i] == 0) { |
| 293 | ie_info->channels[i] = lower_chnl; |
| 294 | break; |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | /* upper channel needs to be atleast last channel in 2.4Ghz band */ |
| 299 | if (upper_chnl < (CHANNEL_14 + 1)) { |
| 300 | for (j = 0; j < sizeof(ie_info->channels); j++) { |
| 301 | if (ie_info->channels[j] == upper_chnl) |
| 302 | break; |
| 303 | if (ie_info->channels[j] == 0) { |
| 304 | ie_info->channels[j] = upper_chnl; |
| 305 | break; |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | if (i == sizeof(ie_info->channels) || j == sizeof(ie_info->channels)) |
| 310 | return false; |
| 311 | else |
| 312 | return true; |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * sap_process_avoid_ie() - processes the detected Q2Q IE |
| 317 | * context's avoid_channels_info struct |
| 318 | * @hal: hal handle |
| 319 | * @sap_ctx: sap context. |
| 320 | * @scan_result: scan results for ACS scan. |
| 321 | * @spect_info: spectrum weights array to update |
| 322 | * |
| 323 | * Detection of Q2Q IE indicates presence of another MDM device with its AP |
| 324 | * operating in MCC mode. This function parses the scan results and processes |
| 325 | * the Q2Q IE if found. It then extracts the channels and populates them in |
| 326 | * sap_ctx struct. It also increases the weights of those channels so that |
| 327 | * ACS logic will avoid those channels in its selection algorithm. |
| 328 | * |
| 329 | * Return: void |
| 330 | */ |
Tang Yingying | 523322d | 2017-01-17 23:28:43 +0800 | [diff] [blame] | 331 | static void sap_process_avoid_ie(tHalHandle hal, |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 332 | struct sap_context *sap_ctx, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 333 | tScanResultHandle scan_result, |
| 334 | tSapChSelSpectInfo *spect_info) |
| 335 | { |
| 336 | uint32_t total_ie_len = 0; |
| 337 | uint8_t *temp_ptr = NULL; |
| 338 | uint8_t i = 0; |
| 339 | struct sAvoidChannelIE *avoid_ch_ie; |
| 340 | tCsrScanResultInfo *node = NULL; |
| 341 | tpAniSirGlobal mac_ctx = NULL; |
| 342 | tSapSpectChInfo *spect_ch = NULL; |
| 343 | |
| 344 | mac_ctx = PMAC_STRUCT(hal); |
| 345 | spect_ch = spect_info->pSpectCh; |
| 346 | node = sme_scan_result_get_first(hal, scan_result); |
| 347 | |
| 348 | while (node) { |
Abhishek Singh | 34a4d86 | 2016-10-26 16:01:51 +0530 | [diff] [blame] | 349 | total_ie_len = |
Jeff Johnson | 38e38a8 | 2017-10-06 10:32:31 -0700 | [diff] [blame] | 350 | GET_IE_LEN_IN_BSS(node->BssDescriptor.length); |
Naveen Rawat | 08db88f | 2017-09-08 15:07:48 -0700 | [diff] [blame] | 351 | temp_ptr = wlan_get_vendor_ie_ptr_from_oui( |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 352 | SIR_MAC_QCOM_VENDOR_OUI, |
| 353 | SIR_MAC_QCOM_VENDOR_SIZE, |
| 354 | ((uint8_t *)&node->BssDescriptor.ieFields), |
| 355 | total_ie_len); |
| 356 | |
| 357 | if (temp_ptr) { |
| 358 | avoid_ch_ie = (struct sAvoidChannelIE *)temp_ptr; |
Will Huang | 55ba104 | 2017-03-22 10:43:30 +0800 | [diff] [blame] | 359 | if (avoid_ch_ie->type != |
| 360 | QCOM_VENDOR_IE_MCC_AVOID_CH) { |
| 361 | node = sme_scan_result_get_next(hal, |
| 362 | scan_result); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 363 | continue; |
Will Huang | 55ba104 | 2017-03-22 10:43:30 +0800 | [diff] [blame] | 364 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 365 | |
| 366 | sap_ctx->sap_detected_avoid_ch_ie.present = 1; |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 367 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 368 | QDF_TRACE_LEVEL_DEBUG, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 369 | "Q2Q IE - avoid ch %d", |
| 370 | avoid_ch_ie->channel); |
| 371 | /* add this channel to to_avoid channel list */ |
| 372 | sap_check_n_add_channel(sap_ctx, |
| 373 | avoid_ch_ie->channel); |
| 374 | sap_check_n_add_overlapped_chnls(sap_ctx, |
| 375 | avoid_ch_ie->channel); |
| 376 | /* |
| 377 | * Mark weight of these channel present in IE to MAX |
| 378 | * so that ACS logic will to avoid thse channels |
| 379 | */ |
| 380 | for (i = 0; i < spect_info->numSpectChans; i++) |
| 381 | if (spect_ch[i].chNum == avoid_ch_ie->channel) { |
| 382 | /* |
| 383 | * weight is set more than max so that, |
| 384 | * in the case of other channels being |
| 385 | * assigned max weight due to noise, |
| 386 | * they may be preferred over channels |
| 387 | * with Q2Q IE. |
| 388 | */ |
| 389 | spect_ch[i].weight = SAP_ACS_WEIGHT_MAX + 1; |
| 390 | spect_ch[i].weight_copy = |
| 391 | SAP_ACS_WEIGHT_MAX + 1; |
| 392 | break; |
| 393 | } |
| 394 | } /* if (temp_ptr) */ |
| 395 | node = sme_scan_result_get_next(hal, scan_result); |
| 396 | } |
| 397 | } |
| 398 | #endif /* FEATURE_AP_MCC_CH_AVOIDANCE */ |
| 399 | |
| 400 | #ifdef FEATURE_WLAN_CH_AVOID |
| 401 | /*========================================================================== |
| 402 | FUNCTION sap_update_unsafe_channel_list |
| 403 | |
| 404 | DESCRIPTION |
| 405 | Function Undate unsafe channel list table |
| 406 | |
| 407 | DEPENDENCIES |
| 408 | NA. |
| 409 | |
| 410 | IN |
| 411 | SapContext pointer |
| 412 | |
| 413 | RETURN VALUE |
| 414 | NULL |
| 415 | ============================================================================*/ |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 416 | void sap_update_unsafe_channel_list(tHalHandle hal, struct sap_context *sap_ctx) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 417 | { |
| 418 | uint16_t i, j; |
Amar Singhal | b8d4f15 | 2016-02-10 10:21:43 -0800 | [diff] [blame] | 419 | uint16_t unsafe_channel_list[NUM_CHANNELS]; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 420 | uint16_t unsafe_channel_count = 0; |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 421 | tpAniSirGlobal mac_ctx = NULL; |
| 422 | |
Yuanyuan Liu | 0e0aa93 | 2016-05-12 10:17:58 -0700 | [diff] [blame] | 423 | qdf_device_t qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 424 | |
Yuanyuan Liu | 9736118 | 2016-06-06 09:38:04 -0700 | [diff] [blame] | 425 | if (!qdf_ctx) { |
| 426 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_FATAL, |
| 427 | "qdf_ctx is NULL"); |
| 428 | return; |
| 429 | } |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 430 | mac_ctx = PMAC_STRUCT(hal); |
| 431 | if (!mac_ctx) { |
| 432 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_FATAL, |
| 433 | "mac_ctx is NULL"); |
| 434 | return; |
| 435 | } |
Yuanyuan Liu | 9736118 | 2016-06-06 09:38:04 -0700 | [diff] [blame] | 436 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 437 | /* Flush, default set all channel safe */ |
Amar Singhal | b8d4f15 | 2016-02-10 10:21:43 -0800 | [diff] [blame] | 438 | for (i = 0; i < NUM_CHANNELS; i++) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 439 | safe_channels[i].isSafe = true; |
| 440 | } |
| 441 | |
| 442 | /* Try to find unsafe channel */ |
Ryan Hsu | 4252a2f | 2016-01-05 11:18:24 -0800 | [diff] [blame] | 443 | #if defined(FEATURE_WLAN_STA_AP_MODE_DFS_DISABLE) |
Amar Singhal | b8d4f15 | 2016-02-10 10:21:43 -0800 | [diff] [blame] | 444 | for (i = 0; i < NUM_CHANNELS; i++) { |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 445 | if (sap_ctx->dfs_ch_disable == true) { |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 446 | if (wlan_reg_is_dfs_ch(mac_ctx->pdev, |
| 447 | safe_channels[i].channelNumber)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 448 | safe_channels[i].isSafe = false; |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 449 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 450 | QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 451 | "%s: DFS Ch %d is not safe in" |
| 452 | " Concurrent mode", |
| 453 | __func__, |
| 454 | safe_channels[i].channelNumber); |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | #endif |
Yuanyuan Liu | 0e0aa93 | 2016-05-12 10:17:58 -0700 | [diff] [blame] | 459 | pld_get_wlan_unsafe_channel(qdf_ctx->dev, |
| 460 | unsafe_channel_list, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 461 | &unsafe_channel_count, |
| 462 | sizeof(unsafe_channel_list)); |
| 463 | |
| 464 | for (i = 0; i < unsafe_channel_count; i++) { |
Amar Singhal | b8d4f15 | 2016-02-10 10:21:43 -0800 | [diff] [blame] | 465 | for (j = 0; j < NUM_CHANNELS; j++) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 466 | if (safe_channels[j].channelNumber == |
| 467 | unsafe_channel_list[i]) { |
| 468 | /* Found unsafe channel, update it */ |
| 469 | safe_channels[j].isSafe = false; |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 470 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 471 | QDF_TRACE_LEVEL_ERROR, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 472 | FL("CH %d is not safe"), |
| 473 | unsafe_channel_list[i]); |
| 474 | break; |
| 475 | } |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | return; |
| 480 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 481 | |
| 482 | #endif /* FEATURE_WLAN_CH_AVOID */ |
| 483 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 484 | /** |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 485 | * sap_channel_in_acs_channel_list() - check if channel in acs channel list |
| 486 | * @channel_num: channel to check |
| 487 | * @sap_ctx: struct ptSapContext |
| 488 | * @spect_info_params: strcut tSapChSelSpectInfo |
| 489 | * |
| 490 | * This function checks if specified channel is in the configured ACS channel |
| 491 | * list. |
| 492 | * |
| 493 | * Return: channel number if in acs channel list or SAP_CHANNEL_NOT_SELECTED |
| 494 | */ |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 495 | uint8_t sap_channel_in_acs_channel_list(uint8_t channel_num, |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 496 | struct sap_context *sap_ctx, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 497 | tSapChSelSpectInfo *spect_info_params) |
| 498 | { |
| 499 | uint8_t i = 0; |
| 500 | |
| 501 | if ((NULL == sap_ctx->acs_cfg->ch_list) || |
| 502 | (NULL == spect_info_params)) |
| 503 | return channel_num; |
| 504 | |
| 505 | if (channel_num > 0 && channel_num <= 252) { |
| 506 | for (i = 0; i < sap_ctx->acs_cfg->ch_list_count; i++) { |
| 507 | if ((sap_ctx->acs_cfg->ch_list[i]) == channel_num) |
| 508 | return channel_num; |
| 509 | } |
| 510 | return SAP_CHANNEL_NOT_SELECTED; |
| 511 | } else { |
| 512 | return SAP_CHANNEL_NOT_SELECTED; |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | /** |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 517 | * sap_select_preferred_channel_from_channel_list() - to calc best cahnnel |
| 518 | * @best_chnl: best channel already calculated among all the chanels |
| 519 | * @sap_ctx: sap context |
| 520 | * @spectinfo_param: Pointer to tSapChSelSpectInfo structure |
| 521 | * |
| 522 | * This function calculates the best channel among the configured channel list. |
| 523 | * If channel list not configured then returns the best channel calculated |
| 524 | * among all the channel list. |
| 525 | * |
| 526 | * Return: uint8_t best channel |
| 527 | */ |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 528 | static |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 529 | uint8_t sap_select_preferred_channel_from_channel_list(uint8_t best_chnl, |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 530 | struct sap_context *sap_ctx, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 531 | tSapChSelSpectInfo *spectinfo_param) |
| 532 | { |
| 533 | uint8_t i = 0; |
Tushnim Bhattacharyya | 518e80f | 2017-08-30 17:35:33 -0700 | [diff] [blame] | 534 | tpAniSirGlobal mac_ctx = sme_get_mac_context(); |
| 535 | |
| 536 | if (NULL == mac_ctx) { |
| 537 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR, |
| 538 | "pmac Global Context is NULL"); |
| 539 | return SAP_CHANNEL_NOT_SELECTED; |
| 540 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 541 | |
| 542 | /* |
| 543 | * If Channel List is not Configured don't do anything |
| 544 | * Else return the Best Channel from the Channel List |
| 545 | */ |
| 546 | if ((NULL == sap_ctx->acs_cfg->ch_list) || |
| 547 | (NULL == spectinfo_param) || |
| 548 | (0 == sap_ctx->acs_cfg->ch_list_count)) |
| 549 | return best_chnl; |
| 550 | |
| 551 | if (best_chnl <= 0 || best_chnl > 252) |
| 552 | return SAP_CHANNEL_NOT_SELECTED; |
| 553 | |
| 554 | /* Select the best channel from allowed list */ |
| 555 | for (i = 0; i < sap_ctx->acs_cfg->ch_list_count; i++) { |
Tushnim Bhattacharyya | 518e80f | 2017-08-30 17:35:33 -0700 | [diff] [blame] | 556 | if ((sap_ctx->acs_cfg->ch_list[i] == best_chnl) && |
| 557 | !(wlan_reg_is_dfs_ch(mac_ctx->pdev, best_chnl) && |
| 558 | policy_mgr_disallow_mcc(mac_ctx->psoc, best_chnl))) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 559 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 560 | QDF_TRACE_LEVEL_INFO_HIGH, |
Naveen Rawat | bec64d9 | 2017-09-13 14:35:21 -0700 | [diff] [blame] | 561 | "Best channel so far is: %d", |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 562 | best_chnl); |
| 563 | return best_chnl; |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | return SAP_CHANNEL_NOT_SELECTED; |
| 568 | } |
| 569 | |
| 570 | /*========================================================================== |
| 571 | FUNCTION sap_chan_sel_init |
| 572 | |
| 573 | DESCRIPTION |
| 574 | Function sap_chan_sel_init allocates the memory, intializes the |
Anurag Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 575 | structures used by the channel selection algorithm |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 576 | |
| 577 | DEPENDENCIES |
| 578 | NA. |
| 579 | |
| 580 | PARAMETERS |
| 581 | |
| 582 | IN |
| 583 | halHandle : Pointer to tHalHandle |
| 584 | *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 585 | sap_ctx : Pointer to SAP Context |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 586 | |
| 587 | RETURN VALUE |
| 588 | bool: Success or FAIL |
| 589 | |
| 590 | SIDE EFFECTS |
| 591 | ============================================================================*/ |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 592 | static bool sap_chan_sel_init(tHalHandle halHandle, |
| 593 | tSapChSelSpectInfo *pSpectInfoParams, |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 594 | struct sap_context *sap_ctx) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 595 | { |
| 596 | tSapSpectChInfo *pSpectCh = NULL; |
| 597 | uint8_t *pChans = NULL; |
| 598 | uint16_t channelnum = 0; |
| 599 | tpAniSirGlobal pMac = PMAC_STRUCT(halHandle); |
| 600 | bool chSafe = true; |
| 601 | #ifdef FEATURE_WLAN_CH_AVOID |
| 602 | uint16_t i; |
| 603 | #endif |
| 604 | uint32_t dfs_master_cap_enabled; |
| 605 | bool include_dfs_ch = true; |
Himanshu Agarwal | fee2e36 | 2018-01-18 20:26:35 +0530 | [diff] [blame] | 606 | uint8_t chan_num; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 607 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 608 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, "In %s", |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 609 | __func__); |
| 610 | |
| 611 | pSpectInfoParams->numSpectChans = |
| 612 | pMac->scan.base_channels.numChannels; |
| 613 | |
| 614 | /* Allocate memory for weight computation of 2.4GHz */ |
| 615 | pSpectCh = |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 616 | (tSapSpectChInfo *) qdf_mem_malloc((pSpectInfoParams->numSpectChans) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 617 | * sizeof(*pSpectCh)); |
| 618 | |
| 619 | if (pSpectCh == NULL) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 620 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR, |
Anurag Chouhan | f04e84f | 2016-03-03 10:12:12 +0530 | [diff] [blame] | 621 | "In %s, QDF_MALLOC_ERR", __func__); |
Srinivas Girigowda | 74a66d6 | 2017-06-21 23:28:25 -0700 | [diff] [blame] | 622 | return false; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 623 | } |
| 624 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 625 | /* Initialize the pointers in the DfsParams to the allocated memory */ |
| 626 | pSpectInfoParams->pSpectCh = pSpectCh; |
| 627 | |
| 628 | pChans = pMac->scan.base_channels.channelList; |
| 629 | |
Ryan Hsu | 4252a2f | 2016-01-05 11:18:24 -0800 | [diff] [blame] | 630 | #if defined(FEATURE_WLAN_STA_AP_MODE_DFS_DISABLE) |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 631 | if (sap_ctx->dfs_ch_disable == true) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 632 | include_dfs_ch = false; |
| 633 | #endif |
| 634 | sme_cfg_get_int(halHandle, WNI_CFG_DFS_MASTER_ENABLED, |
| 635 | &dfs_master_cap_enabled); |
Agrawal Ashish | 6563461 | 2016-08-18 13:24:32 +0530 | [diff] [blame] | 636 | if (dfs_master_cap_enabled == 0 || |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 637 | ACS_DFS_MODE_DISABLE == sap_ctx->dfs_mode) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 638 | include_dfs_ch = false; |
| 639 | |
| 640 | /* Fill the channel number in the spectrum in the operating freq band */ |
| 641 | for (channelnum = 0; |
| 642 | channelnum < pSpectInfoParams->numSpectChans; |
Edhar, Mahesh Kumar | 4f66067 | 2015-10-30 11:53:26 +0530 | [diff] [blame] | 643 | channelnum++, pChans++, pSpectCh++) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 644 | chSafe = true; |
| 645 | |
| 646 | /* check if the channel is in NOL blacklist */ |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 647 | if (sap_dfs_is_channel_in_nol_list(sap_ctx, *pChans, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 648 | PHY_SINGLE_CHANNEL_CENTERED)) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 649 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 650 | "In %s, Ch %d is in NOL list", __func__, |
| 651 | *pChans); |
| 652 | chSafe = false; |
| 653 | continue; |
| 654 | } |
| 655 | |
| 656 | if (include_dfs_ch == false) { |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 657 | if (wlan_reg_is_dfs_ch(pMac->pdev, *pChans)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 658 | chSafe = false; |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 659 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 660 | QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 661 | "In %s, DFS Ch %d not considered for ACS", |
| 662 | __func__, *pChans); |
| 663 | continue; |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | #ifdef FEATURE_WLAN_CH_AVOID |
Amar Singhal | b8d4f15 | 2016-02-10 10:21:43 -0800 | [diff] [blame] | 668 | for (i = 0; i < NUM_CHANNELS; i++) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 669 | if ((safe_channels[i].channelNumber == *pChans) && |
| 670 | (false == safe_channels[i].isSafe)) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 671 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 672 | QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 673 | "In %s, Ch %d is not safe", __func__, |
| 674 | *pChans); |
| 675 | chSafe = false; |
| 676 | break; |
| 677 | } |
| 678 | } |
| 679 | #endif /* FEATURE_WLAN_CH_AVOID */ |
| 680 | |
| 681 | /* OFDM rates are not supported on channel 14 */ |
| 682 | if (*pChans == 14 && |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 683 | eCSR_DOT11_MODE_11b != sap_ctx->csr_roamProfile.phyMode) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 684 | continue; |
| 685 | } |
| 686 | |
Deepthi Gowri | 48b8933 | 2016-08-30 18:43:05 +0530 | [diff] [blame] | 687 | /* Skip DSRC channels */ |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 688 | if (WLAN_REG_IS_11P_CH(*pChans)) |
Deepthi Gowri | 48b8933 | 2016-08-30 18:43:05 +0530 | [diff] [blame] | 689 | continue; |
| 690 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 691 | if (true == chSafe) { |
| 692 | pSpectCh->chNum = *pChans; |
Srinivas Girigowda | 74a66d6 | 2017-06-21 23:28:25 -0700 | [diff] [blame] | 693 | pSpectCh->valid = true; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 694 | pSpectCh->rssiAgr = SOFTAP_MIN_RSSI; /* Initialise for all channels */ |
| 695 | pSpectCh->channelWidth = SOFTAP_HT20_CHANNELWIDTH; /* Initialise 20MHz for all the Channels */ |
Himanshu Agarwal | fee2e36 | 2018-01-18 20:26:35 +0530 | [diff] [blame] | 696 | /* Initialise max ACS weight for all channels */ |
| 697 | pSpectCh->weight = SAP_ACS_WEIGHT_MAX; |
| 698 | for (chan_num = 0; chan_num < sap_ctx->num_of_channel; |
| 699 | chan_num++) { |
| 700 | if (pSpectCh->chNum != |
| 701 | sap_ctx->channelList[chan_num]) |
| 702 | continue; |
| 703 | |
| 704 | /* |
| 705 | * Initialize ACS weight to 0 for channels |
| 706 | * present in sap context scan channel list |
| 707 | */ |
| 708 | pSpectCh->weight = 0; |
| 709 | break; |
| 710 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 711 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 712 | } |
Srinivas Girigowda | 74a66d6 | 2017-06-21 23:28:25 -0700 | [diff] [blame] | 713 | return true; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 714 | } |
| 715 | |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 716 | /** |
| 717 | * sapweight_rssi_count() - calculates the channel weight due to rssi |
Anurag Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 718 | and data count(here number of BSS observed) |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 719 | * @sap_ctx : Softap context |
| 720 | * @rssi : Max signal strength receieved from a BSS for the channel |
| 721 | * @count : Number of BSS observed in the channel |
| 722 | * |
| 723 | * Return: uint32_t Calculated channel weight based on above two |
| 724 | */ |
| 725 | static |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 726 | uint32_t sapweight_rssi_count(struct sap_context *sap_ctx, int8_t rssi, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 727 | uint16_t count) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 728 | { |
| 729 | int32_t rssiWeight = 0; |
| 730 | int32_t countWeight = 0; |
| 731 | uint32_t rssicountWeight = 0; |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 732 | uint8_t softap_rssi_weight_cfg, softap_count_weight_cfg; |
| 733 | uint8_t softap_rssi_weight_local, softap_count_weight_local; |
| 734 | |
| 735 | softap_rssi_weight_cfg = |
| 736 | ACS_WEIGHT_SOFTAP_RSSI_CFG(sap_ctx->auto_channel_select_weight); |
| 737 | |
| 738 | softap_count_weight_cfg = |
| 739 | ACS_WEIGHT_SOFTAP_COUNT_CFG(sap_ctx->auto_channel_select_weight); |
| 740 | |
| 741 | softap_rssi_weight_local = |
| 742 | ACS_WEIGHT_CFG_TO_LOCAL(sap_ctx->auto_channel_select_weight, |
| 743 | softap_rssi_weight_cfg); |
| 744 | |
| 745 | softap_count_weight_local = |
| 746 | ACS_WEIGHT_CFG_TO_LOCAL(sap_ctx->auto_channel_select_weight, |
| 747 | softap_count_weight_cfg); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 748 | |
| 749 | /* Weight from RSSI */ |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 750 | rssiWeight = ACS_WEIGHT_COMPUTE(sap_ctx->auto_channel_select_weight, |
| 751 | softap_rssi_weight_cfg, |
| 752 | rssi - SOFTAP_MIN_RSSI, |
| 753 | SOFTAP_MAX_RSSI - SOFTAP_MIN_RSSI); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 754 | |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 755 | if (rssiWeight > softap_rssi_weight_local) |
| 756 | rssiWeight = softap_rssi_weight_local; |
| 757 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 758 | else if (rssiWeight < 0) |
| 759 | rssiWeight = 0; |
| 760 | |
| 761 | /* Weight from data count */ |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 762 | countWeight = ACS_WEIGHT_COMPUTE(sap_ctx->auto_channel_select_weight, |
| 763 | softap_count_weight_cfg, |
| 764 | count - SOFTAP_MIN_COUNT, |
| 765 | SOFTAP_MAX_COUNT - SOFTAP_MIN_COUNT); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 766 | |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 767 | if (countWeight > softap_count_weight_local) |
| 768 | countWeight = softap_count_weight_local; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 769 | |
| 770 | rssicountWeight = rssiWeight + countWeight; |
| 771 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 772 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 773 | "In %s, rssiWeight=%d, countWeight=%d, rssicountWeight=%d", |
| 774 | __func__, rssiWeight, countWeight, rssicountWeight); |
| 775 | |
| 776 | return rssicountWeight; |
| 777 | } |
| 778 | |
| 779 | /** |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 780 | * sap_get_channel_status() - get channel info via channel number |
| 781 | * @p_mac: Pointer to Global MAC structure |
| 782 | * @channel_id: channel id |
| 783 | * |
| 784 | * Return: chan status info |
| 785 | */ |
| 786 | static struct lim_channel_status *sap_get_channel_status |
| 787 | (tpAniSirGlobal p_mac, uint32_t channel_id) |
| 788 | { |
| 789 | return csr_get_channel_status(p_mac, channel_id); |
| 790 | } |
| 791 | |
| 792 | /** |
| 793 | * sap_clear_channel_status() - clear chan info |
| 794 | * @p_mac: Pointer to Global MAC structure |
| 795 | * |
| 796 | * Return: none |
| 797 | */ |
| 798 | static void sap_clear_channel_status(tpAniSirGlobal p_mac) |
| 799 | { |
| 800 | csr_clear_channel_status(p_mac); |
| 801 | } |
| 802 | |
| 803 | /** |
| 804 | * sap_weight_channel_noise_floor() - compute noise floor weight |
| 805 | * @sap_ctx: sap context |
| 806 | * @chn_stat: Pointer to chan status info |
| 807 | * |
| 808 | * Return: channel noise floor weight |
| 809 | */ |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 810 | static uint32_t sap_weight_channel_noise_floor(struct sap_context *sap_ctx, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 811 | struct lim_channel_status |
| 812 | *channel_stat) |
| 813 | { |
| 814 | uint32_t noise_floor_weight; |
| 815 | uint8_t softap_nf_weight_cfg; |
| 816 | uint8_t softap_nf_weight_local; |
| 817 | |
| 818 | softap_nf_weight_cfg = |
| 819 | ACS_WEIGHT_SOFTAP_NOISE_FLOOR_CFG |
| 820 | (sap_ctx->auto_channel_select_weight); |
| 821 | |
| 822 | softap_nf_weight_local = |
| 823 | ACS_WEIGHT_CFG_TO_LOCAL(sap_ctx->auto_channel_select_weight, |
| 824 | softap_nf_weight_cfg); |
| 825 | |
| 826 | if (channel_stat == NULL || channel_stat->channelfreq == 0) { |
Srinivas Girigowda | 80213e5 | 2018-01-23 14:51:33 -0800 | [diff] [blame] | 827 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_DEBUG, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 828 | "In %s, sanity check failed return max weight", |
| 829 | __func__); |
| 830 | return softap_nf_weight_local; |
| 831 | } |
| 832 | |
| 833 | noise_floor_weight = (channel_stat->noise_floor == 0) ? 0 : |
| 834 | (ACS_WEIGHT_COMPUTE( |
| 835 | sap_ctx->auto_channel_select_weight, |
| 836 | softap_nf_weight_cfg, |
| 837 | channel_stat->noise_floor - |
| 838 | SOFTAP_MIN_NF, |
| 839 | SOFTAP_MAX_NF - SOFTAP_MIN_NF)); |
| 840 | |
| 841 | if (noise_floor_weight > softap_nf_weight_local) |
| 842 | noise_floor_weight = softap_nf_weight_local; |
| 843 | else if (noise_floor_weight < 0) |
| 844 | noise_floor_weight = 0; |
| 845 | |
| 846 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
| 847 | "In %s, nf=%d, nfwc=%d, nfwl=%d, nfw=%d", |
| 848 | __func__, channel_stat->noise_floor, |
| 849 | softap_nf_weight_cfg, softap_nf_weight_local, |
| 850 | noise_floor_weight); |
| 851 | |
| 852 | return noise_floor_weight; |
| 853 | } |
| 854 | |
| 855 | /** |
| 856 | * sap_weight_channel_free() - compute channel free weight |
| 857 | * @sap_ctx: sap context |
| 858 | * @chn_stat: Pointer to chan status info |
| 859 | * |
| 860 | * Return: channel free weight |
| 861 | */ |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 862 | static uint32_t sap_weight_channel_free(struct sap_context *sap_ctx, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 863 | struct lim_channel_status |
| 864 | *channel_stat) |
| 865 | { |
| 866 | uint32_t channel_free_weight; |
| 867 | uint8_t softap_channel_free_weight_cfg; |
| 868 | uint8_t softap_channel_free_weight_local; |
| 869 | uint32_t rx_clear_count = 0; |
| 870 | uint32_t cycle_count = 0; |
| 871 | |
| 872 | softap_channel_free_weight_cfg = |
| 873 | ACS_WEIGHT_SOFTAP_CHANNEL_FREE_CFG |
| 874 | (sap_ctx->auto_channel_select_weight); |
| 875 | |
| 876 | softap_channel_free_weight_local = |
| 877 | ACS_WEIGHT_CFG_TO_LOCAL(sap_ctx->auto_channel_select_weight, |
| 878 | softap_channel_free_weight_cfg); |
| 879 | |
| 880 | if (channel_stat == NULL || channel_stat->channelfreq == 0) { |
Srinivas Girigowda | 80213e5 | 2018-01-23 14:51:33 -0800 | [diff] [blame] | 881 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_DEBUG, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 882 | "In %s, sanity check failed return max weight", |
| 883 | __func__); |
| 884 | return softap_channel_free_weight_local; |
| 885 | } |
| 886 | |
| 887 | rx_clear_count = channel_stat->rx_clear_count - |
| 888 | channel_stat->tx_frame_count - |
| 889 | channel_stat->rx_frame_count; |
| 890 | cycle_count = channel_stat->cycle_count; |
| 891 | |
| 892 | /* LSH 4, otherwise it is always 0. */ |
| 893 | channel_free_weight = (cycle_count == 0) ? 0 : |
| 894 | (ACS_WEIGHT_COMPUTE( |
| 895 | sap_ctx->auto_channel_select_weight, |
| 896 | softap_channel_free_weight_cfg, |
| 897 | ((rx_clear_count << 8) + |
| 898 | (cycle_count >> 1))/cycle_count - |
| 899 | (SOFTAP_MIN_CHNFREE << 8), |
| 900 | (SOFTAP_MAX_CHNFREE - |
| 901 | SOFTAP_MIN_CHNFREE) << 8)); |
| 902 | |
| 903 | if (channel_free_weight > softap_channel_free_weight_local) |
| 904 | channel_free_weight = softap_channel_free_weight_local; |
| 905 | |
| 906 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
| 907 | "In %s, rcc=%d, cc=%d, tc=%d, rc=%d, cfwc=%d, cfwl=%d, cfw=%d", |
| 908 | __func__, rx_clear_count, cycle_count, |
| 909 | channel_stat->tx_frame_count, |
| 910 | channel_stat->rx_frame_count, |
| 911 | softap_channel_free_weight_cfg, |
| 912 | softap_channel_free_weight_local, |
| 913 | channel_free_weight); |
| 914 | |
| 915 | return channel_free_weight; |
| 916 | } |
| 917 | |
| 918 | /** |
| 919 | * sap_weight_channel_txpwr_range() - compute channel tx power range weight |
| 920 | * @sap_ctx: sap context |
| 921 | * @chn_stat: Pointer to chan status info |
| 922 | * |
| 923 | * Return: tx power range weight |
| 924 | */ |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 925 | static uint32_t sap_weight_channel_txpwr_range(struct sap_context *sap_ctx, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 926 | struct lim_channel_status |
| 927 | *channel_stat) |
| 928 | { |
| 929 | uint32_t txpwr_weight_low_speed; |
| 930 | uint8_t softap_txpwr_range_weight_cfg; |
| 931 | uint8_t softap_txpwr_range_weight_local; |
| 932 | |
| 933 | softap_txpwr_range_weight_cfg = |
| 934 | ACS_WEIGHT_SOFTAP_TX_POWER_RANGE_CFG |
| 935 | (sap_ctx->auto_channel_select_weight); |
| 936 | |
| 937 | softap_txpwr_range_weight_local = |
| 938 | ACS_WEIGHT_CFG_TO_LOCAL(sap_ctx->auto_channel_select_weight, |
| 939 | softap_txpwr_range_weight_cfg); |
| 940 | |
| 941 | if (channel_stat == NULL || channel_stat->channelfreq == 0) { |
Srinivas Girigowda | 80213e5 | 2018-01-23 14:51:33 -0800 | [diff] [blame] | 942 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_DEBUG, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 943 | "In %s, sanity check failed return max weight", |
| 944 | __func__); |
| 945 | return softap_txpwr_range_weight_local; |
| 946 | } |
| 947 | |
| 948 | txpwr_weight_low_speed = (channel_stat->chan_tx_pwr_range == 0) ? 0 : |
| 949 | (ACS_WEIGHT_COMPUTE( |
| 950 | sap_ctx->auto_channel_select_weight, |
| 951 | softap_txpwr_range_weight_cfg, |
| 952 | SOFTAP_MAX_TXPWR - |
| 953 | channel_stat->chan_tx_pwr_range, |
| 954 | SOFTAP_MAX_TXPWR - SOFTAP_MIN_TXPWR)); |
| 955 | |
| 956 | if (txpwr_weight_low_speed > softap_txpwr_range_weight_local) |
| 957 | txpwr_weight_low_speed = softap_txpwr_range_weight_local; |
| 958 | |
| 959 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
| 960 | "In %s, tpr=%d, tprwc=%d, tprwl=%d, tprw=%d", |
| 961 | __func__, channel_stat->chan_tx_pwr_range, |
| 962 | softap_txpwr_range_weight_cfg, |
| 963 | softap_txpwr_range_weight_local, |
| 964 | txpwr_weight_low_speed); |
| 965 | |
| 966 | return txpwr_weight_low_speed; |
| 967 | } |
| 968 | |
| 969 | /** |
| 970 | * sap_weight_channel_txpwr_tput() - compute channel tx power |
| 971 | * throughput weight |
| 972 | * @sap_ctx: sap context |
| 973 | * @chn_stat: Pointer to chan status info |
| 974 | * |
| 975 | * Return: tx power throughput weight |
| 976 | */ |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 977 | static uint32_t sap_weight_channel_txpwr_tput(struct sap_context *sap_ctx, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 978 | struct lim_channel_status |
| 979 | *channel_stat) |
| 980 | { |
| 981 | uint32_t txpwr_weight_high_speed; |
| 982 | uint8_t softap_txpwr_tput_weight_cfg; |
| 983 | uint8_t softap_txpwr_tput_weight_local; |
| 984 | |
| 985 | softap_txpwr_tput_weight_cfg = |
| 986 | ACS_WEIGHT_SOFTAP_TX_POWER_THROUGHPUT_CFG |
| 987 | (sap_ctx->auto_channel_select_weight); |
| 988 | |
| 989 | softap_txpwr_tput_weight_local = |
| 990 | ACS_WEIGHT_CFG_TO_LOCAL(sap_ctx->auto_channel_select_weight, |
| 991 | softap_txpwr_tput_weight_cfg); |
| 992 | |
| 993 | if (channel_stat == NULL || channel_stat->channelfreq == 0) { |
Srinivas Girigowda | 80213e5 | 2018-01-23 14:51:33 -0800 | [diff] [blame] | 994 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_DEBUG, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 995 | "In %s, sanity check failed return max weight", |
| 996 | __func__); |
| 997 | return softap_txpwr_tput_weight_local; |
| 998 | } |
| 999 | |
| 1000 | txpwr_weight_high_speed = (channel_stat->chan_tx_pwr_throughput == 0) |
| 1001 | ? 0 : (ACS_WEIGHT_COMPUTE( |
| 1002 | sap_ctx->auto_channel_select_weight, |
| 1003 | softap_txpwr_tput_weight_cfg, |
| 1004 | SOFTAP_MAX_TXPWR - |
| 1005 | channel_stat->chan_tx_pwr_throughput, |
| 1006 | SOFTAP_MAX_TXPWR - SOFTAP_MIN_TXPWR)); |
| 1007 | |
| 1008 | if (txpwr_weight_high_speed > softap_txpwr_tput_weight_local) |
| 1009 | txpwr_weight_high_speed = softap_txpwr_tput_weight_local; |
| 1010 | |
| 1011 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
| 1012 | "In %s, tpt=%d, tptwc=%d, tptwl=%d, tptw=%d", |
| 1013 | __func__, channel_stat->chan_tx_pwr_throughput, |
| 1014 | softap_txpwr_tput_weight_cfg, |
| 1015 | softap_txpwr_tput_weight_local, |
| 1016 | txpwr_weight_high_speed); |
| 1017 | |
| 1018 | return txpwr_weight_high_speed; |
| 1019 | } |
| 1020 | |
| 1021 | /** |
| 1022 | * sap_weight_channel_status() - compute chan status weight |
| 1023 | * @sap_ctx: sap context |
| 1024 | * @chn_stat: Pointer to chan status info |
| 1025 | * |
| 1026 | * Return: chan status weight |
| 1027 | */ |
| 1028 | static |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 1029 | uint32_t sap_weight_channel_status(struct sap_context *sap_ctx, |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 1030 | struct lim_channel_status *channel_stat) |
| 1031 | { |
| 1032 | return sap_weight_channel_noise_floor(sap_ctx, channel_stat) + |
| 1033 | sap_weight_channel_free(sap_ctx, channel_stat) + |
| 1034 | sap_weight_channel_txpwr_range(sap_ctx, channel_stat) + |
| 1035 | sap_weight_channel_txpwr_tput(sap_ctx, channel_stat); |
| 1036 | } |
| 1037 | |
| 1038 | /** |
Yeshwanth Sriram Guntuka | 273889e | 2018-02-16 17:11:46 +0530 | [diff] [blame] | 1039 | * sap_check_channels_same_band() - Check if two channels belong to same band |
| 1040 | * @ch_num1: channel number |
| 1041 | * @ch_num2: channel number |
| 1042 | * |
| 1043 | * Return: true if both channels belong to same band else false |
| 1044 | */ |
| 1045 | static bool sap_check_channels_same_band(uint16_t ch_num1, uint16_t ch_num2) |
| 1046 | { |
| 1047 | if ((ch_num1 <= SIR_11B_CHANNEL_END && |
| 1048 | ch_num2 <= SIR_11B_CHANNEL_END) || |
| 1049 | (ch_num1 >= SIR_11A_CHANNEL_BEGIN && |
| 1050 | ch_num2 >= SIR_11A_CHANNEL_BEGIN)) |
| 1051 | return true; |
| 1052 | |
| 1053 | return false; |
| 1054 | } |
| 1055 | |
| 1056 | /** |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1057 | * sap_update_rssi_bsscount() - updates bss count and rssi effect. |
| 1058 | * |
| 1059 | * @pSpectCh: Channel Information |
| 1060 | * @offset: Channel Offset |
| 1061 | * @sap_24g: Channel is in 2.4G or 5G |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1062 | * @spectch_start: the start of spect ch array |
| 1063 | * @spectch_end: the end of spect ch array |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1064 | * |
| 1065 | * sap_update_rssi_bsscount updates bss count and rssi effect based |
| 1066 | * on the channel offset. |
| 1067 | * |
| 1068 | * Return: None. |
| 1069 | */ |
| 1070 | |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1071 | static void sap_update_rssi_bsscount(tSapSpectChInfo *pSpectCh, int32_t offset, |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1072 | bool sap_24g, tSapSpectChInfo *spectch_start, |
| 1073 | tSapSpectChInfo *spectch_end) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1074 | { |
| 1075 | tSapSpectChInfo *pExtSpectCh = NULL; |
| 1076 | int32_t rssi, rsssi_effect; |
| 1077 | |
| 1078 | pExtSpectCh = (pSpectCh + offset); |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1079 | if (pExtSpectCh != NULL && |
| 1080 | pExtSpectCh >= spectch_start && |
| 1081 | pExtSpectCh < spectch_end) { |
Yeshwanth Sriram Guntuka | 273889e | 2018-02-16 17:11:46 +0530 | [diff] [blame] | 1082 | if (!sap_check_channels_same_band(pSpectCh->chNum, |
| 1083 | pExtSpectCh->chNum)) |
| 1084 | return; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1085 | ++pExtSpectCh->bssCount; |
| 1086 | switch (offset) { |
| 1087 | case -1: |
| 1088 | case 1: |
| 1089 | rsssi_effect = sap_24g ? |
| 1090 | SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY : |
| 1091 | SAP_SUBBAND1_RSSI_EFFECT_PRIMARY; |
| 1092 | break; |
| 1093 | case -2: |
| 1094 | case 2: |
| 1095 | rsssi_effect = sap_24g ? |
| 1096 | SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY : |
| 1097 | SAP_SUBBAND2_RSSI_EFFECT_PRIMARY; |
| 1098 | break; |
| 1099 | case -3: |
| 1100 | case 3: |
| 1101 | rsssi_effect = sap_24g ? |
| 1102 | SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY : |
| 1103 | SAP_SUBBAND3_RSSI_EFFECT_PRIMARY; |
| 1104 | break; |
| 1105 | case -4: |
| 1106 | case 4: |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1107 | rsssi_effect = sap_24g ? |
| 1108 | SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY : |
| 1109 | SAP_SUBBAND4_RSSI_EFFECT_PRIMARY; |
| 1110 | break; |
| 1111 | case -5: |
| 1112 | case 5: |
| 1113 | rsssi_effect = SAP_SUBBAND5_RSSI_EFFECT_PRIMARY; |
| 1114 | break; |
| 1115 | case -6: |
| 1116 | case 6: |
| 1117 | rsssi_effect = SAP_SUBBAND6_RSSI_EFFECT_PRIMARY; |
| 1118 | break; |
| 1119 | case -7: |
| 1120 | case 7: |
| 1121 | rsssi_effect = SAP_SUBBAND7_RSSI_EFFECT_PRIMARY; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1122 | break; |
| 1123 | default: |
| 1124 | rsssi_effect = 0; |
| 1125 | break; |
| 1126 | } |
| 1127 | |
| 1128 | rssi = pSpectCh->rssiAgr + rsssi_effect; |
| 1129 | if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi)) |
| 1130 | pExtSpectCh->rssiAgr = rssi; |
| 1131 | if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI) |
| 1132 | pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI; |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | /** |
| 1137 | * sap_upd_chan_spec_params() - sap_upd_chan_spec_params |
| 1138 | * updates channel parameters obtained from Beacon |
| 1139 | * @pBeaconStruct Beacon strucutre populated by parse_beacon function |
| 1140 | * @channelWidth Channel width |
| 1141 | * @secondaryChannelOffset Secondary Channel Offset |
| 1142 | * @vhtSupport If channel supports VHT |
| 1143 | * @centerFreq Central frequency for the given channel. |
| 1144 | * |
| 1145 | * sap_upd_chan_spec_params updates the spectrum channels based on the |
| 1146 | * pBeaconStruct obtained from Beacon IE |
| 1147 | * |
| 1148 | * Return: NA. |
| 1149 | */ |
| 1150 | |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1151 | static void sap_upd_chan_spec_params(tSirProbeRespBeacon *pBeaconStruct, |
| 1152 | uint16_t *channelWidth, |
| 1153 | uint16_t *secondaryChannelOffset, |
| 1154 | uint16_t *vhtSupport, |
| 1155 | uint16_t *centerFreq, |
| 1156 | uint16_t *centerFreq_2) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1157 | { |
| 1158 | if (NULL == pBeaconStruct) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1159 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1160 | FL("pBeaconStruct is NULL")); |
| 1161 | return; |
| 1162 | } |
| 1163 | |
| 1164 | if (pBeaconStruct->HTCaps.present && pBeaconStruct->HTInfo.present) { |
| 1165 | *channelWidth = pBeaconStruct->HTCaps.supportedChannelWidthSet; |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1166 | *secondaryChannelOffset = |
| 1167 | pBeaconStruct->HTInfo.secondaryChannelOffset; |
| 1168 | if (!pBeaconStruct->VHTOperation.present) |
| 1169 | return; |
| 1170 | *vhtSupport = pBeaconStruct->VHTOperation.present; |
| 1171 | if (pBeaconStruct->VHTOperation.chanWidth) { |
| 1172 | *centerFreq = |
| 1173 | pBeaconStruct->VHTOperation.chanCenterFreqSeg1; |
| 1174 | *centerFreq_2 = |
| 1175 | pBeaconStruct->VHTOperation.chanCenterFreqSeg2; |
| 1176 | /* |
| 1177 | * LHS follows tSirMacHTChannelWidth, while RHS follows |
| 1178 | * WNI_CFG_VHT_CHANNEL_WIDTH_X format hence following |
| 1179 | * adjustment |
| 1180 | */ |
| 1181 | *channelWidth = |
| 1182 | pBeaconStruct->VHTOperation.chanWidth + 1; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1183 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1184 | } |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | /** |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1189 | * sap_update_rssi_bsscount_vht_5G() - updates bss count and rssi effect. |
| 1190 | * |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1191 | * @spect_ch: Channel Information |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1192 | * @offset: Channel Offset |
| 1193 | * @num_ch: no.of channels |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1194 | * @spectch_start: the start of spect ch array |
| 1195 | * @spectch_end: the end of spect ch array |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1196 | * |
| 1197 | * sap_update_rssi_bsscount_vht_5G updates bss count and rssi effect based |
| 1198 | * on the channel offset. |
| 1199 | * |
| 1200 | * Return: None. |
| 1201 | */ |
| 1202 | |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1203 | static void sap_update_rssi_bsscount_vht_5G(tSapSpectChInfo *spect_ch, |
| 1204 | int32_t offset, |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1205 | uint16_t num_ch, |
| 1206 | tSapSpectChInfo *spectch_start, |
| 1207 | tSapSpectChInfo *spectch_end) |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1208 | { |
| 1209 | int32_t ch_offset; |
| 1210 | uint16_t i, cnt; |
| 1211 | |
| 1212 | if (!offset) |
| 1213 | return; |
| 1214 | if (offset > 0) |
| 1215 | cnt = num_ch; |
| 1216 | else |
| 1217 | cnt = num_ch + 1; |
| 1218 | for (i = 0; i < cnt; i++) { |
| 1219 | ch_offset = offset + i; |
| 1220 | if (ch_offset == 0) |
| 1221 | continue; |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1222 | sap_update_rssi_bsscount(spect_ch, ch_offset, false, |
| 1223 | spectch_start, spectch_end); |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1224 | } |
| 1225 | } |
| 1226 | /** |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1227 | * sap_interference_rssi_count_5G() - sap_interference_rssi_count |
| 1228 | * considers the Adjacent channel rssi and |
| 1229 | * data count(here number of BSS observed) |
| 1230 | * @spect_ch: Channel Information |
| 1231 | * @chan_width: Channel width parsed from beacon IE |
| 1232 | * @sec_chan_offset: Secondary Channel Offset |
| 1233 | * @center_freq: Central frequency for the given channel. |
| 1234 | * @channel_id: channel_id |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1235 | * @spectch_start: the start of spect ch array |
| 1236 | * @spectch_end: the end of spect ch array |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1237 | * |
| 1238 | * sap_interference_rssi_count_5G considers the Adjacent channel rssi |
| 1239 | * and data count(here number of BSS observed) |
| 1240 | * |
| 1241 | * Return: NA. |
| 1242 | */ |
| 1243 | |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1244 | static void sap_interference_rssi_count_5G(tSapSpectChInfo *spect_ch, |
| 1245 | uint16_t chan_width, |
| 1246 | uint16_t sec_chan_offset, |
| 1247 | uint16_t center_freq, |
| 1248 | uint16_t center_freq_2, |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1249 | uint8_t channel_id, |
| 1250 | tSapSpectChInfo *spectch_start, |
| 1251 | tSapSpectChInfo *spectch_end) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1252 | { |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1253 | uint16_t num_ch; |
| 1254 | int32_t offset = 0; |
Srinivas Girigowda | 4d65ebe | 2017-10-13 21:41:42 -0700 | [diff] [blame] | 1255 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1256 | if (NULL == spect_ch) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1257 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1258 | FL("spect_ch is NULL")); |
| 1259 | return; |
| 1260 | } |
| 1261 | |
| 1262 | /* Updating the received ChannelWidth */ |
| 1263 | if (spect_ch->channelWidth != chan_width) |
| 1264 | spect_ch->channelWidth = chan_width; |
| 1265 | /* If received ChannelWidth is other than HT20, |
| 1266 | * we need to update the extension channel Params as well |
| 1267 | * chan_width == 0, HT20 |
| 1268 | * chan_width == 1, HT40 |
| 1269 | * chan_width == 2, VHT80 |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1270 | * chan_width == 3, VHT160 |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1271 | */ |
| 1272 | |
| 1273 | switch (spect_ch->channelWidth) { |
| 1274 | case eHT_CHANNEL_WIDTH_40MHZ: /* HT40 */ |
| 1275 | switch (sec_chan_offset) { |
| 1276 | /* Above the Primary Channel */ |
| 1277 | case PHY_DOUBLE_CHANNEL_LOW_PRIMARY: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1278 | sap_update_rssi_bsscount(spect_ch, 1, false, |
| 1279 | spectch_start, spectch_end); |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1280 | return; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1281 | |
| 1282 | /* Below the Primary channel */ |
| 1283 | case PHY_DOUBLE_CHANNEL_HIGH_PRIMARY: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1284 | sap_update_rssi_bsscount(spect_ch, -1, false, |
| 1285 | spectch_start, spectch_end); |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1286 | return; |
| 1287 | } |
| 1288 | return; |
| 1289 | case eHT_CHANNEL_WIDTH_80MHZ: /* VHT80 */ |
| 1290 | num_ch = 3; |
| 1291 | if ((center_freq - channel_id) == 6) { |
| 1292 | offset = 1; |
| 1293 | } else if ((center_freq - channel_id) == 2) { |
| 1294 | offset = -1; |
| 1295 | } else if ((center_freq - channel_id) == -2) { |
| 1296 | offset = -2; |
| 1297 | } else if ((center_freq - channel_id) == -6) { |
| 1298 | offset = -3; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1299 | } |
| 1300 | break; |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1301 | case eHT_CHANNEL_WIDTH_160MHZ: /* VHT160 */ |
| 1302 | num_ch = 7; |
| 1303 | if ((center_freq - channel_id) == 14) |
| 1304 | offset = 1; |
| 1305 | else if ((center_freq - channel_id) == 10) |
| 1306 | offset = -1; |
| 1307 | else if ((center_freq - channel_id) == 6) |
| 1308 | offset = -2; |
| 1309 | else if ((center_freq - channel_id) == 2) |
| 1310 | offset = -3; |
| 1311 | else if ((center_freq - channel_id) == -2) |
| 1312 | offset = -4; |
| 1313 | else if ((center_freq - channel_id) == -6) |
| 1314 | offset = -5; |
| 1315 | else if ((center_freq - channel_id) == -10) |
| 1316 | offset = -6; |
| 1317 | else if ((center_freq - channel_id) == -14) |
| 1318 | offset = -7; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1319 | break; |
| 1320 | default: |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1321 | return; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1322 | } |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1323 | sap_update_rssi_bsscount_vht_5G(spect_ch, offset, num_ch, |
| 1324 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | /** |
| 1328 | * sap_interference_rssi_count() - sap_interference_rssi_count |
| 1329 | * considers the Adjacent channel rssi |
| 1330 | * and data count(here number of BSS observed) |
| 1331 | * @spect_ch Channel Information |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1332 | * @spectch_start: the start of spect ch array |
| 1333 | * @spectch_end: the end of spect ch array |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1334 | * |
| 1335 | * sap_interference_rssi_count considers the Adjacent channel rssi |
| 1336 | * and data count(here number of BSS observed) |
| 1337 | * |
| 1338 | * Return: None. |
| 1339 | */ |
| 1340 | |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1341 | static void sap_interference_rssi_count(tSapSpectChInfo *spect_ch, |
| 1342 | tSapSpectChInfo *spectch_start, |
| 1343 | tSapSpectChInfo *spectch_end) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1344 | { |
| 1345 | if (NULL == spect_ch) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1346 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1347 | "%s: spect_ch is NULL", __func__); |
| 1348 | return; |
| 1349 | } |
| 1350 | |
| 1351 | switch (spect_ch->chNum) { |
| 1352 | case CHANNEL_1: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1353 | sap_update_rssi_bsscount(spect_ch, 1, true, |
| 1354 | spectch_start, spectch_end); |
| 1355 | sap_update_rssi_bsscount(spect_ch, 2, true, |
| 1356 | spectch_start, spectch_end); |
| 1357 | sap_update_rssi_bsscount(spect_ch, 3, true, |
| 1358 | spectch_start, spectch_end); |
| 1359 | sap_update_rssi_bsscount(spect_ch, 4, true, |
| 1360 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1361 | break; |
| 1362 | |
| 1363 | case CHANNEL_2: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1364 | sap_update_rssi_bsscount(spect_ch, -1, true, |
| 1365 | spectch_start, spectch_end); |
| 1366 | sap_update_rssi_bsscount(spect_ch, 1, true, |
| 1367 | spectch_start, spectch_end); |
| 1368 | sap_update_rssi_bsscount(spect_ch, 2, true, |
| 1369 | spectch_start, spectch_end); |
| 1370 | sap_update_rssi_bsscount(spect_ch, 3, true, |
| 1371 | spectch_start, spectch_end); |
| 1372 | sap_update_rssi_bsscount(spect_ch, 4, true, |
| 1373 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1374 | break; |
| 1375 | case CHANNEL_3: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1376 | sap_update_rssi_bsscount(spect_ch, -2, true, |
| 1377 | spectch_start, spectch_end); |
| 1378 | sap_update_rssi_bsscount(spect_ch, -1, true, |
| 1379 | spectch_start, spectch_end); |
| 1380 | sap_update_rssi_bsscount(spect_ch, 1, true, |
| 1381 | spectch_start, spectch_end); |
| 1382 | sap_update_rssi_bsscount(spect_ch, 2, true, |
| 1383 | spectch_start, spectch_end); |
| 1384 | sap_update_rssi_bsscount(spect_ch, 3, true, |
| 1385 | spectch_start, spectch_end); |
| 1386 | sap_update_rssi_bsscount(spect_ch, 4, true, |
| 1387 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1388 | break; |
| 1389 | case CHANNEL_4: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1390 | sap_update_rssi_bsscount(spect_ch, -3, true, |
| 1391 | spectch_start, spectch_end); |
| 1392 | sap_update_rssi_bsscount(spect_ch, -2, true, |
| 1393 | spectch_start, spectch_end); |
| 1394 | sap_update_rssi_bsscount(spect_ch, -1, true, |
| 1395 | spectch_start, spectch_end); |
| 1396 | sap_update_rssi_bsscount(spect_ch, 1, true, |
| 1397 | spectch_start, spectch_end); |
| 1398 | sap_update_rssi_bsscount(spect_ch, 2, true, |
| 1399 | spectch_start, spectch_end); |
| 1400 | sap_update_rssi_bsscount(spect_ch, 3, true, |
| 1401 | spectch_start, spectch_end); |
| 1402 | sap_update_rssi_bsscount(spect_ch, 4, true, |
| 1403 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1404 | break; |
| 1405 | |
| 1406 | case CHANNEL_5: |
| 1407 | case CHANNEL_6: |
| 1408 | case CHANNEL_7: |
| 1409 | case CHANNEL_8: |
| 1410 | case CHANNEL_9: |
| 1411 | case CHANNEL_10: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1412 | sap_update_rssi_bsscount(spect_ch, -4, true, |
| 1413 | spectch_start, spectch_end); |
| 1414 | sap_update_rssi_bsscount(spect_ch, -3, true, |
| 1415 | spectch_start, spectch_end); |
| 1416 | sap_update_rssi_bsscount(spect_ch, -2, true, |
| 1417 | spectch_start, spectch_end); |
| 1418 | sap_update_rssi_bsscount(spect_ch, -1, true, |
| 1419 | spectch_start, spectch_end); |
| 1420 | sap_update_rssi_bsscount(spect_ch, 1, true, |
| 1421 | spectch_start, spectch_end); |
| 1422 | sap_update_rssi_bsscount(spect_ch, 2, true, |
| 1423 | spectch_start, spectch_end); |
| 1424 | sap_update_rssi_bsscount(spect_ch, 3, true, |
| 1425 | spectch_start, spectch_end); |
| 1426 | sap_update_rssi_bsscount(spect_ch, 4, true, |
| 1427 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1428 | break; |
| 1429 | |
| 1430 | case CHANNEL_11: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1431 | sap_update_rssi_bsscount(spect_ch, -4, true, |
| 1432 | spectch_start, spectch_end); |
| 1433 | sap_update_rssi_bsscount(spect_ch, -3, true, |
| 1434 | spectch_start, spectch_end); |
| 1435 | sap_update_rssi_bsscount(spect_ch, -2, true, |
| 1436 | spectch_start, spectch_end); |
| 1437 | sap_update_rssi_bsscount(spect_ch, -1, true, |
| 1438 | spectch_start, spectch_end); |
| 1439 | sap_update_rssi_bsscount(spect_ch, 1, true, |
| 1440 | spectch_start, spectch_end); |
| 1441 | sap_update_rssi_bsscount(spect_ch, 2, true, |
| 1442 | spectch_start, spectch_end); |
| 1443 | sap_update_rssi_bsscount(spect_ch, 3, true, |
| 1444 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1445 | break; |
| 1446 | |
| 1447 | case CHANNEL_12: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1448 | sap_update_rssi_bsscount(spect_ch, -4, true, |
| 1449 | spectch_start, spectch_end); |
| 1450 | sap_update_rssi_bsscount(spect_ch, -3, true, |
| 1451 | spectch_start, spectch_end); |
| 1452 | sap_update_rssi_bsscount(spect_ch, -2, true, |
| 1453 | spectch_start, spectch_end); |
| 1454 | sap_update_rssi_bsscount(spect_ch, -1, true, |
| 1455 | spectch_start, spectch_end); |
| 1456 | sap_update_rssi_bsscount(spect_ch, 1, true, |
| 1457 | spectch_start, spectch_end); |
| 1458 | sap_update_rssi_bsscount(spect_ch, 2, true, |
| 1459 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1460 | break; |
| 1461 | |
| 1462 | case CHANNEL_13: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1463 | sap_update_rssi_bsscount(spect_ch, -4, true, |
| 1464 | spectch_start, spectch_end); |
| 1465 | sap_update_rssi_bsscount(spect_ch, -3, true, |
| 1466 | spectch_start, spectch_end); |
| 1467 | sap_update_rssi_bsscount(spect_ch, -2, true, |
| 1468 | spectch_start, spectch_end); |
| 1469 | sap_update_rssi_bsscount(spect_ch, -1, true, |
| 1470 | spectch_start, spectch_end); |
| 1471 | sap_update_rssi_bsscount(spect_ch, 1, true, |
| 1472 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1473 | break; |
| 1474 | |
| 1475 | case CHANNEL_14: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1476 | sap_update_rssi_bsscount(spect_ch, -4, true, |
| 1477 | spectch_start, spectch_end); |
| 1478 | sap_update_rssi_bsscount(spect_ch, -3, true, |
| 1479 | spectch_start, spectch_end); |
| 1480 | sap_update_rssi_bsscount(spect_ch, -2, true, |
| 1481 | spectch_start, spectch_end); |
| 1482 | sap_update_rssi_bsscount(spect_ch, -1, true, |
| 1483 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1484 | break; |
| 1485 | |
| 1486 | default: |
| 1487 | break; |
| 1488 | } |
| 1489 | } |
| 1490 | |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1491 | /** |
| 1492 | * ch_in_pcl() - Is channel in the Preferred Channel List (PCL) |
| 1493 | * @sap_ctx: SAP context which contains the current PCL |
| 1494 | * @channel: Input channel number to be checked |
| 1495 | * |
| 1496 | * Check if a channel is in the preferred channel list |
| 1497 | * |
| 1498 | * Return: |
| 1499 | * true: channel is in PCL, |
| 1500 | * false: channel is not in PCL |
| 1501 | */ |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 1502 | static bool ch_in_pcl(struct sap_context *sap_ctx, uint8_t channel) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1503 | { |
| 1504 | uint32_t i; |
| 1505 | |
| 1506 | for (i = 0; i < sap_ctx->acs_cfg->pcl_ch_count; i++) { |
| 1507 | if (channel == sap_ctx->acs_cfg->pcl_channels[i]) |
| 1508 | return true; |
| 1509 | } |
| 1510 | |
| 1511 | return false; |
| 1512 | } |
| 1513 | |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1514 | /** |
| 1515 | * sap_compute_spect_weight() - Compute spectrum weight |
| 1516 | * @pSpectInfoParams: Pointer to the tSpectInfoParams structure |
| 1517 | * @halHandle: Pointer to HAL handle |
| 1518 | * @pResult: Pointer to tScanResultHandle |
| 1519 | * @sap_ctx: Context of the SAP |
| 1520 | * |
| 1521 | * Main function for computing the weight of each channel in the |
| 1522 | * spectrum based on the RSSI value of the BSSes on the channel |
| 1523 | * and number of BSS |
| 1524 | */ |
| 1525 | static void sap_compute_spect_weight(tSapChSelSpectInfo *pSpectInfoParams, |
| 1526 | tHalHandle halHandle, |
| 1527 | tScanResultHandle pResult, |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 1528 | struct sap_context *sap_ctx) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1529 | { |
| 1530 | int8_t rssi = 0; |
| 1531 | uint8_t chn_num = 0; |
| 1532 | uint8_t channel_id = 0; |
| 1533 | |
| 1534 | tCsrScanResultInfo *pScanResult; |
| 1535 | tSapSpectChInfo *pSpectCh = pSpectInfoParams->pSpectCh; |
| 1536 | uint32_t operatingBand; |
| 1537 | uint16_t channelWidth; |
| 1538 | uint16_t secondaryChannelOffset; |
| 1539 | uint16_t centerFreq; |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1540 | uint16_t centerFreq_2 = 0; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1541 | uint16_t vhtSupport; |
| 1542 | uint32_t ieLen = 0; |
| 1543 | tSirProbeRespBeacon *pBeaconStruct; |
| 1544 | tpAniSirGlobal pMac = (tpAniSirGlobal) halHandle; |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1545 | tSapSpectChInfo *spectch_start = pSpectInfoParams->pSpectCh; |
| 1546 | tSapSpectChInfo *spectch_end = pSpectInfoParams->pSpectCh + |
| 1547 | pSpectInfoParams->numSpectChans; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1548 | |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 1549 | pBeaconStruct = qdf_mem_malloc(sizeof(tSirProbeRespBeacon)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1550 | if (NULL == pBeaconStruct) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1551 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Kaushik, Sushant | ee3ed03 | 2016-08-04 16:40:46 +0530 | [diff] [blame] | 1552 | "Unable to allocate memory in sap_compute_spect_weight"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1553 | return; |
| 1554 | } |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1555 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1556 | "In %s, Computing spectral weight", __func__); |
| 1557 | |
| 1558 | /** |
| 1559 | * Soft AP specific channel weight calculation using DFS formula |
| 1560 | */ |
| 1561 | SET_ACS_BAND(operatingBand, sap_ctx); |
| 1562 | |
| 1563 | pScanResult = sme_scan_result_get_first(halHandle, pResult); |
| 1564 | |
| 1565 | while (pScanResult) { |
| 1566 | pSpectCh = pSpectInfoParams->pSpectCh; |
| 1567 | /* Defining the default values, so that any value will hold the default values */ |
| 1568 | channelWidth = eHT_CHANNEL_WIDTH_20MHZ; |
| 1569 | secondaryChannelOffset = PHY_SINGLE_CHANNEL_CENTERED; |
| 1570 | vhtSupport = 0; |
| 1571 | centerFreq = 0; |
| 1572 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1573 | |
Yingying Tang | 22facc1 | 2016-10-20 17:43:59 +0800 | [diff] [blame] | 1574 | ieLen = GET_IE_LEN_IN_BSS( |
| 1575 | pScanResult->BssDescriptor.length); |
| 1576 | qdf_mem_set((uint8_t *) pBeaconStruct, |
| 1577 | sizeof(tSirProbeRespBeacon), 0); |
| 1578 | |
| 1579 | |
| 1580 | if ((sir_parse_beacon_ie |
| 1581 | (pMac, pBeaconStruct, (uint8_t *) |
| 1582 | (pScanResult->BssDescriptor.ieFields), |
| 1583 | ieLen)) == eSIR_SUCCESS) |
| 1584 | sap_upd_chan_spec_params( |
| 1585 | pBeaconStruct, |
| 1586 | &channelWidth, |
| 1587 | &secondaryChannelOffset, |
| 1588 | &vhtSupport, ¢erFreq, |
| 1589 | ¢erFreq_2); |
| 1590 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1591 | /* Processing for each tCsrScanResultInfo in the tCsrScanResult DLink list */ |
| 1592 | for (chn_num = 0; chn_num < pSpectInfoParams->numSpectChans; |
| 1593 | chn_num++) { |
| 1594 | |
| 1595 | /* |
| 1596 | * if the Beacon has channel ID, use it other wise we will |
| 1597 | * rely on the channelIdSelf |
| 1598 | */ |
| 1599 | if (pScanResult->BssDescriptor.channelId == 0) |
| 1600 | channel_id = |
| 1601 | pScanResult->BssDescriptor.channelIdSelf; |
| 1602 | else |
| 1603 | channel_id = |
| 1604 | pScanResult->BssDescriptor.channelId; |
| 1605 | |
| 1606 | if (pSpectCh && (channel_id == pSpectCh->chNum)) { |
| 1607 | if (pSpectCh->rssiAgr < |
| 1608 | pScanResult->BssDescriptor.rssi) |
| 1609 | pSpectCh->rssiAgr = |
| 1610 | pScanResult->BssDescriptor.rssi; |
| 1611 | |
| 1612 | ++pSpectCh->bssCount; /* Increment the count of BSS */ |
| 1613 | |
| 1614 | /* |
| 1615 | * Connsidering the Extension Channel |
| 1616 | * only in a channels |
| 1617 | */ |
| 1618 | switch (operatingBand) { |
| 1619 | case eCSR_DOT11_MODE_11a: |
| 1620 | sap_interference_rssi_count_5G( |
| 1621 | pSpectCh, channelWidth, |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1622 | secondaryChannelOffset, |
| 1623 | centerFreq, |
| 1624 | centerFreq_2, |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1625 | channel_id, |
| 1626 | spectch_start, |
| 1627 | spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1628 | break; |
| 1629 | |
| 1630 | case eCSR_DOT11_MODE_11g: |
Liangwei Dong | 71ed650 | 2016-10-20 03:40:45 -0400 | [diff] [blame] | 1631 | sap_interference_rssi_count(pSpectCh, |
| 1632 | spectch_start, spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1633 | break; |
| 1634 | |
| 1635 | case eCSR_DOT11_MODE_abg: |
Himanshu Agarwal | 4f503b8 | 2018-03-19 12:10:45 +0530 | [diff] [blame^] | 1636 | if (pSpectCh->chNum >= |
| 1637 | SIR_11A_CHANNEL_BEGIN) |
| 1638 | sap_interference_rssi_count_5G( |
| 1639 | pSpectCh, channelWidth, |
| 1640 | secondaryChannelOffset, |
| 1641 | centerFreq, |
| 1642 | centerFreq_2, |
| 1643 | channel_id, |
| 1644 | spectch_start, |
| 1645 | spectch_end); |
| 1646 | else |
| 1647 | sap_interference_rssi_count( |
| 1648 | pSpectCh, |
| 1649 | spectch_start, |
| 1650 | spectch_end); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1651 | break; |
| 1652 | } |
| 1653 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1654 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 1655 | QDF_TRACE_LEVEL_INFO_HIGH, |
Jeff Johnson | a7c0ddb | 2017-09-18 08:14:12 -0700 | [diff] [blame] | 1656 | "In %s, bssdes.ch_self=%d, bssdes.ch_ID=%d, bssdes.rssi=%d, SpectCh.bssCount=%d, pScanResult=%pK, ChannelWidth %d, secondaryChanOffset %d, center frequency %d", |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1657 | __func__, |
| 1658 | pScanResult->BssDescriptor. |
| 1659 | channelIdSelf, |
| 1660 | pScanResult->BssDescriptor.channelId, |
| 1661 | pScanResult->BssDescriptor.rssi, |
| 1662 | pSpectCh->bssCount, pScanResult, |
| 1663 | pSpectCh->channelWidth, |
| 1664 | secondaryChannelOffset, centerFreq); |
| 1665 | pSpectCh++; |
| 1666 | break; |
| 1667 | } else { |
| 1668 | pSpectCh++; |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | pScanResult = sme_scan_result_get_next(halHandle, pResult); |
| 1673 | } |
| 1674 | |
| 1675 | /* Calculate the weights for all channels in the spectrum pSpectCh */ |
| 1676 | pSpectCh = pSpectInfoParams->pSpectCh; |
| 1677 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1678 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1679 | "In %s, Spectrum Channels Weight", __func__); |
| 1680 | |
| 1681 | for (chn_num = 0; chn_num < (pSpectInfoParams->numSpectChans); |
| 1682 | chn_num++) { |
| 1683 | |
| 1684 | /* |
| 1685 | rssi : Maximum received signal strength among all BSS on that channel |
| 1686 | bssCount : Number of BSS on that channel |
| 1687 | */ |
| 1688 | |
| 1689 | rssi = (int8_t) pSpectCh->rssiAgr; |
| 1690 | if (ch_in_pcl(sap_ctx, chn_num)) |
| 1691 | rssi -= PCL_RSSI_DISCOUNT; |
| 1692 | |
Himanshu Agarwal | fee2e36 | 2018-01-18 20:26:35 +0530 | [diff] [blame] | 1693 | if (pSpectCh->weight == SAP_ACS_WEIGHT_MAX) |
| 1694 | goto debug_info; |
| 1695 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1696 | pSpectCh->weight = |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 1697 | SAPDFS_NORMALISE_1000 * |
| 1698 | (sapweight_rssi_count(sap_ctx, rssi, |
| 1699 | pSpectCh->bssCount) + sap_weight_channel_status( |
| 1700 | sap_ctx, sap_get_channel_status(pMac, |
| 1701 | pSpectCh->chNum))); |
| 1702 | if (pSpectCh->weight > SAP_ACS_WEIGHT_MAX) |
| 1703 | pSpectCh->weight = SAP_ACS_WEIGHT_MAX; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1704 | pSpectCh->weight_copy = pSpectCh->weight; |
| 1705 | |
Himanshu Agarwal | fee2e36 | 2018-01-18 20:26:35 +0530 | [diff] [blame] | 1706 | debug_info: |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1707 | /* ------ Debug Info ------ */ |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1708 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1709 | "In %s, Chan=%d Weight= %d rssiAgr=%d bssCount=%d", |
| 1710 | __func__, pSpectCh->chNum, pSpectCh->weight, |
| 1711 | pSpectCh->rssiAgr, pSpectCh->bssCount); |
| 1712 | /* ------ Debug Info ------ */ |
| 1713 | pSpectCh++; |
| 1714 | } |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 1715 | sap_clear_channel_status(pMac); |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 1716 | qdf_mem_free(pBeaconStruct); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | /*========================================================================== |
| 1720 | FUNCTION sap_chan_sel_exit |
| 1721 | |
| 1722 | DESCRIPTION |
| 1723 | Exit function for free out the allocated memory, to be called |
| 1724 | at the end of the dfsSelectChannel function |
| 1725 | |
| 1726 | DEPENDENCIES |
| 1727 | NA. |
| 1728 | |
| 1729 | PARAMETERS |
| 1730 | |
| 1731 | IN |
| 1732 | pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure |
| 1733 | |
| 1734 | RETURN VALUE |
| 1735 | void : NULL |
| 1736 | |
| 1737 | SIDE EFFECTS |
| 1738 | ============================================================================*/ |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1739 | static void sap_chan_sel_exit(tSapChSelSpectInfo *pSpectInfoParams) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1740 | { |
| 1741 | /* Free all the allocated memory */ |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 1742 | qdf_mem_free(pSpectInfoParams->pSpectCh); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | /*========================================================================== |
| 1746 | FUNCTION sap_sort_chl_weight |
| 1747 | |
| 1748 | DESCRIPTION |
| 1749 | Funtion to sort the channels with the least weight first for 20MHz channels |
| 1750 | |
| 1751 | DEPENDENCIES |
| 1752 | NA. |
| 1753 | |
| 1754 | PARAMETERS |
| 1755 | |
| 1756 | IN |
| 1757 | pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure |
| 1758 | |
| 1759 | RETURN VALUE |
| 1760 | void : NULL |
| 1761 | |
| 1762 | SIDE EFFECTS |
| 1763 | ============================================================================*/ |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1764 | static void sap_sort_chl_weight(tSapChSelSpectInfo *pSpectInfoParams) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1765 | { |
| 1766 | tSapSpectChInfo temp; |
| 1767 | |
| 1768 | tSapSpectChInfo *pSpectCh = NULL; |
| 1769 | uint32_t i = 0, j = 0, minWeightIndex = 0; |
| 1770 | |
| 1771 | pSpectCh = pSpectInfoParams->pSpectCh; |
| 1772 | for (i = 0; i < pSpectInfoParams->numSpectChans; i++) { |
| 1773 | minWeightIndex = i; |
| 1774 | for (j = i + 1; j < pSpectInfoParams->numSpectChans; j++) { |
| 1775 | if (pSpectCh[j].weight < |
| 1776 | pSpectCh[minWeightIndex].weight) { |
| 1777 | minWeightIndex = j; |
Yeshwanth Sriram Guntuka | 273889e | 2018-02-16 17:11:46 +0530 | [diff] [blame] | 1778 | } else if (pSpectCh[j].weight == |
| 1779 | pSpectCh[minWeightIndex].weight) { |
| 1780 | if (pSpectCh[j].bssCount < |
| 1781 | pSpectCh[minWeightIndex].bssCount) |
| 1782 | minWeightIndex = j; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1783 | } |
| 1784 | } |
| 1785 | if (minWeightIndex != i) { |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 1786 | qdf_mem_copy(&temp, &pSpectCh[minWeightIndex], |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1787 | sizeof(*pSpectCh)); |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 1788 | qdf_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1789 | sizeof(*pSpectCh)); |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 1790 | qdf_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1791 | } |
| 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | /** |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 1796 | * set_ht80_chl_bit() - to set availabe channel to ht80 channel bitmap |
| 1797 | * @channel_bitmap: Pointer to the chan_bonding_bitmap structure |
| 1798 | * @spect_info_params: Pointer to the tSapChSelSpectInfo structure |
| 1799 | * |
| 1800 | * Return: none |
| 1801 | */ |
| 1802 | static void set_ht80_chl_bit(chan_bonding_bitmap *channel_bitmap, |
| 1803 | tSapChSelSpectInfo *spec_info_params) |
| 1804 | { |
| 1805 | uint8_t i, j; |
| 1806 | tSapSpectChInfo *spec_info; |
| 1807 | int start_channel = 0; |
| 1808 | |
| 1809 | channel_bitmap->chanBondingSet[0].startChannel = |
| 1810 | acs_ht80_channels[0].chStartNum; |
| 1811 | channel_bitmap->chanBondingSet[1].startChannel = |
| 1812 | acs_ht80_channels[1].chStartNum; |
| 1813 | channel_bitmap->chanBondingSet[2].startChannel = |
| 1814 | acs_ht80_channels[2].chStartNum; |
| 1815 | channel_bitmap->chanBondingSet[3].startChannel = |
| 1816 | acs_ht80_channels[3].chStartNum; |
| 1817 | channel_bitmap->chanBondingSet[4].startChannel = |
| 1818 | acs_ht80_channels[4].chStartNum; |
| 1819 | channel_bitmap->chanBondingSet[5].startChannel = |
| 1820 | acs_ht80_channels[5].chStartNum; |
| 1821 | |
| 1822 | spec_info = spec_info_params->pSpectCh; |
| 1823 | for (j = 0; j < spec_info_params->numSpectChans; j++) { |
| 1824 | for (i = 0; i < MAX_80MHZ_BANDS; i++) { |
| 1825 | start_channel = |
| 1826 | channel_bitmap->chanBondingSet[i].startChannel; |
| 1827 | if (spec_info[j].chNum >= start_channel && |
| 1828 | (spec_info[j].chNum <= start_channel + 12)) { |
| 1829 | channel_bitmap->chanBondingSet[i].channelMap |= |
| 1830 | 1 << ((spec_info[j].chNum - |
| 1831 | start_channel)/4); |
| 1832 | break; |
| 1833 | } |
| 1834 | } |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | /** |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1839 | * sap_sort_chl_weight_ht80() - to sort the channels with the least weight |
| 1840 | * @pSpectInfoParams: Pointer to the tSapChSelSpectInfo structure |
| 1841 | * |
| 1842 | * Funtion to sort the channels with the least weight first for HT80 channels |
| 1843 | * |
| 1844 | * Return: none |
| 1845 | */ |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1846 | static void sap_sort_chl_weight_ht80(tSapChSelSpectInfo *pSpectInfoParams) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1847 | { |
| 1848 | uint8_t i, j, n; |
| 1849 | tSapSpectChInfo *pSpectInfo; |
| 1850 | uint8_t minIdx; |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 1851 | int start_channel = 0; |
| 1852 | chan_bonding_bitmap *channel_bitmap; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1853 | |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 1854 | channel_bitmap = qdf_mem_malloc(sizeof(chan_bonding_bitmap)); |
| 1855 | if (NULL == channel_bitmap) { |
| 1856 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_DEBUG, |
| 1857 | "%s: Failed to allocate memory", __func__); |
| 1858 | return; |
| 1859 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1860 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 1861 | /* for each HT80 channel, calculate the combined weight of the |
| 1862 | four 20MHz weight */ |
| 1863 | for (i = 0; i < ARRAY_SIZE(acs_ht80_channels); i++) { |
| 1864 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
| 1865 | if (pSpectInfo[j].chNum == |
| 1866 | acs_ht80_channels[i].chStartNum) |
| 1867 | break; |
| 1868 | } |
| 1869 | if (j == pSpectInfoParams->numSpectChans) |
| 1870 | continue; |
| 1871 | |
| 1872 | if (!(((pSpectInfo[j].chNum + 4) == pSpectInfo[j + 1].chNum) && |
| 1873 | ((pSpectInfo[j].chNum + 8) == |
| 1874 | pSpectInfo[j + 2].chNum) && |
| 1875 | ((pSpectInfo[j].chNum + 12) == |
| 1876 | pSpectInfo[j + 3].chNum))) { |
| 1877 | /* |
| 1878 | * some channels does not exist in pSectInfo array, |
| 1879 | * skip this channel and those in the same HT80 width |
| 1880 | */ |
| 1881 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 4; |
| 1882 | if ((pSpectInfo[j].chNum + 4) == |
| 1883 | pSpectInfo[j + 1].chNum) |
| 1884 | pSpectInfo[j + 1].weight = |
| 1885 | SAP_ACS_WEIGHT_MAX * 4; |
| 1886 | if ((pSpectInfo[j].chNum + 8) == |
| 1887 | pSpectInfo[j + 2].chNum) |
| 1888 | pSpectInfo[j + 2].weight = |
| 1889 | SAP_ACS_WEIGHT_MAX * 4; |
| 1890 | if ((pSpectInfo[j].chNum + 12) == |
| 1891 | pSpectInfo[j + 3].chNum) |
| 1892 | pSpectInfo[j + 3].weight = |
| 1893 | SAP_ACS_WEIGHT_MAX * 4; |
| 1894 | continue; |
| 1895 | } |
| 1896 | /*found the channel, add the 4 adjacent channels' weight */ |
| 1897 | acs_ht80_channels[i].weight = pSpectInfo[j].weight + |
| 1898 | pSpectInfo[j + 1].weight + pSpectInfo[j + 2].weight + |
| 1899 | pSpectInfo[j + 3].weight; |
| 1900 | /* find best channel among 4 channels as the primary channel */ |
| 1901 | if ((pSpectInfo[j].weight + pSpectInfo[j + 1].weight) < |
| 1902 | (pSpectInfo[j + 2].weight + pSpectInfo[j + 3].weight)) { |
| 1903 | /* lower 2 channels are better choice */ |
| 1904 | if (pSpectInfo[j].weight < pSpectInfo[j + 1].weight) |
| 1905 | minIdx = 0; |
| 1906 | else |
| 1907 | minIdx = 1; |
| 1908 | } else if (pSpectInfo[j + 2].weight <= |
| 1909 | pSpectInfo[j + 3].weight) { |
| 1910 | /* upper 2 channels are better choice */ |
| 1911 | minIdx = 2; |
| 1912 | } else { |
| 1913 | minIdx = 3; |
| 1914 | } |
| 1915 | |
| 1916 | /* |
| 1917 | * set all 4 channels to max value first, then reset the |
| 1918 | * best channel as the selected primary channel, update its |
| 1919 | * weightage with the combined weight value |
| 1920 | */ |
| 1921 | for (n = 0; n < 4; n++) |
| 1922 | pSpectInfo[j + n].weight = SAP_ACS_WEIGHT_MAX * 4; |
| 1923 | |
| 1924 | pSpectInfo[j + minIdx].weight = acs_ht80_channels[i].weight; |
| 1925 | } |
| 1926 | |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 1927 | /* |
| 1928 | * mark the weight of the channel that can't satisfy 80MHZ |
| 1929 | * as max value, so that it will be sorted to the bottom |
| 1930 | */ |
| 1931 | set_ht80_chl_bit(channel_bitmap, pSpectInfoParams); |
| 1932 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
| 1933 | for (i = 0; i < MAX_80MHZ_BANDS; i++) { |
| 1934 | start_channel = |
| 1935 | channel_bitmap->chanBondingSet[i].startChannel; |
| 1936 | if (pSpectInfo[j].chNum >= start_channel && |
| 1937 | (pSpectInfo[j].chNum <= |
| 1938 | start_channel + 12) && |
| 1939 | channel_bitmap->chanBondingSet[i].channelMap != |
| 1940 | SAP_80MHZ_MASK) |
| 1941 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 4; |
| 1942 | } |
| 1943 | } |
| 1944 | |
Himanshu Agarwal | 75e7441 | 2018-02-01 20:51:47 +0530 | [diff] [blame] | 1945 | /* |
| 1946 | * Assign max weight(SAP_ACS_WEIGHT_MAX * 4) to 2.4 Ghz channels |
| 1947 | * and channel 165 as they cannot be part of a 80Mhz channel bonding. |
| 1948 | */ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1949 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 1950 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
Himanshu Agarwal | 75e7441 | 2018-02-01 20:51:47 +0530 | [diff] [blame] | 1951 | if ((pSpectInfo[j].chNum >= WLAN_REG_CH_NUM(CHAN_ENUM_1) && |
| 1952 | pSpectInfo[j].chNum <= WLAN_REG_CH_NUM(CHAN_ENUM_14)) || |
| 1953 | (CHANNEL_165 == pSpectInfo[j].chNum)) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1954 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 4; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1955 | } |
| 1956 | |
Manishekar Chandrasekaran | 44e334f | 2016-05-30 16:42:50 +0530 | [diff] [blame] | 1957 | sap_sort_chl_weight(pSpectInfoParams); |
| 1958 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1959 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 1960 | for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1961 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1962 | FL("Channel=%d Weight= %d rssi=%d bssCount=%d"), |
| 1963 | pSpectInfo->chNum, pSpectInfo->weight, |
| 1964 | pSpectInfo->rssiAgr, pSpectInfo->bssCount); |
| 1965 | pSpectInfo++; |
| 1966 | } |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 1967 | qdf_mem_free(channel_bitmap); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | /** |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1971 | * sap_sort_chl_weight_vht160() - to sort the channels with the least weight |
| 1972 | * @pSpectInfoParams: Pointer to the tSapChSelSpectInfo structure |
| 1973 | * |
| 1974 | * Funtion to sort the channels with the least weight first for VHT160 channels |
| 1975 | * |
| 1976 | * Return: none |
| 1977 | */ |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 1978 | static void sap_sort_chl_weight_vht160(tSapChSelSpectInfo *pSpectInfoParams) |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 1979 | { |
| 1980 | uint8_t i, j, n, idx; |
| 1981 | tSapSpectChInfo *pSpectInfo; |
| 1982 | uint8_t minIdx; |
| 1983 | |
| 1984 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 1985 | /* for each VHT160 channel, calculate the combined weight of the |
| 1986 | 8 20MHz weight */ |
| 1987 | for (i = 0; i < ARRAY_SIZE(acs_vht160_channels); i++) { |
| 1988 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
| 1989 | if (pSpectInfo[j].chNum == |
| 1990 | acs_vht160_channels[i].chStartNum) |
| 1991 | break; |
| 1992 | } |
| 1993 | if (j == pSpectInfoParams->numSpectChans) |
| 1994 | continue; |
| 1995 | |
| 1996 | if (!(((pSpectInfo[j].chNum + 4) == pSpectInfo[j + 1].chNum) && |
| 1997 | ((pSpectInfo[j].chNum + 8) == |
| 1998 | pSpectInfo[j + 2].chNum) && |
| 1999 | ((pSpectInfo[j].chNum + 12) == |
| 2000 | pSpectInfo[j + 3].chNum) && |
| 2001 | ((pSpectInfo[j].chNum + 16) == |
| 2002 | pSpectInfo[j + 4].chNum) && |
| 2003 | ((pSpectInfo[j].chNum + 20) == |
| 2004 | pSpectInfo[j + 5].chNum) && |
| 2005 | ((pSpectInfo[j].chNum + 24) == |
| 2006 | pSpectInfo[j + 6].chNum) && |
| 2007 | ((pSpectInfo[j].chNum + 28) == |
| 2008 | pSpectInfo[j + 7].chNum))) { |
| 2009 | /* |
| 2010 | * some channels does not exist in pSectInfo array, |
| 2011 | * skip this channel and those in the same VHT160 width |
| 2012 | */ |
| 2013 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 8; |
| 2014 | if ((pSpectInfo[j].chNum + 4) == |
| 2015 | pSpectInfo[j + 1].chNum) |
| 2016 | pSpectInfo[j + 1].weight = |
| 2017 | SAP_ACS_WEIGHT_MAX * 8; |
| 2018 | if ((pSpectInfo[j].chNum + 8) == |
| 2019 | pSpectInfo[j + 2].chNum) |
| 2020 | pSpectInfo[j + 2].weight = |
| 2021 | SAP_ACS_WEIGHT_MAX * 8; |
| 2022 | if ((pSpectInfo[j].chNum + 12) == |
| 2023 | pSpectInfo[j + 3].chNum) |
| 2024 | pSpectInfo[j + 3].weight = |
| 2025 | SAP_ACS_WEIGHT_MAX * 8; |
| 2026 | if ((pSpectInfo[j].chNum + 16) == |
| 2027 | pSpectInfo[j + 4].chNum) |
| 2028 | pSpectInfo[j + 4].weight = |
| 2029 | SAP_ACS_WEIGHT_MAX * 8; |
| 2030 | if ((pSpectInfo[j].chNum + 20) == |
| 2031 | pSpectInfo[j + 5].chNum) |
| 2032 | pSpectInfo[j + 5].weight = |
| 2033 | SAP_ACS_WEIGHT_MAX * 8; |
| 2034 | if ((pSpectInfo[j].chNum + 24) == |
| 2035 | pSpectInfo[j + 6].chNum) |
| 2036 | pSpectInfo[j + 6].weight = |
| 2037 | SAP_ACS_WEIGHT_MAX * 8; |
| 2038 | if ((pSpectInfo[j].chNum + 28) == |
| 2039 | pSpectInfo[j + 7].chNum) |
| 2040 | pSpectInfo[j + 7].weight = |
| 2041 | SAP_ACS_WEIGHT_MAX * 8; |
| 2042 | continue; |
| 2043 | } |
| 2044 | /*found the channel, add the 7 adjacent channels' weight */ |
| 2045 | acs_vht160_channels[i].weight = pSpectInfo[j].weight + |
| 2046 | pSpectInfo[j + 1].weight + pSpectInfo[j + 2].weight + |
| 2047 | pSpectInfo[j + 3].weight + pSpectInfo[j + 4].weight + |
| 2048 | pSpectInfo[j + 5].weight + pSpectInfo[j + 6].weight + |
| 2049 | pSpectInfo[j + 7].weight; |
| 2050 | |
| 2051 | /* find best channel among 8 channels as the primary channel */ |
| 2052 | if ((pSpectInfo[j].weight + pSpectInfo[j + 1].weight + |
| 2053 | pSpectInfo[j + 2].weight + pSpectInfo[j + 3].weight) > |
| 2054 | (pSpectInfo[j + 4].weight + pSpectInfo[j + 5].weight + |
| 2055 | pSpectInfo[j + 6].weight + pSpectInfo[j + 7].weight)) |
| 2056 | idx = 4; |
| 2057 | else |
| 2058 | idx = 0; |
| 2059 | /* find best channel among 4 channels as the primary channel */ |
| 2060 | if ((pSpectInfo[j + idx].weight + |
| 2061 | pSpectInfo[j + idx + 1].weight) < |
| 2062 | (pSpectInfo[j + idx + 2].weight + |
| 2063 | pSpectInfo[j + idx + 3].weight)) { |
| 2064 | /* lower 2 channels are better choice */ |
| 2065 | if (pSpectInfo[j + idx].weight < |
| 2066 | pSpectInfo[j + idx + 1].weight) |
| 2067 | minIdx = 0 + idx; |
| 2068 | else |
| 2069 | minIdx = 1 + idx; |
| 2070 | } else if (pSpectInfo[j + idx + 2].weight <= |
| 2071 | pSpectInfo[j + idx + 3].weight) { |
| 2072 | /* upper 2 channels are better choice */ |
| 2073 | minIdx = 2 + idx; |
| 2074 | } else { |
| 2075 | minIdx = 3 + idx; |
| 2076 | } |
| 2077 | |
| 2078 | /* |
| 2079 | * set all 8 channels to max value first, then reset the |
| 2080 | * best channel as the selected primary channel, update its |
| 2081 | * weightage with the combined weight value |
| 2082 | */ |
| 2083 | for (n = 0; n < 8; n++) |
| 2084 | pSpectInfo[j + n].weight = SAP_ACS_WEIGHT_MAX * 8; |
| 2085 | |
| 2086 | pSpectInfo[j + minIdx].weight = acs_vht160_channels[i].weight; |
| 2087 | } |
| 2088 | |
Himanshu Agarwal | 75e7441 | 2018-02-01 20:51:47 +0530 | [diff] [blame] | 2089 | /* |
| 2090 | * Assign max weight(SAP_ACS_WEIGHT_MAX * 8) to 2.4 Ghz channels |
| 2091 | * and channel 132-165 as they cannot be part of a 160Mhz channel |
| 2092 | * bonding. |
| 2093 | */ |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 2094 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 2095 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
Himanshu Agarwal | 75e7441 | 2018-02-01 20:51:47 +0530 | [diff] [blame] | 2096 | if ((pSpectInfo[j].chNum >= WLAN_REG_CH_NUM(CHAN_ENUM_1) && |
| 2097 | pSpectInfo[j].chNum <= WLAN_REG_CH_NUM(CHAN_ENUM_14)) || |
| 2098 | (pSpectInfo[j].chNum >= WLAN_REG_CH_NUM(CHAN_ENUM_132) && |
| 2099 | pSpectInfo[j].chNum <= WLAN_REG_CH_NUM(CHAN_ENUM_165))) |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 2100 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 8; |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 2101 | } |
| 2102 | |
Manishekar Chandrasekaran | 44e334f | 2016-05-30 16:42:50 +0530 | [diff] [blame] | 2103 | sap_sort_chl_weight(pSpectInfoParams); |
| 2104 | |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 2105 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 2106 | for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 2107 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 2108 | FL("Channel=%d Weight= %d rssi=%d bssCount=%d"), |
| 2109 | pSpectInfo->chNum, pSpectInfo->weight, |
| 2110 | pSpectInfo->rssiAgr, pSpectInfo->bssCount); |
| 2111 | pSpectInfo++; |
| 2112 | } |
| 2113 | } |
| 2114 | |
| 2115 | /** |
Himanshu Agarwal | 91c5c0f | 2018-02-13 14:40:56 +0530 | [diff] [blame] | 2116 | * sap_allocate_max_weight_ht40_24_g() - allocate max weight for 40Mhz |
| 2117 | * to all 2.4Ghz channels |
| 2118 | * @spect_info_params: Pointer to the tSapChSelSpectInfo structure |
| 2119 | * |
| 2120 | * Return: none |
| 2121 | */ |
| 2122 | static void sap_allocate_max_weight_ht40_24_g( |
| 2123 | tSapChSelSpectInfo *spect_info_params) |
| 2124 | { |
| 2125 | tSapSpectChInfo *spect_info; |
| 2126 | uint8_t j; |
| 2127 | |
| 2128 | /* |
| 2129 | * Assign max weight for 40Mhz (SAP_ACS_WEIGHT_MAX * 2) to all |
| 2130 | * 2.4 Ghz channels |
| 2131 | */ |
| 2132 | spect_info = spect_info_params->pSpectCh; |
| 2133 | for (j = 0; j < spect_info_params->numSpectChans; j++) { |
| 2134 | if ((spect_info[j].chNum >= WLAN_REG_CH_NUM(CHAN_ENUM_1) && |
| 2135 | spect_info[j].chNum <= WLAN_REG_CH_NUM(CHAN_ENUM_14))) |
| 2136 | spect_info[j].weight = SAP_ACS_WEIGHT_MAX * 2; |
| 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | /** |
| 2141 | * sap_allocate_max_weight_ht40_5_g() - allocate max weight for 40Mhz |
| 2142 | * to all 5Ghz channels |
| 2143 | * @spect_info_params: Pointer to the tSapChSelSpectInfo structure |
| 2144 | * |
| 2145 | * Return: none |
| 2146 | */ |
| 2147 | static void sap_allocate_max_weight_ht40_5_g( |
| 2148 | tSapChSelSpectInfo *spect_info_params) |
| 2149 | { |
| 2150 | tSapSpectChInfo *spect_info; |
| 2151 | uint8_t j; |
| 2152 | |
| 2153 | /* |
| 2154 | * Assign max weight for 40Mhz (SAP_ACS_WEIGHT_MAX * 2) to all |
| 2155 | * 5 Ghz channels |
| 2156 | */ |
| 2157 | spect_info = spect_info_params->pSpectCh; |
| 2158 | for (j = 0; j < spect_info_params->numSpectChans; j++) { |
| 2159 | if ((spect_info[j].chNum >= WLAN_REG_CH_NUM(CHAN_ENUM_36) && |
| 2160 | spect_info[j].chNum <= WLAN_REG_CH_NUM(CHAN_ENUM_165))) |
| 2161 | spect_info[j].weight = SAP_ACS_WEIGHT_MAX * 2; |
| 2162 | } |
| 2163 | } |
| 2164 | |
| 2165 | /** |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2166 | * sap_sort_chl_weight_ht40_24_g() - to sort channel with the least weight |
| 2167 | * @pSpectInfoParams: Pointer to the tSapChSelSpectInfo structure |
| 2168 | * |
| 2169 | * Funtion to sort the channels with the least weight first for HT40 channels |
| 2170 | * |
| 2171 | * Return: none |
| 2172 | */ |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2173 | static void sap_sort_chl_weight_ht40_24_g(tSapChSelSpectInfo *pSpectInfoParams, |
| 2174 | v_REGDOMAIN_t domain) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2175 | { |
| 2176 | uint8_t i, j; |
| 2177 | tSapSpectChInfo *pSpectInfo; |
| 2178 | uint32_t tmpWeight1, tmpWeight2; |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 2179 | uint32_t ht40plus2gendch = 0; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2180 | |
| 2181 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 2182 | /* |
| 2183 | * for each HT40 channel, calculate the combined weight of the |
| 2184 | * two 20MHz weight |
| 2185 | */ |
| 2186 | for (i = 0; i < ARRAY_SIZE(acs_ht40_channels24_g); i++) { |
| 2187 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
| 2188 | if (pSpectInfo[j].chNum == |
| 2189 | acs_ht40_channels24_g[i].chStartNum) |
| 2190 | break; |
| 2191 | } |
| 2192 | if (j == pSpectInfoParams->numSpectChans) |
| 2193 | continue; |
| 2194 | |
| 2195 | if (!((pSpectInfo[j].chNum + 4) == pSpectInfo[j + 4].chNum)) { |
| 2196 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2; |
| 2197 | continue; |
| 2198 | } |
| 2199 | /* |
| 2200 | * check if there is another channel combination possiblity |
| 2201 | * e.g., {1, 5} & {5, 9} |
| 2202 | */ |
| 2203 | if ((pSpectInfo[j + 4].chNum + 4) == pSpectInfo[j + 8].chNum) { |
| 2204 | /* need to compare two channel pairs */ |
| 2205 | tmpWeight1 = pSpectInfo[j].weight + |
| 2206 | pSpectInfo[j + 4].weight; |
| 2207 | tmpWeight2 = pSpectInfo[j + 4].weight + |
| 2208 | pSpectInfo[j + 8].weight; |
| 2209 | if (tmpWeight1 <= tmpWeight2) { |
| 2210 | if (pSpectInfo[j].weight <= |
| 2211 | pSpectInfo[j + 4].weight) { |
| 2212 | pSpectInfo[j].weight = |
| 2213 | tmpWeight1; |
| 2214 | pSpectInfo[j + 4].weight = |
| 2215 | SAP_ACS_WEIGHT_MAX * 2; |
| 2216 | pSpectInfo[j + 8].weight = |
| 2217 | SAP_ACS_WEIGHT_MAX * 2; |
| 2218 | } else { |
| 2219 | pSpectInfo[j + 4].weight = |
| 2220 | tmpWeight1; |
| 2221 | /* for secondary channel selection */ |
| 2222 | pSpectInfo[j].weight = |
| 2223 | SAP_ACS_WEIGHT_MAX * 2 |
| 2224 | - 1; |
| 2225 | pSpectInfo[j + 8].weight = |
| 2226 | SAP_ACS_WEIGHT_MAX * 2; |
| 2227 | } |
| 2228 | } else { |
| 2229 | if (pSpectInfo[j + 4].weight <= |
| 2230 | pSpectInfo[j + 8].weight) { |
| 2231 | pSpectInfo[j + 4].weight = |
| 2232 | tmpWeight2; |
| 2233 | pSpectInfo[j].weight = |
| 2234 | SAP_ACS_WEIGHT_MAX * 2; |
| 2235 | /* for secondary channel selection */ |
| 2236 | pSpectInfo[j + 8].weight = |
| 2237 | SAP_ACS_WEIGHT_MAX * 2 |
| 2238 | - 1; |
| 2239 | } else { |
| 2240 | pSpectInfo[j + 8].weight = |
| 2241 | tmpWeight2; |
| 2242 | pSpectInfo[j].weight = |
| 2243 | SAP_ACS_WEIGHT_MAX * 2; |
| 2244 | pSpectInfo[j + 4].weight = |
| 2245 | SAP_ACS_WEIGHT_MAX * 2; |
| 2246 | } |
| 2247 | } |
| 2248 | } else { |
bings | aa6f96a | 2017-09-11 09:49:43 +0800 | [diff] [blame] | 2249 | tmpWeight1 = pSpectInfo[j].weight_copy + |
| 2250 | pSpectInfo[j + 4].weight_copy; |
| 2251 | if (pSpectInfo[j].weight_copy <= |
| 2252 | pSpectInfo[j + 4].weight_copy) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2253 | pSpectInfo[j].weight = tmpWeight1; |
| 2254 | pSpectInfo[j + 4].weight = |
| 2255 | SAP_ACS_WEIGHT_MAX * 2; |
| 2256 | } else { |
| 2257 | pSpectInfo[j + 4].weight = tmpWeight1; |
| 2258 | pSpectInfo[j].weight = |
| 2259 | SAP_ACS_WEIGHT_MAX * 2; |
| 2260 | } |
| 2261 | } |
| 2262 | } |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 2263 | /* |
| 2264 | * Every channel should be checked. Add the check for the omissive |
| 2265 | * channel. Mark the channel whose combination can't satisfy 40MHZ |
| 2266 | * as max value, so that it will be sorted to the bottom. |
| 2267 | */ |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2268 | if (REGDOMAIN_FCC == domain) |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 2269 | ht40plus2gendch = HT40PLUS_2G_FCC_CH_END; |
| 2270 | else |
| 2271 | ht40plus2gendch = HT40PLUS_2G_EURJAP_CH_END; |
| 2272 | for (i = HT40MINUS_2G_CH_START; i <= ht40plus2gendch; i++) { |
| 2273 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
| 2274 | if (pSpectInfo[j].chNum == i && |
| 2275 | ((pSpectInfo[j].chNum + 4) != |
| 2276 | pSpectInfo[j+4].chNum) && |
| 2277 | ((pSpectInfo[j].chNum - 4) != |
| 2278 | pSpectInfo[j-4].chNum)) |
| 2279 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2; |
| 2280 | } |
| 2281 | } |
| 2282 | for (i = ht40plus2gendch + 1; i <= HT40MINUS_2G_CH_END; i++) { |
| 2283 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
| 2284 | if (pSpectInfo[j].chNum == i && |
| 2285 | (pSpectInfo[j].chNum - 4) != |
| 2286 | pSpectInfo[j-4].chNum) |
| 2287 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2; |
| 2288 | } |
| 2289 | } |
Himanshu Agarwal | 91c5c0f | 2018-02-13 14:40:56 +0530 | [diff] [blame] | 2290 | |
| 2291 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 2292 | for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) { |
| 2293 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
| 2294 | "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d", |
| 2295 | __func__, pSpectInfo->chNum, pSpectInfo->weight, |
| 2296 | pSpectInfo->rssiAgr, pSpectInfo->bssCount); |
| 2297 | pSpectInfo++; |
| 2298 | } |
| 2299 | |
Manishekar Chandrasekaran | 44e334f | 2016-05-30 16:42:50 +0530 | [diff] [blame] | 2300 | sap_sort_chl_weight(pSpectInfoParams); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | /*========================================================================== |
| 2304 | FUNCTION sap_sort_chl_weight_ht40_5_g |
| 2305 | |
| 2306 | DESCRIPTION |
| 2307 | Funtion to sort the channels with the least weight first for HT40 channels |
| 2308 | |
| 2309 | DEPENDENCIES |
| 2310 | NA. |
| 2311 | |
| 2312 | PARAMETERS |
| 2313 | |
| 2314 | IN |
| 2315 | pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure |
| 2316 | |
| 2317 | RETURN VALUE |
| 2318 | void : NULL |
| 2319 | |
| 2320 | SIDE EFFECTS |
| 2321 | ============================================================================*/ |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 2322 | static void sap_sort_chl_weight_ht40_5_g(tSapChSelSpectInfo *pSpectInfoParams) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2323 | { |
| 2324 | uint8_t i, j; |
| 2325 | tSapSpectChInfo *pSpectInfo; |
| 2326 | |
| 2327 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 2328 | /*for each HT40 channel, calculate the combined weight of the |
| 2329 | two 20MHz weight */ |
| 2330 | for (i = 0; i < ARRAY_SIZE(acs_ht40_channels5_g); i++) { |
| 2331 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
| 2332 | if (pSpectInfo[j].chNum == |
| 2333 | acs_ht40_channels5_g[i].chStartNum) |
| 2334 | break; |
| 2335 | } |
| 2336 | if (j == pSpectInfoParams->numSpectChans) |
| 2337 | continue; |
| 2338 | |
| 2339 | /* found the channel, add the two adjacent channels' weight */ |
| 2340 | if ((pSpectInfo[j].chNum + 4) == pSpectInfo[j + 1].chNum) { |
| 2341 | acs_ht40_channels5_g[i].weight = pSpectInfo[j].weight + |
| 2342 | pSpectInfo[j + 1].weight; |
| 2343 | /* select better of the adjact channel as the primary channel */ |
| 2344 | if (pSpectInfo[j].weight <= pSpectInfo[j + 1].weight) { |
| 2345 | pSpectInfo[j].weight = |
| 2346 | acs_ht40_channels5_g[i].weight; |
| 2347 | /* mark the adjacent channel's weight as max value so |
| 2348 | that it will be sorted to the bottom */ |
| 2349 | pSpectInfo[j + 1].weight = |
| 2350 | SAP_ACS_WEIGHT_MAX * 2; |
| 2351 | } else { |
| 2352 | pSpectInfo[j + 1].weight = |
| 2353 | acs_ht40_channels5_g[i].weight; |
| 2354 | /* mark the adjacent channel's weight as max value so |
| 2355 | that it will be sorted to the bottom */ |
| 2356 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2; |
| 2357 | } |
| 2358 | |
| 2359 | } else |
| 2360 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2; |
| 2361 | } |
| 2362 | |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 2363 | /* |
| 2364 | *Every channel should be checked. Add the check for the omissive |
| 2365 | * channel. Mark the channel whose combination can't satisfy 40MHZ |
| 2366 | * as max value, so that it will be sorted to the bottom |
| 2367 | */ |
| 2368 | for (j = 1; j < pSpectInfoParams->numSpectChans; j++) { |
| 2369 | for (i = 0; i < ARRAY_SIZE(acs_ht40_channels5_g); i++) { |
| 2370 | if (pSpectInfo[j].chNum == |
| 2371 | (acs_ht40_channels5_g[i].chStartNum + |
| 2372 | 4) && |
| 2373 | pSpectInfo[j - 1].chNum != |
| 2374 | acs_ht40_channels5_g[i].chStartNum) { |
| 2375 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2; |
| 2376 | break; |
| 2377 | } |
| 2378 | } |
| 2379 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2380 | /* avoid channel 165 by setting its weight to max */ |
| 2381 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 2382 | for (j = 0; j < pSpectInfoParams->numSpectChans; j++) { |
| 2383 | if (CHANNEL_165 == pSpectInfo[j].chNum) { |
| 2384 | pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2; |
| 2385 | break; |
| 2386 | } |
| 2387 | } |
| 2388 | |
| 2389 | pSpectInfo = pSpectInfoParams->pSpectCh; |
| 2390 | for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 2391 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2392 | "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d", |
| 2393 | __func__, pSpectInfo->chNum, pSpectInfo->weight, |
| 2394 | pSpectInfo->rssiAgr, pSpectInfo->bssCount); |
| 2395 | pSpectInfo++; |
| 2396 | } |
| 2397 | |
| 2398 | sap_sort_chl_weight(pSpectInfoParams); |
| 2399 | } |
| 2400 | |
| 2401 | /*========================================================================== |
| 2402 | FUNCTION sap_sort_chl_weight_all |
| 2403 | |
| 2404 | DESCRIPTION |
| 2405 | Funtion to sort the channels with the least weight first |
| 2406 | |
| 2407 | DEPENDENCIES |
| 2408 | NA. |
| 2409 | |
| 2410 | PARAMETERS |
| 2411 | |
| 2412 | IN |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 2413 | sap_ctx : Pointer to the struct sap_context *structure |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2414 | pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure |
| 2415 | |
| 2416 | RETURN VALUE |
| 2417 | void : NULL |
| 2418 | |
| 2419 | SIDE EFFECTS |
| 2420 | ============================================================================*/ |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 2421 | static void sap_sort_chl_weight_all(struct sap_context *sap_ctx, |
Jeff Johnson | 464f7ea | 2016-10-07 10:21:26 -0700 | [diff] [blame] | 2422 | tSapChSelSpectInfo *pSpectInfoParams, |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2423 | uint32_t operatingBand, |
| 2424 | v_REGDOMAIN_t domain) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2425 | { |
| 2426 | tSapSpectChInfo *pSpectCh = NULL; |
| 2427 | uint32_t j = 0; |
| 2428 | #ifndef SOFTAP_CHANNEL_RANGE |
| 2429 | uint32_t i = 0; |
| 2430 | #endif |
| 2431 | |
| 2432 | pSpectCh = pSpectInfoParams->pSpectCh; |
| 2433 | #ifdef SOFTAP_CHANNEL_RANGE |
| 2434 | |
Jeff Johnson | e13d806 | 2017-09-28 06:54:55 -0700 | [diff] [blame] | 2435 | switch (sap_ctx->acs_cfg->ch_width) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2436 | case CH_WIDTH_40MHZ: |
Himanshu Agarwal | 91c5c0f | 2018-02-13 14:40:56 +0530 | [diff] [blame] | 2437 | /* |
| 2438 | * Assign max weight to all 5Ghz channels when operating band |
| 2439 | * is 11g and to all 2.4Ghz channels when operating band is 11a |
| 2440 | * or 11abg to avoid selection in ACS algorithm for starting SAP |
| 2441 | */ |
| 2442 | if (eCSR_DOT11_MODE_11g == operatingBand) { |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2443 | sap_sort_chl_weight_ht40_24_g(pSpectInfoParams, domain); |
Himanshu Agarwal | 91c5c0f | 2018-02-13 14:40:56 +0530 | [diff] [blame] | 2444 | sap_allocate_max_weight_ht40_5_g(pSpectInfoParams); |
| 2445 | } else { |
| 2446 | sap_allocate_max_weight_ht40_24_g(pSpectInfoParams); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2447 | sap_sort_chl_weight_ht40_5_g(pSpectInfoParams); |
| 2448 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2449 | break; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2450 | case CH_WIDTH_80MHZ: |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 2451 | case CH_WIDTH_80P80MHZ: |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2452 | sap_sort_chl_weight_ht80(pSpectInfoParams); |
| 2453 | break; |
Kiran Kumar Lokere | b3d8b5b | 2015-10-06 19:33:42 -0700 | [diff] [blame] | 2454 | case CH_WIDTH_160MHZ: |
| 2455 | sap_sort_chl_weight_vht160(pSpectInfoParams); |
| 2456 | break; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2457 | case CH_WIDTH_20MHZ: |
| 2458 | default: |
| 2459 | /* Sorting the channels as per weights as 20MHz channels */ |
| 2460 | sap_sort_chl_weight(pSpectInfoParams); |
| 2461 | } |
| 2462 | |
| 2463 | #else |
| 2464 | /* Sorting the channels as per weights */ |
| 2465 | for (i = 0; i < SPECT_24GHZ_CH_COUNT; i++) { |
| 2466 | minWeightIndex = i; |
| 2467 | for (j = i + 1; j < SPECT_24GHZ_CH_COUNT; j++) { |
| 2468 | if (pSpectCh[j].weight < |
| 2469 | pSpectCh[minWeightIndex].weight) { |
| 2470 | minWeightIndex = j; |
| 2471 | } |
| 2472 | } |
| 2473 | if (minWeightIndex != i) { |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 2474 | qdf_mem_copy(&temp, &pSpectCh[minWeightIndex], |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2475 | sizeof(*pSpectCh)); |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 2476 | qdf_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2477 | sizeof(*pSpectCh)); |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 2478 | qdf_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2479 | } |
| 2480 | } |
| 2481 | #endif |
| 2482 | |
| 2483 | /* For testing */ |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 2484 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2485 | "In %s, Sorted Spectrum Channels Weight", __func__); |
| 2486 | pSpectCh = pSpectInfoParams->pSpectCh; |
| 2487 | for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 2488 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2489 | "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d", |
| 2490 | __func__, pSpectCh->chNum, pSpectCh->weight, |
| 2491 | pSpectCh->rssiAgr, pSpectCh->bssCount); |
| 2492 | pSpectCh++; |
| 2493 | } |
| 2494 | |
| 2495 | } |
| 2496 | |
Naveen Rawat | bec64d9 | 2017-09-13 14:35:21 -0700 | [diff] [blame] | 2497 | /** |
| 2498 | * sap_is_ch_non_overlap() - returns true if non-overlapping channel |
| 2499 | * @sap_ctx: Sap context |
| 2500 | * @ch: channel number |
| 2501 | * |
| 2502 | * Returns: true if non-overlapping (1, 6, 11) channel, false otherwise |
| 2503 | */ |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 2504 | static bool sap_is_ch_non_overlap(struct sap_context *sap_ctx, uint16_t ch) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2505 | { |
Naveen Rawat | bec64d9 | 2017-09-13 14:35:21 -0700 | [diff] [blame] | 2506 | if (sap_ctx->enableOverLapCh) |
Srinivas Girigowda | 74a66d6 | 2017-06-21 23:28:25 -0700 | [diff] [blame] | 2507 | return true; |
Naveen Rawat | bec64d9 | 2017-09-13 14:35:21 -0700 | [diff] [blame] | 2508 | |
| 2509 | if ((ch == CHANNEL_1) || (ch == CHANNEL_6) || (ch == CHANNEL_11)) |
Srinivas Girigowda | 74a66d6 | 2017-06-21 23:28:25 -0700 | [diff] [blame] | 2510 | return true; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2511 | |
Srinivas Girigowda | 74a66d6 | 2017-06-21 23:28:25 -0700 | [diff] [blame] | 2512 | return false; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2513 | } |
| 2514 | |
Dustin Brown | 0ce56d3 | 2016-10-17 16:18:03 -0700 | [diff] [blame] | 2515 | #ifdef FEATURE_WLAN_CH_AVOID |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2516 | /** |
| 2517 | * sap_select_channel_no_scan_result() - select SAP channel when no scan results |
| 2518 | * are available. |
| 2519 | * @sap_ctx: Sap context |
| 2520 | * |
| 2521 | * Returns: channel number if success, 0 otherwise |
| 2522 | */ |
Kondabattini, Ganesh | 13bb4b1 | 2016-09-04 16:16:53 +0530 | [diff] [blame] | 2523 | static uint8_t sap_select_channel_no_scan_result(tHalHandle hal, |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 2524 | struct sap_context *sap_ctx) |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2525 | { |
Mohit Khanna | 841044f | 2016-03-25 16:16:24 -0700 | [diff] [blame] | 2526 | enum channel_state ch_type; |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2527 | uint8_t i, first_safe_ch_in_range = SAP_CHANNEL_NOT_SELECTED; |
Kondabattini, Ganesh | 13bb4b1 | 2016-09-04 16:16:53 +0530 | [diff] [blame] | 2528 | uint32_t dfs_master_cap_enabled; |
Dustin Brown | 0ce56d3 | 2016-10-17 16:18:03 -0700 | [diff] [blame] | 2529 | uint32_t start_ch_num = sap_ctx->acs_cfg->start_ch; |
| 2530 | uint32_t end_ch_num = sap_ctx->acs_cfg->end_ch; |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2531 | tpAniSirGlobal mac_ctx = NULL; |
| 2532 | |
| 2533 | mac_ctx = PMAC_STRUCT(hal); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2534 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2535 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
| 2536 | FL("start - end: %d - %d"), start_ch_num, end_ch_num); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2537 | |
Kondabattini, Ganesh | 13bb4b1 | 2016-09-04 16:16:53 +0530 | [diff] [blame] | 2538 | sme_cfg_get_int(hal, WNI_CFG_DFS_MASTER_ENABLED, |
| 2539 | &dfs_master_cap_enabled); |
| 2540 | |
| 2541 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
| 2542 | "%s: dfs_master %x", __func__, dfs_master_cap_enabled); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2543 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2544 | /* get a channel in PCL and within the range */ |
| 2545 | for (i = 0; i < sap_ctx->acs_cfg->pcl_ch_count; i++) { |
| 2546 | if ((sap_ctx->acs_cfg->pcl_channels[i] < start_ch_num) || |
| 2547 | (sap_ctx->acs_cfg->pcl_channels[i] > end_ch_num)) |
| 2548 | continue; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2549 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2550 | first_safe_ch_in_range = sap_ctx->acs_cfg->pcl_channels[i]; |
| 2551 | break; |
| 2552 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2553 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2554 | if (SAP_CHANNEL_NOT_SELECTED != first_safe_ch_in_range) |
| 2555 | return first_safe_ch_in_range; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2556 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2557 | for (i = 0; i < NUM_CHANNELS; i++) { |
| 2558 | if ((safe_channels[i].channelNumber < start_ch_num) || |
| 2559 | (safe_channels[i].channelNumber > end_ch_num)) |
| 2560 | continue; |
| 2561 | |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2562 | ch_type = wlan_reg_get_channel_state(mac_ctx->pdev, |
| 2563 | safe_channels[i].channelNumber); |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2564 | |
| 2565 | if ((ch_type == CHANNEL_STATE_DISABLE) || |
| 2566 | (ch_type == CHANNEL_STATE_INVALID)) |
| 2567 | continue; |
Kondabattini, Ganesh | 13bb4b1 | 2016-09-04 16:16:53 +0530 | [diff] [blame] | 2568 | if ((!dfs_master_cap_enabled) && |
| 2569 | (CHANNEL_STATE_DFS == ch_type)) { |
| 2570 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
| 2571 | "%s: DFS master mode disabled. Skip DFS channel %d", |
| 2572 | __func__, safe_channels[i].channelNumber); |
| 2573 | continue; |
| 2574 | } |
Agrawal Ashish | 6563461 | 2016-08-18 13:24:32 +0530 | [diff] [blame] | 2575 | if ((sap_ctx->dfs_mode == ACS_DFS_MODE_DISABLE) && |
| 2576 | (CHANNEL_STATE_DFS == ch_type)) |
| 2577 | continue; |
Kondabattini, Ganesh | 13bb4b1 | 2016-09-04 16:16:53 +0530 | [diff] [blame] | 2578 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2579 | if (safe_channels[i].isSafe == true) { |
| 2580 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
| 2581 | FL("channel %d in the configuration is safe"), |
| 2582 | safe_channels[i].channelNumber); |
| 2583 | first_safe_ch_in_range = safe_channels[i].channelNumber; |
| 2584 | break; |
| 2585 | } |
| 2586 | |
| 2587 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
| 2588 | FL("channel %d in the configuration is unsafe"), |
| 2589 | safe_channels[i].channelNumber); |
| 2590 | } |
| 2591 | |
| 2592 | /* if no channel selected return SAP_CHANNEL_NOT_SELECTED */ |
| 2593 | return first_safe_ch_in_range; |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2594 | } |
Dustin Brown | 0ce56d3 | 2016-10-17 16:18:03 -0700 | [diff] [blame] | 2595 | #else |
| 2596 | static uint8_t sap_select_channel_no_scan_result(tHalHandle hal, |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 2597 | struct sap_context *sap_ctx) |
Dustin Brown | 0ce56d3 | 2016-10-17 16:18:03 -0700 | [diff] [blame] | 2598 | { |
| 2599 | uint32_t start_ch_num = sap_ctx->acs_cfg->start_ch; |
| 2600 | |
| 2601 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
| 2602 | FL("start - end: %d - %d"), |
| 2603 | start_ch_num, |
| 2604 | sap_ctx->acs_cfg->end_ch); |
| 2605 | |
| 2606 | sap_ctx->acs_cfg->pri_ch = start_ch_num; |
| 2607 | sap_ctx->acs_cfg->ht_sec_ch = 0; |
| 2608 | |
| 2609 | /* pick the first channel in configured range */ |
| 2610 | return start_ch_num; |
| 2611 | } |
| 2612 | #endif /* FEATURE_WLAN_CH_AVOID */ |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2613 | |
| 2614 | /** |
| 2615 | * sap_select_channel() - select SAP channel |
| 2616 | * @hal: Pointer to HAL handle |
| 2617 | * @sap_ctx: Sap context |
| 2618 | * @scan_result: Pointer to tScanResultHandle |
| 2619 | * |
| 2620 | * Runs a algorithm to select the best channel to operate in based on BSS |
| 2621 | * rssi and bss count on each channel |
| 2622 | * |
| 2623 | * Returns: channel number if success, 0 otherwise |
| 2624 | */ |
Jeff Johnson | f1cd3c7 | 2017-09-14 07:18:06 -0700 | [diff] [blame] | 2625 | uint8_t sap_select_channel(tHalHandle hal, struct sap_context *sap_ctx, |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2626 | tScanResultHandle scan_result) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2627 | { |
| 2628 | /* DFS param object holding all the data req by the algo */ |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2629 | tSapChSelSpectInfo spect_info_obj = { NULL, 0 }; |
| 2630 | tSapChSelSpectInfo *spect_info = &spect_info_obj; |
| 2631 | uint8_t best_ch_num = SAP_CHANNEL_NOT_SELECTED; |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 2632 | uint32_t ht40plus2gendch = 0; |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2633 | v_REGDOMAIN_t domain; |
Arif Hussain | 21ad434 | 2017-12-21 12:00:54 -0800 | [diff] [blame] | 2634 | uint8_t country[CDS_COUNTRY_CODE_LEN + 1]; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2635 | #ifdef SOFTAP_CHANNEL_RANGE |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2636 | uint8_t count; |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2637 | uint32_t start_ch_num, end_ch_num, tmp_ch_num, operating_band = 0; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2638 | #endif |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2639 | tpAniSirGlobal mac_ctx; |
| 2640 | |
| 2641 | mac_ctx = PMAC_STRUCT(hal); |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 2642 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2643 | "In %s, Running SAP Ch Select", __func__); |
| 2644 | |
| 2645 | #ifdef FEATURE_WLAN_CH_AVOID |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2646 | sap_update_unsafe_channel_list(hal, sap_ctx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2647 | #endif |
| 2648 | |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 2649 | /* |
| 2650 | * If ACS weight is not enabled on noise_floor/channel_free/tx_power, |
| 2651 | * then skip acs process if no bss found. |
| 2652 | */ |
| 2653 | if (NULL == scan_result && |
| 2654 | !(sap_ctx->auto_channel_select_weight & 0xffff00)) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 2655 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2656 | FL("No external AP present")); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2657 | |
| 2658 | #ifndef SOFTAP_CHANNEL_RANGE |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2659 | return SAP_CHANNEL_NOT_SELECTED; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2660 | #else |
Kondabattini, Ganesh | 13bb4b1 | 2016-09-04 16:16:53 +0530 | [diff] [blame] | 2661 | return sap_select_channel_no_scan_result(hal, sap_ctx); |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2662 | #endif |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2663 | } |
| 2664 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2665 | /* Initialize the structure pointed by spect_info */ |
Srinivas Girigowda | 74a66d6 | 2017-06-21 23:28:25 -0700 | [diff] [blame] | 2666 | if (sap_chan_sel_init(hal, spect_info, sap_ctx) != true) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 2667 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR, |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2668 | FL("Ch Select initialization failed")); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2669 | return SAP_CHANNEL_NOT_SELECTED; |
| 2670 | } |
| 2671 | /* Compute the weight of the entire spectrum in the operating band */ |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2672 | sap_compute_spect_weight(spect_info, hal, scan_result, sap_ctx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2673 | |
| 2674 | #ifdef FEATURE_AP_MCC_CH_AVOIDANCE |
| 2675 | /* process avoid channel IE to collect all channels to avoid */ |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2676 | sap_process_avoid_ie(hal, sap_ctx, scan_result, spect_info); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2677 | #endif /* FEATURE_AP_MCC_CH_AVOIDANCE */ |
| 2678 | |
Paul Zhang | 0f85b41 | 2018-01-18 19:14:51 +0800 | [diff] [blame] | 2679 | wlan_reg_read_current_country(mac_ctx->psoc, country); |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2680 | wlan_reg_get_domain_from_country_code(&domain, country, SOURCE_DRIVER); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2681 | #ifdef SOFTAP_CHANNEL_RANGE |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2682 | start_ch_num = sap_ctx->acs_cfg->start_ch; |
| 2683 | end_ch_num = sap_ctx->acs_cfg->end_ch; |
| 2684 | SET_ACS_BAND(operating_band, sap_ctx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2685 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2686 | sap_ctx->acsBestChannelInfo.channelNum = 0; |
| 2687 | sap_ctx->acsBestChannelInfo.weight = SAP_ACS_WEIGHT_MAX; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2688 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2689 | /* Sort the ch lst as per the computed weights, lesser weight first. */ |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2690 | sap_sort_chl_weight_all(sap_ctx, spect_info, operating_band, domain); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2691 | |
| 2692 | /*Loop till get the best channel in the given range */ |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2693 | for (count = 0; count < spect_info->numSpectChans; count++) { |
| 2694 | if ((start_ch_num > spect_info->pSpectCh[count].chNum) || |
| 2695 | (end_ch_num < spect_info->pSpectCh[count].chNum)) |
| 2696 | continue; |
| 2697 | |
| 2698 | if (best_ch_num == SAP_CHANNEL_NOT_SELECTED) { |
| 2699 | best_ch_num = spect_info->pSpectCh[count].chNum; |
| 2700 | /* check if best_ch_num is in preferred channel list */ |
| 2701 | best_ch_num = |
| 2702 | sap_select_preferred_channel_from_channel_list( |
| 2703 | best_ch_num, sap_ctx, spect_info); |
| 2704 | /* if not in preferred ch lst, go to nxt best ch */ |
| 2705 | if (best_ch_num == SAP_CHANNEL_NOT_SELECTED) |
| 2706 | continue; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2707 | |
| 2708 | #ifdef FEATURE_AP_MCC_CH_AVOIDANCE |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2709 | /* |
| 2710 | * Weight of the channels(device's AP is operating) |
| 2711 | * increased to MAX+1 so that they will be choosen only |
| 2712 | * when there is no other best channel to choose |
| 2713 | */ |
| 2714 | if (sap_check_in_avoid_ch_list(sap_ctx, best_ch_num)) { |
| 2715 | best_ch_num = SAP_CHANNEL_NOT_SELECTED; |
| 2716 | continue; |
| 2717 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2718 | #endif |
| 2719 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2720 | sap_ctx->acsBestChannelInfo.channelNum = best_ch_num; |
| 2721 | sap_ctx->acsBestChannelInfo.weight = |
| 2722 | spect_info->pSpectCh[count].weight_copy; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2723 | } |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2724 | |
| 2725 | if (best_ch_num == SAP_CHANNEL_NOT_SELECTED) |
| 2726 | continue; |
| 2727 | |
Tushnim Bhattacharyya | 03103fd | 2017-06-23 10:48:52 -0700 | [diff] [blame] | 2728 | if (operating_band != eCSR_DOT11_MODE_11g) { |
| 2729 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 2730 | QDF_TRACE_LEVEL_INFO_HIGH, |
| 2731 | "operating_band %d", operating_band); |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2732 | continue; |
Tushnim Bhattacharyya | 03103fd | 2017-06-23 10:48:52 -0700 | [diff] [blame] | 2733 | } |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2734 | |
| 2735 | /* Give preference to Non-overlap channels */ |
Naveen Rawat | bec64d9 | 2017-09-13 14:35:21 -0700 | [diff] [blame] | 2736 | if (false == sap_is_ch_non_overlap(sap_ctx, |
Tushnim Bhattacharyya | 03103fd | 2017-06-23 10:48:52 -0700 | [diff] [blame] | 2737 | spect_info->pSpectCh[count].chNum)) { |
| 2738 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 2739 | QDF_TRACE_LEVEL_INFO_HIGH, |
Naveen Rawat | bec64d9 | 2017-09-13 14:35:21 -0700 | [diff] [blame] | 2740 | FL("ch: %d skipped as its overlapping ch"), |
| 2741 | spect_info->pSpectCh[count].chNum); |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2742 | continue; |
Tushnim Bhattacharyya | 03103fd | 2017-06-23 10:48:52 -0700 | [diff] [blame] | 2743 | } |
| 2744 | |
| 2745 | if (wlan_reg_is_dfs_ch(mac_ctx->pdev, |
| 2746 | spect_info->pSpectCh[count].chNum) && |
| 2747 | policy_mgr_disallow_mcc(mac_ctx->psoc, |
| 2748 | spect_info->pSpectCh[count].chNum)) { |
| 2749 | QDF_TRACE(QDF_MODULE_ID_SAP, |
| 2750 | QDF_TRACE_LEVEL_INFO_HIGH, |
| 2751 | "No DFS MCC"); |
| 2752 | continue; |
| 2753 | } |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2754 | |
bings | 14d1d3b | 2017-08-03 11:14:29 +0800 | [diff] [blame] | 2755 | if (spect_info->pSpectCh[count].weight_copy > |
| 2756 | sap_ctx->acsBestChannelInfo.weight) |
| 2757 | continue; |
| 2758 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2759 | tmp_ch_num = spect_info->pSpectCh[count].chNum; |
gaolez | e510894 | 2017-03-31 16:56:42 +0800 | [diff] [blame] | 2760 | tmp_ch_num = sap_channel_in_acs_channel_list( |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2761 | tmp_ch_num, sap_ctx, spect_info); |
| 2762 | if (tmp_ch_num == SAP_CHANNEL_NOT_SELECTED) |
| 2763 | continue; |
| 2764 | |
| 2765 | best_ch_num = tmp_ch_num; |
| 2766 | break; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2767 | } |
| 2768 | #else |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2769 | /* Sort the ch lst as per the computed weights, lesser weight first. */ |
| 2770 | sap_sort_chl_weight_all(sap_ctx, hal, spect_info); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2771 | /* Get the first channel in sorted array as best 20M Channel */ |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2772 | best_ch_num = (uint8_t) spect_info->pSpectCh[0].chNum; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2773 | /* Select Best Channel from Channel List if Configured */ |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2774 | best_ch_num = sap_select_preferred_channel_from_channel_list( |
| 2775 | best_ch_num, sap_ctx, spect_info); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2776 | #endif |
| 2777 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2778 | /* |
| 2779 | * in case the best channel seleted is not in PCL and there is another |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2780 | * channel which has same weightage and is in PCL, choose the one in |
| 2781 | * PCL |
| 2782 | */ |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2783 | for (count = 0; count < spect_info->numSpectChans; count++) { |
| 2784 | if (!ch_in_pcl(sap_ctx, spect_info->pSpectCh[count].chNum) || |
| 2785 | (spect_info->pSpectCh[count].weight != |
| 2786 | sap_ctx->acsBestChannelInfo.weight)) |
| 2787 | continue; |
| 2788 | |
| 2789 | if (sap_select_preferred_channel_from_channel_list( |
| 2790 | spect_info->pSpectCh[count].chNum, sap_ctx, spect_info) |
| 2791 | == SAP_CHANNEL_NOT_SELECTED) |
| 2792 | continue; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2793 | |
| 2794 | #ifdef FEATURE_AP_MCC_CH_AVOIDANCE |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2795 | if (sap_check_in_avoid_ch_list(sap_ctx, best_ch_num)) |
| 2796 | continue; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2797 | #endif |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2798 | best_ch_num = spect_info->pSpectCh[count].chNum; |
| 2799 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
| 2800 | FL("change best channel to %d in PCL"), best_ch_num); |
| 2801 | break; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2802 | } |
| 2803 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2804 | sap_ctx->acs_cfg->pri_ch = best_ch_num; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2805 | /* determine secondary channel for 2.4G channel 5, 6, 7 in HT40 */ |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2806 | if ((operating_band != eCSR_DOT11_MODE_11g) || |
| 2807 | (sap_ctx->acs_cfg->ch_width != CH_WIDTH_40MHZ)) |
| 2808 | goto sap_ch_sel_end; |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 2809 | if (REGDOMAIN_FCC == domain) |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 2810 | ht40plus2gendch = HT40PLUS_2G_FCC_CH_END; |
| 2811 | else |
| 2812 | ht40plus2gendch = HT40PLUS_2G_EURJAP_CH_END; |
| 2813 | if ((best_ch_num >= HT40MINUS_2G_CH_START) && |
| 2814 | (best_ch_num <= ht40plus2gendch)) { |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2815 | int weight_below, weight_above, i; |
| 2816 | tSapSpectChInfo *pspect_info; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2817 | |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2818 | weight_below = weight_above = SAP_ACS_WEIGHT_MAX; |
| 2819 | pspect_info = spect_info->pSpectCh; |
| 2820 | for (i = 0; i < spect_info->numSpectChans; i++) { |
| 2821 | if (pspect_info[i].chNum == (best_ch_num - 4)) |
| 2822 | weight_below = pspect_info[i].weight; |
| 2823 | if (pspect_info[i].chNum == (best_ch_num + 4)) |
| 2824 | weight_above = pspect_info[i].weight; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2825 | } |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2826 | |
| 2827 | if (weight_below < weight_above) |
| 2828 | sap_ctx->acs_cfg->ht_sec_ch = |
| 2829 | sap_ctx->acs_cfg->pri_ch - 4; |
| 2830 | else |
| 2831 | sap_ctx->acs_cfg->ht_sec_ch = |
| 2832 | sap_ctx->acs_cfg->pri_ch + 4; |
| 2833 | } else if (best_ch_num >= 1 && best_ch_num <= 4) { |
| 2834 | sap_ctx->acs_cfg->ht_sec_ch = sap_ctx->acs_cfg->pri_ch + 4; |
bings | e278238 | 2017-03-23 10:34:52 +0800 | [diff] [blame] | 2835 | } else if (best_ch_num >= ht40plus2gendch && best_ch_num <= |
| 2836 | HT40MINUS_2G_CH_END) { |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2837 | sap_ctx->acs_cfg->ht_sec_ch = sap_ctx->acs_cfg->pri_ch - 4; |
| 2838 | } else if (best_ch_num == 14) { |
| 2839 | sap_ctx->acs_cfg->ht_sec_ch = 0; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2840 | } |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2841 | sap_ctx->secondary_ch = sap_ctx->acs_cfg->ht_sec_ch; |
| 2842 | |
| 2843 | sap_ch_sel_end: |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2844 | /* Free all the allocated memory */ |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2845 | sap_chan_sel_exit(spect_info); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2846 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 2847 | QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH, |
Naveen Rawat | 365d1cb | 2016-02-05 12:10:43 -0800 | [diff] [blame] | 2848 | FL("Running SAP Ch select Completed, Ch=%d"), best_ch_num); |
| 2849 | if (best_ch_num > 0 && best_ch_num <= 252) |
| 2850 | return best_ch_num; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2851 | else |
| 2852 | return SAP_CHANNEL_NOT_SELECTED; |
| 2853 | } |