Skip to contentSkip to conversation

auto-t: update wpas.py to use non_block_wait

PATCH In review James Prestwood 2 participants 17 messages Jan 12, 2022

lore
Share & tools
lore

James Prestwood

author
#0 lore raw

PATCH 1/10 auto-t: update wpas.py to use non_block_wait

This should be used as a replacement for the common GLib wait loop (internally this is all it does).

---
 autotests/util/wpas.py | 31 +++++++++++--------------------
 1 file changed, 11 insertions(+), 20 deletions(-)
autotests/util/wpas.py +11 -20
index c26f116c..0caa947f 100644
@@ -58,29 +58,20 @@ class Wpas:
         f.close()
         return dict([[v.strip() for v in kv] for kv in [l.split('#', 1)[0].split('=', 1) for l in lines] if len(kv) == 2])
 
-    def wait_for_event(self, event, timeout=10):
-        self._wait_timed_out = False
-
-        def wait_timeout_cb():
-            self._wait_timed_out = True
-            return False
-
-        timeout = GLib.timeout_add_seconds(timeout, wait_timeout_cb)
-        context = ctx.mainloop.get_context()
+    def _check_event(self, event):
+        if not event and len(self._rx_data) >= 1:
+            print("returning %s" % self._rx_data[0])
+            return self._rx_data[0]
 
-        while True:
-            context.iteration(may_block=True)
+        for e in self._rx_data:
+            if event in e:
+                return self._rx_data
 
-            if not event and len(self._rx_data) >= 1:
-                return self._rx_data[0]
+        return False
 
-            for e in self._rx_data:
-                if event in e:
-                    GLib.source_remove(timeout)
-                    return self._rx_data
-
-            if self._wait_timed_out:
-                raise TimeoutError('waiting for wpas event timed out')
+    def wait_for_event(self, event, timeout=10):
+        self._rx_data = []
+        return ctx.non_block_wait(self._check_event, timeout, event)
 
     def wait_for_result(self, timeout=10):
         self._rx_data = []
Signature · 1 line
2.31.1
author
#1 lore raw

PATCH 2/10 auto-t: wpas.py: read DPP event until expected result

Controlling wpa_supplicant/hostapd from a text based interface is problematic in that there is no way of knowing if an event corresponds to a request. In certain cases if wpa_s/hostapd is sending out multiple events and we make a request, a random event may come back after the request, but before the actual result.

To fix this, at least for this specific case, we can continue to read from the socket until the result is numeric.

---
 autotests/util/wpas.py | 10 ++++++++++
 1 file changed, 10 insertions(+)
autotests/util/wpas.py +10 -0
index 0caa947f..2e50eb58 100644
@@ -242,19 +242,29 @@ class Wpas:
         self._ctrl_request('SET ' + key + ' ' + value, **kwargs)
 
     def dpp_enrollee_start(self, uri=None):
+        self._rx_data = []
         self._ctrl_request('DPP_BOOTSTRAP_GEN type=qrcode')
         self.wait_for_result()
 
         if uri:
+            self._rx_data = []
             self._ctrl_request('DPP_QR_CODE ' + uri)
             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)
 
     def dpp_configurator_create(self, uri):
+        self._rx_data = []
         self._ctrl_request('DPP_CONFIGURATOR_ADD')
         self._dpp_conf_id = self.wait_for_result()
+        while not self._dpp_conf_id.isnumeric():
+            self._dpp_conf_id = self.wait_for_result()
+
+        self._rx_data = []
         self._ctrl_request('DPP_QR_CODE ' + uri)
         self._dpp_qr_id = self.wait_for_result()
+        while not self._dpp_conf_id.isnumeric():
+            self._dpp_qr_id = self.wait_for_result()
 
         print("DPP Configurator ID: %s. DPP QR ID: %s" % (self._dpp_conf_id, self._dpp_qr_id))
 
Signature · 1 line
2.31.1
author
#2 lore raw

PATCH 3/10 dpp: don't send StartEnrollee reply until offchannel starts

In reply to James Prestwood

IWD may be in the middle of some long operation, e.g. scanning. If the URI is returned before IWD is ready, a configurator could start sending frames and IWD either wont receive them, or will be unable to respond quickly.

---
 src/dpp.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
src/dpp.c +14 -6
index 98d2a75c..c10ec978 100644
@@ -118,6 +118,8 @@ struct dpp_sm {
 
 	struct dpp_configuration *config;
 	uint32_t connect_scan_id;
+
+	struct l_dbus_message *message;
 };
 
 static void dpp_free_auth_data(struct dpp_sm *dpp)
@@ -1257,6 +1259,15 @@ static void dpp_roc_started(void *user_data)
 
 	switch (dpp->state) {
 	case DPP_STATE_PRESENCE:
+		if (dpp->message) {
+			struct l_dbus_message *reply =
+				l_dbus_message_new_method_return(dpp->message);
+
+			l_dbus_message_set_arguments(reply, "s", dpp->uri);
+
+			dbus_pending_reply(&dpp->message, reply);
+		}
+
 		dpp_presence_announce(dpp);
 		break;
 	case DPP_STATE_AUTHENTICATING:
@@ -1694,7 +1705,6 @@ static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
 {
 	struct dpp_sm *dpp = user_data;
 	uint32_t freq = band_channel_to_freq(6, BAND_FREQ_2_4_GHZ);
-	struct l_dbus_message *reply;
 	struct station *station = station_find(netdev_get_ifindex(dpp->netdev));
 
 	if (dpp->state != DPP_STATE_NOTHING)
@@ -1720,6 +1730,8 @@ static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
 
 	l_debug("DPP Start Enrollee: %s", dpp->uri);
 
+	dpp->message = l_dbus_message_ref(message);
+
 	/*
 	 * Going off spec here. Select a single channel to send presence
 	 * announcements on. This will be advertised in the URI. The full
@@ -1727,11 +1739,7 @@ static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
 	 */
 	dpp_start_presence(dpp, &freq, 1);
 
-	reply = l_dbus_message_new_method_return(message);
-
-	l_dbus_message_set_arguments(reply, "s", dpp->uri);
-
-	return reply;
+	return NULL;
 }
 
 static struct l_dbus_message *dpp_dbus_start_configurator(struct l_dbus *dbus,
Signature · 1 line
2.31.1
#3 lore raw

Re: [PATCH 03/10] dpp: don't send StartEnrollee reply until offchannel starts

Hi James,

Quoted 13 lines · James Prestwood

IWD may be in the middle of some long operation, e.g. scanning. If the URI is returned before IWD is ready, a configurator could start sending frames and IWD either wont receive them, or will be unable to respond quickly.

---
  src/dpp.c | 20 ++++++++++++++------
  1 file changed, 14 insertions(+), 6 deletions(-)
src/dpp.c +0 -0
index 98d2a75c..c10ec978 100644

src/dpp.c struct dpp_sm { · line 122

Quoted 5 lines
src/dpp.c +2 -0
@@ -118,6 +118,8 @@ struct dpp_sm {
 
  	struct dpp_configuration *config;
  	uint32_t connect_scan_id;
+
+	struct l_dbus_message *message;

We customarily call this member 'pending', so I changed this naming and applied.

Regards,
-Denis

author
#4 lore raw

PATCH 4/10 dpp: put no station device print behind else if

In reply to James Prestwood

The previous (incorrect) else was removed since it ended up printing in most cases since the if clause returned. This should have been an else if conditional from the start and only print if the station device was not found.

---
 src/dpp.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
src/dpp.c +2 -3
index c10ec978..5e07a61a 100644
@@ -1717,9 +1717,8 @@ static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
 	if (station && station_get_connected_network(station)) {
 		l_warn("cannot be enrollee while connected, please disconnect");
 		return dbus_error_busy(message);
-	}
-
-	l_debug("No station device, continuing anyways...");
+	} else if (!station)
+		l_debug("No station device, continuing anyways...");
 
 	dpp->uri = dpp_generate_uri(dpp->pub_asn1, dpp->pub_asn1_len, 2,
 					netdev_get_address(dpp->netdev), &freq,
Signature · 1 line
2.31.1
#5 lore raw

Re: [PATCH 04/10] dpp: put no station device print behind else if

Hi James,

Quoted 8 lines · James Prestwood

The previous (incorrect) else was removed since it ended up printing in most cases since the if clause returned. This should have been an else if conditional from the start and only print if the station device was not found.

---
  src/dpp.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)

Patches 4 and 5 applied, thanks.

Regards,
-Denis

author
#6 lore raw

PATCH 5/10 dpp: rework order of operations after being configured

In reply to James Prestwood

Now the result is sent immediately. Prior a connect attempt or scan could have started, potentially losing this frame. In addition the offchannel operation is cancelled after sending the result which will allow the subsequent connect or scan to happen much faster since it doesn't have to wait for ROC to expire.

---
 src/dpp.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
src/dpp.c +7 -7
index 5e07a61a..e0ae8aa6 100644
@@ -639,6 +639,11 @@ static void dpp_handle_config_response_frame(const struct mmpdu_header *frame,
 	}
 
 	dpp_write_config(config, network);
+	dpp_configuration_free(config);
+
+	send_config_result(dpp, dpp->auth_addr);
+
+	offchannel_cancel(dpp->wdev_id, dpp->offchannel_id);
 
 	if (network && bss)
 		__station_connect_network(station, network, bss);
@@ -647,15 +652,10 @@ static void dpp_handle_config_response_frame(const struct mmpdu_header *frame,
 						dpp_scan_triggered,
 						dpp_scan_results, dpp,
 						dpp_scan_destroy);
-		if (!dpp->connect_scan_id)
-			goto scan_failed;
+		if (dpp->connect_scan_id)
+			return;
 	}
 
-	dpp_configuration_free(config);
-
-	send_config_result(dpp, dpp->auth_addr);
-
-scan_failed:
 	dpp_reset(dpp);
 }
 
Signature · 1 line
2.31.1
author
#7 lore raw

PATCH 6/10 dpp: pass dpp_sm to dpp_send_frame

In reply to James Prestwood

The SM has the wdev_id already, so rather than using that or looking up just pass the dpp_sm directly.

---
 src/dpp.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)
src/dpp.c +9 -11
index e0ae8aa6..c22788e7 100644
@@ -213,20 +213,20 @@ static void dpp_send_frame_cb(struct l_genl_msg *msg, void *user_data)
 		l_error("Error sending frame");
 }
 
-static void dpp_send_frame(uint64_t wdev_id, struct iovec *iov, size_t iov_len,
+static void dpp_send_frame(struct dpp_sm *dpp, struct iovec *iov, size_t iov_len,
 			uint32_t freq)
 {
 	struct l_genl_msg *msg;
 
 	msg = l_genl_msg_new_sized(NL80211_CMD_FRAME, 512);
-	l_genl_msg_append_attr(msg, NL80211_ATTR_WDEV, 8, &wdev_id);
+	l_genl_msg_append_attr(msg, NL80211_ATTR_WDEV, 8, &dpp->wdev_id);
 	l_genl_msg_append_attr(msg, NL80211_ATTR_WIPHY_FREQ, 4, &freq);
 	l_genl_msg_append_attr(msg, NL80211_ATTR_OFFCHANNEL_TX_OK, 0, NULL);
 	l_genl_msg_append_attrv(msg, NL80211_ATTR_FRAME, iov, iov_len);
 
 	l_debug("Sending frame on frequency %u", freq);
 
-	if (!l_genl_family_send(nl80211, msg, dpp_send_frame_cb, NULL, NULL)) {
+	if (!l_genl_family_send(nl80211, msg, dpp_send_frame_cb, dpp, NULL)) {
 		l_error("Could not send CMD_FRAME");
 		l_genl_msg_unref(msg);
 	}
@@ -378,7 +378,7 @@ static void dpp_configuration_start(struct dpp_sm *dpp, const uint8_t *addr)
 
 	dpp->state = DPP_STATE_CONFIGURING;
 
-	dpp_send_frame(dpp->wdev_id, iov, 2, dpp->current_freq);
+	dpp_send_frame(dpp, iov, 2, dpp->current_freq);
 }
 
 static void send_config_result(struct dpp_sm *dpp, const uint8_t *to)
@@ -401,7 +401,7 @@ static void send_config_result(struct dpp_sm *dpp, const uint8_t *to)
 	iov[1].iov_base = attrs;
 	iov[1].iov_len = ptr - attrs;
 
-	dpp_send_frame(dpp->wdev_id, iov, 2, dpp->current_freq);
+	dpp_send_frame(dpp, iov, 2, dpp->current_freq);
 }
 
 static void dpp_write_config(struct dpp_configuration *config,
@@ -730,7 +730,7 @@ static void dpp_send_config_response(struct dpp_sm *dpp, uint8_t status)
 	iov[1].iov_base = attrs;
 	iov[1].iov_len = ptr - attrs;
 
-	dpp_send_frame(dpp->wdev_id, iov, 2, dpp->current_freq);
+	dpp_send_frame(dpp, iov, 2, dpp->current_freq);
 }
 
 static void dpp_handle_config_request_frame(const struct mmpdu_header *frame,
@@ -1033,8 +1033,7 @@ static void send_authenticate_response(struct dpp_sm *dpp)
 	iov[1].iov_base = attrs;
 	iov[1].iov_len = ptr - attrs;
 
-	dpp_send_frame(netdev_get_wdev_id(dpp->netdev), iov, 2,
-				dpp->current_freq);
+	dpp_send_frame(dpp, iov, 2, dpp->current_freq);
 }
 
 static void authenticate_confirm(struct dpp_sm *dpp, const uint8_t *from,
@@ -1200,8 +1199,7 @@ static void dpp_auth_request_failed(struct dpp_sm *dpp,
 	iov[1].iov_base = attrs;
 	iov[1].iov_len = ptr - attrs;
 
-	dpp_send_frame(netdev_get_wdev_id(dpp->netdev), iov, 2,
-				dpp->current_freq);
+	dpp_send_frame(dpp, iov, 2, dpp->current_freq);
 }
 
 static bool dpp_check_roles(struct dpp_sm *dpp, uint8_t peer_capa)
@@ -1241,7 +1239,7 @@ static void dpp_presence_announce(struct dpp_sm *dpp)
 	l_debug("Sending presense annoucement on frequency %u and waiting %u",
 		dpp->current_freq, dpp->dwell);
 
-	dpp_send_frame(netdev_get_wdev_id(netdev), iov, 2, dpp->current_freq);
+	dpp_send_frame(dpp, iov, 2, dpp->current_freq);
 }
 
 static void dpp_roc_started(void *user_data)
Signature · 1 line
2.31.1
#8 lore raw

Re: [PATCH 06/10] dpp: pass dpp_sm to dpp_send_frame

Hi James,

Quoted 6 lines · James Prestwood

The SM has the wdev_id already, so rather than using that or looking up just pass the dpp_sm directly.

---
  src/dpp.c | 20 +++++++++-----------
  1 file changed, 9 insertions(+), 11 deletions(-)

<snip>

src/dpp.c static void dpp_send_frame_cb(struct l_genl_msg *msg, void *user_data) · line 217

Quoted 4 lines
src/dpp.c +1 -1
-static void dpp_send_frame(uint64_t wdev_id, struct iovec *iov, size_t iov_len,
+static void dpp_send_frame(struct dpp_sm *dpp, struct iovec *iov, size_t iov_len,
  			uint32_t freq)

I fixed up this line being > 80 chars and applied, thanks.

Regards,
-Denis

author
#9 lore raw

PATCH 7/10 dpp: support retransmitting frames with no ACK

In reply to James Prestwood

The DPP spec says nothing about how to handle re-transmits but it was found in testing this can happen relatively easily for a few reasons.

If the configurator requests a channel switch but does not get onto the new channel quick enough the enrollee may have already sent the authenticate response and it was missed. Also by nature of how the kernel goes offchannel there are moments in time between ROC when the card is idle and not receiving any frames.

Only frames where there was no ACK will be retransmitted. If the peer received the frame and dropped it resending the same frame wont do any good.

---
 src/dpp.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 94 insertions(+), 1 deletion(-)
src/dpp.c +94 -1
index c22788e7..a4cc315b 100644
@@ -52,6 +52,9 @@
 #include "src/scan.h"
 #include "src/network.h"
 #include "src/handshake.h"
+#include "src/nl80211util.h"
+
+#define DPP_FRAME_MAX_RETRIES 5
 
 static uint32_t netdev_watch;
 static struct l_genl_family *nl80211;
@@ -118,6 +121,9 @@ struct dpp_sm {
 
 	struct dpp_configuration *config;
 	uint32_t connect_scan_id;
+	uint64_t frame_cookie;
+	uint32_t mlme_watch;
+	uint8_t frame_retry;
 
 	struct l_dbus_message *message;
 };
@@ -174,6 +180,7 @@ static void dpp_reset(struct dpp_sm *dpp)
 
 	dpp->state = DPP_STATE_NOTHING;
 	dpp->new_freq = 0;
+	dpp->frame_retry = 0;
 
 	explicit_bzero(dpp->r_nonce, dpp->nonce_len);
 	explicit_bzero(dpp->i_nonce, dpp->nonce_len);
@@ -204,13 +211,26 @@ static void dpp_free(struct dpp_sm *dpp)
 		dpp->boot_private = NULL;
 	}
 
+	if (dpp->mlme_watch) {
+		l_genl_family_unregister(nl80211, dpp->mlme_watch);
+		dpp->mlme_watch = 0;
+	}
+
 	l_free(dpp);
 }
 
 static void dpp_send_frame_cb(struct l_genl_msg *msg, void *user_data)
 {
-	if (l_genl_msg_get_error(msg) < 0)
+	struct dpp_sm *dpp = user_data;
+
+	if (l_genl_msg_get_error(msg) < 0) {
 		l_error("Error sending frame");
+		return;
+	}
+
+	if (nl80211_parse_attrs(msg, NL80211_ATTR_COOKIE, &dpp->frame_cookie,
+				NL80211_ATTR_UNSPEC) < 0)
+		l_error("Error parsing frame cookie");
 }
 
 static void dpp_send_frame(struct dpp_sm *dpp, struct iovec *iov, size_t iov_len,
@@ -1575,6 +1595,76 @@ static void dpp_handle_frame(const struct mmpdu_header *frame,
 	}
 }
 
+static void dpp_mlme_notify(struct l_genl_msg *msg, void *user_data)
+{
+	struct dpp_sm *dpp = user_data;
+	uint64_t wdev_id = 0;
+	uint64_t cookie = 0;
+	bool ack = false;
+	struct l_genl_attr attr;
+	const void *data;
+	uint16_t len;
+	uint16_t type;
+	const void *frame = NULL;
+	uint16_t frame_len = 0;
+	struct iovec iov;
+	uint8_t cmd = l_genl_msg_get_command(msg);
+
+	if (cmd != NL80211_CMD_FRAME_TX_STATUS)
+		return;
+
+	if (dpp->state <= DPP_STATE_PRESENCE)
+		return;
+
+	l_genl_attr_init(&attr, msg);
+
+	while (l_genl_attr_next(&attr, &type, &len, &data)) {
+		switch (type) {
+		case NL80211_ATTR_WDEV:
+			if (len != 8)
+				return;
+
+			wdev_id = l_get_u64(data);
+			break;
+		case NL80211_ATTR_COOKIE:
+			if (len != 8)
+				return;
+
+			cookie = l_get_u64(data);
+			break;
+		case NL80211_ATTR_ACK:
+			ack = true;
+			break;
+		case NL80211_ATTR_FRAME:
+			frame = data;
+			frame_len = len;
+			break;
+		}
+	}
+
+	/*
+	 * Only want to handle the no-ACK case. Re-transmitting an ACKed
+	 * frame likely wont do any good, at least in the case of DPP.
+	 */
+	if (dpp->wdev_id != wdev_id || dpp->frame_cookie != cookie ||
+				ack || !frame)
+		return;
+
+	if (dpp->frame_retry > DPP_FRAME_MAX_RETRIES) {
+		dpp_reset(dpp);
+		return;
+	}
+
+	iov.iov_base = (void *)frame;
+	iov.iov_len = frame_len;
+
+	l_debug("No ACK from peer, re-transmitting");
+
+	dpp->frame_retry++;
+
+	dpp_send_frame(dpp, &iov, 1, dpp->current_freq);
+}
+
 static void dpp_create(struct netdev *netdev)
 {
 	struct l_dbus *dbus = dbus_get_bus();
@@ -1612,6 +1702,9 @@ static void dpp_create(struct netdev *netdev)
 				dpp_conf_request_prefix,
 				sizeof(dpp_conf_request_prefix),
 				dpp_handle_config_request_frame, dpp, NULL);
+
+	dpp->mlme_watch = l_genl_family_register(nl80211, "mlme",
+						dpp_mlme_notify, dpp, NULL);
 }
 
 static void dpp_netdev_watch(struct netdev *netdev,
Signature · 1 line
2.31.1
#10 lore raw

Re: [PATCH 07/10] dpp: support retransmitting frames with no ACK

Hi James,

Quoted 17 lines · James Prestwood

The DPP spec says nothing about how to handle re-transmits but it was found in testing this can happen relatively easily for a few reasons.

If the configurator requests a channel switch but does not get onto the new channel quick enough the enrollee may have already sent the authenticate response and it was missed. Also by nature of how the kernel goes offchannel there are moments in time between ROC when the card is idle and not receiving any frames.

Only frames where there was no ACK will be retransmitted. If the peer received the frame and dropped it resending the same frame wont do any good.

---
  src/dpp.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
  1 file changed, 94 insertions(+), 1 deletion(-)

<snip>

src/dpp.c static void dpp_free(struct dpp_sm *dpp) · line 218

Quoted 9 lines
src/dpp.c +5 -0
@@ -204,13 +211,26 @@ static void dpp_free(struct dpp_sm *dpp)
  		dpp->boot_private = NULL;
  	}
 
+	if (dpp->mlme_watch) {
+		l_genl_family_unregister(nl80211, dpp->mlme_watch);
+		dpp->mlme_watch = 0;
+	}
+

Might be glass empty vs glass full thing, but wonder if registering the mlme watch for each dpp object is more complicated than just doing it at the module level (dpp_init?). I guess you did it this way because we do not have a dpp_find() equivalent...

In theory it would probably be more efficient to parse the message once and run dpp_find than having each dpp instance run the iterator.

Alternatively, maybe l_genl_family_register should be done only when DPP actually starts instead of at creation time?

Also, do we need to reset the cookie in dpp_reset or so? Maybe it doesn't matter.

Quoted 3 lines
src/dpp.c +0 -0
  	l_free(dpp);
  }
 

<snip>

Quoted 41 lines
src/dpp.c +37 -0
@@ -1575,6 +1595,76 @@ static void dpp_handle_frame(const struct mmpdu_header *frame,
  	}
  }
 
+static void dpp_mlme_notify(struct l_genl_msg *msg, void *user_data)
+{
+	struct dpp_sm *dpp = user_data;
+	uint64_t wdev_id = 0;
+	uint64_t cookie = 0;
+	bool ack = false;
+	struct l_genl_attr attr;
+	const void *data;
+	uint16_t len;
+	uint16_t type;
+	const void *frame = NULL;
+	uint16_t frame_len = 0;
+	struct iovec iov;
+	uint8_t cmd = l_genl_msg_get_command(msg);
+
+	if (cmd != NL80211_CMD_FRAME_TX_STATUS)
+		return;
+
+	if (dpp->state <= DPP_STATE_PRESENCE)
+		return;
+
+	l_genl_attr_init(&attr, msg);
+
+	while (l_genl_attr_next(&attr, &type, &len, &data)) {
+		switch (type) {
+		case NL80211_ATTR_WDEV:
+			if (len != 8)
+				return;
+
+			wdev_id = l_get_u64(data);
+			break;
+		case NL80211_ATTR_COOKIE:
+			if (len != 8)
+				return;
+
+			cookie = l_get_u64(data);
+			break;

src/dpp.c static void dpp_handle_frame(const struct mmpdu_header *frame, · line 1644

Quoted 10 lines
src/dpp.c +10 -0
+		case NL80211_ATTR_ACK:
+			ack = true;
+			break;
+		case NL80211_ATTR_FRAME:
+			frame = data;
+			frame_len = len;
+			break;
+		}
+	}
+

This may look nicer with nl80211_parse_attrs. At least for cookie/wdev/ack. And avoids some of the silent returns you have when the length doesn't match what is expected.

src/dpp.c static void dpp_handle_frame(const struct mmpdu_header *frame, · line 1656

Quoted 12 lines
src/dpp.c +12 -0
+	/*
+	 * Only want to handle the no-ACK case. Re-transmitting an ACKed
+	 * frame likely wont do any good, at least in the case of DPP.
+	 */
+	if (dpp->wdev_id != wdev_id || dpp->frame_cookie != cookie ||
+				ack || !frame)
+		return;
+
+	if (dpp->frame_retry > DPP_FRAME_MAX_RETRIES) {
+		dpp_reset(dpp);
+		return;
+	}

That way you can check these before even needing the frame.

src/dpp.c static void dpp_handle_frame(const struct mmpdu_header *frame, · line 1660

Quoted 4 lines
src/dpp.c +4 -0
+
+	iov.iov_base = (void *)frame;
+	iov.iov_len = frame_len;
+

Actually, it occurs to me that we could add ATTR_FRAME support to nl80211_parse_attrs by using the struct iovec for it.

src/dpp.c static void dpp_handle_frame(const struct mmpdu_header *frame, · line 1670

Quoted 10 lines
src/dpp.c +7 -0
+	l_debug("No ACK from peer, re-transmitting");
+
+	dpp->frame_retry++;
+
+	dpp_send_frame(dpp, &iov, 1, dpp->current_freq);
+}
+
  static void dpp_create(struct netdev *netdev)
  {
  	struct l_dbus *dbus = dbus_get_bus();

Regards,
-Denis

author
#11 lore raw

Re: [PATCH 07/10] dpp: support retransmitting frames with no ACK

Quoted 35 lines · Denis Kenzior

Hi James,

Quoted 19 lines · James Prestwood

The DPP spec says nothing about how to handle re-transmits but it was found in testing this can happen relatively easily for a few reasons.

If the configurator requests a channel switch but does not get onto the new channel quick enough the enrollee may have already sent the authenticate response and it was missed. Also by nature of how the kernel goes offchannel there are moments in time between ROC when the card is idle and not receiving any frames.

Only frames where there was no ACK will be retransmitted. If the peer received the frame and dropped it resending the same frame wont
do any good.
---
  src/dpp.c | 95
++++++++++++++++++++++++++++++++++++++++++++++++++++++-

  1 file changed, 94 insertions(+), 1 deletion(-)

<snip>

Quoted 9 lines
src/dpp.c +0 -0
@@ -204,13 +211,26 @@ static void dpp_free(struct dpp_sm *dpp)
                 dpp->boot_private = NULL;
         }


+       if (dpp->mlme_watch) {
+               l_genl_family_unregister(nl80211, dpp->mlme_watch); +               dpp->mlme_watch = 0;
+       }
+

Quoted 7 lines

Might be glass empty vs glass full thing, but wonder if registering the mlme
watch for each dpp object is more complicated than just doing it at the module
level (dpp_init?).  I guess you did it this way because we do not have a
dpp_find() equivalent...

Yep, that was why.

Quoted 4 lines

In theory it would probably be more efficient to parse the message once and run
dpp_find than having each dpp instance run the iterator.

But yes, I hadn't thought about each instance having to parse out the wdev, I can just add dpp_find instead.

Quoted 8 lines

Alternatively, maybe l_genl_family_register should be done only when DPP
actually starts instead of at creation time?

Also, do we need to reset the cookie in dpp_reset or so?  Maybe it doesn't matter.

Only would matter if cookies are reused or counted per-wdev but it doesn't hurt to zero it out.

Quoted 85 lines
Quoted 4 lines

        l_free(dpp);
  }

<snip>

Quoted 43 lines
(quoted diff) +0 -0
@@ -1575,6 +1595,76 @@ static void dpp_handle_frame(const struct
 mmpdu_header *frame,
         }
   }


+static void dpp_mlme_notify(struct l_genl_msg *msg, void *user_data)

src/dpp.c +36 -0
+{
+       struct dpp_sm *dpp = user_data;
+       uint64_t wdev_id = 0;
+       uint64_t cookie = 0;
+       bool ack = false;
+       struct l_genl_attr attr;
+       const void *data;
+       uint16_t len;
+       uint16_t type;
+       const void *frame = NULL;
+       uint16_t frame_len = 0;
+       struct iovec iov;
+       uint8_t cmd = l_genl_msg_get_command(msg);
+
+       if (cmd != NL80211_CMD_FRAME_TX_STATUS)
+               return;
+
+       if (dpp->state <= DPP_STATE_PRESENCE)
+               return;
+
+       l_genl_attr_init(&attr, msg);
+
+       while (l_genl_attr_next(&attr, &type, &len, &data)) {
+               switch (type) {
+               case NL80211_ATTR_WDEV:
+                       if (len != 8)
+                               return;
+
+                       wdev_id = l_get_u64(data);
+                       break;
+               case NL80211_ATTR_COOKIE:
+                       if (len != 8)
+                               return;
+
+                       cookie = l_get_u64(data);
+                       break;

src/dpp.c static void dpp_handle_frame(const struct mmpdu_header *frame, · line 1644

Quoted 10 lines
src/dpp.c +10 -0
+               case NL80211_ATTR_ACK:
+                       ack = true;
+                       break;
+               case NL80211_ATTR_FRAME:
+                       frame = data;
+                       frame_len = len;
+                       break;
+               }
+       }
+

This may look nicer with nl80211_parse_attrs.  At least for cookie/wdev/ack.
And avoids some of the silent returns you have when the length doesn't match
what is expected.

Quoted 7 lines

+       /*
+        * Only want to handle the no-ACK case. Re-transmitting an ACKed
+        * frame likely wont do any good, at least in the case of DPP.
+        */
+       if (dpp->wdev_id != wdev_id || dpp->frame_cookie != cookie

Quoted 8 lines
||
+                               ack || !frame)

+               return;
+
+       if (dpp->frame_retry > DPP_FRAME_MAX_RETRIES) { +               dpp_reset(dpp);
+               return;
+       }

That way you can check these before even needing the frame.

Quoted 7 lines

src/dpp.c static void dpp_handle_frame(const struct mmpdu_header *frame, · line 1660

Quoted 4 lines
src/dpp.c +4 -0
+
+       iov.iov_base = (void *)frame;
+       iov.iov_len = frame_len;
+

Actually, it occurs to me that we could add ATTR_FRAME support to nl80211_parse_attrs by using the struct iovec for it.

Yeah I'll do this instead. I played around with passing data/length but I always forget about iovec's.

Quoted 14 lines
Quoted 11 lines

+       l_debug("No ACK from peer, re-transmitting");

src/dpp.c +6 -0
+
+       dpp->frame_retry++;
+
+       dpp_send_frame(dpp, &iov, 1, dpp->current_freq);
+}
+

  static void dpp_create(struct netdev *netdev)
  {
        struct l_dbus *dbus = dbus_get_bus();

Regards,
-Denis

author
#12 lore raw

PATCH 8/10 auto-t: wpas.py: add freq argument to configurator_start

In reply to James Prestwood

This forces the configurator to request a new channel during the authentication protocol.

---
 autotests/util/wpas.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
autotests/util/wpas.py +8 -2
index 2e50eb58..f8ef3357 100644
@@ -268,11 +268,17 @@ class Wpas:
 
         print("DPP Configurator ID: %s. DPP QR ID: %s" % (self._dpp_conf_id, self._dpp_qr_id))
 
-    def dpp_configurator_start(self, ssid, passphrase):
+    def dpp_configurator_start(self, ssid, passphrase, freq=None):
         ssid = binascii.hexlify(ssid.encode()).decode()
         passphrase = binascii.hexlify(passphrase.encode()).decode()
 
-        self._ctrl_request('DPP_AUTH_INIT peer=%s conf=sta-psk ssid=%s pass=%s' % (self._dpp_qr_id, ssid, passphrase))
+        cmd = 'DPP_AUTH_INIT peer=%s conf=sta-psk ssid=%s pass=%s ' % (self._dpp_qr_id, ssid, passphrase)
+
+        if freq:
+            cmd += 'neg_freq=%u ' % freq
+
+        self._rx_data = []
+        self._ctrl_request(cmd)
         self.wait_for_event('DPP-AUTH-SUCCESS')
         self.wait_for_event('DPP-CONF-SENT')
 
Signature · 1 line
2.31.1
#13 lore raw

Re: [PATCH 08/10] auto-t: wpas.py: add freq argument to configurator_start

Hi James,

Quoted 5 lines · James Prestwood

This forces the configurator to request a new channel during the authentication protocol.

---
  autotests/util/wpas.py | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)

Patches 8-10 applied, thanks.

Regards,
-Denis

author
#14 lore raw

PATCH 9/10 auto-t: wpas.py: add configurator_remove

In reply to James Prestwood

wpa_supplicant has a limited number of configurator IDs, and its good practice to remove them after we are done.

---
 autotests/util/wpas.py | 6 ++++++
 1 file changed, 6 insertions(+)
autotests/util/wpas.py +6 -0
index f8ef3357..b750ce31 100644
@@ -282,6 +282,12 @@ class Wpas:
         self.wait_for_event('DPP-AUTH-SUCCESS')
         self.wait_for_event('DPP-CONF-SENT')
 
+    def dpp_configurator_remove(self):
+        self._ctrl_request('DPP_CONFIGURATOR_REMOVE *')
+        self.wait_for_result()
+        self._ctrl_request('DPP_BOOTSTRAP_REMOVE *')
+        self.wait_for_result()
+
     # Probably needed: remove references to self so that the GC can call __del__ automatically
     def clean_up(self):
         if self.io_watch is not None:
Signature · 1 line
2.31.1
author
#15 lore raw

PATCH 10/10 auto-t: add a few more DPP tests

In reply to James Prestwood

This adds 3 more tests:
- Channel switch during authentication
- Scan after configuring
- Retransmit auth frames

---
 autotests/testDPP/connection_test.py | 103 +++++++++++++++++++--------
 autotests/testDPP/hw.conf            |   1 +
 2 files changed, 76 insertions(+), 28 deletions(-)
autotests/testDPP/connection_test.py +75 -28
index 43822c55..3c3705e4 100644
@@ -7,58 +7,105 @@ sys.path.append('../util')
 from iwd import IWD
 from wpas import Wpas
 from hostapd import HostapdCLI
+from hwsim import Hwsim
 
 class Test(unittest.TestCase):
-
     def test_iwd_as_enrollee(self):
-        wpas = Wpas('wpas.conf')
+        self.device.autoconnect = True
+        self.hapd.reload()
+
+        uri = self.device.dpp_start_enrollee()
 
-        wd = IWD(True)
+        self.wpas.dpp_configurator_create(uri)
+        self.wpas.dpp_configurator_start('ssidCCMP', 'secret123')
 
-        devices = wd.list_devices(1)
-        device = devices[0]
-        device.autoconnect = True
+        condition = 'obj.state == DeviceState.connected'
+        self.wd.wait_for_object_condition(self.device, condition)
 
-        uri = device.dpp_start_enrollee()
+    def test_iwd_as_enrollee_channel_switch(self):
+        self.device.autoconnect = True
+        self.hapd.reload()
 
-        wpas.dpp_configurator_create(uri)
-        wpas.dpp_configurator_start('ssidCCMP', 'secret123')
+        uri = self.device.dpp_start_enrollee()
+
+        self.wpas.dpp_configurator_create(uri)
+        self.wpas.dpp_configurator_start('ssidCCMP', 'secret123', freq=2462)
 
         condition = 'obj.state == DeviceState.connected'
-        wd.wait_for_object_condition(device, condition)
+        self.wd.wait_for_object_condition(self.device, condition)
 
-        device.disconnect()
-        device.dpp_stop()
+    def test_iwd_as_enrollee_scan_after(self):
+        uri = self.device.dpp_start_enrollee()
 
-        del wpas
+        self.wpas.dpp_configurator_create(uri)
+        self.wpas.dpp_configurator_start('ssidCCMP', 'secret123')
 
-    def test_iwd_as_configurator(self):
-        IWD.copy_to_storage('ssidCCMP.psk')
+        self.hapd.reload()
+
+        with self.assertRaises(Exception):
+            self.device.get_ordered_network('ssidCCMP', scan_if_needed=False)
 
-        wpas = Wpas('wpas.conf')
-        hapd = HostapdCLI('hostapd.conf')
+        self.hapd.wait_for_event('AP-ENABLED')
 
-        wd = IWD(True)
+        self.device.autoconnect = True
+
+        condition = 'obj.state == DeviceState.connected'
+        self.wd.wait_for_object_condition(self.device, condition)
+
+    def test_iwd_as_enrollee_no_ack(self):
+        self.rule0.enabled = True
+        self.device.autoconnect = True
+        self.hapd.reload()
+
+        uri = self.device.dpp_start_enrollee()
+
+        self.wpas.dpp_configurator_create(uri)
+        self.wpas.dpp_configurator_start('ssidCCMP', 'secret123')
+
+        condition = 'obj.state == DeviceState.connected'
+        self.wd.wait_for_object_condition(self.device, condition)
+
+    def test_iwd_as_configurator(self):
+        self.device.autoconnect = True
+        IWD.copy_to_storage('ssidCCMP.psk')
 
-        devices = wd.list_devices(1)
-        device = devices[0]
-        device.autoconnect = True
+        self.hapd.reload()
 
         condition = 'obj.state == DeviceState.connected'
-        wd.wait_for_object_condition(device, condition)
+        self.wd.wait_for_object_condition(self.device, condition)
 
-        uri = device.dpp_start_configurator()
+        uri = self.device.dpp_start_configurator()
 
-        wpas.dpp_enrollee_start(uri)
+        self.wpas.dpp_enrollee_start(uri)
 
-        hapd.wait_for_event('AP-STA-CONNECTED 42:00:00:00:00:00')
+        self.hapd.wait_for_event('AP-STA-CONNECTED 42:00:00:00:00:00')
 
-        device.disconnect()
-        device.dpp_stop()
+    def setUp(self):
+        self.wd = IWD(True)
+        self.device = self.wd.list_devices(1)[0]
+        self.wpas = Wpas('wpas.conf')
+        self.hapd = HostapdCLI('hostapd.conf')
+        self.hapd.disable()
+        self.hwsim = Hwsim()
 
-        del wpas
+        self.rule0 = self.hwsim.rules.create()
+        self.rule0.prefix = 'd0'
+        self.rule0.match_offset = 24
+        self.rule0.match = '04 09 50 6f 9a 1a 01 01'
+        self.rule0.match_times = 1
+        self.rule0.drop = True
 
     def tearDown(self):
+        print("calling Disconnect()")
+        self.device.disconnect()
+        self.device.dpp_stop()
+        self.wpas.dpp_configurator_remove()
+
+        self.wd = None
+        self.device = None
+        self.wpas = None
+        self.hapd = None
+        self.rule0 = None
         IWD.clear_storage()
 
     @classmethod
autotests/testDPP/hw.conf +1 -0
index 478f0633..923595ea 100644
@@ -1,6 +1,7 @@
 [SETUP]
 num_radios=3
 start_iwd=0
+hwsim_medium=yes
 
 [WPA_SUPPLICANT]
 rad0=wpas.conf
Signature · 1 line
2.31.1
#16 lore raw
In reply to James Prestwood

Hi James,

Quoted 6 lines · James Prestwood

This should be used as a replacement for the common GLib wait loop (internally this is all it does).

---
  autotests/util/wpas.py | 31 +++++++++++--------------------
  1 file changed, 11 insertions(+), 20 deletions(-)

Patch 1 & 2 applied, thanks.

Regards,
-Denis