[PATCH 2/2] NAN: Map NDI addressed NAFs to the peer via the ND-TKSA
Andrei Otcheretianski
andrei.otcheretianski at intel.com
Tue Nov 24 07:13:09 PST 2026
When a NAF is received from a peer NDI, the source address is mapped
to the peer NMI only by looking up the NDI in peer->ndps. However, an
NDP being terminated is moved out of this list to peer->ndp_setup until
the termination completes. A NAF from the peer NDI received in this
window, was wrongly attributed to a "new" peer.
Per Wi-Fi Aware Specification v4.0, section 7.3.2, NAFs may be sent
using the NDI addresses only if an ND-TKSA exists for these addresses,
and in such a case they are protected with the ND-TK. Thus, map the
source address only for protected frames and match both the source and
destination addresses against the NDI pairs of the peer security
associations, as is done when selecting the addresses on transmission.
Fixes: 0972015d244f ("NAN: Support transmission and reception of NAFs in a secure manner")
Signed-off-by: Andrei Otcheretianski <andrei.otcheretianski at intel.com>
---
src/nan/nan.c | 32 ++++++++++++++------------------
src/nan/nan_module_tests.c | 7 +++++--
2 files changed, 19 insertions(+), 20 deletions(-)
diff --git a/src/nan/nan.c b/src/nan/nan.c
index 05ae78c3bf..60fcd38bb4 100644
--- a/src/nan/nan.c
+++ b/src/nan/nan.c
@@ -2665,9 +2665,12 @@ static int nan_action_rx_ndp(struct nan_data *nan, struct nan_peer *peer,
* @len: Length of the management frame in octets
*
* NAFs can be sent and received on NDIs. In such cases, the source address
- * in the 802.11 header would be the NDI address. This function checks if
- * the source address matches any known NDI address and if so, substitutes
- * it with the NMI address of the corresponding peer.
+ * in the 802.11 header would be the NDI address. Per Wi-Fi Aware
+ * Specification v4.0, section 7.3.2, this is allowed only for an NDI pair with
+ * an ND-TKSA and such frames are protected with the ND-TK. Thus, if the frame
+ * is protected and its source and destination addresses match the NDI pair of
+ * a security association with a peer, substitute the source address with the
+ * NMI address of that peer.
*/
static const u8 * nan_action_substitute_src(struct nan_data *nan,
const struct ieee80211_mgmt *mgmt,
@@ -2680,27 +2683,20 @@ static const u8 * nan_action_substitute_src(struct nan_data *nan,
if (peer)
return mgmt->sa;
- /*
- * Find a peer with which we have an NDI that matches the source address
- * in the frame, and if found, substitute the frames source address with
- * the peer NMI
- */
+ if (!(le_to_host16(mgmt->frame_control) & WLAN_FC_PROTECTED))
+ return mgmt->sa;
+
dl_list_for_each(peer, &nan->peer_list, struct nan_peer, list) {
- struct nan_ndp *pndp;
+ struct nan_peer_sec_info_entry *sec;
/* When a peer is paired, NAFs are not allowed on NDIs */
if (peer->pairing.flags & NAN_PAIRING_FLAG_PAIRED)
continue;
- dl_list_for_each(pndp, &peer->ndps, struct nan_ndp, list) {
- const u8 *addr;
-
- if (pndp->initiator)
- addr = pndp->resp_ndi;
- else
- addr = pndp->init_ndi;
-
- if (!ether_addr_equal(addr, mgmt->sa))
+ dl_list_for_each(sec, &peer->info.sec,
+ struct nan_peer_sec_info_entry, list) {
+ if (!ether_addr_equal(sec->peer_ndi, mgmt->sa) ||
+ !ether_addr_equal(sec->local_ndi, mgmt->da))
continue;
wpa_printf(MSG_DEBUG,
diff --git a/src/nan/nan_module_tests.c b/src/nan/nan_module_tests.c
index dda5746901..a0cc2ac4f4 100644
--- a/src/nan/nan_module_tests.c
+++ b/src/nan/nan_module_tests.c
@@ -772,10 +772,13 @@ static int nan_test_send_naf_cb(void *ctx, const u8 *dst, const u8 *src,
IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION);
os_memcpy(hdr->addr1, dst, ETH_ALEN);
- if (!src)
+ if (!src) {
os_memcpy(hdr->addr2, dev->nmi, ETH_ALEN);
- else
+ } else {
+ /* NAFs sent on NDIs are always protected with the ND-TK */
os_memcpy(hdr->addr2, src, ETH_ALEN);
+ hdr->frame_control |= host_to_le16(WLAN_FC_PROTECTED);
+ }
if (cluster_id)
os_memcpy(hdr->addr3, cluster_id, ETH_ALEN);
--
2.56.1
More information about the Hostap
mailing list