Skip to contentSkip to conversation

dpp-util: add URI parsing

PATCH Superseded James Prestwood 1 participant 9 messages Feb 22, 2022

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

James Prestwood

author
#0 lore raw

PATCH v6 1/9 dpp-util: add URI parsing

Parses K (key), M (mac), C (class/channels), and V (version) tokens into a new structure dpp_uri_info. H/I are not parsed since there currently isn't any use for them.

---
 src/dpp-util.c | 250 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/dpp-util.h |  13 +++
 2 files changed, 263 insertions(+)

v6
* Set errno to 0 prior to calling strtoul
* check for version 1 or 2 as ascii rather than using strtoul

src/dpp-util.c +250 -0
index 5199d0ae..cd627e2a 100644
@@ -866,3 +866,253 @@ struct l_ecc_point *dpp_point_from_asn1(const uint8_t *asn1, size_t len)
 	return l_ecc_point_from_data(curve, key_data[1],
 					key_data + 2, elen - 2);
 }
+
+/*
+ * Advances 'p' to the next character 'sep' plus one. strchr can be trusted to
+ * find the next character, but we do need to check that the next character + 1
+ * isn't the NULL terminator, i.e. that data actually exists past this point.
+ */
+#define TOKEN_NEXT(p, sep) \
+({ \
+	const char *_next = strchr((p), (sep)); \
+	if (_next) { \
+		if (*(_next + 1) == '\0') \
+			_next = NULL; \
+		else \
+			_next++; \
+	} \
+	_next; \
+})
+
+/*
+ * Finds the length of the current token (characters until next 'sep'). If no
+ * 'sep' is found zero is returned.
+ */
+#define TOKEN_LEN(p, sep) \
+({ \
+	const char *_next = strchr((p), (sep)); \
+	if (!_next) \
+		_next = (p); \
+	(_next - (p)); \
+})
+
+/*
+ * Ensures 'p' points to something resembling a single character followed by
+ * ':' followed by at least one non-null byte of data. This allows the parse
+ * loop to safely advance the pointer to each tokens data (pos + 2)
+ */
+#define TOKEN_OK(p) \
+	((p) && (p)[0] != '\0' && (p)[1] == ':' && (p)[2] != '\0') \
+
+static struct scan_freq_set *dpp_parse_class_and_channel(const char *token,
+							unsigned int len)
+{
+	const char *pos = token;
+	char *end;
+	struct scan_freq_set *freqs = scan_freq_set_new();
+
+	/* Checking for <operclass>/<channel>,<operclass>/<channel>,... */
+	for (; pos && pos < token + len; pos = TOKEN_NEXT(pos, ',')) {
+		unsigned long r;
+		uint8_t channel;
+		uint8_t oper_class;
+		uint32_t freq;
+
+		/* strtoul accepts minus and plus signs before value */
+		if (*pos == '-' || *pos == '+')
+			goto free_set;
+
+		/* to check uint8_t overflow */
+		errno = 0;
+		r = oper_class = strtoul(pos, &end, 10);
+
+		if (errno == ERANGE || errno == EINVAL)
+			goto free_set;
+		/*
+		 * Did strtoul not advance pointer, not reach the next
+		 * token, or overflow?
+		 */
+		if (end == pos || *end != '/' || r != oper_class)
+			goto free_set;
+
+		pos = end + 1;
+
+		if (*pos == '-' || *pos == '+')
+			goto free_set;
+
+		errno = 0;
+		r = channel = strtoul(pos, &end, 10);
+
+		if (errno == ERANGE || errno == EINVAL)
+			goto free_set;
+		/*
+		 * Same verification as above, but also checks either for
+		 * another pair (,) or end of this token (;)
+		 */
+		if (end == pos || (*end != ',' && *end != ';') || r != channel)
+			goto free_set;
+
+		freq = oci_to_frequency(oper_class, channel);
+		if (!freq)
+			goto free_set;
+
+		scan_freq_set_add(freqs, freq);
+	}
+
+	if (token + len != end)
+		goto free_set;
+
+	if (scan_freq_set_isempty(freqs)) {
+free_set:
+		scan_freq_set_free(freqs);
+		return NULL;
+	}
+
+	return freqs;
+}
+
+static int dpp_parse_mac(const char *str, unsigned int len, uint8_t *mac_out)
+{
+	uint8_t mac[6];
+	unsigned int i;
+
+	if (len != 12)
+		return -EINVAL;
+
+	for (i = 0; i < 12; i += 2) {
+		if (!l_ascii_isxdigit(str[i]))
+			return -EINVAL;
+
+		if (!l_ascii_isxdigit(str[i + 1]))
+			return -EINVAL;
+	}
+
+	if (sscanf(str, "%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
+			&mac[0], &mac[1], &mac[2],
+			&mac[3], &mac[4], &mac[5]) != 6)
+		return -EINVAL;
+
+	if (!util_is_valid_sta_address(mac))
+		return -EINVAL;
+
+	memcpy(mac_out, mac, 6);
+
+	return 0;
+}
+
+static int dpp_parse_version(const char *str, unsigned int len,
+				uint8_t *version_out)
+{
+	if (len != 1)
+		return -EINVAL;
+
+	if (str[0] != '1' && str[0] != '2')
+		return -EINVAL;
+
+	*version_out = str[0] - '0';
+
+	return 0;
+}
+
+static struct l_ecc_point *dpp_parse_key(const char *str, unsigned int len)
+{
+	_auto_(l_free) uint8_t *decoded = NULL;
+	size_t decoded_len;
+
+	decoded = l_base64_decode(str, len, &decoded_len);
+	if (!decoded)
+		return NULL;
+
+	return dpp_point_from_asn1(decoded, decoded_len);
+}
+
+/*
+ * Parse a bootstrapping URI. This parses the tokens defined in the Easy Connect
+ * spec, and verifies they are the correct syntax. Some values have extra
+ * verification:
+ *  - The bootstrapping key is base64 decoded and converted to an l_ecc_point
+ *  - The operating class and channels are checked against the OCI table.
+ *  - The version is checked to be either 1 or 2, as defined by the spec.
+ *  - The MAC is verified to be a valid station address.
+ */
+struct dpp_uri_info *dpp_parse_uri(const char *uri)
+{
+	struct dpp_uri_info *info;
+	const char *pos = uri;
+	const char *end = uri + strlen(uri) - 1;
+	int ret = 0;
+
+	if (!l_str_has_prefix(pos, "DPP:"))
+		return NULL;
+
+	info = l_new(struct dpp_uri_info, 1);
+
+	pos += 4;
+
+	/* EasyConnect 5.2.1 - Bootstrapping information format */
+	for (; TOKEN_OK(pos); pos = TOKEN_NEXT(pos, ';')) {
+		unsigned int len = TOKEN_LEN(pos + 2, ';');
+
+		if (!len)
+			goto free_info;
+
+		switch (*pos) {
+		case 'C':
+			info->freqs = dpp_parse_class_and_channel(pos + 2, len);
+			if (!info->freqs)
+				goto free_info;
+			break;
+		case 'M':
+			ret = dpp_parse_mac(pos + 2, len, info->mac);
+			if (ret < 0)
+				goto free_info;
+			break;
+		case 'V':
+			ret = dpp_parse_version(pos + 2, len, &info->version);
+			if (ret < 0)
+				goto free_info;
+			break;
+		case 'K':
+			info->boot_public = dpp_parse_key(pos + 2, len);
+			if (!info->boot_public)
+				goto free_info;
+			break;
+		case 'H':
+		case 'I':
+			break;
+		default:
+			goto free_info;
+		}
+	}
+
+	/* Extra data found after last token */
+	if (pos != end)
+		goto free_info;
+
+	/* The public bootstrapping key is the only required token */
+	if (!info->boot_public)
+		goto free_info;
+
+	return info;
+
+free_info:
+	dpp_free_uri_info(info);
+	return NULL;
+}
+
+void dpp_free_uri_info(struct dpp_uri_info *info)
+{
+	if (info->freqs)
+		scan_freq_set_free(info->freqs);
+
+	if (info->boot_public)
+		l_ecc_point_free(info->boot_public);
+
+	if (info->information)
+		l_free(info->information);
+
+	if (info->host)
+		l_free(info->host);
+
+	l_free(info);
+}
src/dpp-util.h +13 -0
index 82535ff8..a3ddd452 100644
@@ -22,6 +22,16 @@
 struct l_ecc_point;
 struct l_ecc_scalar;
 enum ie_rsn_akm_suite;
+struct scan_freq_set;
+
+struct dpp_uri_info {
+	struct scan_freq_set *freqs;
+	struct l_ecc_point *boot_public;
+	uint8_t mac[6];
+	char *information;
+	uint8_t version;
+	char *host;
+};
 
 enum dpp_frame_type {
 	DPP_FRAME_AUTHENTICATION_REQUEST	= 0,
@@ -168,3 +178,6 @@ bool dpp_derive_ke(const uint8_t *i_nonce, const uint8_t *r_nonce,
 
 uint8_t *dpp_point_to_asn1(const struct l_ecc_point *p, size_t *len_out);
 struct l_ecc_point *dpp_point_from_asn1(const uint8_t *asn1, size_t len);
+
+struct dpp_uri_info *dpp_parse_uri(const char *uri);
+void dpp_free_uri_info(struct dpp_uri_info *info);
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v6 2/9 unit: add DPP unit tests for URI parsing

---
 unit/test-dpp.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 139 insertions(+)

v6:
* Removed a value which was uninitalized and never set

unit/test-dpp.c +139 -0
index bfe6f747..f376345c 100644
@@ -33,6 +33,131 @@
 #include "src/util.h"
 #include "ell/useful.h"
 
+struct dpp_test_info {
+	const char *uri;
+	bool expect_fail;
+	uint32_t expected_freqs[10];
+	struct dpp_uri_info result;
+};
+
+struct dpp_test_info all_values = {
+	.uri = "DPP:C:81/1,115/36;I:SN=4774LH2b4044;M:5254005828e5;V:2;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;",
+	.result = {
+		.mac = { 0x52, 0x54, 0x00, 0x58, 0x28, 0xe5 },
+		.version = 2,
+	},
+	.expected_freqs = { 2412, 5180, 0 }
+};
+
+struct dpp_test_info no_type = {
+	.uri = "C:81/1;K:shouldnotmatter;;",
+	.expect_fail = true
+};
+
+struct dpp_test_info empty = {
+	.uri = "DPP:",
+	.expect_fail = true
+};
+
+struct dpp_test_info no_key = {
+	.uri = "DPP:C:81/1,115/36;I:SN=4774LH2b4044;M:5254005828e5;V:2;;",
+	.expect_fail = true
+};
+
+struct dpp_test_info data_after_terminator = {
+	.uri = "DPP:K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;C:81/1;;",
+	.expect_fail = true
+};
+
+struct dpp_test_info single_terminator = {
+	.uri = "DPP:K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;",
+	.expect_fail = true
+};
+
+struct dpp_test_info no_terminator = {
+	.uri = "DPP:K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=",
+	.expect_fail = true
+};
+
+struct dpp_test_info bad_key = {
+	.uri = "DPP:K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0;;",
+	.expect_fail = true
+};
+
+struct dpp_test_info unexpected_id = {
+	.uri = "DPP:Z:somedata;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;",
+	.expect_fail = true
+};
+
+struct dpp_test_info bad_channels[] = {
+	{
+		.uri = "DPP:C:;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;",
+		.expect_fail = true
+	},
+	{
+		.uri = "DPP:C:81;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;",
+		.expect_fail = true
+	},
+	{
+		.uri = "DPP:C:81/;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;",
+		.expect_fail = true
+	},
+	{
+		.uri = "DPP:C:81/1,;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;",
+		.expect_fail = true
+	},
+	{
+		.uri = "DPP:C:81/1,81/;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;",
+		.expect_fail = true
+	},
+	{
+		.uri = "DPP:C:81/1,/;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;",
+		.expect_fail = true
+	},
+};
+
+static bool verify_info(const struct dpp_uri_info *parsed,
+			const struct dpp_test_info *result)
+{
+	const struct dpp_uri_info *expected = &result->result;
+	uint32_t i;
+
+	assert(!memcmp(parsed->mac, expected->mac, 6));
+	assert(parsed->version == expected->version);
+	assert(parsed->boot_public != NULL);
+
+	for (i = 0; result->expected_freqs[i]; i++)
+		assert(scan_freq_set_contains(parsed->freqs,
+						result->expected_freqs[i]));
+
+	return true;
+}
+
+static void test_uri_parse(const void *data)
+{
+	const struct dpp_test_info *test_info = data;
+	struct dpp_uri_info *info;
+
+	info = dpp_parse_uri(test_info->uri);
+	if (test_info->expect_fail) {
+		assert(info == NULL);
+		return;
+	}
+
+	assert(verify_info(info, test_info));
+
+	dpp_free_uri_info(info);
+}
+
+
+static void test_bad_channels(const void *data)
+{
+	unsigned int i;
+
+	for (i = 0; i < L_ARRAY_SIZE(bad_channels); i++)
+		test_uri_parse(&bad_channels[i]);
+}
+
 /*
  * B.2 Test Vectors for DPP Authentication Using P-256 for
  * Responder-only Authentication
@@ -148,5 +273,19 @@ int main(int argc, char *argv[])
 		l_test_add("DPP test key derivation",
 						test_key_derivation, NULL);
 
+	l_test_add("DPP URI parse", test_uri_parse, &all_values);
+	l_test_add("DPP URI no type", test_uri_parse, &no_type);
+	l_test_add("DPP URI empty", test_uri_parse, &empty);
+	l_test_add("DPP URI no key", test_uri_parse, &no_key);
+	l_test_add("DPP URI data after terminator", test_uri_parse,
+				&data_after_terminator);
+	l_test_add("DPP URI single terminator", test_uri_parse,
+				&single_terminator);
+	l_test_add("DPP URI no terminator", test_uri_parse,
+				&no_terminator);
+	l_test_add("DPP URI bad key", test_uri_parse, &bad_key);
+	l_test_add("DPP URI bad channels", test_bad_channels, &bad_channels);
+	l_test_add("DPP URI unexpected ID", test_uri_parse, &unexpected_id);
+
 	return l_test_run();
 }
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v6 3/9 dpp: manually register for some frame watches

In reply to James Prestwood

The frame watch which covers the presence procedure (and most frames for that matter) needs to support multicast frames for presence to work. Doing this in frame-xchg seems like the right choice but only ath9k supports multicast frame registration. Because of this limited support DPP will register for these frames manually.

---
 src/dpp.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 109 insertions(+), 7 deletions(-)
src/dpp.c +109 -7
index cedf5bfe..17c7425a 100644
@@ -61,6 +61,7 @@ static struct l_genl_family *nl80211;
 static uint8_t broadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 static struct l_queue *dpp_list;
 static uint32_t mlme_watch;
+static uint32_t unicast_watch;
 
 enum dpp_state {
 	DPP_STATE_NOTHING,
@@ -127,6 +128,8 @@ struct dpp_sm {
 	uint8_t frame_retry;
 
 	struct l_dbus_message *pending;
+
+	bool mcast_support : 1;
 };
 
 static void dpp_free_auth_data(struct dpp_sm *dpp)
@@ -1403,6 +1406,9 @@ static void authenticate_request(struct dpp_sm *dpp, const uint8_t *from,
 	const void *ad1 = body + 8;
 	uint32_t freq;
 
+	if (util_is_broadcast_address(from))
+		return;
+
 	if (dpp->state != DPP_STATE_PRESENCE)
 		return;
 
@@ -1577,11 +1583,10 @@ auth_request_failed:
 	dpp_free_auth_data(dpp);
 }
 
-static void dpp_handle_frame(const struct mmpdu_header *frame,
-				const void *body, size_t body_len,
-				int rssi, void *user_data)
+static void dpp_handle_frame(struct dpp_sm *dpp,
+				const struct mmpdu_header *frame,
+				const void *body, size_t body_len)
 {
-	struct dpp_sm *dpp = user_data;
 	const uint8_t *ptr;
 
 	/*
@@ -1664,6 +1669,94 @@ static void dpp_mlme_notify(struct l_genl_msg *msg, void *user_data)
 	dpp_send_frame(dpp, &iov, 1, dpp->current_freq);
 }
 
+static void dpp_unicast_notify(struct l_genl_msg *msg, void *user_data)
+{
+	struct dpp_sm *dpp;
+	const uint64_t *wdev_id = NULL;
+	struct l_genl_attr attr;
+	uint16_t type, len, frame_len;
+	const void *data;
+	const struct mmpdu_header *mpdu = NULL;
+	const uint8_t *body;
+
+	if (l_genl_msg_get_command(msg) != NL80211_CMD_FRAME)
+		return;
+
+	if (!l_genl_attr_init(&attr, msg))
+		return;
+
+	while (l_genl_attr_next(&attr, &type, &len, &data)) {
+		switch (type) {
+		case NL80211_ATTR_WDEV:
+			if (len != 8)
+				break;
+
+			wdev_id = data;
+			break;
+
+		case NL80211_ATTR_FRAME:
+			mpdu = mpdu_validate(data, len);
+			if (!mpdu) {
+				l_warn("Frame didn't validate as MMPDU");
+				return;
+			}
+
+			frame_len = len;
+			break;
+		}
+	}
+
+	if (!wdev_id) {
+		l_warn("Bad wdev attribute");
+		return;
+	}
+
+	dpp = l_queue_find(dpp_list, match_wdev, wdev_id);
+	if (!dpp)
+		return;
+
+	if (!mpdu) {
+		l_warn("Missing frame data");
+		return;
+	}
+
+	body = mmpdu_body(mpdu);
+
+	dpp_handle_frame(dpp, mpdu, body,
+				(const uint8_t *) mpdu + frame_len - body);
+}
+
+static void dpp_frame_watch_cb(struct l_genl_msg *msg, void *user_data)
+{
+	if (l_genl_msg_get_error(msg) < 0)
+		l_error("Could not register frame watch type %04x: %i",
+			L_PTR_TO_UINT(user_data), l_genl_msg_get_error(msg));
+}
+
+/*
+ * Special case the frame watch which includes the presence frames since they
+ * require multicast support. This is only supported by ath9k, so adding
+ * general support to frame-xchg isn't desireable.
+ */
+static void dpp_frame_watch(struct dpp_sm *dpp, uint16_t frame_type,
+				const uint8_t *prefix, size_t prefix_len)
+{
+	struct l_genl_msg *msg;
+
+	msg = l_genl_msg_new_sized(NL80211_CMD_REGISTER_FRAME, 32 + prefix_len);
+
+	l_genl_msg_append_attr(msg, NL80211_ATTR_WDEV, 8, &dpp->wdev_id);
+	l_genl_msg_append_attr(msg, NL80211_ATTR_FRAME_TYPE, 2, &frame_type);
+	l_genl_msg_append_attr(msg, NL80211_ATTR_FRAME_MATCH,
+				prefix_len, prefix);
+	if (dpp->mcast_support)
+		l_genl_msg_append_attr(msg, NL80211_ATTR_RECEIVE_MULTICAST,
+					0, NULL);
+
+	l_genl_family_send(nl80211, msg, dpp_frame_watch_cb,
+					L_UINT_TO_PTR(frame_type), NULL);
+}
+
 static void dpp_create(struct netdev *netdev)
 {
 	struct l_dbus *dbus = dbus_get_bus();
@@ -1678,6 +1771,9 @@ static void dpp_create(struct netdev *netdev)
 	dpp->curve = l_ecc_curve_from_ike_group(19);
 	dpp->key_len = l_ecc_curve_get_scalar_bytes(dpp->curve);
 	dpp->nonce_len = dpp_nonce_len_from_key_len(dpp->key_len);
+	dpp->mcast_support = wiphy_has_ext_feature(
+				wiphy_find_by_wdev(dpp->wdev_id),
+				NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS);
 
 	l_ecdh_generate_key_pair(dpp->curve, &dpp->boot_private,
 					&dpp->boot_public);
@@ -1690,9 +1786,8 @@ static void dpp_create(struct netdev *netdev)
 	l_dbus_object_add_interface(dbus, netdev_get_path(netdev),
 					IWD_DPP_INTERFACE, dpp);
 
-	frame_watch_add(netdev_get_wdev_id(netdev), 0, 0x00d0, dpp_prefix,
-				sizeof(dpp_prefix), dpp_handle_frame,
-				dpp, NULL);
+	dpp_frame_watch(dpp, 0x00d0, dpp_prefix, sizeof(dpp_prefix));
+
 	frame_watch_add(netdev_get_wdev_id(netdev), 0, 0x00d0,
 				dpp_conf_response_prefix,
 				sizeof(dpp_conf_response_prefix),
@@ -1935,6 +2030,11 @@ static int dpp_init(void)
 	mlme_watch = l_genl_family_register(nl80211, "mlme", dpp_mlme_notify,
 						NULL, NULL);
 
+	unicast_watch = l_genl_add_unicast_watch(iwd_get_genl(),
+						NL80211_GENL_NAME,
+						dpp_unicast_notify,
+						NULL, NULL);
+
 	dpp_list = l_queue_new();
 
 	return 0;
@@ -1948,6 +2048,8 @@ static void dpp_exit(void)
 
 	netdev_watch_remove(netdev_watch);
 
+	l_genl_remove_unicast_watch(iwd_get_genl(), unicast_watch);
+
 	l_genl_family_unregister(nl80211, mlme_watch);
 	mlme_watch = 0;
 
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH v6 4/9 dpp: add support for initiating as a configurator

In reply to James Prestwood

The difference between the existing code is that IWD will send the authentication request, making it the initiator.

This handles the use case where IWD is provided a peers URI containing its bootstrapping key rather than IWD always providing its own URI. A new DBus API was added, ConfigureEnrollee().

Using ConfigureEnrollee() IWD will act as a configurator but begin by traversing a channel list (URI provided or default) and waiting for presence announcements (with one caveat). When an announcement is received IWD will send an authentication request to the peer, receive its reply, and send an authentication confirm.

As with being a responder, IWD only supports configuration to the currently connected BSS and will request the enrollee switch to this BSS's frequency to preserve network performance.

The caveat here is that only one driver (ath9k) supports multicast frame registration which prevents presence frame from being received. In this case it will be required the the peer URI contains a MAC and channel information. This is because IWD will jump right into sending auth requests rather than waiting for a presence announcement.

---
 src/dpp.c | 496 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 486 insertions(+), 10 deletions(-)
src/dpp.c +486 -10
index 17c7425a..62790c0c 100644
@@ -84,15 +84,23 @@ struct dpp_sm {
 
 	uint8_t *own_asn1;
 	size_t own_asn1_len;
+	uint8_t *peer_asn1;
+	size_t peer_asn1_len;
 	uint8_t own_boot_hash[32];
+	uint8_t peer_boot_hash[32];
 	const struct l_ecc_curve *curve;
 	size_t key_len;
 	size_t nonce_len;
 	struct l_ecc_scalar *boot_private;
 	struct l_ecc_point *boot_public;
+	struct l_ecc_point *peer_boot_public;
 
 	enum dpp_state state;
 
+	/*
+	 * List of frequencies to jump between. The presence of this list is
+	 * also used to signify that a configurator is an initiator vs responder
+	 */
 	uint32_t *freqs;
 	size_t freqs_len;
 	size_t freqs_idx;
@@ -108,7 +116,9 @@ struct dpp_sm {
 	uint8_t i_nonce[32];
 	uint8_t e_nonce[32];
 
+	struct l_ecc_scalar *m;
 	uint64_t ke[L_ECC_MAX_DIGITS];
+	uint64_t k1[L_ECC_MAX_DIGITS];
 	uint64_t k2[L_ECC_MAX_DIGITS];
 	uint64_t auth_tag[L_ECC_MAX_DIGITS];
 
@@ -148,6 +158,16 @@ static void dpp_free_auth_data(struct dpp_sm *dpp)
 		l_ecc_point_free(dpp->peer_proto_public);
 		dpp->peer_proto_public = NULL;
 	}
+
+	if (dpp->peer_boot_public) {
+		l_ecc_point_free(dpp->peer_boot_public);
+		dpp->peer_boot_public = NULL;
+	}
+
+	if (dpp->m) {
+		l_ecc_scalar_free(dpp->m);
+		dpp->m = NULL;
+	}
 }
 
 static void dpp_reset(struct dpp_sm *dpp)
@@ -182,6 +202,11 @@ static void dpp_reset(struct dpp_sm *dpp)
 		dpp->connect_scan_id = 0;
 	}
 
+	if (dpp->peer_asn1) {
+		l_free(dpp->peer_asn1);
+		dpp->peer_asn1 = NULL;
+	}
+
 	dpp->state = DPP_STATE_NOTHING;
 	dpp->new_freq = 0;
 	dpp->frame_retry = 0;
@@ -191,6 +216,7 @@ static void dpp_reset(struct dpp_sm *dpp)
 	explicit_bzero(dpp->i_nonce, dpp->nonce_len);
 	explicit_bzero(dpp->e_nonce, dpp->nonce_len);
 	explicit_bzero(dpp->ke, dpp->key_len);
+	explicit_bzero(dpp->k1, dpp->key_len);
 	explicit_bzero(dpp->k2, dpp->key_len);
 	explicit_bzero(dpp->auth_tag, dpp->key_len);
 
@@ -1266,21 +1292,69 @@ static void dpp_presence_announce(struct dpp_sm *dpp)
 	dpp_send_frame(dpp, iov, 2, dpp->current_freq);
 }
 
+static void dpp_send_authenticate_request(struct dpp_sm *dpp)
+{
+	uint8_t hdr[32];
+	uint8_t attrs[256];
+	uint8_t *ptr = attrs;
+	uint64_t i_proto_key[L_ECC_MAX_DIGITS * 2];
+	uint8_t version = 2;
+	struct iovec iov[2];
+	struct station *station = station_find(netdev_get_ifindex(dpp->netdev));
+	struct scan_bss *bss = station_get_connected_bss(station);
+
+	l_ecc_point_get_data(dpp->own_proto_public, i_proto_key,
+				sizeof(i_proto_key));
+
+	iov[0].iov_len = dpp_build_header(netdev_get_address(dpp->netdev),
+				dpp->auth_addr,
+				DPP_FRAME_AUTHENTICATION_REQUEST, hdr);
+	iov[0].iov_base = hdr;
+
+	ptr += dpp_append_attr(ptr, DPP_ATTR_RESPONDER_BOOT_KEY_HASH,
+				dpp->peer_boot_hash, 32);
+	ptr += dpp_append_attr(ptr, DPP_ATTR_INITIATOR_BOOT_KEY_HASH,
+				dpp->own_boot_hash, 32);
+	ptr += dpp_append_attr(ptr, DPP_ATTR_INITIATOR_PROTOCOL_KEY,
+				i_proto_key, dpp->key_len * 2);
+	ptr += dpp_append_attr(ptr, DPP_ATTR_PROTOCOL_VERSION, &version, 1);
+
+	if (dpp->current_freq != bss->frequency) {
+		uint8_t pair[2] = { 81,
+				band_freq_to_channel(bss->frequency, NULL) };
+
+		ptr += dpp_append_attr(ptr, DPP_ATTR_CHANNEL, pair, 2);
+	}
+
+	ptr += dpp_append_wrapped_data(hdr + 26, 6, attrs, ptr - attrs,
+			ptr, sizeof(attrs), dpp->k1, dpp->key_len, 2,
+			DPP_ATTR_INITIATOR_NONCE, dpp->nonce_len, dpp->i_nonce,
+			DPP_ATTR_INITIATOR_CAPABILITIES, 1, &dpp->role);
+
+	iov[1].iov_base = attrs;
+	iov[1].iov_len = ptr - attrs;
+
+	dpp_send_frame(dpp, iov, 2, dpp->current_freq);
+}
+
 static void dpp_roc_started(void *user_data)
 {
 	struct dpp_sm *dpp = user_data;
 
 	/*
 	 * - If a configurator, nothing to do but wait for a request
+	 *   (unless multicast frame registration is unsupported in which case
+	 *   send an authenticate request now)
 	 * - If in the presence state continue sending announcements.
 	 * - If authenticating, and this is a result of a channel switch send
 	 *   the authenticate response now.
 	 */
-	if (dpp->role == DPP_CAPABILITY_CONFIGURATOR)
-		return;
 
 	switch (dpp->state) {
 	case DPP_STATE_PRESENCE:
+		if (dpp->role == DPP_CAPABILITY_CONFIGURATOR)
+			return;
+
 		if (dpp->pending) {
 			struct l_dbus_message *reply =
 				l_dbus_message_new_method_return(dpp->pending);
@@ -1293,6 +1367,19 @@ static void dpp_roc_started(void *user_data)
 		dpp_presence_announce(dpp);
 		break;
 	case DPP_STATE_AUTHENTICATING:
+		/*
+		 * No multicast frame registration support, jump right into
+		 * sending auth frames. This diverges from the 2.0 spec, but in
+		 * reality the the main path nearly all drivers will hit.
+		 */
+		if (dpp->role == DPP_CAPABILITY_CONFIGURATOR) {
+			if (dpp->mcast_support)
+				return;
+
+			dpp_send_authenticate_request(dpp);
+			return;
+		}
+
 		if (dpp->new_freq) {
 			dpp->current_freq = dpp->new_freq;
 			dpp->new_freq = 0;
@@ -1550,9 +1637,6 @@ static void authenticate_request(struct dpp_sm *dpp, const uint8_t *from,
 
 	/* Derive keys k2, ke, and R-Auth for authentication response */
 
-	l_ecdh_generate_key_pair(dpp->curve, &dpp->proto_private,
-					&dpp->own_proto_public);
-
 	n = dpp_derive_k2(dpp->peer_proto_public, dpp->proto_private, dpp->k2);
 	if (!n)
 		goto auth_request_failed;
@@ -1583,6 +1667,294 @@ auth_request_failed:
 	dpp_free_auth_data(dpp);
 }
 
+static void dpp_send_authenticate_confirm(struct dpp_sm *dpp)
+{
+	uint8_t hdr[32];
+	struct iovec iov[2];
+	uint8_t attrs[256];
+	uint8_t *ptr = attrs;
+	uint8_t zero = 0;
+
+	iov[0].iov_len = dpp_build_header(netdev_get_address(dpp->netdev),
+					dpp->auth_addr,
+					DPP_FRAME_AUTHENTICATION_CONFIRM, hdr);
+	iov[0].iov_base = hdr;
+
+	ptr += dpp_append_attr(ptr, DPP_ATTR_STATUS, &zero, 1);
+	ptr += dpp_append_attr(ptr, DPP_ATTR_RESPONDER_BOOT_KEY_HASH,
+					dpp->peer_boot_hash, 32);
+
+	ptr += dpp_append_wrapped_data(hdr + 26, 6, attrs, ptr - attrs, ptr,
+			sizeof(attrs), dpp->ke, dpp->key_len, 1,
+			DPP_ATTR_INITIATOR_AUTH_TAG, dpp->key_len,
+			dpp->auth_tag);
+
+	iov[1].iov_base = attrs;
+	iov[1].iov_len = ptr - attrs;
+
+	dpp_send_frame(dpp, iov, 2, dpp->current_freq);
+}
+
+static void authenticate_response(struct dpp_sm *dpp, const uint8_t *from,
+					const uint8_t *body, size_t body_len)
+{
+	struct dpp_attr_iter iter;
+	enum dpp_attribute_type type;
+	size_t len;
+	const uint8_t *data;
+	int status = -1;
+	const void *r_boot_hash = NULL;
+	const void *r_proto = NULL;
+	size_t r_proto_len = 0;
+	const void *wrapped = NULL;
+	size_t wrapped_len;
+	_auto_(l_free) uint8_t *unwrapped1 = NULL;
+	_auto_(l_free) uint8_t *unwrapped2 = NULL;
+	const void *r_nonce = NULL;
+	const void *i_nonce = NULL;
+	const void *r_auth = NULL;
+	_auto_(l_ecc_point_free) struct l_ecc_point *r_proto_key = NULL;
+	_auto_(l_ecc_scalar_free) struct l_ecc_scalar *n = NULL;
+	const void *ad0 = body + 2;
+	const void *ad1 = body + 8;
+	uint64_t r_auth_derived[L_ECC_MAX_DIGITS];
+
+	l_debug("Authenticate response");
+
+	if (dpp->state != DPP_STATE_AUTHENTICATING)
+		return;
+
+	if (dpp->role != DPP_CAPABILITY_CONFIGURATOR)
+		return;
+
+	if (!dpp->freqs)
+		return;
+
+	if (memcmp(from, dpp->auth_addr, 6))
+		return;
+
+	dpp_attr_iter_init(&iter, body + 8, body_len - 8);
+
+	while (dpp_attr_iter_next(&iter, &type, &len, &data)) {
+		switch (type) {
+		case DPP_ATTR_STATUS:
+			if (len != 1)
+				return;
+
+			status = l_get_u8(data);
+			break;
+		case DPP_ATTR_RESPONDER_BOOT_KEY_HASH:
+			r_boot_hash = data;
+			break;
+		case DPP_ATTR_RESPONDER_PROTOCOL_KEY:
+			r_proto = data;
+			r_proto_len = len;
+			break;
+		case DPP_ATTR_PROTOCOL_VERSION:
+			if (len != 1 || l_get_u8(data) != 2)
+				return;
+			break;
+		case DPP_ATTR_WRAPPED_DATA:
+			wrapped = data;
+			wrapped_len = len;
+			break;
+		default:
+			break;
+		}
+	}
+
+	if (status != DPP_STATUS_OK || !r_boot_hash || !r_proto ) {
+		l_debug("Auth response bad status or missing attributes");
+		return;
+	}
+
+	r_proto_key = l_ecc_point_from_data(dpp->curve, L_ECC_POINT_TYPE_FULL,
+						r_proto, r_proto_len);
+	if (!r_proto_key) {
+		l_debug("Peers protocol key was invalid");
+		return;
+	}
+
+	n = dpp_derive_k2(r_proto_key, dpp->proto_private, dpp->k2);
+
+	unwrapped1 = dpp_unwrap_attr(ad0, 6, ad1, wrapped - 4 - ad1, dpp->k2,
+					dpp->key_len, wrapped, wrapped_len,
+					&wrapped_len);
+	if (!unwrapped1) {
+		l_debug("Failed to unwrap primary data");
+		return;
+	}
+
+	wrapped = NULL;
+
+	dpp_attr_iter_init(&iter, unwrapped1, wrapped_len);
+
+	while (dpp_attr_iter_next(&iter, &type, &len, &data)) {
+		switch (type) {
+		case DPP_ATTR_RESPONDER_NONCE:
+			if (len != dpp->nonce_len)
+				return;
+
+			r_nonce = data;
+			break;
+		case DPP_ATTR_INITIATOR_NONCE:
+			if (len != dpp->nonce_len)
+				return;
+
+			i_nonce = data;
+			break;
+		case DPP_ATTR_RESPONDER_CAPABILITIES:
+			break;
+		case DPP_ATTR_WRAPPED_DATA:
+			wrapped = data;
+			wrapped_len = len;
+			break;
+		default:
+			break;
+		}
+	}
+
+	if (!r_nonce || !i_nonce || !wrapped) {
+		l_debug("Wrapped data missing attributes");
+		return;
+	}
+
+	if (!dpp_derive_ke(i_nonce, r_nonce, dpp->m, n, dpp->ke)) {
+		l_debug("Failed to derive ke");
+		return;
+	}
+
+	unwrapped2 = dpp_unwrap_attr(NULL, 0, NULL, 0, dpp->ke, dpp->key_len,
+					wrapped, wrapped_len, &wrapped_len);
+	if (!unwrapped2) {
+		l_debug("Failed to unwrap secondary data");
+		return;
+	}
+
+	dpp_attr_iter_init(&iter, unwrapped2, wrapped_len);
+
+	while (dpp_attr_iter_next(&iter, &type, &len, &data)) {
+		switch (type) {
+		case DPP_ATTR_RESPONDER_AUTH_TAG:
+			if (len != dpp->key_len)
+				return;
+
+			r_auth = data;
+			break;
+		default:
+			break;
+		}
+	}
+
+	if (!r_auth) {
+		l_debug("R-Auth was not in secondary wrapped data");
+		return;
+	}
+
+	if (!dpp_derive_r_auth(i_nonce, r_nonce, dpp->nonce_len,
+				dpp->own_proto_public, r_proto_key,
+				dpp->peer_boot_public, r_auth_derived)) {
+		l_debug("Failed to derive r_auth");
+		return;
+	}
+
+	if (memcmp(r_auth, r_auth_derived, dpp->key_len)) {
+		l_debug("R-Auth did not verify");
+		return;
+	}
+
+	if (!dpp_derive_i_auth(r_nonce, i_nonce, dpp->nonce_len,
+				r_proto_key, dpp->own_proto_public,
+				dpp->peer_boot_public, dpp->auth_tag)) {
+		l_debug("Could not derive I-Auth");
+		return;
+	}
+
+	dpp->current_freq = dpp->new_freq;
+
+	dpp_send_authenticate_confirm(dpp);
+}
+
+static void dpp_handle_presence_announcement(struct dpp_sm *dpp,
+						const uint8_t *from,
+						const uint8_t *body,
+						size_t body_len)
+{
+	struct dpp_attr_iter iter;
+	enum dpp_attribute_type type;
+	size_t len;
+	const uint8_t *data;
+	const void *r_boot = NULL;
+	size_t r_boot_len = 0;
+	uint8_t hash[32];
+
+	l_debug("Presence announcement "MAC, MAC_STR(from));
+
+	/* Must be a configurator, in an initiator role, in PRESENCE state */
+	if (dpp->state != DPP_STATE_PRESENCE)
+		return;
+
+	if (dpp->role != DPP_CAPABILITY_CONFIGURATOR)
+		return;
+
+	if (!dpp->freqs)
+		return;
+
+	/*
+	 * The URI may not have contained a MAC address, if this announcement
+	 * verifies set auth_addr then.
+	 */
+	if (!l_memeqzero(dpp->auth_addr, 6) &&
+				memcmp(from, dpp->auth_addr, 6)) {
+		l_debug("Unexpected source "MAC" expected "MAC, MAC_STR(from),
+						MAC_STR(dpp->auth_addr));
+		return;
+	}
+
+	dpp_attr_iter_init(&iter, body + 8, body_len - 8);
+
+	while (dpp_attr_iter_next(&iter, &type, &len, &data)) {
+		switch (type) {
+		case DPP_ATTR_RESPONDER_BOOT_KEY_HASH:
+			r_boot = data;
+			r_boot_len = len;
+			break;
+		default:
+			break;
+		}
+	}
+
+	if (!r_boot || r_boot_len != 32) {
+		l_debug("No responder boot hash");
+		return;
+	}
+
+	/* Hash what we have for the peer and check its our enrollee */
+	dpp_hash(L_CHECKSUM_SHA256, hash, 2, "chirp", strlen("chirp"),
+			dpp->peer_asn1, dpp->peer_asn1_len);
+
+	if (memcmp(hash, r_boot, sizeof(hash))) {
+		l_debug("Peers boot hash did not match");
+		return;
+	}
+
+	/*
+	 * This is the peer we expected, save away the address and derive the
+	 * initial keys.
+	 */
+	memcpy(dpp->auth_addr, from, 6);
+
+	dpp->state = DPP_STATE_AUTHENTICATING;
+
+	dpp_send_authenticate_request(dpp);
+
+	/*
+	 * Should we wait for an ACK then go offchannel?
+	 */
+	if (dpp->current_freq != dpp->new_freq)
+		dpp_start_offchannel(dpp, dpp->new_freq);
+}
+
 static void dpp_handle_frame(struct dpp_sm *dpp,
 				const struct mmpdu_header *frame,
 				const void *body, size_t body_len)
@@ -1603,6 +1975,9 @@ static void dpp_handle_frame(struct dpp_sm *dpp,
 	case DPP_FRAME_AUTHENTICATION_REQUEST:
 		authenticate_request(dpp, frame->address_2, body, body_len);
 		break;
+	case DPP_FRAME_AUTHENTICATION_RESPONSE:
+		authenticate_response(dpp, frame->address_2, body, body_len);
+		break;
 	case DPP_FRAME_AUTHENTICATION_CONFIRM:
 		authenticate_confirm(dpp, frame->address_2, body, body_len);
 		break;
@@ -1610,6 +1985,10 @@ static void dpp_handle_frame(struct dpp_sm *dpp,
 		dpp_handle_config_result_frame(dpp, frame->address_2,
 						body, body_len);
 		break;
+	case DPP_FRAME_PRESENCE_ANNOUNCEMENT:
+		dpp_handle_presence_announcement(dpp, frame->address_2,
+							body, body_len);
+		break;
 	default:
 		l_debug("Unhandled DPP frame %u", *ptr);
 		break;
@@ -1911,6 +2290,9 @@ static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
 	dpp->state = DPP_STATE_PRESENCE;
 	dpp->role = DPP_CAPABILITY_ENROLLEE;
 
+	l_ecdh_generate_key_pair(dpp->curve, &dpp->proto_private,
+					&dpp->own_proto_public);
+
 	l_debug("DPP Start Enrollee: %s", dpp->uri);
 
 	dpp->pending = l_dbus_message_ref(message);
@@ -1927,9 +2309,66 @@ static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
 	return NULL;
 }
 
-static struct l_dbus_message *dpp_dbus_start_configurator(struct l_dbus *dbus,
+/*
+ * Set up the configurator for an initiator role. The configurator
+ * will go offchannel to frequencies advertised by the enrollees URI or,
+ * if no channels are provided, use a default channel list.
+ */
+static bool dpp_configurator_start_presence(struct dpp_sm *dpp, const char *uri)
+{
+	_auto_(l_free) uint32_t *freqs = NULL;
+	size_t freqs_len = 0;
+	struct dpp_uri_info *info;
+
+	info = dpp_parse_uri(uri);
+	if (!info)
+		return false;
+
+	/*
+	 * Very few drivers actually support registration of multicast frames.
+	 * This renders the presence procedure impossible on most drivers.
+	 * But not all is lost. If the URI contains the MAC and channel
+	 * info we an start going through channels sending auth requests which
+	 * is basically DPP 1.0. Otherwise DPP cannot start.
+	 */
+	if (!dpp->mcast_support &&
+				(l_memeqzero(info->mac, 6) || !info->freqs)) {
+		l_error("No multicast registration support, URI must contain "
+			"MAC and channel information");
+		dpp_free_uri_info(info);
+		return false;
+	}
+
+	if (!l_memeqzero(info->mac, 6))
+		memcpy(dpp->auth_addr, info->mac, 6);
+
+	if (info->freqs)
+		freqs = scan_freq_set_to_fixed_array(info->freqs, &freqs_len);
+
+	dpp->peer_boot_public = l_ecc_point_clone(info->boot_public);
+	dpp->peer_asn1 = dpp_point_to_asn1(info->boot_public,
+						&dpp->peer_asn1_len);
+
+	dpp_free_uri_info(info);
+
+	if (!dpp->peer_asn1) {
+		l_debug("Peer boot key did not convert to asn1");
+		return false;
+	}
+
+	dpp_hash(L_CHECKSUM_SHA256, dpp->peer_boot_hash, 1, dpp->peer_asn1,
+			dpp->peer_asn1_len);
+
+	dpp_start_presence(dpp, freqs, freqs_len);
+
+	return true;
+}
+
+static struct l_dbus_message *dpp_start_configurator_common(
+						struct l_dbus *dbus,
 						struct l_dbus_message *message,
-						void *user_data)
+						void *user_data,
+						bool responder)
 {
 	struct dpp_sm *dpp = user_data;
 	struct l_dbus_message *reply;
@@ -1938,6 +2377,7 @@ static struct l_dbus_message *dpp_dbus_start_configurator(struct l_dbus *dbus,
 	struct network *network;
 	struct l_settings *settings;
 	struct handshake_state *hs = netdev_get_handshake(dpp->netdev);
+	const char *uri;
 
 	/*
 	 * For now limit the configurator to only configuring enrollees to the
@@ -1961,13 +2401,33 @@ static struct l_dbus_message *dpp_dbus_start_configurator(struct l_dbus *dbus,
 	if (dpp->state != DPP_STATE_NOTHING)
 		return dbus_error_busy(message);
 
+	l_ecdh_generate_key_pair(dpp->curve, &dpp->proto_private,
+					&dpp->own_proto_public);
+
+	dpp->state = DPP_STATE_PRESENCE;
+
+	if (!responder) {
+		if (!l_dbus_message_get_arguments(message, "s", &uri))
+			return dbus_error_invalid_args(message);
+
+		if (!dpp_configurator_start_presence(dpp, uri))
+			return dbus_error_invalid_args(message);
+
+		/* Since we have the peer's URI generate the keys now */
+		l_getrandom(dpp->i_nonce, dpp->nonce_len);
+
+		dpp->m = dpp_derive_k1(dpp->peer_boot_public,
+					dpp->proto_private, dpp->k1);
+
+		if (!dpp->mcast_support)
+			dpp->state = DPP_STATE_AUTHENTICATING;
+	} else
+		dpp->current_freq = bss->frequency;
+
 	dpp->uri = dpp_generate_uri(dpp->own_asn1, dpp->own_asn1_len, 2,
 					netdev_get_address(dpp->netdev),
 					&bss->frequency, 1, NULL, NULL);
-
-	dpp->state = DPP_STATE_PRESENCE;
 	dpp->role = DPP_CAPABILITY_CONFIGURATOR;
-	dpp->current_freq = bss->frequency;
 	dpp->config = dpp_configuration_new(settings,
 						network_get_ssid(network),
 						hs->akm_suite);
@@ -1983,6 +2443,20 @@ static struct l_dbus_message *dpp_dbus_start_configurator(struct l_dbus *dbus,
 	return reply;
 }
 
+static struct l_dbus_message *dpp_dbus_start_configurator(struct l_dbus *dbus,
+						struct l_dbus_message *message,
+						void *user_data)
+{
+	return dpp_start_configurator_common(dbus, message, user_data, true);
+}
+
+static struct l_dbus_message *dpp_dbus_configure_enrollee(struct l_dbus *dbus,
+						struct l_dbus_message *message,
+						void *user_data)
+{
+	return dpp_start_configurator_common(dbus, message, user_data, false);
+}
+
 static struct l_dbus_message *dpp_dbus_stop(struct l_dbus *dbus,
 						struct l_dbus_message *message,
 						void *user_data)
@@ -2000,6 +2474,8 @@ static void dpp_setup_interface(struct l_dbus_interface *interface)
 				dpp_dbus_start_enrollee, "s", "", "uri");
 	l_dbus_interface_method(interface, "StartConfigurator", 0,
 				dpp_dbus_start_configurator, "s", "", "uri");
+	l_dbus_interface_method(interface, "ConfigureEnrollee", 0,
+				dpp_dbus_configure_enrollee, "", "s", "uri");
 	l_dbus_interface_method(interface, "Stop", 0,
 				dpp_dbus_stop, "", "");
 }
Signature · 1 line
2.34.1
author
#4 lore raw

PATCH v6 5/9 auto-t: iwd.py: allow passing uri to start_configurator

In reply to James Prestwood

If a URI is passed this will envoke ConfigureEnrollee()

---
 autotests/util/iwd.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
autotests/util/iwd.py +7 -4
index 170dd96b..d6620da5 100755
@@ -280,8 +280,11 @@ class DeviceProvisioning(IWDDBusAbstract):
     def start_enrollee(self):
         return self._iface.StartEnrollee()
 
-    def start_configurator(self):
-        return self._iface.StartConfigurator()
+    def start_configurator(self, uri=None):
+        if uri:
+            return self._iface.ConfigureEnrollee(uri)
+        else:
+            return self._iface.StartConfigurator()
 
     def stop(self):
         self._iface.Stop()
@@ -668,8 +671,8 @@ class Device(IWDDBusAbstract):
     def dpp_start_enrollee(self):
         return self._device_provisioning.start_enrollee()
 
-    def dpp_start_configurator(self):
-        return self._device_provisioning.start_configurator()
+    def dpp_start_configurator(self, uri=None):
+        return self._device_provisioning.start_configurator(uri)
 
     def dpp_stop(self):
         return self._device_provisioning.stop()
Signature · 1 line
2.34.1
author
#5 lore raw

PATCH v6 6/9 auto-t: wpas.py: allow arbitrary events to be handled

In reply to James Prestwood

If an event is in response to some command which is returning an unexpected value (unexpected with respect to wpas.py) handle_eow would raise an exception.

Specifically with DPP this was being hit when the URI was being returned.

---
 autotests/util/wpas.py | 2 --
 1 file changed, 2 deletions(-)
autotests/util/wpas.py +0 -2
index 6b845232..c8e65179 100644
@@ -88,8 +88,6 @@ class Wpas:
         def handle_eow():
             nonlocal key, value, count, event
             if count == 0:
-                if key is not None or not value:
-                    raise Exception('Bad event name')
                 key = 'event'
             elif key is None:
                 if not value:
Signature · 1 line
2.34.1
author
#6 lore raw

PATCH v6 7/9 auto-t: wpas.py: handle enrollee as responder

In reply to James Prestwood

This adds support for wpa_supplicant to generate its own URI and start presence announcements (DPP_CHIRP).

---
 autotests/util/wpas.py | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
autotests/util/wpas.py +14 -3
index c8e65179..995bdad1 100644
@@ -239,10 +239,17 @@ class Wpas:
     def set(self, key, value, **kwargs):
         self._ctrl_request('SET ' + key + ' ' + value, **kwargs)
 
-    def dpp_enrollee_start(self, uri=None):
+    def dpp_enrollee_start(self, uri=None, oper_and_channel=None):
+        if not oper_and_channel:
+            oper_and_channel = '81/1'
+
         self._rx_data = []
-        self._ctrl_request('DPP_BOOTSTRAP_GEN type=qrcode')
-        self.wait_for_result()
+        self._ctrl_request('DPP_BOOTSTRAP_GEN type=qrcode chan=%s' % oper_and_channel)
+        self._dpp_qr_id = self.wait_for_result()
+        self._ctrl_request('DPP_BOOTSTRAP_GET_URI %s' % self._dpp_qr_id)
+        self._dpp_uri = self.wait_for_result()
+
+        print("DPP Enrollee QR: %s" % self._dpp_uri)
 
         if uri:
             self._rx_data = []
@@ -250,6 +257,10 @@ class Wpas:
             self._dpp_qr_id = self.wait_for_result()
             self._rx_data = []
             self._ctrl_request('DPP_AUTH_INIT peer=%s role=enrollee' % self._dpp_qr_id)
+        else:
+            self._ctrl_request('DPP_CHIRP own=%s iter=100' % self._dpp_qr_id)
+
+        return self._dpp_uri
 
     def dpp_configurator_create(self, uri):
         self._rx_data = []
Signature · 1 line
2.34.1
author
#7 lore raw

PATCH v6 8/9 auto-t: add test for IWD as configurator + initiator

In reply to James Prestwood
---
 autotests/testDPP/connection_test.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
autotests/testDPP/connection_test.py +16 -0
index a451d584..b58620b8 100644
@@ -82,6 +82,22 @@ class Test(unittest.TestCase):
 
         self.wpas.wait_for_event('DPP-CONF-RECEIVED')
 
+    def test_iwd_as_configurator_initiator(self):
+        self.hapd.reload()
+        self.hapd.wait_for_event('AP-ENABLED')
+
+        IWD.copy_to_storage('ssidCCMP.psk')
+        self.device.autoconnect = True
+
+        condition = 'obj.state == DeviceState.connected'
+        self.wd.wait_for_object_condition(self.device, condition)
+
+        uri = self.wpas.dpp_enrollee_start(oper_and_channel='81/2')
+
+        self.device.dpp_start_configurator(uri)
+
+        self.hapd.wait_for_event('AP-STA-CONNECTED 42:00:00:00:00:00')
+
     def setUp(self):
         self.wd = IWD(True)
         self.device = self.wd.list_devices(1)[0]
Signature · 1 line
2.34.1
author
#8 lore raw

PATCH v6 9/9 doc: document DPP ConfigureEnrollee()

In reply to James Prestwood
---
 doc/device-provisioning-api.txt | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
doc/device-provisioning-api.txt +16 -0
index bf54c5fe..529aeeb0 100644
@@ -37,3 +37,19 @@ Methods		string StartEnrollee()
 						net.connman.iwd.NotConfigured
 						net.connman.iwd.NotSupported
 						net.connman.iwd.Busy
+
+		string ConfigureEnrollee(string uri)
+
+			Start a DPP configurator with an enrollees URI.
+			Ultimately the configuration itself remains the same as
+			StartConfigurator(). This API is to handle the use case
+			where the enrollee has shared its URI to IWD.
+
+			The URI for IWD is also returned which could be used
+			in the same way as it is with StartConfigurator().
+
+			Possible errors:	net.connman.iwd.NotAvailable
+						net.connman.iwd.NotConnected
+						net.connman.iwd.NotConfigured
+						net.connman.iwd.NotSupported
+						net.connman.iwd.Busy
Signature · 1 line
2.34.1