diff mbox series

[v2,5/8] wiphy: add getter for frequency/band info

Message ID 20221216172606.1799396-5-prestwoj@gmail.com (mailing list archive)
State New
Headers show
Series [v2,1/8] band: introduce new method of tracking frequencies | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-ci-gitlint success GitLint

Commit Message

James Prestwood Dec. 16, 2022, 5:26 p.m. UTC
This adds two new APIs:

wiphy_get_frequency_info(): Used to get additional information about
a given frequency such as disabled/no-IR. This can also be used to
check if the frequency is supported.

wiphy_band_is_disabled(): Checks if a band is disabled. Note that
an unsupported band will also return true. Checking support should
be done with wiphy_get_supported_bands()
---
 src/wiphy.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/wiphy.h |  4 ++++
 2 files changed, 67 insertions(+)
diff mbox series

Patch

diff --git a/src/wiphy.c b/src/wiphy.c
index f3a2a039..7b72b6be 100644
--- a/src/wiphy.c
+++ b/src/wiphy.c
@@ -496,6 +496,69 @@  const struct scan_freq_set *wiphy_get_disabled_freqs(const struct wiphy *wiphy)
 	return wiphy->disabled_freqs;
 }
 
+static struct band *wiphy_get_band(const struct wiphy *wiphy, enum band_freq band)
+{
+	switch (band) {
+	case BAND_FREQ_2_4_GHZ:
+		return wiphy->band_2g;
+	case BAND_FREQ_5_GHZ:
+		return wiphy->band_5g;
+	case BAND_FREQ_6_GHZ:
+		return wiphy->band_6g;
+	default:
+		return NULL;
+	}
+}
+
+bool wiphy_get_frequency_info(const struct wiphy *wiphy, uint32_t freq,
+				struct band_freq_attrs *attr_out)
+{
+	struct band_freq_attrs attr;
+	enum band_freq band;
+	uint8_t channel;
+	struct band *bandp;
+
+	channel = band_freq_to_channel(freq, &band);
+	if (!channel)
+		return false;
+
+	bandp = wiphy_get_band(wiphy, band);
+	if (!bandp)
+		return false;
+
+	attr = bandp->freq_attrs[channel];
+	if (!attr.supported)
+		return false;
+
+	if (attr_out)
+		*attr_out = attr;
+
+	return true;
+}
+
+bool wiphy_band_is_disabled(const struct wiphy *wiphy, enum band_freq band)
+{
+	struct band_freq_attrs attr;
+	unsigned int i;
+	struct band *bandp;
+
+	bandp = wiphy_get_band(wiphy, band);
+	if (!bandp)
+		return false;
+
+	for (i = 0; i < bandp->freqs_len; i++) {
+		attr = bandp->freq_attrs[i];
+
+		if (!attr.supported)
+			continue;
+
+		if (!attr.disabled)
+			return false;
+	}
+
+	return true;
+}
+
 bool wiphy_supports_probe_resp_offload(struct wiphy *wiphy)
 {
 	return wiphy->ap_probe_resp_offload;
diff --git a/src/wiphy.h b/src/wiphy.h
index 09dc4530..8411318a 100644
--- a/src/wiphy.h
+++ b/src/wiphy.h
@@ -102,6 +102,10 @@  const struct scan_freq_set *wiphy_get_supported_freqs(
 						const struct wiphy *wiphy);
 const struct scan_freq_set *wiphy_get_disabled_freqs(const struct wiphy *wiphy);
 
+bool wiphy_get_frequency_info(const struct wiphy *wiphy, uint32_t freq,
+				struct band_freq_attrs *attr_out);
+bool wiphy_band_is_disabled(const struct wiphy *wiphy, enum band_freq band);
+
 bool wiphy_supports_probe_resp_offload(struct wiphy *wiphy);
 bool wiphy_can_transition_disable(struct wiphy *wiphy);
 bool wiphy_can_offload(struct wiphy *wiphy);