[PATCH 42/71] NAN: Move some functions to nan_util.c

Andrei Otcheretianski andrei.otcheretianski at intel.com
Wed Apr 1 15:01:51 PDT 2026


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

Move the function to check if a peer schedule intersects with the
local schedule and the function to convert a channel schedule to
abitfield from nan_ndl.c to nan_util.c as these functions are not
NDP related.

Signed-off-by: Avraham Stern <avraham.stern at intel.com>
---
 src/nan/nan.c      |   8 ++-
 src/nan/nan_i.h    |   9 ++-
 src/nan/nan_ndl.c  | 149 +--------------------------------------------
 src/nan/nan_util.c | 134 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 151 insertions(+), 149 deletions(-)

diff --git a/src/nan/nan.c b/src/nan/nan.c
index bc497f1377..22d321ad17 100644
--- a/src/nan/nan.c
+++ b/src/nan/nan.c
@@ -1201,7 +1201,13 @@ static int nan_configure_peer_schedule(struct nan_data *nan,
 
 	wpa_printf(MSG_DEBUG, "NAN: Configure peer schedule");
 
-	if (!nan_ndl_peer_schedule_intersects(nan, peer)) {
+	if (!peer->ndl) {
+		wpa_printf(MSG_DEBUG,
+			   "NAN: Cannot configure peer NMI STA - no schedule");
+		return 0;
+	}
+
+	if (!nan_peer_schedule_intersects(nan, peer, &peer->ndl->sched)) {
 		wpa_printf(MSG_DEBUG,
 			   "NAN: Cannot configure peer NMI STA - no intersecting schedule");
 		return 0;
diff --git a/src/nan/nan_i.h b/src/nan/nan_i.h
index ef062c08b1..16dabada7d 100644
--- a/src/nan/nan_i.h
+++ b/src/nan/nan_i.h
@@ -14,6 +14,7 @@
 #include "common/nan_defs.h"
 #include "common/wpa_common.h"
 #include "nan.h"
+#include "bitfield.h"
 
 struct nan_config;
 
@@ -567,8 +568,12 @@ int nan_ndl_add_avail_attrs(struct nan_data *nan, const struct nan_peer *peer,
 void nan_ndl_add_elem_container_attr(const struct nan_data *nan,
 				     const struct nan_peer *peer,
 				     struct wpabuf *buf);
-bool nan_ndl_peer_schedule_intersects(struct nan_data *nan,
-				      struct nan_peer *peer);
+bool nan_peer_schedule_intersects(struct nan_data *nan, struct nan_peer *peer,
+				  struct nan_schedule *sched);
+int nan_convert_chan_sched_to_bf(struct nan_data *nan,
+				 struct nan_chan_schedule *chan,
+				 struct bitfield **avail_bf, u8 *map_id,
+				 u8 *op_class, u16 *cbm, u16 *pcbm);
 int nan_get_chan_bm(struct nan_data *nan, const struct nan_sched_chan *chan,
 		    u8 *op_class, u16 *chan_bm, u16 *pri_chan_bm);
 int nan_add_avail_attrs(struct nan_data *nan, u8 sequence_id,
diff --git a/src/nan/nan_ndl.c b/src/nan/nan_ndl.c
index 701aed18e0..aa0a8137e6 100644
--- a/src/nan/nan_ndl.c
+++ b/src/nan/nan_ndl.c
@@ -232,74 +232,6 @@ static bool nan_ndl_validate_peer_avail(struct nan_data *nan,
 }
 
 
-/**
- * nan_ndl_convert_chan_sched_to_bf - Convert channel schedule to bitfield
- * and get the channel information.
- *
- * @nan: NAN module context from nan_init()
- * @chan: Channel schedule to convert
- * @avail_bf: On successful return holds the availability bitmap of the given
- *     channel schedule
- * @map_id: On successful return holds the map ID for the schedule
- * @op_class: On successful return holds the operating class for the schedule
- *     with the peer
- * @cbm: On successful return holds the channel bitmap for the operating class
- * @pcbm: On successful return holds the primary channel bitmap for the
- *     channel in case of bandwidth greater than 40 MHz
- * Returns: 0 on success; -1 on failure
- */
-static int nan_ndl_convert_chan_sched_to_bf(struct nan_data *nan,
-					    struct nan_chan_schedule *chan,
-					    struct bitfield **avail_bf,
-					    u8 *map_id, u8 *op_class,
-					    u16 *cbm, u16 *pcbm)
-{
-	struct bitfield *committed_bf, *conditional_bf;
-	int ret;
-
-	*op_class = 0;
-	*cbm = 0;
-	*pcbm = 0;
-	*map_id = chan->map_id;
-
-	ret = nan_get_chan_bm(nan, &chan->chan, op_class, cbm, pcbm);
-	if (ret) {
-		wpa_printf(MSG_DEBUG,
-			   "NAN: NDL: Failed to convert channel info");
-		return -1;
-	}
-
-	committed_bf = nan_tbm_to_bf(nan, &chan->committed);
-	if (!committed_bf) {
-		wpa_printf(MSG_DEBUG,
-			   "NAN: NDL: Failed to build committed bitfield");
-		return -1;
-	}
-
-	conditional_bf = nan_tbm_to_bf(nan, &chan->conditional);
-	if (!conditional_bf) {
-		wpa_printf(MSG_DEBUG,
-			   "NAN: NDL: Failed to build conditional bitfield");
-		bitfield_free(committed_bf);
-		return -1;
-	}
-
-	*avail_bf = bitfield_union(committed_bf, conditional_bf);
-	bitfield_free(committed_bf);
-	bitfield_free(conditional_bf);
-
-	if (!*avail_bf) {
-		wpa_printf(MSG_DEBUG,
-			   "NAN: NDL: Failed to unify committed and conditional bitfields");
-		return -1;
-	}
-
-	wpa_printf(MSG_DEBUG, "NAN: NDL: map_id=%u, op_class=%u, cbm=0x%x",
-		   *map_id, *op_class, *cbm);
-	return 0;
-}
-
-
 /**
  * enum nan_ndl_ver - Verdict of comparing local availability to given schedule
  * @NAN_NDL_VER_SCHED_SUBSET_OF_LOCAL: The schedule is a subset of the local one
@@ -463,10 +395,9 @@ static enum nan_ndl_status nan_ndl_determine_status(struct nan_data *nan,
 		u8 map_id, op_class;
 
 		/* Convert the schedule for the current channel to bitfield */
-		ret = nan_ndl_convert_chan_sched_to_bf(nan, &sched->chans[i],
-						       &own_chan_bf, &map_id,
-						       &op_class, &cbm,
-						       &pri_cbm);
+		ret = nan_convert_chan_sched_to_bf(nan, &sched->chans[i],
+						   &own_chan_bf, &map_id,
+						   &op_class, &cbm, &pri_cbm);
 		if (ret) {
 			wpa_printf(MSG_DEBUG,
 				   "NAN: NDL: Failed to convert chan sched to bitfield");
@@ -1758,77 +1689,3 @@ void nan_ndl_add_elem_container_attr(const struct nan_data *nan,
 	wpabuf_put_u8(buf, 0);
 	wpabuf_put_buf(buf, ndl->sched.elems);
 }
-
-
-/*
- * nan_ndl_peer_schedule_intersects - Check if local and peer schedules
- * intersect
- *
- * @nan: NAN module context from nan_init()
- * @peer: The peer with whom the NDL is being setup
- * Returns: True if schedules intersect, false otherwise
- *
- * The function checks if the local device schedule intersects with the peer
- * device schedule.
- */
-bool nan_ndl_peer_schedule_intersects(struct nan_data *nan,
-				      struct nan_peer *peer)
-{
-	struct nan_schedule *sched;
-	size_t i;
-
-	if (!peer->ndl)
-		return false;
-
-	sched = &peer->ndl->sched;
-
-	/*
-	 * Iterate over all the channels included in the local schedule. For
-	 * each channel convert the committed and conditional slots to a
-	 * bitfield object and extract the operating class and channel bitmap.
-	 *
-	 * Using the operating class and channel bitmap find the peer
-	 * availability on that channel and check if it intersect with the
-	 * local one.
-	 */
-	wpa_printf(MSG_DEBUG, "NAN: n_chans=%u, ndc_map_id=%u",
-		   sched->n_chans, sched->ndc_map_id);
-
-	for (i = 0; i < sched->n_chans; i++) {
-		struct bitfield *own_chan_bf = NULL, *peer_chan_bf = NULL;
-		u16 cbm, pri_cbm;
-		u8 map_id, op_class;
-		int ret;
-
-		/* Convert the schedule for the current channel to bitfield */
-		ret = nan_ndl_convert_chan_sched_to_bf(nan, &sched->chans[i],
-						       &own_chan_bf, &map_id,
-						       &op_class, &cbm,
-						       &pri_cbm);
-		if (ret) {
-			wpa_printf(MSG_DEBUG,
-				   "NAN: NDL: Failed to convert chan sched to bitfield");
-			return false;
-		}
-
-		/* Get the peer availability for the current channel */
-		peer_chan_bf =
-			nan_avail_entries_to_bf(nan,
-						&peer->info.avail_entries,
-						op_class, cbm, pri_cbm);
-		if (!peer_chan_bf) {
-			bitfield_free(own_chan_bf);
-			continue;
-		}
-
-		ret = bitfield_intersects(own_chan_bf, peer_chan_bf);
-
-		bitfield_free(peer_chan_bf);
-		bitfield_free(own_chan_bf);
-
-		if (ret == 1)
-			return true;
-	}
-
-	return false;
-}
diff --git a/src/nan/nan_util.c b/src/nan/nan_util.c
index 05630464d6..e736ea8510 100644
--- a/src/nan/nan_util.c
+++ b/src/nan/nan_util.c
@@ -1762,3 +1762,137 @@ int nan_get_chan_entry(struct nan_data *nan, const struct nan_sched_chan *chan,
 
 	return 0;
 }
+
+
+/**
+ * nan_convert_chan_sched_to_bf - Convert channel schedule to bitfield
+ * and get the channel information.
+ *
+ * @nan: NAN module context from nan_init()
+ * @chan: Channel schedule to convert
+ * @avail_bf: On successful return holds the availability bitmap of the given
+ * 	channel schedule
+ * @map_id: On successful return holds the map ID for the schedule
+ * @op_class: On successful return holds the operating class for the
+ *     schedule with the peer
+ * @cbm: On successful return holds the channel bitmap for the operating class
+ * @pcbm: On successful return holds the primary channel bitmap for the
+ *     channel in case of bandwidth greater than 40 MHz
+ * Returns: 0 on success; -1 on failure
+ */
+int nan_convert_chan_sched_to_bf(struct nan_data *nan,
+				 struct nan_chan_schedule *chan,
+				 struct bitfield **avail_bf, u8 *map_id,
+				 u8 *op_class, u16 *cbm, u16 *pcbm)
+{
+	struct bitfield *committed_bf, *conditional_bf;
+	int ret;
+
+	*op_class = 0;
+	*cbm = 0;
+	*pcbm = 0;
+	*map_id = chan->map_id;
+
+	ret = nan_get_chan_bm(nan, &chan->chan, op_class, cbm, pcbm);
+	if (ret) {
+		wpa_printf(MSG_DEBUG,
+			   "NAN: NDL: Failed to convert channel info");
+		return -1;
+	}
+
+	committed_bf = nan_tbm_to_bf(nan, &chan->committed);
+	if (!committed_bf) {
+		wpa_printf(MSG_DEBUG,
+			   "NAN: NDL: Failed to build committed bitfield");
+		return -1;
+	}
+
+	conditional_bf = nan_tbm_to_bf(nan, &chan->conditional);
+	if (!conditional_bf) {
+		wpa_printf(MSG_DEBUG,
+			   "NAN: NDL: Failed to build conditional bitfield");
+		bitfield_free(committed_bf);
+		return -1;
+	}
+
+	*avail_bf = bitfield_union(committed_bf, conditional_bf);
+	bitfield_free(committed_bf);
+	bitfield_free(conditional_bf);
+
+	if (!*avail_bf) {
+		wpa_printf(MSG_DEBUG,
+			   "NAN: NDL: Failed to unify committed and conditional bitfields");
+		return -1;
+	}
+
+	wpa_printf(MSG_DEBUG, "NAN: NDL: map_id=%u, op_class=%u, cbm=0x%x",
+		   *map_id, *op_class, *cbm);
+	return 0;
+}
+
+
+/*
+ * nan_peer_schedule_intersects - Check if local and peer schedules intersect
+ *
+ * @nan: NAN module context from nan_init()
+ * @peer: The peer with whom to intersect the schedule
+ * @sched: Local device schedule
+ * Returns: True if schedules intersect, false otherwise
+ *
+ * The function checks if the local device schedule intersects with the peer
+ * device schedule.
+ */
+bool nan_peer_schedule_intersects(struct nan_data *nan, struct nan_peer *peer,
+				  struct nan_schedule *sched)
+{
+	size_t i;
+
+	/*
+	 * Iterate over all the channels included in the local schedule. For
+	 * each channel convert the committed and conditional slots to a
+	 * bitfield object and extract the operating class and channel bitmap.
+	 *
+	 * Using the operating class and channel bitmap find the peer
+	 * availability on that channel and check if it intersect with the
+	 * local one.
+	 */
+	wpa_printf(MSG_DEBUG, "NAN: n_chans=%u, ndc_map_id=%u",
+		   sched->n_chans, sched->ndc_map_id);
+
+	for (i = 0; i < sched->n_chans; i++) {
+		struct bitfield *own_chan_bf = NULL, *peer_chan_bf = NULL;
+		u16 cbm, pri_cbm;
+		u8 map_id, op_class;
+		int ret;
+
+		/* Convert the schedule for the current channel to bitfield */
+		ret = nan_convert_chan_sched_to_bf(nan, &sched->chans[i],
+						   &own_chan_bf, &map_id,
+						   &op_class, &cbm, &pri_cbm);
+		if (ret) {
+			wpa_printf(MSG_DEBUG,
+				   "NAN: NDL: Failed to convert chan sched to bitfield");
+			return false;
+		}
+
+		/* Get the peer availability for the current channel */
+		peer_chan_bf =
+			nan_avail_entries_to_bf(nan,
+						&peer->info.avail_entries,
+						op_class, cbm, pri_cbm);
+		if (!peer_chan_bf) {
+			bitfield_free(own_chan_bf);
+			continue;
+		}
+
+		ret = bitfield_intersects(own_chan_bf, peer_chan_bf);
+
+		bitfield_free(peer_chan_bf);
+		bitfield_free(own_chan_bf);
+
+		if (ret == 1)
+			return true;
+	}
+
+	return false;
+}
-- 
2.53.0




More information about the Hostap mailing list