[PATCH v2 07/11] wifi_stats: hostapd control interface and hostapd_cli commands
Iegor Sergieienkov
iegor at nova-labs.com
Mon Nov 23 04:50:27 PST 2026
Add two control interface commands:
* WIFI_STATS_STATUS - the settings in use and whether statistics are
being collected
* WIFI_STATS_CONNECT_INFO <addr> - the Connect-Info string for a
station
WIFI_STATS_CONNECT_INFO uses the function that generates the RADIUS
attribute, which makes the format observable without a RADIUS server. It
does not count as a report, i.e., it does not start a new accumulation
period.
The wifi_stats_* configuration parameters are changed at runtime with
the existing SET command; apply such a change to the running interface
immediately instead of waiting for a reload.
Add the matching hostapd_cli commands wifi_stats_status and
wifi_stats_connect_info.
Signed-off-by: Iegor Sergieienkov <iegor at nova-labs.com>
---
hostapd/ctrl_iface.c | 49 +++++++++++++++++++++++++++++++++++++++++++
hostapd/hostapd_cli.c | 23 ++++++++++++++++++++
2 files changed, 72 insertions(+)
diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index 12a9bc934..04e0b4e65 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -67,6 +67,7 @@
#include "ap/dfs.h"
#include "ap/nan_usd_ap.h"
#include "ap/robust_av.h"
+#include "ap/wifi_stats.h"
#include "wps/wps_defs.h"
#include "wps/wps.h"
#include "fst/fst_ctrl_iface.h"
@@ -1461,6 +1462,10 @@ static int hostapd_ctrl_iface_set(struct hostapd_data *hapd, char *cmd)
} else if (os_strcasecmp(cmd, "transition_disable") == 0) {
wpa_auth_set_transition_disable(hapd->wpa_auth,
hapd->conf->transition_disable);
+#ifdef CONFIG_WIFI_STATS
+ } else if (os_strncmp(cmd, "wifi_stats_", 11) == 0) {
+ wifi_stats_reload_config(hapd->iface);
+#endif /* CONFIG_WIFI_STATS */
}
#ifdef CONFIG_TESTING_OPTIONS
@@ -1490,6 +1495,42 @@ static int hostapd_ctrl_iface_set(struct hostapd_data *hapd, char *cmd)
}
+#ifdef CONFIG_WIFI_STATS
+static int hostapd_ctrl_iface_wifi_stats_connect_info(struct hostapd_data *hapd,
+ char *cmd, char *buf,
+ size_t buflen)
+{
+ u8 addr[ETH_ALEN];
+ char conn_info[WIFI_STATS_MAX_CONNECT_INFO_LEN + 1];
+ struct sta_info *sta;
+ int written;
+
+ if (hwaddr_aton(cmd, addr)) {
+ wpa_printf(MSG_DEBUG, "wifi_stats: Invalid MAC address: %s",
+ cmd);
+ return -1;
+ }
+
+ sta = ap_get_sta(hapd, addr);
+ if (!sta) {
+ wpa_printf(MSG_DEBUG,
+ "wifi_stats: Station " MACSTR " not found for Connect-Info query",
+ MAC2STR(addr));
+ return -1;
+ }
+
+ if (wifi_stats_connect_info(hapd, sta, conn_info,
+ sizeof(conn_info)) < 0)
+ return -1;
+
+ written = os_snprintf(buf, buflen, "%s\n", conn_info);
+ if (os_snprintf_error(buflen, written))
+ return -1;
+ return written;
+}
+#endif /* CONFIG_WIFI_STATS */
+
+
static int hostapd_ctrl_iface_get(struct hostapd_data *hapd, char *cmd,
char *buf, size_t buflen)
{
@@ -4912,6 +4953,14 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
if (hostapd_ctrl_afc_send_request(hapd, buf + 16) < 0)
reply_len = -1;
#endif /* CONFIG_AFC */
+#ifdef CONFIG_WIFI_STATS
+ } else if (os_strcmp(buf, "WIFI_STATS_STATUS") == 0) {
+ reply_len = wifi_stats_get_status(hapd->iface, reply,
+ reply_size);
+ } else if (os_strncmp(buf, "WIFI_STATS_CONNECT_INFO ", 24) == 0) {
+ reply_len = hostapd_ctrl_iface_wifi_stats_connect_info(
+ hapd, buf + 24, reply, reply_size);
+#endif /* CONFIG_WIFI_STATS */
} else {
os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
reply_len = 16;
diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c
index cf35241fd..14541c181 100644
--- a/hostapd/hostapd_cli.c
+++ b/hostapd/hostapd_cli.c
@@ -1765,6 +1765,22 @@ static int hostapd_cli_cmd_driver(struct wpa_ctrl *ctrl, int argc, char *argv[])
#endif /* ANDROID */
+#ifdef CONFIG_WIFI_STATS
+static int hostapd_cli_cmd_wifi_stats_status(struct wpa_ctrl *ctrl, int argc,
+ char *argv[])
+{
+ return wpa_ctrl_command(ctrl, "WIFI_STATS_STATUS");
+}
+
+
+static int hostapd_cli_cmd_wifi_stats_connect_info(struct wpa_ctrl *ctrl,
+ int argc, char *argv[])
+{
+ return hostapd_cli_cmd(ctrl, "WIFI_STATS_CONNECT_INFO", 1, argc, argv);
+}
+#endif /* CONFIG_WIFI_STATS */
+
+
#ifdef CONFIG_AFC
static int hostapd_cli_cmd_afc_get_request(struct wpa_ctrl *ctrl, int argc,
@@ -2046,6 +2062,13 @@ static const struct hostapd_cli_cmd hostapd_cli_commands[] = {
{ "afc_send_request", hostapd_cli_cmd_afc_send_request, NULL,
" = Send another AFC request and upadte the timeout"},
#endif /* CONFIG_AFC */
+#ifdef CONFIG_WIFI_STATS
+ { "wifi_stats_status", hostapd_cli_cmd_wifi_stats_status, NULL,
+ "= show wifi_stats configuration" },
+ { "wifi_stats_connect_info", hostapd_cli_cmd_wifi_stats_connect_info,
+ hostapd_complete_stations,
+ "<addr> = show Connect-Info string for a station" },
+#endif /* CONFIG_WIFI_STATS */
{ NULL, NULL, NULL, NULL }
};
--
2.43.0
More information about the Hostap
mailing list