iwd.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/8] anqp: print MAC when sending ANQP request
@ 2021-08-18 22:09 James Prestwood
  2021-08-18 22:09 ` [PATCH 2/8] hwsim: require enabling rule before use James Prestwood
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: James Prestwood @ 2021-08-18 22:09 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 543 bytes --]

---
 src/anqp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/anqp.c b/src/anqp.c
index 9f216305..a3c46635 100644
--- a/src/anqp.c
+++ b/src/anqp.c
@@ -248,7 +248,7 @@ uint32_t anqp_request(uint64_t wdev_id, const uint8_t *addr,
 	iov[0].iov_len = request->frame_len;
 	iov[1].iov_base = NULL;
 
-	l_debug("Sending ANQP request");
+	l_debug("Sending ANQP request to "MAC, MAC_STR(bss->addr));
 
 	request->id = frame_xchg_start(request->wdev_id, iov,
 				request->frequency, 0, 300, 0,
-- 
2.31.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/8] hwsim: require enabling rule before use
  2021-08-18 22:09 [PATCH 1/8] anqp: print MAC when sending ANQP request James Prestwood
@ 2021-08-18 22:09 ` James Prestwood
  2021-08-18 22:09 ` [PATCH 3/8] hwsim: remove unconditional packet delay James Prestwood
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: James Prestwood @ 2021-08-18 22:09 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2999 bytes --]

The hwsim Rule API was structured as properties so once a rule is
created it automatically starts being applied to frames. This happens
before anything has time to actually define the rule (source, destination
etc). This leads to every single frame being matched to the rule until
these other properties are added, which can result in unexpected behavior.

To fix this an "Enabled" property has been added and the rule will not
be applied until this is true.
---
 tools/hwsim.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/tools/hwsim.c b/tools/hwsim.c
index fcb83248..c7b41750 100644
--- a/tools/hwsim.c
+++ b/tools/hwsim.c
@@ -124,6 +124,7 @@ struct hwsim_rule {
 	bool destination_any : 1;
 	bool bidirectional : 1;
 	bool drop : 1;
+	bool enabled : 1;
 	uint32_t frequency;
 	int priority;
 	int signal;
@@ -1177,6 +1178,9 @@ static void process_rules(const struct radio_info_rec *src_radio,
 			rule_entry = rule_entry->next) {
 		struct hwsim_rule *rule = rule_entry->data;
 
+		if (!rule->enabled)
+			return;
+
 		if (!rule->source_any &&
 				!radio_match_addr(src_radio, rule->source) &&
 				(!rule->bidirectional ||
@@ -1996,6 +2000,7 @@ static struct l_dbus_message *rule_add(struct l_dbus *dbus,
 	rule->source_any = true;
 	rule->destination_any = true;
 	rule->delay = HWSIM_DELAY_MIN_MS;
+	rule->enabled = false;
 
 	if (!rules)
 		rules = l_queue_new();
@@ -2369,6 +2374,37 @@ invalid_args:
 	return dbus_error_invalid_args(message);
 }
 
+static bool rule_property_get_enabled(struct l_dbus *dbus,
+					struct l_dbus_message *message,
+					struct l_dbus_message_builder *builder,
+					void *user_data)
+{
+	struct hwsim_rule *rule = user_data;
+	bool bval = rule->enabled;
+
+	l_dbus_message_builder_append_basic(builder, 'b', &bval);
+
+	return true;
+}
+
+static struct l_dbus_message *rule_property_set_enabled(
+					struct l_dbus *dbus,
+					struct l_dbus_message *message,
+					struct l_dbus_message_iter *new_value,
+					l_dbus_property_complete_cb_t complete,
+					void *user_data)
+{
+	struct hwsim_rule *rule = user_data;
+	bool bval;
+
+	if (!l_dbus_message_iter_get_variant(new_value, "b", &bval))
+		return dbus_error_invalid_args(message);
+
+	rule->enabled = bval;
+
+	return l_dbus_message_new_method_return(message);
+}
+
 static void setup_rule_interface(struct l_dbus_interface *interface)
 {
 	l_dbus_interface_method(interface, "Remove", 0, rule_remove, "", "");
@@ -2409,6 +2445,10 @@ static void setup_rule_interface(struct l_dbus_interface *interface)
 					L_DBUS_PROPERTY_FLAG_AUTO_EMIT, "ay",
 					rule_property_get_prefix,
 					rule_property_set_prefix);
+	l_dbus_interface_property(interface, "Enabled",
+					L_DBUS_PROPERTY_FLAG_AUTO_EMIT, "b",
+					rule_property_get_enabled,
+					rule_property_set_enabled);
 }
 
 static void request_name_callback(struct l_dbus *dbus, bool success,
-- 
2.31.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/8] hwsim: remove unconditional packet delay
  2021-08-18 22:09 [PATCH 1/8] anqp: print MAC when sending ANQP request James Prestwood
  2021-08-18 22:09 ` [PATCH 2/8] hwsim: require enabling rule before use James Prestwood
@ 2021-08-18 22:09 ` James Prestwood
  2021-08-18 22:09 ` [PATCH 4/8] auto-t: hwsim.py: add Enabled property James Prestwood
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: James Prestwood @ 2021-08-18 22:09 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2343 bytes --]

This was initially put in to solve an issue that was specific to
mac80211_hwsim where the connect callback would get queued and
delayed until after the connect event. This caused IWD to get very
confused.

Later it was found that "real" drivers can sometimes do this so
some code was added to IWD core to handle it.

Now there isn't much point to delay all frames unless a rule specifies
so change the behavior back to sending out frames immediately.
---
 tools/hwsim.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/tools/hwsim.c b/tools/hwsim.c
index c7b41750..cd4a99b7 100644
--- a/tools/hwsim.c
+++ b/tools/hwsim.c
@@ -1436,9 +1436,11 @@ static void frame_delay_callback(struct l_timeout *timeout, void *user_data)
 	else
 		send_frame_destroy(send_info);
 
-	l_timeout_remove(timeout);
+	if (timeout)
+		l_timeout_remove(timeout);
 }
 
+
 /*
  * Process frames in a similar way to how the kernel built-in hwsim medium
  * does this, with an additional optimization for unicast frames and
@@ -1457,7 +1459,7 @@ static void process_frame(struct hwsim_frame *frame)
 		struct radio_info_rec *radio = entry->data;
 		struct send_frame_info *send_info;
 		bool drop = drop_mcast;
-		uint32_t delay = HWSIM_DELAY_MIN_MS;
+		uint32_t delay = 0;
 
 		if (radio == frame->src_radio)
 			continue;
@@ -1499,11 +1501,16 @@ static void process_frame(struct hwsim_frame *frame)
 		send_info->radio = radio;
 		send_info->frame = hwsim_frame_ref(frame);
 
-		if (!l_timeout_create_ms(delay, frame_delay_callback,
-						send_info, NULL)) {
-			l_error("Error delaying frame, frame will be dropped");
-			send_frame_destroy(send_info);
-		}
+		if (delay) {
+			if (!l_timeout_create_ms(delay, frame_delay_callback,
+							send_info, NULL)) {
+				l_error("Error delaying frame %ums, "
+						"frame will be dropped", delay);
+				send_frame_destroy(send_info);
+			}
+		} else
+			frame_delay_callback(NULL, send_info);
+
 	}
 
 	hwsim_frame_unref(frame);
@@ -1999,7 +2006,7 @@ static struct l_dbus_message *rule_add(struct l_dbus *dbus,
 	rule->id = next_rule_id++;
 	rule->source_any = true;
 	rule->destination_any = true;
-	rule->delay = HWSIM_DELAY_MIN_MS;
+	rule->delay = 0;
 	rule->enabled = false;
 
 	if (!rules)
-- 
2.31.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/8] auto-t: hwsim.py: add Enabled property
  2021-08-18 22:09 [PATCH 1/8] anqp: print MAC when sending ANQP request James Prestwood
  2021-08-18 22:09 ` [PATCH 2/8] hwsim: require enabling rule before use James Prestwood
  2021-08-18 22:09 ` [PATCH 3/8] hwsim: remove unconditional packet delay James Prestwood
@ 2021-08-18 22:09 ` James Prestwood
  2021-08-18 22:09 ` [PATCH 5/8] auto-t: hwsim.py: handle Prefix/Enabled in __str__ James Prestwood
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: James Prestwood @ 2021-08-18 22:09 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 902 bytes --]

---
 autotests/util/hwsim.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/autotests/util/hwsim.py b/autotests/util/hwsim.py
index 4e3b8ec2..3a83bcd8 100755
--- a/autotests/util/hwsim.py
+++ b/autotests/util/hwsim.py
@@ -142,6 +142,16 @@ class Rule(HwsimDBusAbstract):
                             reply_handler=self._success, error_handler=self._failure)
         self._wait_for_async_op()
 
+    @property
+    def enabled(self):
+        return self._properties['Enabled']
+
+    @enabled.setter
+    def enabled(self, value):
+        self._prop_proxy.Set(self._iface_name, 'Enabled', value,
+                            reply_handler=self._success, error_handler=self._failure)
+        self._wait_for_async_op()
+
     def remove(self):
         self._iface.Remove(reply_handler=self._success,
                 error_handler=self._failure)
-- 
2.31.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/8] auto-t: hwsim.py: handle Prefix/Enabled in __str__
  2021-08-18 22:09 [PATCH 1/8] anqp: print MAC when sending ANQP request James Prestwood
                   ` (2 preceding siblings ...)
  2021-08-18 22:09 ` [PATCH 4/8] auto-t: hwsim.py: add Enabled property James Prestwood
@ 2021-08-18 22:09 ` James Prestwood
  2021-08-18 22:09 ` [PATCH 6/8] auto-t: combine testBSSBlacklist tests James Prestwood
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: James Prestwood @ 2021-08-18 22:09 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 928 bytes --]

---
 autotests/util/hwsim.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/autotests/util/hwsim.py b/autotests/util/hwsim.py
index 3a83bcd8..52543062 100755
--- a/autotests/util/hwsim.py
+++ b/autotests/util/hwsim.py
@@ -171,7 +171,9 @@ class Rule(HwsimDBusAbstract):
                prefix + '\tFrequency:\t' + str(self.frequency) + '\n' + \
                prefix + '\tApply rssi:\t' + str(self.signal) + '\n' + \
                prefix + '\tApply drop:\t' + str(self.drop) + '\n' + \
-               prefix + '\tPrefix:\t' + str([hex(b) for b in self.prefix]) + '\n'
+               prefix + '\tPrefix:\t' + str([hex(b) for b in self.prefix]) + '\n' + \
+               prefix + '\tDelay:\t' + str(self.delay) + '\n' + \
+               prefix + '\tEnabled:\t' + str(self.enabled) + '\n'
 
 class RuleSet(collections.Mapping):
     def __init__(self, hwsim, objects):
-- 
2.31.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6/8] auto-t: combine testBSSBlacklist tests
  2021-08-18 22:09 [PATCH 1/8] anqp: print MAC when sending ANQP request James Prestwood
                   ` (3 preceding siblings ...)
  2021-08-18 22:09 ` [PATCH 5/8] auto-t: hwsim.py: handle Prefix/Enabled in __str__ James Prestwood
@ 2021-08-18 22:09 ` James Prestwood
  2021-08-18 22:09 ` [PATCH 7/8] auto-t: update tests to enable hwsim rules James Prestwood
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: James Prestwood @ 2021-08-18 22:09 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 19224 bytes --]

All 4 tests were combined to reuse hwsim rule code, and improve
cleanup between running tests.
---
 .../testBSSBlacklist/all_blacklisted_test.py  |  97 --------
 autotests/testBSSBlacklist/bad_pass_test.py   |  90 -------
 autotests/testBSSBlacklist/connection_test.py | 220 +++++++++++++++---
 .../testBSSBlacklist/temp_blacklist_test.py   | 116 ---------
 4 files changed, 192 insertions(+), 331 deletions(-)
 delete mode 100644 autotests/testBSSBlacklist/all_blacklisted_test.py
 delete mode 100644 autotests/testBSSBlacklist/bad_pass_test.py
 delete mode 100644 autotests/testBSSBlacklist/temp_blacklist_test.py

diff --git a/autotests/testBSSBlacklist/all_blacklisted_test.py b/autotests/testBSSBlacklist/all_blacklisted_test.py
deleted file mode 100644
index 4d8cca1e..00000000
--- a/autotests/testBSSBlacklist/all_blacklisted_test.py
+++ /dev/null
@@ -1,97 +0,0 @@
-#!/usr/bin/python3
-
-import unittest
-import sys
-
-sys.path.append('../util')
-import iwd
-from iwd import IWD
-from iwd import PSKAgent
-from iwd import NetworkType
-
-from hostapd import HostapdCLI
-from hwsim import Hwsim
-
-class Test(unittest.TestCase):
-
-    def test_connection_success(self):
-        hwsim = Hwsim()
-
-        bss_hostapd = [ HostapdCLI(config='ssid1.conf'),
-                        HostapdCLI(config='ssid2.conf'),
-                        HostapdCLI(config='ssid3.conf') ]
-        bss_radio =  [ hwsim.get_radio('rad0'),
-                       hwsim.get_radio('rad1'),
-                       hwsim.get_radio('rad2') ]
-
-        rule0 = hwsim.rules.create()
-        rule0.source = bss_radio[0].addresses[0]
-        rule0.bidirectional = True
-        rule0.signal = -2000
-
-        rule1 = hwsim.rules.create()
-        rule1.source = bss_radio[1].addresses[0]
-        rule1.bidirectional = True
-        rule1.signal = -8000
-
-        rule2 = hwsim.rules.create()
-        rule2.source = bss_radio[2].addresses[0]
-        rule2.bidirectional = True
-        rule2.signal = -9000
-
-        wd = IWD(True)
-
-        psk_agent = PSKAgent(["secret123", 'secret123'])
-        wd.register_psk_agent(psk_agent)
-
-        devices = wd.list_devices(1)
-        device = devices[0]
-
-        ordered_network = device.get_ordered_network("TestBlacklist")
-
-        self.assertEqual(ordered_network.type, NetworkType.psk)
-
-        condition = 'not obj.connected'
-        wd.wait_for_object_condition(ordered_network.network_object, condition)
-
-        # Have both APs drop all packets, both should get blacklisted
-        rule0.drop = True
-        rule1.drop = True
-        rule2.drop = True
-
-        with self.assertRaises(iwd.FailedEx):
-            ordered_network.network_object.connect()
-
-        rule0.drop = False
-        rule1.drop = False
-        rule2.drop = False
-
-        # Wait for scanning (likely a quick-scan) to finish, otherwise we will
-        # may not have all BSS's in the list.
-        condition = 'not obj.scanning'
-        wd.wait_for_object_condition(device, condition)
-
-        # This connect should work
-        ordered_network.network_object.connect()
-
-        condition = 'obj.state == DeviceState.connected'
-        wd.wait_for_object_condition(device, condition)
-
-        self.assertIn(device.address, bss_hostapd[0].list_sta())
-
-        wd.unregister_psk_agent(psk_agent)
-
-        rule0.remove()
-        rule1.remove()
-        rule2.remove()
-
-    @classmethod
-    def setUpClass(cls):
-        pass
-
-    @classmethod
-    def tearDownClass(cls):
-        IWD.clear_storage()
-
-if __name__ == '__main__':
-    unittest.main(exit=True)
diff --git a/autotests/testBSSBlacklist/bad_pass_test.py b/autotests/testBSSBlacklist/bad_pass_test.py
deleted file mode 100644
index 5ea5df0c..00000000
--- a/autotests/testBSSBlacklist/bad_pass_test.py
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/usr/bin/python3
-
-import unittest
-import sys
-
-sys.path.append('../util')
-import iwd
-from iwd import IWD
-from iwd import PSKAgent
-from iwd import NetworkType
-
-from hostapd import HostapdCLI
-from hwsim import Hwsim
-
-class Test(unittest.TestCase):
-
-    def test_connection_success(self):
-        hwsim = Hwsim()
-
-        bss_hostapd = [ HostapdCLI(config='ssid1.conf'),
-                        HostapdCLI(config='ssid2.conf'),
-                        HostapdCLI(config='ssid3.conf') ]
-        bss_radio =  [ hwsim.get_radio('rad0'),
-                       hwsim.get_radio('rad1'),
-                       hwsim.get_radio('rad2') ]
-
-        rule0 = hwsim.rules.create()
-        rule0.source = bss_radio[0].addresses[0]
-        rule0.bidirectional = True
-        rule0.signal = -2000
-
-        rule1 = hwsim.rules.create()
-        rule1.source = bss_radio[1].addresses[0]
-        rule1.bidirectional = True
-        rule1.signal = -7000
-
-        rule2 = hwsim.rules.create()
-        rule2.source = bss_radio[2].addresses[0]
-        rule2.bidirectional = True
-        rule2.signal = -8000
-
-        wd = IWD(True)
-
-        psk_agent = PSKAgent("wrong_password")
-        wd.register_psk_agent(psk_agent)
-
-        devices = wd.list_devices(1)
-        device = devices[0]
-
-        ordered_network = device.get_ordered_network("TestBlacklist")
-
-        self.assertEqual(ordered_network.type, NetworkType.psk)
-
-        condition = 'not obj.connected'
-        wd.wait_for_object_condition(ordered_network.network_object, condition)
-
-        with self.assertRaises(iwd.FailedEx):
-            ordered_network.network_object.connect()
-
-        wd.unregister_psk_agent(psk_agent)
-
-        psk_agent = PSKAgent("secret123")
-        wd.register_psk_agent(psk_agent)
-
-        ordered_network.network_object.connect()
-
-        # We failed to connect bss_hostapd[0], but with a bad password. Verify
-        # that this did not trigger a blacklist and that we did reconnect
-        # successfully to bss_hostapd[0]
-        self.assertIn(device.address, bss_hostapd[0].list_sta())
-
-        condition = 'obj.state == DeviceState.connected'
-        wd.wait_for_object_condition(device, condition)
-
-        wd.unregister_psk_agent(psk_agent)
-
-        rule0.remove()
-        rule1.remove()
-        rule2.remove()
-
-    @classmethod
-    def setUpClass(cls):
-        pass
-
-    @classmethod
-    def tearDownClass(cls):
-        IWD.clear_storage()
-
-if __name__ == '__main__':
-    unittest.main(exit=True)
diff --git a/autotests/testBSSBlacklist/connection_test.py b/autotests/testBSSBlacklist/connection_test.py
index 407ee06a..bfcf0523 100644
--- a/autotests/testBSSBlacklist/connection_test.py
+++ b/autotests/testBSSBlacklist/connection_test.py
@@ -8,6 +8,7 @@ import iwd
 from iwd import IWD
 from iwd import PSKAgent
 from iwd import NetworkType
+from iwd import IWD_CONFIG_DIR
 
 from hostapd import HostapdCLI
 from hwsim import Hwsim
@@ -15,33 +16,166 @@ from hwsim import Hwsim
 import time
 
 class Test(unittest.TestCase):
+    def test_temp_blacklist(self):
+        rule0 = self.rule0
+        rule1 = self.rule1
+        rule2 = self.rule2
 
-    def test_connection_success(self):
-        hwsim = Hwsim()
-
-        bss_hostapd = [ HostapdCLI(config='ssid1.conf'),
-                        HostapdCLI(config='ssid2.conf'),
-                        HostapdCLI(config='ssid3.conf') ]
-        bss_radio =  [ hwsim.get_radio('rad0'),
-                       hwsim.get_radio('rad1'),
-                       hwsim.get_radio('rad2') ]
-
-        rule0 = hwsim.rules.create()
-        rule0.source = bss_radio[0].addresses[0]
-        rule0.bidirectional = True
-        rule0.signal = -2000
-
-        rule1 = hwsim.rules.create()
-        rule1.source = bss_radio[1].addresses[0]
-        rule1.bidirectional = True
+        bss_hostapd = self.bss_hostapd
+        wd = self.wd
+
+        rule0.signal = -8000
         rule1.signal = -7000
+        rule2.signal = -2000
+
+        psk_agent = PSKAgent("secret123")
+        wd.register_psk_agent(psk_agent)
+
+        dev1, dev2 = wd.list_devices(2)
+
+        ordered_network = dev1.get_ordered_network("TestBlacklist")
+
+        self.assertEqual(ordered_network.type, NetworkType.psk)
+
+        condition = 'not obj.connected'
+        wd.wait_for_object_condition(ordered_network.network_object, condition)
+
+        ordered_network.network_object.connect()
+
+        condition = 'obj.state == DeviceState.connected'
+        wd.wait_for_object_condition(dev1, condition)
+
+        self.assertIn(dev1.address, bss_hostapd[2].list_sta())
+
+        # dev1 now connected, this should max out the first AP, causing the next
+        # connection to fail to this AP.
+
+        ordered_network = dev2.get_ordered_network("TestBlacklist")
+
+        self.assertEqual(ordered_network.type, NetworkType.psk)
+
+        condition = 'not obj.connected'
+        wd.wait_for_object_condition(ordered_network.network_object, condition)
+
+        ordered_network.network_object.connect()
+
+        condition = 'obj.state == DeviceState.connected'
+        wd.wait_for_object_condition(dev2, condition)
+
+        # We should have temporarily blacklisted the first BSS, and connected
+        # to this one.
+        self.assertIn(dev2.address, bss_hostapd[1].list_sta())
+
+        # Now check that the first BSS is still not blacklisted. We can
+        # disconnect dev1, opening up the AP for more connections
+        dev1.disconnect()
+        dev2.disconnect()
+
+        ordered_network = dev2.get_ordered_network("TestBlacklist")
+
+        self.assertEqual(ordered_network.type, NetworkType.psk)
+
+        condition = 'not obj.connected'
+        wd.wait_for_object_condition(ordered_network.network_object, condition)
+
+        ordered_network.network_object.connect()
+
+        condition = 'obj.state == DeviceState.connected'
+        wd.wait_for_object_condition(dev2, condition)
+
+        self.assertIn(dev2.address, bss_hostapd[2].list_sta())
+
+        wd.unregister_psk_agent(psk_agent)
+
+    def test_all_blacklisted(self):
+        wd = self.wd
+        bss_hostapd = self.bss_hostapd
+
+        rule0 = self.rule0
+        rule1 = self.rule1
+        rule2 = self.rule2
+
+        psk_agent = PSKAgent(["secret123", 'secret123'])
+        wd.register_psk_agent(psk_agent)
+
+        devices = wd.list_devices(1)
+        device = devices[0]
+
+        ordered_network = device.get_ordered_network("TestBlacklist")
+
+        self.assertEqual(ordered_network.type, NetworkType.psk)
+
+        condition = 'not obj.connected'
+        wd.wait_for_object_condition(ordered_network.network_object, condition)
+
+        # Have both APs drop all packets, both should get blacklisted
+        rule0.drop = True
+        rule1.drop = True
+        rule2.drop = True
+
+        with self.assertRaises(iwd.FailedEx):
+            ordered_network.network_object.connect()
+
+        rule0.drop = False
+        rule1.drop = False
+        rule2.drop = False
+
+        # Wait for scanning (likely a quick-scan) to finish, otherwise we will
+        # may not have all BSS's in the list.
+        condition = 'not obj.scanning'
+        wd.wait_for_object_condition(device, condition)
+
+        # This connect should work
+        ordered_network.network_object.connect()
+
+        condition = 'obj.state == DeviceState.connected'
+        wd.wait_for_object_condition(device, condition)
+
+        self.assertIn(device.address, bss_hostapd[0].list_sta())
+
+        wd.unregister_psk_agent(psk_agent)
+
+    def test_invalid_password(self):
+        wd = self.wd
+        bss_hostapd = self.bss_hostapd
+
+        psk_agent = PSKAgent("wrong_password")
+        wd.register_psk_agent(psk_agent)
+
+        devices = wd.list_devices(1)
+        device = devices[0]
 
-        rule2 = hwsim.rules.create()
-        rule2.source = bss_radio[2].addresses[0]
-        rule2.bidirectional = True
-        rule2.signal = -8000
+        ordered_network = device.get_ordered_network("TestBlacklist")
+
+        self.assertEqual(ordered_network.type, NetworkType.psk)
+
+        condition = 'not obj.connected'
+        wd.wait_for_object_condition(ordered_network.network_object, condition)
+
+        with self.assertRaises(iwd.FailedEx):
+            ordered_network.network_object.connect()
+
+        wd.unregister_psk_agent(psk_agent)
+
+        psk_agent = PSKAgent("secret123")
+        wd.register_psk_agent(psk_agent)
+
+        ordered_network.network_object.connect()
+
+        # We failed to connect bss_hostapd[0], but with a bad password. Verify
+        # that this did not trigger a blacklist and that we did reconnect
+        # successfully to bss_hostapd[0]
+        self.assertIn(device.address, bss_hostapd[0].list_sta())
 
-        wd = IWD(True)
+        condition = 'obj.state == DeviceState.connected'
+        wd.wait_for_object_condition(device, condition)
+
+        wd.unregister_psk_agent(psk_agent)
+
+    def test_connection_success(self):
+        wd = self.wd
+        bss_hostapd = self.bss_hostapd
+        rule0 = self.rule0
 
         psk_agent = PSKAgent("secret123")
         wd.register_psk_agent(psk_agent)
@@ -129,19 +263,49 @@ class Test(unittest.TestCase):
 
         self.assertIn(device.address, bss_hostapd[0].list_sta())
 
-        wd.unregister_psk_agent(psk_agent)
+        self.wd.unregister_psk_agent(psk_agent)
 
-        rule0.remove()
-        rule1.remove()
-        rule2.remove()
+    def setUp(self):
+        self.wd = IWD(True)
+
+    def tearDown(self):
+        IWD.clear_storage()
+        self.wd = None
 
     @classmethod
     def setUpClass(cls):
-        IWD.copy_to_storage('main.conf')
+        cls.hwsim = Hwsim()
+
+        cls.bss_hostapd = [ HostapdCLI(config='ssid1.conf'),
+                            HostapdCLI(config='ssid2.conf'),
+                            HostapdCLI(config='ssid3.conf') ]
+        cls.bss_radio =  [ cls.hwsim.get_radio('rad0'),
+                       cls.hwsim.get_radio('rad1'),
+                       cls.hwsim.get_radio('rad2') ]
+
+        cls.rule0 = cls.hwsim.rules.create()
+        cls.rule0.source = cls.bss_radio[0].addresses[0]
+        cls.rule0.bidirectional = True
+        cls.rule0.signal = -2000
+        cls.rule0.enabled = True
+
+        cls.rule1 = cls.hwsim.rules.create()
+        cls.rule1.source = cls.bss_radio[1].addresses[0]
+        cls.rule1.bidirectional = True
+        cls.rule1.signal = -7000
+        cls.rule1.enabled = True
+
+        cls.rule2 = cls.hwsim.rules.create()
+        cls.rule2.source = cls.bss_radio[2].addresses[0]
+        cls.rule2.bidirectional = True
+        cls.rule2.signal = -8000
+        cls.rule2.enabled = True
 
     @classmethod
     def tearDownClass(cls):
         IWD.clear_storage()
 
+        cls.hwsim.rules.remove_all()
+
 if __name__ == '__main__':
     unittest.main(exit=True)
diff --git a/autotests/testBSSBlacklist/temp_blacklist_test.py b/autotests/testBSSBlacklist/temp_blacklist_test.py
deleted file mode 100644
index cbd07ad2..00000000
--- a/autotests/testBSSBlacklist/temp_blacklist_test.py
+++ /dev/null
@@ -1,116 +0,0 @@
-#!/usr/bin/python3
-
-import unittest
-import sys
-
-sys.path.append('../util')
-import iwd
-from iwd import IWD
-from iwd import PSKAgent
-from iwd import NetworkType
-
-from hostapd import HostapdCLI
-from hwsim import Hwsim
-
-class Test(unittest.TestCase):
-
-    def test_connection_success(self):
-        hwsim = Hwsim()
-
-        bss_hostapd = [ HostapdCLI(config='ssid1.conf'),
-                        HostapdCLI(config='ssid2.conf'),
-                        HostapdCLI(config='ssid3.conf') ]
-        bss_radio =  [ hwsim.get_radio('rad0'),
-                       hwsim.get_radio('rad1'),
-                       hwsim.get_radio('rad2') ]
-
-        rule0 = hwsim.rules.create()
-        rule0.source = bss_radio[0].addresses[0]
-        rule0.bidirectional = True
-        rule0.signal = -8000
-
-        rule1 = hwsim.rules.create()
-        rule1.source = bss_radio[1].addresses[0]
-        rule1.bidirectional = True
-        rule1.signal = -7000
-
-        rule2 = hwsim.rules.create()
-        rule2.source = bss_radio[2].addresses[0]
-        rule2.bidirectional = True
-        rule2.signal = -2000
-
-        wd = IWD(True)
-
-        psk_agent = PSKAgent("secret123")
-        wd.register_psk_agent(psk_agent)
-
-        dev1, dev2 = wd.list_devices(2)
-
-        ordered_network = dev1.get_ordered_network("TestBlacklist")
-
-        self.assertEqual(ordered_network.type, NetworkType.psk)
-
-        condition = 'not obj.connected'
-        wd.wait_for_object_condition(ordered_network.network_object, condition)
-
-        ordered_network.network_object.connect()
-
-        condition = 'obj.state == DeviceState.connected'
-        wd.wait_for_object_condition(dev1, condition)
-
-        self.assertIn(dev1.address, bss_hostapd[2].list_sta())
-
-        # dev1 now connected, this should max out the first AP, causing the next
-        # connection to fail to this AP.
-
-        ordered_network = dev2.get_ordered_network("TestBlacklist")
-
-        self.assertEqual(ordered_network.type, NetworkType.psk)
-
-        condition = 'not obj.connected'
-        wd.wait_for_object_condition(ordered_network.network_object, condition)
-
-        ordered_network.network_object.connect()
-
-        condition = 'obj.state == DeviceState.connected'
-        wd.wait_for_object_condition(dev2, condition)
-
-        # We should have temporarily blacklisted the first BSS, and connected
-        # to this one.
-        self.assertIn(dev2.address, bss_hostapd[1].list_sta())
-
-        # Now check that the first BSS is still not blacklisted. We can
-        # disconnect dev1, opening up the AP for more connections
-        dev1.disconnect()
-        dev2.disconnect()
-
-        ordered_network = dev2.get_ordered_network("TestBlacklist")
-
-        self.assertEqual(ordered_network.type, NetworkType.psk)
-
-        condition = 'not obj.connected'
-        wd.wait_for_object_condition(ordered_network.network_object, condition)
-
-        ordered_network.network_object.connect()
-
-        condition = 'obj.state == DeviceState.connected'
-        wd.wait_for_object_condition(dev2, condition)
-
-        self.assertIn(dev2.address, bss_hostapd[2].list_sta())
-
-        wd.unregister_psk_agent(psk_agent)
-
-        rule0.remove()
-        rule1.remove()
-        rule2.remove()
-
-    @classmethod
-    def setUpClass(cls):
-        IWD.copy_to_storage('main.conf')
-
-    @classmethod
-    def tearDownClass(cls):
-        IWD.clear_storage()
-
-if __name__ == '__main__':
-    unittest.main(exit=True)
-- 
2.31.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 7/8] auto-t: update tests to enable hwsim rules
  2021-08-18 22:09 [PATCH 1/8] anqp: print MAC when sending ANQP request James Prestwood
                   ` (4 preceding siblings ...)
  2021-08-18 22:09 ` [PATCH 6/8] auto-t: combine testBSSBlacklist tests James Prestwood
@ 2021-08-18 22:09 ` James Prestwood
  2021-08-18 22:09 ` [PATCH 8/8] auto-t: remove ANQP delay test James Prestwood
  2021-08-19  0:53 ` [PATCH 1/8] anqp: print MAC when sending ANQP request Denis Kenzior
  7 siblings, 0 replies; 9+ messages in thread
From: James Prestwood @ 2021-08-18 22:09 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 4246 bytes --]

---
 autotests/testHT-VHT/connection_test.py    | 3 +++
 autotests/testOWE/timeout_test.py          | 2 ++
 autotests/testRSSIAgent/connection_test.py | 1 +
 autotests/testRoamRetry/fast_retry_test.py | 2 ++
 autotests/testRoamRetry/stop_retry_test.py | 2 ++
 autotests/testSAE/timeout_test.py          | 1 +
 6 files changed, 11 insertions(+)

diff --git a/autotests/testHT-VHT/connection_test.py b/autotests/testHT-VHT/connection_test.py
index 3d190509..051822c2 100644
--- a/autotests/testHT-VHT/connection_test.py
+++ b/autotests/testHT-VHT/connection_test.py
@@ -66,16 +66,19 @@ class Test(unittest.TestCase):
         rule0.source = vht_radio.addresses[0]
         rule0.bidirectional = True
         rule0.signal = -5100
+        rule0.enabled = True
 
         rule1 = hwsim.rules.create()
         rule1.source = ht_radio.addresses[0]
         rule1.bidirectional = True
         rule1.signal = -5200
+        rule1.enabled = True
 
         rule2 = hwsim.rules.create()
         rule2.source = non_ht_radio.addresses[0]
         rule2.bidirectional = True
         rule2.signal = -5300
+        rule2.enabled = True
 
         wd = IWD()
 
diff --git a/autotests/testOWE/timeout_test.py b/autotests/testOWE/timeout_test.py
index fbf79f4c..96d367b3 100644
--- a/autotests/testOWE/timeout_test.py
+++ b/autotests/testOWE/timeout_test.py
@@ -39,12 +39,14 @@ class Test(unittest.TestCase):
         rule0.bidirectional = True
         rule0.drop = True
         rule0.prefix = 'b0'
+        rule0.enabled = True
 
         rule1 = hwsim.rules.create()
         rule1.source = bss_radio1.addresses[0]
         rule1.bidirectional = True
         rule1.drop = True
         rule1.prefix = 'b0'
+        rule1.enabled = True
 
         # Test Authenticate (b0) and Association (00) timeouts
 
diff --git a/autotests/testRSSIAgent/connection_test.py b/autotests/testRSSIAgent/connection_test.py
index f485b388..ded09f6c 100644
--- a/autotests/testRSSIAgent/connection_test.py
+++ b/autotests/testRSSIAgent/connection_test.py
@@ -20,6 +20,7 @@ class Test(unittest.TestCase):
     def test_rssi_agent(self):
         rule = Hwsim().rules.create()
         rule.signal = -4000
+        rule.enabled = True
 
         wd = IWD()
 
diff --git a/autotests/testRoamRetry/fast_retry_test.py b/autotests/testRoamRetry/fast_retry_test.py
index e8b5455d..c7de5055 100644
--- a/autotests/testRoamRetry/fast_retry_test.py
+++ b/autotests/testRoamRetry/fast_retry_test.py
@@ -29,10 +29,12 @@ class Test(unittest.TestCase):
         rule0 = hwsim.rules.create()
         rule0.source = bss_radio[0].addresses[0]
         rule0.bidirectional = True
+        rule0.enabled = True
 
         rule1 = hwsim.rules.create()
         rule1.source = bss_radio[1].addresses[0]
         rule1.bidirectional = True
+        rule1.enabled = True
 
         # Fill in the neighbor AP tables in both BSSes.  By default each
         # instance knows only about current BSS, even inside one hostapd
diff --git a/autotests/testRoamRetry/stop_retry_test.py b/autotests/testRoamRetry/stop_retry_test.py
index 3bf166d8..f2f95990 100644
--- a/autotests/testRoamRetry/stop_retry_test.py
+++ b/autotests/testRoamRetry/stop_retry_test.py
@@ -28,10 +28,12 @@ class Test(unittest.TestCase):
         rule0 = hwsim.rules.create()
         rule0.source = bss_radio[0].addresses[0]
         rule0.bidirectional = True
+        rule0.enabled = True
 
         rule1 = hwsim.rules.create()
         rule1.source = bss_radio[1].addresses[0]
         rule1.bidirectional = True
+        rule1.enabled = True
 
         # Fill in the neighbor AP tables in both BSSes.  By default each
         # instance knows only about current BSS, even inside one hostapd
diff --git a/autotests/testSAE/timeout_test.py b/autotests/testSAE/timeout_test.py
index 28ff288c..abef109b 100644
--- a/autotests/testSAE/timeout_test.py
+++ b/autotests/testSAE/timeout_test.py
@@ -35,6 +35,7 @@ class Test(unittest.TestCase):
         rule0.bidirectional = True
         rule0.drop = True
         rule0.prefix = 'b0'
+        rule0.enabled = True
 
         wd.wait(1)
         print(rule0)
-- 
2.31.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 8/8] auto-t: remove ANQP delay test
  2021-08-18 22:09 [PATCH 1/8] anqp: print MAC when sending ANQP request James Prestwood
                   ` (5 preceding siblings ...)
  2021-08-18 22:09 ` [PATCH 7/8] auto-t: update tests to enable hwsim rules James Prestwood
@ 2021-08-18 22:09 ` James Prestwood
  2021-08-19  0:53 ` [PATCH 1/8] anqp: print MAC when sending ANQP request Denis Kenzior
  7 siblings, 0 replies; 9+ messages in thread
From: James Prestwood @ 2021-08-18 22:09 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 4052 bytes --]

The idea of this test is valid but it is extremely timing dependent
which simply isn't testable on all machines. Removing this test
at least until this can be tested reliably.
---
 autotests/testHotspot/anqp_delay_test.py | 106 -----------------------
 1 file changed, 106 deletions(-)
 delete mode 100644 autotests/testHotspot/anqp_delay_test.py

diff --git a/autotests/testHotspot/anqp_delay_test.py b/autotests/testHotspot/anqp_delay_test.py
deleted file mode 100644
index 22a5bdbe..00000000
--- a/autotests/testHotspot/anqp_delay_test.py
+++ /dev/null
@@ -1,106 +0,0 @@
-#!/usr/bin/python3
-
-import unittest
-import sys
-import os
-
-sys.path.append('../util')
-from iwd import IWD
-from iwd import IWD_CONFIG_DIR
-from iwd import PSKAgent
-from iwd import NetworkType
-from hostapd import HostapdCLI
-from hwsim import Hwsim
-import testutil
-from time import sleep
-
-class Test(unittest.TestCase):
-
-    def test_connection_success(self):
-        wd = self.wd
-        hapd = self.hapd
-        rule0 = self.rule0
-
-        devices = wd.list_devices(1)
-        device = devices[0]
-        device.autoconnect = True
-
-        # We are dependent on a periodic scan here. We want to wait for this
-        # because this is the first opportunity IWD has to do ANQP. Once ANQP
-        # has been done once the network is set up and we cannot simulate the
-        # 'Connect() before ANQP' race condition anymore.
-        condition = 'obj.scanning'
-        wd.wait_for_object_condition(device, condition)
-
-        condition = 'not obj.scanning'
-        wd.wait_for_object_condition(device, condition)
-
-        # If no networks were found we likely had a quick scan. Try again to
-        # allow the full autoconnect scan to happen.
-        try:
-            ordered_network = device.get_ordered_network('Hotspot')
-        except:
-            condition = 'obj.scanning'
-            wd.wait_for_object_condition(device, condition)
-
-            condition = 'not obj.scanning'
-            wd.wait_for_object_condition(device, condition)
-
-            ordered_network = device.get_ordered_network('Hotspot')
-
-        self.assertEqual(ordered_network.type, NetworkType.eap)
-
-        condition = 'not obj.connected'
-        wd.wait_for_object_condition(ordered_network.network_object, condition)
-
-        # Force the case where ANQP does not finish before Connect() comes in
-        rule0.delay = 100
-        rule0.prefix = '0d'
-
-        ordered_network.network_object.connect(wait=False)
-
-        condition = 'obj.state == DeviceState.connected'
-        wd.wait_for_object_condition(device, condition)
-
-        hapd.wait_for_event('AP-STA-CONNECTED')
-
-        testutil.test_iface_operstate()
-        testutil.test_ifaces_connected(device.name, hapd.ifname)
-
-        device.disconnect()
-
-        condition = 'not obj.connected'
-        wd.wait_for_object_condition(ordered_network.network_object, condition)
-
-    @classmethod
-    def setUpClass(cls):
-        cls.hwsim = Hwsim()
-
-        bss_radio = cls.hwsim.get_radio('rad0')
-        cls.rule0 = cls.hwsim.rules.create()
-        cls.rule0.source = bss_radio.addresses[0]
-        cls.rule0.bidirectional = True
-
-        cls.hapd = HostapdCLI(config='ssidHotspot.conf')
-
-        IWD.copy_to_hotspot('example.conf')
-        IWD.copy_to_storage('anqp_enabled.conf', storage_dir=IWD_CONFIG_DIR, name='main.conf')
-
-        cls.wd = IWD(True)
-        cls.psk_agent = PSKAgent('abc', ('domain\\user', 'testpasswd'))
-        cls.wd.register_psk_agent(cls.psk_agent)
-
-    @classmethod
-    def tearDownClass(cls):
-        IWD.clear_storage()
-
-        cls.wd.unregister_psk_agent(cls.psk_agent)
-        cls.psk_agent = None
-        os.remove('/tmp/main.conf')
-
-        cls.hwsim.rules.remove_all()
-        cls.hwsim = None
-        cls.wd = None
-
-if __name__ == '__main__':
-    unittest.main(exit=True)
-- 
2.31.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/8] anqp: print MAC when sending ANQP request
  2021-08-18 22:09 [PATCH 1/8] anqp: print MAC when sending ANQP request James Prestwood
                   ` (6 preceding siblings ...)
  2021-08-18 22:09 ` [PATCH 8/8] auto-t: remove ANQP delay test James Prestwood
@ 2021-08-19  0:53 ` Denis Kenzior
  7 siblings, 0 replies; 9+ messages in thread
From: Denis Kenzior @ 2021-08-19  0:53 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 184 bytes --]

Hi James,

On 8/18/21 5:09 PM, James Prestwood wrote:
> ---
>   src/anqp.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 

All applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-08-19  0:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-18 22:09 [PATCH 1/8] anqp: print MAC when sending ANQP request James Prestwood
2021-08-18 22:09 ` [PATCH 2/8] hwsim: require enabling rule before use James Prestwood
2021-08-18 22:09 ` [PATCH 3/8] hwsim: remove unconditional packet delay James Prestwood
2021-08-18 22:09 ` [PATCH 4/8] auto-t: hwsim.py: add Enabled property James Prestwood
2021-08-18 22:09 ` [PATCH 5/8] auto-t: hwsim.py: handle Prefix/Enabled in __str__ James Prestwood
2021-08-18 22:09 ` [PATCH 6/8] auto-t: combine testBSSBlacklist tests James Prestwood
2021-08-18 22:09 ` [PATCH 7/8] auto-t: update tests to enable hwsim rules James Prestwood
2021-08-18 22:09 ` [PATCH 8/8] auto-t: remove ANQP delay test James Prestwood
2021-08-19  0:53 ` [PATCH 1/8] anqp: print MAC when sending ANQP request Denis Kenzior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).