From 3e470fe614935ab3f1bf1423e77c44ffa219c126 Mon Sep 17 00:00:00 2001
From: Jakob Olsson <jakob.olsson@iopsys.eu>
Date: Tue, 14 Sep 2021 17:11:22 +0200
Subject: [PATCH] TS move pvid/pcp_default to global section

---
 src/controller.conf             | 18 ++++++++---------
 src/core/cntlr_cmdu_generator.c |  4 +---
 src/core/cntlr_tlv_generator.c  |  4 ++--
 src/core/cntlr_ubus.c           |  2 +-
 src/core/config.c               | 34 ++++++++++-----------------------
 src/core/config.h               |  5 ++---
 6 files changed, 24 insertions(+), 43 deletions(-)

diff --git a/src/controller.conf b/src/controller.conf
index ab9003d9..6b9b4454 100644
--- a/src/controller.conf
+++ b/src/controller.conf
@@ -2,8 +2,10 @@ config controller controller
 	option enabled '1'
 	option registrar '5 2'	    #bands on which wps registrar supported
 	option debug '6'
+	option pvid '100'                          # primary vlan id
+	option pcp_default '5'                     # default vlan pcp
 
-config fh-credentials
+config bss
 	option band '5'
 	option encryption 'psk2'
 	option key '1234567890'
@@ -22,7 +24,7 @@ config vlan 'guest'
 	option proto 'static'
 	option ipaddr '10.0.1.1'
 
-config fh-credentials
+config bss
 	option band '5'
 	option encryption 'psk2'
 	option key '1234567890'
@@ -30,20 +32,20 @@ config fh-credentials
 	option bk_key '5555555555'
 	option bk_ssid 'map-bkhaul-5'
 
-config bk-credentials
+config bss
 	option band '5'
 	option encryption 'psk2'
 	option key '5555555555'
 	option ssid 'map-bkhaul-5'
 
-config bk-credentials
+config bss
 	option band '5'
 	option encryption 'psk2'
 	option key '5555555555'
 	option ssid 'map-bkhaul-5-alternative'
 	option vlan_id '2'
 
-config bk-credentials
+config bss
 	option band '5'
 	option encryption 'psk2'
 	option key '5555555555'
@@ -54,7 +56,7 @@ config bk-credentials
 #	option multi_ap_backhaul_ssid 'MultiAP-0022077E9CD6'    # possible future TODO
 	option disallow_bsta '1'		# bitmap, 1 for disallow p1, 2 to disallow p2, 3 to disallow both (probably never applicable)
 
-config bk-credentials
+config bss
 	option band '2'
 	option encryption 'psk2'
 	option key '2222222222'
@@ -81,8 +83,6 @@ config agent-policy
 	option rcpi_hysteresis_margin '0'          # 0, or > 0 - hysteresis margin
 	option include_sta_stats '0'               # sta stats in AP metric resp
 	option include_sta_metric '0'              # sta metric in AP metric resp
-	option pvid '100'                          # primary vlan id
-	option pcp_default '5'                     # default vlan pcp
 	option disallow_bsta_p1 '0'                # 0 or 1 profile-1 bSTA
 	option disallow_bsta_p2 '0'                # 0 or 1 profile-2 bSTA
 
@@ -102,8 +102,6 @@ config agent-policy
 	option rcpi_hysteresis_margin '0'          # 0, or > 0 - hysteresis margin
 	option include_sta_stats '0'               # sta stats in AP metric resp
 	option include_sta_metric '0'              # sta metric in AP metric resp
-	option pvid '100'                          # primary vlan id
-	option pcp_default '5'                     # default vlan pcp
 	option disallow_bsta_p1 '0'                # 0 or 1 profile-1 bSTA
 	option disallow_bsta_p2 '0'                # 0 or 1 profile-2 bSTA
 
diff --git a/src/core/cntlr_cmdu_generator.c b/src/core/cntlr_cmdu_generator.c
index 2553a683..725e9067 100644
--- a/src/core/cntlr_cmdu_generator.c
+++ b/src/core/cntlr_cmdu_generator.c
@@ -352,7 +352,6 @@ struct cmdu_buff *cntlr_gen_bk_caps_query(struct controller *c,
 	}
 	cmdu_set_type(resp, CMDU_BACKHAUL_STA_CAPABILITY_QUERY);
 	cmdu_set_mid(resp, mid);
-	strncpy(resp->dev_ifname, c->cfg.al_bridge, 15);
 
 	memcpy(resp->origin, origin, 6);
 	cmdu_put_eom(resp);
@@ -574,7 +573,6 @@ struct cmdu_buff *cntlr_gen_channel_scan_request(struct controller *c,
 	}
 	cmdu_set_type(resp, CMDU_CHANNEL_SCAN_REQUEST);
 	cmdu_set_mid(resp, mid);
-	strncpy(resp->dev_ifname, c->cfg.al_bridge, 15);
 	ret = cntlr_gen_channel_scan_req(c, resp, num_radios, num_ch_to_scan, channel, radio);
 	if (ret)
 		goto error;
@@ -721,4 +719,4 @@ struct cmdu_buff *cntlr_gen_client_steer_request(struct controller *c,
 error:
 	cmdu_free(frm);
 	return NULL;
-}
\ No newline at end of file
+}
diff --git a/src/core/cntlr_tlv_generator.c b/src/core/cntlr_tlv_generator.c
index 1d5ed70a..390f8982 100644
--- a/src/core/cntlr_tlv_generator.c
+++ b/src/core/cntlr_tlv_generator.c
@@ -118,8 +118,8 @@ int cntlr_gen_8021q_settings(struct controller *c, struct cmdu_buff *frm,
 	t->len = sizeof(*data);
 
 	data = (struct tlv_default_8021q_settings *) t->data;
-	BUF_PUT_BE16(data->pvid, a->pvid);
-	data->pcp = (a->pcp_default << 5) & PCP_MASK;
+	BUF_PUT_BE16(data->pvid, c->cfg.pvid);
+	data->pcp = (c->cfg.pcp_default << 5) & PCP_MASK;
 
 	ret = cmdu_put_tlv(frm, t);
 	if (ret) {
diff --git a/src/core/cntlr_ubus.c b/src/core/cntlr_ubus.c
index eb054bbc..cf9ad695 100644
--- a/src/core/cntlr_ubus.c
+++ b/src/core/cntlr_ubus.c
@@ -1274,7 +1274,7 @@ static int cntlr_config_ap(struct ubus_context *ctx, struct ubus_object *obj,
 
 	cmdu->num_tlvs++;
 	p1->tlv_type = MAP_TLV_DEFAULT_8021Q_SETTINGS;
-	p1->primary_vid = a->pvid;
+	p1->primary_vid = c->cfg->pvid;
 	p1->pcp = a->pcp_default;
 
 	p2 = (struct tlv_traffic_sep_policy *) calloc(1, sizeof(*p2));
diff --git a/src/core/config.c b/src/core/config.c
index b2cca24a..e98e6775 100644
--- a/src/core/config.c
+++ b/src/core/config.c
@@ -379,8 +379,6 @@ void cntlr_config_dump(struct controller_config *c)
 	dbg("  RCPI hysteresis margin: %d\n", c->apolicy.rcpi_hysteresis_margin);
 	dbg("  Include STA stats     : %d\n", c->apolicy.include_sta_stats);
 	dbg("  Include STA metric    : %d\n", c->apolicy.include_sta_metric);
-	dbg("  Primary VLAN ID       : %d\n", c->apolicy.pvid);
-	dbg("  PCP Default           : %d\n", c->apolicy.pcp_default);
 	dbg("  Disallow bSTA P1      : %d\n", c->apolicy.disallow_bsta_p1);
 	dbg("  Disallow bSTA P2      : %d\n", c->apolicy.disallow_bsta_p2);
 
@@ -414,20 +412,22 @@ static int cntlr_config_get_base(struct controller_config *c,
 		CNTLR_ENABLED,
 		CNTLR_REGISTRAR,
 		CNTLR_DEBUG,
-		CNTLR_AL_BRIDGE,
 		CNTLR_ENABLE_STA_STEER,
 		CNTLR_ENABLE_BSTA_STEER,
 		CNTLR_RCPI_STEER_THRESHOLD,
+		CNTLR_PVID,
+		CNTLR_PCP_DEFAULT,
 		NUM_CNTLR_ATTRS
 	};
 	const struct uci_parse_option opts[] = {
 		{ .name = "enabled", .type = UCI_TYPE_STRING },
 		{ .name = "registrar", .type = UCI_TYPE_STRING },
 		{ .name = "debug", .type = UCI_TYPE_STRING },
-		{ .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 },
+		{ .name = "pvid", .type = UCI_TYPE_STRING },
+		{ .name = "pcp_default", .type = UCI_TYPE_STRING },
 	};
 	struct uci_option *tb[NUM_CNTLR_ATTRS];
 
@@ -454,15 +454,6 @@ static int cntlr_config_get_base(struct controller_config *c,
 			verbose = c->debug_level;
 	}
 
-
-	if (tb[CNTLR_AL_BRIDGE]) {
-		const char *iface;
-
-		iface = tb[CNTLR_AL_BRIDGE]->v.string;
-		strncpy(c->al_bridge, iface, sizeof(c->al_bridge) - 1);
-	} else /* Default to br-lan if non-specfied */
-		strncpy(c->al_bridge, "br-lan", sizeof(c->al_bridge) - 1);
-
 	if (tb[CNTLR_ENABLE_STA_STEER]) {
 		const char *val = tb[CNTLR_ENABLE_STA_STEER]->v.string;
 
@@ -482,6 +473,12 @@ static int cntlr_config_get_base(struct controller_config *c,
 	} else
 		c->rcpi_threshold = 120;
 
+	if (tb[CNTLR_PVID])
+		c->pvid = atoi(tb[CNTLR_PVID]->v.string);
+
+	if (tb[CNTLR_PCP_DEFAULT])
+		c->pcp_default = atoi(tb[CNTLR_PCP_DEFAULT]->v.string);
+
 	return 0;
 }
 
@@ -690,8 +687,6 @@ static int cntlr_config_get_agent_policy(struct controller_config *c,
 		POL_RPT_HYS_MARGIN,
 		POL_INC_STA_STATS,
 		POL_INC_STA_METRIC,
-		POL_PVID,
-		POL_PCP_DEFAULT,
 		POL_DISALLOW_BSTA_P1,
 		POL_DISALLOW_BSTA_P2,
 		NUM_POLICIES,
@@ -713,8 +708,6 @@ static int cntlr_config_get_agent_policy(struct controller_config *c,
 		{ .name = "rcpi_hysteresis_margin", .type = UCI_TYPE_STRING },
 		{ .name = "include_sta_stats", .type = UCI_TYPE_STRING },
 		{ .name = "include_sta_metric", .type = UCI_TYPE_STRING },
-		{ .name = "pvid", .type = UCI_TYPE_STRING },
-		{ .name = "pcp_default", .type = UCI_TYPE_STRING },
 		{ .name = "disallow_bsta_p1", .type = UCI_TYPE_STRING },
 		{ .name = "disallow_bsta_p2", .type = UCI_TYPE_STRING },
 	};
@@ -819,13 +812,6 @@ static int cntlr_config_get_agent_policy(struct controller_config *c,
 					true : false;
 	}
 
-	if (tb[POL_PVID])
-		a->pvid = atoi(tb[POL_PVID]->v.string);
-
-	if (tb[POL_PCP_DEFAULT])
-		a->pcp_default = atoi(tb[POL_PCP_DEFAULT]->v.string);
-
-
 	if (tb[POL_DISALLOW_BSTA_P1]) {
 		a->disallow_bsta_p1 =
 			atoi(tb[POL_DISALLOW_BSTA_P1]->v.string) == 1 ?
diff --git a/src/core/config.h b/src/core/config.h
index bb0899b6..0cde4c04 100644
--- a/src/core/config.h
+++ b/src/core/config.h
@@ -77,8 +77,6 @@ struct agent_policy {
 	uint8_t rcpi_hysteresis_margin;   /* 0, or > 0 - hysteresis margin */
 	bool include_sta_stats;           /* sta stats in AP metric response */
 	bool include_sta_metric;          /* sta metric in AP metric response */
-	uint16_t pvid;                    /* primary vlan id */
-	uint8_t pcp_default;              /* default vlan pcp */
 	bool disallow_bsta_p1;            /* disallow profile1 bSTA link */
 	bool disallow_bsta_p2;            /* disallow profile2 bSTA link */
 	int num_steer_stas;
@@ -97,13 +95,14 @@ struct controller_config {
 	bool has_registrar_5g;
 	bool has_registrar_2g;
 	int debug_level;
-	char al_bridge[16];
 	bool enable_sta_steer;
 	bool enable_bsta_steer;
 	int rcpi_threshold;
 	int num_bss;
 	int num_vlans;
 	int num_apolicy;
+	uint16_t pvid;
+	uint8_t pcp_default;
 	struct agent_policy apolicy;
 	struct list_head bsslist;
 	struct list_head vlanlist;
-- 
GitLab