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 2/4] dpp-util: add URI generation API
Date: Mon, 06 Dec 2021 13:03:54 -0800	[thread overview]
Message-ID: <20211206210356.1204046-2-prestwoj@gmail.com> (raw)
In-Reply-To: 20211206210356.1204046-1-prestwoj@gmail.com

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

             reply	other threads:[~2021-12-06 21:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06 21:03 James Prestwood [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-12-06 22:33 [PATCH 2/4] dpp-util: add URI generation API 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=20211206210356.1204046-2-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