From 518549798a9bdd7a62d324a9127a296cf3aa4a94 Mon Sep 17 00:00:00 2001
From: John Crispin <john@phrozen.org>
Date: Wed, 16 Nov 2022 16:38:23 +0100
Subject: [PATCH 20/21] hostapd: add uci-section

Signed-off-by: John Crispin <john@phrozen.org>
---
 .../network/services/hostapd/files/hostapd.sh |  6 ++-
 .../hostapd/patches/901-cfg-section.patch     | 51 +++++++++++++++++++
 2 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 package/network/services/hostapd/patches/901-cfg-section.patch

diff --git a/package/network/services/hostapd/files/hostapd.sh b/package/network/services/hostapd/files/hostapd.sh
index 3ac9e7b590..c308d1d2de 100644
--- a/package/network/services/hostapd/files/hostapd.sh
+++ b/package/network/services/hostapd/files/hostapd.sh
@@ -392,6 +392,8 @@ hostapd_common_add_bss_config() {
 	config_add_string fils_dhcp
 
 	config_add_boolean ratelimit
+
+	config_add_string uci_section
 }
 
 hostapd_set_vlan_file() {
@@ -627,7 +629,7 @@ hostapd_set_bss_options() {
 		airtime_bss_weight airtime_bss_limit airtime_sta_weight \
 		multicast_to_unicast_all proxy_arp per_sta_vif \
 		eap_server eap_user_file ca_cert server_cert private_key private_key_passwd server_id \
-		vendor_elements fils
+		vendor_elements fils uci_section
 
 	set_default fils 0
 	set_default isolate 0
@@ -1152,6 +1154,8 @@ hostapd_set_bss_options() {
 		append bss_conf "per_sta_vif=$per_sta_vif" "$N"
 	fi
 
+	[ -n "$uci_section" ] && append bss_conf "uci_section=$uci_section" "$N"
+
 	json_get_values opts hostapd_bss_options
 	for val in $opts; do
 		append bss_conf "$val" "$N"
diff --git a/package/network/services/hostapd/patches/901-cfg-section.patch b/package/network/services/hostapd/patches/901-cfg-section.patch
new file mode 100644
index 0000000000..dcfdd658fe
--- /dev/null
+++ b/package/network/services/hostapd/patches/901-cfg-section.patch
@@ -0,0 +1,51 @@
+Index: hostapd-2021-02-20-59e9794c/hostapd/config_file.c
+===================================================================
+--- hostapd-2021-02-20-59e9794c.orig/hostapd/config_file.c
++++ hostapd-2021-02-20-59e9794c/hostapd/config_file.c
+@@ -2366,6 +2366,8 @@ static int hostapd_config_fill(struct ho
+ 			return 1;
+ 		}
+ 		conf->driver = driver;
++	} else if (os_strcmp(buf, "uci_section") == 0) {
++		bss->uci_section = os_strdup(pos);
+ 	} else if (os_strcmp(buf, "driver_params") == 0) {
+ 		os_free(conf->driver_params);
+ 		conf->driver_params = os_strdup(pos);
+Index: hostapd-2021-02-20-59e9794c/src/ap/ap_config.h
+===================================================================
+--- hostapd-2021-02-20-59e9794c.orig/src/ap/ap_config.h
++++ hostapd-2021-02-20-59e9794c/src/ap/ap_config.h
+@@ -279,6 +279,7 @@ struct hostapd_bss_config {
+ 	char snoop_iface[IFNAMSIZ + 1];
+ 	char vlan_bridge[IFNAMSIZ + 1];
+ 	char wds_bridge[IFNAMSIZ + 1];
++	char *uci_section;
+ 
+ 	char *config_id;
+ 
+Index: hostapd-2021-02-20-59e9794c/src/ap/ubus.c
+===================================================================
+--- hostapd-2021-02-20-59e9794c.orig/src/ap/ubus.c
++++ hostapd-2021-02-20-59e9794c/src/ap/ubus.c
+@@ -467,6 +467,9 @@ hostapd_bss_get_status(struct ubus_conte
+ 			hapd->iface->cac_started ? hapd->iface->dfs_cac_ms / 1000 - now.sec : 0);
+ 	blobmsg_close_table(&b, dfs_table);
+ 
++	if (hapd->conf->uci_section)
++		blobmsg_add_string(&b, "uci_section", hapd->conf->uci_section);
++
+ 	ubus_send_reply(ctx, req, b.head);
+ 
+ 	return 0;
+Index: hostapd-2021-02-20-59e9794c/src/ap/ap_config.c
+===================================================================
+--- hostapd-2021-02-20-59e9794c.orig/src/ap/ap_config.c
++++ hostapd-2021-02-20-59e9794c/src/ap/ap_config.c
+@@ -785,6 +785,7 @@ void hostapd_config_free_bss(struct host
+ 	os_free(conf->radius_req_attr_sqlite);
+ 	os_free(conf->rsn_preauth_interfaces);
+ 	os_free(conf->ctrl_interface);
++	os_free(conf->uci_section);
+ 	os_free(conf->config_id);
+ 	os_free(conf->ca_cert);
+ 	os_free(conf->server_cert);
-- 
2.25.1

