linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: John Linville <linville@tuxdriver.com>
Cc: linux-wireless@vger.kernel.org
Subject: [PATCH 19/20 v4] cfg80211: implement get_wireless_stats
Date: Wed, 01 Jul 2009 21:27:00 +0200	[thread overview]
Message-ID: <20090701193421.796060337@sipsolutions.net> (raw)
In-Reply-To: 20090701192641.072258140@sipsolutions.net

By dropping the noise reporting, we can implement
wireless stats in cfg80211. We also make the
handler return NULL if we have no information,
which is possible thanks to the recent wext change.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
---
 include/net/cfg80211.h     |    1 
 net/mac80211/wext.c        |   69 ---------------------------------------------
 net/wireless/wext-compat.c |   59 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+), 68 deletions(-)

--- wireless-testing.orig/net/mac80211/wext.c	2009-07-01 20:29:45.000000000 +0200
+++ wireless-testing/net/mac80211/wext.c	2009-07-01 20:29:46.000000000 +0200
@@ -165,73 +165,6 @@ static int ieee80211_ioctl_giwap(struct 
 }
 
 
-/* Get wireless statistics.  Called by /proc/net/wireless and by SIOCGIWSTATS */
-static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
-{
-	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
-	struct iw_statistics *wstats = &local->wstats;
-	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
-	struct sta_info *sta = NULL;
-
-	rcu_read_lock();
-
-	if (sdata->vif.type == NL80211_IFTYPE_STATION)
-		sta = sta_info_get(local, sdata->u.mgd.bssid);
-
-	if (!sta) {
-		wstats->discard.fragment = 0;
-		wstats->discard.misc = 0;
-		wstats->qual.qual = 0;
-		wstats->qual.level = 0;
-		wstats->qual.noise = 0;
-		wstats->qual.updated = IW_QUAL_ALL_INVALID;
-	} else {
-		wstats->qual.updated = 0;
-		/*
-		 * mirror what cfg80211 does for iwrange/scan results,
-		 * otherwise userspace gets confused.
-		 */
-		if (local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
-				       IEEE80211_HW_SIGNAL_DBM)) {
-			wstats->qual.updated |= IW_QUAL_LEVEL_UPDATED;
-			wstats->qual.updated |= IW_QUAL_QUAL_UPDATED;
-		} else {
-			wstats->qual.updated |= IW_QUAL_LEVEL_INVALID;
-			wstats->qual.updated |= IW_QUAL_QUAL_INVALID;
-		}
-
-		if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
-			wstats->qual.level = sta->last_signal;
-			wstats->qual.qual = sta->last_signal;
-		} else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
-			int sig = sta->last_signal;
-
-			wstats->qual.updated |= IW_QUAL_DBM;
-			wstats->qual.level = sig;
-			if (sig < -110)
-				sig = -110;
-			else if (sig > -40)
-				sig = -40;
-			wstats->qual.qual = sig + 110;
-		}
-
-		if (local->hw.flags & IEEE80211_HW_NOISE_DBM) {
-			/*
-			 * This assumes that if driver reports noise, it also
-			 * reports signal in dBm.
-			 */
-			wstats->qual.noise = sta->last_noise;
-			wstats->qual.updated |= IW_QUAL_NOISE_UPDATED;
-		} else {
-			wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
-		}
-	}
-
-	rcu_read_unlock();
-
-	return wstats;
-}
-
 /* Structures to export the Wireless Handlers */
 
 static const iw_handler ieee80211_handler[] =
@@ -298,5 +231,5 @@ const struct iw_handler_def ieee80211_iw
 {
 	.num_standard	= ARRAY_SIZE(ieee80211_handler),
 	.standard	= (iw_handler *) ieee80211_handler,
-	.get_wireless_stats = ieee80211_get_wireless_stats,
+	.get_wireless_stats = cfg80211_wireless_stats,
 };
--- wireless-testing.orig/net/wireless/wext-compat.c	2009-07-01 20:29:45.000000000 +0200
+++ wireless-testing/net/wireless/wext-compat.c	2009-07-01 20:29:46.000000000 +0200
@@ -1157,3 +1157,62 @@ int cfg80211_wext_giwrate(struct net_dev
 	return 0;
 }
 EXPORT_SYMBOL_GPL(cfg80211_wext_giwrate);
+
+/* Get wireless statistics.  Called by /proc/net/wireless and by SIOCGIWSTATS */
+struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
+{
+	struct wireless_dev *wdev = dev->ieee80211_ptr;
+	struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
+	/* we are under RTNL - globally locked - so can use static structs */
+	static struct iw_statistics wstats;
+	static struct station_info sinfo;
+	u8 *addr;
+
+	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
+		return NULL;
+
+	if (!rdev->ops->get_station)
+		return NULL;
+
+	addr = wdev->wext.connect.bssid;
+	if (!addr)
+		return NULL;
+
+	if (rdev->ops->get_station(&rdev->wiphy, dev, addr, &sinfo))
+		return NULL;
+
+	memset(&wstats, 0, sizeof(wstats));
+
+	switch (rdev->wiphy.signal_type) {
+	case CFG80211_SIGNAL_TYPE_MBM:
+		if (sinfo.filled & STATION_INFO_SIGNAL) {
+			int sig = sinfo.signal;
+			wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
+			wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
+			wstats.qual.updated |= IW_QUAL_DBM;
+			wstats.qual.level = sig;
+			if (sig < -110)
+				sig = -110;
+			else if (sig > -40)
+				sig = -40;
+			wstats.qual.qual = sig + 110;
+			break;
+		}
+	case CFG80211_SIGNAL_TYPE_UNSPEC:
+		if (sinfo.filled & STATION_INFO_SIGNAL) {
+			wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
+			wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
+			wstats.qual.level = sinfo.signal;
+			wstats.qual.qual = sinfo.signal;
+			break;
+		}
+	default:
+		wstats.qual.updated |= IW_QUAL_LEVEL_INVALID;
+		wstats.qual.updated |= IW_QUAL_QUAL_INVALID;
+	}
+
+	wstats.qual.updated |= IW_QUAL_NOISE_INVALID;
+
+	return &wstats;
+}
+EXPORT_SYMBOL_GPL(cfg80211_wireless_stats);
--- wireless-testing.orig/include/net/cfg80211.h	2009-07-01 20:29:45.000000000 +0200
+++ wireless-testing/include/net/cfg80211.h	2009-07-01 20:29:46.000000000 +0200
@@ -1646,6 +1646,7 @@ int cfg80211_wext_siwtxpower(struct net_
 int cfg80211_wext_giwtxpower(struct net_device *dev,
 			     struct iw_request_info *info,
 			     union iwreq_data *data, char *keybuf);
+struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev);
 
 int cfg80211_wext_siwpower(struct net_device *dev,
 			   struct iw_request_info *info,

-- 


  parent reply	other threads:[~2009-07-01 19:36 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-01 19:26 [PATCH 00/20 v4] wireless patch dump Johannes Berg
2009-07-01 19:26 ` [PATCH 01/20 v4] wext: allow returning NULL stats Johannes Berg
2009-07-01 19:26 ` [PATCH 02/20 v4] mac80211: fix todo lock Johannes Berg
2009-07-01 19:26 ` [PATCH 03/20 v4] wext: default to y Johannes Berg
2009-07-01 19:26 ` [PATCH 04/20 v4] cfg80211: move break statement to correct place Johannes Berg
2009-07-01 19:26 ` [PATCH 05/20 v4] nl80211: clean up function definitions Johannes Berg
2009-07-01 19:26 ` [PATCH 06/20 v4] cfg80211: use proper allocation flags Johannes Berg
2009-07-01 19:26 ` [PATCH 07/20 v4] cfg80211: remove wireless_dev->bssid Johannes Berg
2009-07-01 19:26 ` [PATCH 08/20 v4] mac80211: tell SME about real auth state Johannes Berg
2009-07-01 19:26 ` [PATCH 09/20 v4] wext: constify extra argument to wireless_send_event Johannes Berg
2009-07-01 19:26 ` [PATCH 10/20 v4] cfg80211: introduce nl80211 testmode command Johannes Berg
2009-07-01 19:26 ` [PATCH 11/20 v4] mac80211: remove an unused function declaration Johannes Berg
2009-07-01 19:26 ` [PATCH 12/20 v4] wireless: define AKM suites Johannes Berg
2009-07-01 19:26 ` [PATCH 13/20 v4] cfg80211: connect/disconnect API Johannes Berg
2009-07-01 19:26 ` [PATCH 14/20 v4] cfg80211: emulate connect with auth/assoc Johannes Berg
2009-07-02  7:13   ` [PATCH 14/20 v4.1] " Johannes Berg
2009-07-01 19:26 ` [PATCH 15/20 v4] cfg80211: managed mode wext compatibility Johannes Berg
2009-07-02 23:55   ` [PATCH] iwmc3200wifi: cfg80211 managed mode port Samuel Ortiz
2009-07-03  8:02     ` Johannes Berg
2009-07-03 13:10       ` Samuel Ortiz
2009-07-05  1:37     ` Johannes Berg
2009-07-03  0:00   ` [PATCH] cfg80211: check for current_bss from giwrate Samuel Ortiz
2009-07-03  8:01     ` Johannes Berg
2009-07-01 19:26 ` [PATCH 16/20 v4] cfg80211: implement iwpower Johannes Berg
2009-07-01 19:26 ` [PATCH 17/20 v4] cfg80211: implement IWAP for WDS Johannes Berg
2009-07-01 19:26 ` [PATCH 18/20 v4] cfg80211: implement IWRATE Johannes Berg
2009-07-01 19:27 ` Johannes Berg [this message]
2009-07-01 19:27 ` [PATCH 20/20 v4] mac80211: re-add HT disabling Johannes Berg
2009-07-01 19:40 ` [PATCH 21/20 v4] mac80211: remove auth algorithm retry Johannes Berg
2009-07-01 19:41 ` [PATCH 22/20 v4] mac80211: remove dead code, clean up Johannes Berg
2009-07-02  7:58 ` [PATCH] cfg80211: send events for userspace SME Johannes Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090701193421.796060337@sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).