[RFC 08/56] NAN: Introduce NDP data structures
Andrei Otcheretianski
andrei.otcheretianski at intel.com
Sun Dec 7 03:18:17 PST 2025
From: Ilan Peer <ilan.peer at intel.com>
Add NAN NDP data structures to describe the state and data
of an NDP session between the local device and a peer.
All established NDP sessions between the local device and
a peer are managed per peer.
Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
src/nan/nan.c | 34 +++++++++++++++++++-
src/nan/nan.h | 12 +++++++
src/nan/nan_i.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 128 insertions(+), 1 deletion(-)
diff --git a/src/nan/nan.c b/src/nan/nan.c
index 6a7e94714e..7b28df54b8 100644
--- a/src/nan/nan.c
+++ b/src/nan/nan.c
@@ -46,6 +46,26 @@ static void nan_del_peer(struct nan_data *nan, struct nan_peer *peer)
wpa_printf(MSG_DEBUG, "NAN: Removing peer: " MACSTR,
MAC2STR(peer->nmi_addr));
+ if (!dl_list_empty(&peer->ndps)) {
+ struct nan_ndp *ndp, *tndp;
+
+ /* TODO: tear down active NDPs */
+ wpa_printf(MSG_DEBUG,
+ "NAN: Peer delete while there are active ndps");
+
+ dl_list_for_each_safe(ndp, tndp, &peer->ndps,
+ struct nan_ndp, list) {
+ dl_list_del(&ndp->list);
+ os_free(ndp);
+ }
+ }
+
+ if (peer->ndp_setup.ndp) {
+ wpa_printf(MSG_DEBUG,
+ "NAN: Peer delete while ndp setup is WIP");
+ os_free(peer->ndp_setup.ndp);
+ }
+
dl_list_del(&peer->list);
os_free(peer);
}
@@ -159,12 +179,23 @@ static struct nan_peer *nan_alloc_peer(struct nan_data *nan)
dl_list_for_each(peer, &nan->peer_list, struct nan_peer, list) {
count++;
+
+ /* Do not expire peers that we have NDPs with */
+ if (!dl_list_empty(&peer->ndps) || peer->ndp_setup.ndp)
+ continue;
+
if (!oldest ||
os_reltime_before(&peer->last_seen, &oldest->last_seen))
oldest = peer;
}
- if (count >= NAN_MAX_PEERS && oldest) {
+ if (count >= NAN_MAX_PEERS) {
+ if (!oldest) {
+ wpa_printf(MSG_DEBUG,
+ "NAN: Cannot remove any of the peers");
+ return NULL;
+ }
+
wpa_printf(MSG_DEBUG,
"NAN: Remove peer=" MACSTR " to make room",
MAC2STR(oldest->nmi_addr));
@@ -177,6 +208,7 @@ static struct nan_peer *nan_alloc_peer(struct nan_data *nan)
return NULL;
dl_list_add(&nan->peer_list, &peer->list);
+ dl_list_init(&peer->ndps);
return peer;
}
diff --git a/src/nan/nan.h b/src/nan/nan.h
index 7bfb05b583..2f4aa5e078 100644
--- a/src/nan/nan.h
+++ b/src/nan/nan.h
@@ -30,6 +30,18 @@ struct nan_device_capabilities {
u8 capa;
};
+/**
+ * struct nan_qos - NAN QoS requirements
+ *
+ * @min_slots: Minimal number of slots.
+ * @max_latency: Maximum allowed NAN slots between every two non-contiguous
+ * NAN Data Link (NDL) Common Resource Blocks (CRB)
+ */
+struct nan_qos {
+ u8 min_slots;
+ u16 max_latency;
+};
+
struct nan_config {
void *cb_ctx;
diff --git a/src/nan/nan_i.h b/src/nan/nan_i.h
index 1338549925..ae8833c94e 100644
--- a/src/nan/nan_i.h
+++ b/src/nan/nan_i.h
@@ -16,16 +16,99 @@
struct nan_config;
+/*
+ * enum nan_ndp_state - State of NDP establishment
+ * @NAN_NDP_STATE_NONE: No NDP establishment in progress.
+ * @NAN_NDP_STATE_START: Starting NDP establishment.
+ * @NAN_NDP_STATE_REQ_SENT: NDP request was sent.
+ * @NAN_NDP_STATE_REQ_RECV: NDP response was received and processed.
+ * @NAN_NDP_STATE_RES_SENT: NDP response was sent and NDP is not accepted yet.
+ * @NAN_NDP_STATE_RES_RECV: NDP response was received and NDP was not accepted
+ * yet (security is negotiated or confirmation is required).
+ * @NAN_NDP_STATE_CON_SENT: NDP confirm was sent and NDP was not done yet, as
+ * security is negotiated.
+ * @NAN_NDP_STATE_CON_RECV: NDP confirm received and NDP was not done yet, as
+ * security is negotiated.
+ * @NAN_NDP_STATE_DONE: NDP establishment is done (either success or reject).
+ * In this state the NAN module handles actions such as notification to the
+ * encapsulating logic etc. Once processing is done the NDP should either be
+ * cleared (rejected) or moved to the list of NDPs associated with the peer.
+ */
+enum nan_ndp_state {
+ NAN_NDP_STATE_NONE = 0,
+ NAN_NDP_STATE_START,
+ NAN_NDP_STATE_REQ_SENT,
+ NAN_NDP_STATE_REQ_RECV,
+ NAN_NDP_STATE_RES_SENT,
+ NAN_NDP_STATE_RES_RECV,
+ NAN_NDP_STATE_CON_SENT,
+ NAN_NDP_STATE_CON_RECV,
+ NAN_NDP_STATE_DONE,
+};
+
+/*
+ * struct nan_ndp - NDP information.
+ *
+ * Used to maintain the NDP as an object in a peer's list of NDPs.
+ *
+ * @list: Used for linking in the NDPs list.
+ * @peer: Pointer to the peer data structure
+ * @initiator: True iff the local device is the initiator
+ * @ndp_id: NDP Id.
+ * @init_ndi: Initiator NDI
+ * @resp_ndi: Responder NDI. Might not always be set (as this depends on the
+ * state of NDP establishment and the status).
+ * @qos: Qos requirements for this NDP
+ */
+struct nan_ndp {
+ /* for nan_peer ndps list */
+ struct dl_list list;
+ struct nan_peer *peer;
+ bool initiator;
+ u8 ndp_id;
+ u8 init_ndi[ETH_ALEN];
+ u8 resp_ndi[ETH_ALEN];
+
+ struct nan_qos qos;
+};
+
+/*
+ * struct nan_ndp_setup - Holds the state of the NDP setup
+ *
+ * @ndp: NDP information
+ * @state: Current state
+ * @status: Current status
+ * @dialog_token: Setup dialog token
+ * @publisher_inst_id: Publish function instance ID
+ * @conf_req: True iff the NDP exchange requires confirm message.
+ * @reason: Reject reason. Only valid when status is rejected.
+ */
+struct nan_ndp_setup {
+ struct nan_ndp *ndp;
+ enum nan_ndp_state state;
+ enum nan_ndp_status status;
+ u8 dialog_token;
+ u8 publish_inst_id;
+ bool conf_req;
+ enum nan_reason reason;
+};
+
/**
* struct nan_peer - Represents a known NAN peer
* @list: List node for linking peers.
* @nmi_addr: NAN MAC address of the peer.
* @last_seen: Timestamp of the last time this peer was seen.
+ * @ndps: List of NDPs associated with this peer.
+ * @ndp_setup: Used to hold an NDP object while NDP establishment is in
+ * progress.
*/
struct nan_peer {
struct dl_list list;
u8 nmi_addr[ETH_ALEN];
struct os_reltime last_seen;
+ struct dl_list ndps;
+
+ struct nan_ndp_setup ndp_setup;
};
/**
--
2.49.0
More information about the Hostap
mailing list