[RFC 13/56] NAN: Add support for parsing element container attributes

Andrei Otcheretianski andrei.otcheretianski at intel.com
Sun Dec 7 03:18:22 PST 2025


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

Support parsing and storing multiple element container
attributes.

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

diff --git a/src/nan/nan.c b/src/nan/nan.c
index bf7bf34637..0cc2c0ca16 100644
--- a/src/nan/nan.c
+++ b/src/nan/nan.c
@@ -68,6 +68,19 @@ static void nan_peer_flush_dev_capa(struct nan_peer_info *info)
 	}
 }
 
+
+static void nan_peer_flush_elem_container(struct nan_peer_info *info)
+{
+	struct nan_elem_container_entry *cur, *next;
+
+	dl_list_for_each_safe(cur, next, &info->element_container,
+			      struct nan_elem_container_entry, list) {
+		dl_list_del(&cur->list);
+		os_free(cur);
+	}
+}
+
+
 static void nan_del_peer(struct nan_data *nan, struct nan_peer *peer)
 {
 	if (!peer)
@@ -99,6 +112,7 @@ static void nan_del_peer(struct nan_data *nan, struct nan_peer *peer)
 	dl_list_del(&peer->list);
 	nan_peer_flush_avail(&peer->info);
 	nan_peer_flush_dev_capa(&peer->info);
+	nan_peer_flush_elem_container(&peer->info);
 	os_free(peer);
 }
 
@@ -838,6 +852,45 @@ static void nan_parse_peer_device_capa(struct nan_data *nan,
 }
 
 
+static void nan_parse_peer_elem_container(struct nan_data *nan,
+					  struct nan_peer *peer,
+					  const struct nan_attrs *attrs)
+{
+	struct nan_attrs_entry *attr;
+
+	dl_list_for_each(attr, &attrs->element_container, struct nan_attrs_entry,
+			 list) {
+		struct nan_elem_container_entry *entry, *next;
+		u8 map_id = *attr->ptr;
+
+		/* Guarantee that there is only a single entry for each map ID */
+		dl_list_for_each_safe(entry, next, &peer->info.element_container,
+				 struct nan_elem_container_entry, list) {
+
+			if (entry->map_id == map_id) {
+				dl_list_del(&entry->list);
+				os_free(entry);
+				break;
+			}
+		}
+
+		entry = os_zalloc(sizeof(*entry) + attr->len - 1);
+		if (!entry) {
+			wpa_printf(MSG_DEBUG,
+				   "NAN: Failed to allocate element container entry");
+			return;
+		}
+
+		dl_list_init(&entry->list);
+		dl_list_add(&peer->info.element_container, &entry->list);
+
+		entry->map_id = map_id;
+		entry->len = attr->len - 1;
+		os_memcpy(entry->data, attr->ptr + 1, entry->len);
+	}
+}
+
+
 /*
  * nan_parse_device_attrs - Parse device attributes and build availability info
  *
@@ -872,6 +925,7 @@ int nan_parse_device_attrs(struct nan_data *nan, struct nan_peer *peer,
 
 	nan_merge_peer_info(&peer->info, &info);
 	nan_parse_peer_device_capa(nan, peer, &attrs);
+	nan_parse_peer_elem_container(nan, peer, &attrs);
 
 	nan_peer_dump(nan, peer);
 	ret = 0;
@@ -918,6 +972,8 @@ static struct nan_peer *nan_alloc_peer(struct nan_data *nan)
 
 	dl_list_init(&peer->info.avail_entries);
 	dl_list_init(&peer->info.dev_capa);
+	dl_list_init(&peer->info.element_container);
+
 	dl_list_add(&nan->peer_list, &peer->list);
 	dl_list_init(&peer->ndps);
 	return peer;
diff --git a/src/nan/nan_i.h b/src/nan/nan_i.h
index cd5a6697c3..e74c5dd14d 100644
--- a/src/nan/nan_i.h
+++ b/src/nan/nan_i.h
@@ -172,6 +172,21 @@ struct nan_dev_capa_entry {
 	struct nan_device_capabilities capa;
 };
 
+/*
+ * struct nan_elem_container_entry - NAN element container entry
+ *
+ * @list: Used for linking in the element container entries list.
+ * @map_id: Map id of the element container.
+ * @len: Length of data.
+ * @data: Pointer to the data.
+ */
+struct nan_elem_container_entry {
+	struct dl_list list;
+	u8 map_id;
+	u16 len;
+	u8 data[];
+};
+
 /*
  * struct nan_peer_info - NAN peer information
  *
@@ -179,12 +194,14 @@ struct nan_dev_capa_entry {
  * @seq_id: Sequence id of the last availability update.
  * @avail_entries: List of availability entries of the peer.
  * @dev_capa: List of device capabilities of the peer.
+ * @element_container: List of element container entries of the peer.
  */
 struct nan_peer_info {
 	struct os_reltime last_seen;
 	u8 seq_id;
 	struct dl_list avail_entries;
 	struct dl_list dev_capa;
+	struct dl_list element_container;
 };
 
 /**
-- 
2.49.0




More information about the Hostap mailing list