[PATCH v2] NAN: Send synchronized service SSI in SDA by default
Paul Hu
paulhu at google.com
Mon Nov 16 23:23:30 PST 2026
nan_de carried the service specific info (SSI) of synchronized NAN
services only in the SDEA Service Info field. Per Wi-Fi Aware v4.0
Sections 4.1.1 and 4.1.3, SSI is carried in either the SDA Service Info
field or the SDEA Service Info field, and receiving the SDA Service Info
field is mandatory while some NAN implementations do not parse or report
raw SSI carried only in the SDEA.
For synchronized services, carry SSI of up to 255 octets in the SDA
Service Info field by default, and use the SDEA Service Info field when
the SSI exceeds 255 octets or when explicitly requested via ssi_in_sdea
(for protocols that require the WFA OUI, Service Protocol Type, and
protocol-specific formatting such as Generic sub-attribute TLVs). Also
compute SDEA Control flags before sizing the buffer so GTK/security
flags are accounted for when SDEA Service Info is omitted. USD services
continue to use the SDEA Service Info field.
Update nan_sync_verify_event() for the default SDA placement (which has
no Service Protocol Type on the air) and add an hwsim test covering
default SDA placement, ssi_in_sdea=1, and >255-octet SSI.
Signed-off-by: Paul Hu <paulhu at google.com>
---
v2:
- Carry synchronized SSI <= 255 octets in either SDA (by default) or
SDEA (when ssi_in_sdea=1 is set), instead of duplicating it in both
SDA and SDEA.
- Add ssi_in_sdea parameter to nan_publish_params,
nan_subscribe_params, and NAN_PUBLISH/NAN_SUBSCRIBE control
interface commands for protocols that require SDEA Service Info.
- Compute publish SDEA Control flags before buffer length calculation
when SDEA Service Info is not included.
- Update hwsim NAN sync helper and test case to cover default SDA
placement, ssi_in_sdea=1, and >255-octet SSI.
src/common/nan_de.c | 48 ++++++++++++++++++--------
src/common/nan_de.h | 12 +++++++
tests/hwsim/test_nan.py | 69 ++++++++++++++++++++++++++++++++-----
wpa_supplicant/ctrl_iface.c | 10 ++++++
4 files changed, 115 insertions(+), 24 deletions(-)
diff --git a/src/common/nan_de.c b/src/common/nan_de.c
index e2570e074..82f821889 100644
--- a/src/common/nan_de.c
+++ b/src/common/nan_de.c
@@ -81,6 +81,7 @@ struct nan_de_service {
bool listen_stopped;
bool sync;
bool discover_sync;
+ bool ssi_in_sdea;
/* Filters */
struct wpabuf *matching_filter_tx;
@@ -783,6 +784,17 @@ static size_t nan_de_sdf_attrs_put(struct wpabuf *buf, struct nan_de *de,
u8 rsid_ctrl = 0; /* b0-b1: 00 = 48 bit RSID by SipHash-2-4 method */
u8 rsid_num = 0, rsid_list_len = 0;
bool zero_rsid = false;
+ bool sda_ssi = false;
+ bool sdea_ssi = false;
+
+ if (!srv->sync) {
+ sdea_ssi = ssi != NULL;
+ } else if (ssi && wpabuf_len(ssi)) {
+ if (wpabuf_len(ssi) > 255 || srv->ssi_in_sdea)
+ sdea_ssi = true;
+ else
+ sda_ssi = true;
+ }
/* Proxy attribute, proxy attribute length, and NMI address */
if (srv->publish.orig_id)
@@ -801,6 +813,12 @@ static size_t nan_de_sdf_attrs_put(struct wpabuf *buf, struct nan_de *de,
ctrl |= NAN_SRV_CTRL_RESP_FILTER;
}
+ if (sda_ssi) {
+ /* Service Info length + Service Info */
+ sda_len += 1 + wpabuf_len(ssi);
+ ctrl |= NAN_SRV_CTRL_SRV_INFO;
+ }
+
if ((srv->type == NAN_DE_SUBSCRIBE || srv->type == NAN_DE_PUBLISH) &&
srv->close_proximity)
ctrl |= NAN_SRV_CTRL_DISCOVERY_RANGE_LIMITED;
@@ -833,19 +851,23 @@ static size_t nan_de_sdf_attrs_put(struct wpabuf *buf, struct nan_de *de,
/* Service Descriptor Extension attribute */
sdea_len = 1 + 2;
- if (ssi)
+ if (sdea_ssi)
sdea_len += 2 + 4 + wpabuf_len(ssi);
if (srv->type == NAN_DE_PUBLISH) {
if (srv->publish.fsd)
sdea_ctrl |= NAN_SDEA_CTRL_FSD_REQ;
if (srv->publish.fsd_gas)
sdea_ctrl |= NAN_SDEA_CTRL_FSD_GAS;
+ if (srv->gtk_required)
+ sdea_ctrl |= NAN_SDEA_CTRL_GTK_REQ;
if (srv->data_path || srv->pbm || srv->publish.extended_pbm)
sdea_ctrl |= NAN_SDEA_CTRL_DATA_PATH_REQ;
if (srv->publish.dp_type)
sdea_ctrl |= NAN_SDEA_CTRL_DATA_PATH_TYPE;
if (srv->publish.security_required || srv->pbm ||
- srv->publish.extended_pbm)
+ srv->publish.extended_pbm ||
+ (srv->data_path && srv->cipher_suites_list &&
+ srv->security_required))
sdea_ctrl |= NAN_SDEA_CTRL_SECURITY_REQ;
}
@@ -859,7 +881,7 @@ static size_t nan_de_sdf_attrs_put(struct wpabuf *buf, struct nan_de *de,
srv->subscribe.extended_pbm)
sdea_ctrl |= NAN_SDEA_CTRL_SECURITY_REQ;
}
- if (ssi || sdea_ctrl)
+ if (sdea_ssi || sdea_ctrl)
len += NAN_ATTR_HDR_LEN + sdea_len;
/* Element Container attribute */
@@ -940,26 +962,20 @@ static size_t nan_de_sdf_attrs_put(struct wpabuf *buf, struct nan_de *de,
wpabuf_put_buf(buf, srv->srf);
}
- /* Service Descriptor Extension attribute */
- if (srv->type == NAN_DE_PUBLISH) {
- if (srv->gtk_required)
- sdea_ctrl |= NAN_SDEA_CTRL_GTK_REQ;
- if (srv->data_path) {
- sdea_ctrl |= NAN_SDEA_CTRL_DATA_PATH_REQ;
- if (srv->cipher_suites_list &&
- srv->security_required)
- sdea_ctrl |= NAN_SDEA_CTRL_SECURITY_REQ;
- }
+ if (ctrl & NAN_SRV_CTRL_SRV_INFO) {
+ wpabuf_put_u8(buf, wpabuf_len(ssi));
+ wpabuf_put_buf(buf, ssi);
}
- if (sdea_ctrl || ssi) {
+ /* Service Descriptor Extension attribute */
+ if (sdea_ctrl || sdea_ssi) {
wpabuf_put_u8(buf, NAN_ATTR_SDEA);
wpabuf_put_le16(buf, sdea_len);
/* Instance ID */
wpabuf_put_u8(buf, srv->publish.orig_id ?
srv->publish.orig_id : srv->id);
wpabuf_put_le16(buf, sdea_ctrl);
- if (ssi) {
+ if (sdea_ssi) {
wpabuf_put_le16(buf, 4 + wpabuf_len(ssi));
wpabuf_put_be24(buf, OUI_WFA);
wpabuf_put_u8(buf, srv->srv_proto_type);
@@ -3824,6 +3840,7 @@ int nan_de_publish(struct nan_de *de, const char *service_name,
srv->sync = params->sync;
srv->discover_sync = params->discover_sync;
+ srv->ssi_in_sdea = params->ssi_in_sdea;
if (addr && params->forced_addr) {
os_memcpy(srv->forced_addr, addr, ETH_ALEN);
@@ -4142,6 +4159,7 @@ int nan_de_subscribe(struct nan_de *de, const char *service_name,
srv->is_pr = params->proximity_ranging && params->active;
srv->sync = params->sync;
srv->discover_sync = params->discover_sync;
+ srv->ssi_in_sdea = params->ssi_in_sdea;
srv->close_proximity = params->close_proximity;
srv->pbm = params->pbm;
srv->gtk_required = params->gtk_required;
diff --git a/src/common/nan_de.h b/src/common/nan_de.h
index f8143a105..3b42aed3e 100644
--- a/src/common/nan_de.h
+++ b/src/common/nan_de.h
@@ -245,6 +245,12 @@ struct nan_publish_params {
bool data_path;
bool security_required;
+
+ /*
+ * Carry SSI in the SDEA Service Info field (with WFA OUI and Service
+ * Protocol Type) even when it fits in the SDA Service Info field.
+ */
+ bool ssi_in_sdea;
};
/* Returns -1 on failure or >0 publish_id */
@@ -353,6 +359,12 @@ struct nan_subscribe_params {
* and received for the service
*/
bool gtk_required;
+
+ /*
+ * Carry SSI in the SDEA Service Info field (with WFA OUI and Service
+ * Protocol Type) even when it fits in the SDA Service Info field.
+ */
+ bool ssi_in_sdea;
};
/* Returns -1 on failure or >0 subscribe_id */
diff --git a/tests/hwsim/test_nan.py b/tests/hwsim/test_nan.py
index 9c8a3b333..61b19102f 100644
--- a/tests/hwsim/test_nan.py
+++ b/tests/hwsim/test_nan.py
@@ -135,7 +135,8 @@ class NanDevice:
close_proximity=0, pbm=0, nd_pmk=None, cipher_suites=None,
ttl=None, data_path=False, pairing_setup_info=None,
randomized_service_id=0, orig_nmi=None, instance_id=None,
- dp_type=None, security_required=0, extended_pbm=0):
+ dp_type=None, security_required=0, extended_pbm=0,
+ ssi_in_sdea=0):
cmd = f"NAN_PUBLISH service_name={service_name} sync={sync} srv_proto_type=2 fsd=0"
@@ -190,6 +191,9 @@ class NanDevice:
if extended_pbm:
cmd += f" extended_pbm={extended_pbm}"
+ if ssi_in_sdea:
+ cmd += " ssi_in_sdea=1"
+
return self.wpas.request(cmd)
def schedule_config(self, *chans, map_id=1):
@@ -266,7 +270,7 @@ class NanDevice:
srf_bf_idx=0, close_proximity=0, pbm=0,
pairing_setup_info=None, randomized_service_id=0,
dp_required=0, dp_type=None, security_required=0,
- cipher_suites=None, extended_pbm=0):
+ cipher_suites=None, extended_pbm=0, ssi_in_sdea=0):
cmd = f"NAN_SUBSCRIBE service_name={service_name} sync={sync} srv_proto_type=2"
@@ -318,6 +322,9 @@ class NanDevice:
if extended_pbm:
cmd += f" extended_pbm={extended_pbm}"
+ if ssi_in_sdea:
+ cmd += " ssi_in_sdea=1"
+
return self.wpas.request(cmd)
def bootstrap(self, peer, handle, peer_instance_id, pbm, auth=False):
@@ -410,10 +417,14 @@ def _check_discovery_result_field(ev, field, expected):
if data[field] != expected:
raise Exception(f"Field '{field}': expected '{expected}', got '{data[field]}' in: {ev}")
-def nan_sync_verify_event(ev, addr, pid, sid, ssi, data_path=None):
+def nan_sync_verify_event(ev, addr, pid, sid, ssi, data_path=None,
+ srv_proto_type=None):
data = split_nan_event(ev)
- if data['srv_proto_type'] != '2':
+ if srv_proto_type is None:
+ srv_proto_type = '2' if ssi and len(ssi) > 255 * 2 else '0'
+
+ if data['srv_proto_type'] != srv_proto_type:
raise Exception("Unexpected srv_proto_type: " + ev)
if data['ssi'] != ssi:
@@ -483,23 +494,27 @@ def nan_check_same_cluster(*nan_devs, timeout=1):
def nan_sync_discovery(pub, sub, service_name, pssi, sssi,
unsolicited=1, solicited=1, active=1,
expect_discovery=True,
- timeout=2, cipher_suites=None):
+ timeout=2, cipher_suites=None, ssi_in_sdea=0):
nan_check_same_cluster(pub, sub)
paddr = pub.wpas.own_addr()
saddr = sub.wpas.own_addr()
pid = pub.publish(service_name, ssi=pssi, unsolicited=unsolicited,
- solicited=solicited, cipher_suites=cipher_suites)
- sid = sub.subscribe(service_name, ssi=sssi, active=active)
+ solicited=solicited, cipher_suites=cipher_suites,
+ ssi_in_sdea=ssi_in_sdea)
+ sid = sub.subscribe(service_name, ssi=sssi, active=active,
+ ssi_in_sdea=ssi_in_sdea)
logger.info(f"Publish ID: {pid}, Subscribe ID: {sid}")
+ srv_proto_type = '2' if ssi_in_sdea else None
ev = sub.wpas.wait_event(["NAN-DISCOVERY-RESULT"], timeout=timeout)
if expect_discovery:
if ev is None:
raise Exception("NAN-DISCOVERY-RESULT event not seen")
- nan_sync_verify_event(ev, paddr, pid, sid, pssi)
+ nan_sync_verify_event(ev, paddr, pid, sid, pssi,
+ srv_proto_type=srv_proto_type)
else:
if ev is not None:
raise Exception("Unexpected NAN-DISCOVERY-RESULT event")
@@ -508,13 +523,49 @@ def nan_sync_discovery(pub, sub, service_name, pssi, sssi,
if active and solicited:
if ev is None:
raise Exception("NAN-REPLIED event not seen")
- nan_sync_verify_event(ev, saddr, pid, sid, sssi)
+ nan_sync_verify_event(ev, saddr, pid, sid, sssi,
+ srv_proto_type=srv_proto_type)
else:
if ev is not None:
raise Exception("Unexpected NAN-REPLIED event")
return pid, sid, paddr, saddr
+def test_nan_sync_ssi_placement(dev, apdev, params):
+ """NAN synchronized discovery SSI placement in SDA vs SDEA"""
+ long_ssi = "ab" * 256
+ with hwsim_nan_radios(count=2) as [wpas1, wpas2], \
+ NanDevice(wpas1, "nan0") as pub, NanDevice(wpas2, "nan1") as sub:
+ nan_sync_discovery(pub, sub, "test_sda",
+ pssi="aabbccdd", sssi="ddbbccaa",
+ unsolicited=0)
+ nan_sync_discovery(pub, sub, "test_sdea_opt",
+ pssi="11223344", sssi="44332211",
+ unsolicited=0, ssi_in_sdea=1)
+ nan_sync_discovery(pub, sub, "test_sdea_long",
+ pssi=long_ssi, sssi="55667788",
+ unsolicited=0)
+
+ capfile = os.path.join(params['logdir'], "hwsim0.pcapng")
+ sda = run_tshark(capfile, "wifi_nan.sda.service_info",
+ ["wifi_nan.sda.service_info"])
+ sda = sda.replace(':', '').replace('-', '').split()
+ sdea = run_tshark(capfile, "wifi_nan.sdea.service_info_specific",
+ ["wifi_nan.sdea.service_info_specific"])
+ sdea = sdea.replace(':', '').replace('-', '').split()
+
+ for ssi in ["aabbccdd", "ddbbccaa", "55667788"]:
+ if ssi not in sda:
+ raise Exception("SSI %s not seen in SDA Service Info" % ssi)
+ if ssi in sdea:
+ raise Exception("SSI %s unexpectedly seen in SDEA Service Info" % ssi)
+
+ for ssi in ["11223344", "44332211", long_ssi]:
+ if ssi not in sdea:
+ raise Exception("SSI %s not seen in SDEA Service Info" % ssi)
+ if ssi in sda:
+ raise Exception("SSI %s unexpectedly seen in SDA Service Info" % ssi)
+
def test_nan_sync_active_subscribe(dev, apdev, params):
"""NAN synchronized active subscribe and solicited publish"""
with hwsim_nan_radios(count=2) as [wpas1, wpas2], \
diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index a39f30895..3e2da1547 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -13275,6 +13275,11 @@ static int wpas_ctrl_nan_publish(struct wpa_supplicant *wpa_s, char *cmd,
continue;
}
+ if (os_strcmp(token, "ssi_in_sdea=1") == 0) {
+ params.ssi_in_sdea = true;
+ continue;
+ }
+
if (os_strncmp(token, "match_filter_tx=", 16) == 0) {
params.match_filter_tx = token + 16;
continue;
@@ -13595,6 +13600,11 @@ static int wpas_ctrl_nan_subscribe(struct wpa_supplicant *wpa_s, char *cmd,
continue;
}
+ if (os_strcmp(token, "ssi_in_sdea=1") == 0) {
+ params.ssi_in_sdea = true;
+ continue;
+ }
+
if (os_strncmp(token, "match_filter_tx=", 16) == 0) {
params.match_filter_tx = token + 16;
continue;
--
2.56.0.679.gc527c65306-goog
More information about the Hostap
mailing list