All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] station: implement Scan on debug interface
@ 2021-08-12 23:12 James Prestwood
  2021-08-12 23:12 ` [PATCH 2/6] auto-t: add python API for StationDebug.Scan James Prestwood
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: James Prestwood @ 2021-08-12 23:12 UTC (permalink / raw)
  To: iwd

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

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

* [PATCH 2/6] auto-t: add python API for StationDebug.Scan
  2021-08-12 23:12 [PATCH 1/6] station: implement Scan on debug interface James Prestwood
@ 2021-08-12 23:12 ` James Prestwood
  2021-08-12 23:12 ` [PATCH 3/6] test-runner: start HostapdCLI from test-runner James Prestwood
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2021-08-12 23:12 UTC (permalink / raw)
  To: iwd

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

---
 autotests/util/iwd.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/autotests/util/iwd.py b/autotests/util/iwd.py
index f5c224b8..7bb4c9f0 100755
--- a/autotests/util/iwd.py
+++ b/autotests/util/iwd.py
@@ -242,6 +242,10 @@ class StationDebug(IWDDBusAbstract):
     def autoconnect(self):
         return self._properties['AutoConnect']
 
+    def scan(self, frequencies):
+        frequencies = dbus.Array([dbus.UInt16(f) for f in frequencies])
+        self._iface.Scan(frequencies)
+
 class Device(IWDDBusAbstract):
     '''
         Class represents a network device object: net.connman.iwd.Device
@@ -585,6 +589,12 @@ class Device(IWDDBusAbstract):
                                                 IWD_STATION_DEBUG_INTERFACE)
         self._station_debug_if.Roam(dbus.ByteArray.fromhex(address.replace(':', '')))
 
+    def debug_scan(self, frequencies):
+        if not self._station_debug:
+            self._station_debug = StationDebug(self._object_path)
+
+        self._station_debug.scan(frequencies)
+
     def __str__(self, prefix = ''):
         return prefix + 'Device: ' + self.device_path + '\n'\
                + prefix + '\tName:\t\t' + self.name + '\n'\
-- 
2.31.1

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

* [PATCH 3/6] test-runner: start HostapdCLI from test-runner
  2021-08-12 23:12 [PATCH 1/6] station: implement Scan on debug interface James Prestwood
  2021-08-12 23:12 ` [PATCH 2/6] auto-t: add python API for StationDebug.Scan James Prestwood
@ 2021-08-12 23:12 ` James Prestwood
  2021-08-12 23:12 ` [PATCH 4/6] auto-t: iwd.py: scan only on needed frequencies James Prestwood
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2021-08-12 23:12 UTC (permalink / raw)
  To: iwd

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

This gives the benefit of test-runner itself having access to
the CLI, e.g. for getting status information.
---
 autotests/util/hostapd.py | 32 +++++++++++++++++++++++++++++---
 tools/test-runner         | 14 ++++++++++++++
 2 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/autotests/util/hostapd.py b/autotests/util/hostapd.py
index f75dbe6b..1575d832 100644
--- a/autotests/util/hostapd.py
+++ b/autotests/util/hostapd.py
@@ -42,6 +42,24 @@ class HostapdCLI:
 
         hapd = ctx.hostapd[config]
 
+        if not hasattr(self, '_hostapd_restarted'):
+            self._hostapd_restarted = False
+
+        #
+        # TODO: In theory some type of instance singleton could be created for
+        #       HostapdCLI where test-runner initializes but any subsequent
+        #       call to HostapdCLI (with the same config) returns the same
+        #       object that test-runner has. This would avoid setting these
+        #       variables.
+        #
+        if hapd.cli:
+            self.ifname = hapd.cli.ifname
+            self.ctrl_sock = hapd.cli.ctrl_sock
+            self.cmdline = hapd.cli.cmdline
+            self.interface = hapd.intf
+            self.config = hapd.config
+            return
+
         self.interface = hapd.intf
         self.config = hapd.config
 
@@ -53,9 +71,6 @@ class HostapdCLI:
 
         self.cmdline = ['hostapd_cli', '-p', self.socket_path, '-i', self.ifname]
 
-        if not hasattr(self, '_hostapd_restarted'):
-            self._hostapd_restarted = False
-
         self.local_ctrl = '/tmp/hostapd_' + str(os.getpid()) + '_' + \
                             str(ctrl_count)
         self.ctrl_sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
@@ -244,3 +259,14 @@ class HostapdCLI:
         bssid = [x for x in status if x.startswith('bssid')]
         bssid = bssid[0].split('=')
         return bssid[1]
+
+    @property
+    def frequency(self):
+        cmd = self.cmdline + ['status']
+        status = ctx.start_process(cmd, wait=True, need_out=True).out
+        status = status.split('\n')
+
+        frequency = [x for x in status if x.startswith('freq')][0]
+        frequency = frequency.split('=')[1]
+
+        return int(frequency)
diff --git a/tools/test-runner b/tools/test-runner
index bfa5d803..87f6ec6d 100755
--- a/tools/test-runner
+++ b/tools/test-runner
@@ -428,6 +428,7 @@ class HostapdInstance:
 	def __init__(self, config, radio):
 		self.radio = radio
 		self.config = config
+		self.cli = None
 
 		self.intf = radio.create_interface(self.config, 'hostapd')
 		self.intf.set_interface_state('up')
@@ -494,6 +495,10 @@ class Hostapd:
 
 		self.process.wait_for_socket(self.global_ctrl_iface, 30)
 
+	def attach_cli(self):
+		for hapd in self.instances:
+			hapd.cli = importlib.import_module('hostapd').HostapdCLI(config=hapd.config)
+
 	def _rewrite_config(self, config):
 		'''
 			Replaces any $ifaceN values with the correct interface
@@ -841,6 +846,15 @@ class TestContext(Namespace):
 		radius_config = settings.get('radius_server', None)
 
 		self.hostapd = Hostapd(self, hapd_radios, hapd_configs, radius_config)
+		self.hostapd.attach_cli()
+
+	def get_frequencies(self):
+		frequencies = []
+
+		for hapd in self.hostapd.instances:
+			frequencies.append(hapd.cli.frequency)
+
+		return frequencies
 
 	def start_wpas_interfaces(self):
 		if 'WPA_SUPPLICANT' not in self.hw_config:
-- 
2.31.1

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

* [PATCH 4/6] auto-t: iwd.py: scan only on needed frequencies
  2021-08-12 23:12 [PATCH 1/6] station: implement Scan on debug interface James Prestwood
  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 ` James Prestwood
  2021-08-12 23:12 ` [PATCH 5/6] auto-t: use .frequency property in SAQuery-spoofing test James Prestwood
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2021-08-12 23:12 UTC (permalink / raw)
  To: iwd

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

get_ordered_network() now scans automatically and has been updated
to use the StationDebug.Scan() API rather than doing a full
dbus scan (unless full_scan = True). The frequencies to be scanned
are picked automatically based on the current hostapd status
(hidden behind ctx.hostapd.get_frequency()).
---
 autotests/util/iwd.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/autotests/util/iwd.py b/autotests/util/iwd.py
index 7bb4c9f0..cee1b99d 100755
--- a/autotests/util/iwd.py
+++ b/autotests/util/iwd.py
@@ -414,7 +414,7 @@ class Device(IWDDBusAbstract):
 
         self._wait_for_async_op()
 
-    def get_ordered_networks(self, scan_if_needed = True):
+    def get_ordered_networks(self, scan_if_needed = True, full_scan = False):
         '''Return the list of networks found in the most recent
            scan, sorted by their user interface importance
            score as calculated by iwd.  If the device is
@@ -440,7 +440,10 @@ class Device(IWDDBusAbstract):
         IWD._wait_for_object_condition(self, condition)
 
         try:
-            self.scan()
+            if full_scan:
+                self.scan()
+            else:
+                self.debug_scan(ctx.get_frequencies())
         except InProgressEx:
             pass
 
@@ -458,7 +461,7 @@ class Device(IWDDBusAbstract):
 
         return None
 
-    def get_ordered_network(self, network, scan_if_needed = True):
+    def get_ordered_network(self, network, scan_if_needed = True, full_scan = False):
         '''Returns a single network from ordered network call, or None if the
            network wasn't found. If the network is not found an exception is
            raised, this removes the need to extra asserts in autotests.
-- 
2.31.1

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

* [PATCH 5/6] auto-t: use .frequency property in SAQuery-spoofing test
  2021-08-12 23:12 [PATCH 1/6] station: implement Scan on debug interface James Prestwood
                   ` (2 preceding siblings ...)
  2021-08-12 23:12 ` [PATCH 4/6] auto-t: iwd.py: scan only on needed frequencies James Prestwood
@ 2021-08-12 23:12 ` 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
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2021-08-12 23:12 UTC (permalink / raw)
  To: iwd

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

---
 autotests/testSAQuery-spoofing/connection_test.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/autotests/testSAQuery-spoofing/connection_test.py b/autotests/testSAQuery-spoofing/connection_test.py
index c4c4e923..f64a93f7 100644
--- a/autotests/testSAQuery-spoofing/connection_test.py
+++ b/autotests/testSAQuery-spoofing/connection_test.py
@@ -49,7 +49,7 @@ class Test(unittest.TestCase):
             wd.wait_for_object_condition(device, condition)
 
         # Spoof a disassociate frame. This will kick off SA Query procedure.
-        hwsim.spoof_disassociate(radio, hostapd.get_freq(), device.address)
+        hwsim.spoof_disassociate(radio, hostapd.frequency, device.address)
 
         # sleep to ensure hostapd responds and SA Query does not timeout
         sleep(4)
-- 
2.31.1

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

* [PATCH 6/6] auto-t: hostapd.py: remove get_freq()/get_config_value()
  2021-08-12 23:12 [PATCH 1/6] station: implement Scan on debug interface James Prestwood
                   ` (3 preceding siblings ...)
  2021-08-12 23:12 ` [PATCH 5/6] auto-t: use .frequency property in SAQuery-spoofing test James Prestwood
@ 2021-08-12 23:12 ` James Prestwood
  2021-08-13 15:46 ` [PATCH 1/6] station: implement Scan on debug interface Denis Kenzior
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2021-08-12 23:12 UTC (permalink / raw)
  To: iwd

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

---
 autotests/util/hostapd.py | 14 --------------
 1 file changed, 14 deletions(-)

diff --git a/autotests/util/hostapd.py b/autotests/util/hostapd.py
index 1575d832..be6e1143 100644
--- a/autotests/util/hostapd.py
+++ b/autotests/util/hostapd.py
@@ -212,20 +212,6 @@ class HostapdCLI:
         if 'OK' not in proc.out:
             raise Exception('BSS_TM_REQ failed, is hostapd built with CONFIG_WNM_AP=y?')
 
-    def get_config_value(self, key):
-        # first find the right config file
-        with open(self.config, 'r') as f:
-            # read in config file and search for key
-            cfg = f.read()
-            match = re.search(r'%s=.*' % key, cfg)
-            if match:
-                return match.group(0).split('=')[1]
-        return None
-
-
-    def get_freq(self):
-        return chan_freq_map[int(self.get_config_value('channel'))]
-
     def ungraceful_restart(self):
         '''
             Ungracefully kill and restart hostapd
-- 
2.31.1

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

* Re: [PATCH 1/6] station: implement Scan on debug interface
  2021-08-12 23:12 [PATCH 1/6] station: implement Scan on debug interface James Prestwood
                   ` (4 preceding siblings ...)
  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 ` Denis Kenzior
  5 siblings, 0 replies; 7+ messages in thread
From: Denis Kenzior @ 2021-08-13 15:46 UTC (permalink / raw)
  To: iwd

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

Hi James,

On 8/12/21 6:12 PM, James Prestwood wrote:
> 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(+)
> 

All applied, thanks.

Regards,
-Denis

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

end of thread, other threads:[~2021-08-13 15:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-12 23:12 [PATCH 1/6] station: implement Scan on debug interface James Prestwood
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

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.