netdev: check connected in channel switch event
PATCH v2 1/4 netdev: check connected in channel switch event
In an ideal world userspace should never be getting a channel switch event unless connected to an AP, but alas this has been seen at least with ath10k hardware. This causes IWD to crash since the logic assumes netdev->handshake is set.
--- src/netdev.c | 3 +++ 1 file changed, 3 insertions(+)
src/netdev.c +3 -0
@@ -5402,6 +5402,9 @@ static void netdev_channel_switch_event(struct l_genl_msg *msg,if (netdev->type !=NL80211_IFTYPE_STATION )return ; +if (L_WARN_ON (!netdev->connected)) +return ; + chandef = l_new(struct band_chandef, 1);if (nl80211_parse_chandef (msg, chandef) <0 ) {
Signature · 1 line
2.34.1
PATCH v2 2/4 netdev: disconnect rather than deauth in FT association failure
After CSA IE parsing was added to the kernel this opened up the possibility that associations could be rejected locally based on the contents of this CSA IE in the AP's beacons. Overall, it was always possible for a local rejection but this case was never considered by IWD. The CSA-based rejection is something that can and does happen out in the wild.
When this association rejection happens it desync's IWD and the kernel's state:
1. IWD begins an FT roam. Authenticates successfully, then proceeds to calling netdev_ft_reassociate().
2. Immediately IWD transitions to a ft-roaming state and waits for an association response.
3. CMD_ASSOCIATE is rejected by the kernel in the ACK which IWD handles by sending a deauthenticate command to the kernel (since we have a valid authentication to the new BSS).
4. Due to a bug IWD uses the target BSSID to deauthenticate which the kernel rejects since it has no knowledge of this auth. This error is not handled or logged.
5. IWD proceeds, assuming its deauthenticated, and transitions to a disconnected state. The kernel remains "connected" which of course prevents any future connections.
A simple fix for this is to address the bug (4) in IWD that deauths using the current BSS roam target. This is actually legacy behavior from back when IWD used CMD_AUTHENTICATE. Today the kernel is unaware that IWD authenticated so a deauth is not going to be effective. Instead we can issue a CMD_DISCONNECT. This is somewhat of a large hammer, but since the handshake and internal state has already been modified to use the new target BSS we cannot go back and maintain the existing connect (though it is _possible_, see the TODO in the patch).
--- src/netdev.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
src/netdev.c +15 -2
@@ -2993,13 +2993,26 @@ static void netdev_cmd_ft_reassociate_cb(struct l_genl_msg *msg, void *user_data) {struct netdev *netdev = user_data; +int err =l_genl_msg_get_error (msg); netdev->connect_cmd_id =0 ; -if (l_genl_msg_get_error (msg) >=0 ) +l_debug ("%d" , err); + +if (err >=0 )return ; -netdev_deauth_and_fail_connection (netdev, +/* +* TODO: It is possible to not trigger a disconnect here and maintain +* the current connection. The issue is that IWD has already +* modified the handshake and we've lost all reference to the old +* BSS keys. +* +* This could be remedied in the future by creating an entirely +* new handshake_state object for the association and only when +* the ack indicates success do we clear out the old object. +*/ +netdev_disconnect_and_fail_connection (netdev,NETDEV_RESULT_ASSOCIATION_FAILED ,MMPDU_STATUS_CODE_UNSPECIFIED ); }
Signature · 1 line
2.34.1
PATCH v2 3/4 auto-t: make waiting for channel switch configurable
In reply to James Prestwood--- autotests/util/hostapd.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
autotests/util/hostapd.py +4 -2
@@ -288,13 +288,15 @@ class HostapdCLI(object): cmd = 'RESEND_M3 %s' % address self.ctrl_sock.sendall(cmd.encode('utf-8')) - def chan_switch(self, channel): + def chan_switch(self, channel, wait=True): if channel > len(chan_freq_map): raise Exception("Only 2.4GHz channels supported for chan_switch") cmd = self.cmdline + ['chan_switch', '50', str(chan_freq_map[channel])] ctx.start_process(cmd).wait() - self.wait_for_event('AP-CSA-FINISHED') + + if wait: + self.wait_for_event('AP-CSA-FINISHED') def _get_status(self): ret = {}
Signature · 1 line
2.34.1
PATCH v2 4/4 auto-t: add test for channel switch during roam
In reply to James PrestwoodIn kernel 6.8 a new CMD_ASSOCIATE failure path was added which checks if the AP has a channel switch in progress. Eariler patches update IWD into handling this case better, and this new test exercises that.
--- autotests/testPSK-roam/chan_switch_test.py | 114 +++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 autotests/testPSK-roam/chan_switch_test.py
autotests/testPSK-roam/chan_switch_test.py new file +114 -0
@@ -0,0 +1,114 @@ +#! /usr/bin/python3 + +import unittest +import sys, os + +sys.path.append('../util') +from iwd import IWD +from iwd import NetworkType +from hostapd import HostapdCLI +from packaging import version +from subprocess import run +import re +import testutil + +# +# The CSA handling was added in kernel 6.8, so for any earlier kernel this test +# won't pass. +# +def kernel_is_newer(min_version="6.8"): + proc = run(["uname", "-r"], capture_output=True) + + version_str = proc.stdout.decode("utf-8") + match = re.match(r"(\d+\.\d+)", version_str) + if not match: + return False + + return version.parse(match.group(1)) >= version.parse(min_version) + +class Test(unittest.TestCase): + def test_channel_switch_during_roam(self): + wd = self.wd + + device = wd.list_devices(1)[0] + + ordered_network = device.get_ordered_network('TestFT', full_scan=True) + + self.assertEqual(ordered_network.type, NetworkType.psk) + + 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()) + + device.connect_bssid(self.bss_hostapd[0].bssid) + + condition = 'obj.state == DeviceState.connected' + wd.wait_for_object_condition(device, condition) + + self.bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % device.address) + + 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, True, True)) + + # Start a channel switch and wait for it to begin + self.bss_hostapd[1].chan_switch(6, wait=False) + self.bss_hostapd[1].wait_for_event("CTRL-EVENT-STARTED-CHANNEL-SWITCH") + # Initiate a roam immediately which should get rejected by the kernel + device.roam(self.bss_hostapd[1].bssid) + + # IWD should authenticate, then proceed to association + device.wait_for_event("ft-authenticating") + device.wait_for_event("ft-roaming") + + # The kernel should reject the association, which should trigger a + # disconnect + condition = 'obj.state == DeviceState.disconnected' + wd.wait_for_object_condition(device, condition) + + condition = 'obj.state == DeviceState.connected' + wd.wait_for_object_condition(device, condition) + + + def tearDown(self): + 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') + + for hapd in self.bss_hostapd: + hapd.default() + + self.wd.stop() + self.wd = None + + def setUp(self): + self.wd = IWD(True) + + @classmethod + def setUpClass(cls): + if not kernel_is_newer(): + raise unittest.SkipTest() + + IWD.copy_to_storage('TestFT.psk') + + cls.bss_hostapd = [ HostapdCLI(config='ft-psk-ccmp-1.conf'), + HostapdCLI(config='ft-psk-ccmp-2.conf'), + HostapdCLI(config='ft-psk-ccmp-3.conf') ] + + unused = HostapdCLI(config='ft-psk-ccmp-3.conf') + unused.disable() + + cls.bss_hostapd[0].set_address('12:00:00:00:00:01') + cls.bss_hostapd[1].set_address('12:00:00:00:00:02') + cls.bss_hostapd[2].set_address('12:00:00:00:00:03') + + HostapdCLI.group_neighbors(*cls.bss_hostapd) + + @classmethod + def tearDownClass(cls): + IWD.clear_storage() + cls.bss_hostapd = None
Signature · 1 line
2.34.1
Hi James,
Quoted 8 lines · James Prestwood
In an ideal world userspace should never be getting a channel switch event unless connected to an AP, but alas this has been seen at least with ath10k hardware. This causes IWD to crash since the logic assumes
netdev->handshakeis set.--- src/netdev.c | 3 +++ 1 file changed, 3 insertions(+)
All applied, thanks.
Regards,
-Denis