[PATCH 42/97] NAN: Add peer's GTK ID to NDP disconnected callback

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


From: Avraham Stern <avraham.stern at intel.com>

Pass the peer's GTK ID in the NDP disconnected event data so the GTK
can be removed from the NDI.

Signed-off-by: Avraham Stern <avraham.stern at intel.com>
---
 src/nan/nan.c                   | 9 +++++----
 src/nan/nan.h                   | 3 ++-
 src/nan/nan_i.h                 | 4 +++-
 src/nan/nan_module_tests.c      | 4 +++-
 src/nan/nan_ndp.c               | 2 +-
 wpa_supplicant/nan_supplicant.c | 2 +-
 6 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/nan/nan.c b/src/nan/nan.c
index f7752f9d84..51ea72e20f 100644
--- a/src/nan/nan.c
+++ b/src/nan/nan.c
@@ -1657,7 +1657,8 @@ static int nan_ndp_connected(struct nan_data *nan, struct nan_peer *peer)
 	if (peer->ndp_setup.sec.local_gtk.csid != NAN_CS_NONE)
 		params.local_gtk = &peer->ndp_setup.sec.local_gtk;
 
-	if (peer->ndp_setup.sec.peer_gtk.csid != NAN_CS_NONE) {
+	peer->ndp_setup.ndp->gtk_id = peer->ndp_setup.sec.peer_gtk.id;
+	if (peer->ndp_setup.sec.peer_gtk.id) {
 		params.peer_gtk = &peer->ndp_setup.sec.peer_gtk;
 		params.peer_gtk_rsc = peer->ndp_setup.sec.peer_gtk_rsc;
 	}
@@ -1722,7 +1723,7 @@ static void nan_ndp_disconnected(struct nan_data *nan, struct nan_peer *peer,
 		nan->cfg->ndp_disconnected(nan->cfg->cb_ctx, &ndp_id,
 					   local_ndi, peer_ndi, reason,
 					   locally_generated, remove_sta,
-					   fail);
+					   fail, peer->ndp_setup.ndp->gtk_id);
 
 	nan_ndp_setup_stop(nan, peer);
 }
@@ -2293,7 +2294,7 @@ int nan_handle_ndp_setup(struct nan_data *nan, struct nan_ndp_params *params)
 
 void nan_ndp_terminated(struct nan_data *nan, struct nan_peer *peer,
 			struct nan_ndp_id *ndp_id, const u8 *local_ndi,
-			const u8 *peer_ndi, enum nan_reason reason)
+			const u8 *peer_ndi, enum nan_reason reason, u8 gtk_id)
 {
 	/*
 	 * Remove the NDI station only if no other NDP is using the same
@@ -2305,7 +2306,7 @@ void nan_ndp_terminated(struct nan_data *nan, struct nan_peer *peer,
 	if (nan->cfg->ndp_disconnected)
 		nan->cfg->ndp_disconnected(nan->cfg->cb_ctx, ndp_id, local_ndi,
 					   peer_ndi, reason, false,
-					   remove_sta, false);
+					   remove_sta, false, gtk_id);
 
 	/* Need to also remove the NDL if it is not needed */
 	if (dl_list_empty(&peer->ndps) && !peer->ndp_setup.ndp)
diff --git a/src/nan/nan.h b/src/nan/nan.h
index 37af4262c2..cf7db9b3b7 100644
--- a/src/nan/nan.h
+++ b/src/nan/nan.h
@@ -530,6 +530,7 @@ struct nan_config {
 	 *     using the same peer NDI)
 	 * @failure: true if NDP setup failed (before connected), false if
 	 *     graceful disconnection after NDP was established
+	 * @gtk_id: GTK key ID used for the NDP; 0 if no GTK should be removed
 	 *
 	 * This callback notifies that an NDP has been disconnected. When
 	 * @failure is true, NDP setup failed before connection was established.
@@ -540,7 +541,7 @@ struct nan_config {
 				 const u8 *local_ndi, const u8 *peer_ndi,
 				 enum nan_reason reason,
 				 bool locally_generated, bool remove_sta,
-				 bool failure);
+				 bool failure, u8 gtk_id);
 
 	/**
 	 * get_chans - Get the prioritized allowed channel information to be
diff --git a/src/nan/nan_i.h b/src/nan/nan_i.h
index 772971ba84..592268aa4a 100644
--- a/src/nan/nan_i.h
+++ b/src/nan/nan_i.h
@@ -144,6 +144,7 @@ enum nan_ndp_state {
  * @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
+ * @gtk_id: GTK key ID used for this NDP. 0 if GTK is not used
  */
 struct nan_ndp {
 	/* for nan_peer ndps list */
@@ -155,6 +156,7 @@ struct nan_ndp {
 	u8 resp_ndi[ETH_ALEN];
 
 	struct nan_qos qos;
+	u8 gtk_id;
 };
 
 /*
@@ -766,7 +768,7 @@ struct bitfield * nan_avail_entries_to_bf(struct nan_data *nan,
 					  u8 op_class, u16 cbm, u16 pri_cbm);
 void nan_ndp_terminated(struct nan_data *nan, struct nan_peer *peer,
 			struct nan_ndp_id *ndp_id, const u8 *local_ndi,
-			const u8 *peer_ndi, enum nan_reason reason);
+			const u8 *peer_ndi, enum nan_reason reason, u8 gtk_id);
 int nan_crypto_pmk_to_ptk(const u8 *pmk, const u8 *iaddr, const u8 *raddr,
 			  const u8 *inonce, const u8 *rnonce,
 			  struct nan_ptk *ptk,
diff --git a/src/nan/nan_module_tests.c b/src/nan/nan_module_tests.c
index 43b8a57c45..61d126d46e 100644
--- a/src/nan/nan_module_tests.c
+++ b/src/nan/nan_module_tests.c
@@ -642,6 +642,7 @@ static int nan_test_ndp_connected_cb(void *ctx,
  * @locally_generated: true if locally generated, false if triggered by peer
  * @remove_sta: true if the NDI station should be removed
  * @failure: true if NDP setup failed, false if graceful disconnection
+ * @gtk_id: GTK key ID used for the NDP; 0 if no GTK was used
  *
  * The handling of the event is done asynchronously through the NAN test actions
  * processing.
@@ -652,7 +653,8 @@ static void nan_test_ndp_disconnected_cb(void *ctx, struct nan_ndp_id *ndp_id,
 					 enum nan_reason reason,
 					 bool locally_generated,
 					 bool remove_sta,
-					 bool failure)
+					 bool failure,
+					 u8 gtk_id)
 {
 	struct nan_device *dev = ctx;
 
diff --git a/src/nan/nan_ndp.c b/src/nan/nan_ndp.c
index e6f790b7c6..354541dd77 100644
--- a/src/nan/nan_ndp.c
+++ b/src/nan/nan_ndp.c
@@ -768,7 +768,7 @@ static int nan_ndp_attr_handle_term(struct nan_data *nan, struct nan_peer *peer,
 	dl_list_del(&pndp->list);
 
 	nan_ndp_terminated(nan, peer, &ndp_id, local_ndi, peer_ndi,
-			   ndp_attr->reason_code);
+			   ndp_attr->reason_code, pndp->gtk_id);
 
 	os_free(pndp);
 
diff --git a/wpa_supplicant/nan_supplicant.c b/wpa_supplicant/nan_supplicant.c
index 94a6aa1f0d..daaf19f78d 100644
--- a/wpa_supplicant/nan_supplicant.c
+++ b/wpa_supplicant/nan_supplicant.c
@@ -638,7 +638,7 @@ static void wpas_nan_ndp_disconnected_cb(void *ctx, struct nan_ndp_id *ndp_id,
 					 enum nan_reason reason,
 					 bool locally_generated,
 					 bool remove_sta,
-					 bool failure)
+					 bool failure, u8 gtk_id)
 {
 	struct wpa_supplicant *wpa_s = ctx;
 
-- 
2.53.0




More information about the Hostap mailing list