aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2024-01-29 19:34:48 +0100
committerJohannes Berg <johannes.berg@intel.com>2024-02-08 13:07:38 +0100
commit8616f27b3fb0d47be053d7bebc9539171a514917 (patch)
tree8f1ceb4073b4dfb925fb01b227613ff60479634b /net/mac80211
parent8f251a0a1566e3e1da0f1d9322c8ffae808a7509 (diff)
downloadlinux-8616f27b3fb0d47be053d7bebc9539171a514917.tar.gz
wifi: mac80211: use cfg80211_chandef_primary_freq()
Instead of calculating the new primary 40/80/160 MHz center frequency here, use the new helper function from cfg80211. Link: https://msgid.link/20240129194108.eb59d6433d18.I74b745f0d1a32e779fb25d50c56407be7c35b840@changeid Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'net/mac80211')
-rw-r--r--net/mac80211/util.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 49eef33b5e7029..63a88169d53d3e 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -4365,8 +4365,9 @@ EXPORT_SYMBOL(ieee80211_radar_detected);
void ieee80211_chandef_downgrade(struct cfg80211_chan_def *c,
struct ieee80211_conn_settings *conn)
{
+ /* no-HT indicates nothing to do */
+ enum nl80211_chan_width new_primary_width = NL80211_CHAN_WIDTH_20_NOHT;
struct ieee80211_conn_settings _ignored = {};
- int tmp;
/* allow passing NULL if caller doesn't care */
if (!conn)
@@ -4390,12 +4391,7 @@ void ieee80211_chandef_downgrade(struct cfg80211_chan_def *c,
conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20;
break;
case NL80211_CHAN_WIDTH_80:
- tmp = (30 + c->chan->center_freq - c->center_freq1)/20;
- /* n_P40 */
- tmp /= 2;
- /* freq_P40 */
- c->center_freq1 = c->center_freq1 - 20 + 40 * tmp;
- c->width = NL80211_CHAN_WIDTH_40;
+ new_primary_width = NL80211_CHAN_WIDTH_40;
if (conn->mode == IEEE80211_CONN_MODE_VHT)
conn->mode = IEEE80211_CONN_MODE_HT;
conn->bw_limit = IEEE80211_CONN_BW_LIMIT_40;
@@ -4406,21 +4402,11 @@ void ieee80211_chandef_downgrade(struct cfg80211_chan_def *c,
conn->bw_limit = IEEE80211_CONN_BW_LIMIT_80;
break;
case NL80211_CHAN_WIDTH_160:
- /* n_P20 */
- tmp = (70 + c->chan->center_freq - c->center_freq1)/20;
- /* n_P80 */
- tmp /= 4;
- c->center_freq1 = c->center_freq1 - 40 + 80 * tmp;
- c->width = NL80211_CHAN_WIDTH_80;
+ new_primary_width = NL80211_CHAN_WIDTH_80;
conn->bw_limit = IEEE80211_CONN_BW_LIMIT_80;
break;
case NL80211_CHAN_WIDTH_320:
- /* n_P20 */
- tmp = (150 + c->chan->center_freq - c->center_freq1) / 20;
- /* n_P160 */
- tmp /= 8;
- c->center_freq1 = c->center_freq1 - 80 + 160 * tmp;
- c->width = NL80211_CHAN_WIDTH_160;
+ new_primary_width = NL80211_CHAN_WIDTH_160;
conn->bw_limit = IEEE80211_CONN_BW_LIMIT_160;
break;
case NL80211_CHAN_WIDTH_1:
@@ -4442,6 +4428,12 @@ void ieee80211_chandef_downgrade(struct cfg80211_chan_def *c,
break;
}
+ if (new_primary_width != NL80211_CHAN_WIDTH_20_NOHT) {
+ c->center_freq1 =
+ cfg80211_chandef_primary_freq(c, new_primary_width);
+ c->width = new_primary_width;
+ }
+
WARN_ON_ONCE(!cfg80211_chandef_valid(c));
}