From: David Bauer Date: Sun, 1 Nov 2020 23:53:41 +0000 (+0100) Subject: hostapd: ubus: add get_status method X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=0ce5f15f9c51926bc56aa8f9d8d848f803f9f251;p=openwrt%2Fstaging%2Fthess.git hostapd: ubus: add get_status method This adds a new get_status method to a hostapd interface, which provides information about the current interface status. Signed-off-by: David Bauer --- diff --git a/package/network/services/hostapd/src/src/ap/ubus.c b/package/network/services/hostapd/src/src/ap/ubus.c index f864d586ab..aae9f91a20 100644 --- a/package/network/services/hostapd/src/src/ap/ubus.c +++ b/package/network/services/hostapd/src/src/ap/ubus.c @@ -372,6 +372,45 @@ hostapd_bss_get_features(struct ubus_context *ctx, struct ubus_object *obj, return 0; } +static int +hostapd_bss_get_status(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + void *airtime_table, *dfs_table; + struct os_reltime now; + char phy_name[17]; + char mac_buf[20]; + + blob_buf_init(&b, 0); + blobmsg_add_string(&b, "status", hostapd_state_text(hapd->iface->state)); + blobmsg_add_u32(&b, "freq", hapd->iface->freq); + + snprintf(phy_name, 17, "%s", hapd->iface->phy); + blobmsg_add_string(&b, "phy", phy_name); + + /* Airtime */ + airtime_table = blobmsg_open_table(&b, "airtime"); + blobmsg_add_u64(&b, "time", hapd->iface->last_channel_time); + blobmsg_add_u64(&b, "time_busy", hapd->iface->last_channel_time_busy); + blobmsg_add_u16(&b, "utilization", hapd->iface->channel_utilization); + blobmsg_close_table(&b, airtime_table); + + /* DFS */ + dfs_table = blobmsg_open_table(&b, "dfs"); + blobmsg_add_u32(&b, "cac_seconds", hapd->iface->dfs_cac_ms / 1000); + blobmsg_add_u8(&b, "cac_active", !!(hapd->iface->cac_started)); + os_reltime_age(&hapd->iface->dfs_cac_start, &now); + blobmsg_add_u32(&b, "cac_seconds_left", + hapd->iface->cac_started ? hapd->iface->dfs_cac_ms / 1000 - now.sec : 0); + blobmsg_close_table(&b, dfs_table); + + ubus_send_reply(ctx, req, b.head); + + return 0; +} + enum { NOTIFY_RESPONSE, __NOTIFY_MAX @@ -1242,6 +1281,7 @@ hostapd_wnm_disassoc_imminent(struct ubus_context *ctx, struct ubus_object *obj, static const struct ubus_method bss_methods[] = { UBUS_METHOD_NOARG("reload", hostapd_bss_reload), UBUS_METHOD_NOARG("get_clients", hostapd_bss_get_clients), + UBUS_METHOD_NOARG("get_status", hostapd_bss_get_status), UBUS_METHOD("del_client", hostapd_bss_del_client, del_policy), UBUS_METHOD_NOARG("list_bans", hostapd_bss_list_bans), #ifdef CONFIG_WPS