station: implement Scan on debug interface
PATCH 1/6 station: implement Scan on debug interface
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(+)
src/station.c +107 -0
@@ -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);
Signature · 1 line
2.31.1
PATCH 2/6 auto-t: add python API for StationDebug.Scan
--- autotests/util/iwd.py | 10 ++++++++++ 1 file changed, 10 insertions(+)
autotests/util/iwd.py +10 -0
@@ -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'\
Signature · 1 line
2.31.1
PATCH 3/6 test-runner: start HostapdCLI from test-runner
In reply to James PrestwoodThis 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(-)
autotests/util/hostapd.py +29 -3
@@ -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)
tools/test-runner +14 -0
@@ -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:
Signature · 1 line
2.31.1
PATCH 4/6 auto-t: iwd.py: scan only on needed frequencies
In reply to James Prestwoodget_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(-)
autotests/util/iwd.py +6 -3
@@ -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.
Signature · 1 line
2.31.1
PATCH 5/6 auto-t: use .frequency property in SAQuery-spoofing test
In reply to James Prestwood--- autotests/testSAQuery-spoofing/connection_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
autotests/testSAQuery-spoofing/connection_test.py +1 -1
@@ -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)
Signature · 1 line
2.31.1
PATCH 6/6 auto-t: hostapd.py: remove get_freq()/get_config_value()
In reply to James Prestwood--- autotests/util/hostapd.py | 14 -------------- 1 file changed, 14 deletions(-)
autotests/util/hostapd.py +0 -14
@@ -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
Signature · 1 line
2.31.1
Hi James,
Quoted 7 lines · James Prestwood
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