Skip to contentSkip to conversation

nl80211util: support ATTR_FRAME in parse_attrs()

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

lore
Share & tools
lore

James Prestwood

author
#0 lore raw

PATCH v2 1/7 nl80211util: support ATTR_FRAME in parse_attrs()

---
 src/nl80211util.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
src/nl80211util.c +12 -0
index d663c6dc..9cd538ec 100644
@@ -118,6 +118,16 @@ static bool extract_flag(const void *data, uint16_t len, void *o)
 	return true;
 }
 
+static bool extract_iovec(const void *data, uint16_t len, void *o)
+{
+	struct iovec *iov = o;
+
+	iov->iov_base = (void *) data;
+	iov->iov_len = len;
+
+	return true;
+}
+
 static attr_handler handler_for_type(enum nl80211_attrs type)
 {
 	switch (type) {
@@ -145,6 +155,8 @@ static attr_handler handler_for_type(enum nl80211_attrs type)
 	case NL80211_ATTR_CENTER_FREQ1:
 	case NL80211_ATTR_CENTER_FREQ2:
 		return extract_uint32;
+	case NL80211_ATTR_FRAME:
+		return extract_iovec;
 	default:
 		break;
 	}
Signature · 1 line
2.31.1
author
#1 lore raw

PATCH v2 2/7 dpp: support retransmitting frames with no ACK

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 | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 86 insertions(+), 1 deletion(-)
src/dpp.c +86 -1
index 17d0bd90..5f24de57 100644
@@ -52,10 +52,15 @@
 #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;
 static uint8_t broadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+static struct l_queue *dpp_list;
+static uint32_t mlme_watch;
 
 enum dpp_state {
 	DPP_STATE_NOTHING,
@@ -118,6 +123,8 @@ struct dpp_sm {
 
 	struct dpp_configuration *config;
 	uint32_t connect_scan_id;
+	uint64_t frame_cookie;
+	uint8_t frame_retry;
 
 	struct l_dbus_message *pending;
 };
@@ -174,6 +181,8 @@ static void dpp_reset(struct dpp_sm *dpp)
 
 	dpp->state = DPP_STATE_NOTHING;
 	dpp->new_freq = 0;
+	dpp->frame_retry = 0;
+	dpp->frame_cookie = 0;
 
 	explicit_bzero(dpp->r_nonce, dpp->nonce_len);
 	explicit_bzero(dpp->i_nonce, dpp->nonce_len);
@@ -209,8 +218,16 @@ static void dpp_free(struct dpp_sm *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,
@@ -1576,6 +1593,59 @@ static void dpp_handle_frame(const struct mmpdu_header *frame,
 	}
 }
 
+static bool match_wdev(const void *a, const void *b)
+{
+	const struct dpp_sm *dpp = a;
+	const uint64_t *wdev_id = b;
+
+	return *wdev_id == dpp->wdev_id;
+}
+
+static void dpp_mlme_notify(struct l_genl_msg *msg, void *user_data)
+{
+	struct dpp_sm *dpp;
+	uint64_t wdev_id = 0;
+	uint64_t cookie = 0;
+	bool ack = false;
+	struct iovec iov;
+	uint8_t cmd = l_genl_msg_get_command(msg);
+
+	if (cmd != NL80211_CMD_FRAME_TX_STATUS)
+		return;
+
+	if (nl80211_parse_attrs(msg, NL80211_ATTR_WDEV, &wdev_id,
+				NL80211_ATTR_COOKIE, &cookie,
+				NL80211_ATTR_ACK, &ack,
+				NL80211_ATTR_FRAME, &iov,
+				NL80211_ATTR_UNSPEC) < 0)
+		return;
+
+	dpp = l_queue_find(dpp_list, match_wdev, &wdev_id);
+	if (!dpp)
+		return;
+
+	if (dpp->state <= DPP_STATE_PRESENCE)
+		return;
+
+	/*
+	 * 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->frame_cookie != cookie || ack)
+		return;
+
+	if (dpp->frame_retry > DPP_FRAME_MAX_RETRIES) {
+		dpp_reset(dpp);
+		return;
+	}
+
+	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();
@@ -1613,6 +1683,8 @@ static void dpp_create(struct netdev *netdev)
 				dpp_conf_request_prefix,
 				sizeof(dpp_conf_request_prefix),
 				dpp_handle_config_request_frame, dpp, NULL);
+
+	l_queue_push_tail(dpp_list, dpp);
 }
 
 static void dpp_netdev_watch(struct netdev *netdev,
@@ -1819,6 +1891,8 @@ static void dpp_destroy_interface(void *user_data)
 {
 	struct dpp_sm *dpp = user_data;
 
+	l_queue_remove(dpp_list, dpp);
+
 	dpp_free(dpp);
 }
 
@@ -1835,6 +1909,12 @@ static int dpp_init(void)
 	l_dbus_register_interface(dbus_get_bus(), IWD_DPP_INTERFACE,
 					dpp_setup_interface,
 					dpp_destroy_interface, false);
+
+	mlme_watch = l_genl_family_register(nl80211, "mlme", dpp_mlme_notify,
+						NULL, NULL);
+
+	dpp_list = l_queue_new();
+
 	return 0;
 }
 
@@ -1843,6 +1923,11 @@ static void dpp_exit(void)
 	l_debug("");
 
 	netdev_watch_remove(netdev_watch);
+
+	l_genl_family_unregister(nl80211, mlme_watch);
+	mlme_watch = 0;
+
+	l_queue_destroy(dpp_list, (l_queue_destroy_func_t) dpp_free);
 }
 
 IWD_MODULE(dpp, dpp_init, dpp_exit);
Signature · 1 line
2.31.1
author
#2 lore raw

PATCH v2 3/7 scan: don't print notification if sc is not found

In reply to James Prestwood

If this scan is not for any IWD wdev's don't print

---
 src/scan.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/scan.c +2 -2
index 0767fa22..156d427f 100644
@@ -1811,8 +1811,6 @@ static void scan_notify(struct l_genl_msg *msg, void *user_data)
 
 	cmd = l_genl_msg_get_command(msg);
 
-	l_debug("Scan notification %s(%u)", nl80211cmd_to_string(cmd), cmd);
-
 	if (nl80211_parse_attrs(msg, NL80211_ATTR_WDEV, &wdev_id,
 					NL80211_ATTR_WIPHY, &wiphy_id,
 					NL80211_ATTR_UNSPEC) < 0)
@@ -1822,6 +1820,8 @@ static void scan_notify(struct l_genl_msg *msg, void *user_data)
 	if (!sc)
 		return;
 
+	l_debug("Scan notification %s(%u)", nl80211cmd_to_string(cmd), cmd);
+
 	if (!l_genl_attr_init(&attr, msg))
 		return;
 
Signature · 1 line
2.31.1
author
#3 lore raw

PATCH v2 4/7 dpp: stop periodic scanning when starting DPP

In reply to James Prestwood
---
 src/dpp.c | 4 ++++
 1 file changed, 4 insertions(+)
src/dpp.c +4 -0
index 5f24de57..f33b655b 100644
@@ -1809,6 +1809,8 @@ static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
 	 */
 	dpp_start_presence(dpp, &freq, 1);
 
+	scan_periodic_stop(dpp->wdev_id);
+
 	return NULL;
 }
 
@@ -1857,6 +1859,8 @@ static struct l_dbus_message *dpp_dbus_start_configurator(struct l_dbus *dbus,
 						network_get_ssid(network),
 						hs->akm_suite);
 
+	scan_periodic_stop(dpp->wdev_id);
+
 	l_debug("DPP Start Configurator: %s", dpp->uri);
 
 	reply = l_dbus_message_new_method_return(message);
Signature · 1 line
2.31.1
author
#4 lore raw

PATCH v2 5/7 auto-t: wpas.py: increase timeout for auth protocol

In reply to James Prestwood

Sometimes wpa_supplicant takes some time to respond to the initial presence anouncements.

---
 autotests/util/wpas.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
autotests/util/wpas.py +1 -1
index b750ce31..440f6227 100644
@@ -279,7 +279,7 @@ class Wpas:
 
         self._rx_data = []
         self._ctrl_request(cmd)
-        self.wait_for_event('DPP-AUTH-SUCCESS')
+        self.wait_for_event('DPP-AUTH-SUCCESS', timeout=30)
         self.wait_for_event('DPP-CONF-SENT')
 
     def dpp_configurator_remove(self):
Signature · 1 line
2.31.1
author
#5 lore raw

PATCH v2 6/7 auto-t: wpas.py: add disconnect()

In reply to James Prestwood
---
 autotests/util/wpas.py | 3 +++
 1 file changed, 3 insertions(+)
autotests/util/wpas.py +3 -0
index 440f6227..6b845232 100644
@@ -288,6 +288,9 @@ class Wpas:
         self._ctrl_request('DPP_BOOTSTRAP_REMOVE *')
         self.wait_for_result()
 
+    def disconnect(self):
+        self._ctrl_request('DISCONNECT')
+
     # 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
#6 lore raw

PATCH v2 7/7 auto-t: improve testDPP reliablity

In reply to James Prestwood

First disconnect wpa_supplicant to make sure it wont miss frames if it decides to connect. Also alter the order of things for the configurator test so autoconnect doesn't start until after hostapd is up (avoids additional scanning and delays)

---
 autotests/testDPP/connection_test.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
autotests/testDPP/connection_test.py +5 -3
index 3c3705e4..38d44b25 100644
@@ -35,6 +35,7 @@ class Test(unittest.TestCase):
         self.wd.wait_for_object_condition(self.device, condition)
 
     def test_iwd_as_enrollee_scan_after(self):
+        self.wpas.disconnect()
         uri = self.device.dpp_start_enrollee()
 
         self.wpas.dpp_configurator_create(uri)
@@ -66,10 +67,11 @@ class Test(unittest.TestCase):
         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')
-
         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)
Signature · 1 line
2.31.1
#7 lore raw
In reply to James Prestwood

Hi James,

Quoted 4 lines · James Prestwood
---
  src/nl80211util.c | 12 ++++++++++++
  1 file changed, 12 insertions(+)

All applied, thanks.

Regards,
-Denis