commit 9594b03a358eb66b589af8b8a1a62e930b44447b parent c7b072ff2103624446b0d913fc8f98b4fa86cf5b Author: James Prestwood <prestwoj@gmail.com> Date: Thu, 10 Sep 2020 16:12:22 -0700 auto-t: prepare autotests for test-runner re-write The tests basically remained the same with a few minor changes. The wiphy_map and in turn hostapd_map are no longer used. This was already partially converted a long time ago when the 'config' parameter was added to HostapdCLI. This patch fully converts all autotests to use 'config' rather than looking up by interface. Some test scripts were named 'test.py' which was fine before but the new rewrite actually loads each python test as a module. The name 'test' is too ambiguous and causes issues due to a native python module with the same name. All of these files were renamed to 'connection_test.py'. Diffstat:
50 files changed, 1545 insertions(+), 1606 deletions(-)
diff --git a/autotests/testAP-no-support/test.py b/autotests/testAP-no-support/connection_test.py diff --git a/autotests/testAP/connection_test.py b/autotests/testAP/connection_test.py @@ -0,0 +1,106 @@ +#! /usr/bin/python3 + +import unittest +import sys, os + +import iwd +from iwd import IWD +from iwd import PSKAgent +from iwd import NetworkType +from hostapd import HostapdCLI +import testutil + +class Test(unittest.TestCase): + + def client_connect(self, wd, dev): + hostapd = HostapdCLI(config='psk-ccmp.conf') + + ordered_network = dev.get_ordered_network('TestAP1', True) + + self.assertEqual(ordered_network.type, NetworkType.psk) + + psk_agent = PSKAgent('Password1') + wd.register_psk_agent(psk_agent) + + ordered_network.network_object.connect() + + condition = 'obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + wd.unregister_psk_agent(psk_agent) + + testutil.test_iface_operstate(dev.name) + testutil.test_ifaces_connected(hostapd.ifname, dev.name) + + dev.disconnect() + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + def test_connection_success(self): + wd = IWD() + + dev1, dev2 = wd.list_devices(2) + + self.client_connect(wd, dev1) + + dev1.start_ap('TestAP2', 'Password2') + + try: + condition = 'not obj.scanning' + wd.wait_for_object_condition(dev2, condition) + dev2.scan() + condition = 'obj.scanning' + wd.wait_for_object_condition(dev2, condition) + condition = 'not obj.scanning' + wd.wait_for_object_condition(dev2, condition) + + ordered_networks = dev2.get_ordered_networks() + + networks = { n.name: n for n in ordered_networks } + self.assertEqual(networks['TestAP1'].type, NetworkType.psk) + self.assertEqual(networks['TestAP2'].type, NetworkType.psk) + + psk_agent = PSKAgent('Password2') + wd.register_psk_agent(psk_agent) + + try: + dev2.disconnect() + + condition = 'not obj.connected' + wd.wait_for_object_condition(dev2, condition) + except: + pass + + networks['TestAP2'].network_object.connect() + + condition = 'obj.connected' + wd.wait_for_object_condition(networks['TestAP2'].network_object, + condition) + + testutil.test_iface_operstate(dev2.name) + testutil.test_ifaces_connected(dev1.name, dev2.name) + + wd.unregister_psk_agent(psk_agent) + + dev2.disconnect() + + condition = 'not obj.connected' + wd.wait_for_object_condition(networks['TestAP2'].network_object, + condition) + finally: + dev1.stop_ap() + + # Finally test dev1 can go to client mode and connect again + self.client_connect(wd, dev1) + + @classmethod + def setUpClass(cls): + IWD.copy_to_storage('TestAP1.psk') + + @classmethod + def tearDownClass(cls): + IWD.clear_storage() + +if __name__ == '__main__': + unittest.main(exit=True) diff --git a/autotests/testAP/failure_test.py b/autotests/testAP/failure_test.py @@ -8,12 +8,13 @@ import iwd from iwd import IWD from iwd import PSKAgent from iwd import NetworkType -import hostapd +from hostapd import HostapdCLI import testutil class Test(unittest.TestCase): def client_connect(self, wd, dev): + hostapd = HostapdCLI(config='psk-ccmp.conf') ordered_network = dev.get_ordered_network('TestAP1', True) @@ -30,8 +31,7 @@ class Test(unittest.TestCase): wd.unregister_psk_agent(psk_agent) testutil.test_iface_operstate(dev.name) - testutil.test_ifaces_connected(list(hostapd.hostapd_map.keys())[0], - dev.name) + testutil.test_ifaces_connected(hostapd.ifname, dev.name) dev.disconnect() diff --git a/autotests/testAP/test.py b/autotests/testAP/test.py @@ -1,105 +0,0 @@ -#! /usr/bin/python3 - -import unittest -import sys, os - -sys.path.append('../util') -import iwd -from iwd import IWD -from iwd import PSKAgent -from iwd import NetworkType -import hostapd -import testutil - -class Test(unittest.TestCase): - - def client_connect(self, wd, dev): - - ordered_network = dev.get_ordered_network('TestAP1', True) - - self.assertEqual(ordered_network.type, NetworkType.psk) - - psk_agent = PSKAgent('Password1') - wd.register_psk_agent(psk_agent) - - ordered_network.network_object.connect() - - condition = 'obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - wd.unregister_psk_agent(psk_agent) - - testutil.test_iface_operstate(dev.name) - testutil.test_ifaces_connected(list(hostapd.hostapd_map.keys())[0], - dev.name) - - dev.disconnect() - - condition = 'not obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - def test_connection_success(self): - wd = IWD() - - dev1, dev2 = wd.list_devices(2) - - self.client_connect(wd, dev1) - - dev1.start_ap('TestAP2', 'Password2') - - try: - condition = 'not obj.scanning' - wd.wait_for_object_condition(dev2, condition) - dev2.scan() - condition = 'obj.scanning' - wd.wait_for_object_condition(dev2, condition) - condition = 'not obj.scanning' - wd.wait_for_object_condition(dev2, condition) - - ordered_networks = dev2.get_ordered_networks() - networks = { n.name: n for n in ordered_networks } - self.assertEqual(networks['TestAP1'].type, NetworkType.psk) - self.assertEqual(networks['TestAP2'].type, NetworkType.psk) - - psk_agent = PSKAgent('Password2') - wd.register_psk_agent(psk_agent) - - try: - dev2.disconnect() - condition = 'not obj.connected' - wd.wait_for_object_condition(dev2, condition) - except: - pass - - networks['TestAP2'].network_object.connect() - - condition = 'obj.connected' - wd.wait_for_object_condition(networks['TestAP2'].network_object, - condition) - - testutil.test_iface_operstate(dev2.name) - testutil.test_ifaces_connected(dev1.name, dev2.name) - - wd.unregister_psk_agent(psk_agent) - - dev2.disconnect() - - condition = 'not obj.connected' - wd.wait_for_object_condition(networks['TestAP2'].network_object, - condition) - finally: - dev1.stop_ap() - - # Finally test dev1 can go to client mode and connect again - self.client_connect(wd, dev1) - - @classmethod - def setUpClass(cls): - IWD.copy_to_storage('TestAP1.psk') - - @classmethod - def tearDownClass(cls): - IWD.clear_storage() - -if __name__ == '__main__': - unittest.main(exit=True) diff --git a/autotests/testAPRoam/connection_test.py b/autotests/testAPRoam/connection_test.py @@ -10,8 +10,6 @@ from iwd import PSKAgent from iwd import NetworkType from hostapd import HostapdCLI -from hostapd import hostapd_map - from hwsim import Hwsim class Test(unittest.TestCase): diff --git a/autotests/testBSSBlacklist/all_blacklisted_test.py b/autotests/testBSSBlacklist/all_blacklisted_test.py @@ -10,12 +10,8 @@ from iwd import PSKAgent from iwd import NetworkType from hostapd import HostapdCLI -from hostapd import hostapd_map - from hwsim import Hwsim -import time - class Test(unittest.TestCase): def test_connection_success(self): diff --git a/autotests/testBSSBlacklist/bad_pass_test.py b/autotests/testBSSBlacklist/bad_pass_test.py @@ -10,12 +10,8 @@ from iwd import PSKAgent from iwd import NetworkType from hostapd import HostapdCLI -from hostapd import hostapd_map - from hwsim import Hwsim -import time - class Test(unittest.TestCase): def test_connection_success(self): diff --git a/autotests/testBSSBlacklist/connection_test.py b/autotests/testBSSBlacklist/connection_test.py @@ -10,7 +10,6 @@ from iwd import PSKAgent from iwd import NetworkType from hostapd import HostapdCLI -from hostapd import hostapd_map from hwsim import Hwsim diff --git a/autotests/testBSSBlacklist/temp_blacklist_test.py b/autotests/testBSSBlacklist/temp_blacklist_test.py @@ -10,12 +10,8 @@ from iwd import PSKAgent from iwd import NetworkType from hostapd import HostapdCLI -from hostapd import hostapd_map - from hwsim import Hwsim -import time - class Test(unittest.TestCase): def test_connection_success(self): diff --git a/autotests/testClientNonInteractive/connect_command_test.py b/autotests/testClientNonInteractive/connect_command_test.py @@ -12,29 +12,25 @@ import subprocess class Test(unittest.TestCase): def check_connection_success(self, ssid): - wd = IWD() - - device = wd.list_devices(1)[0] + device = self.wd.list_devices(1)[0] condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) + self.wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network(ssid) condition = 'obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) + self.wd.wait_for_object_condition(ordered_network.network_object, condition) device.disconnect() condition = 'not obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) + self.wd.wait_for_object_condition(ordered_network.network_object, condition) def test_connection_with_passphrase(self): ssid = 'ssidPassphrase' - wd = IWD() - - device = wd.list_devices(1)[0] + device = self.wd.list_devices(1)[0] # Use --dontaks cmd-line option with self.assertRaises(subprocess.CalledProcessError): @@ -49,9 +45,7 @@ class Test(unittest.TestCase): def test_connection_with_username_and_password(self): ssid = 'ssidUNameAndPWord' - wd = IWD() - - device = wd.list_devices(1)[0] + device = self.wd.list_devices(1)[0] subprocess.check_call(['iwctl', '-u', 'user', '-p', 'password', 'station', device.name, 'connect', ssid]) @@ -61,9 +55,7 @@ class Test(unittest.TestCase): def test_connection_with_password(self): ssid = 'ssidPWord' - wd = IWD() - - device = wd.list_devices(1)[0] + device = self.wd.list_devices(1)[0] subprocess.check_call(['iwctl', '-p', 'password', 'station', device.name, 'connect', ssid]) @@ -73,9 +65,7 @@ class Test(unittest.TestCase): def test_connection_failure(self): ssid = 'ssidPassphrase' - wd = IWD() - - device = wd.list_devices(1)[0] + device = self.wd.list_devices(1)[0] with self.assertRaises(subprocess.CalledProcessError): subprocess.check_call(['iwctl', '-P', 'incorrect_passphrase', @@ -84,18 +74,14 @@ class Test(unittest.TestCase): def test_invalid_command_line_option(self): ssid = 'ssidPassphrase' - wd = IWD() - - device = wd.list_devices(1)[0] + device = self.wd.list_devices(1)[0] with self.assertRaises(subprocess.CalledProcessError): subprocess.check_call(['iwctl', '-z', 'station', device.name, 'connect', ssid]) def test_invalid_command(self): - wd = IWD() - - device = wd.list_devices(1)[0] + device = self.wd.list_devices(1)[0] with self.assertRaises(subprocess.CalledProcessError): subprocess.check_call(['iwctl', 'inexistent', 'command']) @@ -105,17 +91,17 @@ class Test(unittest.TestCase): IWD.copy_to_storage('ssidUNameAndPWord.8021x') IWD.copy_to_storage('ssidPWord.8021x') - wd = IWD() + cls.wd = IWD() - device = wd.list_devices(1)[0] + device = cls.wd.list_devices(1)[0] condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) + cls.wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) + cls.wd.wait_for_object_condition(device, condition) @classmethod def tearDownClass(cls): diff --git a/autotests/testDisconnectByAP/disconnect_by_ap_test.py b/autotests/testDisconnectByAP/disconnect_by_ap_test.py @@ -10,7 +10,6 @@ from iwd import DeviceState from iwd import NetworkType from hostapd import HostapdCLI -from hostapd import hostapd_map class Test(unittest.TestCase): @@ -20,8 +19,7 @@ class Test(unittest.TestCase): devices = wd.list_devices(1) device = devices[0] - hostapd_if = list(hostapd_map.values())[0] - hostapd = HostapdCLI(hostapd_if) + hostapd = HostapdCLI(config='ssidOpen.conf') device.scan() diff --git a/autotests/testEAP-AKA/connection_test.py b/autotests/testEAP-AKA/connection_test.py @@ -10,7 +10,6 @@ from iwd import NetworkType from hlrauc import AuthCenter from hostapd import HostapdCLI -from hostapd import hostapd_map class Test(unittest.TestCase): diff --git a/autotests/testEAP-PEAPv0-CryptoBinding/ISK_test.py b/autotests/testEAP-PEAPv0-CryptoBinding/ISK_test.py @@ -11,7 +11,6 @@ from iwd import NetworkType import testutil from hostapd import HostapdCLI -from hostapd import hostapd_map class Test(unittest.TestCase): diff --git a/autotests/testEAP-PEAPv0-CryptoBinding/NoISK_test.py b/autotests/testEAP-PEAPv0-CryptoBinding/NoISK_test.py @@ -11,7 +11,6 @@ from iwd import NetworkType import testutil from hostapd import HostapdCLI -from hostapd import hostapd_map class Test(unittest.TestCase): diff --git a/autotests/testEAP-PEAPv0-CryptoBinding/main.conf b/autotests/testEAP-PEAPv0-CryptoBinding/main.conf @@ -1,2 +0,0 @@ -[General] -UseDefaultInterface=true diff --git a/autotests/testEAP-PWD/connection_test.py b/autotests/testEAP-PWD/connection_test.py @@ -10,7 +10,6 @@ from iwd import PSKAgent from iwd import NetworkType from hostapd import HostapdCLI -from hostapd import hostapd_map class Test(unittest.TestCase): diff --git a/autotests/testEAP-SIM/connection_test.py b/autotests/testEAP-SIM/connection_test.py @@ -10,7 +10,6 @@ from iwd import NetworkType from hlrauc import AuthCenter from hostapd import HostapdCLI -from hostapd import hostapd_map class Test(unittest.TestCase): diff --git a/autotests/testEAP-TLS-embedded-pems/connection_test.py b/autotests/testEAP-TLS-embedded-pems/connection_test.py @@ -9,23 +9,18 @@ from iwd import IWD from iwd import PSKAgent from iwd import NetworkType import testutil -import hostapd +from hostapd import HostapdCLI class Test(unittest.TestCase): def do_test_connection_success(self, ssid, passphrase=None): + hostapd = HostapdCLI(config=ssid + '.conf') wd = IWD() if passphrase: psk_agent = PSKAgent(passphrase) wd.register_psk_agent(psk_agent) - hostapd_ifname = None - for ifname in hostapd.hostapd_map: - if ssid + '.conf' in hostapd.hostapd_map[ifname].config: - hostapd_ifname = ifname - break - devices = wd.list_devices(1) device = devices[0] @@ -52,7 +47,7 @@ class Test(unittest.TestCase): wd.wait_for_object_condition(ordered_network.network_object, condition) testutil.test_iface_operstate() - testutil.test_ifaces_connected(hostapd_ifname, device.name) + testutil.test_ifaces_connected(hostapd.ifname, device.name) device.disconnect() diff --git a/autotests/testEAP-TTLS-CHAP/connection_test.py b/autotests/testEAP-TTLS-CHAP/connection_test.py @@ -11,7 +11,6 @@ from iwd import PSKAgent from iwd import NetworkType from hostapd import HostapdCLI -from hostapd import hostapd_map class Test(unittest.TestCase): diff --git a/autotests/testEAP-TTLS-MSCHAP/connection_test.py b/autotests/testEAP-TTLS-MSCHAP/connection_test.py @@ -11,7 +11,6 @@ from iwd import PSKAgent from iwd import NetworkType from hostapd import HostapdCLI -from hostapd import hostapd_map class Test(unittest.TestCase): diff --git a/autotests/testEAP-TTLS-PAP/connection_test.py b/autotests/testEAP-TTLS-PAP/connection_test.py @@ -11,7 +11,6 @@ from iwd import PSKAgent from iwd import NetworkType from hostapd import HostapdCLI -from hostapd import hostapd_map class Test(unittest.TestCase): diff --git a/autotests/testEAP-WPS-Frag/wps_frag_test.py b/autotests/testEAP-WPS-Frag/wps_frag_test.py @@ -9,7 +9,6 @@ from iwd import IWD from iwd import DeviceState from hostapd import HostapdCLI -from hostapd import hostapd_map class Test(unittest.TestCase): @@ -32,8 +31,7 @@ class Test(unittest.TestCase): @classmethod def setUpClass(cls): - cls.hostapd_if = list(hostapd_map.values())[0] - cls.hostapd = HostapdCLI(cls.hostapd_if) + cls.hostapd = HostapdCLI(config='ssid-wps-small-mtu.conf') cls.hostapd.wps_push_button() diff --git a/autotests/testEAP-WPS/four_digit_pin_test.py b/autotests/testEAP-WPS/four_digit_pin_test.py @@ -9,7 +9,6 @@ from iwd import IWD from iwd import DeviceState from hostapd import HostapdCLI -from hostapd import hostapd_map class Test(unittest.TestCase): @@ -39,8 +38,7 @@ class Test(unittest.TestCase): @classmethod def setUpClass(cls): - cls.hostapd_if = list(hostapd_map.values())[0] - cls.hostapd = HostapdCLI(cls.hostapd_if) + cls.hostapd = HostapdCLI(config='ssidWPS.conf') @classmethod def tearDownClass(cls): diff --git a/autotests/testEAP-WPS/pin_test.py b/autotests/testEAP-WPS/pin_test.py @@ -9,7 +9,6 @@ from iwd import IWD from iwd import DeviceState from hostapd import HostapdCLI -from hostapd import hostapd_map class Test(unittest.TestCase): @@ -42,8 +41,7 @@ class Test(unittest.TestCase): @classmethod def setUpClass(cls): - cls.hostapd_if = list(hostapd_map.values())[0] - cls.hostapd = HostapdCLI(cls.hostapd_if) + cls.hostapd = HostapdCLI(config='ssidWPS.conf') @classmethod def tearDownClass(cls): diff --git a/autotests/testEAP-WPS/push_button_test.py b/autotests/testEAP-WPS/push_button_test.py @@ -9,8 +9,6 @@ from iwd import IWD from iwd import DeviceState from hostapd import HostapdCLI -from hostapd import hostapd_map - class Test(unittest.TestCase): def push_button_success(self, wd): @@ -38,8 +36,7 @@ class Test(unittest.TestCase): @classmethod def setUpClass(cls): - cls.hostapd_if = list(hostapd_map.values())[0] - cls.hostapd = HostapdCLI(cls.hostapd_if) + cls.hostapd = HostapdCLI(config='ssidWPS.conf') @classmethod def tearDownClass(cls): diff --git a/autotests/testFILS/fils_256_test.py b/autotests/testFILS/fils_256_test.py @@ -9,7 +9,6 @@ import iwd from iwd import IWD from iwd import PSKAgent from iwd import NetworkType -from hostapd import hostapd_map from hostapd import HostapdCLI import testutil diff --git a/autotests/testFILS/fils_384_test.py b/autotests/testFILS/fils_384_test.py @@ -9,7 +9,6 @@ import iwd from iwd import IWD from iwd import PSKAgent from iwd import NetworkType -from hostapd import hostapd_map from hostapd import HostapdCLI import testutil diff --git a/autotests/testFT-8021x-roam/connection_test.py b/autotests/testFT-8021x-roam/connection_test.py @@ -0,0 +1,224 @@ +#! /usr/bin/python3 + +import unittest +import sys, os + +sys.path.append('../util') +import iwd +from iwd import IWD +from iwd import NetworkType +from hwsim import Hwsim +from hostapd import HostapdCLI +import testutil + +class Test(unittest.TestCase): + def test_roam_success(self): + hwsim = Hwsim() + + rule0 = hwsim.rules.create() + rule0.source = self.bss_radio[0].addresses[0] + rule0.bidirectional = True + + rule1 = hwsim.rules.create() + rule1.source = self.bss_radio[1].addresses[0] + rule1.bidirectional = True + + wd = IWD() + + device = wd.list_devices(1)[0] + + # Check that iwd selects BSS 0 first + rule0.signal = -2000 + rule1.signal = -2500 + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + device.scan() + + condition = 'obj.scanning' + wd.wait_for_object_condition(device, condition) + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + ordered_network = device.get_ordered_network('TestFT') + + self.assertEqual(ordered_network.type, NetworkType.eap) + self.assertEqual(ordered_network.signal_strength, -2000) + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertFalse(self.bss_hostapd[0].list_sta()) + self.assertFalse(self.bss_hostapd[1].list_sta()) + + ordered_network.network_object.connect() + + condition = 'obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertTrue(self.bss_hostapd[0].list_sta()) + self.assertFalse(self.bss_hostapd[1].list_sta()) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[1].ifname, device.name)) + + # Check that iwd starts transition to BSS 1 in less than 10 seconds. + # The 10 seconds is longer than needed to scan on just two channels + # but short enough that a full scan on the 2.4 + 5.8 bands supported + # by mac80211_hwsim will not finish. If this times out then, but + # device_roam_trigger_cb has happened, it probably means that + # Neighbor Reports are broken. + rule0.signal = -8000 + + condition = 'obj.state == DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 10) + + # Check that iwd is on BSS 1 once out of roaming state and doesn't + # go through 'disconnected', 'autoconnect', 'connecting' in between + condition = 'obj.state != DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 5) + + self.assertEqual(device.state, iwd.DeviceState.connected) + self.assertTrue(self.bss_hostapd[1].list_sta()) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[0].ifname, device.name)) + + def test_roam_on_beacon_loss(self): + hwsim = Hwsim() + + rule0 = hwsim.rules.create() + rule0.source = self.bss_radio[0].addresses[0] + rule0.bidirectional = True + + rule1 = hwsim.rules.create() + rule1.source = self.bss_radio[1].addresses[0] + rule1.bidirectional = True + + wd = IWD() + + device = wd.list_devices(1)[0] + + # Check that iwd selects BSS 0 first + rule0.signal = -2000 + rule1.signal = -2500 + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + device.scan() + + condition = 'obj.scanning' + wd.wait_for_object_condition(device, condition) + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + ordered_network = device.get_ordered_network("TestFT") + self.assertEqual(ordered_network.type, NetworkType.eap) + self.assertEqual(ordered_network.signal_strength, -2000) + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertFalse(self.bss_hostapd[0].list_sta()) + self.assertFalse(self.bss_hostapd[1].list_sta()) + + ordered_network.network_object.connect() + + condition = 'obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertTrue(self.bss_hostapd[0].list_sta()) + self.assertFalse(self.bss_hostapd[1].list_sta()) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[1].ifname, device.name)) + + # Check that iwd starts transition to BSS 1 in less than 20 seconds + # from a beacon loss event + rule0.drop = True + rule0.signal = -3000 + wd.wait(2) + rule0.drop = False + + condition = 'obj.state == DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 20) + + # Check that iwd is on BSS 1 once out of roaming state and doesn't + # go through 'disconnected', 'autoconnect', 'connecting' in between + condition = 'obj.state != DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 5) + + self.assertEqual(device.state, iwd.DeviceState.connected) + self.assertTrue(self.bss_hostapd[1].list_sta()) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[0].ifname, device.name)) + + def tearDown(self): + os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" down') + os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" down') + os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" up') + os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up') + + hwsim = Hwsim() + wd = IWD() + device = wd.list_devices(1)[0] + try: + device.disconnect() + except: + pass + + condition = 'obj.state == DeviceState.disconnected' + wd.wait_for_object_condition(device, condition) + + for rule in list(hwsim.rules.keys()): + del hwsim.rules[rule] + + @classmethod + def setUpClass(cls): + IWD.copy_to_storage('TestFT.8021x') + + hwsim = Hwsim() + + cls.bss_hostapd = [ HostapdCLI(config='ft-eap-ccmp-1.conf'), + HostapdCLI(config='ft-eap-ccmp-2.conf') ] + cls.bss_radio = [ hwsim.get_radio('rad0'), + hwsim.get_radio('rad1') ] + + # Set interface addresses to those expected by hostapd config files + os.system('ifconfig "' + cls.bss_hostapd[0].ifname + + '" down hw ether 12:00:00:00:00:01 up') + os.system('ifconfig "' + cls.bss_hostapd[1].ifname + + '" down hw ether 12:00:00:00:00:02 up') + + cls.bss_hostapd[0].reload() + cls.bss_hostapd[1].reload() + + # Fill in the neighbor AP tables in both BSSes. By default each + # instance knows only about current BSS, even inside one hostapd + # process. + # FT still works without the neighbor AP table but neighbor reports + # have to be disabled in the .conf files + cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT', + '1200000000028f0000005102060603000000') + cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT', + '1200000000018f0000005101060603000000') + + @classmethod + def tearDownClass(cls): + IWD.clear_storage() + +if __name__ == '__main__': + unittest.main(exit=True) diff --git a/autotests/testFT-8021x-roam/test.py b/autotests/testFT-8021x-roam/test.py @@ -1,224 +0,0 @@ -#! /usr/bin/python3 - -import unittest -import sys, os - -sys.path.append('../util') -import iwd -from iwd import IWD -from iwd import NetworkType -from hwsim import Hwsim -from hostapd import HostapdCLI, hostapd_map -import testutil - -class Test(unittest.TestCase): - def test_roam_success(self): - hwsim = Hwsim() - - rule0 = hwsim.rules.create() - rule0.source = self.bss_radio[0].addresses[0] - rule0.bidirectional = True - - rule1 = hwsim.rules.create() - rule1.source = self.bss_radio[1].addresses[0] - rule1.bidirectional = True - - wd = IWD() - - device = wd.list_devices(1)[0] - - # Check that iwd selects BSS 0 first - rule0.signal = -2000 - rule1.signal = -2500 - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - device.scan() - - condition = 'obj.scanning' - wd.wait_for_object_condition(device, condition) - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - ordered_network = device.get_ordered_network('TestFT') - - self.assertEqual(ordered_network.type, NetworkType.eap) - self.assertEqual(ordered_network.signal_strength, -2000) - - condition = 'not obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertFalse(self.bss_hostapd[0].list_sta()) - self.assertFalse(self.bss_hostapd[1].list_sta()) - - ordered_network.network_object.connect() - - condition = 'obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertTrue(self.bss_hostapd[0].list_sta()) - self.assertFalse(self.bss_hostapd[1].list_sta()) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[1].ifname, device.name)) - - # Check that iwd starts transition to BSS 1 in less than 10 seconds. - # The 10 seconds is longer than needed to scan on just two channels - # but short enough that a full scan on the 2.4 + 5.8 bands supported - # by mac80211_hwsim will not finish. If this times out then, but - # device_roam_trigger_cb has happened, it probably means that - # Neighbor Reports are broken. - rule0.signal = -8000 - - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 10) - - # Check that iwd is on BSS 1 once out of roaming state and doesn't - # go through 'disconnected', 'autoconnect', 'connecting' in between - condition = 'obj.state != DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 5) - - self.assertEqual(device.state, iwd.DeviceState.connected) - self.assertTrue(self.bss_hostapd[1].list_sta()) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[0].ifname, device.name)) - - def test_roam_on_beacon_loss(self): - hwsim = Hwsim() - - rule0 = hwsim.rules.create() - rule0.source = self.bss_radio[0].addresses[0] - rule0.bidirectional = True - - rule1 = hwsim.rules.create() - rule1.source = self.bss_radio[1].addresses[0] - rule1.bidirectional = True - - wd = IWD() - - device = wd.list_devices(1)[0] - - # Check that iwd selects BSS 0 first - rule0.signal = -2000 - rule1.signal = -2500 - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - device.scan() - - condition = 'obj.scanning' - wd.wait_for_object_condition(device, condition) - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - ordered_network = device.get_ordered_network("TestFT") - self.assertEqual(ordered_network.type, NetworkType.eap) - self.assertEqual(ordered_network.signal_strength, -2000) - - condition = 'not obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertFalse(self.bss_hostapd[0].list_sta()) - self.assertFalse(self.bss_hostapd[1].list_sta()) - - ordered_network.network_object.connect() - - condition = 'obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertTrue(self.bss_hostapd[0].list_sta()) - self.assertFalse(self.bss_hostapd[1].list_sta()) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[1].ifname, device.name)) - - # Check that iwd starts transition to BSS 1 in less than 20 seconds - # from a beacon loss event - rule0.drop = True - rule0.signal = -3000 - wd.wait(2) - rule0.drop = False - - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 20) - - # Check that iwd is on BSS 1 once out of roaming state and doesn't - # go through 'disconnected', 'autoconnect', 'connecting' in between - condition = 'obj.state != DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 5) - - self.assertEqual(device.state, iwd.DeviceState.connected) - self.assertTrue(self.bss_hostapd[1].list_sta()) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[0].ifname, device.name)) - - def tearDown(self): - os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" down') - os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" down') - os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" up') - os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up') - - hwsim = Hwsim() - wd = IWD() - device = wd.list_devices(1)[0] - try: - device.disconnect() - except: - pass - - condition = 'obj.state == DeviceState.disconnected' - wd.wait_for_object_condition(device, condition) - - for rule in list(hwsim.rules.keys()): - del hwsim.rules[rule] - - @classmethod - def setUpClass(cls): - IWD.copy_to_storage('TestFT.8021x') - - hwsim = Hwsim() - - cls.bss_hostapd = [ HostapdCLI(config='ft-eap-ccmp-1.conf'), - HostapdCLI(config='ft-eap-ccmp-2.conf') ] - cls.bss_radio = [ hwsim.get_radio('rad0'), - hwsim.get_radio('rad1') ] - - # Set interface addresses to those expected by hostapd config files - os.system('ifconfig "' + cls.bss_hostapd[0].ifname + - '" down hw ether 12:00:00:00:00:01 up') - os.system('ifconfig "' + cls.bss_hostapd[1].ifname + - '" down hw ether 12:00:00:00:00:02 up') - - cls.bss_hostapd[0].reload() - cls.bss_hostapd[1].reload() - - # Fill in the neighbor AP tables in both BSSes. By default each - # instance knows only about current BSS, even inside one hostapd - # process. - # FT still works without the neighbor AP table but neighbor reports - # have to be disabled in the .conf files - cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT', - '1200000000028f0000005102060603000000') - cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT', - '1200000000018f0000005101060603000000') - - @classmethod - def tearDownClass(cls): - IWD.clear_storage() - -if __name__ == '__main__': - unittest.main(exit=True) diff --git a/autotests/testFT-FILS-SHA256/connection_test.py b/autotests/testFT-FILS-SHA256/connection_test.py @@ -0,0 +1,179 @@ +#! /usr/bin/python3 + +import unittest +import sys, os + +sys.path.append('../util') +import iwd +from iwd import IWD +from iwd import PSKAgent +from iwd import NetworkType +from hwsim import Hwsim +from hostapd import HostapdCLI +import testutil + +class Test(unittest.TestCase): + def test_roam_success(self): + hwsim = Hwsim() + + rule0 = hwsim.rules.create() + rule0.source = self.bss_radio[0].addresses[0] + rule0.bidirectional = True + + rule1 = hwsim.rules.create() + rule1.source = self.bss_radio[1].addresses[0] + rule1.bidirectional = True + + wd = IWD() + + psk_agent = PSKAgent('user@example.com', ('user@example.com', + 'secret123')) + wd.register_psk_agent(psk_agent) + + device = wd.list_devices(1)[0] + + # Check that iwd selects BSS 0 first + rule0.signal = -2000 + rule1.signal = -2500 + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + device.scan() + + condition = 'obj.scanning' + wd.wait_for_object_condition(device, condition) + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + ordered_network = device.get_ordered_network('TestFT') + + self.assertEqual(ordered_network.type, NetworkType.eap) + self.assertEqual(ordered_network.signal_strength, -2000) + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertFalse(self.bss_hostapd[0].list_sta()) + self.assertFalse(self.bss_hostapd[1].list_sta()) + + ordered_network.network_object.connect() + + condition = 'obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertTrue(self.bss_hostapd[0].list_sta()) + self.assertFalse(self.bss_hostapd[1].list_sta()) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[1].ifname, device.name)) + + device.disconnect() + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + ordered_network = device.get_ordered_network('TestFT') + + self.assertEqual(ordered_network.type, NetworkType.eap) + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + ordered_network.network_object.connect() + + condition = 'obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertTrue(self.bss_hostapd[0].list_sta()) + self.assertFalse(self.bss_hostapd[1].list_sta()) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[1].ifname, device.name)) + + # Check that iwd starts transition to BSS 1 in less than 10 seconds. + # The 10 seconds is longer than needed to scan on just two channels + # but short enough that a full scan on the 2.4 + 5.8 bands supported + # by mac80211_hwsim will not finish. If this times out then, but + # device_roam_trigger_cb has happened, it probably means that + # Neighbor Reports are broken. + rule0.signal = -8000 + + condition = 'obj.state == DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 10) + + # Check that iwd is on BSS 1 once out of roaming state and doesn't + # go through 'disconnected', 'autoconnect', 'connecting' in between + condition = 'obj.state != DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 5) + + self.assertEqual(device.state, iwd.DeviceState.connected) + self.assertTrue(self.bss_hostapd[1].list_sta()) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[0].ifname, device.name)) + + def tearDown(self): + os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" down') + os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" down') + os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" up') + os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up') + + hwsim = Hwsim() + wd = IWD() + device = wd.list_devices(1)[0] + try: + device.disconnect() + except: + pass + + condition = 'obj.state == DeviceState.disconnected' + wd.wait_for_object_condition(device, condition) + + for rule in list(hwsim.rules.keys()): + del hwsim.rules[rule] + + @classmethod + def setUpClass(cls): + os.system('ifconfig lo up') + IWD.copy_to_storage('TestFT.8021x') + + hwsim = Hwsim() + + cls.bss_hostapd = [ HostapdCLI(config='ft-eap-ccmp-1.conf'), + HostapdCLI(config='ft-eap-ccmp-2.conf') ] + cls.bss_radio = [ hwsim.get_radio('rad0'), + hwsim.get_radio('rad1') ] + + # Set interface addresses to those expected by hostapd config files + os.system('ifconfig "' + cls.bss_hostapd[0].ifname + + '" down hw ether 12:00:00:00:00:01 up') + os.system('ifconfig "' + cls.bss_hostapd[1].ifname + + '" down hw ether 12:00:00:00:00:02 up') + + cls.bss_hostapd[0].reload() + cls.bss_hostapd[1].reload() + + # Fill in the neighbor AP tables in both BSSes. By default each + # instance knows only about current BSS, even inside one hostapd + # process. + # FT still works without the neighbor AP table but neighbor reports + # have to be disabled in the .conf files + cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT', + '1200000000028f0000005102060603000000') + cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT', + '1200000000018f0000005101060603000000') + + @classmethod + def tearDownClass(cls): + IWD.clear_storage() + +if __name__ == '__main__': + unittest.main(exit=True) diff --git a/autotests/testFT-FILS-SHA256/test.py b/autotests/testFT-FILS-SHA256/test.py @@ -1,179 +0,0 @@ -#! /usr/bin/python3 - -import unittest -import sys, os - -sys.path.append('../util') -import iwd -from iwd import IWD -from iwd import PSKAgent -from iwd import NetworkType -from hwsim import Hwsim -from hostapd import HostapdCLI, hostapd_map -import testutil - -class Test(unittest.TestCase): - def test_roam_success(self): - hwsim = Hwsim() - - rule0 = hwsim.rules.create() - rule0.source = self.bss_radio[0].addresses[0] - rule0.bidirectional = True - - rule1 = hwsim.rules.create() - rule1.source = self.bss_radio[1].addresses[0] - rule1.bidirectional = True - - wd = IWD() - - psk_agent = PSKAgent('user@example.com', ('user@example.com', - 'secret123')) - wd.register_psk_agent(psk_agent) - - device = wd.list_devices(1)[0] - - # Check that iwd selects BSS 0 first - rule0.signal = -2000 - rule1.signal = -2500 - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - device.scan() - - condition = 'obj.scanning' - wd.wait_for_object_condition(device, condition) - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - ordered_network = device.get_ordered_network('TestFT') - - self.assertEqual(ordered_network.type, NetworkType.eap) - self.assertEqual(ordered_network.signal_strength, -2000) - - condition = 'not obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertFalse(self.bss_hostapd[0].list_sta()) - self.assertFalse(self.bss_hostapd[1].list_sta()) - - ordered_network.network_object.connect() - - condition = 'obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertTrue(self.bss_hostapd[0].list_sta()) - self.assertFalse(self.bss_hostapd[1].list_sta()) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[1].ifname, device.name)) - - device.disconnect() - - condition = 'not obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - ordered_network = device.get_ordered_network('TestFT') - - self.assertEqual(ordered_network.type, NetworkType.eap) - - condition = 'not obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - ordered_network.network_object.connect() - - condition = 'obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertTrue(self.bss_hostapd[0].list_sta()) - self.assertFalse(self.bss_hostapd[1].list_sta()) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[1].ifname, device.name)) - - # Check that iwd starts transition to BSS 1 in less than 10 seconds. - # The 10 seconds is longer than needed to scan on just two channels - # but short enough that a full scan on the 2.4 + 5.8 bands supported - # by mac80211_hwsim will not finish. If this times out then, but - # device_roam_trigger_cb has happened, it probably means that - # Neighbor Reports are broken. - rule0.signal = -8000 - - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 10) - - # Check that iwd is on BSS 1 once out of roaming state and doesn't - # go through 'disconnected', 'autoconnect', 'connecting' in between - condition = 'obj.state != DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 5) - - self.assertEqual(device.state, iwd.DeviceState.connected) - self.assertTrue(self.bss_hostapd[1].list_sta()) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[0].ifname, device.name)) - - def tearDown(self): - os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" down') - os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" down') - os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" up') - os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up') - - hwsim = Hwsim() - wd = IWD() - device = wd.list_devices(1)[0] - try: - device.disconnect() - except: - pass - - condition = 'obj.state == DeviceState.disconnected' - wd.wait_for_object_condition(device, condition) - - for rule in list(hwsim.rules.keys()): - del hwsim.rules[rule] - - @classmethod - def setUpClass(cls): - os.system('ifconfig lo up') - IWD.copy_to_storage('TestFT.8021x') - - hwsim = Hwsim() - - cls.bss_hostapd = [ HostapdCLI(config='ft-eap-ccmp-1.conf'), - HostapdCLI(config='ft-eap-ccmp-2.conf') ] - cls.bss_radio = [ hwsim.get_radio('rad0'), - hwsim.get_radio('rad1') ] - - # Set interface addresses to those expected by hostapd config files - os.system('ifconfig "' + cls.bss_hostapd[0].ifname + - '" down hw ether 12:00:00:00:00:01 up') - os.system('ifconfig "' + cls.bss_hostapd[1].ifname + - '" down hw ether 12:00:00:00:00:02 up') - - cls.bss_hostapd[0].reload() - cls.bss_hostapd[1].reload() - - # Fill in the neighbor AP tables in both BSSes. By default each - # instance knows only about current BSS, even inside one hostapd - # process. - # FT still works without the neighbor AP table but neighbor reports - # have to be disabled in the .conf files - cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT', - '1200000000028f0000005102060603000000') - cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT', - '1200000000018f0000005101060603000000') - - @classmethod - def tearDownClass(cls): - IWD.clear_storage() - -if __name__ == '__main__': - unittest.main(exit=True) diff --git a/autotests/testFT-FILS-SHA384/connection_test.py b/autotests/testFT-FILS-SHA384/connection_test.py @@ -0,0 +1,179 @@ +#! /usr/bin/python3 + +import unittest +import sys, os + +sys.path.append('../util') +import iwd +from iwd import IWD +from iwd import PSKAgent +from iwd import NetworkType +from hwsim import Hwsim +from hostapd import HostapdCLI +import testutil + +class Test(unittest.TestCase): + def test_roam_success(self): + hwsim = Hwsim() + + rule0 = hwsim.rules.create() + rule0.source = self.bss_radio[0].addresses[0] + rule0.bidirectional = True + + rule1 = hwsim.rules.create() + rule1.source = self.bss_radio[1].addresses[0] + rule1.bidirectional = True + + wd = IWD() + + psk_agent = PSKAgent('user@example.com', ('user@example.com', + 'secret123')) + wd.register_psk_agent(psk_agent) + + device = wd.list_devices(1)[0] + + # Check that iwd selects BSS 0 first + rule0.signal = -2000 + rule1.signal = -2500 + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + device.scan() + + condition = 'obj.scanning' + wd.wait_for_object_condition(device, condition) + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + ordered_network = device.get_ordered_network('TestFT') + + self.assertEqual(ordered_network.type, NetworkType.eap) + self.assertEqual(ordered_network.signal_strength, -2000) + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertFalse(self.bss_hostapd[0].list_sta()) + self.assertFalse(self.bss_hostapd[1].list_sta()) + + ordered_network.network_object.connect() + + condition = 'obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertTrue(self.bss_hostapd[0].list_sta()) + self.assertFalse(self.bss_hostapd[1].list_sta()) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[1].ifname, device.name)) + + device.disconnect() + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + ordered_network = device.get_ordered_network('TestFT') + + self.assertEqual(ordered_network.type, NetworkType.eap) + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + ordered_network.network_object.connect() + + condition = 'obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertTrue(self.bss_hostapd[0].list_sta()) + self.assertFalse(self.bss_hostapd[1].list_sta()) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[1].ifname, device.name)) + + # Check that iwd starts transition to BSS 1 in less than 10 seconds. + # The 10 seconds is longer than needed to scan on just two channels + # but short enough that a full scan on the 2.4 + 5.8 bands supported + # by mac80211_hwsim will not finish. If this times out then, but + # device_roam_trigger_cb has happened, it probably means that + # Neighbor Reports are broken. + rule0.signal = -8000 + + condition = 'obj.state == DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 10) + + # Check that iwd is on BSS 1 once out of roaming state and doesn't + # go through 'disconnected', 'autoconnect', 'connecting' in between + condition = 'obj.state != DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 5) + + self.assertEqual(device.state, iwd.DeviceState.connected) + self.assertTrue(self.bss_hostapd[1].list_sta()) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[0].ifname, device.name)) + + def tearDown(self): + os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" down') + os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" down') + os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" up') + os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up') + + hwsim = Hwsim() + wd = IWD() + device = wd.list_devices(1)[0] + try: + device.disconnect() + except: + pass + + condition = 'obj.state == DeviceState.disconnected' + wd.wait_for_object_condition(device, condition) + + for rule in list(hwsim.rules.keys()): + del hwsim.rules[rule] + + @classmethod + def setUpClass(cls): + os.system('ifconfig lo up') + IWD.copy_to_storage('TestFT.8021x') + + hwsim = Hwsim() + + cls.bss_hostapd = [ HostapdCLI(config='ft-eap-ccmp-1.conf'), + HostapdCLI(config='ft-eap-ccmp-2.conf') ] + cls.bss_radio = [ hwsim.get_radio('rad0'), + hwsim.get_radio('rad1') ] + + # Set interface addresses to those expected by hostapd config files + os.system('ifconfig "' + cls.bss_hostapd[0].ifname + + '" down hw ether 12:00:00:00:00:01 up') + os.system('ifconfig "' + cls.bss_hostapd[1].ifname + + '" down hw ether 12:00:00:00:00:02 up') + + cls.bss_hostapd[0].reload() + cls.bss_hostapd[1].reload() + + # Fill in the neighbor AP tables in both BSSes. By default each + # instance knows only about current BSS, even inside one hostapd + # process. + # FT still works without the neighbor AP table but neighbor reports + # have to be disabled in the .conf files + cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT', + '1200000000028f0000005102060603000000') + cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT', + '1200000000018f0000005101060603000000') + + @classmethod + def tearDownClass(cls): + IWD.clear_storage() + +if __name__ == '__main__': + unittest.main(exit=True) diff --git a/autotests/testFT-FILS-SHA384/test.py b/autotests/testFT-FILS-SHA384/test.py @@ -1,179 +0,0 @@ -#! /usr/bin/python3 - -import unittest -import sys, os - -sys.path.append('../util') -import iwd -from iwd import IWD -from iwd import PSKAgent -from iwd import NetworkType -from hwsim import Hwsim -from hostapd import HostapdCLI, hostapd_map -import testutil - -class Test(unittest.TestCase): - def test_roam_success(self): - hwsim = Hwsim() - - rule0 = hwsim.rules.create() - rule0.source = self.bss_radio[0].addresses[0] - rule0.bidirectional = True - - rule1 = hwsim.rules.create() - rule1.source = self.bss_radio[1].addresses[0] - rule1.bidirectional = True - - wd = IWD() - - psk_agent = PSKAgent('user@example.com', ('user@example.com', - 'secret123')) - wd.register_psk_agent(psk_agent) - - device = wd.list_devices(1)[0] - - # Check that iwd selects BSS 0 first - rule0.signal = -2000 - rule1.signal = -2500 - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - device.scan() - - condition = 'obj.scanning' - wd.wait_for_object_condition(device, condition) - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - ordered_network = device.get_ordered_network('TestFT') - - self.assertEqual(ordered_network.type, NetworkType.eap) - self.assertEqual(ordered_network.signal_strength, -2000) - - condition = 'not obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertFalse(self.bss_hostapd[0].list_sta()) - self.assertFalse(self.bss_hostapd[1].list_sta()) - - ordered_network.network_object.connect() - - condition = 'obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertTrue(self.bss_hostapd[0].list_sta()) - self.assertFalse(self.bss_hostapd[1].list_sta()) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[1].ifname, device.name)) - - device.disconnect() - - condition = 'not obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - ordered_network = device.get_ordered_network('TestFT') - - self.assertEqual(ordered_network.type, NetworkType.eap) - - condition = 'not obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - ordered_network.network_object.connect() - - condition = 'obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertTrue(self.bss_hostapd[0].list_sta()) - self.assertFalse(self.bss_hostapd[1].list_sta()) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[1].ifname, device.name)) - - # Check that iwd starts transition to BSS 1 in less than 10 seconds. - # The 10 seconds is longer than needed to scan on just two channels - # but short enough that a full scan on the 2.4 + 5.8 bands supported - # by mac80211_hwsim will not finish. If this times out then, but - # device_roam_trigger_cb has happened, it probably means that - # Neighbor Reports are broken. - rule0.signal = -8000 - - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 10) - - # Check that iwd is on BSS 1 once out of roaming state and doesn't - # go through 'disconnected', 'autoconnect', 'connecting' in between - condition = 'obj.state != DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 5) - - self.assertEqual(device.state, iwd.DeviceState.connected) - self.assertTrue(self.bss_hostapd[1].list_sta()) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[0].ifname, device.name)) - - def tearDown(self): - os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" down') - os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" down') - os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" up') - os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up') - - hwsim = Hwsim() - wd = IWD() - device = wd.list_devices(1)[0] - try: - device.disconnect() - except: - pass - - condition = 'obj.state == DeviceState.disconnected' - wd.wait_for_object_condition(device, condition) - - for rule in list(hwsim.rules.keys()): - del hwsim.rules[rule] - - @classmethod - def setUpClass(cls): - os.system('ifconfig lo up') - IWD.copy_to_storage('TestFT.8021x') - - hwsim = Hwsim() - - cls.bss_hostapd = [ HostapdCLI(config='ft-eap-ccmp-1.conf'), - HostapdCLI(config='ft-eap-ccmp-2.conf') ] - cls.bss_radio = [ hwsim.get_radio('rad0'), - hwsim.get_radio('rad1') ] - - # Set interface addresses to those expected by hostapd config files - os.system('ifconfig "' + cls.bss_hostapd[0].ifname + - '" down hw ether 12:00:00:00:00:01 up') - os.system('ifconfig "' + cls.bss_hostapd[1].ifname + - '" down hw ether 12:00:00:00:00:02 up') - - cls.bss_hostapd[0].reload() - cls.bss_hostapd[1].reload() - - # Fill in the neighbor AP tables in both BSSes. By default each - # instance knows only about current BSS, even inside one hostapd - # process. - # FT still works without the neighbor AP table but neighbor reports - # have to be disabled in the .conf files - cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT', - '1200000000028f0000005102060603000000') - cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT', - '1200000000018f0000005101060603000000') - - @classmethod - def tearDownClass(cls): - IWD.clear_storage() - -if __name__ == '__main__': - unittest.main(exit=True) diff --git a/autotests/testFT-PSK-over-DS/connection_test.py b/autotests/testFT-PSK-over-DS/connection_test.py @@ -0,0 +1,152 @@ +#! /usr/bin/python3 + +import unittest +import sys, os + +sys.path.append('../util') +import iwd +from iwd import IWD +from iwd import PSKAgent +from iwd import NetworkType +from hwsim import Hwsim +from hostapd import HostapdCLI +import testutil + +class Test(unittest.TestCase): + def test_roam_success(self): + hwsim = Hwsim() + + rule0 = hwsim.rules.create() + rule0.source = self.bss_radio[0].addresses[0] + rule0.bidirectional = True + + rule1 = hwsim.rules.create() + rule1.source = self.bss_radio[1].addresses[0] + rule1.bidirectional = True + + wd = IWD() + + psk_agent = PSKAgent("EasilyGuessedPassword") + wd.register_psk_agent(psk_agent) + + device = wd.list_devices(1)[0] + + # Check that iwd selects BSS 0 first + rule0.signal = -2000 + rule1.signal = -2500 + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + device.scan() + + condition = 'obj.scanning' + wd.wait_for_object_condition(device, condition) + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + ordered_network = device.get_ordered_network('TestFT') + + self.assertEqual(ordered_network.type, NetworkType.psk) + self.assertEqual(ordered_network.signal_strength, -2000) + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertFalse(self.bss_hostapd[0].list_sta()) + self.assertFalse(self.bss_hostapd[1].list_sta()) + + ordered_network.network_object.connect() + + condition = 'obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertTrue(self.bss_hostapd[0].list_sta()) + self.assertFalse(self.bss_hostapd[1].list_sta()) + + wd.unregister_psk_agent(psk_agent) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[1].ifname, device.name)) + + # Check that iwd starts transition to BSS 1 in less than 10 seconds. + # The 10 seconds is longer than needed to scan on just two channels + # but short enough that a full scan on the 2.4 + 5.8 bands supported + # by mac80211_hwsim will not finish. If this times out then, but + # device_roam_trigger_cb has happened, it probably means that + # Neighbor Reports are broken. + rule0.signal = -8000 + + condition = 'obj.state == DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 10) + + # Check that iwd is on BSS 1 once out of roaming state and doesn't + # go through 'disconnected', 'autoconnect', 'connecting' in between + condition = 'obj.state != DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 5) + + self.assertEqual(device.state, iwd.DeviceState.connected) + self.assertTrue(self.bss_hostapd[1].list_sta()) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[0].ifname, device.name)) + + def tearDown(self): + os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" down') + os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" down') + os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" up') + os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up') + + hwsim = Hwsim() + wd = IWD() + device = wd.list_devices(1)[0] + try: + device.disconnect() + except: + pass + + condition = 'obj.state == DeviceState.disconnected' + wd.wait_for_object_condition(device, condition) + + for rule in list(hwsim.rules.keys()): + del hwsim.rules[rule] + + @classmethod + def setUpClass(cls): + hwsim = Hwsim() + + cls.bss_hostapd = [ HostapdCLI(config='ft-psk-ccmp-1.conf'), + HostapdCLI(config='ft-psk-ccmp-2.conf') ] + cls.bss_radio = [ hwsim.get_radio('rad0'), + hwsim.get_radio('rad1') ] + + # Set interface addresses to those expected by hostapd config files + os.system('ifconfig "' + cls.bss_hostapd[0].ifname + + '" down hw ether 12:00:00:00:00:01 up') + os.system('ifconfig "' + cls.bss_hostapd[1].ifname + + '" down hw ether 12:00:00:00:00:02 up') + + cls.bss_hostapd[0].reload() + cls.bss_hostapd[1].reload() + + # Fill in the neighbor AP tables in both BSSes. By default each + # instance knows only about current BSS, even inside one hostapd + # process. + # FT still works without the neighbor AP table but neighbor reports + # have to be disabled in the .conf files + cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT', + '1200000000028f0000005102060603000000') + cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT', + '1200000000018f0000005101060603000000') + + @classmethod + def tearDownClass(cls): + IWD.clear_storage() + +if __name__ == '__main__': + unittest.main(exit=True) diff --git a/autotests/testFT-PSK-over-DS/test.py b/autotests/testFT-PSK-over-DS/test.py @@ -1,152 +0,0 @@ -#! /usr/bin/python3 - -import unittest -import sys, os - -sys.path.append('../util') -import iwd -from iwd import IWD -from iwd import PSKAgent -from iwd import NetworkType -from hwsim import Hwsim -from hostapd import HostapdCLI, hostapd_map -import testutil - -class Test(unittest.TestCase): - def test_roam_success(self): - hwsim = Hwsim() - - rule0 = hwsim.rules.create() - rule0.source = self.bss_radio[0].addresses[0] - rule0.bidirectional = True - - rule1 = hwsim.rules.create() - rule1.source = self.bss_radio[1].addresses[0] - rule1.bidirectional = True - - wd = IWD() - - psk_agent = PSKAgent("EasilyGuessedPassword") - wd.register_psk_agent(psk_agent) - - device = wd.list_devices(1)[0] - - # Check that iwd selects BSS 0 first - rule0.signal = -2000 - rule1.signal = -2500 - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - device.scan() - - condition = 'obj.scanning' - wd.wait_for_object_condition(device, condition) - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - ordered_network = device.get_ordered_network('TestFT') - - self.assertEqual(ordered_network.type, NetworkType.psk) - self.assertEqual(ordered_network.signal_strength, -2000) - - condition = 'not obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertFalse(self.bss_hostapd[0].list_sta()) - self.assertFalse(self.bss_hostapd[1].list_sta()) - - ordered_network.network_object.connect() - - condition = 'obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertTrue(self.bss_hostapd[0].list_sta()) - self.assertFalse(self.bss_hostapd[1].list_sta()) - - wd.unregister_psk_agent(psk_agent) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[1].ifname, device.name)) - - # Check that iwd starts transition to BSS 1 in less than 10 seconds. - # The 10 seconds is longer than needed to scan on just two channels - # but short enough that a full scan on the 2.4 + 5.8 bands supported - # by mac80211_hwsim will not finish. If this times out then, but - # device_roam_trigger_cb has happened, it probably means that - # Neighbor Reports are broken. - rule0.signal = -8000 - - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 10) - - # Check that iwd is on BSS 1 once out of roaming state and doesn't - # go through 'disconnected', 'autoconnect', 'connecting' in between - condition = 'obj.state != DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 5) - - self.assertEqual(device.state, iwd.DeviceState.connected) - self.assertTrue(self.bss_hostapd[1].list_sta()) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[0].ifname, device.name)) - - def tearDown(self): - os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" down') - os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" down') - os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" up') - os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up') - - hwsim = Hwsim() - wd = IWD() - device = wd.list_devices(1)[0] - try: - device.disconnect() - except: - pass - - condition = 'obj.state == DeviceState.disconnected' - wd.wait_for_object_condition(device, condition) - - for rule in list(hwsim.rules.keys()): - del hwsim.rules[rule] - - @classmethod - def setUpClass(cls): - hwsim = Hwsim() - - cls.bss_hostapd = [ HostapdCLI(config='ft-psk-ccmp-1.conf'), - HostapdCLI(config='ft-psk-ccmp-2.conf') ] - cls.bss_radio = [ hwsim.get_radio('rad0'), - hwsim.get_radio('rad1') ] - - # Set interface addresses to those expected by hostapd config files - os.system('ifconfig "' + cls.bss_hostapd[0].ifname + - '" down hw ether 12:00:00:00:00:01 up') - os.system('ifconfig "' + cls.bss_hostapd[1].ifname + - '" down hw ether 12:00:00:00:00:02 up') - - cls.bss_hostapd[0].reload() - cls.bss_hostapd[1].reload() - - # Fill in the neighbor AP tables in both BSSes. By default each - # instance knows only about current BSS, even inside one hostapd - # process. - # FT still works without the neighbor AP table but neighbor reports - # have to be disabled in the .conf files - cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT', - '1200000000028f0000005102060603000000') - cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT', - '1200000000018f0000005101060603000000') - - @classmethod - def tearDownClass(cls): - IWD.clear_storage() - -if __name__ == '__main__': - unittest.main(exit=True) diff --git a/autotests/testFT-PSK-roam/connection_test.py b/autotests/testFT-PSK-roam/connection_test.py @@ -0,0 +1,238 @@ +#! /usr/bin/python3 + +import unittest +import sys, os + +sys.path.append('../util') +import iwd +from iwd import IWD +from iwd import PSKAgent +from iwd import NetworkType +from hwsim import Hwsim +from hostapd import HostapdCLI +import testutil + +class Test(unittest.TestCase): + def test_roam_success(self): + hwsim = Hwsim() + + rule0 = hwsim.rules.create() + rule0.source = self.bss_radio[0].addresses[0] + rule0.bidirectional = True + + rule1 = hwsim.rules.create() + rule1.source = self.bss_radio[1].addresses[0] + rule1.bidirectional = True + + wd = self.wd + + psk_agent = PSKAgent("EasilyGuessedPassword") + wd.register_psk_agent(psk_agent) + + device = wd.list_devices(1)[0] + # prevent autoconnect + device.disconnect() + + # Check that iwd selects BSS 0 first + rule0.signal = -2000 + rule1.signal = -2500 + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + device.scan() + + condition = 'obj.scanning' + wd.wait_for_object_condition(device, condition) + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + ordered_network = device.get_ordered_network('TestFT') + + self.assertEqual(ordered_network.type, NetworkType.psk) + self.assertEqual(ordered_network.signal_strength, -2000) + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertFalse(self.bss_hostapd[0].list_sta()) + self.assertFalse(self.bss_hostapd[1].list_sta()) + + ordered_network.network_object.connect() + + condition = 'obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertTrue(self.bss_hostapd[0].list_sta()) + self.assertFalse(self.bss_hostapd[1].list_sta()) + + wd.unregister_psk_agent(psk_agent) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[1].ifname, device.name)) + + # Check that iwd starts transition to BSS 1 in less than 10 seconds. + # The 10 seconds is longer than needed to scan on just two channels + # but short enough that a full scan on the 2.4 + 5.8 bands supported + # by mac80211_hwsim will not finish. If this times out then, but + # device_roam_trigger_cb has happened, it probably means that + # Neighbor Reports are broken. + rule0.signal = -8000 + + condition = 'obj.state == DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 10) + + # Check that iwd is on BSS 1 once out of roaming state and doesn't + # go through 'disconnected', 'autoconnect', 'connecting' in between + condition = 'obj.state != DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 5) + + self.assertEqual(device.state, iwd.DeviceState.connected) + self.assertTrue(self.bss_hostapd[1].list_sta()) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[0].ifname, device.name)) + + def test_roam_on_beacon_loss(self): + hwsim = Hwsim() + + rule0 = hwsim.rules.create() + rule0.source = self.bss_radio[0].addresses[0] + rule0.bidirectional = True + + rule1 = hwsim.rules.create() + rule1.source = self.bss_radio[1].addresses[0] + rule1.bidirectional = True + + wd = self.wd + + psk_agent = PSKAgent("EasilyGuessedPassword") + wd.register_psk_agent(psk_agent) + + device = wd.list_devices(1)[0] + # prevent autoconnect + device.disconnect() + + # Check that iwd selects BSS 0 first + rule0.signal = -2000 + rule1.signal = -2500 + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + device.scan() + + condition = 'obj.scanning' + wd.wait_for_object_condition(device, condition) + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + ordered_network = device.get_ordered_network("TestFT") + self.assertEqual(ordered_network.type, NetworkType.psk) + self.assertEqual(ordered_network.signal_strength, -2000) + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertFalse(self.bss_hostapd[0].list_sta()) + self.assertFalse(self.bss_hostapd[1].list_sta()) + + ordered_network.network_object.connect() + + condition = 'obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertTrue(self.bss_hostapd[0].list_sta()) + self.assertFalse(self.bss_hostapd[1].list_sta()) + + wd.unregister_psk_agent(psk_agent) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[1].ifname, device.name)) + + # Check that iwd starts transition to BSS 1 in less than 20 seconds + # from a beacon loss event + rule0.drop = True + rule0.signal = -3000 + wd.wait(2) + rule0.drop = False + + condition = 'obj.state == DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 20) + + # Check that iwd is on BSS 1 once out of roaming state and doesn't + # go through 'disconnected', 'autoconnect', 'connecting' in between + condition = 'obj.state != DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 5) + + self.assertEqual(device.state, iwd.DeviceState.connected) + self.assertTrue(self.bss_hostapd[1].list_sta()) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[0].ifname, device.name)) + def setUp(self): + self.wd = IWD() + + def tearDown(self): + os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" down') + os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" down') + os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" up') + os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up') + + hwsim = Hwsim() + device = self.wd.list_devices(1)[0] + try: + device.disconnect() + except: + pass + + condition = 'obj.state == DeviceState.disconnected' + self.wd.wait_for_object_condition(device, condition) + + for rule in list(hwsim.rules.keys()): + del hwsim.rules[rule] + + @classmethod + def setUpClass(cls): + hwsim = Hwsim() + + cls.bss_hostapd = [ HostapdCLI(config='ft-psk-ccmp-1.conf'), + HostapdCLI(config='ft-psk-ccmp-2.conf') ] + cls.bss_radio = [ hwsim.get_radio('rad0'), + hwsim.get_radio('rad1') ] + + # Set interface addresses to those expected by hostapd config files + os.system('ifconfig "' + cls.bss_hostapd[0].ifname + + '" down hw ether 12:00:00:00:00:01 up') + os.system('ifconfig "' + cls.bss_hostapd[1].ifname + + '" down hw ether 12:00:00:00:00:02 up') + + cls.bss_hostapd[0].reload() + cls.bss_hostapd[1].reload() + + # Fill in the neighbor AP tables in both BSSes. By default each + # instance knows only about current BSS, even inside one hostapd + # process. + # FT still works without the neighbor AP table but neighbor reports + # have to be disabled in the .conf files + cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT', + '1200000000028f0000005102060603000000') + cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT', + '1200000000018f0000005101060603000000') + + @classmethod + def tearDownClass(cls): + IWD.clear_storage() + +if __name__ == '__main__': + unittest.main(exit=True) diff --git a/autotests/testFT-PSK-roam/test.py b/autotests/testFT-PSK-roam/test.py @@ -1,233 +0,0 @@ -#! /usr/bin/python3 - -import unittest -import sys, os - -sys.path.append('../util') -import iwd -from iwd import IWD -from iwd import PSKAgent -from iwd import NetworkType -from hwsim import Hwsim -from hostapd import HostapdCLI, hostapd_map -import testutil - -class Test(unittest.TestCase): - def test_roam_success(self): - hwsim = Hwsim() - - rule0 = hwsim.rules.create() - rule0.source = self.bss_radio[0].addresses[0] - rule0.bidirectional = True - - rule1 = hwsim.rules.create() - rule1.source = self.bss_radio[1].addresses[0] - rule1.bidirectional = True - - wd = IWD() - - psk_agent = PSKAgent("EasilyGuessedPassword") - wd.register_psk_agent(psk_agent) - - device = wd.list_devices(1)[0] - - # Check that iwd selects BSS 0 first - rule0.signal = -2000 - rule1.signal = -2500 - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - device.scan() - - condition = 'obj.scanning' - wd.wait_for_object_condition(device, condition) - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - ordered_network = device.get_ordered_network('TestFT') - - self.assertEqual(ordered_network.type, NetworkType.psk) - self.assertEqual(ordered_network.signal_strength, -2000) - - condition = 'not obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertFalse(self.bss_hostapd[0].list_sta()) - self.assertFalse(self.bss_hostapd[1].list_sta()) - - ordered_network.network_object.connect() - - condition = 'obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertTrue(self.bss_hostapd[0].list_sta()) - self.assertFalse(self.bss_hostapd[1].list_sta()) - - wd.unregister_psk_agent(psk_agent) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[1].ifname, device.name)) - - # Check that iwd starts transition to BSS 1 in less than 10 seconds. - # The 10 seconds is longer than needed to scan on just two channels - # but short enough that a full scan on the 2.4 + 5.8 bands supported - # by mac80211_hwsim will not finish. If this times out then, but - # device_roam_trigger_cb has happened, it probably means that - # Neighbor Reports are broken. - rule0.signal = -8000 - - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 10) - - # Check that iwd is on BSS 1 once out of roaming state and doesn't - # go through 'disconnected', 'autoconnect', 'connecting' in between - condition = 'obj.state != DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 5) - - self.assertEqual(device.state, iwd.DeviceState.connected) - self.assertTrue(self.bss_hostapd[1].list_sta()) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[0].ifname, device.name)) - - def test_roam_on_beacon_loss(self): - hwsim = Hwsim() - - rule0 = hwsim.rules.create() - rule0.source = self.bss_radio[0].addresses[0] - rule0.bidirectional = True - - rule1 = hwsim.rules.create() - rule1.source = self.bss_radio[1].addresses[0] - rule1.bidirectional = True - - wd = IWD() - - psk_agent = PSKAgent("EasilyGuessedPassword") - wd.register_psk_agent(psk_agent) - - device = wd.list_devices(1)[0] - - # Check that iwd selects BSS 0 first - rule0.signal = -2000 - rule1.signal = -2500 - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - device.scan() - - condition = 'obj.scanning' - wd.wait_for_object_condition(device, condition) - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - ordered_network = device.get_ordered_network("TestFT") - self.assertEqual(ordered_network.type, NetworkType.psk) - self.assertEqual(ordered_network.signal_strength, -2000) - - condition = 'not obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertFalse(self.bss_hostapd[0].list_sta()) - self.assertFalse(self.bss_hostapd[1].list_sta()) - - ordered_network.network_object.connect() - - condition = 'obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertTrue(self.bss_hostapd[0].list_sta()) - self.assertFalse(self.bss_hostapd[1].list_sta()) - - wd.unregister_psk_agent(psk_agent) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[1].ifname, device.name)) - - # Check that iwd starts transition to BSS 1 in less than 20 seconds - # from a beacon loss event - rule0.drop = True - rule0.signal = -3000 - wd.wait(2) - rule0.drop = False - - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 20) - - # Check that iwd is on BSS 1 once out of roaming state and doesn't - # go through 'disconnected', 'autoconnect', 'connecting' in between - condition = 'obj.state != DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 5) - - self.assertEqual(device.state, iwd.DeviceState.connected) - self.assertTrue(self.bss_hostapd[1].list_sta()) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[0].ifname, device.name)) - - def tearDown(self): - os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" down') - os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" down') - os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" up') - os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up') - - hwsim = Hwsim() - wd = IWD() - device = wd.list_devices(1)[0] - try: - device.disconnect() - except: - pass - - condition = 'obj.state == DeviceState.disconnected' - wd.wait_for_object_condition(device, condition) - - for rule in list(hwsim.rules.keys()): - del hwsim.rules[rule] - - @classmethod - def setUpClass(cls): - hwsim = Hwsim() - - cls.bss_hostapd = [ HostapdCLI(config='ft-psk-ccmp-1.conf'), - HostapdCLI(config='ft-psk-ccmp-2.conf') ] - cls.bss_radio = [ hwsim.get_radio('rad0'), - hwsim.get_radio('rad1') ] - - # Set interface addresses to those expected by hostapd config files - os.system('ifconfig "' + cls.bss_hostapd[0].ifname + - '" down hw ether 12:00:00:00:00:01 up') - os.system('ifconfig "' + cls.bss_hostapd[1].ifname + - '" down hw ether 12:00:00:00:00:02 up') - - cls.bss_hostapd[0].reload() - cls.bss_hostapd[1].reload() - - # Fill in the neighbor AP tables in both BSSes. By default each - # instance knows only about current BSS, even inside one hostapd - # process. - # FT still works without the neighbor AP table but neighbor reports - # have to be disabled in the .conf files - cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT', - '1200000000028f0000005102060603000000') - cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT', - '1200000000018f0000005101060603000000') - - @classmethod - def tearDownClass(cls): - IWD.clear_storage() - -if __name__ == '__main__': - unittest.main(exit=True) diff --git a/autotests/testFT-SAE-roam/connection_test.py b/autotests/testFT-SAE-roam/connection_test.py @@ -0,0 +1,198 @@ +#! /usr/bin/python3 + +import unittest +import sys, os + +sys.path.append('../util') +import iwd +from iwd import IWD +from iwd import PSKAgent +from iwd import NetworkType +from hwsim import Hwsim +from hostapd import HostapdCLI +import testutil + +class Test(unittest.TestCase): + def test_roam_success(self): + hwsim = Hwsim() + + rule0 = hwsim.rules.create() + rule0.source = self.bss_radio[0].addresses[0] + rule0.bidirectional = True + + rule1 = hwsim.rules.create() + rule1.source = self.bss_radio[1].addresses[0] + rule1.bidirectional = True + + rule2 = hwsim.rules.create() + rule2.source = self.bss_radio[2].addresses[0] + rule2.bidirectional = True + + wd = IWD() + + psk_agent = PSKAgent("EasilyGuessedPassword") + wd.register_psk_agent(psk_agent) + + device = wd.list_devices(1)[0] + + # Check that iwd selects BSS 0 first + rule0.signal = -2000 + rule1.signal = -2500 + rule2.signal = -3000 + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + device.scan() + + condition = 'obj.scanning' + wd.wait_for_object_condition(device, condition) + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + ordered_network = device.get_ordered_network('TestFT') + + self.assertEqual(ordered_network.type, NetworkType.psk) + self.assertEqual(ordered_network.signal_strength, -2000) + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertFalse(self.bss_hostapd[0].list_sta()) + self.assertFalse(self.bss_hostapd[1].list_sta()) + + ordered_network.network_object.connect() + + condition = 'obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertTrue(self.bss_hostapd[0].list_sta()) + self.assertFalse(self.bss_hostapd[1].list_sta()) + + wd.unregister_psk_agent(psk_agent) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[1].ifname, device.name)) + + # Check that iwd starts transition to BSS 1 in less than 10 seconds. + # The 10 seconds is longer than needed to scan on just two channels + # but short enough that a full scan on the 2.4 + 5.8 bands supported + # by mac80211_hwsim will not finish. If this times out then, but + # device_roam_trigger_cb has happened, it probably means that + # Neighbor Reports are broken. + rule0.signal = -8000 + + condition = 'obj.state == DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 10) + + # Check that iwd is on BSS 1 once out of roaming state and doesn't + # go through 'disconnected', 'autoconnect', 'connecting' in between + condition = 'obj.state != DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 5) + + rule1.signal = -2000 + + # wait for IWD's signal levels to recover + wd.wait(5) + + self.assertEqual(device.state, iwd.DeviceState.connected) + self.assertTrue(self.bss_hostapd[1].list_sta()) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[0].ifname, device.name)) + + # test FT-PSK after FT-SAE + rule1.signal = -8000 + rule0.signal = -8000 + rule2.signal = -1000 + + condition = 'obj.state == DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 15) + + condition = 'obj.state != DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 5) + + self.assertEqual(device.state, iwd.DeviceState.connected) + self.assertTrue(self.bss_hostapd[2].list_sta()) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(self.bss_hostapd[2].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (self.bss_hostapd[1].ifname, device.name)) + + def tearDown(self): + os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" down') + os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" down') + os.system('ifconfig "' + self.bss_hostapd[2].ifname + '" down') + os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" up') + os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up') + os.system('ifconfig "' + self.bss_hostapd[2].ifname + '" up') + + hwsim = Hwsim() + wd = IWD() + device = wd.list_devices(1)[0] + try: + device.disconnect() + except: + pass + + condition = 'obj.state == DeviceState.disconnected' + wd.wait_for_object_condition(device, condition) + + for rule in list(hwsim.rules.keys()): + del hwsim.rules[rule] + + @classmethod + def setUpClass(cls): + hwsim = Hwsim() + + cls.bss_hostapd = [ HostapdCLI(config='ft-sae-1.conf'), + HostapdCLI(config='ft-sae-2.conf'), + HostapdCLI(config='ft-psk-3.conf') ] + cls.bss_radio = [ hwsim.get_radio('rad0'), + hwsim.get_radio('rad1'), + hwsim.get_radio('rad2') ] + + # Set interface addresses to those expected by hostapd config files + os.system('ifconfig "' + cls.bss_hostapd[0].ifname + + '" down hw ether 12:00:00:00:00:01 up') + os.system('ifconfig "' + cls.bss_hostapd[1].ifname + + '" down hw ether 12:00:00:00:00:02 up') + os.system('ifconfig "' + cls.bss_hostapd[2].ifname + + '" down hw ether 12:00:00:00:00:03 up') + + cls.bss_hostapd[0].reload() + cls.bss_hostapd[1].reload() + cls.bss_hostapd[2].reload() + + # Fill in the neighbor AP tables in both BSSes. By default each + # instance knows only about current BSS, even inside one hostapd + # process. + # FT still works without the neighbor AP table but neighbor reports + # have to be disabled in the .conf files + cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT', + '1200000000028f0000005102060603000000') + cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:03', 'TestFT', + '1200000000038f0000005102060603000000') + + cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT', + '1200000000018f0000005101060603000000') + cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:03', 'TestFT', + '1200000000038f0000005101060603000000') + + cls.bss_hostapd[2].set_neighbor('12:00:00:00:00:01', 'TestFT', + '1200000000018f0000005101060603000000') + cls.bss_hostapd[2].set_neighbor('12:00:00:00:00:02', 'TestFT', + '1200000000028f0000005101060603000000') + + @classmethod + def tearDownClass(cls): + IWD.clear_storage() + +if __name__ == '__main__': + unittest.main(exit=True) diff --git a/autotests/testFT-SAE-roam/test.py b/autotests/testFT-SAE-roam/test.py @@ -1,198 +0,0 @@ -#! /usr/bin/python3 - -import unittest -import sys, os - -sys.path.append('../util') -import iwd -from iwd import IWD -from iwd import PSKAgent -from iwd import NetworkType -from hwsim import Hwsim -from hostapd import HostapdCLI, hostapd_map -import testutil - -class Test(unittest.TestCase): - def test_roam_success(self): - hwsim = Hwsim() - - rule0 = hwsim.rules.create() - rule0.source = self.bss_radio[0].addresses[0] - rule0.bidirectional = True - - rule1 = hwsim.rules.create() - rule1.source = self.bss_radio[1].addresses[0] - rule1.bidirectional = True - - rule2 = hwsim.rules.create() - rule2.source = self.bss_radio[2].addresses[0] - rule2.bidirectional = True - - wd = IWD() - - psk_agent = PSKAgent("EasilyGuessedPassword") - wd.register_psk_agent(psk_agent) - - device = wd.list_devices(1)[0] - - # Check that iwd selects BSS 0 first - rule0.signal = -2000 - rule1.signal = -2500 - rule2.signal = -3000 - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - device.scan() - - condition = 'obj.scanning' - wd.wait_for_object_condition(device, condition) - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - ordered_network = device.get_ordered_network('TestFT') - - self.assertEqual(ordered_network.type, NetworkType.psk) - self.assertEqual(ordered_network.signal_strength, -2000) - - condition = 'not obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertFalse(self.bss_hostapd[0].list_sta()) - self.assertFalse(self.bss_hostapd[1].list_sta()) - - ordered_network.network_object.connect() - - condition = 'obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertTrue(self.bss_hostapd[0].list_sta()) - self.assertFalse(self.bss_hostapd[1].list_sta()) - - wd.unregister_psk_agent(psk_agent) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[1].ifname, device.name)) - - # Check that iwd starts transition to BSS 1 in less than 10 seconds. - # The 10 seconds is longer than needed to scan on just two channels - # but short enough that a full scan on the 2.4 + 5.8 bands supported - # by mac80211_hwsim will not finish. If this times out then, but - # device_roam_trigger_cb has happened, it probably means that - # Neighbor Reports are broken. - rule0.signal = -8000 - - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 10) - - # Check that iwd is on BSS 1 once out of roaming state and doesn't - # go through 'disconnected', 'autoconnect', 'connecting' in between - condition = 'obj.state != DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 5) - - rule1.signal = -2000 - - # wait for IWD's signal levels to recover - wd.wait(5) - - self.assertEqual(device.state, iwd.DeviceState.connected) - self.assertTrue(self.bss_hostapd[1].list_sta()) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[0].ifname, device.name)) - - # test FT-PSK after FT-SAE - rule1.signal = -8000 - rule0.signal = -8000 - rule2.signal = -1000 - - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 15) - - condition = 'obj.state != DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 5) - - self.assertEqual(device.state, iwd.DeviceState.connected) - self.assertTrue(self.bss_hostapd[2].list_sta()) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(self.bss_hostapd[2].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (self.bss_hostapd[1].ifname, device.name)) - - def tearDown(self): - os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" down') - os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" down') - os.system('ifconfig "' + self.bss_hostapd[2].ifname + '" down') - os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" up') - os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up') - os.system('ifconfig "' + self.bss_hostapd[2].ifname + '" up') - - hwsim = Hwsim() - wd = IWD() - device = wd.list_devices(1)[0] - try: - device.disconnect() - except: - pass - - condition = 'obj.state == DeviceState.disconnected' - wd.wait_for_object_condition(device, condition) - - for rule in list(hwsim.rules.keys()): - del hwsim.rules[rule] - - @classmethod - def setUpClass(cls): - hwsim = Hwsim() - - cls.bss_hostapd = [ HostapdCLI(config='ft-sae-1.conf'), - HostapdCLI(config='ft-sae-2.conf'), - HostapdCLI(config='ft-psk-3.conf') ] - cls.bss_radio = [ hwsim.get_radio('rad0'), - hwsim.get_radio('rad1'), - hwsim.get_radio('rad2') ] - - # Set interface addresses to those expected by hostapd config files - os.system('ifconfig "' + cls.bss_hostapd[0].ifname + - '" down hw ether 12:00:00:00:00:01 up') - os.system('ifconfig "' + cls.bss_hostapd[1].ifname + - '" down hw ether 12:00:00:00:00:02 up') - os.system('ifconfig "' + cls.bss_hostapd[2].ifname + - '" down hw ether 12:00:00:00:00:03 up') - - cls.bss_hostapd[0].reload() - cls.bss_hostapd[1].reload() - cls.bss_hostapd[2].reload() - - # Fill in the neighbor AP tables in both BSSes. By default each - # instance knows only about current BSS, even inside one hostapd - # process. - # FT still works without the neighbor AP table but neighbor reports - # have to be disabled in the .conf files - cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT', - '1200000000028f0000005102060603000000') - cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:03', 'TestFT', - '1200000000038f0000005102060603000000') - - cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT', - '1200000000018f0000005101060603000000') - cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:03', 'TestFT', - '1200000000038f0000005101060603000000') - - cls.bss_hostapd[2].set_neighbor('12:00:00:00:00:01', 'TestFT', - '1200000000018f0000005101060603000000') - cls.bss_hostapd[2].set_neighbor('12:00:00:00:00:02', 'TestFT', - '1200000000028f0000005101060603000000') - - @classmethod - def tearDownClass(cls): - IWD.clear_storage() - -if __name__ == '__main__': - unittest.main(exit=True) diff --git a/autotests/testHT-VHT/connection_test.py b/autotests/testHT-VHT/connection_test.py @@ -0,0 +1,109 @@ +#! /usr/bin/python3 + +import unittest +import sys + +sys.path.append('../util') +import iwd +from iwd import IWD +from iwd import PSKAgent +from iwd import NetworkType +from hwsim import Hwsim +import testutil +from time import sleep +from hostapd import HostapdCLI + +class Test(unittest.TestCase): + def do_connect(self, wd, device, hostapd): + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + device.scan() + + condition = 'obj.scanning' + wd.wait_for_object_condition(device, condition) + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + ordered_network = device.get_ordered_network('testSSID') + + self.assertEqual(ordered_network.type, NetworkType.psk) + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + ordered_network.network_object.connect() + + condition = 'obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + sleep(1) + + testutil.test_iface_operstate() + testutil.test_ifaces_connected(device.name, hostapd.ifname) + + device.disconnect() + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + def test_connection_success(self): + hwsim = Hwsim() + non_ht_hostapd = HostapdCLI(config='non-ht-vht.conf') + ht_hostapd = HostapdCLI(config='ht.conf') + vht_hostapd = HostapdCLI(config='vht.conf') + non_ht_radio = hwsim.get_radio('rad0') + ht_radio = hwsim.get_radio('rad1') + vht_radio = hwsim.get_radio('rad2') + + self.assertIsNotNone(non_ht_hostapd) + self.assertIsNotNone(ht_hostapd) + self.assertIsNotNone(vht_hostapd) + + rule0 = hwsim.rules.create() + rule0.source = vht_radio.addresses[0] + rule0.bidirectional = True + rule0.signal = -2000 + + rule1 = hwsim.rules.create() + rule1.source = ht_radio.addresses[0] + rule1.bidirectional = True + rule1.signal = -2000 + + rule2 = hwsim.rules.create() + rule2.source = non_ht_radio.addresses[0] + rule2.bidirectional = True + rule2.signal = -2000 + + wd = IWD() + + psk_agent = PSKAgent("secret123") + wd.register_psk_agent(psk_agent) + + device = wd.list_devices(1)[0] + + self.do_connect(wd, device, vht_hostapd) + + # lower VHT BSS signal, HT should now be preferred + rule0.signal = -6000 + + self.do_connect(wd, device, ht_hostapd) + + # lower HT BSS signal, basic rate BSS should now be preferred + rule1.signal = -6000 + + self.do_connect(wd, device, non_ht_hostapd) + + wd.unregister_psk_agent(psk_agent) + + @classmethod + def setUpClass(cls): + pass + + @classmethod + def tearDownClass(cls): + IWD.clear_storage() + +if __name__ == '__main__': + unittest.main(exit=True) diff --git a/autotests/testHT-VHT/test.py b/autotests/testHT-VHT/test.py @@ -1,109 +0,0 @@ -#! /usr/bin/python3 - -import unittest -import sys - -sys.path.append('../util') -import iwd -from iwd import IWD -from iwd import PSKAgent -from iwd import NetworkType -from hwsim import Hwsim -from hostapd import HostapdCLI, hostapd_map -import testutil -from time import sleep - -class Test(unittest.TestCase): - def do_connect(self, wd, device, hostapd): - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - device.scan() - - condition = 'obj.scanning' - wd.wait_for_object_condition(device, condition) - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - ordered_network = device.get_ordered_network('testSSID') - - self.assertEqual(ordered_network.type, NetworkType.psk) - - condition = 'not obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - ordered_network.network_object.connect() - - condition = 'obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - sleep(1) - - testutil.test_iface_operstate() - testutil.test_ifaces_connected(device.name, hostapd.ifname) - - device.disconnect() - - condition = 'not obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - def test_connection_success(self): - hwsim = Hwsim() - non_ht_hostapd = HostapdCLI(config='non-ht-vht.conf') - ht_hostapd = HostapdCLI(config='ht.conf') - vht_hostapd = HostapdCLI(config='vht.conf') - non_ht_radio = hwsim.get_radio('rad0') - ht_radio = hwsim.get_radio('rad1') - vht_radio = hwsim.get_radio('rad2') - - self.assertIsNotNone(non_ht_hostapd) - self.assertIsNotNone(ht_hostapd) - self.assertIsNotNone(vht_hostapd) - - rule0 = hwsim.rules.create() - rule0.source = vht_radio.addresses[0] - rule0.bidirectional = True - rule0.signal = -2000 - - rule1 = hwsim.rules.create() - rule1.source = ht_radio.addresses[0] - rule1.bidirectional = True - rule1.signal = -2000 - - rule2 = hwsim.rules.create() - rule2.source = non_ht_radio.addresses[0] - rule2.bidirectional = True - rule2.signal = -2000 - - wd = IWD() - - psk_agent = PSKAgent("secret123") - wd.register_psk_agent(psk_agent) - - device = wd.list_devices(1)[0] - - self.do_connect(wd, device, vht_hostapd) - - # lower VHT BSS signal, HT should now be preferred - rule0.signal = -6000 - - self.do_connect(wd, device, ht_hostapd) - - # lower HT BSS signal, basic rate BSS should now be preferred - rule1.signal = -6000 - - self.do_connect(wd, device, non_ht_hostapd) - - wd.unregister_psk_agent(psk_agent) - - @classmethod - def setUpClass(cls): - pass - - @classmethod - def tearDownClass(cls): - IWD.clear_storage() - -if __name__ == '__main__': - unittest.main(exit=True) diff --git a/autotests/testOWE/connection_test.py b/autotests/testOWE/connection_test.py @@ -7,7 +7,6 @@ sys.path.append('../util') import iwd from iwd import IWD from iwd import NetworkType -from hostapd import hostapd_map from hostapd import HostapdCLI import testutil diff --git a/autotests/testOWE/renegotiate_test.py b/autotests/testOWE/renegotiate_test.py @@ -7,7 +7,6 @@ sys.path.append('../util') import iwd from iwd import IWD from iwd import NetworkType -from hostapd import hostapd_map from hostapd import HostapdCLI import testutil diff --git a/autotests/testPreauth-roam/connection_test.py b/autotests/testPreauth-roam/connection_test.py @@ -0,0 +1,127 @@ +#! /usr/bin/python3 + +import unittest +import sys, os + +sys.path.append('../util') +import iwd +from iwd import IWD +from iwd import PSKAgent +from iwd import NetworkType +from hwsim import Hwsim +from hostapd import HostapdCLI +import testutil + +class Test(unittest.TestCase): + def test_preauth_success(self): + hwsim = Hwsim() + + bss_hostapd = [ HostapdCLI(config='eaptls-preauth-1.conf'), + HostapdCLI(config='eaptls-preauth-2.conf') ] + bss_radio = [ hwsim.get_radio('rad0'), + hwsim.get_radio('rad1') ] + + rule0 = hwsim.rules.create() + rule0.source = bss_radio[0].addresses[0] + rule0.bidirectional = True + + rule1 = hwsim.rules.create() + rule1.source = bss_radio[1].addresses[0] + rule1.bidirectional = True + + # Fill in the neighbor AP tables in both BSSes. By default each + # instance knows only about current BSS, even inside one hostapd + # process. + # Roaming still works without the neighbor AP table but neighbor + # reports have to be disabled in the .conf files + bss0_nr = ''.join(bss_radio[0].addresses[0].split(':')) + \ + '8f0000005101060603000000' + bss1_nr = ''.join(bss_radio[1].addresses[0].split(':')) + \ + '8f0000005102060603000000' + + bss_hostapd[0].set_neighbor(bss_radio[1].addresses[0], 'TestPreauth', + bss1_nr) + bss_hostapd[1].set_neighbor(bss_radio[0].addresses[0], 'TestPreauth', + bss0_nr) + + wd = IWD() + + device = wd.list_devices(1)[0] + + # Check that iwd selects BSS 0 first + rule0.signal = -2500 + rule1.signal = -3500 + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + device.scan() + + condition = 'obj.scanning' + wd.wait_for_object_condition(device, condition) + + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + ordered_network = device.get_ordered_network('TestPreauth') + + self.assertEqual(ordered_network.type, NetworkType.eap) + self.assertEqual(ordered_network.signal_strength, -2500) + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertFalse(bss_hostapd[0].list_sta()) + self.assertFalse(bss_hostapd[1].list_sta()) + + ordered_network.network_object.connect() + + condition = 'obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + self.assertTrue(bss_hostapd[0].list_sta()) + self.assertFalse(bss_hostapd[1].list_sta()) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(bss_hostapd[0].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + bss_hostapd[1].ifname, device.name) + + # Check that iwd starts transition to BSS 1 in less than 15 seconds + rule0.signal = -8000 + + condition = 'obj.state == DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 15) + + # TODO: verify that the PMK from preauthentication was used + + # Check that iwd is on BSS 1 once out of roaming state and doesn't + # go through 'disconnected', 'autoconnect', 'connecting' in between + condition = 'obj.state != DeviceState.roaming' + wd.wait_for_object_condition(device, condition, 5) + + self.assertEqual(device.state, iwd.DeviceState.connected) + self.assertTrue(bss_hostapd[1].list_sta()) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(bss_hostapd[1].ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (bss_hostapd[0].ifname, device.name)) + + device.disconnect() + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + @classmethod + def setUpClass(cls): + IWD.copy_to_storage('TestPreauth.8021x') + + os.system('ifconfig lo up') + + @classmethod + def tearDownClass(cls): + IWD.clear_storage() + +if __name__ == '__main__': + unittest.main(exit=True) diff --git a/autotests/testPreauth-roam/test.py b/autotests/testPreauth-roam/test.py @@ -1,127 +0,0 @@ -#! /usr/bin/python3 - -import unittest -import sys, os - -sys.path.append('../util') -import iwd -from iwd import IWD -from iwd import PSKAgent -from iwd import NetworkType -from hwsim import Hwsim -from hostapd import HostapdCLI, hostapd_map -import testutil - -class Test(unittest.TestCase): - def test_preauth_success(self): - hwsim = Hwsim() - - bss_hostapd = [ HostapdCLI(config='eaptls-preauth-1.conf'), - HostapdCLI(config='eaptls-preauth-2.conf') ] - bss_radio = [ hwsim.get_radio('rad0'), - hwsim.get_radio('rad1') ] - - rule0 = hwsim.rules.create() - rule0.source = bss_radio[0].addresses[0] - rule0.bidirectional = True - - rule1 = hwsim.rules.create() - rule1.source = bss_radio[1].addresses[0] - rule1.bidirectional = True - - # Fill in the neighbor AP tables in both BSSes. By default each - # instance knows only about current BSS, even inside one hostapd - # process. - # Roaming still works without the neighbor AP table but neighbor - # reports have to be disabled in the .conf files - bss0_nr = ''.join(bss_radio[0].addresses[0].split(':')) + \ - '8f0000005101060603000000' - bss1_nr = ''.join(bss_radio[1].addresses[0].split(':')) + \ - '8f0000005102060603000000' - - bss_hostapd[0].set_neighbor(bss_radio[1].addresses[0], 'TestPreauth', - bss1_nr) - bss_hostapd[1].set_neighbor(bss_radio[0].addresses[0], 'TestPreauth', - bss0_nr) - - wd = IWD() - - device = wd.list_devices(1)[0] - - # Check that iwd selects BSS 0 first - rule0.signal = -2500 - rule1.signal = -3500 - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - device.scan() - - condition = 'obj.scanning' - wd.wait_for_object_condition(device, condition) - - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) - - ordered_network = device.get_ordered_network('TestPreauth') - - self.assertEqual(ordered_network.type, NetworkType.eap) - self.assertEqual(ordered_network.signal_strength, -2500) - - condition = 'not obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertFalse(bss_hostapd[0].list_sta()) - self.assertFalse(bss_hostapd[1].list_sta()) - - ordered_network.network_object.connect() - - condition = 'obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - self.assertTrue(bss_hostapd[0].list_sta()) - self.assertFalse(bss_hostapd[1].list_sta()) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(bss_hostapd[0].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - bss_hostapd[1].ifname, device.name) - - # Check that iwd starts transition to BSS 1 in less than 15 seconds - rule0.signal = -8000 - - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 15) - - # TODO: verify that the PMK from preauthentication was used - - # Check that iwd is on BSS 1 once out of roaming state and doesn't - # go through 'disconnected', 'autoconnect', 'connecting' in between - condition = 'obj.state != DeviceState.roaming' - wd.wait_for_object_condition(device, condition, 5) - - self.assertEqual(device.state, iwd.DeviceState.connected) - self.assertTrue(bss_hostapd[1].list_sta()) - - testutil.test_iface_operstate(device.name) - testutil.test_ifaces_connected(bss_hostapd[1].ifname, device.name) - self.assertRaises(Exception, testutil.test_ifaces_connected, - (bss_hostapd[0].ifname, device.name)) - - device.disconnect() - - condition = 'not obj.connected' - wd.wait_for_object_condition(ordered_network.network_object, condition) - - @classmethod - def setUpClass(cls): - IWD.copy_to_storage('TestPreauth.8021x') - - os.system('ifconfig lo up') - - @classmethod - def tearDownClass(cls): - IWD.clear_storage() - -if __name__ == '__main__': - unittest.main(exit=True) diff --git a/autotests/testRSSIAgent/test.py b/autotests/testRSSIAgent/connection_test.py diff --git a/autotests/testSAE/connection_test.py b/autotests/testSAE/connection_test.py @@ -8,17 +8,13 @@ import iwd from iwd import IWD from iwd import PSKAgent from iwd import NetworkType -from hostapd import hostapd_map +from hostapd import HostapdCLI import testutil class Test(unittest.TestCase): def validate_connection(self, wd): - hostapd_if = None - - for hostapd in hostapd_map.values(): - if hostapd.config == 'ssidSAE.conf': - hostapd_if = hostapd.name + hostapd = HostapdCLI(config='ssidSAE.conf') psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) @@ -56,7 +52,7 @@ class Test(unittest.TestCase): wd.wait(2) testutil.test_iface_operstate(intf=device.name) - testutil.test_ifaces_connected(if0=device.name, if1=hostapd_if) + testutil.test_ifaces_connected(if0=device.name, if1=hostapd.ifname) device.disconnect() diff --git a/autotests/testSAE/group_20_connection_test.py b/autotests/testSAE/group_20_connection_test.py @@ -8,17 +8,13 @@ import iwd from iwd import IWD from iwd import PSKAgent from iwd import NetworkType -from hostapd import hostapd_map +from hostapd import HostapdCLI import testutil class Test(unittest.TestCase): def validate_connection(self, wd): - hostapd_if = None - - for hostapd in hostapd_map.values(): - if hostapd.config == 'ssidSAE-20.conf': - hostapd_if = hostapd.name + hostapd = HostapdCLI(config='ssidSAE-20.conf') psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) @@ -56,7 +52,7 @@ class Test(unittest.TestCase): wd.wait(2) testutil.test_iface_operstate(intf=device.name) - testutil.test_ifaces_connected(if0=device.name, if1=hostapd_if) + testutil.test_ifaces_connected(if0=device.name, if1=hostapd.ifname) device.disconnect() diff --git a/autotests/testSAQuery-spoofing/connection_test.py b/autotests/testSAQuery-spoofing/connection_test.py @@ -9,7 +9,7 @@ from iwd import IWD from iwd import PSKAgent from iwd import NetworkType from hwsim import Hwsim -from hostapd import HostapdCLI, hostapd_map +from hostapd import HostapdCLI from time import sleep diff --git a/autotests/testSAQuery/connection_test.py b/autotests/testSAQuery/connection_test.py @@ -8,7 +8,7 @@ import iwd from iwd import IWD from iwd import PSKAgent from iwd import NetworkType -from hostapd import HostapdCLI, hostapd_map +from hostapd import HostapdCLI class Test(unittest.TestCase):