wifi: cfg80211: split control freq check from chandef check

In order to introduce NPCA later, split the control frequency
check out of cfg80211_chandef_valid().

Link: https://patch.msgid.link/20260303152641.11b31e4878a7.I534669506008e12ffcd6c115161777e528fdc838@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
Johannes Berg 2026-03-03 15:26:19 +01:00
parent f932856649
commit fd2905157d

View File

@ -6,7 +6,7 @@
*
* Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
* Copyright 2013-2014 Intel Mobile Communications GmbH
* Copyright 2018-2025 Intel Corporation
* Copyright 2018-2026 Intel Corporation
*/
#include <linux/export.h>
@ -339,6 +339,58 @@ static bool cfg80211_valid_center_freq(u32 center,
return (center - bw / 2 - 5945) % step == 0;
}
static bool
cfg80211_chandef_valid_control_freq(const struct cfg80211_chan_def *chandef,
u32 control_freq)
{
switch (chandef->width) {
case NL80211_CHAN_WIDTH_5:
case NL80211_CHAN_WIDTH_10:
case NL80211_CHAN_WIDTH_20:
case NL80211_CHAN_WIDTH_20_NOHT:
case NL80211_CHAN_WIDTH_1:
case NL80211_CHAN_WIDTH_2:
case NL80211_CHAN_WIDTH_4:
case NL80211_CHAN_WIDTH_8:
case NL80211_CHAN_WIDTH_16:
/* checked separately */
break;
case NL80211_CHAN_WIDTH_320:
if (chandef->center_freq1 == control_freq + 150 ||
chandef->center_freq1 == control_freq + 130 ||
chandef->center_freq1 == control_freq + 110 ||
chandef->center_freq1 == control_freq + 90 ||
chandef->center_freq1 == control_freq - 90 ||
chandef->center_freq1 == control_freq - 110 ||
chandef->center_freq1 == control_freq - 130 ||
chandef->center_freq1 == control_freq - 150)
break;
fallthrough;
case NL80211_CHAN_WIDTH_160:
if (chandef->center_freq1 == control_freq + 70 ||
chandef->center_freq1 == control_freq + 50 ||
chandef->center_freq1 == control_freq - 50 ||
chandef->center_freq1 == control_freq - 70)
break;
fallthrough;
case NL80211_CHAN_WIDTH_80P80:
case NL80211_CHAN_WIDTH_80:
if (chandef->center_freq1 == control_freq + 30 ||
chandef->center_freq1 == control_freq - 30)
break;
fallthrough;
case NL80211_CHAN_WIDTH_40:
if (chandef->center_freq1 == control_freq + 10 ||
chandef->center_freq1 == control_freq - 10)
break;
fallthrough;
default:
return false;
}
return true;
}
bool cfg80211_chandef_valid(const struct cfg80211_chan_def *chandef)
{
u32 control_freq, control_freq_khz, start_khz, end_khz;
@ -393,50 +445,8 @@ bool cfg80211_chandef_valid(const struct cfg80211_chan_def *chandef)
break;
}
switch (chandef->width) {
case NL80211_CHAN_WIDTH_5:
case NL80211_CHAN_WIDTH_10:
case NL80211_CHAN_WIDTH_20:
case NL80211_CHAN_WIDTH_20_NOHT:
case NL80211_CHAN_WIDTH_1:
case NL80211_CHAN_WIDTH_2:
case NL80211_CHAN_WIDTH_4:
case NL80211_CHAN_WIDTH_8:
case NL80211_CHAN_WIDTH_16:
/* all checked above */
break;
case NL80211_CHAN_WIDTH_320:
if (chandef->center_freq1 == control_freq + 150 ||
chandef->center_freq1 == control_freq + 130 ||
chandef->center_freq1 == control_freq + 110 ||
chandef->center_freq1 == control_freq + 90 ||
chandef->center_freq1 == control_freq - 90 ||
chandef->center_freq1 == control_freq - 110 ||
chandef->center_freq1 == control_freq - 130 ||
chandef->center_freq1 == control_freq - 150)
break;
fallthrough;
case NL80211_CHAN_WIDTH_160:
if (chandef->center_freq1 == control_freq + 70 ||
chandef->center_freq1 == control_freq + 50 ||
chandef->center_freq1 == control_freq - 50 ||
chandef->center_freq1 == control_freq - 70)
break;
fallthrough;
case NL80211_CHAN_WIDTH_80P80:
case NL80211_CHAN_WIDTH_80:
if (chandef->center_freq1 == control_freq + 30 ||
chandef->center_freq1 == control_freq - 30)
break;
fallthrough;
case NL80211_CHAN_WIDTH_40:
if (chandef->center_freq1 == control_freq + 10 ||
chandef->center_freq1 == control_freq - 10)
break;
fallthrough;
default:
if (!cfg80211_chandef_valid_control_freq(chandef, control_freq))
return false;
}
if (!cfg80211_valid_center_freq(chandef->center_freq1, chandef->width))
return false;