blob: d866ef7ef9a6fbbdd172376d9380dbada1d47bbd [file] [log] [blame]
developera3196032023-12-01 18:35:12 +08001From 73016210704fbe266c98d470f1ffaabfc4d97bc1 Mon Sep 17 00:00:00 2001
2From: Evelyn Tsai <evelyn.tsai@mediatek.com>
3Date: Sat, 2 Dec 2023 07:06:57 +0800
4Subject: [PATCH] Revert "hostapd: use new udebug ubus api to make debug rings
5 configurable"
6
7This reverts commit f909059b7473992e84d5701fa5021faa5bd76e67.
8---
9 package/libs/udebug/files/udebug.config | 8 -
10 .../network/services/hostapd/files/hostapd.uc | 27 +++-
11 .../services/hostapd/files/wpa_supplicant.uc | 25 ++-
12 .../services/hostapd/src/src/utils/ucode.c | 144 ++++++------------
13 4 files changed, 96 insertions(+), 108 deletions(-)
14
15diff --git a/package/libs/udebug/files/udebug.config b/package/libs/udebug/files/udebug.config
16index 21d1ecb1..23d4281b 100644
17--- a/package/libs/udebug/files/udebug.config
18+++ b/package/libs/udebug/files/udebug.config
19@@ -9,17 +9,9 @@ config service log
developer3f10c672023-11-21 14:30:53 +080020
developera3196032023-12-01 18:35:12 +080021 config service hostapd
22 option enabled 0
23- option wpa_log 1
24- option wpa_nl_rx 0
25- option wpa_nl_tx 0
26- option wpa_nl_ctrl 0
developer3f10c672023-11-21 14:30:53 +080027
developera3196032023-12-01 18:35:12 +080028 config service wpa_supplicant
29 option enabled 0
30- option wpa_log 1
31- option wpa_nl_rx 0
32- option wpa_nl_tx 0
33- option wpa_nl_ctrl 0
developer3f10c672023-11-21 14:30:53 +080034
developera3196032023-12-01 18:35:12 +080035 config service netifd
36 option enabled 0
developer3f10c672023-11-21 14:30:53 +080037diff --git a/package/network/services/hostapd/files/hostapd.uc b/package/network/services/hostapd/files/hostapd.uc
developera3196032023-12-01 18:35:12 +080038index b85f523b..84138f29 100644
developer3f10c672023-11-21 14:30:53 +080039--- a/package/network/services/hostapd/files/hostapd.uc
40+++ b/package/network/services/hostapd/files/hostapd.uc
developera3196032023-12-01 18:35:12 +080041@@ -782,9 +782,33 @@ let main_obj = {
developer3f10c672023-11-21 14:30:53 +080042 },
43 };
44
developera3196032023-12-01 18:35:12 +080045+function handle_debug_config(cfg) {
46+ hostapd.printf(`handle_debug_config: ${cfg}\n`);
47+ if (!cfg)
48+ return;
49+
50+ let data = cfg.service;
51+ if (!data)
52+ return;
53+
54+ data = data.hostapd;
55+ if (!data)
56+ return;
57+
58+ hostapd.udebug_set(!!+data.enabled);
59+}
60+
developer3f10c672023-11-21 14:30:53 +080061 hostapd.data.ubus = ubus;
62 hostapd.data.obj = ubus.publish("hostapd", main_obj);
developera3196032023-12-01 18:35:12 +080063-hostapd.udebug_set("hostapd", hostapd.data.ubus);
64+hostapd.data.debug_sub = ubus.subscriber((req) => {
65+ if (req.type != "config")
66+ return;
67+
68+ handle_debug_config(req.data);
69+});
70+
71+hostapd.data.debug_sub.subscribe("udebug");
72+handle_debug_config(ubus.call("udebug", "get_config", {}));
developer3f10c672023-11-21 14:30:53 +080073
74 function bss_event(type, name, data) {
75 let ubus = hostapd.data.ubus;
developera3196032023-12-01 18:35:12 +080076@@ -799,7 +823,6 @@ return {
77 shutdown: function() {
78 for (let phy in hostapd.data.config)
79 iface_set_config(phy, null);
80- hostapd.udebug_set(null);
81 hostapd.ubus.disconnect();
82 },
83 bss_add: function(name, obj) {
developer3f10c672023-11-21 14:30:53 +080084diff --git a/package/network/services/hostapd/files/wpa_supplicant.uc b/package/network/services/hostapd/files/wpa_supplicant.uc
developera3196032023-12-01 18:35:12 +080085index 1709bb01..aac144b3 100644
developer3f10c672023-11-21 14:30:53 +080086--- a/package/network/services/hostapd/files/wpa_supplicant.uc
87+++ b/package/network/services/hostapd/files/wpa_supplicant.uc
developera3196032023-12-01 18:35:12 +080088@@ -244,9 +244,32 @@ let main_obj = {
developer3f10c672023-11-21 14:30:53 +080089 },
90 };
91
developera3196032023-12-01 18:35:12 +080092+function handle_debug_config(cfg) {
93+ if (!cfg)
94+ return;
95+
96+ let data = cfg.service;
97+ if (!data)
98+ return;
99+
100+ data = data.wpa_supplicant;
101+ if (!data)
102+ return;
103+
104+ wpas.udebug_set(!!+data.enabled);
105+}
106+
developer3f10c672023-11-21 14:30:53 +0800107 wpas.data.ubus = ubus;
108 wpas.data.obj = ubus.publish("wpa_supplicant", main_obj);
developera3196032023-12-01 18:35:12 +0800109-wpas.udebug_set("wpa_supplicant", wpas.data.ubus);
110+wpas.data.debug_sub = ubus.subscriber((req) => {
111+ if (req.type != "config")
112+ return;
113+
114+ handle_debug_config(req.data);
115+});
116+
117+wpas.data.debug_sub.subscribe("udebug");
118+handle_debug_config(ubus.call("udebug", "get_config", {}));
developer3f10c672023-11-21 14:30:53 +0800119
120 function iface_event(type, name, data) {
121 let ubus = wpas.data.ubus;
developer3f10c672023-11-21 14:30:53 +0800122diff --git a/package/network/services/hostapd/src/src/utils/ucode.c b/package/network/services/hostapd/src/src/utils/ucode.c
developera3196032023-12-01 18:35:12 +0800123index 29c753c3..14fd6bc5 100644
developer3f10c672023-11-21 14:30:53 +0800124--- a/package/network/services/hostapd/src/src/utils/ucode.c
125+++ b/package/network/services/hostapd/src/src/utils/ucode.c
developera3196032023-12-01 18:35:12 +0800126@@ -16,59 +16,8 @@ static uc_vm_t vm;
developer3f10c672023-11-21 14:30:53 +0800127 static struct uloop_timeout gc_timer;
developera3196032023-12-01 18:35:12 +0800128 static struct udebug ud;
129 static struct udebug_buf ud_log, ud_nl[3];
130-static const struct udebug_buf_meta meta_log = {
131- .name = "wpa_log",
132- .format = UDEBUG_FORMAT_STRING,
133-};
134-static const struct udebug_buf_meta meta_nl_ll = {
135- .name = "wpa_nl_ctrl",
136- .format = UDEBUG_FORMAT_PACKET,
137- .sub_format = UDEBUG_DLT_NETLINK,
138-};
139-static const struct udebug_buf_meta meta_nl_tx = {
140- .name = "wpa_nl_tx",
141- .format = UDEBUG_FORMAT_PACKET,
142- .sub_format = UDEBUG_DLT_NETLINK,
143-};
144+
145 #define UDEBUG_FLAG_RX_FRAME (1ULL << 0)
146-static const struct udebug_buf_flag rx_flags[] = {
147- { "rx_frame", UDEBUG_FLAG_RX_FRAME },
148-};
149-static const struct udebug_buf_meta meta_nl_rx = {
150- .name = "wpa_nl_rx",
151- .format = UDEBUG_FORMAT_PACKET,
152- .sub_format = UDEBUG_DLT_NETLINK,
153- .flags = rx_flags,
154- .n_flags = ARRAY_SIZE(rx_flags),
155-};
156-static struct udebug_ubus_ring udebug_rings[] = {
157- {
158- .buf = &ud_log,
159- .meta = &meta_log,
160- .default_entries = 1024,
161- .default_size = 64 * 1024
162- },
163- {
164- .buf = &ud_nl[0],
165- .meta = &meta_nl_rx,
166- .default_entries = 1024,
167- .default_size = 256 * 1024,
168- },
169- {
170- .buf = &ud_nl[1],
171- .meta = &meta_nl_tx,
172- .default_entries = 1024,
173- .default_size = 64 * 1024,
174- },
175- {
176- .buf = &ud_nl[2],
177- .meta = &meta_nl_ll,
178- .default_entries = 1024,
179- .default_size = 32 * 1024,
180- }
181-};
182-char *udebug_service;
183-struct udebug_ubus ud_ubus;
developer3f10c672023-11-21 14:30:53 +0800184
185 static void uc_gc_timer(struct uloop_timeout *timeout)
186 {
developera3196032023-12-01 18:35:12 +0800187@@ -352,67 +301,68 @@ static void udebug_netlink_hook(int tx, const void *data, size_t len)
188 !(udebug_buf_flags(buf) & UDEBUG_FLAG_RX_FRAME))
189 return;
developer3f10c672023-11-21 14:30:53 +0800190
developera3196032023-12-01 18:35:12 +0800191- if (!udebug_buf_valid(buf))
developer3f10c672023-11-21 14:30:53 +0800192- return;
193-
developera3196032023-12-01 18:35:12 +0800194 udebug_entry_init(buf);
195 udebug_entry_append(buf, &hdr, sizeof(hdr));
196 udebug_entry_append(buf, data, len);
197 udebug_entry_add(buf);
198 }
199
200-static void
201-wpa_udebug_config(struct udebug_ubus *ctx, struct blob_attr *data,
202- bool enabled)
developer3f10c672023-11-21 14:30:53 +0800203-{
developera3196032023-12-01 18:35:12 +0800204- udebug_ubus_apply_config(&ud, udebug_rings, ARRAY_SIZE(udebug_rings),
205- data, enabled);
developer3f10c672023-11-21 14:30:53 +0800206-
developera3196032023-12-01 18:35:12 +0800207- if (udebug_buf_valid(&ud_log)) {
developer3f10c672023-11-21 14:30:53 +0800208- wpa_printf_hook = udebug_printf_hook;
209- wpa_hexdump_hook = udebug_hexdump_hook;
developer3f10c672023-11-21 14:30:53 +0800210- } else {
developer3f10c672023-11-21 14:30:53 +0800211- wpa_printf_hook = NULL;
212- wpa_hexdump_hook = NULL;
developer3f10c672023-11-21 14:30:53 +0800213- }
214-
developera3196032023-12-01 18:35:12 +0800215- if (udebug_buf_valid(&ud_nl[0]) ||
216- udebug_buf_valid(&ud_nl[1]) ||
217- udebug_buf_valid(&ud_nl[2]))
218- wpa_netlink_hook = udebug_netlink_hook;
219- else
220- wpa_netlink_hook = NULL;
developer3f10c672023-11-21 14:30:53 +0800221-}
222-
developera3196032023-12-01 18:35:12 +0800223 uc_value_t *uc_wpa_udebug_set(uc_vm_t *vm, size_t nargs)
developer3f10c672023-11-21 14:30:53 +0800224 {
developera3196032023-12-01 18:35:12 +0800225- uc_value_t *name = uc_fn_arg(0);
226- uc_value_t *ubus = uc_fn_arg(1);
227+ static const struct udebug_buf_meta meta_log = {
228+ .name = "wpa_log",
229+ .format = UDEBUG_FORMAT_STRING,
230+ };
231+ static const struct udebug_buf_meta meta_nl_ll = {
232+ .name = "wpa_nl_ctrl",
233+ .format = UDEBUG_FORMAT_PACKET,
234+ .sub_format = UDEBUG_DLT_NETLINK,
235+ };
236+ static const struct udebug_buf_meta meta_nl_tx = {
237+ .name = "wpa_nl_tx",
238+ .format = UDEBUG_FORMAT_PACKET,
239+ .sub_format = UDEBUG_DLT_NETLINK,
240+ };
241+ static const struct udebug_buf_flag rx_flags[] = {
242+ { "rx_frame", UDEBUG_FLAG_RX_FRAME },
243+ };
244+ static const struct udebug_buf_meta meta_nl_rx = {
245+ .name = "wpa_nl_rx",
246+ .format = UDEBUG_FORMAT_PACKET,
247+ .sub_format = UDEBUG_DLT_NETLINK,
248+ .flags = rx_flags,
249+ .n_flags = ARRAY_SIZE(rx_flags),
250+ };
251+ bool val = ucv_is_truish(uc_fn_arg(0));
252 static bool enabled = false;
253- struct ubus_context *ctx;
254- bool cur_en;
255-
256- cur_en = ucv_type(name) == UC_STRING;
257- ctx = ucv_resource_data(ubus, "ubus.connection");
258- if (!ctx)
259- cur_en = false;
260
261- if (enabled == cur_en)
262+ if (enabled == val)
263 return ucv_boolean_new(true);
264
265- enabled = cur_en;
266- if (enabled) {
267- udebug_service = strdup(ucv_string_get(name));
268+ enabled = val;
269+ if (val) {
270 udebug_init(&ud);
271 udebug_auto_connect(&ud, NULL);
272- udebug_ubus_init(&ud_ubus, ctx, udebug_service, wpa_udebug_config);
273+ udebug_buf_init(&ud_log, 1024, 64 * 1024);
274+ udebug_buf_add(&ud, &ud_log, &meta_log);
275+ udebug_buf_init(&ud_nl[0], 1024, 256 * 1024);
276+ udebug_buf_add(&ud, &ud_nl[0], &meta_nl_rx);
277+ udebug_buf_init(&ud_nl[1], 1024, 64 * 1024);
278+ udebug_buf_add(&ud, &ud_nl[1], &meta_nl_tx);
279+ udebug_buf_init(&ud_nl[2], 256, 32 * 1024);
280+ udebug_buf_add(&ud, &ud_nl[2], &meta_nl_ll);
281+
282+ wpa_printf_hook = udebug_printf_hook;
283+ wpa_hexdump_hook = udebug_hexdump_hook;
284+ wpa_netlink_hook = udebug_netlink_hook;
285 } else {
286- udebug_ubus_free(&ud_ubus);
287- for (size_t i = 0; i < ARRAY_SIZE(udebug_rings); i++)
288- if (udebug_buf_valid(udebug_rings[i].buf))
289- udebug_buf_free(udebug_rings[i].buf);
290+ for (size_t i = 0; i < ARRAY_SIZE(ud_nl); i++)
291+ udebug_buf_free(&ud_nl[i]);
292+ udebug_buf_free(&ud_log);
293 udebug_free(&ud);
294- free(udebug_service);
295+ wpa_printf_hook = NULL;
296+ wpa_hexdump_hook = NULL;
297+ wpa_netlink_hook = NULL;
298 }
developer3f10c672023-11-21 14:30:53 +0800299
developera3196032023-12-01 18:35:12 +0800300 return ucv_boolean_new(true);
301--
3022.18.0
303