1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Fri, 7 Jun 2024 17:58:54 +0200
3 Subject: [PATCH] wifi: cfg80211: add helper for checking if a chandef is
6 Check if the full channel width is in the radio's frequency range.
8 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 --- a/include/net/cfg80211.h
12 +++ b/include/net/cfg80211.h
13 @@ -6485,6 +6485,15 @@ static inline bool cfg80211_channel_is_p
17 + * cfg80211_radio_chandef_valid - Check if the radio supports the chandef
19 + * @radio: wiphy radio
20 + * @chandef: chandef for current channel
22 +bool cfg80211_radio_chandef_valid(const struct wiphy_radio *radio,
23 + const struct cfg80211_chan_def *chandef);
26 * ieee80211_get_response_rate - get basic rate for a given rate
28 * @sband: the band to look for rates in
29 --- a/net/wireless/util.c
30 +++ b/net/wireless/util.c
31 @@ -2884,3 +2884,38 @@ cfg80211_get_iftype_ext_capa(struct wiph
34 EXPORT_SYMBOL(cfg80211_get_iftype_ext_capa);
37 +ieee80211_radio_freq_range_valid(const struct wiphy_radio *radio,
38 + u32 freq, u32 width)
40 + const struct wiphy_radio_freq_range *r;
43 + for (i = 0; i < radio->n_freq_range; i++) {
44 + r = &radio->freq_range[i];
45 + if (freq - width / 2 >= r->start_freq &&
46 + freq + width / 2 <= r->end_freq)
53 +bool cfg80211_radio_chandef_valid(const struct wiphy_radio *radio,
54 + const struct cfg80211_chan_def *chandef)
58 + freq = ieee80211_chandef_to_khz(chandef);
59 + width = nl80211_chan_width_to_mhz(chandef->width);
60 + if (!ieee80211_radio_freq_range_valid(radio, freq, width))
63 + freq = MHZ_TO_KHZ(chandef->center_freq2);
64 + if (freq && !ieee80211_radio_freq_range_valid(radio, freq, width))
69 +EXPORT_SYMBOL(cfg80211_radio_chandef_valid);