2019-08-28 18:14:32 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
|
|
|
sys.path.append('../util')
|
|
|
|
from iwd import IWD
|
2021-08-14 00:45:53 +02:00
|
|
|
from iwd import IWD_CONFIG_DIR
|
2019-08-28 18:14:32 +02:00
|
|
|
from iwd import NetworkType
|
|
|
|
from hostapd import HostapdCLI
|
|
|
|
import testutil
|
|
|
|
|
|
|
|
class Test(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_connection_success(self):
|
2021-08-18 23:50:27 +02:00
|
|
|
wd = self.wd
|
2019-08-28 18:14:32 +02:00
|
|
|
|
|
|
|
hapd_hotspot = HostapdCLI(config='ssidHotspot.conf')
|
|
|
|
hapd_wpa = HostapdCLI(config='ssidWPA2-1.conf')
|
|
|
|
|
|
|
|
self.assertEqual(len(wd.list_known_networks()), 2)
|
|
|
|
|
|
|
|
devices = wd.list_devices(1)
|
|
|
|
device = devices[0]
|
2021-08-12 22:38:12 +02:00
|
|
|
device.autoconnect = True
|
2019-08-28 18:14:32 +02:00
|
|
|
|
|
|
|
condition = 'obj.scanning'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
|
|
|
|
condition = 'not obj.scanning'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
|
|
|
|
wpa_network = device.get_ordered_network("ssidWPA2-1")
|
|
|
|
self.assertEqual(wpa_network.type, NetworkType.psk)
|
|
|
|
|
|
|
|
#
|
|
|
|
# First make sure we can connect to a provisioned, non-Hotspot network,
|
|
|
|
# while there are hotspot networks in range. This should result in
|
|
|
|
# autoconnect *after* ANQP is performed
|
|
|
|
#
|
2020-04-14 03:16:43 +02:00
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
2019-08-28 18:14:32 +02:00
|
|
|
|
|
|
|
testutil.test_iface_operstate()
|
|
|
|
testutil.test_ifaces_connected(device.name, hapd_wpa.ifname)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Remove provisioning file, this should cause a disconnect.
|
|
|
|
#
|
2020-10-29 17:19:02 +01:00
|
|
|
os.remove("/tmp/iwd/ssidWPA2-1.psk")
|
2019-08-28 18:14:32 +02:00
|
|
|
|
2020-04-14 03:16:43 +02:00
|
|
|
condition = 'obj.state == DeviceState.disconnected'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
2019-08-28 18:14:32 +02:00
|
|
|
|
2020-04-14 03:16:45 +02:00
|
|
|
condition = 'len(obj.list_known_networks()) == 1'
|
|
|
|
wd.wait_for_object_condition(wd, condition)
|
2019-08-28 18:14:32 +02:00
|
|
|
|
|
|
|
condition = 'obj.scanning'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
|
|
|
|
condition = 'not obj.scanning'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
|
|
|
|
hotspot_network = device.get_ordered_network("Hotspot")
|
|
|
|
self.assertEqual(hotspot_network.type, NetworkType.eap)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Since there are no other provisioned networks, we should do ANQP and
|
|
|
|
# autoconnect to the hotspot network.
|
|
|
|
#
|
2020-04-14 03:16:43 +02:00
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
2019-08-28 18:14:32 +02:00
|
|
|
|
|
|
|
testutil.test_iface_operstate()
|
|
|
|
testutil.test_ifaces_connected(device.name, hapd_hotspot.ifname)
|
|
|
|
|
2020-10-29 17:19:02 +01:00
|
|
|
os.remove('/tmp/iwd/hotspot/autoconnect.conf')
|
2019-08-28 18:14:32 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# make sure removal of hotspot conf file resulted in disconnect
|
|
|
|
#
|
2020-04-14 03:16:43 +02:00
|
|
|
condition = 'obj.state == DeviceState.disconnected'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
2019-08-28 18:14:32 +02:00
|
|
|
|
2020-04-14 03:16:45 +02:00
|
|
|
IWD.copy_to_storage('ssidWPA2-1.psk')
|
|
|
|
|
|
|
|
condition = 'len(obj.list_known_networks()) == 1'
|
|
|
|
wd.wait_for_object_condition(wd, condition)
|
|
|
|
|
2019-08-28 18:14:32 +02:00
|
|
|
condition = 'obj.scanning'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
|
|
|
|
condition = 'not obj.scanning'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
|
|
|
|
hotspot_network = device.get_ordered_network("ssidWPA2-1")
|
|
|
|
self.assertEqual(hotspot_network.type, NetworkType.psk)
|
|
|
|
|
2020-04-14 03:16:43 +02:00
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
2019-08-28 18:14:32 +02:00
|
|
|
|
|
|
|
testutil.test_iface_operstate()
|
|
|
|
testutil.test_ifaces_connected(device.name, hapd_wpa.ifname)
|
|
|
|
|
2020-04-14 03:16:43 +02:00
|
|
|
device.disconnect()
|
|
|
|
|
2019-08-28 18:14:32 +02:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
IWD.copy_to_hotspot('autoconnect.conf')
|
|
|
|
IWD.copy_to_storage('ssidWPA2-1.psk')
|
2021-08-14 00:45:53 +02:00
|
|
|
IWD.copy_to_storage('anqp_enabled.conf', storage_dir=IWD_CONFIG_DIR, name='main.conf')
|
2019-08-28 18:14:32 +02:00
|
|
|
|
2021-08-18 23:50:27 +02:00
|
|
|
cls.wd = IWD(True)
|
|
|
|
|
2019-08-28 18:14:32 +02:00
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
IWD.clear_storage()
|
|
|
|
os.remove('/tmp/main.conf')
|
|
|
|
|
2021-08-18 23:50:27 +02:00
|
|
|
cls.wd = None
|
|
|
|
|
2019-08-28 18:14:32 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(exit=True)
|