Skip to contentSkip to conversation

cfg80211: fix maximum tx power handling

PATCH New Felix Fietkau 1 participant 1 message Jan 29, 2011 802.11 (including cfg80211/NL80211)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cfg80211: fix maximum tx power handling

When setting a new regulatory domain after the initial one had been set by the driver, the original maximum power is overwritten with the new regulatory power value. This is wrong because chan->orig_mpwr is supposed to contain the hardware tx power limit.
Because of this, the displayed tx power is often much higher than what the hardware is actually capable of using.

Fix this by always using chan->orig_mpwr as a maximum and never overwriting it in the regulatory handling code.

---
 net/wireless/reg.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)
net/wireless/reg.c +6 -7
index c565689..2eb6eca 100644
@@ -838,6 +838,12 @@ static void handle_channel(struct wiphy *wiphy,
 	if (freq_range->max_bandwidth_khz < MHZ_TO_KHZ(40))
 		bw_flags = IEEE80211_CHAN_NO_HT40;
 
+	if (chan->orig_mpwr)
+		chan->max_power = min(chan->orig_mpwr,
+			(int) MBM_TO_DBM(power_rule->max_eirp));
+	else
+		chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp);
+
 	if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER &&
 	    request_wiphy && request_wiphy == wiphy &&
 	    request_wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY) {
@@ -850,19 +856,12 @@ static void handle_channel(struct wiphy *wiphy,
 			map_regdom_flags(reg_rule->flags) | bw_flags;
 		chan->max_antenna_gain = chan->orig_mag =
 			(int) MBI_TO_DBI(power_rule->max_antenna_gain);
-		chan->max_power = chan->orig_mpwr =
-			(int) MBM_TO_DBM(power_rule->max_eirp);
 		return;
 	}
 
 	chan->flags = flags | bw_flags | map_regdom_flags(reg_rule->flags);
 	chan->max_antenna_gain = min(chan->orig_mag,
 		(int) MBI_TO_DBI(power_rule->max_antenna_gain));
-	if (chan->orig_mpwr)
-		chan->max_power = min(chan->orig_mpwr,
-			(int) MBM_TO_DBM(power_rule->max_eirp));
-	else
-		chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp);
 }
 
 static void handle_band(struct wiphy *wiphy,
Signature · 1 line
1.7.3.2