d115dd2e54005ee7339c32ff78475abba26ccd11
[openwrt/staging/wigyori.git] /
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
4 valid on a radio
5
6 Check if the full channel width is in the radio's frequency range.
7
8 Signed-off-by: Felix Fietkau <nbd@nbd.name>
9 ---
10
11 --- a/include/net/cfg80211.h
12 +++ b/include/net/cfg80211.h
13 @@ -6485,6 +6485,15 @@ static inline bool cfg80211_channel_is_p
14 }
15
16 /**
17 + * cfg80211_radio_chandef_valid - Check if the radio supports the chandef
18 + *
19 + * @radio: wiphy radio
20 + * @chandef: chandef for current channel
21 + */
22 +bool cfg80211_radio_chandef_valid(const struct wiphy_radio *radio,
23 + const struct cfg80211_chan_def *chandef);
24 +
25 +/**
26 * ieee80211_get_response_rate - get basic rate for a given rate
27 *
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
32 return NULL;
33 }
34 EXPORT_SYMBOL(cfg80211_get_iftype_ext_capa);
35 +
36 +static bool
37 +ieee80211_radio_freq_range_valid(const struct wiphy_radio *radio,
38 + u32 freq, u32 width)
39 +{
40 + const struct wiphy_radio_freq_range *r;
41 + int i;
42 +
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)
47 + return true;
48 + }
49 +
50 + return false;
51 +}
52 +
53 +bool cfg80211_radio_chandef_valid(const struct wiphy_radio *radio,
54 + const struct cfg80211_chan_def *chandef)
55 +{
56 + u32 freq, width;
57 +
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))
61 + return false;
62 +
63 + freq = MHZ_TO_KHZ(chandef->center_freq2);
64 + if (freq && !ieee80211_radio_freq_range_valid(radio, freq, width))
65 + return false;
66 +
67 + return true;
68 +}
69 +EXPORT_SYMBOL(cfg80211_radio_chandef_valid);