public inbox for iwd@lists.linux.dev
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj at gmail.com>
To: iwd at lists.01.org
Subject: [PATCH 3/6] scan: add scan_freq_set_serialize
Date: Mon, 29 Nov 2021 15:12:57 -0800	[thread overview]
Message-ID: <20211129231300.108873-3-prestwoj@gmail.com> (raw)
In-Reply-To: 20211129231300.108873-1-prestwoj@gmail.com

[-- Attachment #1: Type: text/plain, Size: 1830 bytes --]

This serializes a scan_freq_set into a uint32_t array.
---
 src/scan.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 src/scan.h |  3 +++
 2 files changed, 48 insertions(+)

diff --git a/src/scan.c b/src/scan.c
index b602c8be..1c80dd65 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -2370,6 +2370,51 @@ void scan_freq_set_constrain(struct scan_freq_set *set,
 	set->channels_2ghz &= constraint->channels_2ghz;
 }
 
+struct scan_freq_get_index_data {
+	unsigned int target;
+	unsigned int current;
+	uint32_t found;
+};
+
+static void count_foreach(uint32_t freq, void *user_data)
+{
+	uint8_t *count = user_data;
+
+	l_put_u8(*count + 1, count);
+}
+
+static void add_foreach(uint32_t freq, void *user_data)
+{
+	uint32_t **list = user_data;
+
+	**list = freq;
+
+	*list = *list + 1;
+}
+
+uint32_t *scan_freq_set_serialize(const struct scan_freq_set *set,
+					size_t *len_out)
+{
+	uint8_t count = 0;
+	uint32_t *freqs;
+
+	scan_freq_set_foreach(set, count_foreach, &count);
+
+	if (!count)
+		return NULL;
+
+	freqs = l_new(uint32_t, count);
+
+	scan_freq_set_foreach(set, add_foreach, &freqs);
+
+	/* Move pointer back to start of list */
+	freqs -= count;
+
+	*len_out = count;
+
+	return freqs;
+}
+
 bool scan_wdev_add(uint64_t wdev_id)
 {
 	struct scan_context *sc;
diff --git a/src/scan.h b/src/scan.h
index 66e38410..e6eea1c5 100644
--- a/src/scan.h
+++ b/src/scan.h
@@ -191,5 +191,8 @@ void scan_freq_set_constrain(struct scan_freq_set *set,
 					const struct scan_freq_set *constraint);
 bool scan_freq_set_isempty(const struct scan_freq_set *set);
 
+uint32_t *scan_freq_set_serialize(const struct scan_freq_set *set,
+					size_t *len_out);
+
 bool scan_wdev_add(uint64_t wdev_id);
 bool scan_wdev_remove(uint64_t wdev_id);
-- 
2.31.1

             reply	other threads:[~2021-11-29 23:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-29 23:12 James Prestwood [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-11-29 23:37 [PATCH 3/6] scan: add scan_freq_set_serialize Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211129231300.108873-3-prestwoj@gmail.com \
    --to=iwd@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox