Skip to contentSkip to conversation

d80211: Fix wireless statistics reporting

PATCH Applied Michael Wu 3 participants 5 messages Feb 12, 2007 – Feb 19, 2007 Networking

lore
Share & tools
lore

Michael Wu

author
#0 lore raw

PATCH 1/1 d80211: Fix wireless statistics reporting

d80211: Fix wireless statistics reporting

This fixes statistics reporting. It allows drivers to specify what type of values they support, makes scan results return correct statistics, and generally fixes the brain damaged statistics reporting code.

---

 include/net/d80211.h         |    9 ++++++---
 net/d80211/ieee80211.c       |   18 +++++++++++++++---
 net/d80211/ieee80211_i.h     |    3 ++-
 net/d80211/ieee80211_ioctl.c |   42 ++++++++++++++++++------------------------
 net/d80211/ieee80211_sta.c   |   19 +++++++++++++++++++
 5 files changed, 60 insertions(+), 31 deletions(-)
include/net/d80211.h +6 -3
index 0b7b963..25a4dca 100644
@@ -230,7 +230,7 @@ struct ieee80211_rx_status {
         int channel;
         int phymode;
         int ssi;
-	int signal;
+	int signal; /* used as qual in statistics reporting */
 	int noise;
         int antenna;
         int rate;
@@ -541,8 +541,11 @@ struct ieee80211_hw {
         /* This is the time in us to change channels
          */
         int channel_change_time;
-	/* This is maximum value for rssi reported by this device */
-	int maxssi;
+	/* Maximum values for various statistics.
+	 * Leave at 0 to indicate no support. Use negative numbers for dBm. */
+	char max_rssi;
+	char max_signal;
+	char max_noise;
 
 	/* Number of available hardware TX queues for data packets.
 	 * WMM requires at least four queues. */
net/d80211/ieee80211.c +15 -3
index c83520e..0e5f23f 100644
@@ -3334,9 +3334,12 @@ ieee80211_rx_h_sta_process(struct ieee80
 
 	sta->rx_fragments++;
 	sta->rx_bytes += rx->skb->len;
-	sta->last_rssi = rx->u.rx.status->ssi;
-	sta->last_signal = rx->u.rx.status->signal;
-	sta->last_noise = rx->u.rx.status->noise;
+	sta->last_rssi = (sta->last_rssi * 15 +
+			  rx->u.rx.status->ssi) / 16;
+	sta->last_signal = (sta->last_signal * 15 +
+			    rx->u.rx.status->signal) / 16;
+	sta->last_noise = (sta->last_noise * 15 +
+			   rx->u.rx.status->noise) / 16;
 
 	if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) {
 		/* Change STA power saving mode only in the end of a frame
@@ -4624,6 +4627,15 @@ int ieee80211_register_hw(struct ieee802
 
 	local->hw.conf.beacon_int = 1000;
 
+	local->wstats_flags |= local->hw.max_rssi ?
+			       IW_QUAL_LEVEL_UPDATED : IW_QUAL_LEVEL_INVALID;
+	local->wstats_flags |= local->hw.max_signal ?
+			       IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
+	local->wstats_flags |= local->hw.max_noise ?
+			       IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
+	if (local->hw.max_rssi < 0 || local->hw.max_noise < 0)
+		local->wstats_flags |= IW_QUAL_DBM;
+
 	result = sta_info_start(local);
 	if (result < 0)
 		goto fail_sta_info;
net/d80211/ieee80211_i.h +2 -1
index 3c59a1f..d965704 100644
@@ -83,7 +83,7 @@ struct ieee80211_sta_bss {
 	int hw_mode;
 	int channel;
 	int freq;
-	int rssi;
+	int rssi, signal, noise;
 	u8 *wpa_ie;
 	size_t wpa_ie_len;
 	u8 *rsn_ie;
@@ -355,6 +355,7 @@ struct ieee80211_local {
 	int open_count;
 	int monitors;
 	struct iw_statistics wstats;
+	u8 wstats_flags;
 
 	struct class_device class_dev;
 
net/d80211/ieee80211_ioctl.c +18 -24

72 lines not on this page · raw message

net/d80211/ieee80211_sta.c +19 -0
index 78d5cf5..fc71cb2 100644
@@ -1175,12 +1175,20 @@ static void ieee80211_rx_mgmt_assoc_resp
 	/* Add STA entry for the AP */
 	sta = sta_info_get(local, ifsta->bssid);
 	if (!sta) {
+		struct ieee80211_sta_bss *bss;
 		sta = sta_info_add(local, dev, ifsta->bssid, GFP_ATOMIC);
 		if (!sta) {
 			printk(KERN_DEBUG "%s: failed to add STA entry for the"
 			       " AP\n", dev->name);
 			return;
 		}
+		bss = ieee80211_rx_bss_get(dev, ifsta->bssid);
+		if (bss) {
+			sta->last_rssi = bss->rssi;
+			sta->last_signal = bss->signal;
+			sta->last_noise = bss->noise;
+			ieee80211_rx_bss_put(dev, bss);
+		}
 	}
 
 	sta->dev = dev;
@@ -1566,6 +1574,8 @@ static void ieee80211_rx_bss_info(struct
 	bss->timestamp = timestamp;
 	bss->last_update = jiffies;
 	bss->rssi = rx_status->ssi;
+	bss->signal = rx_status->signal;
+	bss->noise = rx_status->noise;
 	if (!beacon)
 		bss->probe_resp++;
 	ieee80211_rx_bss_put(dev, bss);
@@ -2751,6 +2761,15 @@ ieee80211_sta_scan_result(struct net_dev
 					  IW_EV_FREQ_LEN);
 
 	memset(&iwe, 0, sizeof(iwe));
+	iwe.cmd = IWEVQUAL;
+	iwe.u.qual.qual = bss->signal;
+	iwe.u.qual.level = bss->rssi;
+	iwe.u.qual.noise = bss->noise;
+	iwe.u.qual.updated = local->wstats_flags;
+	current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
+					  IW_EV_QUAL_LEN);
+
+	memset(&iwe, 0, sizeof(iwe));
 	iwe.cmd = SIOCGIWENCODE;
 	if (bss->capability & WLAN_CAPABILITY_PRIVACY)
 		iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
#1 lore raw

Hi, Michael!

Quoted 7 lines · Michael Wu

d80211: Fix wireless statistics reporting

This fixes statistics reporting. It allows drivers to specify what type of values they support, makes scan results return correct statistics, and generally fixes the brain damaged statistics reporting code.

[skip]

include/net/d80211.h struct ieee80211_rx_status { · line 233

Quoted 2 lines
include/net/d80211.h +1 -1
-	int signal;
+	int signal; /* used as qual in statistics reporting */

I'm sorry but that the thing I have always hated about wireless extensions. Such tricks make the API context sensitive and loaded with assumptions.

include/net/d80211.h struct ieee80211_hw { · line 545

Quoted 2 lines
include/net/d80211.h +2 -0
+	/* Maximum values for various statistics.
+	 * Leave at 0 to indicate no support. Use negative numbers for dBm. */

That's another context sensitive API.

I've actually worked with the hardware capable of receiving more that 0 dBm (1mW). It had to be worked around. Please keep in mind that Linux is used not only on FCC approved Part 15 devices, but also on embedded systems operating on licensed frequencies.

"One milliwatt should be enough for everyone" is an approach flawed from the outset. It's limiting even for existing equipment running Linux. One megawatt would be enough though :)

Note that Jean actually added a flag to indicate that a value is in dBm in the latest versions of Wireless Extensions.

I understand d80211 still has to interact with Wireless Extensions, but let's not make things even worse.

Signature · 2 lines
Regards,
Pavel Roskin
author
#2 lore raw
Quoted 7 lines · Pavel Roskin

include/net/d80211.h struct ieee80211_rx_status { · line 233

Quoted 2 lines
include/net/d80211.h +1 -1
-	int signal;
+	int signal; /* used as qual in statistics reporting */

I'm sorry but that the thing I have always hated about wireless extensions. Such tricks make the API context sensitive and loaded with assumptions.

Ok, but I was merely clarifying the current situation. That problem has always been there since the patch for statistics reporting went in.

Quoted 2 lines

I understand d80211 still has to interact with Wireless Extensions, but let's not make things even worse.

I'm making things better. Statistics reporting is pretty bad right now in d80211 with drivers reporting bogus values when they don't know, and statistics reporting of different d80211 drivers interacting with each other when multiple devices are plugged in. This patch attempts to fix the worst issues while attempting to avoid regressions. Feel free to follow up with another patch to make statistics reporting perfect.

-Michael Wu

#3 lore raw
Quoted 10 lines · Michael Wu
Quoted 7 lines · Pavel Roskin

include/net/d80211.h struct ieee80211_rx_status { · line 233

Quoted 2 lines
include/net/d80211.h +1 -1
-	int signal;
+	int signal; /* used as qual in statistics reporting */

I'm sorry but that the thing I have always hated about wireless extensions. Such tricks make the API context sensitive and loaded with assumptions.

Ok, but I was merely clarifying the current situation. That problem has always been there since the patch for statistics reporting went in.

Sorry, I should have made it clear that my post was more a reaction to the comments than to the actual code changes.

Quoted 8 lines
Quoted 2 lines

I understand d80211 still has to interact with Wireless Extensions, but let's not make things even worse.

I'm making things better. Statistics reporting is pretty bad right now in d80211 with drivers reporting bogus values when they don't know, and statistics reporting of different d80211 drivers interacting with each other when multiple devices are plugged in. This patch attempts to fix the worst issues while attempting to avoid regressions. Feel free to follow up with another patch to make statistics reporting perfect.

This effort is very much appreciated. I'll have a closer look if I see any issues after your patch is applied.

Signature · 2 lines
Regards,
Pavel Roskin
Applied
#4 lore raw
In reply to Michael Wu
Quoted 3 lines · Michael Wu

This fixes statistics reporting. It allows drivers to specify what type of values they support, makes scan results return correct statistics, and generally fixes the brain damaged statistics reporting code.

Applied, thanks for the patch!

Jiri

Signature · 2 lines
Jiri Benc
SUSE Labs