[RFC v2 60/99] NAN: Add a function to get peer NDC channel
Andrei Otcheretianski
andrei.otcheretianski at intel.com
Tue Dec 23 03:52:04 PST 2025
Add a helper function that finds NDC channel from peer schedule.
In case NDC bitmap spans across multiple channels, only one channel is
returned (that corresponds to the first NDC bit).
Signed-off-by: Andrei Otcheretianski <andrei.otcheretianski at intel.com>
---
src/nan/nan.h | 3 +++
src/nan/nan_util.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+)
diff --git a/src/nan/nan.h b/src/nan/nan.h
index 91dc1b4464..862d852f83 100644
--- a/src/nan/nan.h
+++ b/src/nan/nan.h
@@ -542,4 +542,7 @@ int nan_convert_sched_to_avail_attrs(struct nan_data *nan, u8 sequence_id,
struct wpabuf *buf);
bool nan_peer_pairing_supported(struct nan_data *nan, const u8 *addr);
bool nan_peer_npk_nik_caching_supported(struct nan_data *nan, const u8 *addr);
+int nan_get_peer_ndc_freq(struct nan_data *nan ,
+ struct nan_peer_schedule *peer_sched,
+ u8 map_idx);
#endif /* NAN_H */
diff --git a/src/nan/nan_util.c b/src/nan/nan_util.c
index 7c143befb2..7dad52a81e 100644
--- a/src/nan/nan_util.c
+++ b/src/nan/nan_util.c
@@ -1632,3 +1632,64 @@ err:
"NAN: Buffer too small to dump peer potential availability");
return -1;
}
+
+
+/**
+ * nan_get_peer_ndc_freq - Get peer NDC frequency from schedule
+ *
+ * @nan: Pointer to NAN data struct
+ * @peer_sched: Pointer to peer schedule struct
+ * @map_idx: Index of the availability map to check
+ *
+ * Returns: Frequency of the committed channel that intersects with NDC,
+ * or -1 on failure or if no intersection found
+ *
+ * In case NDC bitmap spans across multiple channels, only one channel is
+ * returned (that corresponds to the first NDC bit).
+ */
+int nan_get_peer_ndc_freq(struct nan_data *nan ,
+ struct nan_peer_schedule *peer_sched,
+ u8 map_idx)
+{
+ struct bitfield *ndc_bf;
+ int i;
+
+ if (map_idx >= peer_sched->n_maps) {
+ wpa_printf(MSG_DEBUG,
+ "NAN: Invalid map index %u for peer schedule",
+ map_idx);
+ return -1;
+ }
+
+ ndc_bf = nan_tbm_to_bf(nan, &peer_sched->maps[map_idx].ndc);
+ if (!ndc_bf)
+ return -1;
+
+ for (i = 0; i < peer_sched->maps[map_idx].n_chans; i++) {
+ struct bitfield *committed_bf;
+
+ if (!peer_sched->maps[map_idx].chans[i].committed)
+ continue;
+
+ committed_bf =
+ nan_tbm_to_bf(nan,
+ &peer_sched->maps[map_idx].chans[i].tbm);
+ if (!committed_bf) {
+ wpa_printf(MSG_DEBUG,
+ "NAN: Failed to convert peer committed TBM to bitfield");
+ bitfield_free(ndc_bf);
+ return -1;
+ }
+
+ if (bitfield_intersects(ndc_bf, committed_bf)) {
+ bitfield_free(ndc_bf);
+ bitfield_free(committed_bf);
+ return peer_sched->maps[map_idx].chans[i].chan.freq;
+ }
+
+ bitfield_free(committed_bf);
+ }
+
+ bitfield_free(ndc_bf);
+ return -1;
+}
--
2.49.0
More information about the Hostap
mailing list