2019-02-25 21:29:33 +01:00
|
|
|
#! /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
|
2020-09-11 01:12:22 +02:00
|
|
|
from hostapd import HostapdCLI
|
2019-02-25 21:29:33 +01:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
2020-09-14 23:02:33 +02:00
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
2019-02-25 21:29:33 +01:00
|
|
|
|
|
|
|
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()
|
2019-06-11 18:25:54 +02:00
|
|
|
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')
|
2019-02-25 21:29:33 +01:00
|
|
|
|
|
|
|
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
|
2021-05-22 05:35:27 +02:00
|
|
|
rule0.signal = -5100
|
2019-02-25 21:29:33 +01:00
|
|
|
|
|
|
|
rule1 = hwsim.rules.create()
|
|
|
|
rule1.source = ht_radio.addresses[0]
|
|
|
|
rule1.bidirectional = True
|
2021-05-22 05:35:27 +02:00
|
|
|
rule1.signal = -5200
|
2019-02-25 21:29:33 +01:00
|
|
|
|
|
|
|
rule2 = hwsim.rules.create()
|
|
|
|
rule2.source = non_ht_radio.addresses[0]
|
|
|
|
rule2.bidirectional = True
|
2021-05-22 05:35:27 +02:00
|
|
|
rule2.signal = -5300
|
2019-02-25 21:29:33 +01:00
|
|
|
|
|
|
|
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
|
2021-05-22 05:35:27 +02:00
|
|
|
rule0.signal = -7900
|
2019-02-25 21:29:33 +01:00
|
|
|
|
|
|
|
self.do_connect(wd, device, ht_hostapd)
|
|
|
|
|
|
|
|
# lower HT BSS signal, basic rate BSS should now be preferred
|
2021-05-22 05:35:27 +02:00
|
|
|
rule1.signal = -7400
|
2019-02-25 21:29:33 +01:00
|
|
|
|
|
|
|
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)
|