auto-t: wpas.py: don't require strict match on wait_for_event
James Prestwood
PATCH 1/6 auto-t: wpas.py: don't require strict match on wait_for_event
wait_for_event was checking the event string presence in the rx_data array which meant the event string had to match perfectly to any received events. This poses problems with events that include additional information which the caller may not be able to know or does not care about. For example:
DPP-RX src=02:00:00:00:02:00 freq=2437 type=11
Waiting for this event previously would require the caller know src, freq, and type. If the caller only wants to wait for DPP-RX, it can now do that.
--- autotests/util/wpas.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
autotests/util/wpas.py +4 -3
@@ -70,9 +70,10 @@ class Wpas: while True: context.iteration(may_block=True) - if event in self._rx_data: - GLib.source_remove(timeout) - return self._rx_data + for e in self._rx_data: + if event in e: + GLib.source_remove(timeout) + return self._rx_data if self._wait_timed_out: raise TimeoutError('waiting for wpas event timed out')
Signature · 1 line
2.31.1
Denis Kenzior
Hi James,
Quoted 6 lines · James Prestwood
wait_for_eventwas checking the event string presence in therx_dataarray which meant the event string had to match perfectly to any received events. This poses problems with events that include additional information which the caller may not be able to know or does not care about. For example:
Quoted 8 lines
DPP-RX src=02:00:00:00:02:00 freq=2437 type=11
Waiting for this event previously would require the caller know src, freq, and type. If the caller only wants to wait for DPP-RX, it can now do that.
--- autotests/util/wpas.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
All applied, thanks.
Regards,
-Denis
James Prestwood
PATCH 2/6 auto-t: iwd.py: remove unused members
In reply to James Prestwood--- autotests/util/iwd.py | 2 -- 1 file changed, 2 deletions(-)
autotests/util/iwd.py +0 -2
@@ -231,8 +231,6 @@ class StationDebug(IWDDBusAbstract): _iface_name = IWD_STATION_DEBUG_INTERFACE def __init__(self, *args, **kwargs): - self._debug_props = None - self._debug_iface = None self._last_event = None self._last_event_data = []
Signature · 1 line
2.31.1
James Prestwood
PATCH 3/6 auto-t: wpas.py: add wait_for_result
In reply to James PrestwoodSome wpa_cli utilities return some result which isn't possible to get with wait_for_event unless you know what the result will be. This adds wait_for_result which just returns the first event that comes in.
--- autotests/util/wpas.py | 7 +++++++ 1 file changed, 7 insertions(+)
autotests/util/wpas.py +7 -0
@@ -70,6 +70,9 @@ class Wpas: while True: context.iteration(may_block=True) + if not event and len(self._rx_data) >= 1: + return self._rx_data[0] + for e in self._rx_data: if event in e: GLib.source_remove(timeout)
@@ -78,6 +81,10 @@ class Wpas: if self._wait_timed_out: raise TimeoutError('waiting for wpas event timed out') + def wait_for_result(self, timeout=10): + self._rx_data = [] + return self.wait_for_event(None, timeout=timeout) + def _event_parse(self, line): # Unescape event parameter values in '', other escaping rules not implemented key = None
Signature · 1 line
2.31.1
James Prestwood
PATCH 4/6 auto-t: iwd.py: add DPP utilities
In reply to James Prestwood--- autotests/util/iwd.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
autotests/util/iwd.py +36 -0
@@ -40,6 +40,7 @@ IWD_P2P_PEER_INTERFACE = 'net.connman.iwd.p2p.Peer' IWD_P2P_SERVICE_MANAGER_INTERFACE = 'net.connman.iwd.p2p.ServiceManager' IWD_P2P_WFD_INTERFACE = 'net.connman.iwd.p2p.Display' IWD_STATION_DEBUG_INTERFACE = 'net.connman.iwd.StationDebug' +IWD_DPP_INTERFACE = 'net.connman.iwd.DeviceProvisioning' IWD_AGENT_MANAGER_PATH = '/net/connman/iwd' IWD_TOP_LEVEL_PATH = '/'
@@ -270,6 +271,20 @@ class StationDebug(IWDDBusAbstract): self._last_event_data = None self._last_event = None +class DeviceProvisioning(IWDDBusAbstract): + ''' + Class represents net.connman.iwd.DeviceProvisioning + ''' + _iface_name = IWD_DPP_INTERFACE + + def start_enrollee(self): + return self._iface.StartEnrollee() + + def start_configurator(self): + return self._iface.StartConfigurator() + + def stop(self): + self._iface.Stop() class Device(IWDDBusAbstract): '''
@@ -283,6 +298,7 @@ class Device(IWDDBusAbstract): self._station_if = None self._station_props = None self._station_debug_obj = None + self._dpp_obj = None IWDDBusAbstract.__init__(self, *args, **kwargs)
@@ -303,6 +319,17 @@ class Device(IWDDBusAbstract): IWD_STATION_INTERFACE) return self._station_if + @property + def _device_provisioning(self): + if self._properties['Mode'] != 'station': + self._prop_proxy.Set(IWD_DEVICE_INTERFACE, 'Mode', 'station') + + if self._dpp_obj is None: + self._dpp_obj = DeviceProvisioning(object_path=self._object_path, + namespace=self._namespace) + + return self._dpp_obj + @property def _station_debug(self): if self._properties['Mode'] != 'station':
@@ -637,6 +664,15 @@ class Device(IWDDBusAbstract): def wait_for_event(self, event, timeout=10): self._station_debug.wait_for_event(event, timeout) + def dpp_start_enrollee(self): + return self._device_provisioning.start_enrollee() + + def dpp_start_configurator(self): + return self._device_provisioning.start_configurator() + + def dpp_stop(self): + return self._device_provisioning.stop() + def __str__(self, prefix = ''): return prefix + 'Device: ' + self.device_path + '\n'\ + prefix + '\tName:\t\t' + self.name + '\n'\
Signature · 1 line
2.31.1
James Prestwood
PATCH 5/6 auto-t: wpas.py: add DPP utilities
In reply to James Prestwood--- autotests/util/wpas.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
autotests/util/wpas.py +26 -0
@@ -3,6 +3,7 @@ import os import socket from gi.repository import GLib from config import ctx +import binascii ctrl_count = 0
@@ -249,6 +250,31 @@ class Wpas: def set(self, key, value, **kwargs): self._ctrl_request('SET ' + key + ' ' + value, **kwargs) + def dpp_enrollee_start(self, uri=None): + self._ctrl_request('DPP_BOOTSTRAP_GEN type=qrcode') + self.wait_for_result() + + if uri: + self._ctrl_request('DPP_QR_CODE ' + uri) + self._dpp_qr_id = self.wait_for_result() + self._ctrl_request('DPP_AUTH_INIT peer=%s role=enrollee' % self._dpp_qr_id) + + def dpp_configurator_create(self, uri): + self._ctrl_request('DPP_CONFIGURATOR_ADD') + self._dpp_conf_id = self.wait_for_result() + self._ctrl_request('DPP_QR_CODE ' + uri) + self._dpp_qr_id = self.wait_for_result() + + print("DPP Configurator ID: %s. DPP QR ID: %s" % (self._dpp_conf_id, self._dpp_qr_id)) + + def dpp_configurator_start(self, ssid, passphrase): + ssid = binascii.hexlify(ssid.encode()).decode() + passphrase = binascii.hexlify(passphrase.encode()).decode() + + self._ctrl_request('DPP_AUTH_INIT peer=%s conf=sta-psk ssid=%s pass=%s' % (self._dpp_qr_id, ssid, passphrase)) + self.wait_for_event('DPP-AUTH-SUCCESS') + self.wait_for_event('DPP-CONF-SENT') + # Probably needed: remove references to self so that the GC can call __del__ automatically def clean_up(self): if self.io_watch is not None:
Signature · 1 line
2.31.1
James Prestwood
PATCH 6/6 auto-t: add DPP autotests
In reply to James Prestwood--- autotests/testDPP/connection_test.py | 73 ++++++++++++++++++++++++++++ autotests/testDPP/hostapd.conf | 7 +++ autotests/testDPP/hw.conf | 9 ++++ autotests/testDPP/ssidCCMP.psk | 2 + autotests/testDPP/wpas.conf | 5 ++ 5 files changed, 96 insertions(+) create mode 100644 autotests/testDPP/connection_test.py create mode 100644 autotests/testDPP/hostapd.conf create mode 100644 autotests/testDPP/hw.conf create mode 100644 autotests/testDPP/ssidCCMP.psk create mode 100644 autotests/testDPP/wpas.conf
autotests/testDPP/connection_test.py new file +73 -0
@@ -0,0 +1,73 @@ +#!/usr/bin/python3 + +import unittest +import sys + +sys.path.append('../util') +from iwd import IWD +from wpas import Wpas +from hostapd import HostapdCLI + +class Test(unittest.TestCase): + + def test_iwd_as_enrollee(self): + wpas = Wpas('wpas.conf') + + wd = IWD(True) + + devices = wd.list_devices(1) + device = devices[0] + device.autoconnect = True + + uri = device.dpp_start_enrollee() + + wpas.dpp_configurator_create(uri) + wpas.dpp_configurator_start('ssidCCMP', 'secret123') + + condition = 'obj.state == DeviceState.connected' + wd.wait_for_object_condition(device, condition) + + device.disconnect() + device.dpp_stop() + + del wpas + + def test_iwd_as_configurator(self): + IWD.copy_to_storage('ssidCCMP.psk') + + wpas = Wpas('wpas.conf') + hapd = HostapdCLI('hostapd.conf') + + wd = IWD(True) + + devices = wd.list_devices(1) + device = devices[0] + device.autoconnect = True + + condition = 'obj.state == DeviceState.connected' + wd.wait_for_object_condition(device, condition) + + uri = device.dpp_start_configurator() + + wpas.dpp_enrollee_start(uri) + + hapd.wait_for_event('AP-STA-CONNECTED 42:00:00:00:00:00') + + device.disconnect() + device.dpp_stop() + + del wpas + + def tearDown(self): + IWD.clear_storage() + + @classmethod + def setUpClass(cls): + pass + + @classmethod + def tearDownClass(cls): + pass + +if __name__ == '__main__': + unittest.main(exit=True)
autotests/testDPP/hostapd.conf new file +7 -0
@@ -0,0 +1,7 @@ +hw_mode=g +channel=1 +ssid=ssidCCMP + +wpa=2 +wpa_pairwise=CCMP +wpa_passphrase=secret123
autotests/testDPP/hw.conf new file +9 -0
@@ -0,0 +1,9 @@ +[SETUP] +num_radios=3 +start_iwd=0 + +[WPA_SUPPLICANT] +rad0=wpas.conf + +[HOSTAPD] +rad1=hostapd.conf
autotests/testDPP/ssidCCMP.psk new file +2 -0
@@ -0,0 +1,2 @@ +[Security] +Passphrase=secret123
autotests/testDPP/wpas.conf new file +5 -0
@@ -0,0 +1,5 @@ +ctrl_interface=/tmp/rad1-p2p-wpas + +update_config=1 +pmf=2 +dpp_config_processing=2
Signature · 1 line
2.31.1