From 09d13559ab0a01a1428b18587fcc48b97fd4ff25 Mon Sep 17 00:00:00 2001
From: Jakob Olsson <jakob.olsson@iopsys.eu>
Date: Thu, 9 Sep 2021 14:41:45 +0200
Subject: [PATCH] map-controller: introduce rcpi threshold to uci

---
 src/core/cntlr.c     | 1 -
 src/core/cntlr_map.c | 9 +++------
 src/core/config.c    | 9 +++++++++
 src/core/config.h    | 1 +
 4 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/core/cntlr.c b/src/core/cntlr.c
index fb345de9..10b64842 100644
--- a/src/core/cntlr.c
+++ b/src/core/cntlr.c
@@ -1675,7 +1675,6 @@ static void cntlr_query_nodes(struct uloop_timeout *t)
 			send_cmdu(c, cmdu);
 			cmdu_free(cmdu);
 		}
-
 	}
 
 	uloop_timeout_set(&c->query_nodes, 60 * 1000);
diff --git a/src/core/cntlr_map.c b/src/core/cntlr_map.c
index a1b656a8..f6edf1a8 100644
--- a/src/core/cntlr_map.c
+++ b/src/core/cntlr_map.c
@@ -752,9 +752,6 @@ int handle_ap_metrics_response(void *cntlr, struct cmdu_buff *cmdu)
 	return 0;
 }
 
-#define STA_LINK_UL_RCPI_TH_1905 170
-#define STA_LINK_UL_RCPI_TH_NON1905 220
-
 int handle_sta_link_metrics_response(void *cntlr, struct cmdu_buff *cmdu)
 {
 	int i;
@@ -801,14 +798,14 @@ int handle_sta_link_metrics_response(void *cntlr, struct cmdu_buff *cmdu)
 			offset += sizeof(*b);
 		}
 
-		if (s->type == IEEE1905 && s->ul_rcpi < STA_LINK_UL_RCPI_TH_1905) {
+		if (s->type == IEEE1905 && s->ul_rcpi < c->cfg.rcpi_threshold) {
 			struct cmdu_buff *bcn_cmdu;
 			uint8_t wildcard[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 
 			if (!c->cfg.enable_bsta_steer) {
 				trace("|%s:%d| rcpi below %d, but will not query for beacon \
 				       metrics to steer as 'enable_bsta_steer' not set!\n",
-				       __func__, __LINE__, STA_LINK_UL_RCPI_TH_1905);
+				       __func__, __LINE__, c->cfg.rcpi_threshold);
 				return 0;
 			}
 
@@ -821,7 +818,7 @@ int handle_sta_link_metrics_response(void *cntlr, struct cmdu_buff *cmdu)
 				send_cmdu(c, bcn_cmdu);
 				cmdu_free(bcn_cmdu);
 			}
-		} else if (s->type == NON_IEEE1905 && s->ul_rcpi < STA_LINK_UL_RCPI_TH_NON1905) {
+		} else if (s->type == NON_IEEE1905 && s->ul_rcpi < c->cfg.rcpi_threshold) {
 			struct cmdu_buff *bcn_cmdu;
 			int i;
 			uint8_t wildcard[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
diff --git a/src/core/config.c b/src/core/config.c
index 3d74fff4..b2cca24a 100644
--- a/src/core/config.c
+++ b/src/core/config.c
@@ -417,6 +417,7 @@ static int cntlr_config_get_base(struct controller_config *c,
 		CNTLR_AL_BRIDGE,
 		CNTLR_ENABLE_STA_STEER,
 		CNTLR_ENABLE_BSTA_STEER,
+		CNTLR_RCPI_STEER_THRESHOLD,
 		NUM_CNTLR_ATTRS
 	};
 	const struct uci_parse_option opts[] = {
@@ -426,6 +427,7 @@ static int cntlr_config_get_base(struct controller_config *c,
 		{ .name = "al_bridge", .type = UCI_TYPE_STRING },
 		{ .name = "enable_sta_steer", .type = UCI_TYPE_STRING },
 		{ .name = "enable_bsta_steer", .type = UCI_TYPE_STRING },
+		{ .name = "rcpi_threshold", .type = UCI_TYPE_STRING },
 	};
 	struct uci_option *tb[NUM_CNTLR_ATTRS];
 
@@ -473,6 +475,13 @@ static int cntlr_config_get_base(struct controller_config *c,
 		c->enable_bsta_steer = atoi(val) == 1 ? true : false;
 	}
 
+	if (tb[CNTLR_RCPI_STEER_THRESHOLD]) {
+		const char *val = tb[CNTLR_RCPI_STEER_THRESHOLD]->v.string;
+
+		c->rcpi_threshold = atoi(val);
+	} else
+		c->rcpi_threshold = 120;
+
 	return 0;
 }
 
diff --git a/src/core/config.h b/src/core/config.h
index 28f0ba94..bb0899b6 100644
--- a/src/core/config.h
+++ b/src/core/config.h
@@ -100,6 +100,7 @@ struct controller_config {
 	char al_bridge[16];
 	bool enable_sta_steer;
 	bool enable_bsta_steer;
+	int rcpi_threshold;
 	int num_bss;
 	int num_vlans;
 	int num_apolicy;
-- 
GitLab