blob: d866ef7ef9a6fbbdd172376d9380dbada1d47bbd [file] [log] [blame]
From 73016210704fbe266c98d470f1ffaabfc4d97bc1 Mon Sep 17 00:00:00 2001
From: Evelyn Tsai <evelyn.tsai@mediatek.com>
Date: Sat, 2 Dec 2023 07:06:57 +0800
Subject: [PATCH] Revert "hostapd: use new udebug ubus api to make debug rings
configurable"
This reverts commit f909059b7473992e84d5701fa5021faa5bd76e67.
---
package/libs/udebug/files/udebug.config | 8 -
.../network/services/hostapd/files/hostapd.uc | 27 +++-
.../services/hostapd/files/wpa_supplicant.uc | 25 ++-
.../services/hostapd/src/src/utils/ucode.c | 144 ++++++------------
4 files changed, 96 insertions(+), 108 deletions(-)
diff --git a/package/libs/udebug/files/udebug.config b/package/libs/udebug/files/udebug.config
index 21d1ecb1..23d4281b 100644
--- a/package/libs/udebug/files/udebug.config
+++ b/package/libs/udebug/files/udebug.config
@@ -9,17 +9,9 @@ config service log
config service hostapd
option enabled 0
- option wpa_log 1
- option wpa_nl_rx 0
- option wpa_nl_tx 0
- option wpa_nl_ctrl 0
config service wpa_supplicant
option enabled 0
- option wpa_log 1
- option wpa_nl_rx 0
- option wpa_nl_tx 0
- option wpa_nl_ctrl 0
config service netifd
option enabled 0
diff --git a/package/network/services/hostapd/files/hostapd.uc b/package/network/services/hostapd/files/hostapd.uc
index b85f523b..84138f29 100644
--- a/package/network/services/hostapd/files/hostapd.uc
+++ b/package/network/services/hostapd/files/hostapd.uc
@@ -782,9 +782,33 @@ let main_obj = {
},
};
+function handle_debug_config(cfg) {
+ hostapd.printf(`handle_debug_config: ${cfg}\n`);
+ if (!cfg)
+ return;
+
+ let data = cfg.service;
+ if (!data)
+ return;
+
+ data = data.hostapd;
+ if (!data)
+ return;
+
+ hostapd.udebug_set(!!+data.enabled);
+}
+
hostapd.data.ubus = ubus;
hostapd.data.obj = ubus.publish("hostapd", main_obj);
-hostapd.udebug_set("hostapd", hostapd.data.ubus);
+hostapd.data.debug_sub = ubus.subscriber((req) => {
+ if (req.type != "config")
+ return;
+
+ handle_debug_config(req.data);
+});
+
+hostapd.data.debug_sub.subscribe("udebug");
+handle_debug_config(ubus.call("udebug", "get_config", {}));
function bss_event(type, name, data) {
let ubus = hostapd.data.ubus;
@@ -799,7 +823,6 @@ return {
shutdown: function() {
for (let phy in hostapd.data.config)
iface_set_config(phy, null);
- hostapd.udebug_set(null);
hostapd.ubus.disconnect();
},
bss_add: function(name, obj) {
diff --git a/package/network/services/hostapd/files/wpa_supplicant.uc b/package/network/services/hostapd/files/wpa_supplicant.uc
index 1709bb01..aac144b3 100644
--- a/package/network/services/hostapd/files/wpa_supplicant.uc
+++ b/package/network/services/hostapd/files/wpa_supplicant.uc
@@ -244,9 +244,32 @@ let main_obj = {
},
};
+function handle_debug_config(cfg) {
+ if (!cfg)
+ return;
+
+ let data = cfg.service;
+ if (!data)
+ return;
+
+ data = data.wpa_supplicant;
+ if (!data)
+ return;
+
+ wpas.udebug_set(!!+data.enabled);
+}
+
wpas.data.ubus = ubus;
wpas.data.obj = ubus.publish("wpa_supplicant", main_obj);
-wpas.udebug_set("wpa_supplicant", wpas.data.ubus);
+wpas.data.debug_sub = ubus.subscriber((req) => {
+ if (req.type != "config")
+ return;
+
+ handle_debug_config(req.data);
+});
+
+wpas.data.debug_sub.subscribe("udebug");
+handle_debug_config(ubus.call("udebug", "get_config", {}));
function iface_event(type, name, data) {
let ubus = wpas.data.ubus;
diff --git a/package/network/services/hostapd/src/src/utils/ucode.c b/package/network/services/hostapd/src/src/utils/ucode.c
index 29c753c3..14fd6bc5 100644
--- a/package/network/services/hostapd/src/src/utils/ucode.c
+++ b/package/network/services/hostapd/src/src/utils/ucode.c
@@ -16,59 +16,8 @@ static uc_vm_t vm;
static struct uloop_timeout gc_timer;
static struct udebug ud;
static struct udebug_buf ud_log, ud_nl[3];
-static const struct udebug_buf_meta meta_log = {
- .name = "wpa_log",
- .format = UDEBUG_FORMAT_STRING,
-};
-static const struct udebug_buf_meta meta_nl_ll = {
- .name = "wpa_nl_ctrl",
- .format = UDEBUG_FORMAT_PACKET,
- .sub_format = UDEBUG_DLT_NETLINK,
-};
-static const struct udebug_buf_meta meta_nl_tx = {
- .name = "wpa_nl_tx",
- .format = UDEBUG_FORMAT_PACKET,
- .sub_format = UDEBUG_DLT_NETLINK,
-};
+
#define UDEBUG_FLAG_RX_FRAME (1ULL << 0)
-static const struct udebug_buf_flag rx_flags[] = {
- { "rx_frame", UDEBUG_FLAG_RX_FRAME },
-};
-static const struct udebug_buf_meta meta_nl_rx = {
- .name = "wpa_nl_rx",
- .format = UDEBUG_FORMAT_PACKET,
- .sub_format = UDEBUG_DLT_NETLINK,
- .flags = rx_flags,
- .n_flags = ARRAY_SIZE(rx_flags),
-};
-static struct udebug_ubus_ring udebug_rings[] = {
- {
- .buf = &ud_log,
- .meta = &meta_log,
- .default_entries = 1024,
- .default_size = 64 * 1024
- },
- {
- .buf = &ud_nl[0],
- .meta = &meta_nl_rx,
- .default_entries = 1024,
- .default_size = 256 * 1024,
- },
- {
- .buf = &ud_nl[1],
- .meta = &meta_nl_tx,
- .default_entries = 1024,
- .default_size = 64 * 1024,
- },
- {
- .buf = &ud_nl[2],
- .meta = &meta_nl_ll,
- .default_entries = 1024,
- .default_size = 32 * 1024,
- }
-};
-char *udebug_service;
-struct udebug_ubus ud_ubus;
static void uc_gc_timer(struct uloop_timeout *timeout)
{
@@ -352,67 +301,68 @@ static void udebug_netlink_hook(int tx, const void *data, size_t len)
!(udebug_buf_flags(buf) & UDEBUG_FLAG_RX_FRAME))
return;
- if (!udebug_buf_valid(buf))
- return;
-
udebug_entry_init(buf);
udebug_entry_append(buf, &hdr, sizeof(hdr));
udebug_entry_append(buf, data, len);
udebug_entry_add(buf);
}
-static void
-wpa_udebug_config(struct udebug_ubus *ctx, struct blob_attr *data,
- bool enabled)
-{
- udebug_ubus_apply_config(&ud, udebug_rings, ARRAY_SIZE(udebug_rings),
- data, enabled);
-
- if (udebug_buf_valid(&ud_log)) {
- wpa_printf_hook = udebug_printf_hook;
- wpa_hexdump_hook = udebug_hexdump_hook;
- } else {
- wpa_printf_hook = NULL;
- wpa_hexdump_hook = NULL;
- }
-
- if (udebug_buf_valid(&ud_nl[0]) ||
- udebug_buf_valid(&ud_nl[1]) ||
- udebug_buf_valid(&ud_nl[2]))
- wpa_netlink_hook = udebug_netlink_hook;
- else
- wpa_netlink_hook = NULL;
-}
-
uc_value_t *uc_wpa_udebug_set(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *name = uc_fn_arg(0);
- uc_value_t *ubus = uc_fn_arg(1);
+ static const struct udebug_buf_meta meta_log = {
+ .name = "wpa_log",
+ .format = UDEBUG_FORMAT_STRING,
+ };
+ static const struct udebug_buf_meta meta_nl_ll = {
+ .name = "wpa_nl_ctrl",
+ .format = UDEBUG_FORMAT_PACKET,
+ .sub_format = UDEBUG_DLT_NETLINK,
+ };
+ static const struct udebug_buf_meta meta_nl_tx = {
+ .name = "wpa_nl_tx",
+ .format = UDEBUG_FORMAT_PACKET,
+ .sub_format = UDEBUG_DLT_NETLINK,
+ };
+ static const struct udebug_buf_flag rx_flags[] = {
+ { "rx_frame", UDEBUG_FLAG_RX_FRAME },
+ };
+ static const struct udebug_buf_meta meta_nl_rx = {
+ .name = "wpa_nl_rx",
+ .format = UDEBUG_FORMAT_PACKET,
+ .sub_format = UDEBUG_DLT_NETLINK,
+ .flags = rx_flags,
+ .n_flags = ARRAY_SIZE(rx_flags),
+ };
+ bool val = ucv_is_truish(uc_fn_arg(0));
static bool enabled = false;
- struct ubus_context *ctx;
- bool cur_en;
-
- cur_en = ucv_type(name) == UC_STRING;
- ctx = ucv_resource_data(ubus, "ubus.connection");
- if (!ctx)
- cur_en = false;
- if (enabled == cur_en)
+ if (enabled == val)
return ucv_boolean_new(true);
- enabled = cur_en;
- if (enabled) {
- udebug_service = strdup(ucv_string_get(name));
+ enabled = val;
+ if (val) {
udebug_init(&ud);
udebug_auto_connect(&ud, NULL);
- udebug_ubus_init(&ud_ubus, ctx, udebug_service, wpa_udebug_config);
+ udebug_buf_init(&ud_log, 1024, 64 * 1024);
+ udebug_buf_add(&ud, &ud_log, &meta_log);
+ udebug_buf_init(&ud_nl[0], 1024, 256 * 1024);
+ udebug_buf_add(&ud, &ud_nl[0], &meta_nl_rx);
+ udebug_buf_init(&ud_nl[1], 1024, 64 * 1024);
+ udebug_buf_add(&ud, &ud_nl[1], &meta_nl_tx);
+ udebug_buf_init(&ud_nl[2], 256, 32 * 1024);
+ udebug_buf_add(&ud, &ud_nl[2], &meta_nl_ll);
+
+ wpa_printf_hook = udebug_printf_hook;
+ wpa_hexdump_hook = udebug_hexdump_hook;
+ wpa_netlink_hook = udebug_netlink_hook;
} else {
- udebug_ubus_free(&ud_ubus);
- for (size_t i = 0; i < ARRAY_SIZE(udebug_rings); i++)
- if (udebug_buf_valid(udebug_rings[i].buf))
- udebug_buf_free(udebug_rings[i].buf);
+ for (size_t i = 0; i < ARRAY_SIZE(ud_nl); i++)
+ udebug_buf_free(&ud_nl[i]);
+ udebug_buf_free(&ud_log);
udebug_free(&ud);
- free(udebug_service);
+ wpa_printf_hook = NULL;
+ wpa_hexdump_hook = NULL;
+ wpa_netlink_hook = NULL;
}
return ucv_boolean_new(true);
--
2.18.0