From e4fb9786c5801b29228d8104c7f9f7093204abdd Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Mon, 25 Sep 2023 11:54:17 -0700 Subject: [PATCH] scan: add scan_get_band_rank_modifier This exposes the [Rank].BandModifier* settings so other modules can use then. Doing this will allow user-disabling of certain bands by setting these modifier values to 0.0. --- src/scan.c | 41 ++++++++++++++++++++++++++++++----------- src/scan.h | 3 +++ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/scan.c b/src/scan.c index 3979dc03..915e2875 100644 --- a/src/scan.c +++ b/src/scan.c @@ -2310,6 +2310,33 @@ bool scan_get_firmware_scan(uint64_t wdev_id, scan_notify_func_t notify, return true; } +double scan_get_band_rank_modifier(enum band_freq band) +{ + const struct l_settings *config = iwd_get_config(); + double modifier; + char *str; + + switch (band) { + case BAND_FREQ_2_4_GHZ: + str = "BandModifier2_4Ghz"; + break; + case BAND_FREQ_5_GHZ: + str = "BandModifier5Ghz"; + break; + case BAND_FREQ_6_GHZ: + str = "BandModifier6Ghz"; + break; + default: + l_warn("Unhandled band %u", band); + return 0.0; + } + + if (!l_settings_get_double(config, "Rank", str, &modifier)) + modifier = 1.0; + + return modifier; +} + bool scan_wdev_add(uint64_t wdev_id) { struct scan_context *sc; @@ -2359,17 +2386,9 @@ static int scan_init(void) scan_contexts = l_queue_new(); - if (!l_settings_get_double(config, "Rank", "BandModifier2_4Ghz", - &RANK_2G_FACTOR)) - RANK_2G_FACTOR = 1.0; - - if (!l_settings_get_double(config, "Rank", "BandModifier5Ghz", - &RANK_5G_FACTOR)) - RANK_5G_FACTOR = 1.0; - - if (!l_settings_get_double(config, "Rank", "BandModifier6Ghz", - &RANK_6G_FACTOR)) - RANK_6G_FACTOR = 1.0; + RANK_2G_FACTOR = scan_get_band_rank_modifier(BAND_FREQ_2_4_GHZ); + RANK_5G_FACTOR = scan_get_band_rank_modifier(BAND_FREQ_5_GHZ); + RANK_6G_FACTOR = scan_get_band_rank_modifier(BAND_FREQ_6_GHZ); if (!l_settings_get_uint(config, "Scan", "InitialPeriodicScanInterval", &SCAN_INIT_INTERVAL)) diff --git a/src/scan.h b/src/scan.h index 0e06dabe..0db7752d 100644 --- a/src/scan.h +++ b/src/scan.h @@ -29,6 +29,7 @@ struct p2p_beacon; struct mmpdu_header; struct wiphy; enum security; +enum band_freq; enum scan_state { SCAN_STATE_NOT_RUNNING, @@ -170,5 +171,7 @@ struct scan_bss *scan_bss_new_from_probe_req(const struct mmpdu_header *mpdu, size_t body_len, uint32_t frequency, int rssi); +double scan_get_band_rank_modifier(enum band_freq band); + bool scan_wdev_add(uint64_t wdev_id); bool scan_wdev_remove(uint64_t wdev_id);