2017-03-26 03:16:57 +02:00
|
|
|
#! /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
|
2020-09-11 01:12:22 +02:00
|
|
|
from hostapd import HostapdCLI
|
2017-05-22 10:49:47 +02:00
|
|
|
import testutil
|
2017-03-26 03:16:57 +02:00
|
|
|
|
|
|
|
class Test(unittest.TestCase):
|
2022-08-10 01:04:28 +02:00
|
|
|
def validate_connection(self, wd, over_ds=False, pkt_loss=False):
|
2018-12-14 20:15:26 +01:00
|
|
|
device = wd.list_devices(1)[0]
|
2017-08-14 14:31:22 +02:00
|
|
|
|
2022-03-28 19:28:38 +02:00
|
|
|
ordered_network = device.get_ordered_network('TestFT', full_scan=True)
|
2017-08-14 14:31:22 +02:00
|
|
|
|
|
|
|
self.assertEqual(ordered_network.type, NetworkType.psk)
|
2017-03-26 03:16:57 +02:00
|
|
|
|
2017-08-14 14:31:22 +02:00
|
|
|
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())
|
|
|
|
|
2021-08-12 22:22:04 +02:00
|
|
|
device.connect_bssid(self.bss_hostapd[0].bssid)
|
2017-08-14 14:31:22 +02:00
|
|
|
|
2020-09-11 01:12:47 +02:00
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
2017-08-14 14:31:22 +02:00
|
|
|
|
2022-03-28 19:28:38 +02:00
|
|
|
self.bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % device.address)
|
2017-08-14 14:31:22 +02:00
|
|
|
|
|
|
|
testutil.test_iface_operstate(device.name)
|
|
|
|
testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name)
|
|
|
|
self.assertRaises(Exception, testutil.test_ifaces_connected,
|
2021-08-12 22:22:04 +02:00
|
|
|
(self.bss_hostapd[1].ifname, device.name, True, True))
|
2017-08-14 14:31:22 +02:00
|
|
|
|
2021-09-29 00:36:06 +02:00
|
|
|
if over_ds:
|
|
|
|
self.rule0.enabled = True
|
|
|
|
|
2022-08-10 01:04:28 +02:00
|
|
|
if pkt_loss:
|
|
|
|
# Drop all data frames
|
|
|
|
self.rule1.enabled = True
|
|
|
|
# Set the current BSS signal lower so we have roam candidates
|
|
|
|
self.rule2.enabled = True
|
|
|
|
# Send 100 packets (to be dropped), should trigger beacon loss
|
|
|
|
testutil.tx_packets(device.name, self.bss_hostapd[0].ifname, 100)
|
2023-05-18 18:49:57 +02:00
|
|
|
device.wait_for_event('packet-loss-roam', timeout=60)
|
2022-08-10 01:04:28 +02:00
|
|
|
else:
|
|
|
|
device.roam(self.bss_hostapd[1].bssid)
|
2017-08-14 14:31:22 +02:00
|
|
|
|
|
|
|
# Check that iwd is on BSS 1 once out of roaming state and doesn't
|
|
|
|
# go through 'disconnected', 'autoconnect', 'connecting' in between
|
2021-02-05 20:06:37 +01:00
|
|
|
from_condition = 'obj.state == DeviceState.roaming'
|
|
|
|
to_condition = 'obj.state == DeviceState.connected'
|
|
|
|
wd.wait_for_object_change(device, from_condition, to_condition)
|
2017-08-14 14:31:22 +02:00
|
|
|
|
2022-08-22 19:01:45 +02:00
|
|
|
if pkt_loss:
|
|
|
|
self.rule1.enabled = False
|
|
|
|
self.rule2.enabled = False
|
|
|
|
|
2022-03-28 19:28:38 +02:00
|
|
|
self.bss_hostapd[1].wait_for_event('AP-STA-CONNECTED %s' % device.address)
|
2017-08-14 14:31:22 +02:00
|
|
|
|
|
|
|
testutil.test_iface_operstate(device.name)
|
|
|
|
testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name)
|
2017-05-22 10:49:47 +02:00
|
|
|
self.assertRaises(Exception, testutil.test_ifaces_connected,
|
2021-08-12 22:22:04 +02:00
|
|
|
(self.bss_hostapd[0].ifname, device.name, True, True))
|
2017-05-22 10:49:47 +02:00
|
|
|
|
2021-09-29 00:36:09 +02:00
|
|
|
self.bss_hostapd[1].rekey(device.address)
|
|
|
|
|
2021-08-12 22:22:04 +02:00
|
|
|
device.roam(self.bss_hostapd[0].bssid)
|
2021-04-30 20:20:36 +02:00
|
|
|
|
|
|
|
# Check that iwd is on BSS 0 once out of roaming state and doesn't
|
|
|
|
# go through 'disconnected', 'autoconnect', 'connecting' in between
|
|
|
|
from_condition = 'obj.state == DeviceState.roaming'
|
|
|
|
to_condition = 'obj.state == DeviceState.connected'
|
|
|
|
wd.wait_for_object_change(device, from_condition, to_condition)
|
|
|
|
|
2022-03-28 19:28:38 +02:00
|
|
|
self.bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % device.address)
|
2021-04-30 20:20:36 +02:00
|
|
|
|
|
|
|
testutil.test_iface_operstate(device.name)
|
|
|
|
testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name)
|
|
|
|
self.assertRaises(Exception, testutil.test_ifaces_connected,
|
2021-08-12 22:22:04 +02:00
|
|
|
(self.bss_hostapd[1].ifname, device.name, True, True))
|
|
|
|
|
2021-11-23 19:17:32 +01:00
|
|
|
self.bss_hostapd[0].deauthenticate(device.address)
|
|
|
|
condition = 'obj.state == DeviceState.disconnected'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
|
2021-08-12 22:22:04 +02:00
|
|
|
def test_ft_psk(self):
|
2024-01-03 19:46:37 +01:00
|
|
|
self.validate_connection(self.wd)
|
2021-08-12 22:22:04 +02:00
|
|
|
|
|
|
|
def test_ft_psk_over_ds(self):
|
|
|
|
self.bss_hostapd[0].set_value('ft_over_ds', '1')
|
|
|
|
self.bss_hostapd[0].reload()
|
|
|
|
self.bss_hostapd[0].wait_for_event("AP-ENABLED")
|
|
|
|
|
|
|
|
self.bss_hostapd[1].set_value('ft_over_ds', '1')
|
|
|
|
self.bss_hostapd[1].reload()
|
|
|
|
self.bss_hostapd[1].wait_for_event("AP-ENABLED")
|
|
|
|
|
2024-01-03 19:46:37 +01:00
|
|
|
self.validate_connection(self.wd, over_ds=True)
|
2021-08-12 22:22:04 +02:00
|
|
|
|
|
|
|
def test_reassociate_psk(self):
|
|
|
|
self.bss_hostapd[0].set_value('wpa_key_mgmt', 'WPA-PSK')
|
|
|
|
self.bss_hostapd[0].reload()
|
|
|
|
self.bss_hostapd[0].wait_for_event("AP-ENABLED")
|
|
|
|
|
|
|
|
self.bss_hostapd[1].set_value('wpa_key_mgmt', 'WPA-PSK')
|
|
|
|
self.bss_hostapd[1].reload()
|
|
|
|
self.bss_hostapd[1].wait_for_event("AP-ENABLED")
|
|
|
|
|
2024-01-03 19:46:37 +01:00
|
|
|
self.validate_connection(self.wd)
|
2021-04-30 20:20:36 +02:00
|
|
|
|
2022-08-10 01:04:28 +02:00
|
|
|
def test_roam_packet_loss(self):
|
2024-01-03 19:46:37 +01:00
|
|
|
self.validate_connection(self.wd, pkt_loss=True)
|
2022-08-10 01:04:28 +02:00
|
|
|
|
2017-08-14 14:31:22 +02:00
|
|
|
def tearDown(self):
|
2021-11-11 03:12:02 +01:00
|
|
|
os.system('ip link set "' + self.bss_hostapd[0].ifname + '" down')
|
|
|
|
os.system('ip link set "' + self.bss_hostapd[1].ifname + '" down')
|
|
|
|
os.system('ip link set "' + self.bss_hostapd[0].ifname + '" up')
|
|
|
|
os.system('ip link set "' + self.bss_hostapd[1].ifname + '" up')
|
2017-03-26 03:16:57 +02:00
|
|
|
|
2021-09-29 00:36:06 +02:00
|
|
|
self.rule0.enabled = False
|
2022-08-10 01:04:28 +02:00
|
|
|
self.rule1.enabled = False
|
|
|
|
self.rule2.enabled = False
|
2021-09-29 00:36:06 +02:00
|
|
|
|
2023-08-29 16:39:55 +02:00
|
|
|
for hapd in self.bss_hostapd:
|
|
|
|
hapd.default()
|
|
|
|
|
2024-01-03 19:46:37 +01:00
|
|
|
self.wd.stop()
|
|
|
|
self.wd = None
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.wd = IWD(True)
|
|
|
|
|
2017-03-26 03:16:57 +02:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
2021-09-29 00:36:06 +02:00
|
|
|
hwsim = Hwsim()
|
|
|
|
|
2021-08-12 22:22:04 +02:00
|
|
|
IWD.copy_to_storage('TestFT.psk')
|
2017-08-14 14:31:22 +02:00
|
|
|
|
2019-06-11 18:25:54 +02:00
|
|
|
cls.bss_hostapd = [ HostapdCLI(config='ft-psk-ccmp-1.conf'),
|
2024-01-03 19:46:38 +01:00
|
|
|
HostapdCLI(config='ft-psk-ccmp-2.conf') ]
|
|
|
|
|
|
|
|
unused = HostapdCLI(config='ft-psk-ccmp-3.conf')
|
|
|
|
unused.disable()
|
2023-05-18 18:49:57 +02:00
|
|
|
|
2022-08-10 01:04:28 +02:00
|
|
|
rad0 = hwsim.get_radio('rad0')
|
2023-05-18 18:49:57 +02:00
|
|
|
rad3 = hwsim.get_radio('rad3')
|
2021-09-29 00:36:06 +02:00
|
|
|
|
|
|
|
cls.rule0 = hwsim.rules.create()
|
2023-05-18 18:49:57 +02:00
|
|
|
cls.rule0.source = rad3.addresses[0]
|
2021-09-29 00:36:06 +02:00
|
|
|
cls.rule0.bidirectional = True
|
|
|
|
cls.rule0.signal = -2000
|
|
|
|
cls.rule0.prefix = 'b0'
|
|
|
|
cls.rule0.drop = True
|
2017-08-14 14:31:22 +02:00
|
|
|
|
2022-08-10 01:04:28 +02:00
|
|
|
cls.rule1 = hwsim.rules.create()
|
2023-05-18 18:49:57 +02:00
|
|
|
cls.rule1.source = rad3.addresses[0]
|
2022-08-10 01:04:28 +02:00
|
|
|
cls.rule1.prefix = '08'
|
|
|
|
cls.rule1.drop = True
|
|
|
|
|
|
|
|
cls.rule2 = hwsim.rules.create()
|
|
|
|
cls.rule2.source = rad0.addresses[0]
|
2022-08-22 19:01:45 +02:00
|
|
|
cls.rule2.signal = -7000
|
2022-08-10 01:04:28 +02:00
|
|
|
|
2022-08-22 19:01:48 +02:00
|
|
|
cls.bss_hostapd[0].set_address('12:00:00:00:00:01')
|
|
|
|
cls.bss_hostapd[1].set_address('12:00:00:00:00:02')
|
|
|
|
|
|
|
|
HostapdCLI.group_neighbors(*cls.bss_hostapd)
|
2017-03-26 03:16:57 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
IWD.clear_storage()
|
2021-02-25 23:00:54 +01:00
|
|
|
cls.bss_hostapd = None
|
2022-01-19 23:26:52 +01:00
|
|
|
cls.rule0.remove()
|
2024-01-03 19:46:37 +01:00
|
|
|
cls.rule1.remove()
|
|
|
|
cls.rule2.remove()
|
2017-03-26 03:16:57 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(exit=True)
|