From 4afab6c41da326ed40b4f7853dcb797989278d1e Mon Sep 17 00:00:00 2001 From: Srikanth Marepalli Date: Tue, 31 Oct 2023 23:53:59 +0530 Subject: [PATCH] qcacmn: Update BSS score calculation based on Security Profile Update BSS score calculation to consider security profile. Change-Id: I120774ce2472442ebba15e098b4089f8a17cbfc5 CRs-Fixed: 3782206 --- .../core/src/wlan_cm_bss_scoring.c | 104 +++++++++++++++++- .../dispatcher/inc/wlan_cm_bss_score_param.h | 16 ++- 2 files changed, 113 insertions(+), 7 deletions(-) diff --git a/umac/mlme/connection_mgr/core/src/wlan_cm_bss_scoring.c b/umac/mlme/connection_mgr/core/src/wlan_cm_bss_scoring.c index 843c042f6cc9..04d9f3db9d7c 100644 --- a/umac/mlme/connection_mgr/core/src/wlan_cm_bss_scoring.c +++ b/umac/mlme/connection_mgr/core/src/wlan_cm_bss_scoring.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved. - * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved. + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -82,6 +82,7 @@ #define CM_CHAN_WIDTH_WEIGHTAGE 12 #define CM_CHAN_BAND_WEIGHTAGE 2 #define CM_NSS_WEIGHTAGE 16 +#define CM_SECURITY_WEIGHTAGE 4 #define CM_BEAMFORMING_CAP_WEIGHTAGE 2 #define CM_PCL_WEIGHT 10 #define CM_CHANNEL_CONGESTION_WEIGHTAGE 5 @@ -93,6 +94,21 @@ #define CM_MAX_PCT_SCORE 100 #define CM_MAX_INDEX_PER_INI 4 +/** + * This macro give percentage value of security_weightage to be used as per + * security Eg if AP security is WPA 10% will be given for AP. + * + * Indexes are defined in this way. + * 0 Index (BITS 0-7): WPA - Def 25% + * 1 Index (BITS 8-15): WPA2- Def 50% + * 2 Index (BITS 16-23): WPA3- Def 100% + * 3 Index (BITS 24-31): reserved + * + * if AP security is Open/WEP 0% will be given for AP + * These percentage values are stored in HEX. For any index max value, can be 64 + */ +#define CM_SECURITY_INDEX_WEIGHTAGE 0x00643219 + #define CM_BEST_CANDIDATE_MAX_BSS_SCORE (CM_BEST_CANDIDATE_MAX_WEIGHT * 100) #define CM_AVOID_CANDIDATE_MIN_SCORE 1 @@ -535,6 +551,68 @@ static int32_t cm_calculate_nss_score(struct wlan_objmgr_psoc *psoc, prorated_pct) / CM_MAX_PCT_SCORE; } +static int32_t cm_calculate_security_score(struct scoring_cfg *score_config, + struct security_info neg_sec_info) +{ + uint32_t authmode, key_mgmt, ucastcipherset; + uint8_t score_pct = 0; + + authmode = neg_sec_info.authmodeset; + key_mgmt = neg_sec_info.key_mgmt; + ucastcipherset = neg_sec_info.ucastcipherset; + + if (QDF_HAS_PARAM(authmode, WLAN_CRYPTO_AUTH_FILS_SK) || + QDF_HAS_PARAM(authmode, WLAN_CRYPTO_AUTH_SAE) || + QDF_HAS_PARAM(authmode, WLAN_CRYPTO_AUTH_CCKM) || + QDF_HAS_PARAM(authmode, WLAN_CRYPTO_AUTH_RSNA) || + QDF_HAS_PARAM(authmode, WLAN_CRYPTO_AUTH_8021X)) { + if (QDF_HAS_PARAM(key_mgmt, WLAN_CRYPTO_KEY_MGMT_SAE) || + QDF_HAS_PARAM(key_mgmt, WLAN_CRYPTO_KEY_MGMT_FT_SAE) || + QDF_HAS_PARAM(key_mgmt, + WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SUITE_B) || + QDF_HAS_PARAM(key_mgmt, + WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SUITE_B_192) || + QDF_HAS_PARAM(key_mgmt, WLAN_CRYPTO_KEY_MGMT_FILS_SHA256) || + QDF_HAS_PARAM(key_mgmt, WLAN_CRYPTO_KEY_MGMT_FILS_SHA384) || + QDF_HAS_PARAM(key_mgmt, + WLAN_CRYPTO_KEY_MGMT_FT_FILS_SHA256) || + QDF_HAS_PARAM(key_mgmt, + WLAN_CRYPTO_KEY_MGMT_FT_FILS_SHA384) || + QDF_HAS_PARAM(key_mgmt, WLAN_CRYPTO_KEY_MGMT_OWE) || + QDF_HAS_PARAM(key_mgmt, WLAN_CRYPTO_KEY_MGMT_DPP) || + QDF_HAS_PARAM(key_mgmt, + WLAN_CRYPTO_KEY_MGMT_FT_IEEE8021X_SHA384)) { + /*If security is WPA3, consider score_pct = 100%*/ + score_pct = CM_GET_SCORE_PERCENTAGE( + score_config->security_weight_per_index, + CM_SECURITY_WPA3_INDEX); + } else if (QDF_HAS_PARAM(key_mgmt, WLAN_CRYPTO_KEY_MGMT_PSK) || + QDF_HAS_PARAM(key_mgmt, + WLAN_CRYPTO_KEY_MGMT_FT_IEEE8021X) || + QDF_HAS_PARAM(key_mgmt, + WLAN_CRYPTO_KEY_MGMT_FT_PSK) || + QDF_HAS_PARAM(key_mgmt, + WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SHA256) || + QDF_HAS_PARAM(key_mgmt, + WLAN_CRYPTO_KEY_MGMT_PSK_SHA256)) { + /*If security is WPA2, consider score_pct = 50%*/ + score_pct = CM_GET_SCORE_PERCENTAGE( + score_config->security_weight_per_index, + CM_SECURITY_WPA2_INDEX); + } + } else if (QDF_HAS_PARAM(authmode, WLAN_CRYPTO_AUTH_SHARED) || + QDF_HAS_PARAM(authmode, WLAN_CRYPTO_AUTH_WPA) || + QDF_HAS_PARAM(authmode, WLAN_CRYPTO_AUTH_WAPI)) { + /*If security is WPA, consider score_pct = 25%*/ + score_pct = CM_GET_SCORE_PERCENTAGE( + score_config->security_weight_per_index, + CM_SECURITY_WPA_INDEX); + } + + return (score_config->weight_config.security_weightage * score_pct) / + CM_MAX_PCT_SCORE; +} + #ifdef WLAN_POLICY_MGR_ENABLE static uint32_t cm_get_sta_nss(struct wlan_objmgr_psoc *psoc, qdf_freq_t bss_channel_freq, @@ -1401,6 +1479,7 @@ static int cm_calculate_bss_score(struct wlan_objmgr_psoc *psoc, int32_t beamformee_score = 0; int32_t band_score = 0; int32_t nss_score = 0; + int32_t security_score = 0; int32_t congestion_score = 0; int32_t congestion_pct = 0; int32_t oce_wan_score = 0; @@ -1581,7 +1660,16 @@ static int cm_calculate_bss_score(struct wlan_objmgr_psoc *psoc, prorated_pcnt, sta_nss); score += nss_score; - mlme_nofl_debug("Candidate("QDF_MAC_ADDR_FMT" freq %d): rssi %d HT %d VHT %d HE %d su bfer %d phy %d air time frac %d qbss %d cong_pct %d NSS %d ap_tx_pwr_dbm %d oce_subnet_id_present %d sae_pk_cap_present %d prorated_pcnt %d", + /* + * Since older FW will stick to the single AKM for roaming, + * no need to check the fw capability. + */ + security_score = cm_calculate_security_score(score_config, + entry->neg_sec_info); + + score += security_score; + + mlme_nofl_debug("Candidate("QDF_MAC_ADDR_FMT" freq %d): rssi %d HT %d VHT %d HE %d su bfer %d phy %d air time frac %d qbss %d cong_pct %d NSS %d ap_tx_pwr_dbm %d oce_subnet_id_present %d sae_pk_cap_present %d prorated_pcnt %d keymgmt 0x%x", QDF_MAC_ADDR_REF(entry->bssid.bytes), entry->channel.chan_freq, entry->rssi_raw, util_scan_entry_htcap(entry) ? 1 : 0, @@ -1590,14 +1678,15 @@ static int cm_calculate_bss_score(struct wlan_objmgr_psoc *psoc, entry->phy_mode, entry->air_time_fraction, entry->qbss_chan_load, congestion_pct, entry->nss, ap_tx_pwr_dbm, oce_subnet_id_present, - sae_pk_cap_present, prorated_pcnt); + sae_pk_cap_present, prorated_pcnt, + entry->neg_sec_info.key_mgmt); - mlme_nofl_debug("Scores: rssi %d pcl %d ht %d vht %d he %d bfee %d bw %d band %d congestion %d nss %d oce wan %d oce ap tx pwr %d subnet %d sae_pk %d TOTAL %d", + mlme_nofl_debug("Scores: rssi %d pcl %d ht %d vht %d he %d bfee %d bw %d band %d congestion %d nss %d oce wan %d oce ap tx pwr %d subnet %d sae_pk %d security %d TOTAL %d", rssi_score, pcl_score, ht_score, vht_score, he_score, beamformee_score, bandwidth_score, band_score, congestion_score, nss_score, oce_wan_score, oce_ap_tx_pwr_score, oce_subnet_id_score, - sae_pk_score, score); + sae_pk_score, security_score, score); entry->bss_score = score; @@ -2019,6 +2108,7 @@ void wlan_cm_init_score_config(struct wlan_objmgr_psoc *psoc, cfg_get(psoc, CFG_OCE_SUBNET_ID_WEIGHTAGE); score_cfg->weight_config.sae_pk_ap_weightage = cfg_get(psoc, CFG_SAE_PK_AP_WEIGHTAGE); + score_cfg->weight_config.security_weightage = CM_SECURITY_WEIGHTAGE; total_weight = score_cfg->weight_config.rssi_weightage + score_cfg->weight_config.ht_caps_weightage + @@ -2033,7 +2123,8 @@ void wlan_cm_init_score_config(struct wlan_objmgr_psoc *psoc, score_cfg->weight_config.oce_wan_weightage + score_cfg->weight_config.oce_ap_tx_pwr_weightage + score_cfg->weight_config.oce_subnet_id_weightage + - score_cfg->weight_config.sae_pk_ap_weightage; + score_cfg->weight_config.sae_pk_ap_weightage + + score_cfg->weight_config.security_weightage; /* * If configured weights are greater than max weight, @@ -2134,4 +2225,5 @@ void wlan_cm_init_score_config(struct wlan_objmgr_psoc *psoc, cfg_get(psoc, CFG_VENDOR_ROAM_SCORE_ALGORITHM); score_cfg->check_assoc_disallowed = true; cm_fill_6ghz_params(psoc, score_cfg); + score_cfg->security_weight_per_index = CM_SECURITY_INDEX_WEIGHTAGE; } diff --git a/umac/mlme/connection_mgr/dispatcher/inc/wlan_cm_bss_score_param.h b/umac/mlme/connection_mgr/dispatcher/inc/wlan_cm_bss_score_param.h index 55388bd0b9d1..5ddb522b0923 100644 --- a/umac/mlme/connection_mgr/dispatcher/inc/wlan_cm_bss_score_param.h +++ b/umac/mlme/connection_mgr/dispatcher/inc/wlan_cm_bss_score_param.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. - * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. + * Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -41,6 +41,7 @@ * @oce_ap_tx_pwr_weightage: OCE AP tx power weigtage * @oce_subnet_id_weightage: OCE subnet id weigtage * @sae_pk_ap_weightage: SAE-PK AP weigtage + * @security_weightage: Security weightage */ struct weight_cfg { uint8_t rssi_weightage; @@ -57,6 +58,7 @@ struct weight_cfg { uint8_t oce_ap_tx_pwr_weightage; uint8_t oce_subnet_id_weightage; uint8_t sae_pk_ap_weightage; + uint8_t security_weightage; }; /** @@ -132,6 +134,8 @@ struct per_slot_score { * @check_6ghz_security: check security for 6Ghz candidate * @standard_6ghz_conn_policy: check for 6 GHz standard connection policy * @key_mgmt_mask_6ghz: user configurable mask for 6ghz AKM + * @roam_tgt_score_cap: Roam score capability + * @security_weight_per_index: security weight per index */ struct scoring_cfg { struct weight_cfg weight_config; @@ -147,6 +151,8 @@ struct scoring_cfg { uint8_t check_6ghz_security; uint8_t standard_6ghz_conn_policy:1; uint32_t key_mgmt_mask_6ghz; + uint32_t roam_tgt_score_cap; + uint32_t security_weight_per_index; }; /** @@ -207,6 +213,14 @@ wlan_blacklist_action_on_bssid(struct wlan_objmgr_pdev *pdev, } #endif +enum cm_security_idx { + CM_SECURITY_WPA_INDEX, + CM_SECURITY_WPA2_INDEX, + CM_SECURITY_WPA3_INDEX, + CM_SECURITY_WPA_OPEN_WEP_INDEX, + CM_MAX_SECURITY_INDEX +}; + /** * wlan_cm_calculate_bss_score() - calculate bss score for the scan list * @pdev: pointer to pdev object