From 6a20591b20af6a2d33734529f2272a2b7729f912 Mon Sep 17 00:00:00 2001 From: David Bauer Date: Mon, 27 Sep 2021 20:56:41 +0200 Subject: [PATCH] sta-info: add last_connected field Add a last_connected field to the sta_info struct. This field can be used to determine, if and when a client was last connected to a given node. This way, other nodes can determine where a client roamed to or from. Signed-off-by: David Bauer --- local_node.c | 6 +++++- parse.c | 5 ++++- remote.c | 3 +++ remote.h | 2 ++ usteer.h | 1 + 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/local_node.c b/local_node.c index 50e06a7..bc27766 100644 --- a/local_node.c +++ b/local_node.c @@ -172,6 +172,8 @@ usteer_local_node_set_assoc(struct usteer_local_node *ln, struct blob_attr *cl) int n_assoc = 0; int rem; + usteer_update_time(); + list_for_each_entry(si, &node->sta_info, node_list) { if (si->connected) si->connected = STA_DISCONNECTED; @@ -193,8 +195,10 @@ usteer_local_node_set_assoc(struct usteer_local_node *ln, struct blob_attr *cl) h->update_sta(node, si); } usteer_local_node_assoc_update(si, cur); - if (si->connected == STA_CONNECTED) + if (si->connected == STA_CONNECTED) { + si->last_connected = current_time; n_assoc++; + } } node->n_assoc = n_assoc; diff --git a/parse.c b/parse.c index 6f53b03..b0b7bc2 100644 --- a/parse.c +++ b/parse.c @@ -124,6 +124,7 @@ bool parse_apmsg_sta(struct apmsg_sta *msg, struct blob_attr *data) [APMSG_STA_SEEN] = { .type = BLOB_ATTR_INT32 }, [APMSG_STA_TIMEOUT] = { .type = BLOB_ATTR_INT32 }, [APMSG_STA_CONNECTED] = { .type = BLOB_ATTR_INT8 }, + [APMSG_STA_LAST_CONNECTED] = { .type = BLOB_ATTR_INT32 }, }; struct blob_attr *tb[__APMSG_STA_MAX]; @@ -132,7 +133,8 @@ bool parse_apmsg_sta(struct apmsg_sta *msg, struct blob_attr *data) !tb[APMSG_STA_SIGNAL] || !tb[APMSG_STA_SEEN] || !tb[APMSG_STA_TIMEOUT] || - !tb[APMSG_STA_CONNECTED]) + !tb[APMSG_STA_CONNECTED] || + !tb[APMSG_STA_LAST_CONNECTED]) return false; if (blob_len(tb[APMSG_STA_ADDR]) != sizeof(msg->addr)) @@ -143,6 +145,7 @@ bool parse_apmsg_sta(struct apmsg_sta *msg, struct blob_attr *data) msg->seen = blob_get_int32(tb[APMSG_STA_SEEN]); msg->timeout = blob_get_int32(tb[APMSG_STA_TIMEOUT]); msg->connected = blob_get_int8(tb[APMSG_STA_CONNECTED]); + msg->last_connected = blob_get_int32(tb[APMSG_STA_LAST_CONNECTED]); return true; } diff --git a/remote.c b/remote.c index 37d80e6..d0d9e17 100644 --- a/remote.c +++ b/remote.c @@ -180,6 +180,7 @@ interface_add_station(struct usteer_remote_node *node, struct blob_attr *data) si->connected = msg.connected; si->signal = msg.signal; si->seen = current_time - msg.seen; + si->last_connected = current_time - msg.last_connected; usteer_sta_info_update_timeout(si, msg.timeout); } @@ -519,6 +520,7 @@ static void interface_send_msg(struct interface *iface, struct blob_attr *data){ static void usteer_send_sta_info(struct sta_info *sta) { int seen = current_time - sta->seen; + int last_connected = !!sta->connected ? 0 : current_time - sta->last_connected; void *c; c = blob_nest_start(&buf, 0); @@ -526,6 +528,7 @@ static void usteer_send_sta_info(struct sta_info *sta) blob_put_int8(&buf, APMSG_STA_CONNECTED, !!sta->connected); blob_put_int32(&buf, APMSG_STA_SIGNAL, sta->signal); blob_put_int32(&buf, APMSG_STA_SEEN, seen); + blob_put_int32(&buf, APMSG_STA_LAST_CONNECTED, last_connected); blob_put_int32(&buf, APMSG_STA_TIMEOUT, config.local_sta_timeout - seen); blob_nest_end(&buf, c); } diff --git a/remote.h b/remote.h index e821de9..9361b25 100644 --- a/remote.h +++ b/remote.h @@ -72,6 +72,7 @@ enum { APMSG_STA_TIMEOUT, APMSG_STA_SEEN, APMSG_STA_CONNECTED, + APMSG_STA_LAST_CONNECTED, __APMSG_STA_MAX }; @@ -82,6 +83,7 @@ struct apmsg_sta { int signal; int timeout; int seen; + int last_connected; }; bool parse_apmsg(struct apmsg *msg, struct blob_attr *data); diff --git a/usteer.h b/usteer.h index 5afc594..866c0b2 100644 --- a/usteer.h +++ b/usteer.h @@ -210,6 +210,7 @@ struct sta_info { struct sta_info_stats stats[__EVENT_TYPE_MAX]; uint64_t created; uint64_t seen; + uint64_t last_connected; int signal; enum roam_trigger_state roam_state; -- 2.30.2