From: David Bauer <mail@david-bauer.net>
Date: Mon, 7 Feb 2022 22:24:59 +0000 (+0100)
Subject: local-node: convert kick-dely to absolute time
X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=0dd47b143438567986bdb9aba73e8b9aa487377e;p=project%2Fusteer.git

local-node: convert kick-dely to absolute time

Signed-off-by: David Bauer <mail@david-bauer.net>
---

diff --git a/local_node.c b/local_node.c
index 03d824e..b12f7fd 100644
--- a/local_node.c
+++ b/local_node.c
@@ -457,12 +457,14 @@ usteer_local_node_status_cb(struct ubus_request *req, int type, struct blob_attr
 		MSG_FREQ,
 		MSG_CHANNEL,
 		MSG_OP_CLASS,
+		MSG_BEACON_INTERVAL,
 		__MSG_MAX,
 	};
 	static struct blobmsg_policy policy[__MSG_MAX] = {
 		[MSG_FREQ] = { "freq", BLOBMSG_TYPE_INT32 },
 		[MSG_CHANNEL] = { "channel", BLOBMSG_TYPE_INT32 },
 		[MSG_OP_CLASS] = { "op_class", BLOBMSG_TYPE_INT32 },
+		[MSG_BEACON_INTERVAL] = { "beacon_interval", BLOBMSG_TYPE_INT32 },
 	};
 	struct blob_attr *tb[__MSG_MAX];
 	struct usteer_local_node *ln;
@@ -478,6 +480,10 @@ usteer_local_node_status_cb(struct ubus_request *req, int type, struct blob_attr
 		node->channel = blobmsg_get_u32(tb[MSG_CHANNEL]);
 	if (tb[MSG_OP_CLASS])
 		node->op_class = blobmsg_get_u32(tb[MSG_OP_CLASS]);	
+
+	/* Local-Node */
+	if (tb[MSG_BEACON_INTERVAL])
+		ln->beacon_interval = blobmsg_get_u32(tb[MSG_BEACON_INTERVAL]);
 }
 
 static void
@@ -627,12 +633,13 @@ usteer_local_node_process_bss_tm_queries(struct uloop_timeout *timeout)
 	struct usteer_node *node;
 	struct sta_info *si;
 	struct sta *sta;
-
-	uint8_t validity_period = 100; /* ~ 10 seconds */
+	uint8_t validity_period;
 
 	ln = container_of(timeout, struct usteer_local_node, bss_tm_queries_timeout);
 	node = &ln->node;
 
+	validity_period = 10000 / usteer_local_node_get_beacon_interval(ln); /* ~ 10 seconds */
+
 	list_for_each_entry_safe(query, tmp, &ln->bss_tm_queries, list) {
 		sta = usteer_sta_get(query->sta_addr, false);
 		if (!sta)
@@ -806,6 +813,16 @@ node_list_cb(struct ubus_context *ctx, struct ubus_object_data *obj, void *priv)
 	usteer_register_node(ctx, obj->path, obj->id);
 }
 
+int
+usteer_local_node_get_beacon_interval(struct usteer_local_node *ln)
+{
+	/* Check if beacon-interval is not available (pre-21.02+) */
+	if (ln->beacon_interval < 1)
+		return 100;
+
+	return ln->beacon_interval;
+}
+
 void config_set_node_up_script(struct blob_attr *data)
 {
 	const char *val;
diff --git a/main.c b/main.c
index 37053d3..f46ec78 100644
--- a/main.c
+++ b/main.c
@@ -97,7 +97,7 @@ void usteer_init_defaults(void)
 	config.initial_connect_delay = 0;
 	config.remote_node_timeout = 10;
 
-	config.roam_kick_delay = 100;
+	config.roam_kick_delay = 10000;
 	config.roam_process_timeout = 5 * 1000;
 	config.roam_scan_tries = 3;
 	config.roam_scan_timeout = 0;
diff --git a/node.h b/node.h
index 6d5f8fd..1e36f58 100644
--- a/node.h
+++ b/node.h
@@ -57,6 +57,8 @@ struct usteer_local_node {
 	struct uloop_timeout bss_tm_queries_timeout;
 	struct list_head bss_tm_queries;
 
+	int beacon_interval;
+
 	struct {
 		bool present;
 		struct uloop_timeout update;
diff --git a/openwrt/usteer/files/etc/config/usteer b/openwrt/usteer/files/etc/config/usteer
index fb27fd9..534031d 100644
--- a/openwrt/usteer/files/etc/config/usteer
+++ b/openwrt/usteer/files/etc/config/usteer
@@ -87,8 +87,8 @@ config usteer
 	# Minimum time (ms) between client roaming trigger attempts
 	#option roam_trigger_interval 60000
 
-	# Timeout (in 100ms beacon intervals) for client roam requests
-	#option roam_kick_delay 100
+	# Timeout (ms) for client roam requests. usteer will kick the client after this times out.
+	#option roam_kick_delay 10000
 
 	# Minimum signal strength difference until AP steering policy is active
 	#option signal_diff_threshold 0
diff --git a/ubus.c b/ubus.c
index e5b054c..8527851 100644
--- a/ubus.c
+++ b/ubus.c
@@ -642,7 +642,7 @@ int usteer_ubus_notify_client_disassoc(struct sta_info *si)
 
 	blob_buf_init(&b, 0);
 	blobmsg_printf(&b, "addr", MAC_ADDR_FMT, MAC_ADDR_DATA(si->sta->addr));
-	blobmsg_add_u32(&b, "duration", config.roam_kick_delay);
+	blobmsg_add_u32(&b, "duration", config.roam_kick_delay / usteer_local_node_get_beacon_interval(ln));
 	usteer_ubus_disassoc_add_neighbors(si);
 	return ubus_invoke(ubus_ctx, ln->obj_id, "wnm_disassoc_imminent", b.head, NULL, 0, 100);
 }
diff --git a/usteer.h b/usteer.h
index 39412bb..a7d0bf4 100644
--- a/usteer.h
+++ b/usteer.h
@@ -311,6 +311,8 @@ int usteer_snr_to_signal(struct usteer_node *node, int snr);
 void usteer_local_nodes_init(struct ubus_context *ctx);
 void usteer_local_node_kick(struct usteer_local_node *ln);
 
+int usteer_local_node_get_beacon_interval(struct usteer_local_node *ln);
+
 void usteer_ubus_init(struct ubus_context *ctx);
 void usteer_ubus_kick_client(struct sta_info *si);
 int usteer_ubus_trigger_client_scan(struct sta_info *si);