[PATCH v2 04/11] wifi_stats: hostapd configuration parameters
Iegor Sergieienkov
iegor at nova-labs.com
Mon Nov 23 04:50:24 PST 2026
Add the configuration parameters of the wifi_stats module:
* wifi_stats_wba_enabled - collect station statistics and report them
in the WBA Connect-Info format, 0 or 1, default 0
* wifi_stats_interval - interval between driver polls in seconds,
1..3600, default 1
* wifi_stats_wba_window - aggregation window in seconds, 1..3600,
default 60
* wifi_stats_span - how the aggregation span is determined, window
(default) or report
* wifi_stats_ewma_weight - exponential weight used by AVG-EXP, 1..9,
default 5
* wifi_stats_metric_<metric>=<algorithm> - per-metric aggregation
algorithm
The metric names are rxbitrate, txbitrate, rssi, frameloss, and
frameretry. The algorithms are MIN, MAX, AVG-LIN, AVG-EXP, ACC, and
NONE; frameloss and frameretry accept only ACC or NONE and the other
metrics anything but ACC. The defaults are MAX for the two bit rates,
AVG-LIN for RSSI, and ACC for frameloss and frameretry.
The feature is disabled by default: without wifi_stats_wba_enabled=1
nothing is collected and the RADIUS Connect-Info attribute is not
changed.
Signed-off-by: Iegor Sergieienkov <iegor at nova-labs.com>
---
hostapd/config_file.c | 102 ++++++++++++++++++++++++++++++++++++++++++
hostapd/hostapd.conf | 82 +++++++++++++++++++++++++++++++++
src/ap/ap_config.c | 7 +++
src/ap/ap_config.h | 13 ++++++
4 files changed, 204 insertions(+)
diff --git a/hostapd/config_file.c b/hostapd/config_file.c
index 553551734..d47e20fb4 100644
--- a/hostapd/config_file.c
+++ b/hostapd/config_file.c
@@ -23,6 +23,7 @@
#include "radius/radius_client.h"
#include "ap/wpa_auth.h"
#include "ap/ap_config.h"
+#include "ap/wifi_stats.h"
#include "config_file.h"
@@ -2519,6 +2520,107 @@ static int hostapd_config_fill(struct hostapd_config *conf,
} else if (os_strcmp(buf, "config_id") == 0) {
os_free(bss->config_id);
bss->config_id = os_strdup(pos);
+#ifdef CONFIG_WIFI_STATS
+ } else if (os_strcmp(buf, "wifi_stats_interval") == 0) {
+ char *end;
+ long int val = strtol(pos, &end, 10);
+
+ if (end == pos || *end ||
+ val < WIFI_STATS_MIN_INTERVAL ||
+ val > WIFI_STATS_MAX_INTERVAL) {
+ wpa_printf(MSG_ERROR,
+ "Line %d: Invalid wifi_stats_interval '%s' (must be %d-%d)",
+ line, pos, WIFI_STATS_MIN_INTERVAL,
+ WIFI_STATS_MAX_INTERVAL);
+ return 1;
+ }
+ conf->wifi_stats_interval = (unsigned int) val;
+ } else if (os_strcmp(buf, "wifi_stats_wba_window") == 0) {
+ char *end;
+ long int val = strtol(pos, &end, 10);
+
+ if (end == pos || *end ||
+ val < WIFI_STATS_MIN_WINDOW ||
+ val > WIFI_STATS_MAX_WINDOW) {
+ wpa_printf(MSG_ERROR,
+ "Line %d: Invalid wifi_stats_wba_window '%s' (must be %d-%d seconds)",
+ line, pos, WIFI_STATS_MIN_WINDOW,
+ WIFI_STATS_MAX_WINDOW);
+ return 1;
+ }
+ conf->wifi_stats_wba_window = (unsigned int) val;
+ } else if (os_strcmp(buf, "wifi_stats_span") == 0) {
+ enum wifi_stats_span_mode mode =
+ wifi_stats_span_mode_from_str(pos);
+
+ if (mode >= WIFI_STATS_SPAN_COUNT) {
+ wpa_printf(MSG_ERROR,
+ "Line %d: Invalid wifi_stats_span '%s' (must be report or window)",
+ line, pos);
+ return 1;
+ }
+ conf->wifi_stats_span = mode;
+ } else if (os_strcmp(buf, "wifi_stats_ewma_weight") == 0) {
+ char *end;
+ long int val = strtol(pos, &end, 10);
+
+ if (end == pos || *end ||
+ val < WIFI_STATS_MIN_EWMA_WEIGHT ||
+ val > WIFI_STATS_MAX_EWMA_WEIGHT) {
+ wpa_printf(MSG_ERROR,
+ "Line %d: Invalid wifi_stats_ewma_weight '%s' (must be %d-%d)",
+ line, pos, WIFI_STATS_MIN_EWMA_WEIGHT,
+ WIFI_STATS_MAX_EWMA_WEIGHT);
+ return 1;
+ }
+ conf->wifi_stats_ewma_weight = (unsigned int) val;
+ } else if (os_strcmp(buf, "wifi_stats_wba_enabled") == 0) {
+ char *end;
+ long int val = strtol(pos, &end, 10);
+
+ if (end == pos || *end ||
+ (val != 0 && val != 1)) {
+ wpa_printf(MSG_ERROR,
+ "Line %d: Invalid wifi_stats_wba_enabled '%s' (must be 0 or 1)",
+ line, pos);
+ return 1;
+ }
+ conf->wifi_stats_wba_enabled = val;
+ } else if (os_strncmp(buf, "wifi_stats_metric_", 18) == 0) {
+ const char *metric_name = buf + 18;
+ enum wifi_stats_metric_type metric_idx;
+ enum wifi_stats_agg_type algorithm;
+
+ metric_idx = wifi_stats_metric_type_from_str(metric_name);
+ if (metric_idx >= WIFI_STATS_METRIC_COUNT) {
+ wpa_printf(MSG_ERROR,
+ "Line %d: Unknown wifi_stats metric '%s'",
+ line, metric_name);
+ return 1;
+ }
+
+ algorithm = wifi_stats_agg_type_from_str(pos);
+ if (algorithm >= WIFI_STATS_AGG_COUNT) {
+ wpa_printf(MSG_ERROR,
+ "Line %d: Unknown algorithm '%s'",
+ line, pos);
+ return 1;
+ }
+
+ if (!wifi_stats_algorithm_valid(metric_idx, algorithm)) {
+ wpa_printf(MSG_ERROR,
+ "Line %d: Algorithm '%s' is not valid for wifi_stats metric '%s'",
+ line, pos, metric_name);
+ return 1;
+ }
+
+ conf->wifi_stats_metrics[metric_idx].configured = true;
+ conf->wifi_stats_metrics[metric_idx].algorithm = algorithm;
+
+ wpa_printf(MSG_DEBUG,
+ "wifi_stats: Configured metric=%s algorithm=%s",
+ metric_name, pos);
+#endif /* CONFIG_WIFI_STATS */
} else if (os_strcmp(buf, "country_code") == 0) {
if (pos[0] < 'A' || pos[0] > 'Z' ||
pos[1] < 'A' || pos[1] > 'Z') {
diff --git a/hostapd/hostapd.conf b/hostapd/hostapd.conf
index c2bd5efe5..9b1fbdc48 100644
--- a/hostapd/hostapd.conf
+++ b/hostapd/hostapd.conf
@@ -3683,6 +3683,88 @@ own_ip_addr=127.0.0.1
#enable_dscp_policy_capa=0
#
+##### Wi-Fi statistics and WBA Connect-Info ###################################
+#
+# The options in this section are only available when the build configuration
+# option CONFIG_WIFI_STATS is set while compiling hostapd.
+#
+# When enabled with wifi_stats_wba_enabled=1, hostapd polls the driver
+# periodically for per-station statistics, aggregates them, and reports the
+# result in the RADIUS Connect-Info attribute using the format defined in
+# draft-ietf-radext-connectinfo-02.
+#
+# For an MLD station, the statistics of its links are combined: counters are
+# summed, bit rates are summed over the links carrying traffic, and RSSI is
+# taken from the best link. One Global-OC is reported for each link with its
+# Link-ID and the maximum rate of an AP MLD is the sum over its links.
+
+# Interval in seconds between driver polls for station statistics.
+# wifi_stats_interval is in 1..3600 range. Default is 1 second.
+#wifi_stats_interval=1
+
+# Length of the aggregation window in seconds. With wifi_stats_span=window, the
+# samples collected within the last wifi_stats_wba_window seconds are
+# aggregated into the values reported in Connect-Info. A metric with fewer than
+# two samples in the window is reported as its latest value without an
+# aggregation suffix (frameloss and frameretry are left out unless their
+# algorithm is NONE), so the window should be at least twice
+# wifi_stats_interval.
+# hostapd keeps wifi_stats_wba_window / wifi_stats_interval + 1 samples of 64
+# bytes for each associated station (about 4 kB with the default values).
+# With wifi_stats_span=report, no samples are kept and this value can only
+# bound the accumulation period (see wifi_stats_span below).
+# wifi_stats_wba_window is in 1..3600 range. Default is 60 seconds.
+#wifi_stats_wba_window=60
+
+# How the aggregation span is determined
+# window - sliding window of wifi_stats_wba_window seconds (default)
+# report - since the previous RADIUS accounting report for the station
+# (draft-ietf-radext-connectinfo-02, Section 4.2). With interim
+# updates, the period is bounded by twice the interim interval or
+# by wifi_stats_wba_window, whichever is longer. Without RADIUS
+# accounting, it is bounded by wifi_stats_wba_window.
+# Changing wifi_stats_interval, wifi_stats_wba_window, or wifi_stats_span at
+# runtime restarts the statistics of all stations.
+#wifi_stats_span=window
+
+# Exponential weight used by the AVG-EXP algorithm. The smoothing factor is
+# 1/(2^weight), so larger values smooth more heavily. AVG-EXP metrics report
+# the weight in place of a time window, followed by the sample period in
+# milliseconds (e.g., "5-1000") when wifi_stats_interval is 9 seconds or less.
+# wifi_stats_ewma_weight is in 1..9 range. Default is 5.
+#wifi_stats_ewma_weight=5
+
+# Whether to collect station statistics and report them in the WBA Connect-Info
+# format. When disabled, nothing is collected and the
+# "CONNECT <rate>Mbps <mode>" format is used.
+# This does not change the Connect-Info attribute in the Access-Request
+# messages of RADIUS MAC ACL (macaddr_acl=2) and RADIUS PSK (wpa_psk_radius=3),
+# in RSN pre-authentication, or when the attribute is set with
+# radius_auth_req_attr or radius_acct_req_attr.
+# 0 = disabled (default)
+# 1 = enabled
+#wifi_stats_wba_enabled=0
+
+# Per-metric aggregation algorithm: wifi_stats_metric_<metric>=<algorithm>
+# <metric> is one of: rxbitrate, txbitrate, rssi, frameloss, frameretry
+# <algorithm> is one of:
+# MIN - minimum value within the aggregation span
+# MAX - maximum value within the aggregation span
+# AVG-LIN - arithmetic mean within the aggregation span
+# AVG-EXP - exponentially weighted moving average
+# ACC - percentage calculated from the change in the driver counters
+# NONE - no aggregation; report the most recent value (frameloss and
+# frameretry: the percentage since association)
+# frameloss and frameretry accept only ACC or NONE. The other metrics accept
+# any algorithm except ACC.
+# rssi and rxbitrate are aggregated only from samples taken after frames were
+# received from the station and txbitrate only after frames were sent to it.
+# frameloss and frameretry are reported once they cover at least 20 frames.
+# Defaults: rxbitrate=MAX, txbitrate=MAX, rssi=AVG-LIN, frameloss=ACC,
+# frameretry=ACC
+#wifi_stats_metric_rssi=AVG-LIN
+#wifi_stats_metric_frameloss=ACC
+
##### Multiple BSSID support ##################################################
#
# Above configuration is using the default interface (wlan#, or multi-SSID VLAN
diff --git a/src/ap/ap_config.c b/src/ap/ap_config.c
index f15175c50..ea2942473 100644
--- a/src/ap/ap_config.c
+++ b/src/ap/ap_config.c
@@ -326,6 +326,13 @@ struct hostapd_config * hostapd_config_defaults(void)
conf->disable_mcs15_rx = true;
+#ifdef CONFIG_WIFI_STATS
+ conf->wifi_stats_interval = WIFI_STATS_DEFAULT_INTERVAL;
+ conf->wifi_stats_wba_window = WIFI_STATS_DEFAULT_WINDOW;
+ conf->wifi_stats_ewma_weight = WIFI_STATS_DEFAULT_EWMA_WEIGHT;
+ conf->wifi_stats_span = WIFI_STATS_SPAN_WINDOW;
+#endif /* CONFIG_WIFI_STATS */
+
return conf;
}
diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
index 8c62cadbc..ab878f53b 100644
--- a/src/ap/ap_config.h
+++ b/src/ap/ap_config.h
@@ -19,6 +19,7 @@
#include "wps/wps.h"
#include "fst/fst.h"
#include "vlan.h"
+#include "wifi_stats.h"
enum macaddr_acl {
ACCEPT_UNLESS_DENIED = 0,
@@ -1345,6 +1346,18 @@ struct hostapd_config {
int min_power;
} afc;
#endif /* CONFIG_AFC */
+
+#ifdef CONFIG_WIFI_STATS
+ unsigned int wifi_stats_interval;
+ unsigned int wifi_stats_wba_window;
+ unsigned int wifi_stats_ewma_weight;
+ enum wifi_stats_span_mode wifi_stats_span;
+ bool wifi_stats_wba_enabled;
+ struct wifi_stats_metric_config {
+ bool configured;
+ enum wifi_stats_agg_type algorithm;
+ } wifi_stats_metrics[WIFI_STATS_METRIC_COUNT];
+#endif /* CONFIG_WIFI_STATS */
};
--
2.43.0
More information about the Hostap
mailing list