developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 1 | From 73016210704fbe266c98d470f1ffaabfc4d97bc1 Mon Sep 17 00:00:00 2001 |
| 2 | From: Evelyn Tsai <evelyn.tsai@mediatek.com> |
| 3 | Date: Sat, 2 Dec 2023 07:06:57 +0800 |
| 4 | Subject: [PATCH] Revert "hostapd: use new udebug ubus api to make debug rings |
| 5 | configurable" |
| 6 | |
| 7 | This 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 | |
| 15 | diff --git a/package/libs/udebug/files/udebug.config b/package/libs/udebug/files/udebug.config |
| 16 | index 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 |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 20 | |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 21 | 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 |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 27 | |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 28 | 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 |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 34 | |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 35 | config service netifd |
| 36 | option enabled 0 |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 37 | diff --git a/package/network/services/hostapd/files/hostapd.uc b/package/network/services/hostapd/files/hostapd.uc |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 38 | index b85f523b..84138f29 100644 |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 39 | --- a/package/network/services/hostapd/files/hostapd.uc |
| 40 | +++ b/package/network/services/hostapd/files/hostapd.uc |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 41 | @@ -782,9 +782,33 @@ let main_obj = { |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 42 | }, |
| 43 | }; |
| 44 | |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 45 | +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 | + |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 61 | hostapd.data.ubus = ubus; |
| 62 | hostapd.data.obj = ubus.publish("hostapd", main_obj); |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 63 | -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", {})); |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 73 | |
| 74 | function bss_event(type, name, data) { |
| 75 | let ubus = hostapd.data.ubus; |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 76 | @@ -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) { |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 84 | diff --git a/package/network/services/hostapd/files/wpa_supplicant.uc b/package/network/services/hostapd/files/wpa_supplicant.uc |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 85 | index 1709bb01..aac144b3 100644 |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 86 | --- a/package/network/services/hostapd/files/wpa_supplicant.uc |
| 87 | +++ b/package/network/services/hostapd/files/wpa_supplicant.uc |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 88 | @@ -244,9 +244,32 @@ let main_obj = { |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 89 | }, |
| 90 | }; |
| 91 | |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 92 | +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 | + |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 107 | wpas.data.ubus = ubus; |
| 108 | wpas.data.obj = ubus.publish("wpa_supplicant", main_obj); |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 109 | -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", {})); |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 119 | |
| 120 | function iface_event(type, name, data) { |
| 121 | let ubus = wpas.data.ubus; |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 122 | diff --git a/package/network/services/hostapd/src/src/utils/ucode.c b/package/network/services/hostapd/src/src/utils/ucode.c |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 123 | index 29c753c3..14fd6bc5 100644 |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 124 | --- a/package/network/services/hostapd/src/src/utils/ucode.c |
| 125 | +++ b/package/network/services/hostapd/src/src/utils/ucode.c |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 126 | @@ -16,59 +16,8 @@ static uc_vm_t vm; |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 127 | static struct uloop_timeout gc_timer; |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 128 | 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; |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 184 | |
| 185 | static void uc_gc_timer(struct uloop_timeout *timeout) |
| 186 | { |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 187 | @@ -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; |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 190 | |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 191 | - if (!udebug_buf_valid(buf)) |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 192 | - return; |
| 193 | - |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 194 | 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) |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 203 | -{ |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 204 | - udebug_ubus_apply_config(&ud, udebug_rings, ARRAY_SIZE(udebug_rings), |
| 205 | - data, enabled); |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 206 | - |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 207 | - if (udebug_buf_valid(&ud_log)) { |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 208 | - wpa_printf_hook = udebug_printf_hook; |
| 209 | - wpa_hexdump_hook = udebug_hexdump_hook; |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 210 | - } else { |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 211 | - wpa_printf_hook = NULL; |
| 212 | - wpa_hexdump_hook = NULL; |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 213 | - } |
| 214 | - |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 215 | - 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; |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 221 | -} |
| 222 | - |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 223 | uc_value_t *uc_wpa_udebug_set(uc_vm_t *vm, size_t nargs) |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 224 | { |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 225 | - 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 | } |
developer | 3f10c67 | 2023-11-21 14:30:53 +0800 | [diff] [blame] | 299 | |
developer | a319603 | 2023-12-01 18:35:12 +0800 | [diff] [blame] | 300 | return ucv_boolean_new(true); |
| 301 | -- |
| 302 | 2.18.0 |
| 303 | |