Skip to contentSkip to conversation

AdHoc fixes

PATCH In review James Prestwood 2 participants 9 messages Sep 14, 2020

lore
Share & tools
lore
#0 lore raw

cover AdHoc fixes

These should make AdHoc pass very reliably now. There is still the problem of the failure test. Its not really testing anything at this point since there is no way of knowing if EAPoL was successful or not via DBus.

James Prestwood (6):
adhoc: start both eapol SM's
adhoc: print handshake failure reason
adhoc: delay setting setting Started
auto-t: make AdHoc APIs behave like others
auto-t: update AdHoc tests to use AdHocDevice
auto-t: remove old AdHoc APIs

 autotests/testAdHoc/adhoc_test.py | 18 ++++++--
 autotests/testAdHoc/open_test.py  | 19 ++++++---
 autotests/util/iwd.py             | 71 +++++++------------------------
 src/adhoc.c                       | 51 ++++++++++++++++++++--
 4 files changed, 92 insertions(+), 67 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/6 adhoc: start both eapol SM's

At some point in the past starting only one SM worked. But now it does not. Both SM's need to be started for EAPoL to work properly and kick off both sets of handshakes.

---
 src/adhoc.c | 1 +
 1 file changed, 1 insertion(+)
src/adhoc.c +1 -0
index ceec2dea..3050ce27 100644
@@ -302,6 +302,7 @@ static void adhoc_start_rsna(struct sta_state *sta, const uint8_t *gtk_rsc)
 	eapol_register(sta->sm_a);
 
 	eapol_start(sta->sm);
+	eapol_start(sta->sm_a);
 
 	return;
 
Signature · 1 line
2.26.2
#2 lore raw

Re: [PATCH 1/6] adhoc: start both eapol SM's

Hi James,

Quoted 7 lines · James Prestwood

At some point in the past starting only one SM worked. But now it does not. Both SM's need to be started for EAPoL to work properly and kick off both sets of handshakes.

---
  src/adhoc.c | 1 +
  1 file changed, 1 insertion(+)

Applied with a slight commit description change to mention the offending commit.

Regards,
-Denis

#3 lore raw

PATCH 2/6 adhoc: print handshake failure reason

In reply to James Prestwood
---
 src/adhoc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
src/adhoc.c +6 -1
index 3050ce27..9f3b32e7 100644
@@ -179,10 +179,15 @@ static void adhoc_handshake_event(struct handshake_state *hs,
 {
 	struct sta_state *sta = user_data;
 	struct adhoc_state *adhoc = sta->adhoc;
+	va_list args;
+
+	va_start(args, user_data);
 
 	switch (event) {
 	case HANDSHAKE_EVENT_FAILED:
-		l_error("handshake failed with STA "MAC, MAC_STR(sta->addr));
+		l_error("handshake failed with STA "MAC" (%d)",
+						MAC_STR(sta->addr),
+						va_arg(args, int));
 
 		/*
 		 * eapol frees the state machines upon handshake failure. Since
Signature · 1 line
2.26.2
#4 lore raw

Re: [PATCH 2/6] adhoc: print handshake failure reason

Hi James,

Quoted 4 lines · James Prestwood
---
  src/adhoc.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)

Patches 2-6 applied, thanks.

Regards,
-Denis

#5 lore raw

PATCH 3/6 adhoc: delay setting setting Started

In reply to James Prestwood

The Started property was being set in the Join IBSS callback which isn't really when the IBSS has been started. The kernel automatically scans for IBSS networks which takes some time. Its better to wait on setting Started until we get the Join IBSS event.

---
 src/adhoc.c | 43 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 41 insertions(+), 2 deletions(-)
src/adhoc.c +41 -2
index 9f3b32e7..7f9ce765 100644
@@ -52,6 +52,7 @@ struct adhoc_state {
 	struct l_queue *sta_states;
 	uint32_t sta_watch_id;
 	uint32_t netdev_watch_id;
+	unsigned int mlme_watch;
 	struct l_dbus_message *pending;
 	uint32_t ciphers;
 	uint32_t group_cipher;
@@ -137,6 +138,7 @@ static void adhoc_reset(struct adhoc_state *adhoc)
 	adhoc->ssid = NULL;
 
 	netdev_station_watch_remove(adhoc->netdev, adhoc->sta_watch_id);
+	adhoc->sta_watch_id = 0;
 
 	l_queue_destroy(adhoc->sta_states, adhoc_sta_free);
 	adhoc->sta_states = NULL;
@@ -145,6 +147,9 @@ static void adhoc_reset(struct adhoc_state *adhoc)
 
 	l_dbus_property_changed(dbus_get_bus(), netdev_get_path(adhoc->netdev),
 						IWD_ADHOC_INTERFACE, "Started");
+
+	if (adhoc->mlme_watch)
+		l_genl_family_unregister(adhoc->nl80211, adhoc->mlme_watch);
 }
 
 static void adhoc_set_rsn_info(struct adhoc_state *adhoc,
@@ -493,11 +498,35 @@ static void adhoc_join_cb(struct netdev *netdev, int result, void *user_data)
 
 	reply = l_dbus_message_new_method_return(adhoc->pending);
 	dbus_pending_reply(&adhoc->pending, reply);
+}
 
-	adhoc->started = true;
+static void adhoc_mlme_notify(struct l_genl_msg *msg, void *user_data)
+{
+	struct adhoc_state *adhoc = user_data;
+	uint32_t ifindex;
 
-	l_dbus_property_changed(dbus_get_bus(), netdev_get_path(adhoc->netdev),
+	if (nl80211_parse_attrs(msg, NL80211_ATTR_IFINDEX, &ifindex,
+				NL80211_ATTR_UNSPEC) < 0 ||
+			ifindex != netdev_get_ifindex(adhoc->netdev))
+		return;
+
+	switch (l_genl_msg_get_command(msg)) {
+	case NL80211_CMD_JOIN_IBSS:
+		/*
+		 * if watch is set the join_ibss_cb has come back. This event
+		 * will come in for each new STA joining the IBSS so we only
+		 * want to set it once
+		 */
+		if (adhoc->sta_watch_id && !adhoc->started) {
+			adhoc->started = true;
+
+			l_dbus_property_changed(dbus_get_bus(),
+						netdev_get_path(adhoc->netdev),
 						IWD_ADHOC_INTERFACE, "Started");
+		}
+
+		break;
+	}
 }
 
 static struct l_dbus_message *adhoc_dbus_start(struct l_dbus *dbus,
@@ -538,6 +567,11 @@ static struct l_dbus_message *adhoc_dbus_start(struct l_dbus *dbus,
 			adhoc))
 		return dbus_error_invalid_args(message);
 
+	adhoc->mlme_watch = l_genl_family_register(adhoc->nl80211, "mlme",
+						adhoc_mlme_notify, adhoc, NULL);
+	if (!adhoc->mlme_watch)
+		return dbus_error_failed(message);
+
 	return NULL;
 }
 
@@ -573,6 +607,11 @@ static struct l_dbus_message *adhoc_dbus_start_open(struct l_dbus *dbus,
 			adhoc))
 		return dbus_error_invalid_args(message);
 
+	adhoc->mlme_watch = l_genl_family_register(adhoc->nl80211, "mlme",
+						adhoc_mlme_notify, adhoc, NULL);
+	if (!adhoc->mlme_watch)
+		return dbus_error_failed(message);
+
 	return NULL;
 }
 
Signature · 1 line
2.26.2
#6 lore raw

PATCH 4/6 auto-t: make AdHoc APIs behave like others

In reply to James Prestwood

The AdHoc functionality in iwd.py was not consistent at all with how all the other classes worked (my bad). Instead we can create a very simple AdHocDevice class which inherits all the DBus magic in the IWDDBusAbstract class.

---
 autotests/util/iwd.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
autotests/util/iwd.py +16 -0
index e74a6faf..2713d774 100755
@@ -206,6 +206,20 @@ class SignalAgent(dbus.service.Object):
     def handle_new_level(self, path, level):
         pass
 
+class AdHocDevice(IWDDBusAbstract):
+    '''
+        Class represents an AdHoc device object: net.connman.iwd.AdHoc
+    '''
+    _iface_name = IWD_ADHOC_INTERFACE
+
+    @property
+    def started(self):
+        return self._properties['Started']
+
+    @property
+    def connected_peers(self):
+        return self._properties['ConnectedPeers']
+
 
 class Device(IWDDBusAbstract):
     '''
@@ -506,6 +520,8 @@ class Device(IWDDBusAbstract):
                                         error_handler=self._failure)
         self._wait_for_async_op()
 
+        return AdHocDevice(self.device_path)
+
     def stop_adhoc(self):
         self._prop_proxy.Set(IWD_DEVICE_INTERFACE, 'Mode', 'station')
 
Signature · 1 line
2.26.2
#7 lore raw

PATCH 5/6 auto-t: update AdHoc tests to use AdHocDevice

In reply to James Prestwood
---
 autotests/testAdHoc/adhoc_test.py | 18 ++++++++++++++----
 autotests/testAdHoc/open_test.py  | 19 ++++++++++++++-----
 2 files changed, 28 insertions(+), 9 deletions(-)
autotests/testAdHoc/adhoc_test.py +14 -4
index 119c6c7e..13c0c016 100644
@@ -17,11 +17,21 @@ class Test(unittest.TestCase):
         self.assertIsNotNone(dev1)
         self.assertIsNotNone(dev2)
 
-        dev1.start_adhoc("AdHocNetwork", "secret123")
-        dev2.start_adhoc("AdHocNetwork", "secret123")
+        adhoc1 = dev1.start_adhoc("AdHocNetwork", "secret123")
 
-        dev1.adhoc_wait_for_connected(dev2.address)
-        dev2.adhoc_wait_for_connected(dev1.address)
+        condition = 'obj.started == True'
+        wd.wait_for_object_condition(adhoc1, condition)
+
+        adhoc2 = dev2.start_adhoc("AdHocNetwork", "secret123")
+
+        condition = 'obj.started == True'
+        wd.wait_for_object_condition(adhoc1, condition)
+
+        condition = '"%s" in obj.connected_peers' % dev2.address
+        wd.wait_for_object_condition(adhoc1, condition)
+
+        condition = '"%s" in obj.connected_peers' % dev1.address
+        wd.wait_for_object_condition(adhoc2, condition)
 
         testutil.test_iface_operstate(dev1.name)
         testutil.test_iface_operstate(dev2.name)
autotests/testAdHoc/open_test.py +14 -5
index a3882a50..4e0ae27f 100644
@@ -18,12 +18,21 @@ class Test(unittest.TestCase):
         self.assertIsNotNone(dev1)
         self.assertIsNotNone(dev2)
 
-        dev1.start_adhoc("AdHocNetwork")
-        sleep(1)
-        dev2.start_adhoc("AdHocNetwork")
+        adhoc1 = dev1.start_adhoc("AdHocNetwork")
 
-        dev1.adhoc_wait_for_connected(dev2.address)
-        dev2.adhoc_wait_for_connected(dev1.address)
+        condition = 'obj.started == True'
+        wd.wait_for_object_condition(adhoc1, condition)
+
+        adhoc2 = dev2.start_adhoc("AdHocNetwork")
+
+        condition = 'obj.started == True'
+        wd.wait_for_object_condition(adhoc1, condition)
+
+        condition = '"%s" in obj.connected_peers' % dev2.address
+        wd.wait_for_object_condition(adhoc1, condition)
+
+        condition = '"%s" in obj.connected_peers' % dev1.address
+        wd.wait_for_object_condition(adhoc2, condition)
 
         testutil.test_iface_operstate(dev1.name)
         testutil.test_iface_operstate(dev2.name)
Signature · 1 line
2.26.2
#8 lore raw

PATCH 6/6 auto-t: remove old AdHoc APIs

In reply to James Prestwood
---
 autotests/util/iwd.py | 55 -------------------------------------------
 1 file changed, 55 deletions(-)
autotests/util/iwd.py +0 -55
index 2713d774..67bb6e41 100755
@@ -525,61 +525,6 @@ class Device(IWDDBusAbstract):
     def stop_adhoc(self):
         self._prop_proxy.Set(IWD_DEVICE_INTERFACE, 'Mode', 'station')
 
-    def adhoc_wait_for_disconnected(self, addr):
-        self._adhoc_prop_found = False
-        self._adhoc_timed_out = False
-
-        def wait_timeout_cb():
-            self._adhoc_timed_out = True
-            return False
-
-        def adhoc_props_changed(iface, changed, invalid):
-            if changed.get('ConnectedPeers', None):
-                if addr not in changed['ConnectedPeers']:
-                    self._adhoc_prop_found = True
-
-        self._prop_proxy.connect_to_signal('PropertiesChanged',
-                                            adhoc_props_changed)
-        props = self._prop_proxy.GetAll(IWD_ADHOC_INTERFACE)
-        if props.get('ConnectedPeers', None):
-            if addr not in props['ConnectedPeers']:
-                return
-
-        GLib.timeout_add(int(50 * 1000), wait_timeout_cb)
-        context = ctx.mainloop.get_context()
-        while not self._adhoc_prop_found:
-            context.iteration(may_block=True)
-            if self._adhoc_timed_out:
-                raise TimeoutError("Timed out waiting for peer %s" % addr)
-
-    def adhoc_wait_for_connected(self, addr):
-        self._adhoc_prop_found = False
-        self._adhoc_timed_out = False
-
-        def wait_timeout_cb():
-            self._adhoc_timed_out = True
-            return False
-
-        def adhoc_props_changed(iface, changed, invalid):
-            if changed.get('ConnectedPeers', None):
-                if addr in changed['ConnectedPeers']:
-                    self._adhoc_prop_found = True
-
-        self._prop_proxy.connect_to_signal('PropertiesChanged',
-                                            adhoc_props_changed)
-
-        props = self._prop_proxy.GetAll(IWD_ADHOC_INTERFACE)
-        if props.get('ConnectedPeers', None):
-            if addr in props['ConnectedPeers']:
-                return
-
-        GLib.timeout_add(int(50 * 1000), wait_timeout_cb)
-        context = ctx.mainloop.get_context()
-        while not self._adhoc_prop_found:
-            context.iteration(may_block=True)
-            if self._adhoc_timed_out:
-                raise TimeoutError("Timed out waiting for peer %s" % addr)
-
     def __str__(self, prefix = ''):
         return prefix + 'Device: ' + self.device_path + '\n'\
                + prefix + '\tName:\t\t' + self.name + '\n'\
Signature · 1 line
2.26.2