[PATCH 2/3] NAN: Add pairing parameters to discovery result notifications
Junyu Lai
junyulai at google.com
Mon Oct 12 23:08:16 PDT 2026
Upper-layer notification consumers need the peer's NAN pairing
configuration (pairing_setup, npk_caching, pairing_verification),
supported bootstrap methods, and NAN Identity Resolution Attribute
(NIRA) nonce and tag when a service is discovered. Additionally, during
Unsynchronized Service Discovery (USD) on non-NAN interfaces (such as
p2p0 for Wi-Fi Direct R2), wpa_s->nan is NULL, so discovery result
processing must fall back to default pairing values instead of aborting.
Query nan_peer_get_pairing_cfg() and
nan_bootstrap_get_supported_methods() in wpas_nan_de_discovery_result()
when wpa_s->nan is non-NULL, and pass the pairing flags, bootstrap
methods, and NIRA nonce and tag to wpas_notify_nan_discovery_result().
This is safe because all pairing parameters are initialized to
false/0/NULL before checking wpa_s->nan != NULL, preserving discovery
notifications when wpa_s->nan is NULL or when the peer does not
advertise pairing attributes.
Signed-off-by: Junyu Lai <junyulai at google.com>
---
wpa_supplicant/nan_supplicant.c | 39 ++++++++++++++++++++++++++++++++-
wpa_supplicant/notify.c | 8 ++++++-
wpa_supplicant/notify.h | 8 ++++++-
3 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/wpa_supplicant/nan_supplicant.c b/wpa_supplicant/nan_supplicant.c
index 6975553b9..fae80fb21 100644
--- a/wpa_supplicant/nan_supplicant.c
+++ b/wpa_supplicant/nan_supplicant.c
@@ -4787,6 +4787,12 @@ static void
wpas_nan_de_discovery_result(void *ctx, struct nan_discovery_result *res)
{
struct wpa_supplicant *wpa_s = ctx;
+ const u8 *nonce = NULL;
+ const u8 *tag = NULL;
+ u16 bootstrap_methods = 0;
+ bool pairing_setup = false;
+ bool npk_caching = false;
+ bool pairing_verification = false;
#ifdef CONFIG_NAN
if (wpa_s->nan && !nan_get_peer(wpa_s->nan, res->peer_addr)) {
@@ -4802,9 +4808,40 @@ wpas_nan_de_discovery_result(void *ctx, struct nan_discovery_result *res)
"NAN: No raw buffer to add peer");
}
}
+
+ if (wpa_s->nan != NULL) {
+ const struct nan_pairing_cfg *pairing_cfg;
+
+ pairing_cfg = nan_peer_get_pairing_cfg(wpa_s->nan,
+ res->peer_addr,
+ &nonce, &tag);
+ if (!pairing_cfg) {
+ wpa_printf(MSG_DEBUG,
+ "NAN: Pairing config not available for peer "
+ MACSTR, MAC2STR(res->peer_addr));
+ } else {
+ pairing_setup = pairing_cfg->pairing_setup;
+ npk_caching = pairing_cfg->npk_caching;
+ pairing_verification =
+ pairing_cfg->pairing_verification;
+ }
+
+ if (nan_bootstrap_get_supported_methods(
+ wpa_s->nan, res->peer_addr,
+ &bootstrap_methods) < 0) {
+ wpa_printf(MSG_DEBUG,
+ "NAN: Failed to get bootstrap methods for peer "
+ MACSTR, MAC2STR(res->peer_addr));
+ }
+ }
#endif /* CONFIG_NAN */
- wpas_notify_nan_discovery_result(wpa_s, res);
+ wpas_notify_nan_discovery_result(wpa_s, res,
+ pairing_setup,
+ npk_caching,
+ pairing_verification,
+ bootstrap_methods,
+ nonce, tag);
}
diff --git a/wpa_supplicant/notify.c b/wpa_supplicant/notify.c
index 18cd63113..9c638ddbc 100644
--- a/wpa_supplicant/notify.c
+++ b/wpa_supplicant/notify.c
@@ -1101,7 +1101,13 @@ void wpas_notify_hs20_t_c_acceptance(struct wpa_supplicant *wpa_s,
#if defined(CONFIG_NAN) || defined(CONFIG_NAN_USD)
void wpas_notify_nan_discovery_result(struct wpa_supplicant *wpa_s,
- struct nan_discovery_result *res)
+ struct nan_discovery_result *res,
+ bool pairing_setup,
+ bool pairing_cache,
+ bool pairing_verification,
+ u16 pbm,
+ const u8 *nonce,
+ const u8 *tag)
{
char *ssi_hex, *pmkid_hex = NULL;
char *cipher_suites_str = NULL;
diff --git a/wpa_supplicant/notify.h b/wpa_supplicant/notify.h
index e3a8dc013..15c9ca56c 100644
--- a/wpa_supplicant/notify.h
+++ b/wpa_supplicant/notify.h
@@ -187,7 +187,13 @@ void wpas_notify_signal_change(struct wpa_supplicant *wpa_s);
void wpas_notify_hs20_t_c_acceptance(struct wpa_supplicant *wpa_s,
const char *url);
void wpas_notify_nan_discovery_result(struct wpa_supplicant *wpa_s,
- struct nan_discovery_result *res);
+ struct nan_discovery_result *res,
+ bool pairing_setup,
+ bool pairing_cache,
+ bool pairing_verification,
+ u16 pbm,
+ const u8 *nonce,
+ const u8 *tag);
void wpas_notify_nan_replied(struct wpa_supplicant *wpa_s,
enum nan_service_protocol_type srv_proto_type,
int publish_id, int peer_subscribe_id,
--
2.56.0.385.gd3acb90ef8-goog
More information about the Hostap
mailing list