hostapd: ubus: add get_status method
authorDavid Bauer <mail@david-bauer.net>
Sun, 1 Nov 2020 23:53:41 +0000 (00:53 +0100)
committerDavid Bauer <mail@david-bauer.net>
Tue, 17 Nov 2020 16:05:06 +0000 (17:05 +0100)
This adds a new get_status method to a hostapd interface, which
provides information about the current interface status.

Signed-off-by: David Bauer <mail@david-bauer.net>
package/network/services/hostapd/src/src/ap/ubus.c

index f864d586abc8fc61b7f0ab4c354bc1e7f9854714..aae9f91a20d4456b8a149356f8590a203667452d 100644 (file)
@@ -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