linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Henning Rogge <hrogge@googlemail.com>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: Henning Rogge <rogge@fgan.de>,
	"Luis R. Rodriguez" <lrodriguez@atheros.com>,
	Luis Rodriguez <Luis.Rodriguez@atheros.com>,
	Marcel Holtmann <holtmann@linux.intel.com>,
	"linux-wireless" <linux-wireless@vger.kernel.org>,
	"nbd@openwrt.org" <nbd@openwrt.org>
Subject: Re: [Patch] nl80211: Add signal strength and bandwith to nl80211station info
Date: Thu, 11 Dec 2008 21:10:48 +0100	[thread overview]
Message-ID: <200812112110.59679.hrogge@googlemail.com> (raw)
In-Reply-To: <1229020101.8081.55.camel@johannes.berg>


[-- Attachment #1.1: Type: text/plain, Size: 5470 bytes --]

I noticed the MAX/AFTER_LAST comments are missing for most nl80211 enums. ;)

But I get this output on my local (2 card) ad-hoc network:
# ./iw dev wlan0 station dump
Station 00:1b:fc:91:7d:d2 (on wlan0)
        inactive time:  52 ms
        rx bytes:       207220
        tx bytes:       1396
        signal:         -66 dBm
        tx bitrate:     18.0 MBit/s

Patch for iw attached (based on git tree an hour ago). Of course the 802.11n 
output part is only compile tested. Most of the patch is to put the new copy 
of nl80211.h into iw (why does iw carry a copy of this file ?)

Henning
------------
diff --git a/nl80211.h b/nl80211.h
index 04d4516..cc93e7a 100644
--- a/nl80211.h
+++ b/nl80211.h
@@ -425,6 +425,30 @@ enum nl80211_sta_flags {
 };
 
 /**
+ * enum nl80211_rate_info - bitrate information
+ *
+ * These attribute types are used with %NL80211_STA_INFO_TXRATE
+ * when getting information about the bitrate of a station.
+ *
+ * @__NL80211_RATE_INFO_INVALID: attribute number 0 is reserved
+ * @NL80211_RATE_INFO_BITRATE: total bitrate (u16, 100kbit/s)
+ * @NL80211_RATE_INFO_MCS: mcs index for 802.11n (u8)
+ * @NL80211_RATE_INFO_40_MHZ_WIDTH: 40 Mhz dualchannel bitrate
+ * @NL80211_RATE_INFO_SHORT_GI: 400ns guard interval
+ */
+enum nl80211_rate_info {
+	__NL80211_RATE_INFO_INVALID,
+	NL80211_RATE_INFO_BITRATE,
+	NL80211_RATE_INFO_MCS,
+	NL80211_RATE_INFO_40_MHZ_WIDTH,
+	NL80211_RATE_INFO_SHORT_GI,
+
+	/* keep last */
+	__NL80211_RATE_INFO_AFTER_LAST,
+	NL80211_RATE_INFO_MAX = __NL80211_RATE_INFO_AFTER_LAST - 1
+};
+
+/**
  * enum nl80211_sta_info - station information
  *
  * These attribute types are used with %NL80211_ATTR_STA_INFO
@@ -436,6 +460,9 @@ enum nl80211_sta_flags {
  * @NL80211_STA_INFO_TX_BYTES: total transmitted bytes (u32, to this station)
  * @__NL80211_STA_INFO_AFTER_LAST: internal
  * @NL80211_STA_INFO_MAX: highest possible station info attribute
+ * @NL80211_STA_INFO_SIGNAL: signal strength of last received PPDU (u8, dBm)
+ * @NL80211_STA_INFO_TX_BITRATE: current unicast tx rate, nested attribute
+ * 	containing info as possible, see &enum nl80211_sta_info_txrate.
  */
 enum nl80211_sta_info {
 	__NL80211_STA_INFO_INVALID,
@@ -445,6 +472,8 @@ enum nl80211_sta_info {
 	NL80211_STA_INFO_LLID,
 	NL80211_STA_INFO_PLID,
 	NL80211_STA_INFO_PLINK_STATE,
+	NL80211_STA_INFO_SIGNAL,
+	NL80211_STA_INFO_TX_BITRATE,
 
 	/* keep last */
 	__NL80211_STA_INFO_AFTER_LAST,
diff --git a/station.c b/station.c
index 6503574..cf13f61 100644
--- a/station.c
+++ b/station.c
@@ -27,22 +27,31 @@ enum plink_actions {
 	PLINK_ACTION_BLOCK,
 };
 
-
 static int print_sta_handler(struct nl_msg *msg, void *arg)
 {
 	struct nlattr *tb[NL80211_ATTR_MAX + 1];
 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
 	struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1];
+	struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1];
 	char mac_addr[20], state_name[10], dev[20];
 	static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
 		[NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
 		[NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
 		[NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
+		[NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 },
+		[NL80211_STA_INFO_TX_BITRATE] = { .type = NLA_NESTED },
 		[NL80211_STA_INFO_LLID] = { .type = NLA_U16 },
 		[NL80211_STA_INFO_PLID] = { .type = NLA_U16 },
 		[NL80211_STA_INFO_PLINK_STATE] = { .type = NLA_U8 },
 	};
 
+	static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
+		[NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
+		[NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
+		[NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG },
+		[NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
+	};
+
 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
 		  genlmsg_attrlen(gnlh, 0), NULL);
 
@@ -62,7 +71,7 @@ static int print_sta_handler(struct nl_msg *msg, void *arg)
 		fprintf(stderr, "failed to parse nested attributes!");
 		return NL_SKIP;
 	}
-
+	
 	mac_addr_n2a(mac_addr, nla_data(tb[NL80211_ATTR_MAC]));
 	if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev);
 	printf("Station %s (on %s)", mac_addr, dev);
@@ -76,6 +85,33 @@ static int print_sta_handler(struct nl_msg *msg, void *arg)
 	if (sinfo[NL80211_STA_INFO_TX_BYTES])
 		printf("\n\ttx bytes:\t%d",
 			nla_get_u32(sinfo[NL80211_STA_INFO_TX_BYTES]));
+	if (sinfo[NL80211_STA_INFO_SIGNAL])
+		printf("\n\tsignal:  \t%d dBm",
+			(int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]));
+
+	if (sinfo[NL80211_STA_INFO_TX_BITRATE]) {
+		if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX,
+				sinfo[NL80211_STA_INFO_TX_BITRATE],
+				rate_policy)) {
+			fprintf(stderr, "failed to parse nested rate attributes!");
+		} else {
+			printf("\n\ttx bitrate:\t");
+			if (rinfo[NL80211_RATE_INFO_BITRATE]) {
+				int rate = nla_get_u16(rinfo[NL80211_RATE_INFO_BITRATE]);
+				printf("%d.%d MBit/s", rate / 10, rate % 10);
+			}
+			else
+				printf("?");
+
+			if (rinfo[NL80211_RATE_INFO_MCS])
+				printf(" msc:%d",
+					nla_get_u8(rinfo[NL80211_RATE_INFO_MCS]));
+			if (rinfo[NL80211_RATE_INFO_40_MHZ_WIDTH])
+				printf(" 40Mhz");
+			if (rinfo[NL80211_RATE_INFO_SHORT_GI])
+				printf(" short-guard-interval");
+		}
+	}
 	if (sinfo[NL80211_STA_INFO_LLID])
 		printf("\n\tmesh llid:\t%d",
 			nla_get_u16(sinfo[NL80211_STA_INFO_LLID]));


[-- Attachment #1.2: iw.patch --]
[-- Type: text/x-patch, Size: 4847 bytes --]

diff --git a/nl80211.h b/nl80211.h
index 04d4516..cc93e7a 100644
--- a/nl80211.h
+++ b/nl80211.h
@@ -425,6 +425,30 @@ enum nl80211_sta_flags {
 };
 
 /**
+ * enum nl80211_rate_info - bitrate information
+ *
+ * These attribute types are used with %NL80211_STA_INFO_TXRATE
+ * when getting information about the bitrate of a station.
+ *
+ * @__NL80211_RATE_INFO_INVALID: attribute number 0 is reserved
+ * @NL80211_RATE_INFO_BITRATE: total bitrate (u16, 100kbit/s)
+ * @NL80211_RATE_INFO_MCS: mcs index for 802.11n (u8)
+ * @NL80211_RATE_INFO_40_MHZ_WIDTH: 40 Mhz dualchannel bitrate
+ * @NL80211_RATE_INFO_SHORT_GI: 400ns guard interval
+ */
+enum nl80211_rate_info {
+	__NL80211_RATE_INFO_INVALID,
+	NL80211_RATE_INFO_BITRATE,
+	NL80211_RATE_INFO_MCS,
+	NL80211_RATE_INFO_40_MHZ_WIDTH,
+	NL80211_RATE_INFO_SHORT_GI,
+
+	/* keep last */
+	__NL80211_RATE_INFO_AFTER_LAST,
+	NL80211_RATE_INFO_MAX = __NL80211_RATE_INFO_AFTER_LAST - 1
+};
+
+/**
  * enum nl80211_sta_info - station information
  *
  * These attribute types are used with %NL80211_ATTR_STA_INFO
@@ -436,6 +460,9 @@ enum nl80211_sta_flags {
  * @NL80211_STA_INFO_TX_BYTES: total transmitted bytes (u32, to this station)
  * @__NL80211_STA_INFO_AFTER_LAST: internal
  * @NL80211_STA_INFO_MAX: highest possible station info attribute
+ * @NL80211_STA_INFO_SIGNAL: signal strength of last received PPDU (u8, dBm)
+ * @NL80211_STA_INFO_TX_BITRATE: current unicast tx rate, nested attribute
+ * 	containing info as possible, see &enum nl80211_sta_info_txrate.
  */
 enum nl80211_sta_info {
 	__NL80211_STA_INFO_INVALID,
@@ -445,6 +472,8 @@ enum nl80211_sta_info {
 	NL80211_STA_INFO_LLID,
 	NL80211_STA_INFO_PLID,
 	NL80211_STA_INFO_PLINK_STATE,
+	NL80211_STA_INFO_SIGNAL,
+	NL80211_STA_INFO_TX_BITRATE,
 
 	/* keep last */
 	__NL80211_STA_INFO_AFTER_LAST,
diff --git a/station.c b/station.c
index 6503574..cf13f61 100644
--- a/station.c
+++ b/station.c
@@ -27,22 +27,31 @@ enum plink_actions {
 	PLINK_ACTION_BLOCK,
 };
 
-
 static int print_sta_handler(struct nl_msg *msg, void *arg)
 {
 	struct nlattr *tb[NL80211_ATTR_MAX + 1];
 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
 	struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1];
+	struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1];
 	char mac_addr[20], state_name[10], dev[20];
 	static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
 		[NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
 		[NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
 		[NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
+		[NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 },
+		[NL80211_STA_INFO_TX_BITRATE] = { .type = NLA_NESTED },
 		[NL80211_STA_INFO_LLID] = { .type = NLA_U16 },
 		[NL80211_STA_INFO_PLID] = { .type = NLA_U16 },
 		[NL80211_STA_INFO_PLINK_STATE] = { .type = NLA_U8 },
 	};
 
+	static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
+		[NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
+		[NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
+		[NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG },
+		[NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
+	};
+
 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
 		  genlmsg_attrlen(gnlh, 0), NULL);
 
@@ -62,7 +71,7 @@ static int print_sta_handler(struct nl_msg *msg, void *arg)
 		fprintf(stderr, "failed to parse nested attributes!");
 		return NL_SKIP;
 	}
-
+	
 	mac_addr_n2a(mac_addr, nla_data(tb[NL80211_ATTR_MAC]));
 	if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev);
 	printf("Station %s (on %s)", mac_addr, dev);
@@ -76,6 +85,33 @@ static int print_sta_handler(struct nl_msg *msg, void *arg)
 	if (sinfo[NL80211_STA_INFO_TX_BYTES])
 		printf("\n\ttx bytes:\t%d",
 			nla_get_u32(sinfo[NL80211_STA_INFO_TX_BYTES]));
+	if (sinfo[NL80211_STA_INFO_SIGNAL])
+		printf("\n\tsignal:  \t%d dBm",
+			(int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]));
+
+	if (sinfo[NL80211_STA_INFO_TX_BITRATE]) {
+		if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX,
+				sinfo[NL80211_STA_INFO_TX_BITRATE],
+				rate_policy)) {
+			fprintf(stderr, "failed to parse nested rate attributes!");
+		} else {
+			printf("\n\ttx bitrate:\t");
+			if (rinfo[NL80211_RATE_INFO_BITRATE]) {
+				int rate = nla_get_u16(rinfo[NL80211_RATE_INFO_BITRATE]);
+				printf("%d.%d MBit/s", rate / 10, rate % 10);
+			}
+			else
+				printf("?");
+
+			if (rinfo[NL80211_RATE_INFO_MCS])
+				printf(" msc:%d",
+					nla_get_u8(rinfo[NL80211_RATE_INFO_MCS]));
+			if (rinfo[NL80211_RATE_INFO_40_MHZ_WIDTH])
+				printf(" 40Mhz");
+			if (rinfo[NL80211_RATE_INFO_SHORT_GI])
+				printf(" short-guard-interval");
+		}
+	}
 	if (sinfo[NL80211_STA_INFO_LLID])
 		printf("\n\tmesh llid:\t%d",
 			nla_get_u16(sinfo[NL80211_STA_INFO_LLID]));

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

  reply	other threads:[~2008-12-11 20:11 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-25 20:31 RFC Patch: Add signal strength to nl80211station info Henning Rogge
2008-11-25 20:47 ` Johannes Berg
2008-11-25 21:01   ` Henning Rogge
2008-11-26  5:21   ` Marcel Holtmann
2008-11-26  8:32     ` Johannes Berg
2008-11-26 16:17     ` Henning Rogge
2008-11-29 10:50     ` RFC Patch v2: " Henning Rogge
2008-12-01 11:17       ` Johannes Berg
2008-12-01 13:22         ` Henning Rogge
2008-12-01 17:39           ` Luis R. Rodriguez
2008-12-01 17:45             ` Luis R. Rodriguez
2008-12-01 17:53             ` Henning Rogge
2008-12-02 13:25             ` Henning Rogge
2008-12-02 20:29               ` Luis R. Rodriguez
2008-12-02 20:46                 ` Henning Rogge
2008-12-03  1:44                   ` Luis R. Rodriguez
2008-12-03 10:31                     ` Henning Rogge
2008-12-04  8:47                       ` Johannes Berg
2008-12-04  9:48                         ` Henning Rogge
2008-12-04 13:02                           ` Johannes Berg
2008-12-04 20:26                       ` Johannes Berg
2008-12-04 21:12                         ` Luis R. Rodriguez
2008-12-04 21:20                           ` Johannes Berg
2008-12-05  8:34                             ` Henning Rogge
2008-12-05  9:45                               ` Johannes Berg
2008-12-05  9:51                                 ` Henning Rogge
2008-12-05  9:54                                   ` Johannes Berg
2008-12-05 23:26                                     ` Henning Rogge
2008-12-06  9:15                                       ` Johannes Berg
2008-12-06 11:12                                         ` Henning Rogge
2008-12-06 14:10                                 ` Henning Rogge
2008-12-06 14:43                                   ` Henning Rogge
2008-12-06 14:51                                   ` Johannes Berg
2008-12-06 15:03                                     ` Henning Rogge
2008-12-06 15:46                                       ` Henning Rogge
2008-12-06 15:59                                         ` Johannes Berg
2008-12-06 16:08                                           ` Henning Rogge
2008-12-06 20:46                                           ` Luis R. Rodriguez
2008-12-07 17:32                                             ` Henning Rogge
2008-12-07 17:39                                               ` Johannes Berg
2008-12-07 18:17                                                 ` [PATCH 1/2] Add signal strength and bandwith " Henning Rogge
2008-12-08 19:43                                                   ` Johannes Berg
2008-12-09 19:50                                                     ` Henning Rogge
2008-12-09 21:16                                                       ` Johannes Berg
2008-12-10  6:53                                                         ` Henning Rogge
2008-12-10  9:05                                                           ` Johannes Berg
2008-12-10 17:40                                                             ` Henning Rogge
2008-12-10 20:45                                                               ` Johannes Berg
2008-12-10 20:58                                                                 ` Henning Rogge
2008-12-10 21:01                                                                   ` Johannes Berg
2008-12-11 17:07                                                                     ` [Patch] nl80211: " Henning Rogge
2008-12-11 17:24                                                                       ` Johannes Berg
2008-12-11 18:02                                                                         ` Henning Rogge
2008-12-11 18:14                                                                           ` Johannes Berg
2008-12-11 18:22                                                                             ` Henning Rogge
2008-12-11 18:28                                                                               ` Johannes Berg
2008-12-11 20:10                                                                                 ` Henning Rogge [this message]
2008-12-11 20:24                                                                                   ` Johannes Berg
2008-12-11 20:12                                                                                 ` Henning Rogge
2008-12-11 20:23                                                                                   ` Johannes Berg
2008-12-09 19:54                                                     ` [Patch 1/2 v2] " Henning Rogge
2008-12-09 19:58                                                     ` [Patch 2/2 " Henning Rogge
2008-12-09 21:19                                                       ` Johannes Berg
2008-12-07 18:19                                                 ` [PATCH 2/2] " Henning Rogge
2008-12-07 18:20                                                 ` [PATCH 0/2] " Henning Rogge
2008-12-06 15:48                                       ` RFC Patch v2: Add signal strength " 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=200812112110.59679.hrogge@googlemail.com \
    --to=hrogge@googlemail.com \
    --cc=Luis.Rodriguez@atheros.com \
    --cc=holtmann@linux.intel.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lrodriguez@atheros.com \
    --cc=nbd@openwrt.org \
    --cc=rogge@fgan.de \
    /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).