From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.linux.dev
Cc: James Prestwood <prestwoj@gmail.com>
Subject: [PATCH v3 5/8] wiphy: add getter for frequency/band info
Date: Fri, 16 Dec 2022 13:27:38 -0800 [thread overview]
Message-ID: <20221216212741.1833286-5-prestwoj@gmail.com> (raw)
In-Reply-To: <20221216212741.1833286-1-prestwoj@gmail.com>
This adds two new APIs:
wiphy_get_frequency_info(): Used to get information about a given
frequency such as disabled/no-IR. This can also be used to check
if the frequency is supported (NULL return is unsupported).
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 | 91 +++++++++++++++++++++++++++++++++++++----------------
src/wiphy.h | 5 +++
2 files changed, 69 insertions(+), 27 deletions(-)
diff --git a/src/wiphy.c b/src/wiphy.c
index f3a2a039..714da9bc 100644
--- a/src/wiphy.c
+++ b/src/wiphy.c
@@ -496,6 +496,67 @@ 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;
+ }
+}
+
+const struct band_freq_attrs *wiphy_get_frequency_info(
+ const struct wiphy *wiphy,
+ uint32_t freq)
+{
+ 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 NULL;
+
+ bandp = wiphy_get_band(wiphy, band);
+ if (!bandp)
+ return NULL;
+
+ attr = &bandp->freq_attrs[channel];
+ if (!attr->supported)
+ return NULL;
+
+ return attr;
+}
+
+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 true;
+
+ 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;
@@ -819,21 +880,7 @@ const uint8_t *wiphy_get_supported_rates(struct wiphy *wiphy,
enum band_freq band,
unsigned int *out_num)
{
- struct band *bandp;
-
- switch (band) {
- case BAND_FREQ_2_4_GHZ:
- bandp = wiphy->band_2g;
- break;
- case BAND_FREQ_5_GHZ:
- bandp = wiphy->band_5g;
- break;
- case BAND_FREQ_6_GHZ:
- bandp = wiphy->band_6g;
- break;
- default:
- return NULL;
- }
+ struct band *bandp = wiphy_get_band(wiphy, band);
if (!bandp)
return NULL;
@@ -891,19 +938,9 @@ int wiphy_estimate_data_rate(struct wiphy *wiphy,
if (band_freq_to_channel(bss->frequency, &band) == 0)
return -ENOTSUP;
- switch (band) {
- case BAND_FREQ_2_4_GHZ:
- bandp = wiphy->band_2g;
- break;
- case BAND_FREQ_5_GHZ:
- bandp = wiphy->band_5g;
- break;
- case BAND_FREQ_6_GHZ:
- bandp = wiphy->band_6g;
- break;
- default:
+ bandp = wiphy_get_band(wiphy, band);
+ if (!bandp)
return -ENOTSUP;
- }
ie_tlv_iter_init(&iter, ies, ies_len);
diff --git a/src/wiphy.h b/src/wiphy.h
index 09dc4530..c1919b4c 100644
--- a/src/wiphy.h
+++ b/src/wiphy.h
@@ -102,6 +102,11 @@ 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);
+const struct band_freq_attrs *wiphy_get_frequency_info(
+ const struct wiphy *wiphy,
+ uint32_t freq);
+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);
--
2.34.3
next prev parent reply other threads:[~2022-12-16 21:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-16 21:27 [PATCH v3 1/8] band: introduce new method of tracking frequencies James Prestwood
2022-12-16 21:27 ` [PATCH v3 2/8] wiphy: parse/store frequency info in band object James Prestwood
2022-12-16 21:27 ` [PATCH v3 3/8] wiphy: remove pending_freqs from wiphy_regdom_is_updating James Prestwood
2022-12-16 21:27 ` [PATCH v3 4/8] wiphy: don't parse dumps from unregistered wiphy's James Prestwood
2022-12-16 21:27 ` James Prestwood [this message]
2022-12-16 21:27 ` [PATCH v3 6/8] station: use wiphy_get_frequency_info James Prestwood
2022-12-16 21:27 ` [PATCH v3 7/8] ap: " James Prestwood
2022-12-16 21:27 ` [PATCH v3 8/8] wiphy: remove disabled_freqs and related dump code James Prestwood
2022-12-16 22:37 ` [PATCH v3 1/8] band: introduce new method of tracking frequencies Denis Kenzior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221216212741.1833286-5-prestwoj@gmail.com \
--to=prestwoj@gmail.com \
--cc=iwd@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox