All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.01.org
Subject: [PATCH 1/6] station: implement Scan on debug interface
Date: Thu, 12 Aug 2021 16:12:28 -0700	[thread overview]
Message-ID: <20210812231233.747743-1-prestwoj@gmail.com> (raw)

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

This is to support the autotesting framework by allowing a smaller
scan subset. This will cut down on the amount of time spent scanning
via normal DBus scans (where the entire spectrum is scanned).
---
 src/station.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 107 insertions(+)

diff --git a/src/station.c b/src/station.c
index 2155aa3c..5d447356 100644
--- a/src/station.c
+++ b/src/station.c
@@ -3839,6 +3839,109 @@ invalid_args:
 	return dbus_error_invalid_args(message);
 }
 
+static void station_debug_scan_triggered(int err, void *user_data)
+{
+	struct station *station = user_data;
+	struct l_dbus_message *reply;
+
+	if (err < 0) {
+		if (station->scan_pending) {
+			reply = dbus_error_from_errno(err,
+							station->scan_pending);
+			dbus_pending_reply(&station->scan_pending, reply);
+		}
+
+		station_dbus_scan_done(station);
+		return;
+	}
+
+	l_debug("debug scan triggered for %s",
+			netdev_get_name(station->netdev));
+
+	if (station->scan_pending) {
+		reply = l_dbus_message_new_method_return(station->scan_pending);
+		l_dbus_message_set_arguments(reply, "");
+		dbus_pending_reply(&station->scan_pending, reply);
+	}
+
+	station_property_set_scanning(station, true);
+}
+
+static bool station_debug_scan_results(int err, struct l_queue *bss_list,
+					const struct scan_freq_set *freqs,
+					void *userdata)
+{
+	struct station *station = userdata;
+	bool autoconnect;
+
+	if (err) {
+		station_dbus_scan_done(station);
+		return false;
+	}
+
+	autoconnect = station_is_autoconnecting(station);
+	station_set_scan_results(station, bss_list, freqs, autoconnect);
+
+	station_dbus_scan_done(station);
+
+	return true;
+}
+
+static struct l_dbus_message *station_debug_scan(struct l_dbus *dbus,
+						struct l_dbus_message *message,
+						void *user_data)
+{
+	struct station *station = user_data;
+	struct l_dbus_message_iter iter;
+	uint16_t *freqs;
+	uint32_t freqs_len;
+	struct scan_freq_set *freq_set;
+	unsigned int i;
+
+	if (station->dbus_scan_id)
+		return dbus_error_busy(message);
+
+	if (station->state == STATION_STATE_CONNECTING ||
+			station->state == STATION_STATE_CONNECTING_AUTO)
+		return dbus_error_busy(message);
+
+	if (!l_dbus_message_get_arguments(message, "aq", &iter))
+		goto invalid_args;
+
+	if (!l_dbus_message_iter_get_fixed_array(&iter, &freqs, &freqs_len))
+		goto invalid_args;
+
+	freq_set = scan_freq_set_new();
+
+	for (i = 0; i < freqs_len; i++) {
+		if (!scan_freq_set_add(freq_set, (uint32_t)freqs[i])) {
+			scan_freq_set_free(freq_set);
+			goto invalid_args;
+		}
+
+		l_debug("added frequency %u", freqs[i]);
+	}
+
+	station->dbus_scan_id = station_scan_trigger(station, freq_set,
+						station_debug_scan_triggered,
+						station_debug_scan_results,
+						NULL);
+
+	scan_freq_set_free(freq_set);
+
+	if (!station->dbus_scan_id)
+		goto failed;
+
+	station->scan_pending = l_dbus_message_ref(message);
+
+	return NULL;
+
+failed:
+	return dbus_error_failed(message);
+invalid_args:
+	return dbus_error_invalid_args(message);
+}
+
 static bool station_property_get_autoconnect(struct l_dbus *dbus,
 					struct l_dbus_message *message,
 					struct l_dbus_message_builder *builder,
@@ -3883,6 +3986,10 @@ static void station_setup_debug_interface(
 	l_dbus_interface_method(interface, "Roam", 0,
 					station_force_roam, "", "ay", "mac");
 
+	l_dbus_interface_method(interface, "Scan", 0,
+					station_debug_scan, "", "aq",
+					"frequencies");
+
 	l_dbus_interface_property(interface, "AutoConnect", 0, "b",
 					station_property_get_autoconnect,
 					station_property_set_autoconnect);
-- 
2.31.1

             reply	other threads:[~2021-08-12 23:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-12 23:12 James Prestwood [this message]
2021-08-12 23:12 ` [PATCH 2/6] auto-t: add python API for StationDebug.Scan James Prestwood
2021-08-12 23:12 ` [PATCH 3/6] test-runner: start HostapdCLI from test-runner James Prestwood
2021-08-12 23:12 ` [PATCH 4/6] auto-t: iwd.py: scan only on needed frequencies James Prestwood
2021-08-12 23:12 ` [PATCH 5/6] auto-t: use .frequency property in SAQuery-spoofing test James Prestwood
2021-08-12 23:12 ` [PATCH 6/6] auto-t: hostapd.py: remove get_freq()/get_config_value() James Prestwood
2021-08-13 15:46 ` [PATCH 1/6] station: implement Scan on debug interface Denis Kenzior

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=20210812231233.747743-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.