public inbox for iwd@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH 2/4] dpp-util: add URI generation API
@ 2021-12-06 21:03 James Prestwood
  0 siblings, 0 replies; 2+ messages in thread
From: James Prestwood @ 2021-12-06 21:03 UTC (permalink / raw)
  To: iwd 

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

---
 src/dpp-util.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/dpp-util.h |  4 ++++
 2 files changed, 64 insertions(+)

diff --git a/src/dpp-util.c b/src/dpp-util.c
index 8482b1ff..ca641311 100644
--- a/src/dpp-util.c
+++ b/src/dpp-util.c
@@ -33,6 +33,66 @@
 #include "src/dpp-util.h"
 #include "src/util.h"
 #include "src/crypto.h"
+#include "src/scan.h"
+
+static void append_freqs(struct l_string *uri, const uint32_t *freqs, size_t len)
+{
+	size_t i;
+	enum band_freq band;
+
+	l_string_append_printf(uri, "C:");
+
+	for (i = 0; i < len; i++) {
+		uint8_t oper_class;
+		uint8_t channel = band_freq_to_channel(freqs[i], &band);
+
+		/* For now use global operating classes */
+		if (band == BAND_FREQ_2_4_GHZ)
+			oper_class = 81;
+		else
+			oper_class = 115;
+
+		l_string_append_printf(uri, "%u/%u", oper_class, channel);
+
+		if (i != len - 1)
+			l_string_append_c(uri, ',');
+	}
+
+	l_string_append_c(uri, ';');
+}
+
+char *dpp_generate_uri(const uint8_t *asn1, size_t asn1_len, uint8_t version,
+			const uint8_t *mac, const uint32_t *freqs,
+			size_t freqs_len, const char *info, const char *host)
+{
+	struct l_string *uri = l_string_new(256);
+	char *base64;
+
+	base64 = l_base64_encode(asn1, asn1_len, 0);
+
+	l_string_append_printf(uri, "DPP:K:%s;", base64);
+	l_free(base64);
+
+	if (mac)
+		l_string_append_printf(uri, "M:%02x%02x%02x%02x%02x%02x;",
+					MAC_STR(mac));
+
+	if (freqs)
+		append_freqs(uri, freqs, freqs_len);
+
+	if (info)
+		l_string_append_printf(uri, "I:%s;", info);
+
+	if (host)
+		l_string_append_printf(uri, "H:%s;", host);
+
+	if (version)
+		l_string_append_printf(uri, "V:%u;", version);
+
+	l_string_append_c(uri, ';');
+
+	return l_string_unwrap(uri);
+}
 
 /*
  * EasyConnect 2.0 Table 3. Key and Nonce Length Dependency on Prime Length
diff --git a/src/dpp-util.h b/src/dpp-util.h
index 92fc38e3..971c0ce4 100644
--- a/src/dpp-util.h
+++ b/src/dpp-util.h
@@ -22,6 +22,10 @@
 struct l_ecc_point;
 struct l_ecc_scalar;
 
+char *dpp_generate_uri(const uint8_t *asn1, size_t asn1_len, uint8_t version,
+			const uint8_t *mac, const uint32_t *freqs,
+			size_t freqs_len, const char *info, const char *host);
+
 size_t dpp_nonce_len_from_key_len(size_t len);
 
 bool dpp_hash(enum l_checksum_type type, uint8_t *out, unsigned int num, ...);
-- 
2.31.1

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

* Re: [PATCH 2/4] dpp-util: add URI generation API
@ 2021-12-06 22:33 Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2021-12-06 22:33 UTC (permalink / raw)
  To: iwd 

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

On 12/6/21 3:03 PM, James Prestwood wrote:
> ---
>   src/dpp-util.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
>   src/dpp-util.h |  4 ++++
>   2 files changed, 64 insertions(+)
> 
> diff --git a/src/dpp-util.c b/src/dpp-util.c
> index 8482b1ff..ca641311 100644
> --- a/src/dpp-util.c
> +++ b/src/dpp-util.c
> @@ -33,6 +33,66 @@
>   #include "src/dpp-util.h"
>   #include "src/util.h"
>   #include "src/crypto.h"
> +#include "src/scan.h"
> +

I switched this to include src/band.h instead of scan.h, which is what seems to 
be intended.

Also a whitespace fix for a line > 80 chars.

Patches 1-3 applied, thanks.

Regards,
-Denis

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

end of thread, other threads:[~2021-12-06 22:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-06 21:03 [PATCH 2/4] dpp-util: add URI generation API James Prestwood
  -- strict thread matches above, loose matches on Subject: below --
2021-12-06 22:33 Denis Kenzior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox