From c44da224706b8d394232bbc64faa99124bda7f50 Mon Sep 17 00:00:00 2001 From: Tim Kourt Date: Thu, 11 Apr 2019 12:14:27 -0700 Subject: [PATCH] wiphy: Add freq set constrain API --- src/scan.c | 17 +++++++++++++++++ src/scan.h | 2 ++ src/wiphy.c | 12 ++++++++++++ src/wiphy.h | 4 ++++ 4 files changed, 35 insertions(+) diff --git a/src/scan.c b/src/scan.c index ac298d66..1da4b5cc 100644 --- a/src/scan.c +++ b/src/scan.c @@ -1725,6 +1725,23 @@ void scan_freq_set_foreach(const struct scan_freq_set *freqs, } } +void scan_freq_set_constrain(struct scan_freq_set *set, + const struct scan_freq_set *constraint) +{ + struct l_uintset *intersection; + + intersection = l_uintset_intersect(constraint->channels_5ghz, + set->channels_5ghz); + if (!intersection) + /* This shouldn't ever be the case. */ + return; + + l_uintset_free(set->channels_5ghz); + set->channels_5ghz = intersection; + + set->channels_2ghz &= constraint->channels_2ghz; +} + bool scan_init(struct l_genl_family *in) { const struct l_settings *config = iwd_get_config(); diff --git a/src/scan.h b/src/scan.h index 436ea439..ce7a1a34 100644 --- a/src/scan.h +++ b/src/scan.h @@ -126,6 +126,8 @@ void scan_freq_set_foreach(const struct scan_freq_set *freqs, scan_freq_set_func_t func, void *user_data); void scan_freq_set_merge(struct scan_freq_set *to, const struct scan_freq_set *from); +void scan_freq_set_constrain(struct scan_freq_set *set, + const struct scan_freq_set *constraint); bool scan_ifindex_add(uint32_t ifindex); bool scan_ifindex_remove(uint32_t ifindex); diff --git a/src/wiphy.c b/src/wiphy.c index 953fa0db..2d6d0b40 100644 --- a/src/wiphy.c +++ b/src/wiphy.c @@ -306,6 +306,18 @@ bool wiphy_supports_adhoc_rsn(struct wiphy *wiphy) return wiphy->support_adhoc_rsn; } +bool wiphy_constrain_freq_set(const struct wiphy *wiphy, + struct scan_freq_set *set) +{ + scan_freq_set_constrain(set, wiphy->supported_freqs); + + if (!scan_freq_set_get_bands(set)) + /* The set is empty. */ + return false; + + return true; +} + static char **wiphy_get_supported_iftypes(struct wiphy *wiphy, uint16_t mask) { uint16_t supported_mask = wiphy->supported_iftypes & mask; diff --git a/src/wiphy.h b/src/wiphy.h index 7172716b..4b98b7be 100644 --- a/src/wiphy.h +++ b/src/wiphy.h @@ -25,6 +25,7 @@ struct wiphy; struct scan_bss; +struct scan_freq_set; enum wiphy_state_watch_event { WIPHY_STATE_WATCH_EVENT_POWERED, @@ -50,6 +51,9 @@ struct wiphy *wiphy_create(uint32_t wiphy_id, const char *name); bool wiphy_destroy(struct wiphy *wiphy); void wiphy_update_from_genl(struct wiphy *wiphy, struct l_genl_msg *msg); +bool wiphy_constrain_freq_set(const struct wiphy *wiphy, + struct scan_freq_set *set); + const char *wiphy_get_path(struct wiphy *wiphy); uint32_t wiphy_get_supported_bands(struct wiphy *wiphy); const struct scan_freq_set *wiphy_get_supported_freqs(