[RFC v2 16/99] NAN: Add utility function to convert channel to bitmap

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


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

Add a function that converts an operating class and channel index to
a NAN availability entry channel bit map.

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

diff --git a/src/nan/nan_i.h b/src/nan/nan_i.h
index e74c5dd14d..9608de244d 100644
--- a/src/nan/nan_i.h
+++ b/src/nan/nan_i.h
@@ -310,4 +310,6 @@ int nan_ndp_naf_sent(struct nan_data *nan, struct nan_peer *peer,
 		     enum nan_subtype subtype);
 int nan_parse_device_attrs(struct nan_data *nan, struct nan_peer *peer,
 			   const u8 *attrs_data, size_t attrs_len);
+int nan_chan_to_chan_idx_map(struct nan_data *nan,
+			     u8 op_class, u8 channel, u16 *chan_idx_map);
 #endif
diff --git a/src/nan/nan_util.c b/src/nan/nan_util.c
index 987928da2b..f7c35a3155 100644
--- a/src/nan/nan_util.c
+++ b/src/nan/nan_util.c
@@ -9,6 +9,7 @@
 #include "includes.h"
 #include "common.h"
 #include "nan_i.h"
+#include "common/ieee802_11_common.h"
 
 
 static void nan_attrs_clear_list(struct nan_data *nan,
@@ -328,3 +329,41 @@ void nan_add_dev_capa_attr(struct nan_data *nan, struct wpabuf *buf)
 	wpabuf_put_le16(buf, nan->cfg->dev_capa.channel_switch_time);
 	wpabuf_put_u8(buf, nan->cfg->dev_capa.capa);
 }
+
+
+/**
+ * nan_chan_to_chan_idx_map - convert an op_class and chan to channel
+ * bitmap
+ *
+ * @nan: NAN module context from nan_init()
+ * @op_class: the operating class
+ * @channel: channel number
+ * @chan_idx_map: On success, would hold the channel index bitmap
+ * Returns 0 on success, otherwise a negative value
+ */
+int nan_chan_to_chan_idx_map(struct nan_data *nan,
+			     u8 op_class, u8 channel, u16 *chan_idx_map)
+{
+	u32 i;
+	int ret;
+
+	if (!chan_idx_map)
+		return -1;
+
+	for (i = 0; global_op_class[i].op_class; i++)
+		if (global_op_class[i].op_class == op_class)
+			break;
+
+	if (!global_op_class[i].op_class)
+		return -1;
+
+	ret = op_class_chan_to_idx(&global_op_class[i], channel);
+	if (ret < 0)
+		return ret;
+
+	if ((u16)ret >= (sizeof(*chan_idx_map) * 8))
+		return -1;
+
+	*chan_idx_map = BIT(ret);
+	return 0;
+}
-- 
2.49.0




More information about the Hostap mailing list