iwd.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/9] hwsim: add MatchTimes property
@ 2021-09-07 21:14 James Prestwood
  2021-09-07 21:14 ` [PATCH 2/9] auto-t: hwsim.py: add match_times property James Prestwood
                   ` (8 more replies)
  0 siblings, 9 replies; 15+ messages in thread
From: James Prestwood @ 2021-09-07 21:14 UTC (permalink / raw)
  To: iwd

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

This integer property can be set to only match a rule a number of
times rather than all packets. This is useful for testing behavior
of a single dropped frame or ack. Once the rule has been matched
'MatchTimes' the rules will no longer be applied (unless set again
to some integer greater than zero).
---
 tools/hwsim.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/tools/hwsim.c b/tools/hwsim.c
index cd4a99b7..18ba111a 100644
--- a/tools/hwsim.c
+++ b/tools/hwsim.c
@@ -131,6 +131,7 @@ struct hwsim_rule {
 	int delay;
 	uint8_t *prefix;
 	size_t prefix_len;
+	int match_times; /* negative value indicates unused */
 };
 
 struct hwsim_support {
@@ -1217,6 +1218,8 @@ static void process_rules(const struct radio_info_rec *src_radio,
 		}
 
 		/* Rule deemed to match frame, apply any changes */
+		if (rule->match_times == 0)
+			continue;
 
 		if (rule->signal)
 			frame->signal = rule->signal / 100;
@@ -1225,6 +1228,9 @@ static void process_rules(const struct radio_info_rec *src_radio,
 
 		if (delay)
 			*delay = rule->delay;
+
+		if (rule->match_times > 0)
+			rule->match_times--;
 	}
 }
 
@@ -2008,6 +2014,7 @@ static struct l_dbus_message *rule_add(struct l_dbus *dbus,
 	rule->destination_any = true;
 	rule->delay = 0;
 	rule->enabled = false;
+	rule->match_times = -1;
 
 	if (!rules)
 		rules = l_queue_new();
@@ -2412,6 +2419,37 @@ static struct l_dbus_message *rule_property_set_enabled(
 	return l_dbus_message_new_method_return(message);
 }
 
+static bool rule_property_get_match_times(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_times;
+
+	l_dbus_message_builder_append_basic(builder, 'q', &val);
+
+	return true;
+}
+
+static struct l_dbus_message *rule_property_set_match_times(
+					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_times = val;
+
+	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, "", "");
@@ -2456,6 +2494,10 @@ static void setup_rule_interface(struct l_dbus_interface *interface)
 					L_DBUS_PROPERTY_FLAG_AUTO_EMIT, "b",
 					rule_property_get_enabled,
 					rule_property_set_enabled);
+	l_dbus_interface_property(interface, "MatchTimes",
+					L_DBUS_PROPERTY_FLAG_AUTO_EMIT, "q",
+					rule_property_get_match_times,
+					rule_property_set_match_times);
 }
 
 static void request_name_callback(struct l_dbus *dbus, bool success,
-- 
2.31.1

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

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

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-07 21:14 [PATCH 1/9] hwsim: add MatchTimes property James Prestwood
2021-09-07 21:14 ` [PATCH 2/9] auto-t: hwsim.py: add match_times property James Prestwood
2021-09-07 21:14 ` [PATCH 3/9] hwsim: add DropAck rule property James Prestwood
2021-09-07 21:14 ` [PATCH 4/9] auto-t: hwsim.py: add drop_ack property James Prestwood
2021-09-07 21:14 ` [PATCH 5/9] netdev: print error if CMD_ASSOCIATE fails James Prestwood
2021-09-07 21:14 ` [PATCH 6/9] sae: print state and transaction on received packets James Prestwood
2021-09-07 21:14 ` [PATCH 7/9] sae: fix a few spec violations regarding dropped frames James Prestwood
2021-09-08  1:05   ` Denis Kenzior
2021-09-07 21:14 ` [PATCH 8/9] sae: don't send commit in confirmed state James Prestwood
2021-09-07 23:02   ` Paul Menzel
2021-09-07 23:34     ` James Prestwood
2021-09-08 13:24       ` Paul Menzel
2021-09-08 16:40         ` James Prestwood
2021-09-07 21:14 ` [PATCH 9/9] auto-t: add sae test for non-acked commit James Prestwood
2021-09-08  1:03 ` [PATCH 1/9] hwsim: add MatchTimes property 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).