[PATCH 23/35] wpa_supplicant: Support synchronized NAN publish/subscribe

Andrei Otcheretianski andrei.otcheretianski at intel.com
Mon Oct 20 05:27:58 PDT 2025


Extend wpas_nan_publish() and wpas_nan_subscribe() to support
synchronized discovery configuration.
Make sure NAN synchronization is active and check driver support for
user space DE.
In addition, prevent P2P2 discovery as it supposed to be USD only.

Signed-off-by: Andrei Otcheretianski <andrei.otcheretianski at intel.com>
---
 wpa_supplicant/ctrl_iface.c     | 10 ++++++
 wpa_supplicant/nan_supplicant.c | 61 +++++++++++++++++++++++++++++++--
 2 files changed, 69 insertions(+), 2 deletions(-)

diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index 30eb6ce238..c3a9194426 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -12795,6 +12795,11 @@ static int wpas_ctrl_nan_publish(struct wpa_supplicant *wpa_s, char *cmd,
 			continue;
 		}
 
+		if (os_strcmp(token, "sync=1") == 0) {
+			params.sync = true;
+			continue;
+		}
+
 		wpa_printf(MSG_INFO, "CTRL: Invalid NAN_PUBLISH parameter: %s",
 			   token);
 		goto fail;
@@ -12957,6 +12962,11 @@ static int wpas_ctrl_nan_subscribe(struct wpa_supplicant *wpa_s, char *cmd,
 			continue;
 		}
 
+		if (os_strcmp(token, "sync=1") == 0) {
+			params.sync = true;
+			continue;
+		}
+
 		wpa_printf(MSG_INFO,
 			   "CTRL: Invalid NAN_SUBSCRIBE parameter: %s",
 			   token);
diff --git a/wpa_supplicant/nan_supplicant.c b/wpa_supplicant/nan_supplicant.c
index 511a73b84a..6e19263017 100644
--- a/wpa_supplicant/nan_supplicant.c
+++ b/wpa_supplicant/nan_supplicant.c
@@ -573,6 +573,35 @@ int wpas_nan_publish(struct wpa_supplicant *wpa_s, const char *service_name,
 
 	addr = wpa_s->own_addr;
 
+#ifdef CONFIG_NAN
+	if (params->sync) {
+		if (!(wpa_s->nan_drv_flags &
+		      WPA_DRIVER_FLAGS_NAN_SUPPORT_USERSPACE_DE)) {
+			wpa_printf(MSG_DEBUG,
+				   "NAN: Can't advertise sync service, driver does not support user space DE");
+			return -1;
+		}
+
+		if (!wpas_nan_ready(wpa_s)) {
+			wpa_printf(MSG_DEBUG,
+				   "NAN: Synchronized support is not enabled");
+			return -1;
+		}
+
+		if (p2p) {
+			wpa_printf(MSG_DEBUG,
+				   "NAN: Sync discovery is not supported for P2P");
+			return -1;
+		}
+
+		if (params->proximity_ranging) {
+			wpa_printf(MSG_DEBUG,
+				   "NAN: Sync discovery is not supported for PR");
+			return -1;
+		}
+	}
+#endif /* CONFIG_NAN */
+
 	if (p2p) {
 		elems = wpas_p2p_usd_elems(wpa_s, service_name);
 		addr = wpa_s->global->p2p_dev_addr;
@@ -582,7 +611,7 @@ int wpas_nan_publish(struct wpa_supplicant *wpa_s, const char *service_name,
 
 	publish_id = nan_de_publish(wpa_s->nan_de, service_name, srv_proto_type,
 				    ssi, elems, params, p2p);
-	if (publish_id >= 1 &&
+	if (publish_id >= 1 && !params->sync &&
 	    (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_NAN_USD_OFFLOAD) &&
 	    wpas_drv_nan_publish(wpa_s, addr, publish_id, service_name,
 				 nan_de_get_service_id(wpa_s->nan_de,
@@ -654,6 +683,34 @@ int wpas_nan_subscribe(struct wpa_supplicant *wpa_s,
 
 	addr = wpa_s->own_addr;
 
+#ifdef CONFIG_NAN
+	if (params->sync) {
+		if (!(wpa_s->nan_drv_flags &
+		      WPA_DRIVER_FLAGS_NAN_SUPPORT_USERSPACE_DE)) {
+			wpa_printf(MSG_DEBUG,
+				   "NAN: Can't subscribe sync, user space DE is not supported");
+			return -1;
+		}
+
+		if (!wpas_nan_ready(wpa_s)) {
+			wpa_printf(MSG_DEBUG, "NAN: Not ready (subscribe)");
+			return -1;
+		}
+
+		if (p2p) {
+			wpa_printf(MSG_DEBUG,
+				   "NAN: Sync discovery is not supported for P2P (subscribe)");
+			return -1;
+		}
+
+		if (params->proximity_ranging) {
+			wpa_printf(MSG_DEBUG,
+				   "NAN: Sync discovery is not supported for PR (subscribe)");
+			return -1;
+		}
+	}
+#endif /* CONFIG_NAN */
+
 	if (p2p) {
 		elems = wpas_p2p_usd_elems(wpa_s, service_name);
 		addr = wpa_s->global->p2p_dev_addr;
@@ -664,7 +721,7 @@ int wpas_nan_subscribe(struct wpa_supplicant *wpa_s,
 	subscribe_id = nan_de_subscribe(wpa_s->nan_de, service_name,
 					srv_proto_type, ssi, elems, params,
 					p2p);
-	if (subscribe_id >= 1 &&
+	if (subscribe_id >= 1 && !params->sync &&
 	    (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_NAN_USD_OFFLOAD) &&
 	    wpas_drv_nan_subscribe(wpa_s, addr, subscribe_id, service_name,
 				   nan_de_get_service_id(wpa_s->nan_de,
-- 
2.49.0




More information about the Hostap mailing list