[RFC PATCH] wpa_supplicant: Add experimental WLAN sensing session framework
Chong zhu
zhuchong2025 at gmail.com
Wed Nov 4 22:14:26 PST 2026
Add an opt-in host-side WLAN sensing session framework for discussion.
This prototype manages a single session per interface, with pending/active
states, a bounded lifetime, peer and host-ID validation, bounded opaque
reports, and cleanup on stop, disassociation, and interface teardown.
Optional driver callbacks define an offload boundary. A separately gated
simulation backend allows testing without sensing-capable hardware.
This is not IEEE 802.11bf wire-protocol support. It adds no sensing
capability advertisement, management-frame codec, CSI acquisition, or
working hardware backend. The goal of this RFC is feedback on whether
this host/offload boundary and control API are appropriate before a real
backend and standards-based exchanges are implemented.
The normal build does not expose simulation commands. The control API
reports wire_protocol=unimplemented and returns FAIL-NOT-SUPPORTED when
no backend is available. Raw report bytes are not logged in normal debug
mode and are cleared on replacement and session termination.
Add standalone local-control integration tests and developer documentation.
Tested on macOS ARM64 with the none driver: enabled, disabled, and
simulation builds passed; the simulation build used AddressSanitizer and
UndefinedBehaviorSanitizer. All 125 integration assertions passed. Local
clang compatibility flags were used only in the build configuration and
are not part of this patch. Linux, RF interoperability, and conformance
have not been tested.
This patch was developed with AI assistance and reviewed through source
inspection and the local tests described above.
Signed-off-by: Chong zhu <zhuchong2025 at gmail.com>
---
RFC questions:
- Should this interface use existing driver event delivery instead of
dedicated callbacks, and where should firmware-owned negotiation end?
- Which concrete sensing-capable backend and parameter/report format
should be targeted before considering inclusion?
- Is a standalone host-only prototype useful, or should it be posted only
together with the first standards-based backend?
Base: 2ea78bb9af5f27250f97eda04d429d87bd88705f
src/common/wlan_sensing.h | 34 +++++
src/drivers/driver.h | 17 +++
tests/sensing/build-macos.sh | 22 +++
tests/sensing/test_sensing.py | 191 +++++++++++++++++++++++++
wpa_supplicant/Makefile | 8 ++
wpa_supplicant/README-SENSING | 119 +++++++++++++++
wpa_supplicant/ctrl_iface.c | 11 +-
wpa_supplicant/defconfig | 6 +
wpa_supplicant/events.c | 1 +
wpa_supplicant/sensing.c | 294 ++++++++++++++++++++++++++++++++++++++
wpa_supplicant/sensing.h | 31 ++++
wpa_supplicant/wpa_supplicant.c | 1 +
wpa_supplicant/wpa_supplicant_i.h | 4 +
13 files changed, 737 insertions(+), 2 deletions(-)
diff --git a/src/common/wlan_sensing.h b/src/common/wlan_sensing.h
new file mode 100644
index 0000000..a32f045
--- /dev/null
+++ b/src/common/wlan_sensing.h
@@ -0,0 +1,34 @@
+/* Experimental WLAN sensing host/driver API; not an IEEE wire format.
+ * Distributed under the BSD license. See README for details.
+ */
+#ifndef WLAN_SENSING_H
+#define WLAN_SENSING_H
+
+#define WPAS_SENSING_MAX_REPORT 512
+
+struct wpa_sensing_params {
+ unsigned int id; /* Host correlation ID, not an IEEE measurement ID */
+ u8 peer[ETH_ALEN];
+ unsigned int timeout; /* Host session lifetime in seconds */
+};
+
+enum wpa_sensing_event_type {
+ WPA_SENSING_ACCEPTED,
+ WPA_SENSING_REJECTED,
+ WPA_SENSING_REPORT,
+ WPA_SENSING_TERMINATED
+};
+
+struct wpa_sensing_event {
+ enum wpa_sensing_event_type type;
+ unsigned int id;
+ u8 peer[ETH_ALEN];
+ /* Opaque backend data, not assumed to be CSI or an IEEE report. */
+ const u8 *data;
+ size_t data_len;
+};
+
+typedef void (*wpa_sensing_event_cb)(void *ctx,
+ const struct wpa_sensing_event *event);
+
+#endif /* WLAN_SENSING_H */
diff --git a/src/drivers/driver.h b/src/drivers/driver.h
index 33e6193..c57a2df 100644
--- a/src/drivers/driver.h
+++ b/src/drivers/driver.h
@@ -23,6 +23,7 @@
#include "common/ieee802_11_defs.h"
#include "common/wpa_common.h"
#include "common/nan_defs.h"
+#include "common/wlan_sensing.h"
#ifdef CONFIG_MACSEC
#include "pae/ieee802_1x_kay.h"
#endif /* CONFIG_MACSEC */
@@ -3600,6 +3601,22 @@ struct nan_peer_schedule_config {
* in this wrapper.
*/
struct wpa_driver_ops {
+ /* Experimental sensing offload interface. No backend implements this
+ * yet. A backend must validate peer capability, association/protection,
+ * roles, regulatory constraints and its supported IEEE parameters.
+ * start copies params before returning. Return 0 only when queued,
+ * negative on failure (no callbacks in that case). Callbacks run on
+ * the eloop thread, only after start returns. Event data is borrowed
+ * for the duration of the callback. stop must synchronously cancel all
+ * callbacks for this ID; callback delivery must cease before it returns.
+ * stop must be safe after rejection or peer termination as well.
+ * Capability is opt-in through BOTH function pointers, never inferred
+ * from ordinary scan or beamforming support.
+ */
+ int (*sensing_start)(void *priv, const struct wpa_sensing_params *params,
+ wpa_sensing_event_cb cb, void *ctx);
+ void (*sensing_stop)(void *priv, unsigned int id);
+
/** Name of the driver interface */
const char *name;
/** One line description of the driver interface */
diff --git a/tests/sensing/build-macos.sh b/tests/sensing/build-macos.sh
new file mode 100644
index 0000000..86c0a31
--- /dev/null
+++ b/tests/sensing/build-macos.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+set -eu
+cd "$(dirname "$0")/../.."
+mkdir -p .build/sensing
+cp wpa_supplicant/.config .build/sensing/test.config
+printf '\nCONFIG_WLAN_SENSING_TEST=y\n' >> .build/sensing/test.config
+task_root="$PWD"
+# Separate object directories; restore the normal executable even on failure.
+restore_normal() {
+ make -B -C "$task_root/wpa_supplicant" -j4 all eapol_test
+}
+trap restore_normal EXIT
+make -B -C wpa_supplicant -j4 \
+ CONFIG_FILE="$task_root/.build/sensing/test.config" \
+ BUILDDIR="$task_root/.build/sensing/objects" \
+ EXTRA_CFLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer" \
+ LDFLAGS="-fsanitize=address,undefined" wpa_supplicant
+cp wpa_supplicant/wpa_supplicant .build/sensing/wpa_supplicant-test
+make -B -C wpa_supplicant -j4 \
+ CONFIG_WLAN_SENSING= \
+ BUILDDIR="$task_root/.build/sensing/disabled-objects" wpa_supplicant
+cp wpa_supplicant/wpa_supplicant .build/sensing/wpa_supplicant-disabled
diff --git a/tests/sensing/test_sensing.py b/tests/sensing/test_sensing.py
new file mode 100644
index 0000000..328e7f9
--- /dev/null
+++ b/tests/sensing/test_sensing.py
@@ -0,0 +1,191 @@
+"""Integration tests for the experimental host framework, not 11bf RF tests."""
+from pathlib import Path
+import socket
+import subprocess
+import tempfile
+import time
+
+ROOT = Path(__file__).resolve().parents[2]
+PEER = '02:00:00:00:00:01'
+OTHER = '02:00:00:00:00:02'
+checks = 0
+
+
+def check(condition, message):
+ global checks
+ assert condition, message
+ checks += 1
+
+
+def run(binary, simulation, disabled=False):
+ label = 'disabled' if disabled else ('simulation' if simulation
else 'normal')
+ log_path = ROOT / f'sensing-{label}.log'
+ with tempfile.TemporaryDirectory(prefix='sense-', dir='/tmp') as folder:
+ config = Path(folder) / 'config'
+ config.write_text(f'ctrl_interface={folder}\nap_scan=0\n')
+ with log_path.open('w+') as log:
+ process = subprocess.Popen(
+ [str(binary), '-dd', '-Dnone', '-itest0', '-c', str(config)],
+ stdout=log, stderr=log)
+ control = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
+ monitor = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
+ events = []
+ try:
+ for _ in range(100):
+ if (Path(folder) / 'test0').exists() or
process.poll() is not None:
+ break
+ time.sleep(0.05)
+ check(process.poll() is None, 'daemon failed to start')
+ for sock, name in [(control, 'client'), (monitor, 'monitor')]:
+ sock.bind(str(Path(folder) / name))
+ sock.connect(str(Path(folder) / 'test0'))
+ sock.settimeout(3)
+
+ def cmd(command):
+ control.send(command.encode())
+ response = control.recv(8192).decode().strip()
+ monitor.setblocking(False)
+ try:
+ while True:
+ events.append(monitor.recv(4096).decode())
+ except BlockingIOError:
+ pass
+ finally:
+ monitor.settimeout(3)
+ return response
+
+ def expect(command, expected):
+ response = cmd(command)
+ check(response == expected, f'{command[:100]}:
{response!r} != {expected!r}')
+
+ def start(timeout=10):
+ response = cmd(f'SENSING START {PEER} {timeout}')
+ check(response.startswith('id='), response)
+ return int(response.split('=')[1])
+
+ def event(kind, session, peer=PEER, data=''):
+ return f'SENSING TEST {kind} {session} {peer}' +
(f' {data}' if data else '')
+
+ expect('PING', 'PONG')
+ if disabled:
+ expect('SENSING CAPABILITY', 'UNKNOWN COMMAND')
+ print(f'PASS: {label}; log={log_path.name}')
+ return
+ capability = cmd('SENSING CAPABILITY')
+ check('supported=0' in capability, capability)
+ check('wire_protocol=unimplemented' in capability, capability)
+ expect(f'SENSING START {PEER} 10', 'FAIL-NOT-SUPPORTED')
+ expect('SENSING RESULT', 'FAIL')
+ expect('SENSING STOP 1', 'FAIL')
+ expect('SENSING INVALID', 'FAIL-UNKNOWN-SENSING-COMMAND')
+ invalid = [
+ f'{PEER}', f'{PEER} 0', f'{PEER} 61', f'{PEER} -1',
+ f'{PEER} +1', f'{PEER} 1x', f'{PEER} 4294967297',
+ f'{PEER} 99999999999999999999999999', f'{PEER} 1 extra',
+ '00:00:00:00:00:00 1', 'ff:ff:ff:ff:ff:ff 1',
+ '01:00:00:00:00:01 1', 'invalid 1', f'{PEER}x 1',
+ ]
+ for args in invalid:
+ expect(f'SENSING START {args}', 'FAIL-INVALID-ARGS')
+ if not simulation:
+ expect('SENSING TEST ENABLE',
'FAIL-UNKNOWN-SENSING-COMMAND')
+ print(f'PASS: {label}; log={log_path.name}')
+ return
+
+ monitor.send(b'ATTACH')
+ check(monitor.recv(128).strip() == b'OK', 'monitor
attach failed')
+ expect('SENSING TEST ENABLE', 'OK')
+ check('backend=simulation' in cmd('SENSING
CAPABILITY'), 'missing simulation label')
+ check('supported=1' in cmd('SENSING CAPABILITY'),
'test backend unavailable')
+ first = start()
+ check('state=PENDING' in cmd('SENSING STATUS'), 'not pending')
+ expect(f'SENSING START {PEER} 10', 'FAIL-BUSY')
+ expect('SENSING TEST ENABLE', 'FAIL')
+ expect(event('REPORT', first, data='0102'), 'FAIL')
+ expect(event('ACCEPT', first, OTHER), 'FAIL')
+ expect(event('ACCEPT', first + 1), 'FAIL')
+ expect(event('ACCEPT', first, data='00'), 'FAIL')
+ expect(event('ACCEPT', first), 'OK')
+ expect(event('ACCEPT', first), 'FAIL')
+ check('state=ACTIVE' in cmd('SENSING STATUS'), 'not active')
+ expect(event('REJECT', first), 'FAIL')
+ for data in ['0', 'zz', '00' * 513]:
+ expect(event('REPORT', first, data=data), 'FAIL')
+ report = 'cafebabedeadbeef'
+ expect(event('REPORT', first, data=report), 'OK')
+ expect('SENSING RESULT', report)
+ full_report = 'a5' * 512
+ expect(event('REPORT', first, data=full_report), 'OK')
+ expect('SENSING RESULT', full_report)
+ status = cmd('SENSING STATUS')
+ check('reports=2' in status and 'report_bytes=512' in
status, status)
+ expect(f'SENSING STOP {first + 1}', 'FAIL')
+ expect(f'SENSING STOP {first}', 'OK')
+ expect('SENSING RESULT', 'FAIL')
+ expect(event('REPORT', first, data='01'), 'FAIL')
+ second = start()
+ check(second > first, 'ID reused')
+ expect(event('ACCEPT', first), 'FAIL')
+ expect(event('REJECT', second), 'OK')
+ check('state=IDLE' in cmd('SENSING STATUS'),
'rejection did not clean up')
+ third = start(1)
+ deadline = time.monotonic() + 3
+ while 'state=IDLE' not in cmd('SENSING STATUS'):
+ check(time.monotonic() < deadline, 'pending
timeout did not fire')
+ time.sleep(0.1)
+ expect(event('ACCEPT', third), 'FAIL')
+ active_timeout = start(1)
+ expect(event('ACCEPT', active_timeout), 'OK')
+ time.sleep(1.1)
+ check('state=IDLE' in cmd('SENSING STATUS'), 'active
timeout did not fire')
+ fourth = start()
+ expect(event('ACCEPT', fourth), 'OK')
+ expect(event('END', fourth), 'OK')
+ check('state=IDLE' in cmd('SENSING STATUS'), 'peer
end did not clean up')
+ fifth = start()
+ expect(event('ACCEPT', fifth), 'OK')
+ expect('DISCONNECT', 'OK')
+ check('state=IDLE' in cmd('SENSING STATUS'),
'disconnect did not clean up')
+ sixth = start()
+ expect('SENSING TEST DISABLE', 'OK')
+ expect(f'SENSING START {PEER} 10', 'FAIL-NOT-SUPPORTED')
+ expect(event('ACCEPT', sixth), 'FAIL')
+ expect('SENSING TEST ENABLE', 'OK')
+ final = start()
+ expect(event('ACCEPT', final), 'OK')
+
+ monitor.settimeout(0.1)
+ while True:
+ try:
+ events.append(monitor.recv(4096).decode())
+ except socket.timeout:
+ break
+ for marker in ['SENSING-PENDING', 'SENSING-ACTIVE',
'SENSING-REPORT',
+ 'reason=timeout', 'reason=rejected',
'reason=reset',
+ 'reason=peer-terminated', 'reason=requested']:
+ check(any(marker in entry for entry in events),
f'missing event: {marker}')
+ except Exception:
+ log.flush()
+ log.seek(0)
+ print(log.read())
+ raise
+ finally:
+ control.close()
+ monitor.close()
+ if process.poll() is None:
+ process.terminate()
+ process.wait(timeout=5)
+ check(process.returncode == 0, f'daemon exited
{process.returncode}')
+ text = log_path.read_text()
+ if simulation:
+ check('runtime error:' not in text and 'ERROR:
AddressSanitizer' not in text,
+ 'sanitizer diagnostics in runtime log')
+ check('cafebabedeadbeef' not in text, 'measurement leaked
into debug log')
+ check(f'id={final} reason=reset' in text, 'shutdown did
not reset active session')
+ print(f'PASS: {label}; log={log_path.name}')
+
+
+run(ROOT / 'wpa_supplicant/wpa_supplicant', False)
+run(ROOT / '.build/sensing/wpa_supplicant-disabled', False, disabled=True)
+run(ROOT / '.build/sensing/wpa_supplicant-test', True)
+print(f'PASS: {checks} assertions (host simulation only; no RF measurements)')
diff --git a/wpa_supplicant/Makefile b/wpa_supplicant/Makefile
index 7fe5ffe..b8d9bf2 100644
--- a/wpa_supplicant/Makefile
+++ b/wpa_supplicant/Makefile
@@ -546,6 +546,14 @@ ifdef CONFIG_NO_LOAD_DYNAMIC_EAP
CFLAGS += -DCONFIG_NO_LOAD_DYNAMIC_EAP
endif
+ifdef CONFIG_WLAN_SENSING
+CFLAGS += -DCONFIG_WLAN_SENSING
+OBJS += sensing.o
+ifdef CONFIG_WLAN_SENSING_TEST
+CFLAGS += -DCONFIG_WLAN_SENSING_TEST
+endif
+endif
+
ifdef CONFIG_NO_RRM
CFLAGS += -DCONFIG_NO_RRM
else
diff --git a/wpa_supplicant/README-SENSING b/wpa_supplicant/README-SENSING
new file mode 100644
index 0000000..4eec86a
--- /dev/null
+++ b/wpa_supplicant/README-SENSING
@@ -0,0 +1,119 @@
+Experimental WLAN sensing framework for wpa_supplicant
+=========================================================
+
+Scope and status
+----------------
+This change adds a host-side foundation for future IEEE 802.11bf work.
+It DOES NOT implement the IEEE 802.11bf-2025 on-air protocol, advertise
+802.11bf capability, send sensing Action frames, collect CSI, or detect
+presence/motion. No real driver implements the new offload API yet.
+Reports are opaque backend bytes, not a specified IEEE report format.
+The simulation backend injects explicitly supplied test bytes only.
+
+Implemented
+-----------
+* Per-interface single-session state: IDLE -> PENDING -> ACTIVE -> IDLE.
+* Strict peer/timeout parsing; unicast, nonzero MAC; lifetime 1..60 seconds.
+* Monotonically increasing host IDs retained across reset to reject stale
+ callbacks. These IDs are NOT IEEE measurement session identifiers.
+* Acceptance, rejection, termination and bounded report callbacks.
+* Fixed absolute session deadline covering negotiation and active lifetime.
+* Stop, disconnect and interface cleanup cancel timers and the backend.
+* Report data cleared on replacement and termination. Only the most recent
+ report (up to 512 bytes) is retained; no history or filesystem persistence.
+* Capability/status/result commands and monitor notifications.
+* Simulation injection is compile-time gated, absent in normal builds,
+ and requires explicit runtime enablement in test builds.
+
+Build and verify
+----------------
+Enable CONFIG_WLAN_SENSING=y, not its test option, in the normal .config.
+ # Configure wpa_supplicant/.config for your platform first.
+ # Set CONFIG_WLAN_SENSING=y and CONFIG_DRIVER_NONE=y for these tests.
+ # The macOS example additionally uses CONFIG_OSX=y, CONFIG_L2_PACKET=none,
+ # CONFIG_TLS=internal and CONFIG_INTERNAL_LIBTOMMATH=y.
+ sh tests/sensing/build-macos.sh > build-sensing-test.log 2>&1
+ python3 tests/sensing/test_sensing.py
+
+tests/sensing/build-macos.sh builds a separate simulation executable at
+.build/sensing/wpa_supplicant-test, then restores the normal executables.
+The simulation executable uses AddressSanitizer and UndefinedBehaviorSanitizer.
+A feature-disabled executable is also built to verify optional integration.
+Its build process overwrites the normal executable temporarily; do not
+run concurrent builds or launch it during that process.
+Unix socket tests may need authorization to run outside restricted sandboxes.
+
+Control commands (after launching an interface)
+----------------------------------------------
+ wpa_cli -p /path/to/control -i test0 raw SENSING CAPABILITY
+ wpa_cli -p /path/to/control -i test0 raw SENSING STATUS
+ wpa_cli -p /path/to/control -i test0 raw SENSING START 02:00:00:00:00:01 10
+ wpa_cli -p /path/to/control -i test0 raw SENSING RESULT
+ wpa_cli -p /path/to/control -i test0 raw SENSING STOP 1
+
+START arguments: peer MAC and lifetime seconds. Success returns id=<host ID>.
+The none driver returns FAIL-NOT-SUPPORTED. CAPABILITY explicitly reports
+framework=experimental and wire_protocol=unimplemented, even in simulation.
+RESULT returns the last opaque report as hex only for an active session.
+These new commands are local experimental API, not upstream-standard CLI.
+
+Test executable only:
+ SENSING TEST ENABLE
+ SENSING START 02:00:00:00:00:01 10
+ SENSING TEST ACCEPT <id> 02:00:00:00:00:01
+ SENSING TEST REPORT <id> 02:00:00:00:00:01 01020304
+ SENSING RESULT
+ SENSING TEST END <id> 02:00:00:00:00:01
+ SENSING TEST DISABLE
+REJECT is also supported for pending sessions. Test commands require the
+same protected local control socket access as other control commands.
+
+Monitor events:
+ CTRL-EVENT-SENSING-PENDING id=... peer=...
+ CTRL-EVENT-SENSING-ACTIVE id=... peer=...
+ CTRL-EVENT-SENSING-REPORT id=... reports=... bytes=...
+ CTRL-EVENT-SENSING-ENDED id=... reason=...
+Report bytes are not included in these events or normal debug logs.
+Upstream key-debug mode (-K) can print injected report command contents;
+do not enable that mode when testing confidential data.
+
+Driver contract
+---------------
+src/common/wlan_sensing.h defines host parameters and borrowed events.
+src/drivers/driver.h adds optional sensing_start/sensing_stop callbacks.
+Both callbacks are required for the backend to be considered available.
+start must copy params, return before delivering any callback, and use the
+eloop thread for callbacks. Failed start must leave no live session.
+stop must synchronously quiesce callbacks before returning, including when
+called from a rejected/terminated event. See driver.h for full contract.
+The backend must enforce association, peer capability, protected exchanges,
+supported roles and regulatory constraints before transmitting/accepting
+real traffic. None of those properties is asserted by this host prototype.
+
+Remaining work for actual 802.11bf support
+-----------------------------------------
+1. Obtain and verify the final 802.11bf-2025 wire layouts, assigned element
+ and Action identifiers, capability bits and normative state rules.
+2. Define supported roles, negotiated measurement parameters, reporting
+ formats and protected/unassociated peer behavior against that standard.
+3. Implement and test the real driver/firmware transport and capability
+ discovery, plus management-frame RX/TX and measurement result delivery.
+4. Integrate capability advertisement only when the supported subset and
+ hardware are verified; do not infer it from this experimental build flag.
+5. Run conformance vectors, malformed-frame tests and interoperable RF
+ tests with a capable peer. Then address multi-session/resource scheduling.
+
+Sources (background; older papers describe drafts, not final wire formats)
+------------------------------------------------------------------------
+Final standard overview:
+https://standards.ieee.org/ieee/802.11bf/11574/
+NIST overview of the first draft:
+https://www.nist.gov/publications/ieee-80211bf-enabling-widespread-adoption-wi-fi-sensing
+
+Validation artifacts
+--------------------
+tests/sensing/test_sensing.py: normal and simulation
control-interface integration tests.
+sensing-normal.log, sensing-simulation.log: runtime logs.
+build-sensing-test.log: simulation and normal restore build log.
+The tests exercise host behavior only; successful tests are NOT evidence
+of IEEE 802.11bf conformance or physical sensing capability.
diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index 282ef52..79dec97 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -13840,7 +13840,8 @@ char *
wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
os_strncmp(buf, "PMKSA_ADD ", 10) == 0 ||
- os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
+ os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0 ||
+ os_strncmp(buf, "SENSING TEST REPORT ", 20) == 0) {
if (wpa_debug_show_keys)
wpa_dbg(wpa_s, MSG_DEBUG,
"Control interface command '%s'", buf);
@@ -13851,7 +13852,9 @@ char *
wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
os_strlen(WPA_CTRL_RSP)) == 0 ?
WPA_CTRL_RSP :
(os_strncmp(buf, "SET_NETWORK ", 12) == 0 ?
- "SET_NETWORK" : "key-add"));
+ "SET_NETWORK" :
+ (os_strncmp(buf, "SENSING TEST REPORT ", 20) == 0 ?
+ "SENSING TEST REPORT" : "key-add")));
} else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
@@ -13873,6 +13876,10 @@ char *
wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
if (os_strcmp(buf, "PING") == 0) {
os_memcpy(reply, "PONG\n", 5);
reply_len = 5;
+#ifdef CONFIG_WLAN_SENSING
+ } else if (os_strncmp(buf, "SENSING ", 8) == 0) {
+ reply_len = wpas_sensing_ctrl(wpa_s, buf + 8, reply, reply_size);
+#endif
} else if (os_strcmp(buf, "IFNAME") == 0) {
reply_len = os_strlen(wpa_s->ifname);
os_memcpy(reply, wpa_s->ifname, reply_len);
diff --git a/wpa_supplicant/defconfig b/wpa_supplicant/defconfig
index 3ecd1e5..2671b80 100644
--- a/wpa_supplicant/defconfig
+++ b/wpa_supplicant/defconfig
@@ -668,6 +668,12 @@ CONFIG_DPP2=y
# AP manage the network and STA steering.
#CONFIG_NO_RRM=y
+# Experimental host-side WLAN sensing session framework. This does not
+# implement IEEE 802.11bf wire encoding or provide a hardware backend.
+#CONFIG_WLAN_SENSING=y
+# Local simulated callbacks for development ONLY; disabled by default.
+#CONFIG_WLAN_SENSING_TEST=y
+
# Disable support for Robust AV streaming for consumer and enterprise Wi-Fi
# applications; IEEE Std 802.11-2020, 4.3.24; SCS, MSCS, QoS Management
#CONFIG_NO_ROBUST_AV=y
diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
index e166471..e99a6e6 100644
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -364,6 +364,7 @@ void wpa_supplicant_mark_disassoc(struct
wpa_supplicant *wpa_s)
{
int bssid_changed;
+ wpas_sensing_reset(wpa_s);
wnm_bss_keep_alive_deinit(wpa_s);
#ifdef CONFIG_IBSS_RSN
diff --git a/wpa_supplicant/sensing.c b/wpa_supplicant/sensing.c
new file mode 100644
index 0000000..a1bfa3b
--- /dev/null
+++ b/wpa_supplicant/sensing.c
@@ -0,0 +1,294 @@
+/*
+ * Experimental WLAN sensing host-side session framework.
+ * This is not an implementation of the IEEE 802.11bf wire protocol.
+ * Distributed under the BSD license. See README for details.
+ */
+#include "utils/includes.h"
+#include <limits.h>
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "drivers/driver.h"
+#include "wpa_supplicant_i.h"
+#include "sensing.h"
+
+static void sensing_timeout(void *eloop_ctx, void *timeout_ctx);
+
+static int sensing_supported(struct wpa_supplicant *wpa_s)
+{
+#ifdef CONFIG_WLAN_SENSING_TEST
+ if (wpa_s->sensing.test_backend)
+ return 1;
+#endif
+ return wpa_s->driver && wpa_s->driver->sensing_start &&
+ wpa_s->driver->sensing_stop;
+}
+
+static void sensing_end(struct wpa_supplicant *wpa_s, const char *reason)
+{
+ struct wpas_sensing *s = &wpa_s->sensing;
+ unsigned int id;
+
+ if (s->state == WPAS_SENSING_IDLE)
+ return;
+ id = s->params.id;
+ /* Invalidate first so a synchronous stop callback cannot revive it. */
+ s->state = WPAS_SENSING_IDLE;
+ eloop_cancel_timeout(sensing_timeout, wpa_s, NULL);
+#ifdef CONFIG_WLAN_SENSING_TEST
+ if (!s->test_backend)
+#endif
+ {
+ if (wpa_s->driver && wpa_s->driver->sensing_stop)
+ wpa_s->driver->sensing_stop(wpa_s->drv_priv, id);
+ }
+ forced_memzero(s->report, sizeof(s->report));
+ s->report_len = 0;
+ s->reports = 0;
+ os_memset(&s->params, 0, sizeof(s->params));
+ wpa_msg(wpa_s, MSG_INFO, "CTRL-EVENT-SENSING-ENDED id=%u reason=%s",
+ id, reason);
+}
+
+void wpas_sensing_reset(struct wpa_supplicant *wpa_s)
+{
+ sensing_end(wpa_s, "reset");
+}
+
+static void sensing_timeout(void *eloop_ctx, void *timeout_ctx)
+{
+ sensing_end(eloop_ctx, "timeout");
+}
+
+static int sensing_notify(struct wpa_supplicant *wpa_s,
+ const struct wpa_sensing_event *event)
+{
+ struct wpas_sensing *s = &wpa_s->sensing;
+
+ if (!event || s->state == WPAS_SENSING_IDLE ||
+ event->id != s->params.id ||
+ os_memcmp(event->peer, s->params.peer, ETH_ALEN) != 0)
+ return -1;
+
+ switch (event->type) {
+ case WPA_SENSING_ACCEPTED:
+ if (s->state != WPAS_SENSING_PENDING)
+ return -1;
+ s->state = WPAS_SENSING_ACTIVE;
+ wpa_msg(wpa_s, MSG_INFO,
+ "CTRL-EVENT-SENSING-ACTIVE id=%u peer=" MACSTR,
+ event->id, MAC2STR(event->peer));
+ return 0;
+ case WPA_SENSING_REJECTED:
+ if (s->state != WPAS_SENSING_PENDING)
+ return -1;
+ sensing_end(wpa_s, "rejected");
+ return 0;
+ case WPA_SENSING_TERMINATED:
+ sensing_end(wpa_s, "peer-terminated");
+ return 0;
+ case WPA_SENSING_REPORT:
+ if (s->state != WPAS_SENSING_ACTIVE || !event->data ||
+ !event->data_len || event->data_len > sizeof(s->report) ||
+ s->reports == UINT_MAX)
+ return -1;
+ forced_memzero(s->report, sizeof(s->report));
+ os_memcpy(s->report, event->data, event->data_len);
+ s->report_len = event->data_len;
+ s->reports++;
+ /* Raw measurements are retrieved explicitly, never logged. */
+ wpa_msg(wpa_s, MSG_INFO,
+ "CTRL-EVENT-SENSING-REPORT id=%u reports=%u bytes=%u",
+ event->id, s->reports, (unsigned int) event->data_len);
+ return 0;
+ default:
+ return -1;
+ }
+}
+
+static void sensing_driver_event(void *ctx,
+ const struct wpa_sensing_event *event)
+{
+ if (sensing_notify(ctx, event) < 0)
+ wpa_printf(MSG_DEBUG, "SENSING: Ignoring invalid or stale event");
+}
+
+/* Decimal only, reject signs, whitespace, junk and overflow before casting. */
+static int sensing_uint(const char *text, unsigned int max, unsigned int *out)
+{
+ unsigned int value = 0;
+ const char *p;
+
+ if (!text || !*text)
+ return -1;
+ for (p = text; *p; p++) {
+ unsigned int digit;
+ if (*p < '0' || *p > '9')
+ return -1;
+ digit = *p - '0';
+ if (digit > max || value > (max - digit) / 10)
+ return -1;
+ value = value * 10 + digit;
+ }
+ if (!value)
+ return -1;
+ *out = value;
+ return 0;
+}
+
+static int sensing_start(struct wpa_supplicant *wpa_s, char *cmd,
+ char *reply, size_t len)
+{
+ struct wpas_sensing *s = &wpa_s->sensing;
+ struct wpa_sensing_params params;
+ char *context = NULL, *peer, *timeout;
+ int ret = 0;
+
+ os_memset(¶ms, 0, sizeof(params));
+ peer = str_token(cmd, " ", &context);
+ timeout = str_token(cmd, " ", &context);
+ if (!peer || !timeout || str_token(cmd, " ", &context) ||
+ os_strlen(peer) != 17 || hwaddr_aton(peer, params.peer) ||
+ is_zero_ether_addr(params.peer) ||
+ is_multicast_ether_addr(params.peer) ||
+ sensing_uint(timeout, 60, ¶ms.timeout))
+ return os_snprintf(reply, len, "FAIL-INVALID-ARGS\n");
+ if (s->state != WPAS_SENSING_IDLE)
+ return os_snprintf(reply, len, "FAIL-BUSY\n");
+ if (!sensing_supported(wpa_s))
+ return os_snprintf(reply, len, "FAIL-NOT-SUPPORTED\n");
+ /* Never reuse an ID on this interface, including after a reset. */
+ if (s->next_id == INT_MAX)
+ return os_snprintf(reply, len, "FAIL-ID-EXHAUSTED\n");
+ params.id = ++s->next_id;
+ s->params = params;
+ s->state = WPAS_SENSING_PENDING;
+ if (eloop_register_timeout(params.timeout, 0, sensing_timeout,
+ wpa_s, NULL) < 0) {
+ s->state = WPAS_SENSING_IDLE;
+ os_memset(&s->params, 0, sizeof(s->params));
+ return -1;
+ }
+#ifdef CONFIG_WLAN_SENSING_TEST
+ if (!s->test_backend)
+#endif
+ ret = wpa_s->driver->sensing_start(wpa_s->drv_priv, ¶ms,
+ sensing_driver_event, wpa_s);
+ if (ret < 0) {
+ /* Failed start guarantees no callbacks and no session to stop. */
+ eloop_cancel_timeout(sensing_timeout, wpa_s, NULL);
+ s->state = WPAS_SENSING_IDLE;
+ os_memset(&s->params, 0, sizeof(s->params));
+ return os_snprintf(reply, len, "FAIL-DRIVER\n");
+ }
+ wpa_msg(wpa_s, MSG_INFO, "CTRL-EVENT-SENSING-PENDING id=%u peer="
+ MACSTR, params.id, MAC2STR(params.peer));
+ return os_snprintf(reply, len, "id=%u\n", params.id);
+}
+
+#ifdef CONFIG_WLAN_SENSING_TEST
+static int sensing_test(struct wpa_supplicant *wpa_s, char *cmd)
+{
+ struct wpas_sensing *s = &wpa_s->sensing;
+ struct wpa_sensing_event event;
+ char *context = NULL, *kind, *id, *peer, *hex;
+ u8 data[WPAS_SENSING_MAX_REPORT];
+ int ret;
+
+ if (os_strcmp(cmd, "ENABLE") == 0) {
+ if (s->state != WPAS_SENSING_IDLE)
+ return -1;
+ s->test_backend = 1;
+ return 0;
+ }
+ if (os_strcmp(cmd, "DISABLE") == 0) {
+ sensing_end(wpa_s, "test-disabled");
+ s->test_backend = 0;
+ return 0;
+ }
+ if (!s->test_backend)
+ return -1;
+ os_memset(&event, 0, sizeof(event));
+ kind = str_token(cmd, " ", &context);
+ id = str_token(cmd, " ", &context);
+ peer = str_token(cmd, " ", &context);
+ hex = str_token(cmd, " ", &context);
+ if (!kind || !peer || sensing_uint(id, INT_MAX, &event.id) ||
+ os_strlen(peer) != 17 || hwaddr_aton(peer, event.peer) ||
+ str_token(cmd, " ", &context))
+ return -1;
+ if (os_strcmp(kind, "ACCEPT") == 0)
+ event.type = WPA_SENSING_ACCEPTED;
+ else if (os_strcmp(kind, "REJECT") == 0)
+ event.type = WPA_SENSING_REJECTED;
+ else if (os_strcmp(kind, "END") == 0)
+ event.type = WPA_SENSING_TERMINATED;
+ else if (os_strcmp(kind, "REPORT") == 0)
+ event.type = WPA_SENSING_REPORT;
+ else
+ return -1;
+ if (event.type == WPA_SENSING_REPORT) {
+ if (!hex || !*hex || os_strlen(hex) % 2 ||
+ os_strlen(hex) / 2 > sizeof(data))
+ return -1;
+ event.data_len = os_strlen(hex) / 2;
+ if (hexstr2bin(hex, data, event.data_len))
+ return -1;
+ event.data = data;
+ } else if (hex) {
+ return -1;
+ }
+ ret = sensing_notify(wpa_s, &event);
+ forced_memzero(data, sizeof(data));
+ return ret;
+}
+#endif /* CONFIG_WLAN_SENSING_TEST */
+
+int wpas_sensing_ctrl(struct wpa_supplicant *wpa_s, char *cmd,
+ char *reply, size_t len)
+{
+ struct wpas_sensing *s = &wpa_s->sensing;
+ const char *backend = "driver";
+ const char *states[] = { "IDLE", "PENDING", "ACTIVE" };
+ unsigned int id;
+
+#ifdef CONFIG_WLAN_SENSING_TEST
+ if (s->test_backend)
+ backend = "simulation";
+ if (os_strncmp(cmd, "TEST ", 5) == 0) {
+ if (sensing_test(wpa_s, cmd + 5) < 0)
+ return -1;
+ return os_snprintf(reply, len, "OK\n");
+ }
+#endif
+ if (os_strcmp(cmd, "CAPABILITY") == 0)
+ return os_snprintf(reply, len,
+ "framework=experimental\nwire_protocol=unimplemented\n"
+ "backend=%s\nsupported=%d\nmax_sessions=1\n"
+ "max_report_bytes=%u\n", backend,
+ sensing_supported(wpa_s), WPAS_SENSING_MAX_REPORT);
+ if (os_strcmp(cmd, "STATUS") == 0)
+ return os_snprintf(reply, len,
+ "state=%s\nid=%u\npeer=" MACSTR "\nreports=%u\n"
+ "report_bytes=%u\nbackend=%s\n",
+ states[s->state], s->params.id,
+ MAC2STR(s->params.peer), s->reports,
+ (unsigned int) s->report_len, backend);
+ if (os_strncmp(cmd, "START ", 6) == 0)
+ return sensing_start(wpa_s, cmd + 6, reply, len);
+ if (os_strncmp(cmd, "STOP ", 5) == 0) {
+ if (sensing_uint(cmd + 5, INT_MAX, &id) ||
+ s->state == WPAS_SENSING_IDLE || id != s->params.id)
+ return -1;
+ sensing_end(wpa_s, "requested");
+ return os_snprintf(reply, len, "OK\n");
+ }
+ if (os_strcmp(cmd, "RESULT") == 0) {
+ if (s->state != WPAS_SENSING_ACTIVE || !s->report_len ||
+ len < 2 * s->report_len + 2)
+ return -1;
+ wpa_snprintf_hex(reply, len, s->report, s->report_len);
+ reply[2 * s->report_len] = '\n';
+ return 2 * s->report_len + 1;
+ }
+ return os_snprintf(reply, len, "FAIL-UNKNOWN-SENSING-COMMAND\n");
+}
diff --git a/wpa_supplicant/sensing.h b/wpa_supplicant/sensing.h
new file mode 100644
index 0000000..754348f
--- /dev/null
+++ b/wpa_supplicant/sensing.h
@@ -0,0 +1,31 @@
+/* Experimental sensing session management. BSD license; see README. */
+#ifndef WPAS_SENSING_H
+#define WPAS_SENSING_H
+
+#include "common/wlan_sensing.h"
+
+struct wpa_supplicant;
+
+struct wpas_sensing {
+ enum { WPAS_SENSING_IDLE, WPAS_SENSING_PENDING,
+ WPAS_SENSING_ACTIVE } state;
+ struct wpa_sensing_params params;
+ unsigned int next_id;
+ unsigned int reports;
+ u8 report[WPAS_SENSING_MAX_REPORT];
+ size_t report_len;
+#ifdef CONFIG_WLAN_SENSING_TEST
+ int test_backend;
+#endif
+};
+
+int wpas_sensing_ctrl(struct wpa_supplicant *wpa_s, char *cmd,
+ char *reply, size_t len);
+
+#ifdef CONFIG_WLAN_SENSING
+void wpas_sensing_reset(struct wpa_supplicant *wpa_s);
+#else
+static inline void wpas_sensing_reset(struct wpa_supplicant *wpa_s) {}
+#endif
+
+#endif /* WPAS_SENSING_H */
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index a04652f..d030162 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -830,6 +830,7 @@ static void wpa_supplicant_cleanup(struct
wpa_supplicant *wpa_s)
#endif /* CONFIG_MBO */
free_bss_tmp_disallowed(wpa_s);
+ wpas_sensing_reset(wpa_s);
wpabuf_free(wpa_s->lci);
wpa_s->lci = NULL;
diff --git a/wpa_supplicant/wpa_supplicant_i.h
b/wpa_supplicant/wpa_supplicant_i.h
index a1d8029..b02bec3 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -11,6 +11,7 @@
#include "utils/bitfield.h"
#include "utils/list.h"
+#include "sensing.h"
#include "common/defs.h"
#include "common/sae.h"
#include "common/wpa_ctrl.h"
@@ -765,6 +766,9 @@ struct auth_802_1x_data {
* core functions.
*/
struct wpa_supplicant {
+#ifdef CONFIG_WLAN_SENSING
+ struct wpas_sensing sensing;
+#endif
struct wpa_global *global;
struct wpa_radio *radio; /* shared radio context */
struct dl_list radio_list; /* list head: struct wpa_radio::ifaces */
More information about the Hostap
mailing list