[PATCH v2 1/3] NAN: Add peer on discovery before notifying discovery result

Otcheretianski, Andrei andrei.otcheretianski at intel.com
Wed Nov 4 08:05:34 PST 2026


> Subject: [PATCH v2 1/3] NAN: Add peer on discovery before notifying
> discovery result
> 
> In wpas_nan_de_rx_sdf(), nan_de_rx_sdf() invokes the discovery_result
> callback (wpas_nan_de_discovery_result()) before nan_add_peer() adds the
> peer to wpa_s->nan. As a result, when wpas_nan_de_discovery_result() runs
> for the first Service Discovery Frame (SDF) from a newly discovered peer, the
> peer entry does not yet exist in wpa_s->nan.

Why should it exist in wpa_s->nan before the notification? No one is accessing it yet.

> 
> - Store the raw SDF attribute buffer (raw_buf and raw_buf_len) in struct
>   nan_discovery_result.
> - Add the peer via nan_add_peer() in wpas_nan_de_discovery_result() if
>   it is not already present in wpa_s->nan.
> 
> Signed-off-by: Junyu Lai <junyulai at google.com>
> ---
> v2:
>   - Rebase onto latest main.
> ---
>  src/common/nan_de.c             |  2 ++
>  src/common/nan_de.h             |  2 ++
>  wpa_supplicant/nan_supplicant.c | 17 +++++++++++++++++
>  3 files changed, 21 insertions(+)
> 
> diff --git a/src/common/nan_de.c b/src/common/nan_de.c index
> f070d82aa..f4f8aa8db 100644
> --- a/src/common/nan_de.c
> +++ b/src/common/nan_de.c
> @@ -2354,6 +2354,8 @@ send_event:
>  	res.pmkid_list = pmkid_count > 0 ? pmkid_list : NULL;
>  	res.pmkid_count = pmkid_count;
>  	res.orig_addr = orig_addr;
> +	res.raw_buf = buf;
> +	res.raw_buf_len = buf_len;
> 
>  	if (de->cb.discovery_result) {
>  		char *locale = NULL, *vendor_name = NULL; diff --git
> a/src/common/nan_de.h b/src/common/nan_de.h index
> 17efd8552..1f8282f03 100644
> --- a/src/common/nan_de.h
> +++ b/src/common/nan_de.h
> @@ -47,6 +47,8 @@ struct nan_discovery_result {
>  	const char *psi_vendor_name;
>  	const char *psi_model_name;
>  	const char *psi_pairing_name;
> +	const u8 *raw_buf;
> +	size_t raw_buf_len;
>  };
> 
>  struct nan_callbacks {
> diff --git a/wpa_supplicant/nan_supplicant.c
> b/wpa_supplicant/nan_supplicant.c index 42d3c4787..60d0c4ae0 100644
> --- a/wpa_supplicant/nan_supplicant.c
> +++ b/wpa_supplicant/nan_supplicant.c
> @@ -18,6 +18,7 @@
>  #include "wpa_supplicant_i.h"
>  #include "driver_i.h"
>  #include "nan/nan.h"
> +#include "nan/nan_i.h"

This is NAN module internal header that shouldn't be included in wpa_supplicant 

>  #include "config.h"
>  #include "offchannel.h"
>  #include "notify.h"
> @@ -4957,6 +4958,22 @@ wpas_nan_de_discovery_result(void *ctx, struct
> nan_discovery_result *res)  {

Why is this specific to discovery result only?

>  	struct wpa_supplicant *wpa_s = ctx;
> 
> +#ifdef CONFIG_NAN
> +	if (wpa_s->nan && !nan_get_peer(wpa_s->nan, res->peer_addr)) {
> +		wpa_printf(MSG_DEBUG,
> +			   "NAN: Peer " MACSTR
> +			   " not in list, adding it on discovery",
> +			   MAC2STR(res->peer_addr));
> +		if (res->raw_buf) {
> +			nan_add_peer(wpa_s->nan, res->peer_addr, NULL, 0,
> +				     res->raw_buf, res->raw_buf_len);
> +		} else {
> +			wpa_printf(MSG_DEBUG,
> +				   "NAN: No raw buffer to add peer");
> +		}
> +	}
> +#endif /* CONFIG_NAN */

NAN peers are managed by NAN module only.
The logic here btw differs from wpas_nan_de_rx_sdf() and it will attempt to add it again (or not).
In any case, I don't see any reason for this patch as upper layers shouldn't care whether NAN peers are created before or after the notification to upper layers and should never call directly back into NAN module callbacks as the processing isn't complete yet.

Andrei
> +
>  	wpas_notify_nan_discovery_result(wpa_s, res);  }
> 
> --
> 2.56.0.385.gac671c819a-goog
> 
> 
> _______________________________________________
> Hostap mailing list
> Hostap at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/hostap


More information about the Hostap mailing list