Skip to content

Commit

Permalink
add led triggers to connect logic
Browse files Browse the repository at this point in the history
Signed-off-by: John Crispin <john@phrozen.org>
  • Loading branch information
blogic committed Sep 7, 2023
1 parent 8bf3ea4 commit b642d98
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
3 changes: 3 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down
30 changes: 24 additions & 6 deletions ubus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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 };
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions ucentral.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b642d98

Please sign in to comment.