From 46a1009062c40a632761b2960f92bee8bb17a0d5 Mon Sep 17 00:00:00 2001
From: Jakob Olsson <jakob.olsson@iopsys.eu>
Date: Tue, 24 Aug 2021 11:25:09 +0200
Subject: [PATCH] map-agent: enabled/disabled via AP-Autoconfig

---
 src/core/agent.h     |  1 +
 src/core/agent_map.c |  3 +++
 src/core/config.c    | 15 ++++++++++++---
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/core/agent.h b/src/core/agent.h
index 7694a1379..b5c8dcf3d 100644
--- a/src/core/agent.h
+++ b/src/core/agent.h
@@ -353,6 +353,7 @@ struct iop_ext {
 	uint8_t bridge[16];
 	uint8_t proto[8];
 	uint8_t vid;
+	bool enabled;
 	uint32_t br_ip;
 };
 
diff --git a/src/core/agent_map.c b/src/core/agent_map.c
index 2b71e93fb..6614a34c0 100644
--- a/src/core/agent_map.c
+++ b/src/core/agent_map.c
@@ -1051,6 +1051,7 @@ int wsc_get_iop_ext(uint8_t *msg, uint16_t msglen, struct iop_ext *exts)
 {
 	uint8_t *p;
 	uint8_t *msg_end;
+#define ATTR_ENABLED (0x4C) /* IOPSYS m2 vendor extension */
 
 	if (!msg || msglen == 0 || !exts)
 		return -1;
@@ -1103,6 +1104,8 @@ int wsc_get_iop_ext(uint8_t *msg, uint16_t msglen, struct iop_ext *exts)
 						memcpy(&exts->vid, p, len);
 					else if (subelem == ATTR_BR_IP)
 						memcpy(&exts->br_ip, p, len);
+					else if (subelem == ATTR_ENABLED)
+						memcpy(&exts->enabled, p, len);
 
 					p += len;
 					attr_len -= len;
diff --git a/src/core/config.c b/src/core/config.c
index 9cb9705a6..850588b35 100644
--- a/src/core/config.c
+++ b/src/core/config.c
@@ -920,6 +920,7 @@ int uci_apply_m2(struct agent_config *cfg, char *interface_name, char *device,
 	dbg("  - VID             : 0x%02x\n", exts->vid);
 	dbg("  - BR_IP           : %s\n", ipaddr_str);
 	dbg("  - BAND            : %s\n", band_str);
+	dbg("  - ENABLED        : %d\n", exts->enabled);
 
 	// if teardown bit is set, return
 	if (BIT(4, out->mapie))
@@ -968,7 +969,7 @@ int uci_apply_m2(struct agent_config *cfg, char *interface_name, char *device,
 	uci_set_wireless_interface_option(UCI_AGENT, UCI_FH_AGENT, "ifname",
 			interface_name, "multi_ap", multiap_str);
 	uci_set_wireless_interface_option(UCI_AGENT, UCI_FH_AGENT, "ifname",
-			interface_name, "enabled", "1");
+			interface_name, "enabled", (exts->enabled ? "1" : "0"));
 	if (multi_ap & 0x01) {
 		char disallow_str[2] = {0};
 
@@ -1018,7 +1019,9 @@ int uci_apply_m2(struct agent_config *cfg, char *interface_name, char *device,
 				"ieee80211w", mfp == 1 ? "1" : "2");
 	}
 	uci_set_wireless_interface_option(UCI_WIRELESS, UCI_WLAN_IFACE, "ifname",
-			interface_name, "start_disabled", "0");
+			interface_name, "start_disabled", (exts->enabled ? "0" : "1"));
+
+
 	dbg("|%s:%d| Enabled interface %s\n", __func__, __LINE__,
 			interface_name);
 
@@ -1863,6 +1866,7 @@ static int agent_config_get_fh_iface(struct agent_config *a,
 		FH_REPORT_UTIL_THRESHOLD,
 		FH_INCLUDE_STA_STATS,
 		FH_INCLUDE_STA_METRIC,
+		FH_ENABLED,
 		NUM_POLICIES,
 	};
 	const struct uci_parse_option opts[] = {
@@ -1887,7 +1891,9 @@ static int agent_config_get_fh_iface(struct agent_config *a,
 		{ .name = "rcpi_hysteresis_margin", .type = UCI_TYPE_STRING },
 		{ .name = "report_util_threshold", .type = UCI_TYPE_STRING },
 		{ .name = "include_sta_stats", .type = UCI_TYPE_STRING },
-		{ .name = "include_sta_metric", .type = UCI_TYPE_STRING }
+		{ .name = "include_sta_metric", .type = UCI_TYPE_STRING },
+		{ .name = "enabled", .type = UCI_TYPE_STRING }
+
 	};
 	struct uci_option *tb[NUM_POLICIES];
 	struct netif_fhcfg *fh;
@@ -2026,6 +2032,9 @@ static int agent_config_get_fh_iface(struct agent_config *a,
 		fh->include_sta_metric =
 			atoi(tb[FH_INCLUDE_STA_METRIC]->v.string);
 
+	if (tb[FH_ENABLED])
+		fh->enabled = atoi(tb[FH_ENABLED]->v.string);
+
 	return 0;
 }
 
-- 
GitLab