chan_switch_test.py (3780B)
1 #! /usr/bin/python3 2 3 import unittest 4 import sys, os 5 6 sys.path.append('../util') 7 from iwd import IWD 8 from iwd import NetworkType 9 from hostapd import HostapdCLI 10 from packaging import version 11 from subprocess import run 12 import re 13 import testutil 14 15 # 16 # The CSA handling was added in kernel 6.8, so for any earlier kernel this test 17 # won't pass. 18 # 19 def kernel_is_newer(min_version="6.8"): 20 proc = run(["uname", "-r"], capture_output=True) 21 22 version_str = proc.stdout.decode("utf-8") 23 match = re.match(r"(\d+\.\d+)", version_str) 24 if not match: 25 return False 26 27 return version.parse(match.group(1)) >= version.parse(min_version) 28 29 class Test(unittest.TestCase): 30 def test_channel_switch_during_roam(self): 31 wd = self.wd 32 33 device = wd.list_devices(1)[0] 34 35 ordered_network = device.get_ordered_network('TestFT', full_scan=True) 36 37 self.assertEqual(ordered_network.type, NetworkType.psk) 38 39 condition = 'not obj.connected' 40 wd.wait_for_object_condition(ordered_network.network_object, condition) 41 42 self.assertFalse(self.bss_hostapd[0].list_sta()) 43 self.assertFalse(self.bss_hostapd[1].list_sta()) 44 45 device.connect_bssid(self.bss_hostapd[0].bssid) 46 47 condition = 'obj.state == DeviceState.connected' 48 wd.wait_for_object_condition(device, condition) 49 50 self.bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % device.address) 51 52 testutil.test_iface_operstate(device.name) 53 testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) 54 self.assertRaises(Exception, testutil.test_ifaces_connected, 55 (self.bss_hostapd[1].ifname, device.name, True, True)) 56 57 # Start a channel switch and wait for it to begin 58 self.bss_hostapd[1].chan_switch(6, wait=False) 59 self.bss_hostapd[1].wait_for_event("CTRL-EVENT-STARTED-CHANNEL-SWITCH") 60 # Initiate a roam immediately which should get rejected by the kernel 61 device.roam(self.bss_hostapd[1].bssid) 62 63 # IWD should authenticate, then proceed to association 64 device.wait_for_event("ft-authenticating") 65 device.wait_for_event("ft-roaming") 66 67 # The kernel should reject the association, which should trigger a 68 # disconnect 69 condition = 'obj.state == DeviceState.disconnected' 70 wd.wait_for_object_condition(device, condition) 71 72 condition = 'obj.state == DeviceState.connected' 73 wd.wait_for_object_condition(device, condition) 74 75 76 def tearDown(self): 77 os.system('ip link set "' + self.bss_hostapd[0].ifname + '" down') 78 os.system('ip link set "' + self.bss_hostapd[1].ifname + '" down') 79 os.system('ip link set "' + self.bss_hostapd[0].ifname + '" up') 80 os.system('ip link set "' + self.bss_hostapd[1].ifname + '" up') 81 82 for hapd in self.bss_hostapd: 83 hapd.default() 84 85 self.wd.stop() 86 self.wd = None 87 88 def setUp(self): 89 self.wd = IWD(True) 90 91 @classmethod 92 def setUpClass(cls): 93 if not kernel_is_newer(): 94 raise unittest.SkipTest() 95 96 IWD.copy_to_storage('TestFT.psk') 97 98 cls.bss_hostapd = [ HostapdCLI(config='ft-psk-ccmp-1.conf'), 99 HostapdCLI(config='ft-psk-ccmp-2.conf'), 100 HostapdCLI(config='ft-psk-ccmp-3.conf') ] 101 102 unused = HostapdCLI(config='ft-psk-ccmp-3.conf') 103 unused.disable() 104 105 cls.bss_hostapd[0].set_address('12:00:00:00:00:01') 106 cls.bss_hostapd[1].set_address('12:00:00:00:00:02') 107 cls.bss_hostapd[2].set_address('12:00:00:00:00:03') 108 109 HostapdCLI.group_neighbors(*cls.bss_hostapd) 110 111 @classmethod 112 def tearDownClass(cls): 113 IWD.clear_storage() 114 cls.bss_hostapd = None