Commit 3bb1ccc4 authored by Johannes Berg's avatar Johannes Berg

cfg80211: simplify cfg80211_chandef_valid()

There are a lot of duplicate checks in this function to
check the delta between the control channel and CF1.
With the addition of 320 MHz, this will become even more.
Simplify the code so that the common checks are done
only once for multiple bandwidths.
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
Signed-off-by: default avatarLuca Coelho <luciano.coelho@intel.com>
Link: https://lore.kernel.org/r/iwlwifi.20211129152938.2d0240b07f11.I759e8e990f5386ba2b56ffb2488a8d4e16e22c1b@changeidSigned-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent cee04f3c
...@@ -245,19 +245,7 @@ bool cfg80211_chandef_valid(const struct cfg80211_chan_def *chandef) ...@@ -245,19 +245,7 @@ bool cfg80211_chandef_valid(const struct cfg80211_chan_def *chandef)
oper_freq - MHZ_TO_KHZ(oper_width) / 2) oper_freq - MHZ_TO_KHZ(oper_width) / 2)
return false; return false;
break; break;
case NL80211_CHAN_WIDTH_40:
if (chandef->center_freq1 != control_freq + 10 &&
chandef->center_freq1 != control_freq - 10)
return false;
if (chandef->center_freq2)
return false;
break;
case NL80211_CHAN_WIDTH_80P80: case NL80211_CHAN_WIDTH_80P80:
if (chandef->center_freq1 != control_freq + 30 &&
chandef->center_freq1 != control_freq + 10 &&
chandef->center_freq1 != control_freq - 10 &&
chandef->center_freq1 != control_freq - 30)
return false;
if (!chandef->center_freq2) if (!chandef->center_freq2)
return false; return false;
/* adjacent is not allowed -- that's a 160 MHz channel */ /* adjacent is not allowed -- that's a 160 MHz channel */
...@@ -265,28 +253,42 @@ bool cfg80211_chandef_valid(const struct cfg80211_chan_def *chandef) ...@@ -265,28 +253,42 @@ bool cfg80211_chandef_valid(const struct cfg80211_chan_def *chandef)
chandef->center_freq2 - chandef->center_freq1 == 80) chandef->center_freq2 - chandef->center_freq1 == 80)
return false; return false;
break; break;
case NL80211_CHAN_WIDTH_80: default:
if (chandef->center_freq1 != control_freq + 30 &&
chandef->center_freq1 != control_freq + 10 &&
chandef->center_freq1 != control_freq - 10 &&
chandef->center_freq1 != control_freq - 30)
return false;
if (chandef->center_freq2) if (chandef->center_freq2)
return false; return false;
break; break;
case NL80211_CHAN_WIDTH_160: }
if (chandef->center_freq1 != control_freq + 70 &&
chandef->center_freq1 != control_freq + 50 && switch (chandef->width) {
chandef->center_freq1 != control_freq + 30 && case NL80211_CHAN_WIDTH_5:
chandef->center_freq1 != control_freq + 10 && case NL80211_CHAN_WIDTH_10:
chandef->center_freq1 != control_freq - 10 && case NL80211_CHAN_WIDTH_20:
chandef->center_freq1 != control_freq - 30 && case NL80211_CHAN_WIDTH_20_NOHT:
chandef->center_freq1 != control_freq - 50 && case NL80211_CHAN_WIDTH_1:
chandef->center_freq1 != control_freq - 70) case NL80211_CHAN_WIDTH_2:
return false; case NL80211_CHAN_WIDTH_4:
if (chandef->center_freq2) case NL80211_CHAN_WIDTH_8:
return false; case NL80211_CHAN_WIDTH_16:
/* all checked above */
break; break;
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: default:
return false; return false;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment