Skip to contentSkip to conversation

Support Cisco DTPC IE to reduce transmit power

PATCH In review Steinar H. Gunderson 2 participants 26 messages Aug 23, 2014 – Oct 6, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Support Cisco DTPC IE to reduce transmit power

Hi,

I noticed the other day that Linux and Cisco don't always seem to speak the same language when it comes to reducing the client transmit power. I've written a quick patch to try to remedy it; please consider applying to the wireless tree.

/* Steinar */

Signature · 1 line
Homepage: http://www.sesse.net/
Quoted 1 line

From d8fc81539016ae8663b0f479ad95cc42f286ec0b Mon Sep 17 00:00:00 2001

From: "Steinar H. Gunderson" <[email protected]>
Date: Sat, 23 Aug 2014 23:22:08 +0200
Subject: [PATCH] Support DTPC IE (from Cisco Client eXtensions)

Linux already supports 802.11h, where the access point can tell the client to reduce its transmission power. However, 802.11h is only defined for 5 GHz, where the need for this is much smaller than on 2.4 GHz.

Cisco has their own solution, called DTPC (Dynamic Transmit Power Control). Cisco APs on a controller sometimes but not always send 802.11h; they always send DTPC, even on 2.4 GHz. This patch adds support for parsing and honoring the DTPC IE if there is no 802.11h element; the format is not documented, but very simple.

Tested (on top of wireless.git and on 3.16.1) against a Cisco Aironet 1142 joined to a Cisco 2504 WLC, by setting various transmit power levels for the given access points and observing the results. The Wireshark 802.11 dissector agrees with the interpretation of the element, except for negative numbers, which we guard against to be conservative.

---
 include/linux/ieee80211.h  |    3 ++-
 net/mac80211/ieee80211_i.h |    1 +
 net/mac80211/mlme.c        |   27 +++++++++++++++++++++++++++
 net/mac80211/util.c        |   19 +++++++++++++++++++
 4 files changed, 49 insertions(+), 1 deletion(-)
include/linux/ieee80211.h +2 -1
index 63ab3873..d0ec287 100644
@@ -1806,7 +1806,8 @@ enum ieee80211_eid {
 	WLAN_EID_DMG_TSPEC = 146,
 	WLAN_EID_DMG_AT = 147,
 	WLAN_EID_DMG_CAP = 148,
-	/* 149-150 reserved for Cisco */
+	/* 149 reserved for Cisco */
+	WLAN_EID_CISCO_VENDOR_SPECIFIC = 150,
 	WLAN_EID_DMG_OPERATION = 151,
 	WLAN_EID_DMG_BSS_PARAM_CHANGE = 152,
 	WLAN_EID_DMG_BEAM_REFINEMENT = 153,
net/mac80211/ieee80211_i.h +1 -0
index ef7a089..e995556 100644
@@ -1367,6 +1367,7 @@ struct ieee802_11_elems {
 	const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
 	const u8 *country_elem;
 	const u8 *pwr_constr_elem;
+	const u8 *cisco_dtpc_elem;
 	const struct ieee80211_timeout_interval_ie *timeout_int;
 	const u8 *opmode_notif;
 	const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
net/mac80211/mlme.c +27 -0
index 31a8afa..1c8c0a3 100644
@@ -1227,6 +1227,30 @@ static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
 	return 0;
 }
 
+static u32 ieee80211_handle_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
+				       struct ieee80211_channel *channel,
+				       const u8 *cisco_dtpc_elem)
+{
+	/* From practical testing, the two data bytes of the DTPC element
+	 * seem to contain the requested dBm level in little-endian.
+	 * It never seems to go negative even if -1 dBm is requested
+	 * (capped at zero), but just to be sure, we do it ourselves.
+	 */
+	__s16 new_ap_level = (__s16) le16_to_cpup((__le16 *)(cisco_dtpc_elem + 4));
+	new_ap_level = max_t(__s16, 0, new_ap_level);
+
+	if (sdata->ap_power_level == new_ap_level)
+		return 0;
+
+	sdata_info(sdata,
+		   "Limiting TX power to %d dBm as advertised by %pM\n",
+		   new_ap_level, sdata->u.mgd.bssid);
+	sdata->ap_power_level = new_ap_level;
+	if (__ieee80211_recalc_txpower(sdata))
+		return BSS_CHANGED_TXPOWER;
+	return 0;
+}
+
 /* powersave */
 static void ieee80211_enable_ps(struct ieee80211_local *local,
 				struct ieee80211_sub_if_data *sdata)
@@ -3197,6 +3221,9 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
 						       elems.country_elem,
 						       elems.country_elem_len,
 						       elems.pwr_constr_elem);
+	else if (elems.cisco_dtpc_elem) 
+		changed |= ieee80211_handle_cisco_dtpc(sdata, chan,
+						       elems.cisco_dtpc_elem);
 
 	ieee80211_bss_info_change_notify(sdata, changed);
 }
net/mac80211/util.c +19 -0
index 725af7a..a253487 100644
@@ -1014,6 +1014,25 @@ u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
 			}
 			elems->pwr_constr_elem = pos;
 			break;
+		case WLAN_EID_CISCO_VENDOR_SPECIFIC:
+			/* Lots of different options exist, but we only care about the
+			 * Dynamic Transmit Power Control element. First check
+			 * for the Cisco OUI, then for the DTPC tag (0x00).
+			 */
+			if (elen < 4) {
+				elem_parse_failed = true;
+				break;
+			}
+			if (pos[0] != 0x00 || pos[1] != 0x40 ||
+			    pos[2] != 0x96 || pos[3] != 0x00) {
+				break;
+			}
+			if (elen != 6) {
+				elem_parse_failed = true;
+				break;
+			}
+			elems->cisco_dtpc_elem = pos;
+			break;
 		case WLAN_EID_TIMEOUT_INTERVAL:
 			if (elen >= sizeof(struct ieee80211_timeout_interval_ie))
 				elems->timeout_int = (void *)pos;
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 4 lines · Steinar H. Gunderson

I noticed the other day that Linux and Cisco don't always seem to speak the same language when it comes to reducing the client transmit power. I've written a quick patch to try to remedy it; please consider applying to the wireless tree.

I looked in the CLI as well, and it pretty clearly indicates that the range here is -127 to 127 dBm, which means I've changed my mind; this is not a two-byte value. Updated patch attached.

/* Steinar */

Signature · 1 line
Homepage: http://www.sesse.net/
#2 lore raw

PATCH 1/1 Support DTPC IE (from Cisco Client eXtensions)

Linux already supports 802.11h, where the access point can tell the client to reduce its transmission power. However, 802.11h is only defined for 5 GHz, where the need for this is much smaller than on 2.4 GHz.

Cisco has their own solution, called DTPC (Dynamic Transmit Power Control). Cisco APs on a controller sometimes but not always send 802.11h; they always send DTPC, even on 2.4 GHz. This patch adds support for parsing and honoring the DTPC IE if there is no 802.11h element; the format is not documented, but very simple.

Tested (on top of wireless.git and on 3.16.1) against a Cisco Aironet 1142 joined to a Cisco 2504 WLC, by setting various transmit power levels for the given access points and observing the results. The Wireshark 802.11 dissector agrees with the interpretation of the element, except for negative numbers, which seem to never happen anyway.

---
 include/linux/ieee80211.h  |    3 ++-
 net/mac80211/ieee80211_i.h |    1 +
 net/mac80211/mlme.c        |   27 +++++++++++++++++++++++++++
 net/mac80211/util.c        |   19 +++++++++++++++++++
 4 files changed, 49 insertions(+), 1 deletion(-)
include/linux/ieee80211.h +2 -1
index 63ab3873..d0ec287 100644
@@ -1806,7 +1806,8 @@ enum ieee80211_eid {
 	WLAN_EID_DMG_TSPEC = 146,
 	WLAN_EID_DMG_AT = 147,
 	WLAN_EID_DMG_CAP = 148,
-	/* 149-150 reserved for Cisco */
+	/* 149 reserved for Cisco */
+	WLAN_EID_CISCO_VENDOR_SPECIFIC = 150,
 	WLAN_EID_DMG_OPERATION = 151,
 	WLAN_EID_DMG_BSS_PARAM_CHANGE = 152,
 	WLAN_EID_DMG_BEAM_REFINEMENT = 153,
net/mac80211/ieee80211_i.h +1 -0
index ef7a089..e995556 100644
@@ -1367,6 +1367,7 @@ struct ieee802_11_elems {
 	const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
 	const u8 *country_elem;
 	const u8 *pwr_constr_elem;
+	const u8 *cisco_dtpc_elem;
 	const struct ieee80211_timeout_interval_ie *timeout_int;
 	const u8 *opmode_notif;
 	const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
net/mac80211/mlme.c +27 -0
index 31a8afa..39167c1 100644
@@ -1227,6 +1227,30 @@ static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
 	return 0;
 }
 
+static u32 ieee80211_handle_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
+				       struct ieee80211_channel *channel,
+				       const u8 *cisco_dtpc_elem)
+{
+	/* From practical testing, the first data byte of the DTPC element
+	 * seems to contain the requested dBm level, and the CLI on Cisco
+	 * APs clearly state the range is -127 to 127 dBm, which indicates
+	 * a signed byte, although it seemingly never actually goes negative.
+	 * The other byte seems to always be zero.
+	 */
+	__s8 new_ap_level = (__s8)cisco_dtpc_elem[4];
+
+	if (sdata->ap_power_level == new_ap_level)
+		return 0;
+
+	sdata_info(sdata,
+		   "Limiting TX power to %d dBm as advertised by %pM\n",
+		   new_ap_level, sdata->u.mgd.bssid);
+	sdata->ap_power_level = new_ap_level;
+	if (__ieee80211_recalc_txpower(sdata))
+		return BSS_CHANGED_TXPOWER;
+	return 0;
+}
+
 /* powersave */
 static void ieee80211_enable_ps(struct ieee80211_local *local,
 				struct ieee80211_sub_if_data *sdata)
@@ -3197,6 +3221,9 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
 						       elems.country_elem,
 						       elems.country_elem_len,
 						       elems.pwr_constr_elem);
+	else if (elems.cisco_dtpc_elem)
+		changed |= ieee80211_handle_cisco_dtpc(sdata, chan,
+						       elems.cisco_dtpc_elem);
 
 	ieee80211_bss_info_change_notify(sdata, changed);
 }
net/mac80211/util.c +19 -0
index 725af7a..a253487 100644
@@ -1014,6 +1014,25 @@ u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
 			}
 			elems->pwr_constr_elem = pos;
 			break;
+		case WLAN_EID_CISCO_VENDOR_SPECIFIC:
+			/* Lots of different options exist, but we only care about the
+			 * Dynamic Transmit Power Control element. First check
+			 * for the Cisco OUI, then for the DTPC tag (0x00).
+			 */
+			if (elen < 4) {
+				elem_parse_failed = true;
+				break;
+			}
+			if (pos[0] != 0x00 || pos[1] != 0x40 ||
+			    pos[2] != 0x96 || pos[3] != 0x00) {
+				break;
+			}
+			if (elen != 6) {
+				elem_parse_failed = true;
+				break;
+			}
+			elems->cisco_dtpc_elem = pos;
+			break;
 		case WLAN_EID_TIMEOUT_INTERVAL:
 			if (elen >= sizeof(struct ieee80211_timeout_interval_ie))
 				elems->timeout_int = (void *)pos;
Signature · 1 line
1.7.10.4
maintainer
#3 lore raw

Re: [PATCH] Support DTPC IE (from Cisco Client eXtensions)

Quoted 11 lines · Steinar H. Gunderson

Linux already supports 802.11h, where the access point can tell the client to reduce its transmission power. However, 802.11h is only defined for 5 GHz, where the need for this is much smaller than on 2.4 GHz.

Cisco has their own solution, called DTPC (Dynamic Transmit Power Control). Cisco APs on a controller sometimes but not always send 802.11h; they always send DTPC, even on 2.4 GHz. This patch adds support for parsing and honoring the DTPC IE if there is no 802.11h element; the format is not documented, but very simple.

Quoted 6 lines

Tested (on top of wireless.git and on 3.16.1) against a Cisco Aironet 1142 joined to a Cisco 2504 WLC, by setting various transmit power levels for the given access points and observing the results. The Wireshark 802.11 dissector agrees with the interpretation of the element, except for negative numbers, which seem to never happen anyway.

Can you say *why* we want this? Does it yield better behaviour on a Cisco deployment?

johannes

#4 lore raw

Re: [PATCH] Support DTPC IE (from Cisco Client eXtensions)

Quoted 2 lines · Johannes Berg

Can you say *why* we want this? Does it yield better behaviour on a Cisco deployment?

Yes. The basic idea is: When your density goes up (many clients, many access points), the 2.4 GHz band becomes very crowded and you get interference across cells. The controller observes this (by seeing that the APs see each other too strongly), and reduces the transmit power to reduce the cell size. (This might be counterintuitive, because people's initial idea for better Wi-Fi usually involves turning power _up_, but that only makes the problem here worse, since the problem is interference, not range.)

It then also asks the clients to do the same (through DTPC), because the clients' traffic of course also contributes to the interference. We should honor its request, just as we honor it when it comes through 802.11h or 802.11d. If the controller detects that this creates coverage holes, it will turn the power back up and just live with the interference.

Like the subject says, this is part of CCX (Cisco's set of wireless extensions), so as far as I know, any CCX-certified driver, e.g. Intel drivers on Windows, already support this.

/* Steinar */

Signature · 1 line
Homepage: http://www.sesse.net/
#5 lore raw

Re: [PATCH] Support DTPC IE (from Cisco Client eXtensions)

Quoted 2 lines · Steinar H. Gunderson

We should honor its request, just as we honor it when it comes through 802.11h or 802.11d.

I've been running with this a few days now, and I've noticed that while the patch works fine, it is not entirely complete.

The problem is that sometimes the AP can send _both_ 802.11h and the DTPC IE; the 802.11h IE seemingly because there's some kind of regulatory pressure (ie., “something detected on your channel, you have to go down”), and the DTPC IE due to the configured lower transmit power. In this case, 802.11h says 21 (24 - 3) dBm and DTPC 7 dBm, and we pick the former.

In this situation, my current patch lets 802.11h override (on the grounds that it's an official standard, and that it's required for regulatory compliance), but it should probably do a min() of the two advertised power levels instead. Does this sound reasonable? I'll be sending a patch later today.

/* Steinar */

Signature · 1 line
Homepage: http://www.sesse.net/
#6 lore raw

PATCH 1/2 mac80211: split 802.11h parsing from transmit power policy

Decouple the logic of parsing the 802.11d and 802.11h IEs from the part of deciding what to do about the data (messaging, clamping to 0 dBm, doing the actual setting). This paves the way for the next patch, which introduces more data sources for transmit power limitation.

---
 net/mac80211/mlme.c |   62 ++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 42 insertions(+), 20 deletions(-)
net/mac80211/mlme.c +42 -20
index b82a12a..5c90e49 100644
@@ -1157,19 +1157,22 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
 			  TU_TO_EXP_TIME(csa_ie.count * cbss->beacon_interval));
 }
 
-static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
-				       struct ieee80211_channel *channel,
-				       const u8 *country_ie, u8 country_ie_len,
-				       const u8 *pwr_constr_elem)
+static bool ieee80211_find_80211h_pwr_constr(
+	struct ieee80211_sub_if_data *sdata,
+	struct ieee80211_channel *channel,
+	const u8 *country_ie, u8 country_ie_len,
+	const u8 *pwr_constr_elem,
+	int *chan_pwr,
+	int *pwr_reduction)
 {
 	struct ieee80211_country_ie_triplet *triplet;
 	int chan = ieee80211_frequency_to_channel(channel->center_freq);
-	int i, chan_pwr, chan_increment, new_ap_level;
+	int i, chan_increment;
 	bool have_chan_pwr = false;
 
 	/* Invalid IE */
 	if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
-		return 0;
+		return false;
 
 	triplet = (void *)(country_ie + 3);
 	country_ie_len -= 3;
@@ -1197,7 +1200,7 @@ static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
 		for (i = 0; i < triplet->chans.num_channels; i++) {
 			if (first_channel + i * chan_increment == chan) {
 				have_chan_pwr = true;
-				chan_pwr = triplet->chans.max_power;
+				*chan_pwr = triplet->chans.max_power;
 				break;
 			}
 		}
@@ -1209,19 +1212,41 @@ static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
 		country_ie_len -= 3;
 	}
 
-	if (!have_chan_pwr)
-		return 0;
+	if (have_chan_pwr)
+		*pwr_reduction = *pwr_constr_elem;
+	return have_chan_pwr;
+}
 
-	new_ap_level = max_t(int, 0, chan_pwr - *pwr_constr_elem);
+static bool ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
+					struct ieee80211_channel *channel,
+					struct ieee80211_mgmt *mgmt,
+					const u8 *country_ie, u8 country_ie_len,
+					const u8 *pwr_constr_ie)
+{
+	bool has_80211h_pwr = false;
+	int chan_pwr, pwr_reduction_80211h;
+	int new_ap_level;
 
-	if (sdata->ap_power_level == new_ap_level)
+	if (country_ie && pwr_constr_ie &&
+	    mgmt->u.probe_resp.capab_info &
+		cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT)) {
+		has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
+			sdata, channel, country_ie, country_ie_len,
+			pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
+		new_ap_level = max_t(int, 0, chan_pwr - pwr_reduction_80211h);
+	}
+
+	if (!has_80211h_pwr)
 		return 0;
 
 	sdata_info(sdata,
 		   "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
-		   new_ap_level, chan_pwr, *pwr_constr_elem,
+		   new_ap_level, chan_pwr, pwr_reduction_80211h,
 		   sdata->u.mgd.bssid);
-	sdata->ap_power_level = new_ap_level;
+
+	if (sdata->ap_power_level == new_ap_level)
+		return 0;
+
 	if (__ieee80211_recalc_txpower(sdata))
 		return BSS_CHANGED_TXPOWER;
 	return 0;
@@ -3190,13 +3215,10 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
 					    rx_status->band, true);
 	mutex_unlock(&local->sta_mtx);
 
-	if (elems.country_elem && elems.pwr_constr_elem &&
-	    mgmt->u.probe_resp.capab_info &
-				cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT))
-		changed |= ieee80211_handle_pwr_constr(sdata, chan,
-						       elems.country_elem,
-						       elems.country_elem_len,
-						       elems.pwr_constr_elem);
+	changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
+					       elems.country_elem,
+					       elems.country_elem_len,
+					       elems.pwr_constr_elem);
 
 	ieee80211_bss_info_change_notify(sdata, changed);
 }
Signature · 1 line
1.7.10.4
#7 lore raw

PATCH 2/2 mac80211: support DTPC IE (from Cisco Client eXtensions)

In reply to Steinar H. Gunderson

Linux already supports 802.11h, where the access point can tell the client to reduce its transmission power. However, 802.11h is only defined for 5 GHz, where the need for this is much smaller than on 2.4 GHz.

Cisco has their own solution, called DTPC (Dynamic Transmit Power Control). Cisco APs on a controller sometimes but not always send 802.11h; they always send DTPC, even on 2.4 GHz. This patch adds support for parsing and honoring the DTPC IE in addition to the 802.11h element (they do not always contain the same limits, so both must be honored); the format is not documented, but very simple.

Tested (on top of wireless.git and on 3.16.1) against a Cisco Aironet 1142 joined to a Cisco 2504 WLC, by setting various transmit power levels for the given access points and observing the results. The Wireshark 802.11 dissector agrees with the interpretation of the element, except for negative numbers, which seem to never happen anyway.

---
 include/linux/ieee80211.h  |    3 ++-
 net/mac80211/ieee80211_i.h |    1 +
 net/mac80211/mlme.c        |   55 ++++++++++++++++++++++++++++++++++++--------
 net/mac80211/util.c        |   20 ++++++++++++++++
 4 files changed, 68 insertions(+), 11 deletions(-)
include/linux/ieee80211.h +2 -1
index 63ab3873..d0ec287 100644
@@ -1806,7 +1806,8 @@ enum ieee80211_eid {
 	WLAN_EID_DMG_TSPEC = 146,
 	WLAN_EID_DMG_AT = 147,
 	WLAN_EID_DMG_CAP = 148,
-	/* 149-150 reserved for Cisco */
+	/* 149 reserved for Cisco */
+	WLAN_EID_CISCO_VENDOR_SPECIFIC = 150,
 	WLAN_EID_DMG_OPERATION = 151,
 	WLAN_EID_DMG_BSS_PARAM_CHANGE = 152,
 	WLAN_EID_DMG_BEAM_REFINEMENT = 153,
net/mac80211/ieee80211_i.h +1 -0
index ef7a089..e995556 100644
@@ -1367,6 +1367,7 @@ struct ieee802_11_elems {
 	const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
 	const u8 *country_elem;
 	const u8 *pwr_constr_elem;
+	const u8 *cisco_dtpc_elem;
 	const struct ieee80211_timeout_interval_ie *timeout_int;
 	const u8 *opmode_notif;
 	const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
net/mac80211/mlme.c +45 -10

82 lines not on this page · raw message

net/mac80211/util.c +20 -0
index 725af7a..56105f4 100644
@@ -1014,6 +1014,26 @@ u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
 			}
 			elems->pwr_constr_elem = pos;
 			break;
+		case WLAN_EID_CISCO_VENDOR_SPECIFIC:
+			/* Lots of different options exist, but we only care
+			 * about the Dynamic Transmit Power Control element.
+			 * First check for the Cisco OUI, then for the DTPC
+			 * tag (0x00).
+			 */
+			if (elen < 4) {
+				elem_parse_failed = true;
+				break;
+			}
+			if (pos[0] != 0x00 || pos[1] != 0x40 ||
+			    pos[2] != 0x96 || pos[3] != 0x00) {
+				break;
+			}
+			if (elen != 6) {
+				elem_parse_failed = true;
+				break;
+			}
+			elems->cisco_dtpc_elem = pos;
+			break;
 		case WLAN_EID_TIMEOUT_INTERVAL:
 			if (elen >= sizeof(struct ieee80211_timeout_interval_ie))
 				elems->timeout_int = (void *)pos;
Signature · 1 line
1.7.10.4
#8 lore raw

Re: [PATCH] Support DTPC IE (from Cisco Client eXtensions)

In reply to Steinar H. Gunderson
Quoted 1 line · Steinar H. Gunderson

I'll be sending a patch later today.

...and of course, in the refactoring, I removed the part that actually sets sdata->ap_power_level, so my new patch series is borked, too. I'll fix, do some more testing, and then send a new patch series.

Feedback on the general structure is very welcome, though!

/* Steinar */

Signature · 1 line
Homepage: http://www.sesse.net/
#9 lore raw

Re: [PATCH] Support DTPC IE (from Cisco Client eXtensions)

Quoted 3 lines · Steinar H. Gunderson

...and of course, in the refactoring, I removed the part that actually sets sdata->ap_power_level, so my new patch series is borked, too. I'll fix, do some more testing, and then send a new patch series.

The fix was trivial (just add back the line). I'll be traveling a bit the next two weeks, so I guess I'll be seeing a few different installations and see how this pans out. But in my home network, it now looks to be working very well.

Sending v4 of the patch series as response to this email.

/* Steinar */

Signature · 1 line
Homepage: http://www.sesse.net/
#10 lore raw

PATCH 1/2 mac80211: split 802.11h parsing from transmit power policy

Decouple the logic of parsing the 802.11d and 802.11h IEs from the part of deciding what to do about the data (messaging, clamping to 0 dBm, doing the actual setting). This paves the way for the next patch, which introduces more data sources for transmit power limitation.

---
 net/mac80211/mlme.c |   61 +++++++++++++++++++++++++++++++++++----------------
 1 file changed, 42 insertions(+), 19 deletions(-)
net/mac80211/mlme.c +42 -19
index b82a12a..524c7cc 100644
@@ -1157,19 +1157,22 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
 			  TU_TO_EXP_TIME(csa_ie.count * cbss->beacon_interval));
 }
 
-static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
-				       struct ieee80211_channel *channel,
-				       const u8 *country_ie, u8 country_ie_len,
-				       const u8 *pwr_constr_elem)
+static bool ieee80211_find_80211h_pwr_constr(
+	struct ieee80211_sub_if_data *sdata,
+	struct ieee80211_channel *channel,
+	const u8 *country_ie, u8 country_ie_len,
+	const u8 *pwr_constr_elem,
+	int *chan_pwr,
+	int *pwr_reduction)
 {
 	struct ieee80211_country_ie_triplet *triplet;
 	int chan = ieee80211_frequency_to_channel(channel->center_freq);
-	int i, chan_pwr, chan_increment, new_ap_level;
+	int i, chan_increment;
 	bool have_chan_pwr = false;
 
 	/* Invalid IE */
 	if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
-		return 0;
+		return false;
 
 	triplet = (void *)(country_ie + 3);
 	country_ie_len -= 3;
@@ -1197,7 +1200,7 @@ static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
 		for (i = 0; i < triplet->chans.num_channels; i++) {
 			if (first_channel + i * chan_increment == chan) {
 				have_chan_pwr = true;
-				chan_pwr = triplet->chans.max_power;
+				*chan_pwr = triplet->chans.max_power;
 				break;
 			}
 		}
@@ -1209,18 +1212,41 @@ static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
 		country_ie_len -= 3;
 	}
 
-	if (!have_chan_pwr)
-		return 0;
+	if (have_chan_pwr)
+		*pwr_reduction = *pwr_constr_elem;
+	return have_chan_pwr;
+}
 
-	new_ap_level = max_t(int, 0, chan_pwr - *pwr_constr_elem);
+static bool ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
+					struct ieee80211_channel *channel,
+					struct ieee80211_mgmt *mgmt,
+					const u8 *country_ie, u8 country_ie_len,
+					const u8 *pwr_constr_ie)
+{
+	bool has_80211h_pwr = false;
+	int chan_pwr, pwr_reduction_80211h;
+	int new_ap_level;
 
-	if (sdata->ap_power_level == new_ap_level)
+	if (country_ie && pwr_constr_ie &&
+	    mgmt->u.probe_resp.capab_info &
+		cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT)) {
+		has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
+			sdata, channel, country_ie, country_ie_len,
+			pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
+		new_ap_level = max_t(int, 0, chan_pwr - pwr_reduction_80211h);
+	}
+
+	if (!has_80211h_pwr)
 		return 0;
 
 	sdata_info(sdata,
 		   "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
-		   new_ap_level, chan_pwr, *pwr_constr_elem,
+		   new_ap_level, chan_pwr, pwr_reduction_80211h,
 		   sdata->u.mgd.bssid);
+
+	if (sdata->ap_power_level == new_ap_level)
+		return 0;
+
 	sdata->ap_power_level = new_ap_level;
 	if (__ieee80211_recalc_txpower(sdata))
 		return BSS_CHANGED_TXPOWER;
@@ -3190,13 +3216,10 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
 					    rx_status->band, true);
 	mutex_unlock(&local->sta_mtx);
 
-	if (elems.country_elem && elems.pwr_constr_elem &&
-	    mgmt->u.probe_resp.capab_info &
-				cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT))
-		changed |= ieee80211_handle_pwr_constr(sdata, chan,
-						       elems.country_elem,
-						       elems.country_elem_len,
-						       elems.pwr_constr_elem);
+	changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
+					       elems.country_elem,
+					       elems.country_elem_len,
+					       elems.pwr_constr_elem);
 
 	ieee80211_bss_info_change_notify(sdata, changed);
 }
Signature · 1 line
1.7.10.4
#11 lore raw

PATCH 2/2 mac80211: support DTPC IE (from Cisco Client eXtensions)

In reply to Steinar H. Gunderson

Linux already supports 802.11h, where the access point can tell the client to reduce its transmission power. However, 802.11h is only defined for 5 GHz, where the need for this is much smaller than on 2.4 GHz.

Cisco has their own solution, called DTPC (Dynamic Transmit Power Control). Cisco APs on a controller sometimes but not always send 802.11h; they always send DTPC, even on 2.4 GHz. This patch adds support for parsing and honoring the DTPC IE in addition to the 802.11h element (they do not always contain the same limits, so both must be honored); the format is not documented, but very simple.

Tested (on top of wireless.git and on 3.16.1) against a Cisco Aironet 1142 joined to a Cisco 2504 WLC, by setting various transmit power levels for the given access points and observing the results. The Wireshark 802.11 dissector agrees with the interpretation of the element, except for negative numbers, which seem to never happen anyway.

---
 include/linux/ieee80211.h  |    3 ++-
 net/mac80211/ieee80211_i.h |    1 +
 net/mac80211/mlme.c        |   55 ++++++++++++++++++++++++++++++++++++--------
 net/mac80211/util.c        |   20 ++++++++++++++++
 4 files changed, 68 insertions(+), 11 deletions(-)
include/linux/ieee80211.h +2 -1
index 63ab3873..d0ec287 100644
@@ -1806,7 +1806,8 @@ enum ieee80211_eid {
 	WLAN_EID_DMG_TSPEC = 146,
 	WLAN_EID_DMG_AT = 147,
 	WLAN_EID_DMG_CAP = 148,
-	/* 149-150 reserved for Cisco */
+	/* 149 reserved for Cisco */
+	WLAN_EID_CISCO_VENDOR_SPECIFIC = 150,
 	WLAN_EID_DMG_OPERATION = 151,
 	WLAN_EID_DMG_BSS_PARAM_CHANGE = 152,
 	WLAN_EID_DMG_BEAM_REFINEMENT = 153,
net/mac80211/ieee80211_i.h +1 -0
index ef7a089..e995556 100644
@@ -1367,6 +1367,7 @@ struct ieee802_11_elems {
 	const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
 	const u8 *country_elem;
 	const u8 *pwr_constr_elem;
+	const u8 *cisco_dtpc_elem;
 	const struct ieee80211_timeout_interval_ie *timeout_int;
 	const u8 *opmode_notif;
 	const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
net/mac80211/mlme.c +45 -10

82 lines not on this page · raw message

net/mac80211/util.c +20 -0
index 725af7a..56105f4 100644
@@ -1014,6 +1014,26 @@ u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
 			}
 			elems->pwr_constr_elem = pos;
 			break;
+		case WLAN_EID_CISCO_VENDOR_SPECIFIC:
+			/* Lots of different options exist, but we only care
+			 * about the Dynamic Transmit Power Control element.
+			 * First check for the Cisco OUI, then for the DTPC
+			 * tag (0x00).
+			 */
+			if (elen < 4) {
+				elem_parse_failed = true;
+				break;
+			}
+			if (pos[0] != 0x00 || pos[1] != 0x40 ||
+			    pos[2] != 0x96 || pos[3] != 0x00) {
+				break;
+			}
+			if (elen != 6) {
+				elem_parse_failed = true;
+				break;
+			}
+			elems->cisco_dtpc_elem = pos;
+			break;
 		case WLAN_EID_TIMEOUT_INTERVAL:
 			if (elen >= sizeof(struct ieee80211_timeout_interval_ie))
 				elems->timeout_int = (void *)pos;
Signature · 1 line
1.7.10.4
#12 lore raw

PATCH v5 1/2 mac80211: split 802.11h parsing from transmit power policy

In reply to Steinar H. Gunderson

Decouple the logic of parsing the 802.11d and 802.11h IEs from the part of deciding what to do about the data (messaging, clamping to 0 dBm, doing the actual setting). This paves the way for the next patch, which introduces more data sources for transmit power limitation.

---
 net/mac80211/mlme.c |   61 +++++++++++++++++++++++++++++++++++----------------
 1 file changed, 42 insertions(+), 19 deletions(-)
net/mac80211/mlme.c +42 -19
index b82a12a..524c7cc 100644
@@ -1157,19 +1157,22 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
 			  TU_TO_EXP_TIME(csa_ie.count * cbss->beacon_interval));
 }
 
-static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
-				       struct ieee80211_channel *channel,
-				       const u8 *country_ie, u8 country_ie_len,
-				       const u8 *pwr_constr_elem)
+static bool ieee80211_find_80211h_pwr_constr(
+	struct ieee80211_sub_if_data *sdata,
+	struct ieee80211_channel *channel,
+	const u8 *country_ie, u8 country_ie_len,
+	const u8 *pwr_constr_elem,
+	int *chan_pwr,
+	int *pwr_reduction)
 {
 	struct ieee80211_country_ie_triplet *triplet;
 	int chan = ieee80211_frequency_to_channel(channel->center_freq);
-	int i, chan_pwr, chan_increment, new_ap_level;
+	int i, chan_increment;
 	bool have_chan_pwr = false;
 
 	/* Invalid IE */
 	if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
-		return 0;
+		return false;
 
 	triplet = (void *)(country_ie + 3);
 	country_ie_len -= 3;
@@ -1197,7 +1200,7 @@ static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
 		for (i = 0; i < triplet->chans.num_channels; i++) {
 			if (first_channel + i * chan_increment == chan) {
 				have_chan_pwr = true;
-				chan_pwr = triplet->chans.max_power;
+				*chan_pwr = triplet->chans.max_power;
 				break;
 			}
 		}
@@ -1209,18 +1212,41 @@ static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
 		country_ie_len -= 3;
 	}
 
-	if (!have_chan_pwr)
-		return 0;
+	if (have_chan_pwr)
+		*pwr_reduction = *pwr_constr_elem;
+	return have_chan_pwr;
+}
 
-	new_ap_level = max_t(int, 0, chan_pwr - *pwr_constr_elem);
+static bool ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
+					struct ieee80211_channel *channel,
+					struct ieee80211_mgmt *mgmt,
+					const u8 *country_ie, u8 country_ie_len,
+					const u8 *pwr_constr_ie)
+{
+	bool has_80211h_pwr = false;
+	int chan_pwr, pwr_reduction_80211h;
+	int new_ap_level;
 
-	if (sdata->ap_power_level == new_ap_level)
+	if (country_ie && pwr_constr_ie &&
+	    mgmt->u.probe_resp.capab_info &
+		cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT)) {
+		has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
+			sdata, channel, country_ie, country_ie_len,
+			pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
+		new_ap_level = max_t(int, 0, chan_pwr - pwr_reduction_80211h);
+	}
+
+	if (!has_80211h_pwr)
 		return 0;
 
 	sdata_info(sdata,
 		   "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
-		   new_ap_level, chan_pwr, *pwr_constr_elem,
+		   new_ap_level, chan_pwr, pwr_reduction_80211h,
 		   sdata->u.mgd.bssid);
+
+	if (sdata->ap_power_level == new_ap_level)
+		return 0;
+
 	sdata->ap_power_level = new_ap_level;
 	if (__ieee80211_recalc_txpower(sdata))
 		return BSS_CHANGED_TXPOWER;
@@ -3190,13 +3216,10 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
 					    rx_status->band, true);
 	mutex_unlock(&local->sta_mtx);
 
-	if (elems.country_elem && elems.pwr_constr_elem &&
-	    mgmt->u.probe_resp.capab_info &
-				cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT))
-		changed |= ieee80211_handle_pwr_constr(sdata, chan,
-						       elems.country_elem,
-						       elems.country_elem_len,
-						       elems.pwr_constr_elem);
+	changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
+					       elems.country_elem,
+					       elems.country_elem_len,
+					       elems.pwr_constr_elem);
 
 	ieee80211_bss_info_change_notify(sdata, changed);
 }
Signature · 1 line
1.7.10.4
#15 lore raw

PATCH v5 2/2 mac80211: support DTPC IE (from Cisco Client eXtensions)

In reply to Steinar H. Gunderson

Linux already supports 802.11h, where the access point can tell the client to reduce its transmission power. However, 802.11h is only defined for 5 GHz, where the need for this is much smaller than on 2.4 GHz.

Cisco has their own solution, called DTPC (Dynamic Transmit Power Control). Cisco APs on a controller sometimes but not always send 802.11h; they always send DTPC, even on 2.4 GHz. This patch adds support for parsing and honoring the DTPC IE in addition to the 802.11h element (they do not always contain the same limits, so both must be honored); the format is not documented, but very simple.

Tested (on top of wireless.git and on 3.16.1) against a Cisco Aironet 1142 joined to a Cisco 2504 WLC, by setting various transmit power levels for the given access points and observing the results. The Wireshark 802.11 dissector agrees with the interpretation of the element, except for negative numbers, which seem to never happen anyway.

---
 include/linux/ieee80211.h  |    3 ++-
 net/mac80211/ieee80211_i.h |    1 +
 net/mac80211/mlme.c        |   59 +++++++++++++++++++++++++++++++++++---------
 net/mac80211/util.c        |   22 +++++++++++++++++
 4 files changed, 73 insertions(+), 12 deletions(-)
include/linux/ieee80211.h +2 -1
index 63ab3873..d0ec287 100644
@@ -1806,7 +1806,8 @@ enum ieee80211_eid {
 	WLAN_EID_DMG_TSPEC = 146,
 	WLAN_EID_DMG_AT = 147,
 	WLAN_EID_DMG_CAP = 148,
-	/* 149-150 reserved for Cisco */
+	/* 149 reserved for Cisco */
+	WLAN_EID_CISCO_VENDOR_SPECIFIC = 150,
 	WLAN_EID_DMG_OPERATION = 151,
 	WLAN_EID_DMG_BSS_PARAM_CHANGE = 152,
 	WLAN_EID_DMG_BEAM_REFINEMENT = 153,
net/mac80211/ieee80211_i.h +1 -0
index ef7a089..e995556 100644
@@ -1367,6 +1367,7 @@ struct ieee802_11_elems {
 	const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
 	const u8 *country_elem;
 	const u8 *pwr_constr_elem;
+	const u8 *cisco_dtpc_elem;
 	const struct ieee80211_timeout_interval_ie *timeout_int;
 	const u8 *opmode_notif;
 	const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
net/mac80211/mlme.c +48 -11

92 lines not on this page · raw message

net/mac80211/util.c +22 -0
index 725af7a..e393dfa 100644
@@ -1014,6 +1014,28 @@ u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
 			}
 			elems->pwr_constr_elem = pos;
 			break;
+		case WLAN_EID_CISCO_VENDOR_SPECIFIC:
+			/* Lots of different options exist, but we only care
+			 * about the Dynamic Transmit Power Control element.
+			 * First check for the Cisco OUI, then for the DTPC
+			 * tag (0x00).
+			 */
+			if (elen < 4) {
+				elem_parse_failed = true;
+				break;
+			}
+			if (pos[0] != 0x00 || pos[1] != 0x40 ||
+			    pos[2] != 0x96 || pos[3] != 0x00) {
+				break;
+			}
+			if (elen != 6) {
+				elem_parse_failed = true;
+				break;
+			}
+			if (calc_crc)
+				crc = crc32_be(crc, pos - 2, elen + 2);
+			elems->cisco_dtpc_elem = pos;
+			break;
 		case WLAN_EID_TIMEOUT_INTERVAL:
 			if (elen >= sizeof(struct ieee80211_timeout_interval_ie))
 				elems->timeout_int = (void *)pos;
Signature · 1 line
1.7.10.4
maintainer
#13 lore raw

Re: [PATCH v5 1/2] mac80211: split 802.11h parsing from transmit power policy

In reply to Steinar H. Gunderson
Quoted 1 line · Steinar H. Gunderson

ieee80211_find_80211h_pwr_constr

Please format the code like this:

static bool
ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
struct ieee80211_channel *channel, const u8 *country_ie, u8
country_ie_len,
const u8 *pwr_constr_elem, int *chan_pwr, int *pwr_reduction)

Do we need the pwr_reduction? Couldn't we just return it? We don't handle 0/negative anyway, do we?

net/mac80211/mlme.c ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,

Quoted 3 lines
net/mac80211/mlme.c +1 -1
-static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
 
+static bool ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,

I think you meant to keep u32 here? Otherwise return values from the function simply get converted to 0/1 which doesn't seem right.

johannes

maintainer
#16 lore raw

Re: [PATCH v5 2/2] mac80211: support DTPC IE (from Cisco Client eXtensions)

In reply to Steinar H. Gunderson
Quoted 11 lines · Steinar H. Gunderson

Linux already supports 802.11h, where the access point can tell the client to reduce its transmission power. However, 802.11h is only defined for 5 GHz, where the need for this is much smaller than on 2.4 GHz.

Cisco has their own solution, called DTPC (Dynamic Transmit Power Control). Cisco APs on a controller sometimes but not always send 802.11h; they always send DTPC, even on 2.4 GHz. This patch adds support for parsing and honoring the DTPC IE in addition to the 802.11h element (they do not always contain the same limits, so both must be honored); the format is not documented, but very simple.

The format is documented for CCX partners, I suppose, but we don't have access to that :)

I think for some vendors shipping our stack this might become problematic. I think it would make sense to have a Kconfig option for this, probably hidden away under "if EXPERT" and defaulting to yes, to enable this code, it might be something that interferes with more CCX implementations maybe?

Quoted 2 lines

+static bool ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,

The return value is useless here, so it could be void?

net/mac80211/util.c u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action, · line 1030

Quoted 4 lines
net/mac80211/util.c +4 -0
+                       if (pos[0] != 0x00 || pos[1] != 0x40 ||
+                           pos[2] != 0x96 || pos[3] != 0x00) {
+                               break;
+                       }

Please remove those useless braces - maybe run ./scripts/checkpatch.pl?

johannes

#14 lore raw

Re: [PATCH v5 1/2] mac80211: split 802.11h parsing from transmit power policy

In reply to Johannes Berg

Thanks for reviewing. I'll send out a new patch series as soon as I'm through all of your comments.

Quoted 9 lines · Johannes Berg

Please format the code like this:

static bool
ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
struct ieee80211_channel *channel, const u8 *country_ie, u8
country_ie_len,
const u8 *pwr_constr_elem, int *chan_pwr, int *pwr_reduction)

Done.

Quoted 2 lines

Do we need the pwr_reduction? Couldn't we just return it? We don't handle 0/negative anyway, do we?

We could do the calculation directly in ieee80211_find_80211h_pwr_constr; however, then we couldn't message the calculation in the printk (it currently says e.g. 0 (17 - 23) dBm). I don't know if that is important or not, but I opted to let it stay as-is.

Quoted 6 lines

net/mac80211/mlme.c ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,

Quoted 3 lines
net/mac80211/mlme.c +1 -1
-static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
 
+static bool ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,

I think you meant to keep u32 here? Otherwise return values from the function simply get converted to 0/1 which doesn't seem right.

You're right; this function is supposed to return a bitmask. Fixed.

/* Steinar */

Signature · 1 line
Homepage: http://www.sesse.net/
#17 lore raw

Re: [PATCH v5 2/2] mac80211: support DTPC IE (from Cisco Client eXtensions)

In reply to Johannes Berg
Quoted 5 lines · Johannes Berg

I think for some vendors shipping our stack this might become problematic. I think it would make sense to have a Kconfig option for this, probably hidden away under "if EXPERT" and defaulting to yes, to enable this code, it might be something that interferes with more CCX implementations maybe?

Are there any CCX implementations for Linux at this time? Could you even do that from just userspace? (I sort of doubt it, but it's never easy to know what illustrious userspace programmers can do :-) )

I can make a config option, but it seems a bit odd, maybe. Are you thinking there would be problems since this is an undocumented protocol, or because of the possible conflict?

Quoted 3 lines
Quoted 2 lines

+static bool ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,

The return value is useless here, so it could be void?

It is useless indeed; I kept it this way for symmetry with the other _find_ function and because it makes for slightly easier code around (you can set has_cisco_pwr = directly without needing an additional statement to make it true). But I've changed it so it's void.

I could also change it to use a return instead of an output parameter for pwr_level_cisco if you want, but I think it might become a bit confusing to have two so similar functions with different calling style.

Quoted 5 lines

net/mac80211/util.c u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action, · line 1030

Quoted 4 lines
net/mac80211/util.c +4 -0
+                       if (pos[0] != 0x00 || pos[1] != 0x40 ||
+                           pos[2] != 0x96 || pos[3] != 0x00) {
+                               break;
+                       }

Please remove those useless braces - maybe run ./scripts/checkpatch.pl?

Removed. But I've already run checkpatch and it didn't complain about this (the patch set is checkpatch-clean).

I'm in a hotel room in Seattle right now whose Wi-Fi is not Cisco-based, so I can't test the new version as thoroughly as I'd like, but I'll at least give it a boot test and then send an updated patch series as reply to this message.

/* Steinar */

Signature · 1 line
Homepage: http://www.sesse.net/
#18 lore raw

PATCH v6 1/2 mac80211: split 802.11h parsing from transmit power policy

Decouple the logic of parsing the 802.11d and 802.11h IEs from the part of deciding what to do about the data (messaging, clamping to 0 dBm, doing the actual setting). This paves the way for the next patch, which introduces more data sources for transmit power limitation.

---
 net/mac80211/mlme.c | 60 ++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 41 insertions(+), 19 deletions(-)
net/mac80211/mlme.c +41 -19
index b82a12a..918011a 100644
@@ -1157,19 +1157,21 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
 			  TU_TO_EXP_TIME(csa_ie.count * cbss->beacon_interval));
 }
 
-static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
-				       struct ieee80211_channel *channel,
-				       const u8 *country_ie, u8 country_ie_len,
-				       const u8 *pwr_constr_elem)
+static bool
+ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
+				 struct ieee80211_channel *channel,
+				 const u8 *country_ie, u8 country_ie_len,
+				 const u8 *pwr_constr_elem,
+				 int *chan_pwr, int *pwr_reduction)
 {
 	struct ieee80211_country_ie_triplet *triplet;
 	int chan = ieee80211_frequency_to_channel(channel->center_freq);
-	int i, chan_pwr, chan_increment, new_ap_level;
+	int i, chan_increment;
 	bool have_chan_pwr = false;
 
 	/* Invalid IE */
 	if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
-		return 0;
+		return false;
 
 	triplet = (void *)(country_ie + 3);
 	country_ie_len -= 3;
@@ -1197,7 +1199,7 @@ static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
 		for (i = 0; i < triplet->chans.num_channels; i++) {
 			if (first_channel + i * chan_increment == chan) {
 				have_chan_pwr = true;
-				chan_pwr = triplet->chans.max_power;
+				*chan_pwr = triplet->chans.max_power;
 				break;
 			}
 		}
@@ -1209,18 +1211,41 @@ static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
 		country_ie_len -= 3;
 	}
 
-	if (!have_chan_pwr)
-		return 0;
+	if (have_chan_pwr)
+		*pwr_reduction = *pwr_constr_elem;
+	return have_chan_pwr;
+}
+
+static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
+				       struct ieee80211_channel *channel,
+				       struct ieee80211_mgmt *mgmt,
+				       const u8 *country_ie, u8 country_ie_len,
+				       const u8 *pwr_constr_ie)
+{
+	bool has_80211h_pwr = false;
+	int chan_pwr, pwr_reduction_80211h;
+	int new_ap_level;
 
-	new_ap_level = max_t(int, 0, chan_pwr - *pwr_constr_elem);
+	if (country_ie && pwr_constr_ie &&
+	    mgmt->u.probe_resp.capab_info &
+		cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT)) {
+		has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
+			sdata, channel, country_ie, country_ie_len,
+			pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
+		new_ap_level = max_t(int, 0, chan_pwr - pwr_reduction_80211h);
+	}
 
-	if (sdata->ap_power_level == new_ap_level)
+	if (!has_80211h_pwr)
 		return 0;
 
 	sdata_info(sdata,
 		   "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
-		   new_ap_level, chan_pwr, *pwr_constr_elem,
+		   new_ap_level, chan_pwr, pwr_reduction_80211h,
 		   sdata->u.mgd.bssid);
+
+	if (sdata->ap_power_level == new_ap_level)
+		return 0;
+
 	sdata->ap_power_level = new_ap_level;
 	if (__ieee80211_recalc_txpower(sdata))
 		return BSS_CHANGED_TXPOWER;
@@ -3190,13 +3215,10 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
 					    rx_status->band, true);
 	mutex_unlock(&local->sta_mtx);
 
-	if (elems.country_elem && elems.pwr_constr_elem &&
-	    mgmt->u.probe_resp.capab_info &
-				cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT))
-		changed |= ieee80211_handle_pwr_constr(sdata, chan,
-						       elems.country_elem,
-						       elems.country_elem_len,
-						       elems.pwr_constr_elem);
+	changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
+					       elems.country_elem,
+					       elems.country_elem_len,
+					       elems.pwr_constr_elem);
 
 	ieee80211_bss_info_change_notify(sdata, changed);
 }
Signature · 1 line
2.1.0
#19 lore raw

PATCH v6 2/2 mac80211: support DTPC IE (from Cisco Client eXtensions)

In reply to Steinar H. Gunderson

Linux already supports 802.11h, where the access point can tell the client to reduce its transmission power. However, 802.11h is only defined for 5 GHz, where the need for this is much smaller than on 2.4 GHz.

Cisco has their own solution, called DTPC (Dynamic Transmit Power Control). Cisco APs on a controller sometimes but not always send 802.11h; they always send DTPC, even on 2.4 GHz. This patch adds support for parsing and honoring the DTPC IE in addition to the 802.11h element (they do not always contain the same limits, so both must be honored); the format is not documented, but very simple.

Tested (on top of wireless.git and on 3.16.1) against a Cisco Aironet 1142 joined to a Cisco 2504 WLC, by setting various transmit power levels for the given access points and observing the results. The Wireshark 802.11 dissector agrees with the interpretation of the element, except for negative numbers, which seem to never happen anyway.

---
 include/linux/ieee80211.h  |  3 ++-
 net/mac80211/ieee80211_i.h |  1 +
 net/mac80211/mlme.c        | 60 +++++++++++++++++++++++++++++++++++++---------
 net/mac80211/util.c        | 21 ++++++++++++++++
 4 files changed, 73 insertions(+), 12 deletions(-)
include/linux/ieee80211.h +2 -1
index 63ab3873..d0ec287 100644
@@ -1806,7 +1806,8 @@ enum ieee80211_eid {
 	WLAN_EID_DMG_TSPEC = 146,
 	WLAN_EID_DMG_AT = 147,
 	WLAN_EID_DMG_CAP = 148,
-	/* 149-150 reserved for Cisco */
+	/* 149 reserved for Cisco */
+	WLAN_EID_CISCO_VENDOR_SPECIFIC = 150,
 	WLAN_EID_DMG_OPERATION = 151,
 	WLAN_EID_DMG_BSS_PARAM_CHANGE = 152,
 	WLAN_EID_DMG_BEAM_REFINEMENT = 153,
net/mac80211/ieee80211_i.h +1 -0
index ef7a089..e995556 100644
@@ -1367,6 +1367,7 @@ struct ieee802_11_elems {
 	const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
 	const u8 *country_elem;
 	const u8 *pwr_constr_elem;
+	const u8 *cisco_dtpc_elem;
 	const struct ieee80211_timeout_interval_ie *timeout_int;
 	const u8 *opmode_notif;
 	const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
net/mac80211/mlme.c +49 -11

93 lines not on this page · raw message

net/mac80211/util.c +21 -0
index 725af7a..95a9159 100644
@@ -1014,6 +1014,27 @@ u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
 			}
 			elems->pwr_constr_elem = pos;
 			break;
+		case WLAN_EID_CISCO_VENDOR_SPECIFIC:
+			/* Lots of different options exist, but we only care
+			 * about the Dynamic Transmit Power Control element.
+			 * First check for the Cisco OUI, then for the DTPC
+			 * tag (0x00).
+			 */
+			if (elen < 4) {
+				elem_parse_failed = true;
+				break;
+			}
+			if (pos[0] != 0x00 || pos[1] != 0x40 ||
+			    pos[2] != 0x96 || pos[3] != 0x00)
+				break;
+			if (elen != 6) {
+				elem_parse_failed = true;
+				break;
+			}
+			if (calc_crc)
+				crc = crc32_be(crc, pos - 2, elen + 2);
+			elems->cisco_dtpc_elem = pos;
+			break;
 		case WLAN_EID_TIMEOUT_INTERVAL:
 			if (elen >= sizeof(struct ieee80211_timeout_interval_ie))
 				elems->timeout_int = (void *)pos;
Signature · 1 line
2.1.0
maintainer
#24 lore raw

Re: [PATCH v5 2/2] mac80211: support DTPC IE (from Cisco Client eXtensions)

In reply to Steinar H. Gunderson
Quoted 10 lines · Steinar H. Gunderson
Quoted 5 lines · Johannes Berg

I think for some vendors shipping our stack this might become problematic. I think it would make sense to have a Kconfig option for this, probably hidden away under "if EXPERT" and defaulting to yes, to enable this code, it might be something that interferes with more CCX implementations maybe?

Are there any CCX implementations for Linux at this time? Could you even do that from just userspace? (I sort of doubt it, but it's never easy to know what illustrious userspace programmers can do :-) )

I have no idea :-)

Quoted 3 lines

I can make a config option, but it seems a bit odd, maybe. Are you thinking there would be problems since this is an undocumented protocol, or because of the possible conflict?

I'm just thinking it might be a problem for a vendor to ship an (obviously incomplete) CCX implementation, even without advertising such. Most vendors have some relationship with Cisco at least for other drivers, so I'd prefer to avoid any possible conflict. You could argue that we shouldn't care upstream, and I'm not really sure where I fall on that question - it seems that vendors might then decide to patch it out though (which would be easy enough to do as well.)

Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

+static bool ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,

The return value is useless here, so it could be void?

Quoted 8 lines

It is useless indeed; I kept it this way for symmetry with the other _find_ function and because it makes for slightly easier code around (you can set has_cisco_pwr = directly without needing an additional statement to make it true). But I've changed it so it's void.

I could also change it to use a return instead of an output parameter for pwr_level_cisco if you want, but I think it might become a bit confusing to have two so similar functions with different calling style.

Right, that makes sense.

Quoted 8 lines
Quoted 5 lines

net/mac80211/util.c u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action, · line 1030

Quoted 4 lines
net/mac80211/util.c +4 -0
+                       if (pos[0] != 0x00 || pos[1] != 0x40 ||
+                           pos[2] != 0x96 || pos[3] != 0x00) {
+                               break;
+                       }

Please remove those useless braces - maybe run ./scripts/checkpatch.pl?

Removed. But I've already run checkpatch and it didn't complain about this (the patch set is checkpatch-clean).

Hmmm, interesting. I thought it warned about that, oh well. Thanks :)

Quoted 4 lines

I'm in a hotel room in Seattle right now whose Wi-Fi is not Cisco-based, so I can't test the new version as thoroughly as I'd like, but I'll at least give it a boot test and then send an updated patch series as reply to this message.

Great, thanks. Safe travels then :-)

It's getting late here, but I'll take a look tomorrow. Regarding the Kconfig question, I'll make up my mind and just do whichever option I decide for myself, if that's OK with you?

johannes

#25 lore raw

Re: [PATCH v5 2/2] mac80211: support DTPC IE (from Cisco Client eXtensions)

In reply to Steinar H. Gunderson
Quoted 4 lines · Steinar H. Gunderson

I'm in a hotel room in Seattle right now whose Wi-Fi is not Cisco-based, so I can't test the new version as thoroughly as I'd like, but I'll at least give it a boot test and then send an updated patch series as reply to this message.

It seems the airport in Seattle has Cisco-based Wi-Fi, so while waiting on the plane to take me on, I got:

wlan0: Limiting TX power to 23 dBm as advertised by 50:06:04:bb:d2:de

In other words, v6 still appears to work fine in practical testing. :-)

/* Steinar */

Signature · 1 line
Homepage: http://www.sesse.net/
maintainer
#20 lore raw

Re: [PATCH v6 2/2] mac80211: support DTPC IE (from Cisco Client eXtensions)

In reply to Steinar H. Gunderson
Quoted 12 lines · Steinar H. Gunderson

Linux already supports 802.11h, where the access point can tell the client to reduce its transmission power. However, 802.11h is only defined for 5 GHz, where the need for this is much smaller than on 2.4 GHz.

Cisco has their own solution, called DTPC (Dynamic Transmit Power Control). Cisco APs on a controller sometimes but not always send 802.11h; they always send DTPC, even on 2.4 GHz. This patch adds support for parsing and honoring the DTPC IE in addition to the 802.11h element (they do not always contain the same limits, so both must be honored); the format is not documented, but very simple.

Quoted 6 lines

Tested (on top of wireless.git and on 3.16.1) against a Cisco Aironet 1142 joined to a Cisco 2504 WLC, by setting various transmit power levels for the given access points and observing the results. The Wireshark 802.11 dissector agrees with the interpretation of the element, except for negative numbers, which seem to never happen anyway.

Applied both.

johannes

#21 lore raw

Re: [PATCH v6 2/2] mac80211: support DTPC IE (from Cisco Client eXtensions)

Quoted 12 lines · Johannes Berg
Quoted 12 lines

Linux already supports 802.11h, where the access point can tell the client to reduce its transmission power. However, 802.11h is only defined for 5 GHz, where the need for this is much smaller than on 2.4 GHz.

Cisco has their own solution, called DTPC (Dynamic Transmit Power Control). Cisco APs on a controller sometimes but not always send 802.11h; they always send DTPC, even on 2.4 GHz. This patch adds support for parsing and honoring the DTPC IE in addition to the 802.11h element (they do not always contain the same limits, so both must be honored); the format is not documented, but very simple.

Quoted 7 lines
Quoted 6 lines

Tested (on top of wireless.git and on 3.16.1) against a Cisco Aironet 1142 joined to a Cisco 2504 WLC, by setting various transmit power levels for the given access points and observing the results. The Wireshark 802.11 dissector agrees with the interpretation of the element, except for negative numbers, which seem to never happen anyway.

Applied both.

I found what I believe is an edge case: What happens if the element suddenly goes away from one beacon to another? Shouldn't there be a reset of the power level and then a new call to __ieee80211_recalc_txpower()?

(If so, I believe this bug was already present in the code before my first patch, as I understand the existing logic.)

/* Steinar */

Signature · 1 line
Homepage: http://www.sesse.net/
maintainer
#22 lore raw

Re: [PATCH v6 2/2] mac80211: support DTPC IE (from Cisco Client eXtensions)

Quoted 19 lines · Steinar H. Gunderson
Quoted 18 lines · Johannes Berg
Quoted 18 lines

Linux already supports 802.11h, where the access point can tell the client to reduce its transmission power. However, 802.11h is only defined for 5 GHz, where the need for this is much smaller than on 2.4 GHz.

Cisco has their own solution, called DTPC (Dynamic Transmit Power Control). Cisco APs on a controller sometimes but not always send 802.11h; they always send DTPC, even on 2.4 GHz. This patch adds support for parsing and honoring the DTPC IE in addition to the 802.11h element (they do not always contain the same limits, so both must be honored); the format is not documented, but very simple.

Tested (on top of wireless.git and on 3.16.1) against a Cisco Aironet 1142 joined to a Cisco 2504 WLC, by setting various transmit power levels for the given access points and observing the results. The Wireshark 802.11 dissector agrees with the interpretation of the element, except for negative numbers, which seem to never happen anyway.

Quoted 8 lines
Quoted 1 line

Applied both.

I found what I believe is an edge case: What happens if the element suddenly goes away from one beacon to another? Shouldn't there be a reset of the power level and then a new call to __ieee80211_recalc_txpower()?

(If so, I believe this bug was already present in the code before my first patch, as I understand the existing logic.)

I'm not sure it's worth worrying about, but if you want to write a patch I'd take it :)

johannes

#23 lore raw

Re: [PATCH v6 2/2] mac80211: support DTPC IE (from Cisco Client eXtensions)

Quoted 8 lines · Johannes Berg
Quoted 6 lines

I found what I believe is an edge case: What happens if the element suddenly goes away from one beacon to another? Shouldn't there be a reset of the power level and then a new call to __ieee80211_recalc_txpower()?

(If so, I believe this bug was already present in the code before my first patch, as I understand the existing logic.)

I'm not sure it's worth worrying about, but if you want to write a patch I'd take it :)

It actually happened to me in a real situation, which is why I noticed. It seems neither power element is typically sent at all if the value is 0. (Well, Aruba seems to do. I haven't found anyone else who does.)

/* Steinar */

Signature · 1 line
Homepage: http://www.sesse.net/