Linux-Wireless Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH-v2 1/2] iw:  Support associated-at station statistic.
@ 2019-09-09 20:13 greearb
  2019-09-09 20:13 ` [PATCH-v2 2/2] iw: Print current time in station info dump greearb
  0 siblings, 1 reply; 2+ messages in thread
From: greearb @ 2019-09-09 20:13 UTC (permalink / raw)
  To: linux-wireless; +Cc: Ben Greear

From: Ben Greear <greearb@candelatech.com>

This can be helpful for calculating roaming time and other
higher precision stats.

Signed-off-by: Ben Greear <greearb@candelatech.com>
---
 nl80211.h | 2 ++
 station.c | 6 ++++++
 2 files changed, 8 insertions(+)

diff --git a/nl80211.h b/nl80211.h
index ca8f207..89d88fc 100644
--- a/nl80211.h
+++ b/nl80211.h
@@ -3201,6 +3201,7 @@ enum nl80211_sta_bss_param {
  *	sent to the station (u64, usec)
  * @NL80211_STA_INFO_AIRTIME_WEIGHT: current airtime weight for station (u16)
  * @NL80211_STA_INFO_AIRTIME_LINK_METRIC: airtime link metric for mesh station
+ * @NL80211_STA_INFO_ASSOC_AT_BOOTTIME: Timestamp of last assoc -> auth transition
  * @__NL80211_STA_INFO_AFTER_LAST: internal
  * @NL80211_STA_INFO_MAX: highest possible station info attribute
  */
@@ -3247,6 +3248,7 @@ enum nl80211_sta_info {
 	NL80211_STA_INFO_TX_DURATION,
 	NL80211_STA_INFO_AIRTIME_WEIGHT,
 	NL80211_STA_INFO_AIRTIME_LINK_METRIC,
+	NL80211_STA_INFO_ASSOC_AT_BOOTTIME,
 
 	/* keep last */
 	__NL80211_STA_INFO_AFTER_LAST,
diff --git a/station.c b/station.c
index aaad079..61a317d 100644
--- a/station.c
+++ b/station.c
@@ -569,6 +569,12 @@ static int print_sta_handler(struct nl_msg *msg, void *arg)
 	if (sinfo[NL80211_STA_INFO_CONNECTED_TIME])
 		printf("\n\tconnected time:\t%u seconds",
 			nla_get_u32(sinfo[NL80211_STA_INFO_CONNECTED_TIME]));
+	if (sinfo[NL80211_STA_INFO_ASSOC_AT_BOOTTIME]) {
+		unsigned long long bt;
+		bt = (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_ASSOC_AT_BOOTTIME]);
+		printf("\n\tassociated at:\t%llu.%.3llus [boottime]",
+		       bt/1000000000, (bt%1000000000)/1000000);
+	}
 
 	printf("\n");
 	return NL_SKIP;
-- 
2.7.5


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH-v2 2/2] iw:  Print current time in station info dump
  2019-09-09 20:13 [PATCH-v2 1/2] iw: Support associated-at station statistic greearb
@ 2019-09-09 20:13 ` greearb
  0 siblings, 0 replies; 2+ messages in thread
From: greearb @ 2019-09-09 20:13 UTC (permalink / raw)
  To: linux-wireless; +Cc: Ben Greear

From: Ben Greear <greearb@candelatech.com>

This lets us more precisely calculate the absolute timestamp
of last-rix (ie, now - idle).

Signed-off-by: Ben Greear <greearb@candelatech.com>
---
 station.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/station.c b/station.c
index 61a317d..1be3974 100644
--- a/station.c
+++ b/station.c
@@ -7,6 +7,7 @@
 #include <netlink/genl/ctrl.h>
 #include <netlink/msg.h>
 #include <netlink/attr.h>
+#include <time.h>
 
 #include "nl80211.h"
 #include "iw.h"
@@ -326,6 +327,12 @@ static int print_sta_handler(struct nl_msg *msg, void *arg)
 		[NL80211_STA_INFO_ACK_SIGNAL_AVG] = { .type = NLA_U8 },
 	};
 	char *chain;
+	struct timeval now;
+	unsigned long long now_ms;
+
+	gettimeofday(&now, NULL);
+	now_ms = now.tv_sec * 1000;
+	now_ms += (now.tv_usec / 1000);
 
 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
 		  genlmsg_attrlen(gnlh, 0), NULL);
@@ -571,12 +578,22 @@ static int print_sta_handler(struct nl_msg *msg, void *arg)
 			nla_get_u32(sinfo[NL80211_STA_INFO_CONNECTED_TIME]));
 	if (sinfo[NL80211_STA_INFO_ASSOC_AT_BOOTTIME]) {
 		unsigned long long bt;
+		struct timespec now_ts;
+		unsigned long long boot_ns;
+		unsigned long long assoc_at_ms;
+
+		clock_gettime(CLOCK_BOOTTIME, &now_ts);
+		boot_ns = now_ts.tv_sec * 1000000000;
+		boot_ns += now_ts.tv_nsec;
+
 		bt = (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_ASSOC_AT_BOOTTIME]);
-		printf("\n\tassociated at:\t%llu.%.3llus [boottime]",
+		printf("\n\tassociated at [boottime]:\t%llu.%.3llus",
 		       bt/1000000000, (bt%1000000000)/1000000);
+		assoc_at_ms = now_ms - ((boot_ns - bt) / 1000000);
+		printf("\n\tassociated at:\t%llu ms", assoc_at_ms);
 	}
 
-	printf("\n");
+	printf("\n\tcurrent time:\t%llu ms\n", now_ms);
 	return NL_SKIP;
 }
 
-- 
2.7.5


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-09 20:13 [PATCH-v2 1/2] iw: Support associated-at station statistic greearb
2019-09-09 20:13 ` [PATCH-v2 2/2] iw: Print current time in station info dump greearb

Linux-Wireless Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-wireless/0 linux-wireless/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-wireless linux-wireless/ https://lore.kernel.org/linux-wireless \
		linux-wireless@vger.kernel.org linux-wireless@archiver.kernel.org
	public-inbox-index linux-wireless


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-wireless


AGPL code for this site: git clone https://public-inbox.org/ public-inbox