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