hwsim: add PrefixOffset rule property
PATCH 1/5 hwsim: add PrefixOffset rule property
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(-)
tools/hwsim.c +43 -2
@@ -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,
Signature · 1 line
2.31.1
PATCH 2/5 auto-t: hwsim.py: add prefix_offset property
--- autotests/util/hwsim.py | 8 ++++++++ 1 file changed, 8 insertions(+)
autotests/util/hwsim.py +8 -0
@@ -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)
Signature · 1 line
2.31.1
PATCH 3/5 auto-t: change testSAE timeout_test to use prefix_offset
In reply to James PrestwoodThis 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(-)
autotests/testSAE/timeout_test.py +4 -1
@@ -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
Signature · 1 line
2.31.1
PATCH 4/5 auto-t: add SAE test for a non-ACKed confirm
In reply to James Prestwood--- autotests/testSAE/timeout_test.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
autotests/testSAE/timeout_test.py +21 -0
@@ -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
Signature · 1 line
2.31.1
PATCH 5/5 auto-t: add SAE test for no supported groups
In reply to James Prestwood--- autotests/testSAE/failure_test.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
autotests/testSAE/failure_test.py +12 -3
@@ -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):
Signature · 1 line
2.31.1
Re: [PATCH 3/5] auto-t: change testSAE timeout_test to use prefix_offset
In reply to James PrestwoodHi James,
Quoted 12 lines · James Prestwood
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(-)autotests/testSAE/timeout_test.py +0
-0
autotests/testSAE/timeout_test.py class Test(unittest.TestCase): · line 53
Quoted 6 lines
autotests/testSAE/timeout_test.py +2
-1@@ -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
autotests/testSAE/timeout_test.py class Test(unittest.TestCase): · line 56
Quoted 3 lines
autotests/testSAE/timeout_test.py +0
-0rule0.match_times = 1 rule0.drop_ack = True rule0.enabled = True
Regards,
-Denis