iwd.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.01.org
Subject: [PATCH 1/5] hwsim: add PrefixOffset rule property
Date: Wed, 08 Sep 2021 15:47:40 -0700	[thread overview]
Message-ID: <20210908224744.102156-1-prestwoj@gmail.com> (raw)

[-- 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

             reply	other threads:[~2021-09-08 22:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-08 22:47 James Prestwood [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210908224744.102156-1-prestwoj@gmail.com \
    --to=prestwoj@gmail.com \
    --cc=iwd@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).