1 /* 2 * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved. 3 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 /** 19 * DOC: Define bss scoring structures and APIs 20 */ 21 22 #ifndef _WLAN_CM_BSS_SCORE_H 23 #define _WLAN_CM_BSS_SCORE_H 24 25 #include <wlan_scan_utils_api.h> 26 #include "wlan_reg_services_api.h" 27 28 /** 29 * struct weight_cfg - weight params to calculate best candidate 30 * @rssi_weightage: RSSI weightage 31 * @ht_caps_weightage: HT caps weightage 32 * @vht_caps_weightage: VHT caps weightage 33 * @he_caps_weightage: HE caps weightage 34 * @chan_width_weightage: Channel width weightage 35 * @chan_band_weightage: Channel band weightage 36 * @nss_weightage: NSS weightage 37 * @beamforming_cap_weightage: Beamforming caps weightage 38 * @pcl_weightage: PCL weightage 39 * @channel_congestion_weightage: channel congestion weightage 40 * @oce_wan_weightage: OCE WAN metrics weightage 41 * @oce_ap_tx_pwr_weightage: OCE AP tx power weigtage 42 * @oce_subnet_id_weightage: OCE subnet id weigtage 43 * @sae_pk_ap_weightage: SAE-PK AP weigtage 44 * @eht_caps_weightage: EHT caps weightage 45 * @mlo_weightage: MLO weightage 46 * @joint_rssi_alpha: Joint RSSI alpha value 47 * @joint_esp_alpha: Joint ESP alpha value 48 * @joint_oce_alpha: Joint OCE alpha value 49 * @low_band_rssi_boost: Flag to assign higher alpha weightage low band RSSI 50 * @low_band_esp_boost: Flag to assign higher alpha weightage low band esp 51 * @low_band_oce_boost: Flag to assign higher alpha weightage low band oce 52 * @wlm_indication_weightage: WLM indication weightage 53 * @emlsr_weightage: eMLSR weightage 54 * @security_weightage: Security weightage 55 */ 56 struct weight_cfg { 57 uint8_t rssi_weightage; 58 uint8_t ht_caps_weightage; 59 uint8_t vht_caps_weightage; 60 uint8_t he_caps_weightage; 61 uint8_t chan_width_weightage; 62 uint8_t chan_band_weightage; 63 uint8_t nss_weightage; 64 uint8_t beamforming_cap_weightage; 65 uint8_t pcl_weightage; 66 uint8_t channel_congestion_weightage; 67 uint8_t oce_wan_weightage; 68 uint8_t oce_ap_tx_pwr_weightage; 69 uint8_t oce_subnet_id_weightage; 70 uint8_t sae_pk_ap_weightage; 71 #ifdef WLAN_FEATURE_11BE_MLO 72 uint8_t eht_caps_weightage; 73 uint8_t mlo_weightage; 74 uint8_t joint_rssi_alpha; 75 uint8_t joint_esp_alpha; 76 uint8_t joint_oce_alpha; 77 uint8_t low_band_rssi_boost:1, 78 low_band_esp_boost:1, 79 low_band_oce_boost:1, 80 reserved:5; 81 uint8_t wlm_indication_weightage; 82 uint8_t emlsr_weightage; 83 #endif 84 uint8_t security_weightage; 85 }; 86 87 /** 88 * struct rssi_config_score - rssi related params for scoring logic 89 * @best_rssi_threshold: RSSI weightage 90 * @good_rssi_threshold: HT caps weightage 91 * @bad_rssi_threshold: VHT caps weightage 92 * @good_rssi_pcnt: HE caps weightage 93 * @bad_rssi_pcnt: Channel width weightage 94 * @good_rssi_bucket_size: Channel band weightage 95 * @bad_rssi_bucket_size: NSS weightage 96 * @rssi_pref_5g_rssi_thresh: Beamforming caps weightage 97 * @con_non_hint_target_rssi_threshold: RSSI threshold value 98 */ 99 struct rssi_config_score { 100 uint8_t best_rssi_threshold; 101 uint8_t good_rssi_threshold; 102 uint8_t bad_rssi_threshold; 103 uint8_t good_rssi_pcnt; 104 uint8_t bad_rssi_pcnt; 105 uint8_t good_rssi_bucket_size; 106 uint8_t bad_rssi_bucket_size; 107 uint8_t rssi_pref_5g_rssi_thresh; 108 int8_t con_non_hint_target_rssi_threshold; 109 }; 110 111 /** 112 * struct per_slot_score - define % score for different slots for a 113 * scoring param. 114 * num_slot: number of slots in which the param will be divided. 115 * Max 15. index 0 is used for 'not_present. Num_slot will 116 * equally divide 100. e.g, if num_slot = 4 slot 0 = 0-25%, slot 117 * 1 = 26-50% slot 2 = 51-75%, slot 3 = 76-100% 118 * score_pcnt3_to_0: Contains score percentage for slot 0-3 119 * BITS 0-7 :- the scoring pcnt when not present 120 * BITS 8-15 :- SLOT_1 121 * BITS 16-23 :- SLOT_2 122 * BITS 24-31 :- SLOT_3 123 * score_pcnt7_to_4: Contains score percentage for slot 4-7 124 * BITS 0-7 :- SLOT_4 125 * BITS 8-15 :- SLOT_5 126 * BITS 16-23 :- SLOT_6 127 * BITS 24-31 :- SLOT_7 128 * score_pcnt11_to_8: Contains score percentage for slot 8-11 129 * BITS 0-7 :- SLOT_8 130 * BITS 8-15 :- SLOT_9 131 * BITS 16-23 :- SLOT_10 132 * BITS 24-31 :- SLOT_11 133 * score_pcnt15_to_12: Contains score percentage for slot 12-15 134 * BITS 0-7 :- SLOT_12 135 * BITS 8-15 :- SLOT_13 136 * BITS 16-23 :- SLOT_14 137 * BITS 24-31 :- SLOT_15 138 */ 139 struct per_slot_score { 140 uint8_t num_slot; 141 uint32_t score_pcnt3_to_0; 142 uint32_t score_pcnt7_to_4; 143 uint32_t score_pcnt11_to_8; 144 uint32_t score_pcnt15_to_12; 145 }; 146 147 #ifndef WLAN_FEATURE_11BE 148 #define CM_20MHZ_BW_INDEX 0 149 #define CM_40MHZ_BW_INDEX 1 150 #define CM_80MHZ_BW_INDEX 2 151 #define CM_160MHZ_BW_INDEX 3 152 #define CM_MAX_BW_INDEX 4 153 154 #define CM_NSS_1x1_INDEX 0 155 #define CM_NSS_2x2_INDEX 1 156 #define CM_NSS_3x3_INDEX 2 157 #define CM_NSS_4x4_INDEX 3 158 #define CM_MAX_NSS_INDEX 4 159 #else 160 enum cm_bw_idx { 161 CM_20MHZ_BW_INDEX = 0, 162 CM_40MHZ_BW_INDEX = 1, 163 CM_80MHZ_BW_INDEX = 2, 164 CM_160MHZ_BW_INDEX = 3, 165 CM_320MHZ_BW_INDEX = 4, 166 CM_80MHZ_BW_20MHZ_PUNCTURE_INDEX = 5, 167 CM_160MHZ_BW_40MHZ_PUNCTURE_INDEX = 6, 168 CM_160MHZ_BW_20MHZ_PUNCTURE_INDEX = 7, 169 CM_320MHZ_BW_40MHZ_80MHZ_PUNCTURE_INDEX = 8, 170 CM_320MHZ_BW_80MHZ_PUNCTURE_INDEX = 9, 171 CM_320MHZ_BW_40MHZ_PUNCTURE_INDEX = 10, 172 #ifdef WLAN_FEATURE_11BE_MLO 173 CM_MLO_20_PLUS_20MHZ_BW_INDEX = 11, 174 CM_MLO_20_PLUS_40MHZ_BW_INDEX = 12, 175 CM_MLO_40_PLUS_40MHZ_BW_INDEX = 13, 176 CM_MLO_20_PLUS_80MHZ_BW_20MHZ_PUNCTURE_INDEX = 14, 177 CM_MLO_20_PLUS_80MHZ_BW_INDEX = 15, 178 CM_MLO_40_PLUS_80MHZ_BW_20MHZ_PUNCTURE_INDEX = 16, 179 CM_MLO_40_PLUS_80MHZ_BW_INDEX = 17, 180 CM_MLO_80_PLUS_80MHZ_BW_40MHZ_PUNCTURE_INDEX = 18, 181 CM_MLO_80_PLUS_80MHZ_BW_20MHZ_PUNCTURE_INDEX = 19, 182 CM_MLO_80_PLUS_80MHZ_BW_INDEX = 20, 183 CM_MLO_20_PLUS_160HZ_BW_40MHZ_PUNCTURE_INDEX = 21, 184 CM_MLO_20_PLUS_160HZ_BW_20MHZ_PUNCTURE_INDEX = 22, 185 CM_MLO_20_PLUS_160HZ_BW_INDEX = 23, 186 CM_MLO_40_PLUS_160HZ_BW_40MHZ_PUNCTURE_INDEX = 24, 187 CM_MLO_40_PLUS_160HZ_BW_20MHZ_PUNCTURE_INDEX = 25, 188 CM_MLO_40_PLUS_160HZ_BW_INDEX = 26, 189 CM_MLO_80_PLUS_160HZ_BW_60MHZ_PUNCTURE_INDEX = 27, 190 CM_MLO_80_PLUS_160HZ_BW_40MHZ_PUNCTURE_INDEX = 28, 191 CM_MLO_80_PLUS_160HZ_BW_20MHZ_PUNCTURE_INDEX = 29, 192 CM_MLO_80_PLUS_160HZ_BW_INDEX = 30, 193 CM_MLO_160_PLUS_160HZ_BW_80MHZ_PUNCTURE_INDEX = 31, 194 CM_MLO_160_PLUS_160HZ_BW_60MHZ_PUNCTURE_INDEX = 32, 195 CM_MLO_160_PLUS_160HZ_BW_40MHZ_PUNCTURE_INDEX = 33, 196 CM_MLO_160_PLUS_160HZ_BW_20MHZ_PUNCTURE_INDEX = 34, 197 CM_MLO_160_PLUS_160HZ_BW_INDEX = 35, 198 #endif 199 CM_MAX_BW_INDEX 200 }; 201 202 enum cm_nss_idx { 203 CM_NSS_1x1_INDEX, 204 CM_NSS_2x2_INDEX, 205 CM_NSS_3x3_INDEX, 206 CM_NSS_4x4_INDEX, 207 #ifdef WLAN_FEATURE_11BE_MLO 208 CM_NSS_2x2_PLUS_2x2_INDEX, 209 CM_NSS_4x4_PLUS_4x4_INDEX, 210 #endif 211 CM_MAX_NSS_INDEX 212 }; 213 #endif 214 215 enum cm_security_idx { 216 CM_SECURITY_WPA_INDEX, 217 CM_SECURITY_WPA2_INDEX, 218 CM_SECURITY_WPA3_INDEX, 219 CM_SECURITY_WPA_OPEN_WEP_INDEX, 220 CM_MAX_SECURITY_INDEX 221 }; 222 223 /** 224 * struct scoring_cfg - Scoring related configuration 225 * @weight_cfg: weigtage config for config 226 * @rssi_score: Rssi related config for scoring config 227 * @esp_qbss_scoring: esp and qbss related scoring config 228 * @oce_wan_scoring: oce related scoring config 229 * @bandwidth_weight_per_index: BW weight per index 230 * @nss_weight_per_index: nss weight per index 231 * @band_weight_per_index: band weight per index 232 * @is_bssid_hint_priority: True if bssid_hint is given priority 233 * @check_assoc_disallowed: Should assoc be disallowed if MBO OCE IE indicate so 234 * @vendor_roam_score_algorithm: Preferred ETP vendor roam score algorithm 235 * @check_6ghz_security: check security for 6Ghz candidate 236 * @relaxed_6ghz_conn_policy: check for 6Ghz relaxed connection policy 237 * @standard_6ghz_conn_policy: check for 6 GHz standard connection policy 238 * @key_mgmt_mask_6ghz: user configurable mask for 6ghz AKM 239 * @mlsr_link_selection: MLSR link selection config 240 * @roam_tgt_score_cap: Roam score capability 241 * @security_weight_per_index: security weight per index 242 */ 243 struct scoring_cfg { 244 struct weight_cfg weight_config; 245 struct rssi_config_score rssi_score; 246 struct per_slot_score esp_qbss_scoring; 247 struct per_slot_score oce_wan_scoring; 248 uint32_t bandwidth_weight_per_index[qdf_ceil(CM_MAX_BW_INDEX, 4)]; 249 uint32_t nss_weight_per_index[qdf_ceil(CM_MAX_NSS_INDEX, 4)]; 250 uint32_t band_weight_per_index; 251 uint8_t is_bssid_hint_priority:1, 252 check_assoc_disallowed:1, 253 vendor_roam_score_algorithm:1, 254 check_6ghz_security:1, 255 relaxed_6ghz_conn_policy:1, 256 standard_6ghz_conn_policy:1; 257 258 uint32_t key_mgmt_mask_6ghz; 259 #ifdef WLAN_FEATURE_11BE_MLO 260 uint8_t mlsr_link_selection; 261 #endif 262 uint32_t roam_tgt_score_cap; 263 uint32_t security_weight_per_index; 264 }; 265 266 /** 267 * struct pcl_freq_weight_list - pcl freq weight info 268 * @num_of_pcl_channels: number of pcl channel 269 * @pcl_freq_list: pcl freq list 270 * @pcl_weight_list: pcl freq weight list 271 */ 272 struct pcl_freq_weight_list { 273 uint32_t num_of_pcl_channels; 274 uint32_t pcl_freq_list[NUM_CHANNELS]; 275 uint8_t pcl_weight_list[NUM_CHANNELS]; 276 }; 277 278 /** 279 * enum cm_denylist_action - action taken by denylist manager for the bssid 280 * @CM_DLM_NO_ACTION: No operation to be taken for the BSSID in the scan list. 281 * @CM_DLM_REMOVE: Remove the BSSID from the scan list (AP is denylisted) 282 * This param is a way to inform the caller that this BSSID is denylisted 283 * but it is a driver denylist and we can connect to them if required. 284 * @CM_DLM_FORCE_REMOVE: Forcefully remove the BSSID from scan list. 285 * This param is introduced as we want to differentiate between optional 286 * mandatory denylisting. Driver denylisting is optional and won't 287 * fail any CERT or protocol violations as it is internal implementation. 288 * hence FORCE_REMOVE will mean that driver cannot connect to this BSSID 289 * in any situation. 290 * @CM_DLM_AVOID: Add the Ap at last of the scan list (AP to Avoid) 291 */ 292 enum cm_denylist_action { 293 CM_DLM_NO_ACTION, 294 CM_DLM_REMOVE, 295 CM_DLM_FORCE_REMOVE, 296 CM_DLM_AVOID, 297 }; 298 299 /** 300 * struct etp_params - params for estimated throughput 301 * @airtime_fraction: Portion of airtime available for outbound transmissions 302 * @data_ppdu_dur_target_us: Expected duration of a single PPDU, in us 303 * @ba_window_size: Block ack window size of the transmitter 304 */ 305 struct etp_params { 306 uint32_t airtime_fraction; 307 uint32_t data_ppdu_dur_target_us; 308 uint32_t ba_window_size; 309 }; 310 311 #ifdef FEATURE_DENYLIST_MGR 312 enum cm_denylist_action 313 wlan_denylist_action_on_bssid(struct wlan_objmgr_pdev *pdev, 314 struct scan_cache_entry *entry); 315 #else 316 static inline enum cm_denylist_action 317 wlan_denylist_action_on_bssid(struct wlan_objmgr_pdev *pdev, 318 struct scan_cache_entry *entry) 319 { 320 return CM_DLM_NO_ACTION; 321 } 322 #endif 323 324 /** 325 * wlan_cm_calculate_bss_score() - calculate bss score for the scan list 326 * @pdev: pointer to pdev object 327 * @pcl_list: pcl list for scoring 328 * @scan_list: scan list, contains the input list and after the 329 * func it will have sorted list 330 * @bssid_hint: bssid hint 331 * 332 * Return: void 333 */ 334 void wlan_cm_calculate_bss_score(struct wlan_objmgr_pdev *pdev, 335 struct pcl_freq_weight_list *pcl_lst, 336 qdf_list_t *scan_list, 337 struct qdf_mac_addr *bssid_hint); 338 339 /** 340 * wlan_cm_init_score_config() - Init score INI and config 341 * @psoc: pointer to psoc object 342 * @score_cfg: score config 343 * 344 * Return: void 345 */ 346 void wlan_cm_init_score_config(struct wlan_objmgr_psoc *psoc, 347 struct scoring_cfg *score_cfg); 348 349 /** 350 * wlan_cm_6ghz_allowed_for_akm() - check if 6Ghz channel can be allowed for AKM 351 * @psoc: pointer to psoc object 352 * @key_mgmt: key mgmt used 353 * @rsn_caps: rsn caps 354 * @rsnxe: rsnxe pointer if present 355 * @sae_pwe: support for SAE password 356 * @is_wps: if security is WPS 357 * 358 * Return: bool 359 */ 360 #ifdef CONFIG_BAND_6GHZ 361 bool wlan_cm_6ghz_allowed_for_akm(struct wlan_objmgr_psoc *psoc, 362 uint32_t key_mgmt, uint16_t rsn_caps, 363 const uint8_t *rsnxe, uint8_t sae_pwe, 364 bool is_wps); 365 366 /** 367 * wlan_cm_set_check_6ghz_security() - Set check 6Ghz security 368 * @psoc: pointer to psoc object 369 * @value: value to be set 370 * 371 * Return: void 372 */ 373 void wlan_cm_set_check_6ghz_security(struct wlan_objmgr_psoc *psoc, 374 bool value); 375 376 /** 377 * wlan_cm_reset_check_6ghz_security() - reset check 6Ghz security to original 378 * value 379 * @psoc: pointer to psoc object 380 * 381 * Return: void 382 */ 383 void wlan_cm_reset_check_6ghz_security(struct wlan_objmgr_psoc *psoc); 384 385 /** 386 * wlan_cm_get_check_6ghz_security() - Get 6Ghz allowed AKM mask 387 * @psoc: pointer to psoc object 388 * @value: value to be set 389 * 390 * Return: value 391 */ 392 bool wlan_cm_get_check_6ghz_security(struct wlan_objmgr_psoc *psoc); 393 394 /** 395 * wlan_cm_set_6ghz_key_mgmt_mask() - Set 6Ghz allowed AKM mask 396 * @psoc: pointer to psoc object 397 * 398 * Return: void 399 */ 400 void wlan_cm_set_6ghz_key_mgmt_mask(struct wlan_objmgr_psoc *psoc, 401 uint32_t value); 402 403 /** 404 * wlan_cm_get_6ghz_key_mgmt_mask() - Get 6Ghz allowed AKM mask 405 * @psoc: pointer to psoc object 406 * 407 * Return: value 408 */ 409 uint32_t wlan_cm_get_6ghz_key_mgmt_mask(struct wlan_objmgr_psoc *psoc); 410 411 /** 412 * wlan_cm_set_relaxed_6ghz_conn_policy() - Set 6Ghz relaxed connection policy 413 * @psoc: pointer to psoc object 414 * @value: value to be set 415 * 416 * Return: void 417 */ 418 void wlan_cm_set_relaxed_6ghz_conn_policy(struct wlan_objmgr_psoc *psoc, 419 bool value); 420 /** 421 * wlan_cm_get_relaxed_6ghz_conn_policy() - Get 6Ghz relaxed connection policy 422 * flag 423 * @psoc: pointer to psoc object 424 * 425 * Return: value 426 */ 427 bool wlan_cm_get_relaxed_6ghz_conn_policy(struct wlan_objmgr_psoc *psoc); 428 429 /** 430 * wlan_cm_set_standard_6ghz_conn_policy() - Set 6 GHz standard connection 431 * policy 432 * @psoc: pointer to psoc object 433 * @value: value to be set 434 * 435 * Return: void 436 */ 437 void wlan_cm_set_standard_6ghz_conn_policy(struct wlan_objmgr_psoc *psoc, 438 bool value); 439 440 /** 441 * wlan_cm_get_standard_6ghz_conn_policy() - Get 6Ghz standard connection 442 * policy 443 * @psoc: pointer to psoc object 444 * 445 * Return: value 446 */ 447 bool wlan_cm_get_standard_6ghz_conn_policy(struct wlan_objmgr_psoc *psoc); 448 449 #else 450 static inline bool 451 wlan_cm_6ghz_allowed_for_akm(struct wlan_objmgr_psoc *psoc, 452 uint32_t key_mgmt, uint16_t rsn_caps, 453 const uint8_t *rsnxe, uint8_t sae_pwe, 454 bool is_wps) 455 { 456 return true; 457 } 458 459 static inline 460 void wlan_cm_set_check_6ghz_security(struct wlan_objmgr_psoc *psoc, 461 bool value) {} 462 463 static inline 464 void wlan_cm_reset_check_6ghz_security(struct wlan_objmgr_psoc *psoc) {} 465 466 static inline 467 bool wlan_cm_get_check_6ghz_security(struct wlan_objmgr_psoc *psoc) 468 { 469 return false; 470 } 471 472 static inline 473 void wlan_cm_set_standard_6ghz_conn_policy(struct wlan_objmgr_psoc *psoc, 474 uint32_t value) 475 { 476 } 477 478 static inline 479 bool wlan_cm_get_standard_6ghz_conn_policy(struct wlan_objmgr_psoc *psoc) 480 { 481 return false; 482 } 483 484 static inline 485 void wlan_cm_set_6ghz_key_mgmt_mask(struct wlan_objmgr_psoc *psoc, 486 uint32_t value) {} 487 488 static inline 489 uint32_t wlan_cm_get_6ghz_key_mgmt_mask(struct wlan_objmgr_psoc *psoc) 490 { 491 return DEFAULT_KEYMGMT_6G_MASK; 492 } 493 494 static inline 495 void wlan_cm_set_relaxed_6ghz_conn_policy(struct wlan_objmgr_psoc *psoc, 496 bool value) 497 {} 498 499 static inline 500 bool wlan_cm_get_relaxed_6ghz_conn_policy(struct wlan_objmgr_psoc *psoc) 501 { 502 return false; 503 } 504 #endif 505 506 #ifdef CONN_MGR_ADV_FEATURE 507 /** 508 * wlan_cm_set_check_assoc_disallowed() - Set check assoc disallowed param 509 * @psoc: pointer to psoc object 510 * @value: value to be set 511 * 512 * Return: void 513 */ 514 void wlan_cm_set_check_assoc_disallowed(struct wlan_objmgr_psoc *psoc, 515 bool value); 516 517 /** 518 * wlan_cm_get_check_assoc_disallowed() - get check assoc disallowed param 519 * @psoc: pointer to psoc object 520 * @value: value to be filled 521 * 522 * Return: void 523 */ 524 void wlan_cm_get_check_assoc_disallowed(struct wlan_objmgr_psoc *psoc, 525 bool *value); 526 #endif 527 #endif 528