[RFC 45/56] NAN: Add a callback to allow verifying publish instance ID
Andrei Otcheretianski
andrei.otcheretianski at intel.com
Sun Dec 7 03:18:54 PST 2025
From: Ilan Peer <ilan.peer at intel.com>
Add a callback API that allows the NDP state machine to validate
that a given publish instance ID is indeed valid and to retrieve
the corresponding service ID.
Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
src/common/nan_de.c | 22 ++++++++++++++++++++++
src/common/nan_de.h | 2 ++
src/nan/nan.c | 15 ++++++++++-----
src/nan/nan.h | 9 +++++++++
4 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/src/common/nan_de.c b/src/common/nan_de.c
index eb35723632..32a3fe7ae7 100644
--- a/src/common/nan_de.c
+++ b/src/common/nan_de.c
@@ -2035,3 +2035,25 @@ void nan_de_set_cluster_id(struct nan_de *de, const u8 *cluster_id)
de->cluster_id_set = false;
}
}
+
+
+bool nan_de_is_valid_instance_id(struct nan_de *de, int handle,
+ bool publish, u8 *service_id)
+{
+ struct nan_de_service *srv;
+
+ if (handle < 1 || handle > NAN_DE_MAX_SERVICE)
+ return false;
+
+ srv = de->service[handle - 1];
+ if (!srv)
+ return false;
+
+ if (publish && srv->type != NAN_DE_PUBLISH)
+ return false;
+ if (!publish && srv->type != NAN_DE_SUBSCRIBE)
+ return false;
+
+ os_memcpy(service_id, srv->service_id, NAN_SERVICE_ID_LEN);
+ return true;
+}
diff --git a/src/common/nan_de.h b/src/common/nan_de.h
index 5fb1485c69..2326c3b866 100644
--- a/src/common/nan_de.h
+++ b/src/common/nan_de.h
@@ -209,6 +209,8 @@ int nan_de_transmit(struct nan_de *de, int handle,
const u8 *peer_addr, u8 req_instance_id);
void nan_de_dw_trigger(struct nan_de *de, int freq);
void nan_de_set_cluster_id(struct nan_de *de, const u8 *cluster_id);
+bool nan_de_is_valid_instance_id(struct nan_de *de, int handle,
+ bool publish, u8 *service_id);
int nan_de_stop_listen(struct nan_de *de, int handle);
diff --git a/src/nan/nan.c b/src/nan/nan.c
index a1c65bb855..4e3463a12d 100644
--- a/src/nan/nan.c
+++ b/src/nan/nan.c
@@ -1122,7 +1122,8 @@ static bool nan_ndp_supported(struct nan_data *nan)
{
if (nan->cfg->ndp_action_notif && nan->cfg->ndp_connected &&
nan->cfg->ndp_disconnected &&
- nan->cfg->send_naf && nan->cfg->get_chans)
+ nan->cfg->send_naf && nan->cfg->get_chans &&
+ nan->cfg->is_valid_publish_id)
return true;
wpa_printf(MSG_DEBUG, "NAN: NDP operations are not supported");
@@ -1469,10 +1470,14 @@ done:
bool nan_publish_instance_id_valid(struct nan_data *nan, u8 instance_id,
u8 *service_id)
{
- /* TODO: Need implement this logic */
- wpa_printf(MSG_DEBUG,
- "NAN: TODO: Publish instance ID validation not implemented");
- return true;
+ if (!nan->cfg->is_valid_publish_id) {
+ wpa_printf(MSG_DEBUG,
+ "NAN: is_valid_publish_id callback not defined");
+ return false;
+ }
+
+ return nan->cfg->is_valid_publish_id(nan->cfg->cb_ctx, instance_id,
+ service_id);
}
diff --git a/src/nan/nan.h b/src/nan/nan.h
index ef77acee88..017ded8d1a 100644
--- a/src/nan/nan.h
+++ b/src/nan/nan.h
@@ -418,6 +418,15 @@ struct nan_config {
*/
int (*send_naf)(void *ctx, const u8 *dst, const u8 *src,
const u8 *cluster_id, struct wpabuf *buf);
+
+ /**
+ * is_valid_publish_id - Check if a publish instance ID is valid
+ * @ctx: Callback context from cb_ctx
+ * @instance_id: the instance ID to check
+ * Return true iff there is a local publish service ID with the given
+ * instance ID
+ */
+ bool (*is_valid_publish_id)(void *ctx, u8 instance_id, u8 *service_id);
};
struct nan_data * nan_init(const struct nan_config *cfg);
--
2.49.0
More information about the Hostap
mailing list