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