All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/6] scan: add scan_freq_set_serialize
@ 2021-11-29 23:12 James Prestwood
  0 siblings, 0 replies; 2+ messages in thread
From: James Prestwood @ 2021-11-29 23:12 UTC (permalink / raw)
  To: iwd

[-- 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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 3/6] scan: add scan_freq_set_serialize
@ 2021-11-29 23:37 Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2021-11-29 23:37 UTC (permalink / raw)
  To: iwd

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

Hi James,

On 11/29/21 5:12 PM, James Prestwood wrote:
> 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;
> +};

Whats this for?

> +
> +static void count_foreach(uint32_t freq, void *user_data)
> +{
> +	uint8_t *count = user_data;
> +
> +	l_put_u8(*count + 1, count);
> +}

Hmm, I wonder if you can either calculate this directly or book-keep the count 
in scan_freq_set itself.  In theory the 2g freqs (if not zero) are just 
__builtin_popcount().  For the uintset it is essentially the same.

> +
> +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);
> +

Can we call this scan_freq_set_to_fixed_array, similar to how l_dbus_message 
names this.

>   bool scan_wdev_add(uint64_t wdev_id);
>   bool scan_wdev_remove(uint64_t wdev_id);
> 

Regards,
-Denis

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-29 23:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-29 23:12 [PATCH 3/6] scan: add scan_freq_set_serialize James Prestwood
2021-11-29 23:37 Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.