From da3c8feb33d1500ce5cd5ec6c08f34cdd09f8770 Mon Sep 17 00:00:00 2001
From: Filip Matusiak <filip.matusiak@iopsys.eu>
Date: Mon, 2 Jun 2025 16:18:32 +0200
Subject: [PATCH] Only remove stations with no active node from client
 hashtable

---
 src/cntlr.c | 26 ++++++++++++++++++++++++--
 src/cntlr.h |  1 +
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/src/cntlr.c b/src/cntlr.c
index 9d290cd4..980c0116 100644
--- a/src/cntlr.c
+++ b/src/cntlr.c
@@ -231,6 +231,23 @@ struct node *cntlr_find_node_with_bssid(struct controller *c, uint8_t *bssid)
 	return NULL;
 }
 
+/* find node to which given STA is connected */
+struct node *cntlr_find_node_with_sta(struct controller *c, uint8_t *sta_mac)
+{
+	struct node *n = NULL;
+
+	list_for_each_entry(n, &c->nodelist, list) {
+		struct sta *s = NULL;
+
+		list_for_each_entry(s, &n->stalist, list) {
+			if (!memcmp(s->macaddr, sta_mac, 6))
+				return n;
+		}
+	}
+
+	return NULL;
+}
+
 #if (EASYMESH_VERSION >= 6)
 bool cntlr_radio_support_ap_wifi7(struct wifi7_radio_capabilities *wifi7_caps)
 {
@@ -547,9 +564,14 @@ static void cntlr_freeze_sta(struct controller *c, struct sta *s)
 
 static void cntlr_remove_sta(struct controller *c, struct node *n, struct sta *s)
 {
-	cntlr_freeze_sta(c, s);
+	struct node *curr_sta_node;
+
 	node_del_sta(n, s);
-	cntlr_del_sta(c->sta_table, s->macaddr);
+	curr_sta_node = cntlr_find_node_with_sta(c, s->macaddr);
+	if (!curr_sta_node) {
+		cntlr_freeze_sta(c, s);
+		cntlr_del_sta(c->sta_table, s->macaddr);
+	}
 }
 
 struct cmdu_buff *cntlr_query_sta_metric(struct controller *c, struct sta *s)
diff --git a/src/cntlr.h b/src/cntlr.h
index 0fb959de..cd582703 100644
--- a/src/cntlr.h
+++ b/src/cntlr.h
@@ -367,6 +367,7 @@ struct node *cntlr_add_node(struct controller *c, uint8_t *almacaddr);
 struct node *cntlr_alloc_node(struct controller *c, uint8_t *almacaddr);
 struct node *cntlr_find_node(struct controller *c, uint8_t *almacaddr);
 struct node *cntlr_find_node_with_bssid(struct controller *c, uint8_t *bssid);
+struct node *cntlr_find_node_with_sta(struct controller *c, uint8_t *sta_mac);
 
 struct netif_link *cntlr_alloc_link(struct controller *c,
 		uint8_t *upstream, uint8_t *downstream);
-- 
GitLab