2022-01-04 19:18:57 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.append('../util')
|
|
|
|
from iwd import IWD
|
2022-06-30 20:03:29 +02:00
|
|
|
from iwd import DeviceProvisioning
|
2022-01-04 19:18:57 +01:00
|
|
|
from wpas import Wpas
|
|
|
|
from hostapd import HostapdCLI
|
2022-01-12 01:55:58 +01:00
|
|
|
from hwsim import Hwsim
|
2022-06-30 20:03:29 +02:00
|
|
|
from config import ctx
|
2022-01-04 19:18:57 +01:00
|
|
|
|
|
|
|
class Test(unittest.TestCase):
|
|
|
|
def test_iwd_as_enrollee(self):
|
2022-01-12 01:55:58 +01:00
|
|
|
self.device.autoconnect = True
|
|
|
|
self.hapd.reload()
|
|
|
|
|
|
|
|
uri = self.device.dpp_start_enrollee()
|
2022-01-04 19:18:57 +01:00
|
|
|
|
2022-01-12 01:55:58 +01:00
|
|
|
self.wpas.dpp_configurator_create(uri)
|
|
|
|
self.wpas.dpp_configurator_start('ssidCCMP', 'secret123')
|
2022-01-04 19:18:57 +01:00
|
|
|
|
2022-01-12 01:55:58 +01:00
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
|
|
self.wd.wait_for_object_condition(self.device, condition)
|
2022-01-04 19:18:57 +01:00
|
|
|
|
2022-01-12 01:55:58 +01:00
|
|
|
def test_iwd_as_enrollee_channel_switch(self):
|
|
|
|
self.device.autoconnect = True
|
|
|
|
self.hapd.reload()
|
2022-01-04 19:18:57 +01:00
|
|
|
|
2022-01-12 01:55:58 +01:00
|
|
|
uri = self.device.dpp_start_enrollee()
|
|
|
|
|
|
|
|
self.wpas.dpp_configurator_create(uri)
|
|
|
|
self.wpas.dpp_configurator_start('ssidCCMP', 'secret123', freq=2462)
|
2022-01-04 19:18:57 +01:00
|
|
|
|
|
|
|
condition = 'obj.state == DeviceState.connected'
|
2022-01-12 01:55:58 +01:00
|
|
|
self.wd.wait_for_object_condition(self.device, condition)
|
2022-01-04 19:18:57 +01:00
|
|
|
|
2022-01-12 01:55:58 +01:00
|
|
|
def test_iwd_as_enrollee_scan_after(self):
|
2022-01-12 19:08:45 +01:00
|
|
|
self.wpas.disconnect()
|
2024-07-24 17:46:41 +02:00
|
|
|
self.device.autoconnect = True
|
2022-01-12 01:55:58 +01:00
|
|
|
uri = self.device.dpp_start_enrollee()
|
2022-01-04 19:18:57 +01:00
|
|
|
|
2022-01-12 01:55:58 +01:00
|
|
|
self.wpas.dpp_configurator_create(uri)
|
|
|
|
self.wpas.dpp_configurator_start('ssidCCMP', 'secret123')
|
2022-01-04 19:18:57 +01:00
|
|
|
|
2022-01-12 01:55:58 +01:00
|
|
|
with self.assertRaises(Exception):
|
|
|
|
self.device.get_ordered_network('ssidCCMP', scan_if_needed=False)
|
2022-01-04 19:18:57 +01:00
|
|
|
|
2024-07-24 17:46:41 +02:00
|
|
|
self.hapd.reload()
|
2022-01-12 01:55:58 +01:00
|
|
|
self.hapd.wait_for_event('AP-ENABLED')
|
2022-01-04 19:18:57 +01:00
|
|
|
|
2022-01-12 01:55:58 +01:00
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
|
|
self.wd.wait_for_object_condition(self.device, condition)
|
|
|
|
|
|
|
|
def test_iwd_as_enrollee_no_ack(self):
|
|
|
|
self.rule0.enabled = True
|
|
|
|
self.device.autoconnect = True
|
|
|
|
self.hapd.reload()
|
|
|
|
|
|
|
|
uri = self.device.dpp_start_enrollee()
|
|
|
|
|
|
|
|
self.wpas.dpp_configurator_create(uri)
|
|
|
|
self.wpas.dpp_configurator_start('ssidCCMP', 'secret123')
|
|
|
|
|
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
|
|
self.wd.wait_for_object_condition(self.device, condition)
|
|
|
|
|
|
|
|
def test_iwd_as_configurator(self):
|
|
|
|
self.hapd.reload()
|
2022-01-12 19:08:45 +01:00
|
|
|
self.hapd.wait_for_event('AP-ENABLED')
|
|
|
|
|
|
|
|
IWD.copy_to_storage('ssidCCMP.psk')
|
|
|
|
self.device.autoconnect = True
|
2022-01-04 19:18:57 +01:00
|
|
|
|
|
|
|
condition = 'obj.state == DeviceState.connected'
|
2022-01-12 01:55:58 +01:00
|
|
|
self.wd.wait_for_object_condition(self.device, condition)
|
2022-01-04 19:18:57 +01:00
|
|
|
|
2022-01-12 01:55:58 +01:00
|
|
|
uri = self.device.dpp_start_configurator()
|
2022-01-04 19:18:57 +01:00
|
|
|
|
2022-01-12 01:55:58 +01:00
|
|
|
self.wpas.dpp_enrollee_start(uri)
|
2022-01-04 19:18:57 +01:00
|
|
|
|
2022-03-28 19:28:42 +02:00
|
|
|
self.wpas.wait_for_event('DPP-CONF-RECEIVED', timeout=30)
|
2022-01-04 19:18:57 +01:00
|
|
|
|
2022-02-22 23:28:46 +01:00
|
|
|
def test_iwd_as_configurator_initiator(self):
|
|
|
|
self.hapd.reload()
|
|
|
|
self.hapd.wait_for_event('AP-ENABLED')
|
|
|
|
|
|
|
|
IWD.copy_to_storage('ssidCCMP.psk')
|
|
|
|
self.device.autoconnect = True
|
|
|
|
|
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
|
|
self.wd.wait_for_object_condition(self.device, condition)
|
|
|
|
|
|
|
|
uri = self.wpas.dpp_enrollee_start(oper_and_channel='81/2')
|
|
|
|
|
|
|
|
self.device.dpp_start_configurator(uri)
|
|
|
|
|
2022-03-28 19:28:42 +02:00
|
|
|
self.wpas.wait_for_event('DPP-CONF-RECEIVED', timeout=30)
|
2022-02-22 23:28:46 +01:00
|
|
|
|
2022-06-30 20:03:29 +02:00
|
|
|
def test_client_as_configurator(self):
|
|
|
|
self.hapd.reload()
|
|
|
|
self.hapd.wait_for_event('AP-ENABLED')
|
|
|
|
|
|
|
|
IWD.copy_to_storage('ssidCCMP.psk')
|
|
|
|
self.device.autoconnect = True
|
|
|
|
|
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
|
|
self.wd.wait_for_object_condition(self.device, condition)
|
|
|
|
|
|
|
|
ctx.start_process(['iwctl', 'dpp', self.device.name, 'start-configurator'], check=True)
|
|
|
|
|
|
|
|
dpp = DeviceProvisioning(self.device.device_path)
|
|
|
|
|
|
|
|
self.wpas.dpp_enrollee_start(dpp.uri)
|
|
|
|
|
|
|
|
self.wpas.wait_for_event('DPP-CONF-RECEIVED', timeout=30)
|
|
|
|
|
|
|
|
def test_client_as_enrollee(self):
|
|
|
|
self.device.autoconnect = True
|
|
|
|
self.hapd.reload()
|
|
|
|
|
|
|
|
ctx.start_process(['iwctl', 'dpp', self.device.name, 'start-enrollee'], check=True)
|
|
|
|
|
|
|
|
dpp = DeviceProvisioning(self.device.device_path)
|
|
|
|
|
|
|
|
self.wpas.dpp_configurator_create(dpp.uri)
|
|
|
|
self.wpas.dpp_configurator_start('ssidCCMP', 'secret123')
|
|
|
|
|
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
|
|
self.wd.wait_for_object_condition(self.device, condition)
|
|
|
|
|
2022-01-12 01:55:58 +01:00
|
|
|
def setUp(self):
|
2022-06-02 20:49:55 +02:00
|
|
|
self.wpas = Wpas('wpas.conf')
|
2022-01-12 01:55:58 +01:00
|
|
|
self.wd = IWD(True)
|
|
|
|
self.device = self.wd.list_devices(1)[0]
|
|
|
|
self.hapd = HostapdCLI('hostapd.conf')
|
|
|
|
self.hapd.disable()
|
|
|
|
self.hwsim = Hwsim()
|
2022-01-04 19:18:57 +01:00
|
|
|
|
2022-01-12 01:55:58 +01:00
|
|
|
self.rule0 = self.hwsim.rules.create()
|
|
|
|
self.rule0.prefix = 'd0'
|
|
|
|
self.rule0.match_offset = 24
|
|
|
|
self.rule0.match = '04 09 50 6f 9a 1a 01 01'
|
|
|
|
self.rule0.match_times = 1
|
|
|
|
self.rule0.drop = True
|
2022-01-04 19:18:57 +01:00
|
|
|
|
|
|
|
def tearDown(self):
|
2023-11-08 18:21:48 +01:00
|
|
|
# Tests end in various states, don't fail when tearing down.
|
|
|
|
try:
|
|
|
|
self.device.disconnect()
|
|
|
|
self.device.dpp_stop()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2022-01-12 01:55:58 +01:00
|
|
|
self.wpas.dpp_configurator_remove()
|
2022-03-28 19:28:42 +02:00
|
|
|
self.wpas.clean_up()
|
2022-01-12 01:55:58 +01:00
|
|
|
|
|
|
|
self.wd = None
|
|
|
|
self.device = None
|
|
|
|
self.wpas = None
|
|
|
|
self.hapd = None
|
|
|
|
self.rule0 = None
|
2022-01-04 19:18:57 +01:00
|
|
|
IWD.clear_storage()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
pass
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(exit=True)
|