From b642d989f4411ce79790d6ed13d270e917628300 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Thu, 7 Sep 2023 10:00:51 +0200 Subject: [PATCH] add led triggers to connect logic Signed-off-by: John Crispin --- main.c | 3 +++ ubus.c | 30 ++++++++++++++++++++++++------ ucentral.h | 1 + 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index fd74690..cb4476c 100644 --- a/main.c +++ b/main.c @@ -111,6 +111,8 @@ sul_connect_attempt(struct lws_sorted_usec_list *sul) { struct per_vhost_data__minimal *vhd; + ubus_set_client_status("connect"); + vhd = lws_container_of(sul, struct per_vhost_data__minimal, sul); vhd->i.context = vhd->context; @@ -215,6 +217,7 @@ callback_broker(struct lws *wsi, enum lws_callback_reasons reason, return 0; case LWS_CALLBACK_CLIENT_ESTABLISHED: + ubus_set_client_status("online"); ULOG_INFO("connection established\n"); if (!client.selfsigned) { if (!lws_tls_peer_cert_info(wsi, LWS_TLS_CERT_INFO_VALIDITY_TO, &ci, 0)) diff --git a/ubus.c b/ubus.c index 391e642..ba22d1e 100644 --- a/ubus.c +++ b/ubus.c @@ -7,6 +7,7 @@ static struct ubus_auto_conn conn; static struct blob_buf u; static uint32_t radius_proxy; +static uint32_t state; static int ubus_status_cb(struct ubus_context *ctx, struct ubus_object *obj, @@ -328,6 +329,21 @@ void ubus_forward_radius(struct blob_buf *msg) ubus_abort_request(&conn.ctx, &async); } +void ubus_set_client_status(char *status) +{ + struct ubus_request async = { }; + + if (!state) { + ULOG_ERR("state is not running\n"); + return; + } + blob_buf_init(&u, 0); + blobmsg_add_string(&u, "state", status); + + ubus_invoke_async(&conn.ctx, state, "set", u.head, &async); + ubus_abort_request(&conn.ctx, &async); +} + static const struct ubus_method ucentral_methods[] = { UBUS_METHOD("health", ubus_health_cb, health_policy), UBUS_METHOD("result", ubus_result_cb, result_policy), @@ -392,14 +408,16 @@ event_handler_cb(struct ubus_context *ctx, struct ubus_event_handler *ev, path = blobmsg_get_string(tb[EVENT_PATH]); id = blobmsg_get_u32(tb[EVENT_ID]); - if (strcmp(path, "radius.proxy")) - return; if (!strcmp("ubus.object.remove", type)) - radius_proxy = 0; - else + id = 0; + if (strcmp(path, "radius.proxy")) radius_proxy = id; + else if (strcmp(path, "state")) + state = id; + else + return; - ULOG_INFO("%s radius.proxy (%d)\n", radius_proxy ? "add" : "remove", radius_proxy); + ULOG_INFO("%s %s (%d)\n", id ? "add" : "remove", path, id); } static struct ubus_event_handler event_handler = { .cb = event_handler_cb }; @@ -411,7 +429,7 @@ static void ubus_connect_handler(struct ubus_context *ctx) ubus_register_event_handler(ctx, &event_handler, "ubus.object.remove"); ubus_lookup_id(ctx, "radius.proxy", &radius_proxy); - + ubus_lookup_id(ctx, "state", &state); } void ubus_init(void) diff --git a/ucentral.h b/ucentral.h index bf1d6ed..bd15915 100644 --- a/ucentral.h +++ b/ucentral.h @@ -95,6 +95,7 @@ void config_rejected(struct blob_attr *b); void ubus_init(void); void ubus_deinit(void); void ubus_forward_radius(struct blob_buf *msg); +void ubus_set_client_status(char *status); void blink_run(uint32_t duration, uint32_t id);