[PATCH 13/97] NAN: Send NDP termination on timeout

Andrei Otcheretianski andrei.otcheretianski at intel.com
Tue Apr 28 13:05:14 PDT 2026


It is possible (for example, in case of open connection with NDL
counter proposal) that the responder side hits timeout when the
initiator doesn't respond to the counter proposal on time.
This may result in a connection state mismatch between the peers.
Send NDP termination frame on timeout to prevent it.

Signed-off-by: Andrei Otcheretianski <andrei.otcheretianski at intel.com>
---
 src/nan/nan.c | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/src/nan/nan.c b/src/nan/nan.c
index 102c4a42cc..792ef5fa20 100644
--- a/src/nan/nan.c
+++ b/src/nan/nan.c
@@ -1368,6 +1368,8 @@ bool nan_process_followup(struct nan_data *nan, const u8 *addr, const u8 *buf,
 }
 
 
+static void nan_set_peer_timeout(struct nan_data *nan, struct nan_peer *peer,
+				 unsigned int sec, unsigned int usec);
 static void nan_peer_state_timeout(void *eloop_ctx, void *timeout_ctx)
 {
 	struct nan_data *nan = eloop_ctx;
@@ -1379,7 +1381,42 @@ static void nan_peer_state_timeout(void *eloop_ctx, void *timeout_ctx)
 	if (!peer->ndp_setup.ndp)
 		return;
 
-	nan_ndp_disconnected(nan, peer, NAN_REASON_UNSPECIFIED_REASON, true);
+	/* If we already sent termination just disconnect */
+	if (peer->ndp_setup.state == NAN_NDP_STATE_DONE &&
+	    peer->ndp_setup.status == NAN_NDP_STATUS_REJECTED) {
+		wpa_printf(MSG_DEBUG,
+			   "NAN: Timeout (NDP setup is done), disconnecting");
+		nan_ndp_disconnected(nan, peer, NAN_REASON_UNSPECIFIED_REASON,
+				     true);
+		return;
+	}
+
+	/*
+	 * Send NDP Termination to notify the peer about the timeout.
+	 * Prepare the state for building a termination frame.
+	 */
+	wpa_printf(MSG_DEBUG,
+		   "NAN: NDP: state: %u --> %u (timeout termination)",
+		   peer->ndp_setup.state, NAN_NDP_STATE_DONE);
+
+	peer->ndp_setup.state = NAN_NDP_STATE_DONE;
+	peer->ndp_setup.status = NAN_NDP_STATUS_REJECTED;
+	peer->ndp_setup.reason = NAN_REASON_UNSPECIFIED_REASON;
+
+	if (nan_action_send(nan, peer, NAN_SUBTYPE_DATA_PATH_TERMINATION)) {
+		wpa_printf(MSG_DEBUG,
+			   "NAN: Failed to send termination on timeout");
+		nan_ndp_disconnected(nan, peer, NAN_REASON_UNSPECIFIED_REASON,
+				     true);
+		return;
+	}
+
+	/*
+	 * Termination frame sent successfully. Set a short timeout to wait
+	 * for TX status. The TX status handler (nan_tx_status) will call
+	 * nan_ndp_disconnected().
+	 */
+	nan_set_peer_timeout(nan, peer, NAN_NDP_SETUP_TIMEOUT_SHORT, 0);
 }
 
 
-- 
2.53.0




More information about the Hostap mailing list