iwd.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] hwsim: add PrefixOffset rule property
@ 2021-09-08 22:47 James Prestwood
  2021-09-08 22:47 ` [PATCH 2/5] auto-t: hwsim.py: add prefix_offset property James Prestwood
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: James Prestwood @ 2021-09-08 22:47 UTC (permalink / raw)
  To: iwd

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

If set, a rule will start matching a prefix some number of bytes
into the frame. This is useful since header information, addresses,
and sequence numbers may be unpredictable between test runs.
---
 tools/hwsim.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 2 deletions(-)

diff --git a/tools/hwsim.c b/tools/hwsim.c
index 8fb9b0a4..9a7a90a9 100644
--- a/tools/hwsim.c
+++ b/tools/hwsim.c
@@ -132,6 +132,7 @@ struct hwsim_rule {
 	int delay;
 	uint8_t *prefix;
 	size_t prefix_len;
+	uint16_t prefix_offset;
 	int match_times; /* negative value indicates unused */
 };
 
@@ -1212,8 +1213,13 @@ static void process_rules(const struct radio_info_rec *src_radio,
 		if (rule->frequency && rule->frequency != frame->frequency)
 			continue;
 
-		if (rule->prefix && frame->payload_len >= rule->prefix_len) {
-			if (memcmp(rule->prefix, frame->payload,
+		if (rule->prefix) {
+			if (frame->payload_len <
+					rule->prefix_len + rule->prefix_offset)
+				continue;
+
+			if (memcmp(rule->prefix,
+					frame->payload + rule->prefix_offset,
 					rule->prefix_len) != 0)
 				continue;
 		}
@@ -2394,6 +2400,37 @@ invalid_args:
 	return dbus_error_invalid_args(message);
 }
 
+static bool rule_property_get_prefix_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->prefix_offset;
+
+	l_dbus_message_builder_append_basic(builder, 'q', &val);
+
+	return true;
+}
+
+static struct l_dbus_message *rule_property_set_prefix_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->prefix_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 +2564,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, "PrefixOffset",
+					L_DBUS_PROPERTY_FLAG_AUTO_EMIT, "q",
+					rule_property_get_prefix_offset,
+					rule_property_set_prefix_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] 6+ messages in thread

* [PATCH 2/5] auto-t: hwsim.py: add prefix_offset property
  2021-09-08 22:47 [PATCH 1/5] hwsim: add PrefixOffset rule property James Prestwood
@ 2021-09-08 22:47 ` James Prestwood
  2021-09-08 22:47 ` [PATCH 3/5] auto-t: change testSAE timeout_test to use prefix_offset James Prestwood
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: James Prestwood @ 2021-09-08 22:47 UTC (permalink / raw)
  To: iwd

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

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

diff --git a/autotests/util/hwsim.py b/autotests/util/hwsim.py
index e5d336e3..732a1fcf 100755
--- a/autotests/util/hwsim.py
+++ b/autotests/util/hwsim.py
@@ -169,6 +169,14 @@ class Rule(HwsimDBusAbstract):
     def drop_ack(self, value):
         self._prop_proxy.Set(self._iface_name, 'DropAck', value)
 
+    @property
+    def prefix_offset(self):
+        return self._properties(['PrefixOffset'])
+
+    @prefix_offset.setter
+    def prefix_offset(self, value):
+        self._prop_proxy.Set(self._iface_name, 'PrefixOffset', 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] 6+ messages in thread

* [PATCH 3/5] auto-t: change testSAE timeout_test to use prefix_offset
  2021-09-08 22:47 [PATCH 1/5] hwsim: add PrefixOffset rule property James Prestwood
  2021-09-08 22:47 ` [PATCH 2/5] auto-t: hwsim.py: add prefix_offset property James Prestwood
@ 2021-09-08 22:47 ` James Prestwood
  2021-09-09 19:47   ` Denis Kenzior
  2021-09-08 22:47 ` [PATCH 4/5] auto-t: add SAE test for a non-ACKed confirm James Prestwood
  2021-09-08 22:47 ` [PATCH 5/5] auto-t: add SAE test for no supported groups James Prestwood
  3 siblings, 1 reply; 6+ messages in thread
From: James Prestwood @ 2021-09-08 22:47 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 1029 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 | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/autotests/testSAE/timeout_test.py b/autotests/testSAE/timeout_test.py
index 1792f1c0..263f4e28 100644
--- a/autotests/testSAE/timeout_test.py
+++ b/autotests/testSAE/timeout_test.py
@@ -49,7 +49,8 @@ class Test(unittest.TestCase):
         rule0 = hwsim.rules.create()
         rule0.source = bss_radio.addresses[0]
         rule0.drop = True
-        rule0.prefix = 'b0'
+        rule0.prefix = '01 00 00 00 13 00'
+        rule0.prefix_offset = 26
         rule0.match_times = 1
         rule0.drop_ack = True
         rule0.enabled = True
@@ -57,6 +58,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] 6+ messages in thread

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

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

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

diff --git a/autotests/testSAE/timeout_test.py b/autotests/testSAE/timeout_test.py
index 263f4e28..8de21176 100644
--- a/autotests/testSAE/timeout_test.py
+++ b/autotests/testSAE/timeout_test.py
@@ -60,6 +60,27 @@ class Test(unittest.TestCase):
 
         rule0.remove()
 
+    def test_sta_confirm_not_acked(self):
+        hostapd = HostapdCLI(config='ssidSAE.conf')
+        hostapd.set_value('vendor_elements', 'dd0cf4f5e8050500000000000000')
+
+        hwsim = Hwsim()
+        bss_radio = hwsim.get_radio('rad0')
+
+        rule0 = hwsim.rules.create()
+        rule0.source = bss_radio.addresses[0]
+        rule0.drop = True
+        rule0.prefix = '02 00 00 00'
+        rule0.prefix_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] 6+ messages in thread

* [PATCH 5/5] auto-t: add SAE test for no supported groups
  2021-09-08 22:47 [PATCH 1/5] hwsim: add PrefixOffset rule property James Prestwood
                   ` (2 preceding siblings ...)
  2021-09-08 22:47 ` [PATCH 4/5] auto-t: add SAE test for a non-ACKed confirm James Prestwood
@ 2021-09-08 22:47 ` James Prestwood
  3 siblings, 0 replies; 6+ messages in thread
From: James Prestwood @ 2021-09-08 22:47 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] 6+ messages in thread

* Re: [PATCH 3/5] auto-t: change testSAE timeout_test to use prefix_offset
  2021-09-08 22:47 ` [PATCH 3/5] auto-t: change testSAE timeout_test to use prefix_offset James Prestwood
@ 2021-09-09 19:47   ` Denis Kenzior
  0 siblings, 0 replies; 6+ messages in thread
From: Denis Kenzior @ 2021-09-09 19:47 UTC (permalink / raw)
  To: iwd

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

Hi James,

On 9/8/21 5:47 PM, James Prestwood wrote:
> 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 | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/autotests/testSAE/timeout_test.py b/autotests/testSAE/timeout_test.py
> index 1792f1c0..263f4e28 100644
> --- a/autotests/testSAE/timeout_test.py
> +++ b/autotests/testSAE/timeout_test.py
> @@ -49,7 +49,8 @@ class Test(unittest.TestCase):
>           rule0 = hwsim.rules.create()
>           rule0.source = bss_radio.addresses[0]
>           rule0.drop = True
> -        rule0.prefix = 'b0'
> +        rule0.prefix = '01 00 00 00 13 00'
> +        rule0.prefix_offset = 26

So I wonder if we might end up matching arbitrary frames this way?  Perhaps we 
should keep the subtype prefix and add the prefix/prefix_offset as an additional 
match?

Something like
rule0.prefix = 'b0'
rule0.match0 = '01 00 00 00 13 00'
rule0.match0_offset = 26

>           rule0.match_times = 1
>           rule0.drop_ack = True
>           rule0.enabled = True

Regards,
-Denis

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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-08 22:47 [PATCH 1/5] hwsim: add PrefixOffset rule property James Prestwood
2021-09-08 22:47 ` [PATCH 2/5] auto-t: hwsim.py: add prefix_offset property James Prestwood
2021-09-08 22:47 ` [PATCH 3/5] auto-t: change testSAE timeout_test to use prefix_offset James Prestwood
2021-09-09 19:47   ` Denis Kenzior
2021-09-08 22:47 ` [PATCH 4/5] auto-t: add SAE test for a non-ACKed confirm James Prestwood
2021-09-08 22:47 ` [PATCH 5/5] auto-t: add SAE test for no supported groups 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).