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