iwd.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v3 1/6] hwsim: add MatchBytes/MatchBytesOffset rule properties
  2021-09-09 22:08 [PATCH v3 1/6] hwsim: add MatchBytes/MatchBytesOffset rule properties James Prestwood
@ 2021-09-09 22:01 ` Denis Kenzior
  2021-09-09 22:08 ` [PATCH v3 2/6] auto-t: hwsim.py: add match/match_offset properties James Prestwood
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Denis Kenzior @ 2021-09-09 22:01 UTC (permalink / raw)
  To: iwd

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

Hi James,

On 9/9/21 5:08 PM, James Prestwood wrote:
> If set, a rule will start matching 'MatchBytes' some number of bytes
> into the frame (MatchBytesOffset). This is useful since header
> information, addresses, and sequence numbers may be unpredictable
> between test runs.
> 
> To avoid unintended matches the Prefix property is left unchanged
> and will match starting at the beginning of the frame.
> ---
>   tools/hwsim.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 106 insertions(+)
> 

All applied, thanks.

Regards,
-Denis

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

* [PATCH v3 1/6] hwsim: add MatchBytes/MatchBytesOffset rule properties
@ 2021-09-09 22:08 James Prestwood
  2021-09-09 22:01 ` Denis Kenzior
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: James Prestwood @ 2021-09-09 22:08 UTC (permalink / raw)
  To: iwd

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

If set, a rule will start matching 'MatchBytes' some number of bytes
into the frame (MatchBytesOffset). This is useful since header
information, addresses, and sequence numbers may be unpredictable
between test runs.

To avoid unintended matches the Prefix property is left unchanged
and will match starting at the beginning of the frame.
---
 tools/hwsim.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 106 insertions(+)

diff --git a/tools/hwsim.c b/tools/hwsim.c
index 8fb9b0a4..2352dcce 100644
--- a/tools/hwsim.c
+++ b/tools/hwsim.c
@@ -132,6 +132,9 @@ struct hwsim_rule {
 	int delay;
 	uint8_t *prefix;
 	size_t prefix_len;
+	uint8_t *match;
+	size_t match_len;
+	uint16_t match_offset;
 	int match_times; /* negative value indicates unused */
 };
 
@@ -1218,6 +1221,14 @@ static void process_rules(const struct radio_info_rec *src_radio,
 				continue;
 		}
 
+		if (rule->match && frame->payload_len >=
+					rule->match_len + rule->match_offset) {
+			if (memcmp(rule->match,
+					frame->payload + rule->match_offset,
+					rule->match_len))
+				continue;
+		}
+
 		/* Rule deemed to match frame, apply any changes */
 		if (rule->match_times == 0)
 			continue;
@@ -2063,6 +2074,9 @@ static struct l_dbus_message *rule_remove(struct l_dbus *dbus,
 	if (rule->prefix)
 		l_free(rule->prefix);
 
+	if (rule->match)
+		l_free(rule->match);
+
 	l_free(rule);
 	l_dbus_unregister_object(dbus, path);
 
@@ -2394,6 +2408,90 @@ invalid_args:
 	return dbus_error_invalid_args(message);
 }
 
+static bool rule_property_get_match(struct l_dbus *dbus,
+					struct l_dbus_message *message,
+					struct l_dbus_message_builder *builder,
+					void *user_data)
+{
+	struct hwsim_rule *rule = user_data;
+	size_t i;
+
+	l_dbus_message_builder_enter_array(builder, "y");
+
+	for (i = 0; i < rule->match_len; i++)
+		l_dbus_message_builder_append_basic(builder, 'y',
+							rule->match + i);
+
+	l_dbus_message_builder_leave_array(builder);
+
+	return true;
+}
+
+static struct l_dbus_message *rule_property_set_match(
+					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;
+	struct l_dbus_message_iter iter;
+	const uint8_t *match;
+	uint32_t len;
+
+	if (!l_dbus_message_iter_get_variant(new_value, "ay", &iter))
+		goto invalid_args;
+
+	if (!l_dbus_message_iter_get_fixed_array(&iter,
+						(const void **)&match, &len))
+		goto invalid_args;
+
+	if (len > HWSIM_MAX_PREFIX_LEN)
+		goto invalid_args;
+
+	if (rule->match)
+		l_free(rule->match);
+
+	rule->match = l_memdup(match, len);
+	rule->match_len = len;
+
+	return l_dbus_message_new_method_return(message);
+
+invalid_args:
+	return dbus_error_invalid_args(message);
+}
+
+static bool rule_property_get_match_offset(struct l_dbus *dbus,
+					struct l_dbus_message *message,
+					struct l_dbus_message_builder *builder,
+					void *user_data)
+{
+	struct hwsim_rule *rule = user_data;
+	uint16_t val = rule->match_offset;
+
+	l_dbus_message_builder_append_basic(builder, 'q', &val);
+
+	return true;
+}
+
+static struct l_dbus_message *rule_property_set_match_offset(
+					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;
+	uint16_t val;
+
+	if (!l_dbus_message_iter_get_variant(new_value, "q", &val))
+		return dbus_error_invalid_args(message);
+
+	rule->match_offset = val;
+
+	return l_dbus_message_new_method_return(message);
+}
+
 static bool rule_property_get_enabled(struct l_dbus *dbus,
 					struct l_dbus_message *message,
 					struct l_dbus_message_builder *builder,
@@ -2527,6 +2625,14 @@ 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, "MatchBytes",
+					L_DBUS_PROPERTY_FLAG_AUTO_EMIT, "ay",
+					rule_property_get_match,
+					rule_property_set_match);
+	l_dbus_interface_property(interface, "MatchBytesOffset",
+					L_DBUS_PROPERTY_FLAG_AUTO_EMIT, "q",
+					rule_property_get_match_offset,
+					rule_property_set_match_offset);
 	l_dbus_interface_property(interface, "Enabled",
 					L_DBUS_PROPERTY_FLAG_AUTO_EMIT, "b",
 					rule_property_get_enabled,
-- 
2.31.1

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

* [PATCH v3 2/6] auto-t: hwsim.py: add match/match_offset properties
  2021-09-09 22:08 [PATCH v3 1/6] hwsim: add MatchBytes/MatchBytesOffset rule properties James Prestwood
  2021-09-09 22:01 ` Denis Kenzior
@ 2021-09-09 22:08 ` James Prestwood
  2021-09-09 22:08 ` [PATCH v3 3/6] auto-t: change testSAE timeout_test to use match/offset James Prestwood
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2021-09-09 22:08 UTC (permalink / raw)
  To: iwd

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

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

diff --git a/autotests/util/hwsim.py b/autotests/util/hwsim.py
index e5d336e3..34859910 100755
--- a/autotests/util/hwsim.py
+++ b/autotests/util/hwsim.py
@@ -169,6 +169,22 @@ class Rule(HwsimDBusAbstract):
     def drop_ack(self, value):
         self._prop_proxy.Set(self._iface_name, 'DropAck', value)
 
+    @property
+    def match(self):
+        return self._properties['MatchBytes']
+
+    @match.setter
+    def match(self, value):
+        self._prop_proxy.Set(self._iface_name, 'MatchBytes', dbus.ByteArray.fromhex(value))
+
+    @property
+    def match_offset(self):
+        return self._properties(['MatchBytesOffset'])
+
+    @match_offset.setter
+    def match_offset(self, value):
+        self._prop_proxy.Set(self._iface_name, 'MatchBytesOffset', dbus.UInt16(value))
+
     def remove(self):
         self._iface.Remove(reply_handler=self._success,
                 error_handler=self._failure)
-- 
2.31.1

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

* [PATCH v3 3/6] auto-t: change testSAE timeout_test to use match/offset
  2021-09-09 22:08 [PATCH v3 1/6] hwsim: add MatchBytes/MatchBytesOffset rule properties James Prestwood
  2021-09-09 22:01 ` Denis Kenzior
  2021-09-09 22:08 ` [PATCH v3 2/6] auto-t: hwsim.py: add match/match_offset properties James Prestwood
@ 2021-09-09 22:08 ` James Prestwood
  2021-09-09 22:08 ` [PATCH v3 4/6] auto-t: add SAE test for a non-ACKed confirm James Prestwood
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2021-09-09 22:08 UTC (permalink / raw)
  To: iwd

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

This makes things more clear on what frames are being blocked
since it passes over header information to get to the actual
SAE payload.
---
 autotests/testSAE/timeout_test.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/autotests/testSAE/timeout_test.py b/autotests/testSAE/timeout_test.py
index 1792f1c0..6f757edb 100644
--- a/autotests/testSAE/timeout_test.py
+++ b/autotests/testSAE/timeout_test.py
@@ -42,6 +42,8 @@ class Test(unittest.TestCase):
         #
         hostapd = HostapdCLI(config='ssidSAE.conf')
         hostapd.set_value('vendor_elements', 'dd0cf4f5e8050500000000000000')
+        hostapd.set_value('sae_groups', '19')
+        hostapd.reload()
 
         hwsim = Hwsim()
         bss_radio = hwsim.get_radio('rad0')
@@ -50,6 +52,8 @@ class Test(unittest.TestCase):
         rule0.source = bss_radio.addresses[0]
         rule0.drop = True
         rule0.prefix = 'b0'
+        rule0.match = '01 00 00 00 13 00'
+        rule0.match_offset = 26
         rule0.match_times = 1
         rule0.drop_ack = True
         rule0.enabled = True
@@ -57,6 +61,8 @@ class Test(unittest.TestCase):
         wd = IWD(True)
         self.validate_connection(wd)
 
+        rule0.remove()
+
     @classmethod
     def setUpClass(cls):
         pass
-- 
2.31.1

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

* [PATCH v3 4/6] auto-t: add SAE test for a non-ACKed confirm
  2021-09-09 22:08 [PATCH v3 1/6] hwsim: add MatchBytes/MatchBytesOffset rule properties James Prestwood
                   ` (2 preceding siblings ...)
  2021-09-09 22:08 ` [PATCH v3 3/6] auto-t: change testSAE timeout_test to use match/offset James Prestwood
@ 2021-09-09 22:08 ` James Prestwood
  2021-09-09 22:08 ` [PATCH v3 5/6] auto-t: add SAE test for no supported groups James Prestwood
  2021-09-09 22:08 ` [PATCH v3 6/6] auto-t: remove ';' in testSAE autoconnect_test.py James Prestwood
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2021-09-09 22:08 UTC (permalink / raw)
  To: iwd

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

---
 autotests/testSAE/timeout_test.py | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/autotests/testSAE/timeout_test.py b/autotests/testSAE/timeout_test.py
index 6f757edb..1413bb4a 100644
--- a/autotests/testSAE/timeout_test.py
+++ b/autotests/testSAE/timeout_test.py
@@ -63,6 +63,30 @@ class Test(unittest.TestCase):
 
         rule0.remove()
 
+    def test_sta_confirm_not_acked(self):
+        hostapd = HostapdCLI(config='ssidSAE.conf')
+        hostapd.set_value('vendor_elements', 'dd0cf4f5e8050500000000000000')
+        hostapd.set_value('sae_groups', '19')
+        hostapd.reload()
+
+        hwsim = Hwsim()
+        bss_radio = hwsim.get_radio('rad0')
+
+        rule0 = hwsim.rules.create()
+        rule0.source = bss_radio.addresses[0]
+        rule0.drop = True
+        rule0.prefix = 'b0'
+        rule0.match = '02 00 00 00'
+        rule0.match_offset = 26
+        rule0.match_times = 1
+        rule0.drop_ack = True
+        rule0.enabled = True
+
+        wd = IWD(True)
+        self.validate_connection(wd)
+
+        rule0.remove()
+
     @classmethod
     def setUpClass(cls):
         pass
-- 
2.31.1

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

* [PATCH v3 5/6] auto-t: add SAE test for no supported groups
  2021-09-09 22:08 [PATCH v3 1/6] hwsim: add MatchBytes/MatchBytesOffset rule properties James Prestwood
                   ` (3 preceding siblings ...)
  2021-09-09 22:08 ` [PATCH v3 4/6] auto-t: add SAE test for a non-ACKed confirm James Prestwood
@ 2021-09-09 22:08 ` James Prestwood
  2021-09-09 22:08 ` [PATCH v3 6/6] auto-t: remove ';' in testSAE autoconnect_test.py James Prestwood
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2021-09-09 22:08 UTC (permalink / raw)
  To: iwd

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

---
 autotests/testSAE/failure_test.py | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/autotests/testSAE/failure_test.py b/autotests/testSAE/failure_test.py
index 95872413..e61bf585 100644
--- a/autotests/testSAE/failure_test.py
+++ b/autotests/testSAE/failure_test.py
@@ -8,11 +8,12 @@ import iwd
 from iwd import IWD
 from iwd import PSKAgent
 from iwd import NetworkType
+from hostapd import HostapdCLI
 
 class Test(unittest.TestCase):
 
-    def validate_connection(self, wd):
-        psk_agent = PSKAgent("InvalidSecret")
+    def validate_connection(self, wd, passphrase):
+        psk_agent = PSKAgent(passphrase)
         wd.register_psk_agent(psk_agent)
 
         devices = wd.list_devices(1)
@@ -33,7 +34,15 @@ class Test(unittest.TestCase):
 
     def test_connection_success(self):
         wd = IWD(True)
-        self.validate_connection(wd)
+        self.validate_connection(wd, 'InvalidSecret')
+
+    def test_no_supported_groups(self):
+        hostapd = HostapdCLI(config='ssidSAE.conf')
+        hostapd.set_value('sae_groups', '1')
+        hostapd.reload()
+
+        wd = IWD(True)
+        self.validate_connection(wd, 'secret123')
 
     @classmethod
     def setUpClass(cls):
-- 
2.31.1

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

* [PATCH v3 6/6] auto-t: remove ';' in testSAE autoconnect_test.py
  2021-09-09 22:08 [PATCH v3 1/6] hwsim: add MatchBytes/MatchBytesOffset rule properties James Prestwood
                   ` (4 preceding siblings ...)
  2021-09-09 22:08 ` [PATCH v3 5/6] auto-t: add SAE test for no supported groups James Prestwood
@ 2021-09-09 22:08 ` James Prestwood
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2021-09-09 22:08 UTC (permalink / raw)
  To: iwd

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

---
 autotests/testSAE/autoconnect_test.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/autotests/testSAE/autoconnect_test.py b/autotests/testSAE/autoconnect_test.py
index 9095b7e9..64a60e7c 100644
--- a/autotests/testSAE/autoconnect_test.py
+++ b/autotests/testSAE/autoconnect_test.py
@@ -35,8 +35,8 @@ class Test(unittest.TestCase):
         wd.wait_for_object_condition(ordered_network.network_object, condition)
 
     def test_SAE(self):
-        self.hostapd.set_value('sae_pwe', '0');
-        self.hostapd.set_value('sae_groups', '19');
+        self.hostapd.set_value('sae_pwe', '0')
+        self.hostapd.set_value('sae_groups', '19')
         self.hostapd.reload()
         self.hostapd.wait_for_event("AP-ENABLED")
 
@@ -44,8 +44,8 @@ class Test(unittest.TestCase):
         self.validate_connection(wd)
 
     def test_SAE_H2E(self):
-        self.hostapd.set_value('sae_pwe', '1');
-        self.hostapd.set_value('sae_groups', '20');
+        self.hostapd.set_value('sae_pwe', '1')
+        self.hostapd.set_value('sae_groups', '20')
         self.hostapd.reload()
         self.hostapd.wait_for_event("AP-ENABLED")
         wd = IWD(True)
-- 
2.31.1

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

end of thread, other threads:[~2021-09-09 22:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-09 22:08 [PATCH v3 1/6] hwsim: add MatchBytes/MatchBytesOffset rule properties James Prestwood
2021-09-09 22:01 ` Denis Kenzior
2021-09-09 22:08 ` [PATCH v3 2/6] auto-t: hwsim.py: add match/match_offset properties James Prestwood
2021-09-09 22:08 ` [PATCH v3 3/6] auto-t: change testSAE timeout_test to use match/offset James Prestwood
2021-09-09 22:08 ` [PATCH v3 4/6] auto-t: add SAE test for a non-ACKed confirm James Prestwood
2021-09-09 22:08 ` [PATCH v3 5/6] auto-t: add SAE test for no supported groups James Prestwood
2021-09-09 22:08 ` [PATCH v3 6/6] auto-t: remove ';' in testSAE autoconnect_test.py James Prestwood

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).