Wireless Daemon for Linux
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.01.org
Subject: [PATCH 07/10] hwsim: add new 'Delay' property to Rules
Date: Tue, 02 Jun 2020 10:30:18 -0700	[thread overview]
Message-ID: <20200602173021.20085-8-prestwoj@gmail.com> (raw)
In-Reply-To: <20200602173021.20085-1-prestwoj@gmail.com>

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

This allows a matching frame to be delayed by some number of
milliseconds.
---
 tools/hwsim.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 48 insertions(+), 5 deletions(-)

diff --git a/tools/hwsim.c b/tools/hwsim.c
index d066f814..3ccc936e 100644
--- a/tools/hwsim.c
+++ b/tools/hwsim.c
@@ -113,6 +113,7 @@ enum hwsim_tx_control_flags {
 };
 
 #define IEEE80211_TX_RATE_TABLE_SIZE	4
+#define HWSIM_DELAY_MIN_MS		1
 
 struct hwsim_rule {
 	unsigned int id;
@@ -125,6 +126,7 @@ struct hwsim_rule {
 	uint32_t frequency;
 	int priority;
 	int signal;
+	int delay;
 };
 
 struct hwsim_support {
@@ -1106,7 +1108,8 @@ static bool radio_match_addr(const struct radio_info_rec *radio,
 
 static void process_rules(const struct radio_info_rec *src_radio,
 				const struct radio_info_rec *dst_radio,
-				struct hwsim_frame *frame, bool *drop)
+				struct hwsim_frame *frame, bool *drop,
+				uint32_t *delay)
 {
 	const struct l_queue_entry *rule_entry;
 
@@ -1149,6 +1152,9 @@ static void process_rules(const struct radio_info_rec *src_radio,
 			frame->signal = rule->signal / 100;
 
 		*drop = rule->drop;
+
+		if (delay)
+			*delay = rule->delay;
 	}
 }
 
@@ -1232,7 +1238,7 @@ static void hwsim_frame_unref(struct hwsim_frame *frame)
 			bool drop = false;
 
 			process_rules(frame->ack_radio, frame->src_radio,
-					frame, &drop);
+					frame, &drop, NULL);
 
 			if (!drop)
 				frame->flags |= HWSIM_TX_STAT_ACK;
@@ -1374,13 +1380,14 @@ static void process_frame(struct hwsim_frame *frame)
 	bool drop_mcast = false;
 
 	if (util_is_broadcast_address(frame->dst_ether_addr))
-		process_rules(frame->src_radio, NULL, frame, &drop_mcast);
+		process_rules(frame->src_radio, NULL, frame, &drop_mcast, NULL);
 
 	for (entry = l_queue_get_entries(radio_info); entry;
 			entry = entry->next) {
 		struct radio_info_rec *radio = entry->data;
 		struct send_frame_info *send_info;
 		bool drop = drop_mcast;
+		uint32_t delay = HWSIM_DELAY_MIN_MS;
 
 		if (radio == frame->src_radio)
 			continue;
@@ -1413,7 +1420,7 @@ static void process_frame(struct hwsim_frame *frame)
 				continue;
 		}
 
-		process_rules(frame->src_radio, radio, frame, &drop);
+		process_rules(frame->src_radio, radio, frame, &drop, &delay);
 
 		if (drop)
 			continue;
@@ -1422,7 +1429,7 @@ static void process_frame(struct hwsim_frame *frame)
 		send_info->radio = radio;
 		send_info->frame = hwsim_frame_ref(frame);
 
-		if (!l_timeout_create_ms(1, frame_delay_callback,
+		if (!l_timeout_create_ms(delay, frame_delay_callback,
 						send_info, NULL)) {
 			l_error("Error delaying frame, frame will be dropped");
 			send_frame_destroy(send_info);
@@ -1875,6 +1882,7 @@ static struct l_dbus_message *rule_add(struct l_dbus *dbus,
 	rule->id = next_rule_id++;
 	rule->source_any = true;
 	rule->destination_any = true;
+	rule->delay = HWSIM_DELAY_MIN_MS;
 
 	if (!rules)
 		rules = l_queue_new();
@@ -2160,6 +2168,37 @@ static struct l_dbus_message *rule_property_set_drop(
 	return l_dbus_message_new_method_return(message);
 }
 
+static bool rule_property_get_delay(struct l_dbus *dbus,
+					struct l_dbus_message *message,
+					struct l_dbus_message_builder *builder,
+					void *user_data)
+{
+	struct hwsim_rule *rule = user_data;
+
+	l_dbus_message_builder_append_basic(builder, 'u', &rule->delay);
+
+	return true;
+}
+
+static struct l_dbus_message *rule_property_set_delay(
+					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;
+	uint32_t val;
+
+	if (!l_dbus_message_iter_get_variant(new_value, "u", &val) ||
+				val < HWSIM_DELAY_MIN_MS)
+		return dbus_error_invalid_args(message);
+
+	rule->delay = 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, "", "");
@@ -2192,6 +2231,10 @@ static void setup_rule_interface(struct l_dbus_interface *interface)
 					L_DBUS_PROPERTY_FLAG_AUTO_EMIT, "b",
 					rule_property_get_drop,
 					rule_property_set_drop);
+	l_dbus_interface_property(interface, "Delay",
+					L_DBUS_PROPERTY_FLAG_AUTO_EMIT, "u",
+					rule_property_get_delay,
+					rule_property_set_delay);
 }
 
 static void request_name_callback(struct l_dbus *dbus, bool success,
-- 
2.21.1

  parent reply	other threads:[~2020-06-02 17:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-02 17:30 [PATCH 00/10] ANQP Refactor to use frame-xchg James Prestwood
2020-06-02 17:30 ` [PATCH 01/10] frame-xchg: fix bug when starting new xchg from callback James Prestwood
2020-06-02 17:30 ` [PATCH 02/10] frame-xchg: Fix frame_watch_remove_by_handler for group 0 James Prestwood
2020-06-02 17:30 ` [PATCH 03/10] frame-xchg: Use frame_watch_group_match in frame_watch_group_get James Prestwood
2020-06-02 17:30 ` [PATCH 04/10] anqp: refactor to use frame-xchg James Prestwood
2020-06-02 17:30 ` [PATCH 05/10] station: add ANQP state watch API James Prestwood
2020-06-02 17:30 ` [PATCH 06/10] network: delay connect if ANQP has not completed James Prestwood
2020-06-02 17:30 ` James Prestwood [this message]
2020-06-08 20:15   ` [PATCH 07/10] hwsim: add new 'Delay' property to Rules Denis Kenzior
2020-06-02 17:30 ` [PATCH 08/10] doc: document new 'Delay' property for hwsim Rules James Prestwood
2020-06-02 17:30 ` [PATCH 09/10] auto-t: add 'Delay' property to hwsim python module James Prestwood
2020-06-02 17:30 ` [PATCH 10/10] auto-t: add test for delayed ANQP response 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=20200602173021.20085-8-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