[RFC v2 19/99] NAN: Add Tx status notification to NDL

Andrei Otcheretianski andrei.otcheretianski at intel.com
Tue Dec 23 03:51:23 PST 2025


From: Ilan Peer <ilan.peer at intel.com>

Add a notification to the NDL state machine to indicate
successful transmission of a NAF. The notification is used
by the state machine to trigger appropriate operations such
as setting the state and updating schedule as needed.

Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
 src/nan/nan_i.h   |  2 ++
 src/nan/nan_ndl.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+)

diff --git a/src/nan/nan_i.h b/src/nan/nan_i.h
index 0a5d64c8f9..a01d318fe7 100644
--- a/src/nan/nan_i.h
+++ b/src/nan/nan_i.h
@@ -412,4 +412,6 @@ int nan_ndl_add_qos_attr(struct nan_data *nan,
 			 struct wpabuf *buf);
 int nan_chan_to_chan_idx_map(struct nan_data *nan,
 			     u8 op_class, u8 channel, u16 *chan_idx_map);
+int nan_ndl_naf_sent(struct nan_data *nan, struct nan_peer *peer,
+		     enum nan_subtype subtype);
 #endif
diff --git a/src/nan/nan_ndl.c b/src/nan/nan_ndl.c
index d398f9e97a..e3cb8f0ed3 100644
--- a/src/nan/nan_ndl.c
+++ b/src/nan/nan_ndl.c
@@ -1059,3 +1059,93 @@ int nan_ndl_add_qos_attr(struct nan_data *nan,
 
 	return 0;
 }
+
+
+/*
+ * nan_ndl_naf_sent - Indicate a NAF has been sent
+ *
+ * @nan: NAN module context from nan_init()
+ * @peer: the peer with whom the NDL is being setup
+ * @subtype: the NAN OUI subtype. See &enum nan_oui_subtype
+ *
+ * Notification, indicating to the NDL SM that a NAF was sent, so the
+ * NDL SM could update its state.
+ *
+ * In case that the NDL setup negotiation is successfully done, the final
+ * schedule is applied and the NDL is active. If the negotiation is done
+ * and failed, the NDL state is reset.
+ */
+int nan_ndl_naf_sent(struct nan_data *nan, struct nan_peer *peer,
+		     enum nan_subtype subtype)
+{
+	struct nan_ndl *ndl;
+
+	if (!peer || !peer->ndl)
+		return -1;
+
+	ndl = peer->ndl;
+
+	if (ndl->state == NAN_NDL_STATE_DONE)
+		return 0;
+
+	wpa_printf(MSG_DEBUG,
+		   "NAN: NDL: Tx done with peer=" MACSTR " state=%s, status=%u",
+		   MAC2STR(peer->nmi_addr), nan_ndl_state_str(ndl->state),
+		   ndl->status);
+
+	/* Note: due to races between the Tx status and Rx path, it is possible
+	 * that the Tx status is received after the peer response was already
+	 * processed (which can result with another frame being sent). In such a
+	 * case the logic above fast-forwards the state, and the transitions
+	 * here need to take this into consideration.
+	 */
+	switch (ndl->state) {
+	case NAN_NDL_STATE_START:
+		if (subtype != NAN_SUBTYPE_DATA_PATH_REQUEST)
+			return 0;
+		if (ndl->status != NAN_NDL_STATUS_CONTINUED) {
+			wpa_printf(MSG_DEBUG,
+				   "NAN: NDL: Tx sent: invalid continue status");
+			return -1;
+		}
+		nan_ndl_set_state(nan, ndl, NAN_NDL_STATE_REQ_SENT);
+		return 0;
+	case NAN_NDL_STATE_REQ_RECV:
+		if (subtype != NAN_SUBTYPE_DATA_PATH_RESPONSE)
+			return 0;
+		if (ndl->status == NAN_NDL_STATUS_CONTINUED) {
+			nan_ndl_set_state(nan, ndl, NAN_NDL_STATE_RES_SENT);
+			return 0;
+		}
+		break;
+	case NAN_NDL_STATE_RES_RECV:
+		if (subtype != NAN_SUBTYPE_DATA_PATH_CONFIRM)
+			return 0;
+		if (ndl->status == NAN_NDL_STATUS_CONTINUED) {
+			wpa_printf(MSG_DEBUG,
+				   "NAN: NDL: Tx sent: invalid continue status");
+			return -1;
+		}
+		break;
+	case NAN_NDL_STATE_CON_RECV:
+	case NAN_NDL_STATE_REQ_SENT:
+	case NAN_NDL_STATE_RES_SENT:
+	case NAN_NDL_STATE_CON_SENT:
+	case NAN_NDL_STATE_DONE:
+	default:
+		wpa_printf(MSG_DEBUG,
+			   "NAN: NDL: Tx sent: unexpected state");
+		return 0;
+	}
+
+	if (ndl->status == NAN_NDL_STATUS_ACCEPTED) {
+		wpa_printf(MSG_DEBUG, "NAN: NDL: schedule setup success");
+		nan_ndl_set_state(nan, ndl, NAN_NDL_STATE_DONE);
+		return 0;
+	}
+
+	/* NDL is rejected and NAF already sent. Higher layer is expected to
+	 * handle it.
+	 */
+	return 0;
+}
-- 
2.49.0




More information about the Hostap mailing list