eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

commit 143a5859542aafedb85822df8fc1e3b50e403cc4
parent 1cc515d90b4555f2cddffe12f39c3d559d3e9925
Author: illiliti <illiliti@protonmail.com>
Date:   Tue, 13 Feb 2024 15:15:32 +0300

Merge tag '2.14'

Release 2.14

Diffstat:
MChangeLog | 20++++++++++++++++++++
Aautotests/testDPP/existingProfile.psk | 2++
Mautotests/testDPP/hw.conf | 5+++--
Mautotests/testDPP/pkex_test.py | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Aautotests/testDPP/ssidHidden.conf | 9+++++++++
Aautotests/testDPP/ssidHidden.psk | 5+++++
Mautotests/testKnownNetworks/frequency_test.py | 110++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
Mautotests/testKnownNetworks/hw.conf | 1+
Aautotests/testNetconfig/autoconnect.psk | 2++
Aautotests/testNetconfig/timeout_test.py | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aautotests/testNetconfigRoam/TestFT.psk | 2++
Aautotests/testNetconfigRoam/ft-psk-ccmp-1.conf | 41+++++++++++++++++++++++++++++++++++++++++
Aautotests/testNetconfigRoam/ft-psk-ccmp-2.conf | 41+++++++++++++++++++++++++++++++++++++++++
Aautotests/testNetconfigRoam/hw.conf | 8++++++++
Aautotests/testNetconfigRoam/main.conf | 3+++
Aautotests/testNetconfigRoam/netconfig_roam_test.py | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mautotests/testPSK-roam/connection_test.py | 32++++++++++++++++----------------
Mautotests/testPSK-roam/failed_roam_test.py | 67+++++++++++++++++++++++++++++++++++++++++++++----------------------
Mautotests/testPSK-roam/roam_ap_disconnect_test.py | 11+++++++----
Mautotests/testSAE/autoconnect_test.py | 20++++++++++++++------
Mautotests/testSAE/failure_test.py | 2+-
Mautotests/testSAE/ssidSAE.conf | 3++-
Rautotests/testSAE/ssidSAE.psk -> autotests/testSAE/ssidSAE.psk.default | 0
Aautotests/testSAE/ssidSAE.psk.identifier | 3+++
Mautotests/util/hostapd.py | 9++++++++-
Mautotests/util/iwd.py | 10+++++++---
Mclient/ap.c | 13+++++++++++--
Mconfigure.ac | 6+++---
Mmonitor/main.c | 176++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mmonitor/nlmon.c | 277++++++++++++++-----------------------------------------------------------------
Mmonitor/nlmon.h | 2+-
Msrc/dpp-util.c | 5+++--
Msrc/dpp.c | 126+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
Msrc/eapol.c | 9+++++++--
Msrc/erp.c | 2+-
Msrc/fils.c | 2+-
Msrc/ft.c | 230+++++++++++++++++++++++++++++++++----------------------------------------------
Msrc/ft.h | 4++--
Msrc/handshake.c | 35++++++++++++++++++++++++++++++-----
Msrc/handshake.h | 15+++++++++++++--
Msrc/iwd.network.rst | 6++++++
Msrc/knownnetworks.c | 34+++++++++++++++++++++++-----------
Msrc/knownnetworks.h | 7+++++--
Msrc/mpdu.h | 1+
Msrc/netconfig.c | 9+++++++--
Msrc/netdev.c | 109+++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/netdev.h | 8+++++---
Msrc/network.c | 148+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
Msrc/network.h | 2++
Msrc/p2p.c | 28+++++++++++-----------------
Msrc/sae.c | 24++++++++++++++++++++----
Msrc/scan.c | 20+++++++++++++++++---
Msrc/scan.h | 2++
Msrc/station.c | 111+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
Msrc/station.h | 1+
Msrc/wiphy.c | 7++++++-
Msrc/wsc.c | 5++++-
Mtools/runner.py | 7++++++-
Mtools/utils.py | 3+++
Munit/gencerts.cnf | 1-
Munit/test-eapol.c | 2+-
61 files changed, 1408 insertions(+), 663 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,23 @@ +ver 2.14: + Fix issue with accepting PTK 4/4 after receiving PTK 2/4. + Fix issue with frequency limit for quick scans. + Fix issue with limiting DHCPv4 attempts. + +ver 2.13: + Fix issue with handling netconfig and roaming conditions. + Fix issue with logging requirement for CMD_EXTERNAL_AUTH. + Fix issue with using OpenSSL 3.2 installations. + +ver 2.12: + Fix issue with DPP extra settings not being used. + Fix issue with DPP and PRF+ handling on AARCH64. + Add support for SAE password identifiers. + +ver 2.11: + Fix issue with handling iovecs with multiple IEs. + Fix issue with handling SAE password identifiers. + Fix issue with handling agent release method call. + ver 2.10: Fix issue with buffer overflow for 32 byte SSIDs. Fix issue with deauthentication before FT work completes. diff --git a/autotests/testDPP/existingProfile.psk b/autotests/testDPP/existingProfile.psk @@ -0,0 +1,2 @@ +[Security] +Passphrase=IncorrectPassphrase diff --git a/autotests/testDPP/hw.conf b/autotests/testDPP/hw.conf @@ -1,5 +1,5 @@ [SETUP] -num_radios=4 +num_radios=5 start_iwd=0 hwsim_medium=yes @@ -8,6 +8,7 @@ rad0=wpas.conf [HOSTAPD] rad1=hostapd.conf +rad2=ssidHidden.conf [NameSpaces] -ns0=rad2 +ns0=rad3 diff --git a/autotests/testDPP/pkex_test.py b/autotests/testDPP/pkex_test.py @@ -26,11 +26,11 @@ class Test(unittest.TestCase): self.wpas.dpp_stop_listen() self.wpas.dpp_configurator_remove() - def start_iwd_pkex_configurator(self, device, agent=False): + def start_iwd_pkex_configurator(self, device, agent=False, profile='ssidCCMP.psk'): self.hapd.reload() self.hapd.wait_for_event('AP-ENABLED') - IWD.copy_to_storage('ssidCCMP.psk') + IWD.copy_to_storage(profile) device.autoconnect = True condition = 'obj.state == DeviceState.connected' @@ -186,6 +186,71 @@ class Test(unittest.TestCase): self.agent = None + def test_existing_network(self): + self.hapd.reload() + self.hapd.wait_for_event('AP-ENABLED') + IWD.copy_to_storage("existingProfile.psk", "/tmp/ns0/", "ssidCCMP.psk") + + # Scan first so a network object exists, and its a known network + self.device[1].scan() + self.wd.wait_for_object_condition(self.device[1], 'obj.scanning == True') + self.wd.wait_for_object_condition(self.device[1], 'obj.scanning == False') + + self.start_iwd_pkex_configurator(self.device[0]) + + self.device[1].dpp_pkex_enroll('secret123', identifier="test") + self.device[1].autoconnect = False + + condition = 'obj.state == DeviceState.connected' + self.wd.wait_for_object_condition(self.device[1], condition) + + # Check additional settings were carried over + with open('/tmp/ns0/ssidCCMP.psk', 'r') as f: + settings = f.read() + + self.assertIn("SendHostname=true", settings) + + def test_existing_hidden_network(self): + self.hapd_hidden.reload() + self.hapd_hidden.wait_for_event('AP-ENABLED') + IWD.copy_to_storage("existingProfile.psk", "/tmp/ns0/", "ssidHidden.psk") + + # Scan first so a network object exists, and its a known network + self.device[1].scan() + self.wd.wait_for_object_condition(self.device[1], 'obj.scanning == True') + self.wd.wait_for_object_condition(self.device[1], 'obj.scanning == False') + + self.start_iwd_pkex_configurator(self.device[0], profile='ssidHidden.psk') + + self.device[1].dpp_pkex_enroll('secret123', identifier="test") + self.device[1].autoconnect = False + + condition = 'obj.state == DeviceState.connected' + self.wd.wait_for_object_condition(self.device[1], condition) + + # Check additional settings were carried over + with open('/tmp/ns0/ssidHidden.psk', 'r') as f: + settings = f.read() + + self.assertIn("Hidden=true", settings) + + def test_hidden_network(self): + self.hapd_hidden.reload() + self.hapd_hidden.wait_for_event('AP-ENABLED') + self.start_iwd_pkex_configurator(self.device[0], profile='ssidHidden.psk') + + self.device[1].dpp_pkex_enroll('secret123', identifier="test") + self.device[1].autoconnect = False + + condition = 'obj.state == DeviceState.connected' + self.wd.wait_for_object_condition(self.device[1], condition) + + # Check additional settings were carried over + with open('/tmp/ns0/ssidHidden.psk', 'r') as f: + settings = f.read() + + self.assertIn("Hidden=true", settings) + def setUp(self): ns0 = ctx.get_namespace('ns0') self.wpas = Wpas('wpas.conf') @@ -197,6 +262,8 @@ class Test(unittest.TestCase): self.device.append(self.wd_ns0.list_devices(1)[0]) self.hapd = HostapdCLI('hostapd.conf') self.hapd.disable() + self.hapd_hidden = HostapdCLI('ssidHidden.conf') + self.hapd_hidden.disable() self.hwsim = Hwsim() self.rule_xchg_resp = self.hwsim.rules.create() @@ -240,6 +307,7 @@ class Test(unittest.TestCase): self.hapd = None self.rule_xchg_resp = None IWD.clear_storage() + IWD.clear_storage('/tmp/ns0') @classmethod def setUpClass(cls): diff --git a/autotests/testDPP/ssidHidden.conf b/autotests/testDPP/ssidHidden.conf @@ -0,0 +1,9 @@ +hw_mode=g +channel=6 +ssid=ssidHidden + +wpa=1 +wpa_pairwise=TKIP +wpa_passphrase=secret123 + +ignore_broadcast_ssid=1 diff --git a/autotests/testDPP/ssidHidden.psk b/autotests/testDPP/ssidHidden.psk @@ -0,0 +1,5 @@ +[Security] +Passphrase=secret123 + +[Settings] +Hidden=true diff --git a/autotests/testKnownNetworks/frequency_test.py b/autotests/testKnownNetworks/frequency_test.py @@ -4,17 +4,15 @@ import unittest import sys sys.path.append('../util') -import iwd from iwd import IWD from iwd import PSKAgent -from iwd import NetworkType -import testutil +from hwsim import Hwsim import os from configparser import ConfigParser class Test(unittest.TestCase): def connect_network(self, wd, device, network): - ordered_network = device.get_ordered_network(network) + ordered_network = device.get_ordered_network(network, full_scan=True) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) @@ -30,7 +28,7 @@ class Test(unittest.TestCase): wd.wait_for_object_condition(ordered_network.network_object, condition) def test_connection_success(self): - wd = IWD(True, '/tmp') + wd = self.wd psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) @@ -38,6 +36,11 @@ class Test(unittest.TestCase): devices = wd.list_devices(1) device = devices[0] + + # Set the signals so that the 2.4GHz ranking will be higher + self.ssidccmp_2g_rule.signal = -2000 + self.ssidccmp_5g_rule.signal = -8000 + # # Connect to the PSK network, then Hotspot so IWD creates 2 entries in # the known frequency file. @@ -75,8 +78,10 @@ class Test(unittest.TestCase): # self.assertIsNotNone(psk_freqs) self.assertIsNotNone(psk_uuid) - self.assertIn('5180', psk_freqs) - self.assertIn('2412', psk_freqs) + + # The 2.4GHz frequency should come first, as it was ranked higher + self.assertEqual('2412', psk_freqs[0]) + self.assertEqual('5180', psk_freqs[1]) self.assertIsNotNone(hs20_freqs) self.assertIsNotNone(hs20_uuid) @@ -92,6 +97,10 @@ class Test(unittest.TestCase): psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) + # Now set the signals so that the 5GHz ranking will be higher + self.ssidccmp_2g_rule.signal = -8000 + self.ssidccmp_5g_rule.signal = -2000 + # # Reconnect, this should generate a completely new UUID since we # previously forgot the network. @@ -120,8 +129,78 @@ class Test(unittest.TestCase): self.assertIsNotNone(psk_freqs) self.assertIsNotNone(psk_uuid2) self.assertNotEqual(psk_uuid, psk_uuid2) - self.assertIn('5180', psk_freqs) - self.assertIn('2412', psk_freqs) + # Now the 5GHz frequency should be first + self.assertEqual('5180', psk_freqs[0]) + self.assertEqual('2412', psk_freqs[1]) + + def test_maximum_frequencies(self): + psk_agent = PSKAgent("secret123") + self.wd.register_psk_agent(psk_agent) + + devices = self.wd.list_devices(1) + device = devices[0] + + # Connect and generate a known frequencies file + self.connect_network(self.wd, device, 'ssidCCMP') + + self.wd.unregister_psk_agent(psk_agent) + + # + # Rewrite the known frequencies file to move the valid network + # frequencies to the end, past the maximum for a quick scan + # + config = ConfigParser() + config.read('/tmp/iwd/.known_network.freq') + for s in config.sections(): + if os.path.basename(config[s]['name']) == 'ssidCCMP.psk': + config.set(s, 'list', "2417 2422 2427 2432 2437 2442 2447 2452 2457 2462 2467 2472 2484 2412 5180") + break + + self.wd.stop() + + with open('/tmp/iwd/.known_network.freq', 'w') as f: + config.write(f) + + self.wd = IWD(True) + + devices = self.wd.list_devices(1) + device = devices[0] + + device.autoconnect = True + + device.wait_for_event("autoconnect_quick") + + condition = "obj.scanning == True" + self.wd.wait_for_object_condition(device, condition) + + condition = "obj.scanning == False" + self.wd.wait_for_object_condition(device, condition) + + # + # Check that the quick scan didn't return any results + # + with self.assertRaises(Exception): + device.get_ordered_network("ssidCCMP", scan_if_needed=False) + + device.wait_for_event("autoconnect_full") + + condition = "obj.scanning == True" + self.wd.wait_for_object_condition(device, condition) + + condition = "obj.scanning == False" + self.wd.wait_for_object_condition(device, condition) + + # + # The full scan should now see the network + # + device.get_ordered_network("ssidCCMP", scan_if_needed=False) + + def setUp(self): + self.wd = IWD(True) + + def tearDown(self): + self.wd.stop() + self.wd = None @classmethod def setUpClass(cls): @@ -129,10 +208,23 @@ class Test(unittest.TestCase): conf = '[General]\nDisableANQP=0\n' os.system('echo "%s" > /tmp/main.conf' % conf) + hwsim = Hwsim() + + cls.ssidccmp_2g_rule = hwsim.rules.create() + cls.ssidccmp_2g_rule.source = hwsim.get_radio('rad1').addresses[0] + cls.ssidccmp_2g_rule.enabled = True + + cls.ssidccmp_5g_rule = hwsim.rules.create() + cls.ssidccmp_5g_rule.source = hwsim.get_radio('rad2').addresses[0] + cls.ssidccmp_5g_rule.enabled = True + @classmethod def tearDownClass(cls): IWD.clear_storage() os.remove('/tmp/main.conf') + cls.ssidccmp_2g_rule.remove() + cls.ssidccmp_5g_rule.remove() + if __name__ == '__main__': unittest.main(exit=True) diff --git a/autotests/testKnownNetworks/hw.conf b/autotests/testKnownNetworks/hw.conf @@ -2,6 +2,7 @@ num_radios=5 start_iwd=0 reg_domain=US +hwsim_medium=yes [HOSTAPD] rad0=ssidNew.conf diff --git a/autotests/testNetconfig/autoconnect.psk b/autotests/testNetconfig/autoconnect.psk @@ -0,0 +1,2 @@ +[IPv4] +SendHostname=true diff --git a/autotests/testNetconfig/timeout_test.py b/autotests/testNetconfig/timeout_test.py @@ -0,0 +1,65 @@ +import unittest +import sys +import os + +sys.path.append('../util') +from iwd import IWD +from iwd import PSKAgent +from iwd import NetworkType + +class Test(unittest.TestCase): + + def test_netconfig_timeout(self): + IWD.copy_to_storage('autoconnect.psk', name='ap-ns1.psk') + + wd = IWD(True) + + psk_agent = PSKAgent("secret123") + wd.register_psk_agent(psk_agent) + + devices = wd.list_devices(1) + device = devices[0] + + ordered_network = device.get_ordered_network('ap-ns1') + + 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() + + condition = 'obj.state == DeviceState.connecting' + wd.wait_for_object_condition(device, condition) + + device.wait_for_event("connecting (netconfig)") + + # Netconfig should fail, and IWD should disconnect + from_condition = 'obj.state == DeviceState.connecting' + to_condition = 'obj.state == DeviceState.disconnecting' + wd.wait_for_object_change(device, from_condition, to_condition, max_wait=60) + + # Autoconnect should then try again + condition = 'obj.state == DeviceState.connecting' + wd.wait_for_object_condition(device, condition) + + device.wait_for_event("connecting (netconfig)") + + device.disconnect() + condition = 'obj.state == DeviceState.disconnected' + wd.wait_for_object_condition(device, condition) + + @classmethod + def setUpClass(cls): + cls.orig_path = os.environ['PATH'] + os.environ['PATH'] = '/tmp/test-bin:' + os.environ['PATH'] + IWD.copy_to_storage('resolvconf', '/tmp/test-bin') + + @classmethod + def tearDownClass(cls): + IWD.clear_storage() + os.system('rm -rf /tmp/radvd.conf /tmp/resolvconf.log /tmp/test-bin') + os.environ['PATH'] = cls.orig_path + +if __name__ == '__main__': + unittest.main(exit=True) diff --git a/autotests/testNetconfigRoam/TestFT.psk b/autotests/testNetconfigRoam/TestFT.psk @@ -0,0 +1,2 @@ +[Security] +Passphrase=EasilyGuessedPassword diff --git a/autotests/testNetconfigRoam/ft-psk-ccmp-1.conf b/autotests/testNetconfigRoam/ft-psk-ccmp-1.conf @@ -0,0 +1,41 @@ +hw_mode=g +channel=1 +ssid=TestFT +utf8_ssid=1 +ctrl_interface=/var/run/hostapd + +r1_key_holder=120000000001 +nas_identifier=dummy1 + +wpa=2 +# Can support WPA-PSK and FT-PSK (space separated list) and/or EAP at the same +# time but we want to force FT +wpa_key_mgmt=FT-PSK +wpa_pairwise=CCMP +wpa_passphrase=EasilyGuessedPassword +ieee80211w=1 +rsn_preauth=1 +rsn_preauth_interfaces=lo +disable_pmksa_caching=0 +# Allow PMK cache to be shared opportunistically among configured interfaces +# and BSSes (i.e., all configurations within a single hostapd process). +okc=1 +mobility_domain=1234 +reassociation_deadline=60000 +r0kh=12:00:00:00:00:01 dummy1 000102030405060708090a0b0c0d0e0f +r0kh=12:00:00:00:00:02 dummy2 000102030405060708090a0b0c0d0e0f +r1kh=12:00:00:00:00:01 00:00:00:00:00:01 000102030405060708090a0b0c0d0e0f +r1kh=12:00:00:00:00:02 00:00:00:00:00:02 000102030405060708090a0b0c0d0e0f +# Push mode only needed for 8021x, not PSK mode since msk already known +pmk_r1_push=0 +# Allow locally generated FT response so we don't have to configure push/pull +# between BSSes running as separate hostapd processes as in the test-runner +# case. Only works with FT-PSK, otherwise brctl needs to be installed and +# CONFIG_BRIDGE enabled in the kernel. +ft_psk_generate_local=1 +rkh_pull_timeout=50 +ft_over_ds=0 +ap_table_expiration_time=36000 +ap_table_max_size=10 +rrm_neighbor_report=1 +ocv=1 diff --git a/autotests/testNetconfigRoam/ft-psk-ccmp-2.conf b/autotests/testNetconfigRoam/ft-psk-ccmp-2.conf @@ -0,0 +1,41 @@ +hw_mode=g +channel=2 +ssid=TestFT +utf8_ssid=1 +ctrl_interface=/var/run/hostapd + +r1_key_holder=120000000002 +nas_identifier=dummy2 + +wpa=2 +# Can support WPA-PSK and FT-PSK (space separated list) and/or EAP at the same +# time but we want to force FT +wpa_key_mgmt=FT-PSK +wpa_pairwise=CCMP +wpa_passphrase=EasilyGuessedPassword +ieee80211w=1 +rsn_preauth=1 +rsn_preauth_interfaces=lo +disable_pmksa_caching=0 +# Allow PMK cache to be shared opportunistically among configured interfaces +# and BSSes (i.e., all configurations within a single hostapd process). +okc=1 +mobility_domain=1234 +reassociation_deadline=60000 +r0kh=12:00:00:00:00:01 dummy1 000102030405060708090a0b0c0d0e0f +r0kh=12:00:00:00:00:02 dummy2 000102030405060708090a0b0c0d0e0f +r1kh=12:00:00:00:00:01 00:00:00:00:00:01 000102030405060708090a0b0c0d0e0f +r1kh=12:00:00:00:00:02 00:00:00:00:00:02 000102030405060708090a0b0c0d0e0f +# Push mode only needed for 8021x, not PSK mode since msk already known +pmk_r1_push=0 +# Allow locally generated FT response so we don't have to configure push/pull +# between BSSes running as separate hostapd processes as in the test-runner +# case. Only works with FT-PSK, otherwise brctl needs to be installed and +# CONFIG_BRIDGE enabled in the kernel. +ft_psk_generate_local=1 +rkh_pull_timeout=50 +ft_over_ds=0 +ap_table_expiration_time=36000 +ap_table_max_size=10 +rrm_neighbor_report=1 +ocv=1 diff --git a/autotests/testNetconfigRoam/hw.conf b/autotests/testNetconfigRoam/hw.conf @@ -0,0 +1,8 @@ +[SETUP] +num_radios=3 +start_iwd=0 +hwsim_medium=yes + +[HOSTAPD] +rad0=ft-psk-ccmp-1.conf +rad1=ft-psk-ccmp-2.conf diff --git a/autotests/testNetconfigRoam/main.conf b/autotests/testNetconfigRoam/main.conf @@ -0,0 +1,3 @@ +[General] +EnableNetworkConfiguration=true +RoamRetryInterval=1 diff --git a/autotests/testNetconfigRoam/netconfig_roam_test.py b/autotests/testNetconfigRoam/netconfig_roam_test.py @@ -0,0 +1,91 @@ +#! /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 iwd import DeviceState +from hwsim import Hwsim +from hostapd import HostapdCLI +import testutil + +class Test(unittest.TestCase): + def test_roam_before_netconfig(self): + wd = IWD(True) + + device = wd.list_devices(1)[0] + device.get_ordered_network('TestFT', full_scan=True) + device.connect_bssid(self.bss_hostapd[1].bssid) + + self.bss_hostapd[1].wait_for_event(f'AP-STA-CONNECTED {device.address}') + device.wait_for_event("connecting (netconfig)") + + roam_to = 0 + roam_from = 1 + + # Roam back and forth, ensuring that the state transitions between + # roaming and connecting (netconfig). + for _ in range(0, 5): + self.rules[roam_to].signal = -2000 + self.rules[roam_from].signal = -8000 + + # Station should internally transition to roaming, but remain in a + # connecting state on DBus + device.wait_for_event("ft-roaming") + self.assertEqual(device.state, DeviceState.connecting) + + self.bss_hostapd[roam_to].wait_for_event(f'AP-STA-CONNECTED {device.address}') + device.wait_for_event("connecting (netconfig)") + + tmp = roam_from + roam_from = roam_to + roam_to = tmp + + self.bss_hostapd[roam_from].deauthenticate(device.address) + condition = 'obj.state == DeviceState.disconnected' + 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') + + @classmethod + def setUpClass(cls): + hwsim = Hwsim() + + IWD.copy_to_storage('TestFT.psk') + + cls.bss_hostapd = [ HostapdCLI(config='ft-psk-ccmp-1.conf'), + HostapdCLI(config='ft-psk-ccmp-2.conf') ] + + rule0 = hwsim.rules.create() + rule0.source = cls.bss_hostapd[0].bssid + rule0.signal = -6000 + rule0.enabled = True + + rule1 = hwsim.rules.create() + rule1.source = cls.bss_hostapd[1].bssid + rule1.signal = -2000 + rule1.enabled = True + + cls.rules = [rule0, rule1] + + 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) + + @classmethod + def tearDownClass(cls): + IWD.clear_storage() + cls.bss_hostapd = None + cls.rules = None + +if __name__ == '__main__': + unittest.main(exit=True) diff --git a/autotests/testPSK-roam/connection_test.py b/autotests/testPSK-roam/connection_test.py @@ -91,13 +91,9 @@ class Test(unittest.TestCase): wd.wait_for_object_condition(device, condition) def test_ft_psk(self): - wd = IWD(True) - - self.validate_connection(wd) + self.validate_connection(self.wd) def test_ft_psk_over_ds(self): - wd = IWD(True) - self.bss_hostapd[0].set_value('ft_over_ds', '1') self.bss_hostapd[0].reload() self.bss_hostapd[0].wait_for_event("AP-ENABLED") @@ -106,11 +102,9 @@ class Test(unittest.TestCase): self.bss_hostapd[1].reload() self.bss_hostapd[1].wait_for_event("AP-ENABLED") - self.validate_connection(wd, over_ds=True) + self.validate_connection(self.wd, over_ds=True) def test_reassociate_psk(self): - wd = IWD(True) - 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") @@ -119,12 +113,10 @@ class Test(unittest.TestCase): self.bss_hostapd[1].reload() self.bss_hostapd[1].wait_for_event("AP-ENABLED") - self.validate_connection(wd) + self.validate_connection(self.wd) def test_roam_packet_loss(self): - wd = IWD(True) - - self.validate_connection(wd, pkt_loss=True) + self.validate_connection(self.wd, pkt_loss=True) def tearDown(self): os.system('ip link set "' + self.bss_hostapd[0].ifname + '" down') @@ -139,6 +131,12 @@ class Test(unittest.TestCase): 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): hwsim = Hwsim() @@ -146,9 +144,10 @@ class Test(unittest.TestCase): 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') ] - cls.bss_hostapd[2].disable() + HostapdCLI(config='ft-psk-ccmp-2.conf') ] + + unused = HostapdCLI(config='ft-psk-ccmp-3.conf') + unused.disable() rad0 = hwsim.get_radio('rad0') rad3 = hwsim.get_radio('rad3') @@ -178,8 +177,9 @@ class Test(unittest.TestCase): def tearDownClass(cls): IWD.clear_storage() cls.bss_hostapd = None - cls.rule0.enabled = False cls.rule0.remove() + cls.rule1.remove() + cls.rule2.remove() if __name__ == '__main__': unittest.main(exit=True) diff --git a/autotests/testPSK-roam/failed_roam_test.py b/autotests/testPSK-roam/failed_roam_test.py @@ -46,11 +46,9 @@ class Test(unittest.TestCase): self.rule2.enabled = True self.rule3.enabled = True - wd = IWD(True) + device = self.wd.list_devices(1)[0] - device = wd.list_devices(1)[0] - - self.connect(wd, device, self.bss_hostapd[0]) + self.connect(self.wd, device, self.bss_hostapd[0]) self.rule0.enabled = True @@ -62,11 +60,26 @@ class Test(unittest.TestCase): self.rule0.enabled = False # IWD should then try BSS 2, and succeed - device.wait_for_event('ft-roam', timeout=60) - self.verify_roam(wd, device, self.bss_hostapd[0], self.bss_hostapd[2]) + device.wait_for_event('ft-roaming', timeout=60) + self.verify_roam(self.wd, device, self.bss_hostapd[0], self.bss_hostapd[2]) self.bss_hostapd[2].deauthenticate(device.address) + # Tests that an associate even should cause a disconnect + def test_ft_over_air_assoc_timeout(self): + self.rule2.enabled = True + self.rule3.enabled = True + self.assoc_rule.enabled = True + + device = self.wd.list_devices(1)[0] + + self.connect(self.wd, device, self.bss_hostapd[0]) + + device.wait_for_event('ft-roaming', timeout=60) + + condition = 'obj.state == DeviceState.disconnected' + self.wd.wait_for_object_condition(device, condition) + # FT-over-Air failure with Invalid PMKID, should reassociate def test_ft_over_air_fallback(self): self.rule_bss0.signal = -8000 @@ -81,30 +94,28 @@ class Test(unittest.TestCase): self.bss_hostapd[2].set_value('ft_psk_generate_local', '0') self.bss_hostapd[2].reload() - wd = IWD(True) - - device = wd.list_devices(1)[0] + device = self.wd.list_devices(1)[0] - self.connect(wd, device, self.bss_hostapd[0]) + self.connect(self.wd, device, self.bss_hostapd[0]) # IWD should connect, then attempt a roam to BSS 1, which should # fail and cause a fallback to reassociation device.wait_for_event('ft-fallback-to-reassoc', timeout=60) - device.wait_for_event('reassoc-roam', timeout=60) + device.wait_for_event('roaming', timeout=60) - self.verify_roam(wd, device, self.bss_hostapd[0], self.bss_hostapd[2]) + self.verify_roam(self.wd, device, self.bss_hostapd[0], self.bss_hostapd[2]) # Trigger another roam self.rule_bss2.signal = -8000 - device.wait_for_event('ft-roam', timeout=60) + device.wait_for_event('ft-roaming', timeout=60) # Ensure an FT roam back to a properly configured AP works. - self.verify_roam(wd, device, self.bss_hostapd[2], self.bss_hostapd[1]) + self.verify_roam(self.wd, device, self.bss_hostapd[2], self.bss_hostapd[1]) self.bss_hostapd[1].deauthenticate(device.address) condition = 'obj.state == DeviceState.disconnected' - wd.wait_for_object_condition(device, condition) + self.wd.wait_for_object_condition(device, condition) # FT-over-Air failure with Invalid PMKID. The ranking is such that other # FT candidates are available so it should FT elsewhere rather than @@ -122,24 +133,24 @@ class Test(unittest.TestCase): self.bss_hostapd[2].set_value('ft_psk_generate_local', '0') self.bss_hostapd[2].reload() - wd = IWD(True) - - device = wd.list_devices(1)[0] + device = self.wd.list_devices(1)[0] - self.connect(wd, device, self.bss_hostapd[0]) + self.connect(self.wd, device, self.bss_hostapd[0]) # IWD should connect, then attempt a roam to BSS 1, which should # fail and cause the rank to be re-computed. This should then put # bss 1 as the next candidate (since the FT factor is removed) device.wait_for_event('ft-fallback-to-reassoc', timeout=60) - device.wait_for_event('ft-roam', timeout=60) + device.wait_for_event('ft-roaming', timeout=60) - self.verify_roam(wd, device, self.bss_hostapd[0], self.bss_hostapd[1]) + self.verify_roam(self.wd, device, self.bss_hostapd[0], self.bss_hostapd[1]) self.bss_hostapd[1].deauthenticate(device.address) condition = 'obj.state == DeviceState.disconnected' - wd.wait_for_object_condition(device, condition) + self.wd.wait_for_object_condition(device, condition) + def setUp(self): + self.wd = IWD(True) def tearDown(self): os.system('ip link set "' + self.bss_hostapd[0].ifname + '" down') @@ -154,10 +165,14 @@ class Test(unittest.TestCase): self.rule_bss0.enabled = False self.rule_bss1.enabled = False self.rule_bss2.enabled = False + self.assoc_rule.enabled = False for hapd in self.bss_hostapd: hapd.default() + self.wd.stop() + self.wd = None + @classmethod def setUpClass(cls): hwsim = Hwsim() @@ -178,6 +193,11 @@ class Test(unittest.TestCase): cls.rule0.prefix = 'b0' cls.rule0.drop = True + # Drop Associate frames + cls.assoc_rule = hwsim.rules.create() + cls.assoc_rule.prefix = '20' + cls.assoc_rule.drop = True + # Drop Action frames cls.rule1 = hwsim.rules.create() cls.rule1.bidirectional = True @@ -207,6 +227,9 @@ class Test(unittest.TestCase): cls.bss_hostapd = None cls.rule0.remove() cls.rule1.remove() + cls.rule2.remove() + cls.rule3.remove() + cls.assoc_rule.remove() if __name__ == '__main__': unittest.main(exit=True) diff --git a/autotests/testPSK-roam/roam_ap_disconnect_test.py b/autotests/testPSK-roam/roam_ap_disconnect_test.py @@ -14,8 +14,7 @@ class Test(unittest.TestCase): # Tests a crash reported where multiple roam scans combined with an AP # disconnect result in a crash getting scan results. # - def validate(self): - wd = IWD(True) + def validate(self, wd): device = wd.list_devices(1)[0] ordered_network = device.get_ordered_network('TestFT', full_scan=True) @@ -43,14 +42,15 @@ class Test(unittest.TestCase): wd.wait_for_object_condition(device, condition) def test_ap_disconnect_no_neighbors(self): - self.validate() + self.validate(self.wd) def test_ap_disconnect_neighbors(self): HostapdCLI.group_neighbors(*self.bss_hostapd) - self.validate() + self.validate(self.wd) def setUp(self): + self.wd = IWD(True) self.bss_hostapd[0].reload() self.bss_hostapd[0].wait_for_event("AP-ENABLED") @@ -63,6 +63,9 @@ class Test(unittest.TestCase): self.bss_hostapd[0].remove_neighbor(self.bss_hostapd[1].bssid) self.bss_hostapd[1].remove_neighbor(self.bss_hostapd[0].bssid) + self.wd.stop() + self.wd = None + @classmethod def setUpClass(cls): hwsim = Hwsim() diff --git a/autotests/testSAE/autoconnect_test.py b/autotests/testSAE/autoconnect_test.py @@ -35,12 +35,23 @@ class Test(unittest.TestCase): wd.wait_for_object_condition(ordered_network.network_object, condition) def test_SAE(self): + IWD.copy_to_storage("ssidSAE.psk.default", name="ssidSAE.psk") self.hostapd.wait_for_event("AP-ENABLED") wd = IWD(True) self.validate_connection(wd) def test_SAE_H2E(self): + IWD.copy_to_storage("ssidSAE.psk.default", name="ssidSAE.psk") + self.hostapd.set_value('sae_pwe', '1') + self.hostapd.set_value('sae_groups', '20') + self.hostapd.reload() + self.hostapd.wait_for_event("AP-ENABLED") + wd = IWD(True) + self.validate_connection(wd) + + def test_SAE_H2E_password_identifier(self): + IWD.copy_to_storage("ssidSAE.psk.identifier", name="ssidSAE.psk") self.hostapd.set_value('sae_pwe', '1') self.hostapd.set_value('sae_groups', '20') self.hostapd.reload() @@ -51,15 +62,12 @@ class Test(unittest.TestCase): def setUp(self): self.hostapd.default() + def tearDown(self): + IWD.clear_storage() + @classmethod def setUpClass(cls): cls.hostapd = HostapdCLI(config='ssidSAE.conf') - IWD.copy_to_storage('ssidSAE.psk') - pass - - @classmethod - def tearDownClass(cls): - IWD.clear_storage() if __name__ == '__main__': unittest.main(exit=True) diff --git a/autotests/testSAE/failure_test.py b/autotests/testSAE/failure_test.py @@ -37,7 +37,7 @@ class Test(unittest.TestCase): self.validate_connection(wd, 'InvalidSecret') def test_no_supported_groups(self): - self.hostapd.set_value('sae_groups', '1') + self.hostapd.set_value('sae_groups', '21') self.hostapd.reload() wd = IWD(True) diff --git a/autotests/testSAE/ssidSAE.conf b/autotests/testSAE/ssidSAE.conf @@ -5,7 +5,8 @@ ssid=ssidSAE wpa=2 wpa_key_mgmt=SAE wpa_pairwise=CCMP -sae_password=secret123|mac=ff:ff:ff:ff:ff:ff +sae_password=secret123 +sae_password=withidentifier|id=myidentifier sae_groups=19 ieee80211w=2 sae_pwe=0 diff --git a/autotests/testSAE/ssidSAE.psk b/autotests/testSAE/ssidSAE.psk.default diff --git a/autotests/testSAE/ssidSAE.psk.identifier b/autotests/testSAE/ssidSAE.psk.identifier @@ -0,0 +1,3 @@ +[Security] +Passphrase=withidentifier +PasswordIdentifier=myidentifier diff --git a/autotests/util/hostapd.py b/autotests/util/hostapd.py @@ -75,6 +75,8 @@ class HostapdCLI(object): if self._default_config.get('vendor_elements', None) == None: self._default_config['vendor_elements'] = '' + self._current_config = self._default_config.copy() + if not self.interface: raise Exception('config %s not found' % config) @@ -170,6 +172,8 @@ class HostapdCLI(object): if self._default_config.get(key, None) == None: raise Exception("Untracked setting '%s'! Please set default in hostapd config" % key) + self._current_config[key] = value + cmd = self.cmdline + ['set', key, value] ctx.start_process(cmd).wait() @@ -200,7 +204,10 @@ class HostapdCLI(object): def default(self): for k, v in self._default_config.items(): - self.set_value(k, v) + # Only bother setting the value if it differs + if self._current_config[k] != v: + self.set_value(k, v) + self._current_config[k] = v self.reload() diff --git a/autotests/util/iwd.py b/autotests/util/iwd.py @@ -201,9 +201,9 @@ class SignalAgent(dbus.service.Object): return self._path @dbus.service.method(IWD_SIGNAL_AGENT_INTERFACE, - in_signature='', out_signature='') - def Release(self): - print("SignalAgent released") + in_signature='o', out_signature='') + def Release(self, path): + print("SignalAgent released %s" % path) @dbus.service.method(IWD_SIGNAL_AGENT_INTERFACE, in_signature='oy', out_signature='') @@ -1363,6 +1363,10 @@ class IWD(AsyncOpAbstract): self.psk_agents = [] + def stop(self): + if self.namespace.is_process_running('iwd'): + self._iwd_proc.kill() + def __del__(self): for agent in self.psk_agents: self.unregister_psk_agent(agent) diff --git a/client/ap.c b/client/ap.c @@ -162,18 +162,27 @@ static const char *get_freq_tostr(const void *data) static void update_pairwise(void *data, struct l_dbus_message_iter *variant) { struct ap *ap = data; + struct l_dbus_message_iter array; char *value; + char **strv; + if (ap->pairwise) l_free(ap->pairwise); - if (!l_dbus_message_iter_get_variant(variant, "s", &value)) { + if (!l_dbus_message_iter_get_variant(variant, "as", &array)) { ap->pairwise = NULL; return; } - ap->pairwise = l_strdup(value); + strv = l_strv_new(); + + while (l_dbus_message_iter_next_entry(&array, &value)) + strv = l_strv_append(strv, value); + + ap->pairwise = l_strjoinv(strv, ' '); + l_strv_free(strv); } static const char *get_pairwise_tostr(const void *data) diff --git a/configure.ac b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.69]) -AC_INIT([iwd],[2.10]) +AC_INIT([iwd],[2.14]) AC_CONFIG_HEADERS(config.h) AC_CONFIG_AUX_DIR(build-aux) @@ -44,7 +44,7 @@ AC_ARG_ENABLE(optimization, AS_HELP_STRING([--disable-optimization], if (test "${enable_optimization}" != "no"); then CFLAGS="$CFLAGS -O2" - CFLAGS+=" -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2" + CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2" fi AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug], @@ -302,7 +302,7 @@ if (test "${enable_external_ell}" = "yes"); then test "${enable_monitor}" != "no" || test "${enable_wired}" = "yes" || test "${enable_hwsim}" = "yes"); then - ell_min_version="0.61" + ell_min_version="0.62" else ell_min_version="0.5" fi diff --git a/monitor/main.c b/monitor/main.c @@ -32,10 +32,14 @@ #include <string.h> #include <getopt.h> #include <signal.h> +#include <unistd.h> +#include <arpa/inet.h> #include <sys/socket.h> #include <linux/genetlink.h> #include <linux/rtnetlink.h> #include <linux/if_arp.h> +#include <linux/filter.h> +#include <sys/ioctl.h> #include <ell/ell.h> #ifndef ARPHRD_NETLINK @@ -68,11 +72,160 @@ static struct nlmon_config config; #define NLMON_TYPE "nlmon" #define NLMON_LEN 5 +static bool nlmon_receive(struct l_io *io, void *user_data) +{ + struct nlmon *nlmon = user_data; + struct msghdr msg; + struct sockaddr_ll sll; + struct iovec iov; + struct cmsghdr *cmsg; + struct timeval copy_tv; + const struct timeval *tv = NULL; + uint16_t proto_type; + unsigned char buf[8192]; + unsigned char control[32]; + ssize_t bytes_read; + int fd; + + fd = l_io_get_fd(io); + if (fd < 0) + return false; + + memset(&sll, 0, sizeof(sll)); + + memset(&iov, 0, sizeof(iov)); + iov.iov_base = buf; + iov.iov_len = sizeof(buf); + + memset(&msg, 0, sizeof(msg)); + msg.msg_name = &sll; + msg.msg_namelen = sizeof(sll); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = control; + msg.msg_controllen = sizeof(control); + + bytes_read = recvmsg(fd, &msg, 0); + if (bytes_read < 0) { + if (errno != EAGAIN && errno != EINTR) + return false; + + return true; + } + + if (sll.sll_hatype != ARPHRD_NETLINK) + return true; + + proto_type = ntohs(sll.sll_protocol); + + for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; + cmsg = CMSG_NXTHDR(&msg, cmsg)) { + if (cmsg->cmsg_level == SOL_SOCKET && + cmsg->cmsg_type == SCM_TIMESTAMP) { + memcpy(&copy_tv, CMSG_DATA(cmsg), sizeof(copy_tv)); + tv = &copy_tv; + } + } + + switch (proto_type) { + case NETLINK_ROUTE: + nlmon_print_rtnl(nlmon, tv, iov.iov_base, bytes_read); + break; + case NETLINK_GENERIC: + nlmon_print_genl(nlmon, tv, iov.iov_base, bytes_read); + break; + } + + return true; +} + +/* + * BPF filter to match skb->dev->type == 824 (ARPHRD_NETLINK) and + * either match skb->protocol == 0x0000 (NETLINK_ROUTE) or match + * skb->protocol == 0x0010 (NETLINK_GENERIC). + */ +static struct sock_filter mon_filter[] = { + { 0x28, 0, 0, 0xfffff01c }, /* ldh #hatype */ + { 0x15, 0, 3, 0x00000338 }, /* jne #824, drop */ + { 0x28, 0, 0, 0xfffff000 }, /* ldh #proto */ + { 0x15, 2, 0, 0000000000 }, /* jeq #0x0000, pass */ + { 0x15, 1, 0, 0x00000010 }, /* jeq #0x0010, pass */ + { 0x06, 0, 0, 0000000000 }, /* drop: ret #0 */ + { 0x06, 0, 0, 0xffffffff }, /* pass: ret #-1 */ +}; + +static const struct sock_fprog mon_fprog = { .len = 7, .filter = mon_filter }; + +static struct l_io *open_packet(const char *name) +{ + struct l_io *io; + struct sockaddr_ll sll; + struct packet_mreq mr; + struct ifreq ifr; + int fd, opt = 1; + + fd = socket(PF_PACKET, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, 0); + if (fd < 0) { + perror("Failed to create packet socket"); + return NULL; + } + + strncpy(ifr.ifr_name, name, IFNAMSIZ - 1); + + if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) { + perror("Failed to get monitor index"); + close(fd); + return NULL; + } + + memset(&sll, 0, sizeof(sll)); + sll.sll_family = AF_PACKET; + sll.sll_protocol = htons(ETH_P_ALL); + sll.sll_ifindex = ifr.ifr_ifindex; + + if (bind(fd, (struct sockaddr *) &sll, sizeof(sll)) < 0) { + perror("Failed to bind packet socket"); + close(fd); + return NULL; + } + + memset(&mr, 0, sizeof(mr)); + mr.mr_ifindex = ifr.ifr_ifindex; + mr.mr_type = PACKET_MR_ALLMULTI; + + if (setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, + &mr, sizeof(mr)) < 0) { + perror("Failed to enable all multicast"); + close(fd); + return NULL; + } + + if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, + &mon_fprog, sizeof(mon_fprog)) < 0) { + perror("Failed to enable monitor filter"); + close(fd); + return NULL; + } + + if (setsockopt(fd, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt)) < 0) { + perror("Failed to enable monitor timestamps"); + close(fd); + return NULL; + } + + io = l_io_new(fd); + + l_io_set_close_on_destroy(io, true); + + return io; +} + struct iwmon_interface { char *ifname; bool exists; struct l_netlink *rtnl; struct l_netlink *genl; + struct l_io *io; }; static struct iwmon_interface monitor_interface = { }; @@ -109,11 +262,23 @@ static void genl_parse(uint16_t type, const void *data, uint32_t len, if (id == 0) return; - if (!strcmp(name, NL80211_GENL_NAME)) { - nlmon = nlmon_open(ifname, id, writer_path, &config); - if (!nlmon) - l_main_quit(); - } + if (strcmp(name, NL80211_GENL_NAME)) + return; + + monitor_interface.io = open_packet(ifname); + if (!monitor_interface.io) + goto failed; + + nlmon = nlmon_open(id, writer_path, &config); + if (!nlmon) + goto failed; + + l_io_set_read_handler(monitor_interface.io, nlmon_receive, nlmon, NULL); + + return; + +failed: + l_main_quit(); } static void genl_notify(uint16_t type, const void *data, @@ -790,6 +955,7 @@ int main(int argc, char *argv[]) exit_status = l_main_run_with_signal(signal_handler, NULL); + l_io_destroy(monitor_interface.io); l_netlink_destroy(monitor_interface.rtnl); l_netlink_destroy(monitor_interface.genl); l_free(monitor_interface.ifname); diff --git a/monitor/nlmon.c b/monitor/nlmon.c @@ -96,7 +96,6 @@ enum msg_type { struct nlmon { uint16_t id; - struct l_io *io; struct l_io *pae_io; struct l_queue *req_list; struct pcap *pcap; @@ -5128,6 +5127,16 @@ static void print_probe_response(unsigned int level, (const uint8_t *) mmpdu + len - resp->ies); } +static void print_probe_request(unsigned int level, + const struct mmpdu_header *mmpdu, size_t len) +{ + const struct mmpdu_probe_request *req = mmpdu_body(mmpdu); + + print_attr(level, "Subtype: Probe Request"); + print_ie(level + 1, "Probe Request IEs", req->ies, + (const uint8_t *) mmpdu + len - req->ies); +} + static void print_beacon(unsigned int level, const struct mmpdu_header *mmpdu, size_t len) { @@ -5165,7 +5174,10 @@ static void print_frame_type(unsigned int level, const char *label, switch (subtype) { case 0x00: - str = "Association request"; + if (mpdu) + str = "Association request"; + else + str = "Association request (invalid MPDU)"; break; case 0x01: if (mpdu) @@ -5174,19 +5186,28 @@ static void print_frame_type(unsigned int level, const char *label, str = "Association response"; break; case 0x02: - str = "Reassociation request"; + if (mpdu) + str = "Reassociation request"; + else + str = "Reassociation request (invalid MPDU)"; break; case 0x03: - str = "Reassociation response"; + if (mpdu) + str = "Reassociation response"; + else + str = "Reassociation response (invalid MPDU)"; break; case 0x04: - str = "Probe request"; + if (mpdu) + print_probe_request(level + 1, mpdu, size); + else + str = "Probe request (invalid MPDU)"; break; case 0x05: if (mpdu) print_probe_response(level + 1, mpdu, size); else - str = "Probe response"; + str = "Probe response (invalid MPDU)"; break; case 0x06: str = "Timing Advertisement"; @@ -5195,25 +5216,28 @@ static void print_frame_type(unsigned int level, const char *label, if (mpdu) print_beacon(level + 1, mpdu, size); else - str = "Beacon"; + str = "Beacon (invalid MPDU)"; break; case 0x09: str = "ATIM"; break; case 0x0a: - str = "Disassociation"; + if (mpdu) + str = "Disassociation"; + else + str = "Disassociation (invalid MPDU)"; break; case 0x0b: if (mpdu) print_authentication_mgmt_frame(level + 1, mpdu, size); else - str = "Authentication"; + str = "Authentication (invalid MPDU)"; break; case 0x0c: if (mpdu) print_deauthentication_mgmt_frame(level + 1, mpdu); else - str = "Deauthentication"; + str = "Deauthentication (invalid MPDU)"; break; case 0x0d: case 0x0e: @@ -7240,7 +7264,6 @@ static void store_message(struct nlmon *nlmon, const struct timeval *tv, } static void nlmon_message(struct nlmon *nlmon, const struct timeval *tv, - const struct tpacket_auxdata *tp, const struct nlmsghdr *nlmsg) { struct nlmon_req *req; @@ -7281,12 +7304,6 @@ static void nlmon_message(struct nlmon *nlmon, const struct timeval *tv, return; } - if (!nlmon->read && nlmsg->nlmsg_type != nlmon->id) { - if (nlmsg->nlmsg_type == GENL_ID_CTRL) - store_message(nlmon, tv, nlmsg); - return; - } - if (nlmsg->nlmsg_flags & NLM_F_REQUEST) { const struct genlmsghdr *genlmsg = NLMSG_DATA(nlmsg); uint32_t flags = nlmsg->nlmsg_flags & ~NLM_F_REQUEST; @@ -7359,35 +7376,6 @@ void nlmon_destroy(struct nlmon *nlmon) l_free(nlmon); } -static void genl_ctrl(struct nlmon *nlmon, const void *data, uint32_t len) -{ - const struct genlmsghdr *genlmsg = data; - const struct nlattr *nla; - char name[GENL_NAMSIZ]; - uint16_t id = 0; - - if (genlmsg->cmd != CTRL_CMD_NEWFAMILY) - return; - - for (nla = data + GENL_HDRLEN; NLA_OK(nla, len); - nla = NLA_NEXT(nla, len)) { - switch (nla->nla_type & NLA_TYPE_MASK) { - case CTRL_ATTR_FAMILY_ID: - id = *((uint16_t *) NLA_DATA(nla)); - break; - case CTRL_ATTR_FAMILY_NAME: - strncpy(name, NLA_DATA(nla), GENL_NAMSIZ - 1); - break; - } - } - - if (id == 0) - return; - - if (!strcmp(name, NL80211_GENL_NAME)) - nlmon->id = id; -} - static const char *scope_to_string(uint8_t scope) { switch (scope) { @@ -8167,13 +8155,15 @@ void nlmon_print_rtnl(struct nlmon *nlmon, const struct timeval *tv, int64_t aligned_size = NLMSG_ALIGN(size); const struct nlmsghdr *nlmsg; - if (nlmon->nortnl) - return; - update_time_offset(tv); for (nlmsg = data; NLMSG_OK(nlmsg, aligned_size); nlmsg = NLMSG_NEXT(nlmsg, aligned_size)) { + store_netlink(nlmon, tv, NETLINK_ROUTE, nlmsg); + + if (nlmon->nortnl) + continue; + switch (nlmsg->nlmsg_type) { case NLMSG_NOOP: case NLMSG_OVERRUN: @@ -8207,177 +8197,16 @@ void nlmon_print_genl(struct nlmon *nlmon, const struct timeval *tv, for (nlmsg = data; NLMSG_OK(nlmsg, size); nlmsg = NLMSG_NEXT(nlmsg, size)) { - if (nlmsg->nlmsg_type == GENL_ID_CTRL) - genl_ctrl(nlmon, NLMSG_DATA(nlmsg), - NLMSG_PAYLOAD(nlmsg, 0)); - else - nlmon_message(nlmon, tv, NULL, nlmsg); - } -} - -static bool nlmon_receive(struct l_io *io, void *user_data) -{ - struct nlmon *nlmon = user_data; - struct nlmsghdr *nlmsg; - struct msghdr msg; - struct sockaddr_ll sll; - struct iovec iov; - struct cmsghdr *cmsg; - struct timeval copy_tv; - struct tpacket_auxdata copy_tp; - const struct timeval *tv = NULL; - const struct tpacket_auxdata *tp = NULL; - uint16_t proto_type; - unsigned char buf[8192]; - unsigned char control[32]; - ssize_t bytes_read; - int64_t nlmsg_len; - int fd; - - fd = l_io_get_fd(io); - if (fd < 0) - return false; - - memset(&sll, 0, sizeof(sll)); - - memset(&iov, 0, sizeof(iov)); - iov.iov_base = buf; - iov.iov_len = sizeof(buf); - - memset(&msg, 0, sizeof(msg)); - msg.msg_name = &sll; - msg.msg_namelen = sizeof(sll); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - msg.msg_control = control; - msg.msg_controllen = sizeof(control); - - bytes_read = recvmsg(fd, &msg, 0); - if (bytes_read < 0) { - if (errno != EAGAIN && errno != EINTR) - return false; - - return true; - } - - if (sll.sll_hatype != ARPHRD_NETLINK) - return true; - - proto_type = ntohs(sll.sll_protocol); - - for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; - cmsg = CMSG_NXTHDR(&msg, cmsg)) { - if (cmsg->cmsg_level == SOL_SOCKET && - cmsg->cmsg_type == SCM_TIMESTAMP) { - memcpy(&copy_tv, CMSG_DATA(cmsg), sizeof(copy_tv)); - tv = &copy_tv; - } - - if (cmsg->cmsg_level == SOL_PACKET && - cmsg->cmsg_type != PACKET_AUXDATA) { - memcpy(&copy_tp, CMSG_DATA(cmsg), sizeof(copy_tp)); - tp = &copy_tp; - } - } - - nlmsg_len = bytes_read; - - for (nlmsg = iov.iov_base; NLMSG_OK(nlmsg, nlmsg_len); - nlmsg = NLMSG_NEXT(nlmsg, nlmsg_len)) { - switch (proto_type) { - case NETLINK_ROUTE: - store_netlink(nlmon, tv, proto_type, nlmsg); - - nlmon_print_rtnl(nlmon, tv, nlmsg, nlmsg->nlmsg_len); - break; - case NETLINK_GENERIC: - nlmon_message(nlmon, tv, tp, nlmsg); - break; + if (nlmsg->nlmsg_type == GENL_ID_CTRL) { + store_message(nlmon, tv, nlmsg); + continue; } - } - - return true; -} - -/* - * BPF filter to match skb->dev->type == 824 (ARPHRD_NETLINK) and - * either match skb->protocol == 0x0000 (NETLINK_ROUTE) or match - * skb->protocol == 0x0010 (NETLINK_GENERIC). - */ -static struct sock_filter mon_filter[] = { - { 0x28, 0, 0, 0xfffff01c }, /* ldh #hatype */ - { 0x15, 0, 3, 0x00000338 }, /* jne #824, drop */ - { 0x28, 0, 0, 0xfffff000 }, /* ldh #proto */ - { 0x15, 2, 0, 0000000000 }, /* jeq #0x0000, pass */ - { 0x15, 1, 0, 0x00000010 }, /* jeq #0x0010, pass */ - { 0x06, 0, 0, 0000000000 }, /* drop: ret #0 */ - { 0x06, 0, 0, 0xffffffff }, /* pass: ret #-1 */ -}; - -static const struct sock_fprog mon_fprog = { .len = 7, .filter = mon_filter }; - -static struct l_io *open_packet(const char *name) -{ - struct l_io *io; - struct sockaddr_ll sll; - struct packet_mreq mr; - struct ifreq ifr; - int fd, opt = 1; - - fd = socket(PF_PACKET, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, 0); - if (fd < 0) { - perror("Failed to create packet socket"); - return NULL; - } - - strncpy(ifr.ifr_name, name, IFNAMSIZ - 1); - - if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) { - perror("Failed to get monitor index"); - close(fd); - return NULL; - } - memset(&sll, 0, sizeof(sll)); - sll.sll_family = AF_PACKET; - sll.sll_protocol = htons(ETH_P_ALL); - sll.sll_ifindex = ifr.ifr_ifindex; - - if (bind(fd, (struct sockaddr *) &sll, sizeof(sll)) < 0) { - perror("Failed to bind packet socket"); - close(fd); - return NULL; - } - - memset(&mr, 0, sizeof(mr)); - mr.mr_ifindex = ifr.ifr_ifindex; - mr.mr_type = PACKET_MR_ALLMULTI; - - if (setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, - &mr, sizeof(mr)) < 0) { - perror("Failed to enable all multicast"); - close(fd); - return NULL; - } - - if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, - &mon_fprog, sizeof(mon_fprog)) < 0) { - perror("Failed to enable monitor filter"); - close(fd); - return NULL; - } + if (!nlmon->read && nlmsg->nlmsg_type != nlmon->id) + continue; - if (setsockopt(fd, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt)) < 0) { - perror("Failed to enable monitor timestamps"); - close(fd); - return NULL; + nlmon_message(nlmon, tv, nlmsg); } - - io = l_io_new(fd); - - l_io_set_close_on_destroy(io, true); - - return io; } void nlmon_print_pae(struct nlmon *nlmon, const struct timeval *tv, @@ -8507,28 +8336,21 @@ static struct l_io *open_pae(void) return io; } -struct nlmon *nlmon_open(const char *ifname, uint16_t id, const char *pathname, +struct nlmon *nlmon_open(uint16_t id, const char *pathname, const struct nlmon_config *config) { struct nlmon *nlmon; - struct l_io *io, *pae_io; + struct l_io *pae_io; struct pcap *pcap; - io = open_packet(ifname); - if (!io) - return NULL; - pae_io = open_pae(); - if (!pae_io) { - l_io_destroy(io); + if (!pae_io) return NULL; - } if (pathname) { pcap = pcap_create(pathname); if (!pcap) { l_io_destroy(pae_io); - l_io_destroy(io); return NULL; } } else @@ -8537,11 +8359,9 @@ struct nlmon *nlmon_open(const char *ifname, uint16_t id, const char *pathname, nlmon = nlmon_create(id, config); - nlmon->io = io; nlmon->pae_io = pae_io; nlmon->pcap = pcap; - l_io_set_read_handler(nlmon->io, nlmon_receive, nlmon, NULL); l_io_set_read_handler(nlmon->pae_io, pae_receive, nlmon, NULL); wlan_iface_list = l_hashmap_new(); @@ -8554,7 +8374,6 @@ void nlmon_close(struct nlmon *nlmon) if (!nlmon) return; - l_io_destroy(nlmon->io); l_io_destroy(nlmon->pae_io); l_queue_destroy(nlmon->req_list, nlmon_req_free); diff --git a/monitor/nlmon.h b/monitor/nlmon.h @@ -33,7 +33,7 @@ struct nlmon_config { bool read_only; }; -struct nlmon *nlmon_open(const char *ifname, uint16_t id, const char *pathname, +struct nlmon *nlmon_open(uint16_t id, const char *pathname, const struct nlmon_config *config); void nlmon_close(struct nlmon *nlmon); diff --git a/src/dpp-util.c b/src/dpp-util.c @@ -1376,8 +1376,9 @@ bool dpp_derive_z(const uint8_t *mac_i, const uint8_t *mac_r, hkdf_extract(sha, NULL, 0, 1, prk, k_x, bytes); /* HKDF-Extract (since it doesn't take non-string arguments)*/ - prf_plus(sha, prk, bytes, z_out, bytes, 5, mac_i, 6, mac_r, 6, m_x, - bytes, n_x, bytes, key, strlen(key)); + prf_plus(sha, prk, bytes, z_out, bytes, 5, + mac_i, (size_t) 6, mac_r, (size_t) 6, m_x, bytes, + n_x, bytes, key, strlen(key)); *z_len = bytes; diff --git a/src/dpp.c b/src/dpp.c @@ -53,6 +53,7 @@ #include "src/network.h" #include "src/handshake.h" #include "src/nl80211util.h" +#include "src/knownnetworks.h" #define DPP_FRAME_MAX_RETRIES 5 #define DPP_FRAME_RETRY_TIMEOUT 1 @@ -101,6 +102,7 @@ struct dpp_sm { uint8_t role; int refcount; uint32_t station_watch; + uint32_t known_network_watch; uint64_t wdev_id; @@ -168,6 +170,8 @@ struct dpp_sm { struct l_dbus_message *pending; + struct l_idle *connect_idle; + /* PKEX-specific values */ char *pkex_id; char *pkex_key; @@ -391,6 +395,7 @@ static void dpp_agent_release(struct dpp_sm *dpp) dpp->agent->path, IWD_SHARED_CODE_AGENT_INTERFACE, "Release"); + l_dbus_message_set_arguments(msg, ""); l_dbus_message_set_no_reply(msg, true); l_dbus_send(dbus_get_bus(), msg); } @@ -514,6 +519,11 @@ static void dpp_reset(struct dpp_sm *dpp) dpp->pkex_scan_id = 0; } + if (dpp->connect_idle) { + l_idle_remove(dpp->connect_idle); + dpp->connect_idle = NULL; + } + dpp->state = DPP_STATE_NOTHING; dpp->new_freq = 0; dpp->frame_retry = 0; @@ -569,6 +579,8 @@ static void dpp_free(struct dpp_sm *dpp) if (station) station_remove_state_watch(station, dpp->station_watch); + known_networks_watch_remove(dpp->known_network_watch); + l_free(dpp); } @@ -811,8 +823,6 @@ static void dpp_write_config(struct dpp_configuration *config, { _auto_(l_settings_free) struct l_settings *settings = l_settings_new(); _auto_(l_free) char *path; - _auto_(l_free) uint8_t *psk = NULL; - size_t psk_len; path = storage_get_network_file_path(SECURITY_PSK, config->ssid); @@ -821,22 +831,13 @@ static void dpp_write_config(struct dpp_configuration *config, l_settings_remove_group(settings, "Security"); } - if (config->passphrase) { + if (config->passphrase) l_settings_set_string(settings, "Security", "Passphrase", config->passphrase); - if (network) - network_set_passphrase(network, config->passphrase); - - } else if (config->psk) { + else if (config->psk) l_settings_set_string(settings, "Security", "PreSharedKey", config->psk); - psk = l_util_from_hexstring(config->psk, &psk_len); - - if (network) - network_set_psk(network, psk); - } - if (config->send_hostname) l_settings_set_bool(settings, "IPv4", "SendHostname", true); @@ -855,14 +856,39 @@ static void dpp_scan_triggered(int err, void *user_data) l_error("Failed to trigger DPP scan"); } +static void dpp_start_connect(struct l_idle *idle, void *user_data) +{ + struct dpp_sm *dpp = user_data; + struct station *station = station_find(netdev_get_ifindex(dpp->netdev)); + struct scan_bss *bss; + struct network *network; + int ret; + + network = station_network_find(station, dpp->config->ssid, + SECURITY_PSK); + + dpp_reset(dpp); + + if (!network) { + l_debug("Network was not found!"); + return; + } + + l_debug("connecting to %s from DPP", network_get_ssid(network)); + + bss = network_bss_select(network, true); + ret = network_autoconnect(network, bss); + if (ret < 0) + l_warn("failed to connect after DPP (%d) %s", ret, + strerror(-ret)); +} + static bool dpp_scan_results(int err, struct l_queue *bss_list, const struct scan_freq_set *freqs, void *userdata) { struct dpp_sm *dpp = userdata; struct station *station = station_find(netdev_get_ifindex(dpp->netdev)); - struct scan_bss *bss; - struct network *network; if (err < 0) goto reset; @@ -879,18 +905,7 @@ static bool dpp_scan_results(int err, struct l_queue *bss_list, station_set_scan_results(station, bss_list, freqs, false); - network = station_network_find(station, dpp->config->ssid, - SECURITY_PSK); - - dpp_reset(dpp); - - if (!network) { - l_debug("Network was not found after scanning"); - return true; - } - - bss = network_bss_select(network, true); - network_autoconnect(network, bss); + dpp_start_connect(NULL, dpp); return true; @@ -906,6 +921,51 @@ static void dpp_scan_destroy(void *userdata) dpp_reset(dpp); } +static void dpp_known_network_watch(enum known_networks_event event, + const struct network_info *info, + void *user_data) +{ + struct dpp_sm *dpp = user_data; + + /* + * Check the following + * - DPP is enrolling + * - DPP finished (dpp->config is set) + * - This is for the network DPP just configured + * - DPP isn't already trying to connect (e.g. if the profile was + * immediately modified after DPP synced it). + * - DPP didn't start a scan for the network. + */ + if (dpp->role != DPP_CAPABILITY_ENROLLEE) + return; + if (!dpp->config) + return; + if (strcmp(info->ssid, dpp->config->ssid)) + return; + if (dpp->connect_idle) + return; + if (dpp->connect_scan_id) + return; + + switch (event) { + case KNOWN_NETWORKS_EVENT_ADDED: + case KNOWN_NETWORKS_EVENT_UPDATED: + /* + * network.c takes care of updating the settings for the + * network. This callback just tells us to begin the connection. + * We do have use an idle here because there is no strict + * guarantee of ordering between known network events, e.g. DPP + * could have been called into prior to network and the network + * object isn't updated yet. + */ + dpp->connect_idle = l_idle_create(dpp_start_connect, dpp, NULL); + break; + case KNOWN_NETWORKS_EVENT_REMOVED: + l_warn("profile was removed before DPP could connect"); + break; + } +} + static void dpp_handle_config_response_frame(const struct mmpdu_header *frame, const void *body, size_t body_len, int rssi, void *user_data) @@ -1073,10 +1133,11 @@ static void dpp_handle_config_response_frame(const struct mmpdu_header *frame, offchannel_cancel(dpp->wdev_id, dpp->offchannel_id); - if (network && bss) - __station_connect_network(station, network, bss, - STATION_STATE_CONNECTING); - else if (station) { + if (network && bss) { + l_debug("delaying connect until settings are synced"); + dpp->config = config; + return; + } else if (station) { struct scan_parameters params = {0}; params.ssid = (void *) config->ssid; @@ -3700,6 +3761,7 @@ static void dpp_station_state_watch(enum station_state state, void *user_data) case STATION_STATE_CONNECTING: case STATION_STATE_CONNECTED: case STATION_STATE_CONNECTING_AUTO: + case STATION_STATE_NETCONFIG: if (L_WARN_ON(dpp->role == DPP_CAPABILITY_CONFIGURATOR)) dpp_reset(dpp); @@ -3779,6 +3841,8 @@ static void dpp_create(struct netdev *netdev) dpp->station_watch = station_add_state_watch(station, dpp_station_state_watch, dpp, NULL); + dpp->known_network_watch = known_networks_watch_add( + dpp_known_network_watch, dpp, NULL); l_queue_push_tail(dpp_list, dpp); } diff --git a/src/eapol.c b/src/eapol.c @@ -1299,7 +1299,8 @@ static void eapol_handle_ptk_1_of_4(struct eapol_sm *sm, ies_len = ies[1] + 2; ies_len += append_ie(ies + ies_len, sm->handshake->mde); - ies_len += append_ie(ies + ies_len, sm->handshake->fte); + ies_len += append_ie(ies + ies_len, + sm->handshake->authenticator_fte); } else { ies_len = append_ie(ies, own_ie); } @@ -1795,7 +1796,7 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm, if (eapol_ie_matches(decrypted_key_data, decrypted_key_data_size, IE_TYPE_FAST_BSS_TRANSITION, - hs->fte) < 0) + hs->authenticator_fte) < 0) goto error_ie_different; } @@ -2091,6 +2092,10 @@ static void eapol_handle_ptk_4_of_4(struct eapol_sm *sm, if (L_BE64_TO_CPU(ek->key_replay_counter) != sm->replay_counter) return; + /* Ensure we received Message 2 and thus have a PTK to verify MIC */ + if (!sm->handshake->have_snonce) + return; + kck = handshake_state_get_kck(sm->handshake); if (!eapol_verify_mic(sm->handshake->akm_suite, kck, ek, diff --git a/src/erp.c b/src/erp.c @@ -325,7 +325,7 @@ static bool erp_derive_reauth_keys(const uint8_t *emsk, size_t emsk_len, if (!prf_plus(L_CHECKSUM_SHA256, r_rk, emsk_len, r_ik, emsk_len, 3, ERP_RIK_LABEL, strlen(ERP_RIK_LABEL) + 1, - &cryptosuite, 1, &len, sizeof(len))) + &cryptosuite, (size_t) 1, &len, sizeof(len))) return false; return true; diff --git a/src/fils.c b/src/fils.c @@ -445,7 +445,7 @@ static int fils_rx_authenticate(struct auth_proto *driver, const uint8_t *frame, kck_len, &ft_info) < 0) goto invalid_ies; - handshake_state_set_fte(fils->hs, fte); + handshake_state_set_authenticator_fte(fils->hs, fte); handshake_state_set_kh_ids(fils->hs, ft_info.r0khid, ft_info.r0khid_len, ft_info.r1khid); diff --git a/src/ft.c b/src/ft.c @@ -43,7 +43,6 @@ static const unsigned int FT_ONCHANNEL_TIME = 300u; /* ms */ static ft_tx_frame_func_t tx_frame = NULL; -static ft_tx_associate_func_t tx_assoc = NULL; static struct l_queue *info_list = NULL; struct ft_info { @@ -224,117 +223,6 @@ static bool ft_parse_associate_resp_frame(const uint8_t *frame, size_t frame_len return true; } -static int ft_tx_reassociate(uint32_t ifindex, uint32_t freq, - const uint8_t *prev_bssid) -{ - struct netdev *netdev = netdev_find(ifindex); - struct handshake_state *hs = netdev_get_handshake(netdev); - struct iovec iov[3]; - int iov_elems = 0; - uint32_t kck_len = handshake_state_get_kck_len(hs); - bool is_rsn = hs->supplicant_ie != NULL; - uint8_t *rsne = NULL; - - if (is_rsn) { - struct ie_rsn_info rsn_info; - - /* - * Rebuild the RSNE to include the PMKR1Name and append - * MDE + FTE. - * - * 12.8.4: "If present, the RSNE shall be set as follows: - * - Version field shall be set to 1. - * - PMKID Count field shall be set to 1. - * - PMKID field shall contain the PMKR1Name. - * - All other fields shall be as specified in 8.4.2.27 - * and 11.5.3." - */ - if (ie_parse_rsne_from_data(hs->supplicant_ie, - hs->supplicant_ie[1] + 2, - &rsn_info) < 0) - goto error; - - rsn_info.num_pmkids = 1; - rsn_info.pmkids = hs->pmk_r1_name; - - /* Always set OCVC false for FT for now */ - rsn_info.ocvc = false; - - rsne = alloca(256); - ie_build_rsne(&rsn_info, rsne); - - iov[iov_elems].iov_base = rsne; - iov[iov_elems].iov_len = rsne[1] + 2; - iov_elems += 1; - } - - /* The MDE advertised by the BSS must be passed verbatim */ - iov[iov_elems].iov_base = (void *) hs->mde; - iov[iov_elems].iov_len = hs->mde[1] + 2; - iov_elems += 1; - - if (is_rsn) { - struct ie_ft_info ft_info; - uint8_t *fte; - - /* - * 12.8.4: "If present, the FTE shall be set as follows: - * - ANonce, SNonce, R0KH-ID, and R1KH-ID shall be set to - * the values contained in the second message of this - * sequence. - * - The Element Count field of the MIC Control field shall - * be set to the number of elements protected in this - * frame (variable). - * [...] - * - All other fields shall be set to 0." - */ - - memset(&ft_info, 0, sizeof(ft_info)); - - ft_info.mic_element_count = 3; - memcpy(ft_info.r0khid, hs->r0khid, hs->r0khid_len); - ft_info.r0khid_len = hs->r0khid_len; - memcpy(ft_info.r1khid, hs->r1khid, 6); - ft_info.r1khid_present = true; - memcpy(ft_info.anonce, hs->anonce, 32); - memcpy(ft_info.snonce, hs->snonce, 32); - - /* - * IEEE 802.11-2020 Section 13.7.1 FT reassociation in an RSN - * - * "If dot11RSNAOperatingChannelValidationActivated is true and - * the FTO indicates OCVC capability, the target AP shall - * ensure that OCI subelement of the FTE matches by ensuring - * that all of the following are true: - * - OCI subelement is present - * - Channel information in the OCI matches current - * operating channel parameters (see 12.2.9)" - */ - if (hs->supplicant_ocvc && hs->chandef) { - oci_from_chandef(hs->chandef, ft_info.oci); - ft_info.oci_present = true; - } - - fte = alloca(256); - ie_build_fast_bss_transition(&ft_info, kck_len, fte); - - if (!ft_calculate_fte_mic(hs, 5, rsne, fte, NULL, ft_info.mic)) - goto error; - - /* Rebuild the FT IE now with the MIC included */ - ie_build_fast_bss_transition(&ft_info, kck_len, fte); - - iov[iov_elems].iov_base = fte; - iov[iov_elems].iov_len = fte[1] + 2; - iov_elems += 1; - } - - return tx_assoc(ifindex, freq, prev_bssid, iov, iov_elems); - -error: - return -EINVAL; -} - static bool ft_verify_rsne(const uint8_t *rsne, const uint8_t *pmk_r0_name, const uint8_t *authenticator_ie) { @@ -762,11 +650,6 @@ void __ft_set_tx_frame_func(ft_tx_frame_func_t func) tx_frame = func; } -void __ft_set_tx_associate_func(ft_tx_associate_func_t func) -{ - tx_assoc = func; -} - static bool ft_parse_ies(struct ft_info *info, struct handshake_state *hs, const uint8_t *ies, size_t ies_len) { @@ -904,9 +787,15 @@ static void ft_info_destroy(void *data) l_free(info); } -static void ft_prepare_handshake(struct ft_info *info, +static bool ft_prepare_handshake(struct ft_info *info, struct handshake_state *hs) { + uint32_t kck_len = handshake_state_get_kck_len(hs); + struct ie_rsn_info rsn_info; + struct ie_ft_info ft_info; + uint8_t *fte; + uint8_t *rsne; + handshake_state_set_authenticator_address(hs, info->aa); memcpy(hs->mde + 2, info->mde, 3); @@ -914,7 +803,7 @@ static void ft_prepare_handshake(struct ft_info *info, handshake_state_set_chandef(hs, NULL); if (!hs->supplicant_ie) - return; + return true; if (info->authenticator_ie) handshake_state_set_authenticator_ie(hs, @@ -922,7 +811,7 @@ static void ft_prepare_handshake(struct ft_info *info, memcpy(hs->snonce, info->snonce, sizeof(hs->snonce)); - handshake_state_set_fte(hs, info->fte); + handshake_state_set_authenticator_fte(hs, info->fte); handshake_state_set_anonce(hs, info->ft_info.anonce); @@ -931,6 +820,80 @@ static void ft_prepare_handshake(struct ft_info *info, info->ft_info.r1khid); handshake_state_derive_ptk(hs); + + /* + * Rebuild the RSNE to include the PMKR1Name and append + * MDE + FTE. + * + * 12.8.4: "If present, the RSNE shall be set as follows: + * - Version field shall be set to 1. + * - PMKID Count field shall be set to 1. + * - PMKID field shall contain the PMKR1Name. + * - All other fields shall be as specified in 8.4.2.27 + * and 11.5.3." + */ + if (ie_parse_rsne_from_data(hs->supplicant_ie, + hs->supplicant_ie[1] + 2, + &rsn_info) < 0) + return false; + + rsn_info.num_pmkids = 1; + rsn_info.pmkids = hs->pmk_r1_name; + /* Always set OCVC false for FT for now */ + rsn_info.ocvc = false; + rsne = alloca(256); + + ie_build_rsne(&rsn_info, rsne); + handshake_state_set_supplicant_ie(hs, rsne); + + /* + * 12.8.4: "If present, the FTE shall be set as follows: + * - ANonce, SNonce, R0KH-ID, and R1KH-ID shall be set to + * the values contained in the second message of this + * sequence. + * - The Element Count field of the MIC Control field shall + * be set to the number of elements protected in this + * frame (variable). + * [...] + * - All other fields shall be set to 0." + */ + memset(&ft_info, 0, sizeof(ft_info)); + ft_info.mic_element_count = 3; + memcpy(ft_info.r0khid, hs->r0khid, hs->r0khid_len); + ft_info.r0khid_len = hs->r0khid_len; + memcpy(ft_info.r1khid, hs->r1khid, 6); + ft_info.r1khid_present = true; + memcpy(ft_info.anonce, hs->anonce, 32); + memcpy(ft_info.snonce, hs->snonce, 32); + + /* + * IEEE 802.11-2020 Section 13.7.1 FT reassociation in an RSN + * + * "If dot11RSNAOperatingChannelValidationActivated is true and + * the FTO indicates OCVC capability, the target AP shall + * ensure that OCI subelement of the FTE matches by ensuring + * that all of the following are true: + * - OCI subelement is present + * - Channel information in the OCI matches current + * operating channel parameters (see 12.2.9)" + */ + if (hs->supplicant_ocvc && hs->chandef) { + oci_from_chandef(hs->chandef, ft_info.oci); + ft_info.oci_present = true; + } + + fte = alloca(256); + ie_build_fast_bss_transition(&ft_info, kck_len, fte); + + if (!ft_calculate_fte_mic(hs, 5, rsne, fte, NULL, ft_info.mic)) + return false; + + /* Rebuild the FT IE now with the MIC included */ + ie_build_fast_bss_transition(&ft_info, kck_len, fte); + + handshake_state_set_supplicant_fte(hs, fte); + + return true; } static bool ft_send_action(struct wiphy_radio_work_item *work) @@ -1093,7 +1056,7 @@ static void ft_authenticate_destroy(int error, void *user_data) /* * There is no callback here because its assumed that another work item will * be inserted following this call which will check if authentication succeeded - * via ft_associate. + * via ft_handshake_setup. * * If the netdev goes away while authentication is in-flight station will clear * the authentications during cleanup, and in turn cancel the offchannel @@ -1155,21 +1118,14 @@ int ft_authenticate_onchannel(uint32_t ifindex, const struct scan_bss *target) return 0; } -int ft_associate(uint32_t ifindex, const uint8_t *addr) +int ft_handshake_setup(uint32_t ifindex, const uint8_t *target) { struct netdev *netdev = netdev_find(ifindex); struct handshake_state *hs = netdev_get_handshake(netdev); struct ft_info *info; - int ret; + int ret = 0; - /* - * TODO: Since FT-over-DS is done early, before the time of roaming, it - * may end up that a completely new BSS is the best candidate and - * we haven't yet authenticated. We could actually authenticate - * at this point, but for now just assume the caller will choose - * a different BSS. - */ - info = ft_info_find(ifindex, addr); + info = ft_info_find(ifindex, target); if (!info) return -ENOENT; @@ -1186,9 +1142,15 @@ int ft_associate(uint32_t ifindex, const uint8_t *addr) return status; } - ft_prepare_handshake(info, hs); - - ret = ft_tx_reassociate(ifindex, info->frequency, info->prev_bssid); + /* + * This shouldn't ever fail: + * - supplicant_ie has already been validated long ago + * - l_checksum_* shouldn't fail since we presumable have kernel + * support, how else could we have made it this far. + * But just in case... + */ + if (L_WARN_ON(!ft_prepare_handshake(info, hs))) + ret = -EINVAL; /* After this no previous auths will be valid */ ft_clear_authentications(ifindex); diff --git a/src/ft.h b/src/ft.h @@ -32,15 +32,15 @@ typedef int (*ft_tx_associate_func_t)(uint32_t ifindex, uint32_t freq, struct iovec *ie_iov, size_t iov_len); void __ft_set_tx_frame_func(ft_tx_frame_func_t func); -void __ft_set_tx_associate_func(ft_tx_associate_func_t func); int __ft_rx_associate(uint32_t ifindex, const uint8_t *frame, size_t frame_len); void __ft_rx_action(uint32_t ifindex, const uint8_t *frame, size_t frame_len); void __ft_rx_authenticate(uint32_t ifindex, const uint8_t *frame, size_t frame_len); +int ft_handshake_setup(uint32_t ifindex, const uint8_t *target); + void ft_clear_authentications(uint32_t ifindex); int ft_action(uint32_t ifindex, uint32_t freq, const struct scan_bss *target); -int ft_associate(uint32_t ifindex, const uint8_t *addr); int ft_authenticate(uint32_t ifindex, const struct scan_bss *target); int ft_authenticate_onchannel(uint32_t ifindex, const struct scan_bss *target); diff --git a/src/handshake.c b/src/handshake.c @@ -105,7 +105,12 @@ void __handshake_set_install_ext_tk_func(handshake_install_ext_tk_func_t func) void handshake_state_free(struct handshake_state *s) { - __typeof__(s->free) destroy = s->free; + __typeof__(s->free) destroy; + + if (!s) + return; + + destroy = s->free; if (s->in_event) { s->in_event = false; @@ -117,7 +122,8 @@ void handshake_state_free(struct handshake_state *s) l_free(s->authenticator_rsnxe); l_free(s->supplicant_rsnxe); l_free(s->mde); - l_free(s->fte); + l_free(s->authenticator_fte); + l_free(s->supplicant_fte); l_free(s->fils_ip_req_ie); l_free(s->fils_ip_resp_ie); l_free(s->vendor_ies); @@ -132,6 +138,12 @@ void handshake_state_free(struct handshake_state *s) l_free(s->passphrase); } + if (s->password_identifier) { + explicit_bzero(s->password_identifier, + strlen(s->password_identifier)); + l_free(s->password_identifier); + } + if (s->ecc_sae_pts) { unsigned int i; @@ -303,9 +315,16 @@ void handshake_state_set_mde(struct handshake_state *s, const uint8_t *mde) replace_ie(&s->mde, mde); } -void handshake_state_set_fte(struct handshake_state *s, const uint8_t *fte) +void handshake_state_set_authenticator_fte(struct handshake_state *s, + const uint8_t *fte) { - replace_ie(&s->fte, fte); + replace_ie(&s->authenticator_fte, fte); +} + +void handshake_state_set_supplicant_fte(struct handshake_state *s, + const uint8_t *fte) +{ + replace_ie(&s->supplicant_fte, fte); } void handshake_state_set_vendor_ies(struct handshake_state *s, @@ -359,6 +378,12 @@ void handshake_state_set_passphrase(struct handshake_state *s, s->passphrase = l_strdup(passphrase); } +void handshake_state_set_password_identifier(struct handshake_state *s, + const char *id) +{ + s->password_identifier = l_strdup(id); +} + void handshake_state_set_no_rekey(struct handshake_state *s, bool no_rekey) { s->no_rekey = no_rekey; @@ -509,7 +534,7 @@ bool handshake_state_derive_ptk(struct handshake_state *s) IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256 | IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA256 | IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384)) && - (!s->mde || !s->fte)) + (!s->mde || !s->authenticator_fte)) return false; s->ptk_complete = false; diff --git a/src/handshake.h b/src/handshake.h @@ -24,6 +24,7 @@ #include <stdbool.h> #include <asm/byteorder.h> #include <linux/types.h> +#include <ell/cleanup.h> struct handshake_state; enum crypto_cipher; @@ -102,7 +103,8 @@ struct handshake_state { uint8_t *authenticator_rsnxe; uint8_t *supplicant_rsnxe; uint8_t *mde; - uint8_t *fte; + uint8_t *authenticator_fte; + uint8_t *supplicant_fte; uint8_t *vendor_ies; size_t vendor_ies_len; enum ie_rsn_cipher_suite pairwise_cipher; @@ -142,6 +144,7 @@ struct handshake_state { uint8_t ssid[32]; size_t ssid_len; char *passphrase; + char *password_identifier; uint8_t r0khid[48]; size_t r0khid_len; uint8_t r1khid[6]; @@ -213,7 +216,11 @@ void handshake_state_set_ssid(struct handshake_state *s, const uint8_t *ssid, size_t ssid_len); void handshake_state_set_mde(struct handshake_state *s, const uint8_t *mde); -void handshake_state_set_fte(struct handshake_state *s, const uint8_t *fte); +void handshake_state_set_authenticator_fte(struct handshake_state *s, + const uint8_t *fte); +void handshake_state_set_supplicant_fte(struct handshake_state *s, + const uint8_t *fte); + void handshake_state_set_vendor_ies(struct handshake_state *s, const struct iovec *iov, size_t n_iovs); @@ -227,6 +234,8 @@ void handshake_state_set_event_func(struct handshake_state *s, void *user_data); void handshake_state_set_passphrase(struct handshake_state *s, const char *passphrase); +void handshake_state_set_password_identifier(struct handshake_state *s, + const char *id); bool handshake_state_add_ecc_sae_pt(struct handshake_state *s, const struct l_ecc_point *pt); void handshake_state_set_no_rekey(struct handshake_state *s, bool no_rekey); @@ -298,3 +307,5 @@ const uint8_t *handshake_util_find_pmkid_kde(const uint8_t *data, size_t data_len); void handshake_util_build_gtk_kde(enum crypto_cipher cipher, const uint8_t *key, unsigned int key_index, uint8_t *to); + +DEFINE_CLEANUP_FUNC(handshake_state_free); diff --git a/src/iwd.network.rst b/src/iwd.network.rst @@ -199,6 +199,12 @@ connect to that network. required if the *PreSharedKey* is not provided. If not provided in settings, the agent will be asked for the passphrase at connection time. + * - PasswordIdentifier + - string + + An identifer string to be used with the passphrase. This is used for + WPA3-Personal (SAE) networks if the security has enabled password + identifiers for clients. * - PreSharedKey - 64 character hex string diff --git a/src/knownnetworks.c b/src/knownnetworks.c @@ -474,6 +474,10 @@ void known_network_update(struct network_info *network, known_network_set_autoconnect(network, new->is_autoconnectable); memcpy(&network->config, new, sizeof(struct network_config)); + + WATCHLIST_NOTIFY(&known_network_watches, + known_networks_watch_func_t, + KNOWN_NETWORKS_EVENT_UPDATED, network); } bool known_networks_foreach(known_networks_foreach_func_t function, @@ -519,8 +523,23 @@ struct network_info *known_networks_find(const char *ssid, return l_queue_find(known_networks, network_info_match, &query); } +static void known_network_append_frequencies(const struct network_info *info, + struct scan_freq_set *set, + uint8_t max) +{ + const struct l_queue_entry *entry; + + for (entry = l_queue_get_entries(info->known_frequencies); entry && max; + entry = entry->next, max--) { + const struct known_frequency *known_freq = entry->data; + + scan_freq_set_add(set, known_freq->frequency); + } +} + struct scan_freq_set *known_networks_get_recent_frequencies( - uint8_t num_networks_tosearch) + uint8_t num_networks_tosearch, + uint8_t freqs_per_network) { /* * This search function assumes that the known networks are always @@ -529,10 +548,9 @@ struct scan_freq_set *known_networks_get_recent_frequencies( * list. */ const struct l_queue_entry *network_entry; - const struct l_queue_entry *freq_entry; struct scan_freq_set *set; - if (!num_networks_tosearch) + if (!num_networks_tosearch || !freqs_per_network) return NULL; set = scan_freq_set_new(); @@ -543,14 +561,8 @@ struct scan_freq_set *known_networks_get_recent_frequencies( num_networks_tosearch--) { const struct network_info *network = network_entry->data; - for (freq_entry = l_queue_get_entries( - network->known_frequencies); - freq_entry; freq_entry = freq_entry->next) { - const struct known_frequency *known_freq = - freq_entry->data; - - scan_freq_set_add(set, known_freq->frequency); - } + known_network_append_frequencies(network, set, + freqs_per_network); } return set; diff --git a/src/knownnetworks.h b/src/knownnetworks.h @@ -35,6 +35,7 @@ struct network_info; enum known_networks_event { KNOWN_NETWORKS_EVENT_ADDED, KNOWN_NETWORKS_EVENT_REMOVED, + KNOWN_NETWORKS_EVENT_UPDATED, }; struct network_info_ops { @@ -112,8 +113,10 @@ struct network_info *known_networks_find(const char *ssid, enum security security); struct scan_freq_set *known_networks_get_recent_frequencies( - uint8_t num_networks_tosearch); -int known_network_add_frequency(struct network_info *info, uint32_t frequency); + uint8_t num_networks_tosearch, + uint8_t freqs_per_network); +int known_network_add_frequency(struct network_info *info, + uint32_t frequency); void known_network_frequency_sync(struct network_info *info); uint32_t known_networks_watch_add(known_networks_watch_func_t func, diff --git a/src/mpdu.h b/src/mpdu.h @@ -231,6 +231,7 @@ enum mmpdu_status_code { MMPDU_STATUS_CODE_ENABLEMENT_DENIED = 105, MMPDU_STATUS_CODE_RESTRICT_AUTH_GDB = 106, MMPDU_STATUS_CODE_AUTHORIZATION_DEENABLED = 107, + MMPDU_STATUS_CODE_UNKNOWN_PASSWORD_IDENTIFIER = 123, MMPDU_STATUS_CODE_SAE_HASH_TO_ELEMENT = 126, MMPDU_STATUS_CODE_SAE_PK = 127, }; diff --git a/src/netconfig.c b/src/netconfig.c @@ -50,6 +50,8 @@ #include "src/netconfig.h" #include "src/sysfs.h" +#define DHCP_ATTEMPTS 4 + /* * Routing priority offset, configurable in main.conf. The route with lower * priority offset is preferred. @@ -696,6 +698,7 @@ struct netconfig *netconfig_new(uint32_t ifindex) int dhcp_priority = L_LOG_INFO; struct l_dhcp6_client *dhcp6; struct l_icmp6_client *icmp6; + struct l_dhcp_client *dhcp; l_debug("Creating netconfig for interface: %d", ifindex); @@ -723,8 +726,8 @@ struct netconfig *netconfig_new(uint32_t ifindex) l_netconfig_set_event_handler(netconfig->nc, netconfig_event_handler, netconfig, NULL); - l_dhcp_client_set_debug(l_netconfig_get_dhcp_client(netconfig->nc), - do_debug, "[DHCPv4] ", NULL, dhcp_priority); + dhcp = l_netconfig_get_dhcp_client(netconfig->nc); + l_dhcp_client_set_max_attempts(dhcp, DHCP_ATTEMPTS); dhcp6 = l_netconfig_get_dhcp6_client(netconfig->nc); l_dhcp6_client_set_lla_randomized(dhcp6, true); @@ -735,6 +738,8 @@ struct netconfig *netconfig_new(uint32_t ifindex) if (debug_level) { l_dhcp6_client_set_debug(dhcp6, do_debug, "[DHCPv6] ", NULL); l_icmp6_client_set_debug(icmp6, do_debug, "[ICMPv6] ", NULL); + l_dhcp_client_set_debug(dhcp, do_debug, "[DHCPv4] ", NULL, + dhcp_priority); } return netconfig; diff --git a/src/netdev.c b/src/netdev.c @@ -209,7 +209,7 @@ static bool mac_per_ssid; static unsigned int iov_ie_append(struct iovec *iov, unsigned int n_iov, unsigned int c, - const uint8_t *ie) + const uint8_t *ie, size_t len) { if (L_WARN_ON(c >= n_iov)) return n_iov; @@ -218,7 +218,7 @@ static unsigned int iov_ie_append(struct iovec *iov, return c; iov[c].iov_base = (void *) ie; - iov[c].iov_len = ie[1] + 2; + iov[c].iov_len = len; return c + 1u; } @@ -286,19 +286,22 @@ static unsigned int netdev_populate_common_ies(struct netdev *netdev, extended_capabilities = wiphy_get_extended_capabilities(netdev->wiphy, netdev->type); - c_iov = iov_ie_append(iov, n_iov, c_iov, extended_capabilities); + c_iov = iov_ie_append(iov, n_iov, c_iov, extended_capabilities, + IE_LEN(extended_capabilities)); rm_enabled_capabilities = wiphy_get_rm_enabled_capabilities(netdev->wiphy); - c_iov = iov_ie_append(iov, n_iov, c_iov, rm_enabled_capabilities); + c_iov = iov_ie_append(iov, n_iov, c_iov, rm_enabled_capabilities, + IE_LEN(rm_enabled_capabilities)); if (rm_enabled_capabilities) l_genl_msg_append_attr(msg, NL80211_ATTR_USE_RRM, 0, NULL); - c_iov = iov_ie_append(iov, n_iov, c_iov, hs->vendor_ies); + c_iov = iov_ie_append(iov, n_iov, c_iov, + hs->vendor_ies, hs->vendor_ies_len); - if (hs->fils_ip_req_ie) - c_iov = iov_ie_append(iov, n_iov, c_iov, hs->fils_ip_req_ie); + c_iov = iov_ie_append(iov, n_iov, c_iov, hs->fils_ip_req_ie, + IE_LEN(hs->fils_ip_req_ie)); return c_iov; } @@ -1406,16 +1409,13 @@ static void netdev_connect_ok(struct netdev *netdev) scan_bss_free(netdev->fw_roam_bss); netdev->fw_roam_bss = NULL; - } else if (netdev->in_ft) { - if (netdev->event_filter) - netdev->event_filter(netdev, NETDEV_EVENT_FT_ROAMED, - NULL, netdev->user_data); - netdev->in_ft = false; } else if (netdev->connect_cb) { netdev->connect_cb(netdev, NETDEV_RESULT_OK, NULL, netdev->user_data); netdev->connect_cb = NULL; - } + netdev->in_ft = false; + } else + l_warn("Connection event without a connect callback!"); netdev_rssi_polling_update(netdev); @@ -2447,9 +2447,7 @@ static void netdev_driver_connected(struct netdev *netdev) static struct l_genl_msg *netdev_build_cmd_connect(struct netdev *netdev, struct handshake_state *hs, - const uint8_t *prev_bssid, - const struct iovec *vendor_ies, - size_t num_vendor_ies) + const uint8_t *prev_bssid) { struct netdev_handshake_state *nhs = l_container_of(hs, struct netdev_handshake_state, super); @@ -2502,7 +2500,8 @@ static struct l_genl_msg *netdev_build_cmd_connect(struct netdev *netdev, if (is_rsn) { nl80211_append_rsn_attributes(msg, hs); - c_iov = iov_ie_append(iov, n_iov, c_iov, hs->supplicant_ie); + c_iov = iov_ie_append(iov, n_iov, c_iov, hs->supplicant_ie, + IE_LEN(hs->supplicant_ie)); } if (is_rsn || hs->settings_8021x) { @@ -2517,20 +2516,14 @@ static struct l_genl_msg *netdev_build_cmd_connect(struct netdev *netdev, if (netdev->owe_sm) { owe_build_dh_ie(netdev->owe_sm, owe_dh_ie, &dh_ie_len); - c_iov = iov_ie_append(iov, n_iov, c_iov, owe_dh_ie); + c_iov = iov_ie_append(iov, n_iov, c_iov, owe_dh_ie, dh_ie_len); } - c_iov = iov_ie_append(iov, n_iov, c_iov, hs->mde); + c_iov = iov_ie_append(iov, n_iov, c_iov, hs->mde, IE_LEN(hs->mde)); c_iov = netdev_populate_common_ies(netdev, hs, msg, iov, n_iov, c_iov); mpdu_sort_ies(subtype, iov, c_iov); - if (vendor_ies && !L_WARN_ON(n_iov - c_iov < num_vendor_ies)) { - memcpy(iov + c_iov, vendor_ies, - sizeof(*vendor_ies) * num_vendor_ies); - c_iov += num_vendor_ies; - } - if (c_iov) l_genl_msg_append_attrv(msg, NL80211_ATTR_IE, iov, c_iov); @@ -2566,8 +2559,7 @@ static bool netdev_retry_owe(struct netdev *netdev) if (!owe_next_group(netdev->owe_sm)) return false; - connect_cmd = netdev_build_cmd_connect(netdev, - netdev->handshake, NULL, NULL, 0); + connect_cmd = netdev_build_cmd_connect(netdev, netdev->handshake, NULL); netdev->connect_cmd_id = l_genl_family_send(nl80211, connect_cmd, netdev_cmd_connect_cb, netdev, @@ -2782,7 +2774,7 @@ process_resp_ies: */ if (ie_parse_fast_bss_transition_from_data(fte, fte[1] + 2, kck_len, &ft_info) >= 0) { - handshake_state_set_fte(hs, fte); + handshake_state_set_authenticator_fte(hs, fte); handshake_state_set_kh_ids(hs, ft_info.r0khid, ft_info.r0khid_len, @@ -3267,9 +3259,11 @@ static void netdev_sae_tx_associate(void *user_data) msg = netdev_build_cmd_associate_common(netdev); - n_used = iov_ie_append(iov, n_iov, n_used, hs->supplicant_ie); - n_used = iov_ie_append(iov, n_iov, n_used, hs->mde); - n_used = iov_ie_append(iov, n_iov, n_used, hs->supplicant_rsnxe); + n_used = iov_ie_append(iov, n_iov, n_used, hs->supplicant_ie, + IE_LEN(hs->supplicant_ie)); + n_used = iov_ie_append(iov, n_iov, n_used, hs->mde, IE_LEN(hs->mde)); + n_used = iov_ie_append(iov, n_iov, n_used, hs->supplicant_rsnxe, + IE_LEN(hs->supplicant_rsnxe)); n_used = netdev_populate_common_ies(netdev, hs, msg, iov, n_iov, n_used); mpdu_sort_ies(subtype, iov, n_used); @@ -3801,8 +3795,6 @@ static void netdev_connect_common(struct netdev *netdev, const struct scan_bss *bss, const struct scan_bss *prev_bss, struct handshake_state *hs, - const struct iovec *vendor_ies, - size_t num_vendor_ies, netdev_event_func_t event_filter, netdev_connect_cb_t cb, void *user_data) { @@ -3860,8 +3852,7 @@ static void netdev_connect_common(struct netdev *netdev, break; default: build_cmd_connect: - cmd_connect = netdev_build_cmd_connect(netdev, hs, prev_bssid, - vendor_ies, num_vendor_ies); + cmd_connect = netdev_build_cmd_connect(netdev, hs, prev_bssid); if (!is_offload(hs) && (is_rsn || hs->settings_8021x)) { sm = eapol_sm_new(hs); @@ -3894,8 +3885,6 @@ build_cmd_connect: int netdev_connect(struct netdev *netdev, const struct scan_bss *bss, struct handshake_state *hs, - const struct iovec *vendor_ies, - size_t num_vendor_ies, netdev_event_func_t event_filter, netdev_connect_cb_t cb, void *user_data) { @@ -3912,9 +3901,8 @@ int netdev_connect(struct netdev *netdev, const struct scan_bss *bss, if (netdev_handshake_state_setup_connection_type(hs) < 0) return -ENOTSUP; - netdev_connect_common(netdev, bss, NULL, hs, vendor_ies, - num_vendor_ies, event_filter, cb, - user_data); + netdev_connect_common(netdev, bss, NULL, hs, + event_filter, cb, user_data); return 0; } @@ -4019,7 +4007,7 @@ int netdev_reassociate(struct netdev *netdev, const struct scan_bss *target_bss, netdev->connected = false; netdev->in_reassoc = true; - netdev_connect_common(netdev, target_bss, orig_bss, hs, NULL, 0, + netdev_connect_common(netdev, target_bss, orig_bss, hs, event_filter, cb, user_data); if (netdev->ap) @@ -4214,13 +4202,14 @@ static int netdev_tx_ft_frame(uint32_t ifindex, uint16_t frame_type, return 0; } -static int netdev_ft_tx_associate(uint32_t ifindex, uint32_t freq, - const uint8_t *prev_bssid, - struct iovec *ft_iov, size_t n_ft_iov) +int netdev_ft_reassociate(struct netdev *netdev, + const struct scan_bss *target_bss, + const struct scan_bss *orig_bss, + netdev_event_func_t event_filter, + netdev_connect_cb_t cb, void *user_data) { - struct netdev *netdev = netdev_find(ifindex); - struct netdev_handshake_state *nhs; struct handshake_state *hs = netdev->handshake; + struct netdev_handshake_state *nhs; struct l_genl_msg *msg; struct iovec iov[64]; unsigned int n_iov = L_ARRAY_SIZE(iov); @@ -4232,11 +4221,14 @@ static int netdev_ft_tx_associate(uint32_t ifindex, uint32_t freq, * At this point there is no going back with FT so reset all the flags * needed to associate with a new BSS. */ - netdev->frequency = freq; + netdev->frequency = target_bss->frequency; netdev->handshake->active_tk_index = 0; netdev->associated = false; netdev->operational = false; netdev->in_ft = true; + netdev->event_filter = event_filter; + netdev->connect_cb = cb; + netdev->user_data = user_data; /* * Cancel commands that could be running because of EAPoL activity @@ -4280,15 +4272,22 @@ static int netdev_ft_tx_associate(uint32_t ifindex, uint32_t freq, c_iov = netdev_populate_common_ies(netdev, hs, msg, iov, n_iov, c_iov); - if (!L_WARN_ON(n_iov - c_iov < n_ft_iov)) { - memcpy(iov + c_iov, ft_iov, sizeof(*ft_iov) * n_ft_iov); - c_iov += n_ft_iov; - } + if (hs->supplicant_ie) + c_iov = iov_ie_append(iov, n_iov, c_iov, hs->supplicant_ie, + IE_LEN(hs->supplicant_ie)); + + if (hs->supplicant_fte) + c_iov = iov_ie_append(iov, n_iov, c_iov, hs->supplicant_fte, + IE_LEN(hs->supplicant_fte)); + + if (hs->mde) + c_iov = iov_ie_append(iov, n_iov, c_iov, hs->mde, + IE_LEN(hs->mde)); mpdu_sort_ies(subtype, iov, c_iov); l_genl_msg_append_attr(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, - prev_bssid); + orig_bss->addr); l_genl_msg_append_attrv(msg, NL80211_ATTR_IE, iov, c_iov); netdev->connect_cmd_id = l_genl_family_send(nl80211, msg, @@ -4735,7 +4734,7 @@ static void netdev_unprot_disconnect_event(struct l_genl_msg *msg, uint16_t type; uint16_t len; const void *data; - uint8_t reason_code; + uint16_t reason_code; if (!netdev->connected) return; @@ -4763,7 +4762,8 @@ static void netdev_unprot_disconnect_event(struct l_genl_msg *msg, reason_code = l_get_le16(mmpdu_body(hdr)); - l_info("disconnect event, src="MAC" dest="MAC" bssid="MAC" reason=%u", + l_info("unprotected disconnect event, src="MAC" dest="MAC + " bssid="MAC" reason=%u", MAC_STR(hdr->address_2), MAC_STR(hdr->address_1), MAC_STR(hdr->address_3), reason_code); @@ -6265,7 +6265,6 @@ static int netdev_init(void) __eapol_set_install_pmk_func(netdev_set_pmk); __ft_set_tx_frame_func(netdev_tx_ft_frame); - __ft_set_tx_associate_func(netdev_ft_tx_associate); unicast_watch = l_genl_add_unicast_watch(genl, NL80211_GENL_NAME, netdev_unicast_notify, diff --git a/src/netdev.h b/src/netdev.h @@ -50,7 +50,6 @@ enum netdev_event { NETDEV_EVENT_RSSI_THRESHOLD_HIGH, NETDEV_EVENT_RSSI_LEVEL_NOTIFY, NETDEV_EVENT_PACKET_LOSS_NOTIFY, - NETDEV_EVENT_FT_ROAMED, NETDEV_EVENT_BEACON_LOSS_NOTIFY, }; @@ -155,8 +154,6 @@ struct handshake_state *netdev_get_handshake(struct netdev *netdev); int netdev_connect(struct netdev *netdev, const struct scan_bss *bss, struct handshake_state *hs, - const struct iovec *vendor_ies, - size_t num_vendor_ies, netdev_event_func_t event_filter, netdev_connect_cb_t cb, void *user_data); int netdev_disconnect(struct netdev *netdev, @@ -167,6 +164,11 @@ int netdev_reassociate(struct netdev *netdev, struct handshake_state *hs, netdev_event_func_t event_filter, netdev_connect_cb_t cb, void *user_data); +int netdev_ft_reassociate(struct netdev *netdev, + const struct scan_bss *target_bss, + const struct scan_bss *orig_bss, + netdev_event_func_t event_filter, + netdev_connect_cb_t cb, void *user_data); int netdev_preauthenticate(struct netdev *netdev, const struct scan_bss *target_bss, diff --git a/src/network.c b/src/network.c @@ -70,6 +70,7 @@ struct network { struct network_info *info; unsigned char *psk; char *passphrase; + char *password_identifier; struct l_ecc_point *sae_pt_19; /* SAE PT for Group 19 */ struct l_ecc_point *sae_pt_20; /* SAE PT for Group 20 */ unsigned int agent_request; @@ -124,6 +125,13 @@ static void network_reset_passphrase(struct network *network) network->passphrase = NULL; } + if (network->password_identifier) { + explicit_bzero(network->password_identifier, + strlen(network->password_identifier)); + l_free(network->password_identifier); + network->password_identifier = NULL; + } + if (network->sae_pt_19) { l_ecc_point_free(network->sae_pt_19); network->sae_pt_19 = NULL; @@ -317,7 +325,8 @@ static struct l_ecc_point *network_generate_sae_pt(struct network *network, l_debug("Generating PT for Group %u", group); pt = crypto_derive_sae_pt_ecc(group, network->ssid, - network->passphrase, NULL); + network->passphrase, + network->password_identifier); if (!pt) l_warn("SAE PT generation for Group %u failed", group); @@ -462,6 +471,10 @@ static int network_set_handshake_secrets_psk(struct network *network, handshake_state_set_passphrase(hs, network->passphrase); + if (network->password_identifier) + handshake_state_set_password_identifier(hs, + network->password_identifier); + if (ie_rsnxe_capable(hs->authenticator_rsnxe, IE_RSNX_SAE_H2E)) { l_debug("Authenticator is SAE H2E capable"); @@ -495,6 +508,19 @@ int network_handshake_setup(struct network *network, struct scan_bss *bss, switch (network->security) { case SECURITY_PSK: + /* Check the BSS password ID settings match our configuration */ + if (bss->sae_pw_id_exclusive && !network->password_identifier) { + l_error("[Security].PasswordIdentifier is not set but " + "BSS requires SAE password identifiers"); + return -ENOKEY; + } + + if (!bss->sae_pw_id_used && network->password_identifier) { + l_error("[Security].PasswordIdentifier set but BSS " + "does not not use password identifiers"); + return -ENOKEY; + } + r = network_set_handshake_secrets_psk(network, hs); if (r < 0) return r; @@ -556,7 +582,6 @@ int network_handshake_setup(struct network *network, struct scan_bss *bss, } static int network_settings_load_pt_ecc(struct network *network, - const char *path, unsigned int group, struct l_ecc_point **out_pt) { @@ -581,7 +606,7 @@ static int network_settings_load_pt_ecc(struct network *network, return 0; bad_format: - l_error("%s: invalid %s format", path, key); + l_error("%s profile: invalid %s format", network->ssid, key); generate: if (!network->passphrase) @@ -594,8 +619,34 @@ generate: return -EIO; } -static int network_load_psk(struct network *network, bool need_passphrase) +static inline bool __bss_is_sae(const struct scan_bss *bss, + const struct ie_rsn_info *rsn) +{ + if (rsn->akm_suites & IE_RSN_AKM_SUITE_SAE_SHA256) + return true; + + return false; +} + +static bool bss_is_sae(const struct scan_bss *bss) { + struct ie_rsn_info rsn; + + memset(&rsn, 0, sizeof(rsn)); + scan_bss_get_rsn_info(bss, &rsn); + + return __bss_is_sae(bss, &rsn); +} + +static int network_load_psk(struct network *network, struct scan_bss *bss) +{ + /* + * A legacy psk file may only contain the PreSharedKey entry. For SAE + * networks the raw Passphrase is required. So in this case where + * the psk is found but no Passphrase, we ask the agent. The psk file + * will then be re-written to contain the raw passphrase. + */ + bool is_sae = bss_is_sae(bss); const char *ssid = network_get_ssid(network); enum security security = network_get_security(network); size_t psk_len; @@ -605,6 +656,9 @@ static int network_load_psk(struct network *network, bool need_passphrase) _auto_(l_free) char *passphrase = l_settings_get_string(network->settings, "Security", "Passphrase"); + _auto_(l_free) char *password_id = + l_settings_get_string(network->settings, "Security", + "PasswordIdentifier"); _auto_(l_free) char *path = storage_get_network_file_path(security, ssid); @@ -616,7 +670,7 @@ static int network_load_psk(struct network *network, bool need_passphrase) } /* PSK can be generated from the passphrase but not the other way */ - if (!psk || need_passphrase) { + if (!psk || is_sae) { if (!passphrase) return -ENOKEY; @@ -629,13 +683,12 @@ static int network_load_psk(struct network *network, bool need_passphrase) network_reset_passphrase(network); network_reset_psk(network); network->passphrase = l_steal_ptr(passphrase); + network->password_identifier = l_steal_ptr(password_id); - if (network_settings_load_pt_ecc(network, path, - 19, &network->sae_pt_19) > 0) + if (network_settings_load_pt_ecc(network, 19, &network->sae_pt_19) > 0) network->sync_settings = true; - if (network_settings_load_pt_ecc(network, path, - 20, &network->sae_pt_20) > 0) + if (network_settings_load_pt_ecc(network, 20, &network->sae_pt_20) > 0) network->sync_settings = true; network->psk = l_steal_ptr(psk); @@ -700,6 +753,11 @@ static void network_settings_save(struct network *network, l_settings_set_string(settings, "Security", "Passphrase", network->passphrase); + if (network->password_identifier) + l_settings_set_string(settings, "Security", + "PasswordIdentifier", + network->password_identifier); + if (network->sae_pt_19) network_settings_save_sae_pt_ecc(settings, network->sae_pt_19); @@ -744,21 +802,13 @@ const struct network_info *network_get_info(const struct network *network) return network->info; } -static void add_known_frequency(void *data, void *user_data) -{ - struct scan_bss *bss = data; - struct network_info *info = user_data; - - known_network_add_frequency(info, bss->frequency); -} - void network_set_info(struct network *network, struct network_info *info) { if (info) { network->info = info; network->info->seen_count++; - l_queue_foreach(network->bss_list, add_known_frequency, info); + network_update_known_frequencies(network); } else { network->info->seen_count--; network->info = NULL; @@ -780,25 +830,6 @@ bool network_get_force_default_owe_group(struct network *network) return network->force_default_owe_group; } -static inline bool __bss_is_sae(const struct scan_bss *bss, - const struct ie_rsn_info *rsn) -{ - if (rsn->akm_suites & IE_RSN_AKM_SUITE_SAE_SHA256) - return true; - - return false; -} - -static bool bss_is_sae(const struct scan_bss *bss) -{ - struct ie_rsn_info rsn; - - memset(&rsn, 0, sizeof(rsn)); - scan_bss_get_rsn_info(bss, &rsn); - - return __bss_is_sae(bss, &rsn); -} - int network_can_connect_bss(struct network *network, const struct scan_bss *bss) { struct station *station = network->station; @@ -961,7 +992,7 @@ int network_autoconnect(struct network *network, struct scan_bss *bss) switch (security) { case SECURITY_PSK: - ret = network_load_psk(network, bss_is_sae(bss)); + ret = network_load_psk(network, bss); if (ret < 0) goto close_settings; @@ -1050,15 +1081,39 @@ static bool match_hotspot_network(const struct network_info *info, return true; } +bool network_update_known_frequencies(struct network *network) +{ + const struct l_queue_entry *e; + struct l_queue *reversed; + + if (!network->info) + return false; + + reversed = l_queue_new(); + + for (e = l_queue_get_entries(network->bss_list); e; e = e->next) { + struct scan_bss *bss = e->data; + + l_queue_push_head(reversed, bss); + } + + for (e = l_queue_get_entries(reversed); e; e = e->next) { + struct scan_bss *bss = e->data; + + known_network_add_frequency(network->info, bss->frequency); + } + + l_queue_destroy(reversed, NULL); + + return true; +} + bool network_bss_add(struct network *network, struct scan_bss *bss) { if (!l_queue_insert(network->bss_list, bss, scan_bss_rank_compare, NULL)) return false; - if (network->info) - known_network_add_frequency(network->info, bss->frequency); - /* Done if BSS is not HS20 or we already have network_info set */ if (!bss->hs20_capable) return true; @@ -1287,20 +1342,13 @@ static struct l_dbus_message *network_connect_psk(struct network *network, struct l_dbus_message *message) { struct station *station = network->station; - /* - * A legacy psk file may only contain the PreSharedKey entry. For SAE - * networks the raw Passphrase is required. So in this case where - * the psk is found but no Passphrase, we ask the agent. The psk file - * will then be re-written to contain the raw passphrase. - */ - bool need_passphrase = bss_is_sae(bss); if (!network_settings_load(network)) { network->settings = l_settings_new(); network->ask_passphrase = true; } else if (!network->ask_passphrase) network->ask_passphrase = - network_load_psk(network, need_passphrase) < 0; + network_load_psk(network, bss) < 0; l_debug("ask_passphrase: %s", network->ask_passphrase ? "true" : "false"); @@ -2015,6 +2063,8 @@ static void known_networks_changed(enum known_networks_event event, case KNOWN_NETWORKS_EVENT_REMOVED: station_foreach(emit_known_network_removed, (void *) info); break; + case KNOWN_NETWORKS_EVENT_UPDATED: + break; } } diff --git a/src/network.h b/src/network.h @@ -61,6 +61,8 @@ void network_set_info(struct network *network, struct network_info *info); void network_set_force_default_owe_group(struct network *network); bool network_get_force_default_owe_group(struct network *network); +bool network_update_known_frequencies(struct network *network); + int network_can_connect_bss(struct network *network, const struct scan_bss *bss); int network_autoconnect(struct network *network, struct scan_bss *bss); diff --git a/src/p2p.c b/src/p2p.c @@ -1500,23 +1500,22 @@ static void p2p_handshake_event(struct handshake_state *hs, static void p2p_try_connect_group(struct p2p_device *dev) { struct scan_bss *bss = dev->conn_wsc_bss; - struct handshake_state *hs = NULL; + _auto_(handshake_state_free) struct handshake_state *hs = NULL; struct iovec ie_iov[16]; int ie_num = 0; int r; - struct p2p_association_req info = {}; + struct p2p_association_req info = { + .capability = dev->capability, + .device_info = dev->device_info, + }; struct ie_rsn_info bss_info = {}; struct ie_rsn_info rsn_info = {}; uint8_t rsne_buf[256]; uint8_t wfd_ie[32]; + _auto_(l_free) uint8_t *req_ie = + p2p_build_association_req(&info, &ie_iov[ie_num].iov_len); - info.capability = dev->capability; - info.device_info = dev->device_info; - - ie_iov[0].iov_base = p2p_build_association_req(&info, - &ie_iov[0].iov_len); - L_WARN_ON(!ie_iov[0].iov_base); - ie_num = 1; + ie_iov[ie_num++].iov_base = req_ie; if (dev->conn_own_wfd) { ie_iov[ie_num].iov_base = wfd_ie; @@ -1555,30 +1554,25 @@ static void p2p_try_connect_group(struct p2p_device *dev) handshake_state_set_event_func(hs, p2p_handshake_event, dev); handshake_state_set_ssid(hs, bss->ssid, bss->ssid_len); handshake_state_set_pmk(hs, dev->conn_psk, 32); + handshake_state_set_vendor_ies(hs, ie_iov, ie_num); if (dev->conn_peer_capability.group_caps & P2P_GROUP_CAP_IP_ALLOCATION) hs->support_ip_allocation = true; - r = netdev_connect(dev->conn_netdev, bss, hs, ie_iov, ie_num, + r = netdev_connect(dev->conn_netdev, bss, hs, p2p_netdev_event, p2p_netdev_connect_cb, dev); if (r < 0) { l_error("netdev_connect error: %s (%i)", strerror(-r), -r); goto error; } + l_steal_ptr(hs); dev->conn_retry_count++; - -done: - l_free(ie_iov[0].iov_base); return; error: not_supported: - if (hs) - handshake_state_free(hs); - p2p_connect_failed(dev); - goto done; } static void p2p_peer_provision_done(int err, struct wsc_credentials_info *creds, diff --git a/src/sae.c b/src/sae.c @@ -637,6 +637,14 @@ old_commit: ie_tlv_builder_set_data(&builder, sm->token, sm->token_len); } + if (sm->sae_type == CRYPTO_SAE_HASH_TO_ELEMENT && + sm->handshake->password_identifier) { + ie_tlv_builder_next(&builder, IE_TYPE_PASSWORD_IDENTIFIER); + ie_tlv_builder_set_data(&builder, + sm->handshake->password_identifier, + strlen(sm->handshake->password_identifier)); + } + ie_tlv_builder_finalize(&builder, &len); return ptr - commit + len; @@ -1096,11 +1104,19 @@ static int sae_verify_committed(struct sae_sm *sm, uint16_t transaction, * If the Status is some other nonzero value, the frame shall be * silently discarded and the t0 (retransmission) timer shall be set. */ - if (status != 0 && status != MMPDU_STATUS_CODE_SAE_HASH_TO_ELEMENT) + switch (status) { + case 0: + case MMPDU_STATUS_CODE_SAE_HASH_TO_ELEMENT: + if (status != sae_status_code(sm)) + return -EBADMSG; + break; + case MMPDU_STATUS_CODE_UNKNOWN_PASSWORD_IDENTIFIER: + sae_debug("Incorrect password identifier, check " + "[Security].PasswordIdentifier"); + /* fall through */ + default: return -ENOMSG; - - if (status != sae_status_code(sm)) - return -EBADMSG; + } if (len < 2) return -EBADMSG; diff --git a/src/scan.c b/src/scan.c @@ -1404,10 +1404,24 @@ static bool scan_parse_bss_information_elements(struct scan_bss *bss, * Currently only Proxy ARP bit (12) is checked, and if * not found, this is not a fatal error. */ - if (iter.len < 2) - break; + if (iter.len >= 2) + bss->proxy_arp = test_bit(iter.data, 12); + + /* + * 802.11-2020 Table 9-153 + * + * The spec merely mentions the "exclusive" bit and + * doesn't enforce a requirement to check it anywhere. + * But if set it would indicate the AP will only accept + * auths when a password ID is used so store this in + * order to fail early if no ID is set. + */ + if (iter.len >= 11) { + bss->sae_pw_id_used = test_bit(iter.data, 81); + bss->sae_pw_id_exclusive = + test_bit(iter.data, 82); + } - bss->proxy_arp = test_bit(iter.data, 12); } } diff --git a/src/scan.h b/src/scan.h @@ -88,6 +88,8 @@ struct scan_bss { uint8_t cost_level : 3; uint8_t cost_flags : 4; bool dpp_configurator : 1; + bool sae_pw_id_used : 1; + bool sae_pw_id_exclusive : 1; }; struct scan_parameters { diff --git a/src/station.c b/src/station.c @@ -64,6 +64,9 @@ #include "src/eap-tls-common.h" #include "src/storage.h" +#define STATION_RECENT_NETWORK_LIMIT 5 +#define STATION_RECENT_FREQS_LIMIT 5 + static struct l_queue *station_list; static uint32_t netdev_watch; static uint32_t mfp_setting; @@ -352,6 +355,8 @@ static bool process_network(const void *key, void *data, void *user_data) l_queue_insert(station->networks_sorted, network, network_rank_compare, NULL); + network_update_known_frequencies(network); + return false; } @@ -801,6 +806,8 @@ free: scan_bss_free(bss); } + network_update_known_frequencies(network); + l_queue_destroy(bss_list, NULL); done: @@ -1436,7 +1443,9 @@ static int station_quick_scan_trigger(struct station *station) return -EAGAIN; } - known_freq_set = known_networks_get_recent_frequencies(5); + known_freq_set = known_networks_get_recent_frequencies( + STATION_RECENT_NETWORK_LIMIT, + STATION_RECENT_FREQS_LIMIT); if (!known_freq_set) return -ENODATA; @@ -1499,6 +1508,8 @@ static const char *station_state_to_string(enum station_state state) return "ft-roaming"; case STATION_STATE_FW_ROAMING: return "fw-roaming"; + case STATION_STATE_NETCONFIG: + return "connecting (netconfig)"; } return "invalid"; @@ -1559,6 +1570,8 @@ static void station_enter_state(struct station *station, station_state_to_string(state)); #ifdef HAVE_DBUS + station_debug_event(station, station_state_to_string(state)); + disconnected = !station_is_busy(station); if ((disconnected && state > STATION_STATE_AUTOCONNECT_FULL) || @@ -1643,6 +1656,7 @@ static void station_enter_state(struct station *station, station_set_drop_unicast_l2_multicast(station, false); break; case STATION_STATE_DISCONNECTING: + case STATION_STATE_NETCONFIG: break; case STATION_STATE_ROAMING: case STATION_STATE_FT_ROAMING: @@ -1779,6 +1793,7 @@ static void station_reset_connection_state(struct station *station) if (station->state == STATION_STATE_CONNECTED || station->state == STATION_STATE_CONNECTING || station->state == STATION_STATE_CONNECTING_AUTO || + station->state == STATION_STATE_NETCONFIG || station_is_roaming(station)) network_disconnected(network); } @@ -2054,8 +2069,7 @@ static void station_netconfig_event_handler(enum netconfig_event event, dbus_pending_reply(&station->connect_pending, reply); } - if (L_IN_SET(station->state, STATION_STATE_CONNECTING, - STATION_STATE_CONNECTING_AUTO)) + if (station->state == STATION_STATE_NETCONFIG) network_connect_failed(station->connected_network, false); @@ -2081,9 +2095,14 @@ static bool netconfig_after_roam(struct station *station) network_get_settings(network))) return false; - return netconfig_configure(station->netconfig, + if (!netconfig_configure(station->netconfig, station_netconfig_event_handler, - station); + station)) + return false; + + station_enter_state(station, STATION_STATE_NETCONFIG); + + return true; } static void station_roamed(struct station *station) @@ -2195,7 +2214,8 @@ static void station_reassociate_cb(struct netdev *netdev, l_debug("%u, result: %d", netdev_get_ifindex(station->netdev), result); - if (station->state != STATION_STATE_ROAMING) + if (station->state != STATION_STATE_ROAMING && + station->state != STATION_STATE_FT_ROAMING) return; if (result == NETDEV_RESULT_OK) @@ -2225,8 +2245,6 @@ static int station_transition_reassociate(struct station *station, station->preparing_roam = false; station_enter_state(station, STATION_STATE_ROAMING); - station_debug_event(station, "reassoc-roam"); - return 0; } @@ -2328,7 +2346,8 @@ static bool station_ft_work_ready(struct wiphy_radio_work_item *item) if (!bss) goto try_next; - ret = ft_associate(netdev_get_ifindex(station->netdev), bss->addr); + ret = ft_handshake_setup(netdev_get_ifindex(station->netdev), + bss->addr); switch (ret) { case MMPDU_STATUS_CODE_INVALID_PMKID: /* @@ -2357,12 +2376,26 @@ try_next: station_transition_start(station); break; case 0: + ret = netdev_ft_reassociate(station->netdev, bss, + station->connected_bss, + station_netdev_event, + station_reassociate_cb, station); + if (ret < 0) + goto disassociate; + station->connected_bss = bss; station->preparing_roam = false; station_enter_state(station, STATION_STATE_FT_ROAMING); - station_debug_event(station, "ft-roam"); - + break; + case -EINVAL: + /* + * Likely an impossible situation, but since ft_handshake_setup + * rederived the handshake keys we can't do anything but + * disconnect. + */ +disassociate: + station_disassociated(station); break; default: if (ret > 0) @@ -2617,6 +2650,12 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list, util_address_to_string(current_bss->addr), util_ssid_to_utf8(current_bss->ssid_len, current_bss->ssid)); + /* + * Reverse now so the known frequency list gets updated in the correct + * order (via network_bss_update). + */ + l_queue_reverse(bss_list); + while ((bss = l_queue_pop_head(bss_list))) { double rank; uint32_t kbps100 = DIV_ROUND_CLOSEST(bss->data_rate, 100000); @@ -2747,7 +2786,8 @@ static int station_roam_scan_known_freqs(struct station *station) const struct network_info *info = network_get_info( station->connected_network); struct scan_freq_set *freqs = network_info_get_roam_frequencies(info, - station->connected_bss->frequency, 5); + station->connected_bss->frequency, + STATION_RECENT_FREQS_LIMIT); int r = -ENODATA; if (!freqs) @@ -3248,6 +3288,8 @@ static void station_connect_ok(struct station *station) station_netconfig_event_handler, station))) return; + + station_enter_state(station, STATION_STATE_NETCONFIG); } else station_enter_state(station, STATION_STATE_CONNECTED); } @@ -3340,6 +3382,7 @@ static void station_disconnect_event(struct station *station, void *event_data) case STATION_STATE_CONNECTED: case STATION_STATE_FT_ROAMING: case STATION_STATE_FW_ROAMING: + case STATION_STATE_NETCONFIG: station_disassociated(station); return; default: @@ -3402,6 +3445,16 @@ static void station_beacon_lost(struct station *station) station_roam_timeout_rearm(station, LOSS_ROAM_RATE_LIMIT); } +static void station_event_roaming(struct station *station) +{ + if (station->netconfig && station->state != STATION_STATE_CONNECTED) { + netconfig_reset(station->netconfig); + station->netconfig_after_roam = true; + } + + station_enter_state(station, STATION_STATE_FW_ROAMING); +} + static void station_netdev_event(struct netdev *netdev, enum netdev_event event, void *event_data, void *user_data) { @@ -3429,7 +3482,7 @@ static void station_netdev_event(struct netdev *netdev, enum netdev_event event, station_signal_agent_notify(station); break; case NETDEV_EVENT_ROAMING: - station_enter_state(station, STATION_STATE_FW_ROAMING); + station_event_roaming(station); break; case NETDEV_EVENT_ROAMED: station_event_roamed(station, (struct scan_bss *) event_data); @@ -3440,12 +3493,6 @@ static void station_netdev_event(struct netdev *netdev, enum netdev_event event, case NETDEV_EVENT_PACKET_LOSS_NOTIFY: station_packets_lost(station, l_get_u32(event_data)); break; - case NETDEV_EVENT_FT_ROAMED: - if (L_WARN_ON(station->state != STATION_STATE_FT_ROAMING)) - return; - - station_roamed(station); - break; case NETDEV_EVENT_BEACON_LOSS_NOTIFY: station_beacon_lost(station); break; @@ -3467,7 +3514,7 @@ int __station_connect_network(struct station *station, struct network *network, if (!hs) return -ENOTSUP; - r = netdev_connect(station->netdev, bss, hs, NULL, 0, + r = netdev_connect(station->netdev, bss, hs, station_netdev_event, station_connect_cb, station); if (r < 0) { @@ -3679,6 +3726,8 @@ next: return true; } + network_update_known_frequencies(network_psk ?: network_open); + error = network_connect_new_hidden_network(network_psk ?: network_open, msg); @@ -4068,8 +4117,10 @@ static struct l_dbus_message *station_dbus_scan(struct l_dbus *dbus, if (station->dbus_scan_id) return dbus_error_busy(message); - if (station->state == STATION_STATE_CONNECTING || - station->state == STATION_STATE_CONNECTING_AUTO) + if (L_IN_SET(station->state, STATION_STATE_CONNECTING, + STATION_STATE_CONNECTING_AUTO, + STATION_STATE_NETCONFIG) || + station_is_roaming(station)) return dbus_error_busy(message); station->dbus_scan_subset_idx = 0; @@ -4280,6 +4331,7 @@ static bool station_property_get_state(struct l_dbus *dbus, break; case STATION_STATE_CONNECTING: case STATION_STATE_CONNECTING_AUTO: + case STATION_STATE_NETCONFIG: statestr = "connecting"; break; case STATION_STATE_CONNECTED: @@ -4291,7 +4343,14 @@ static bool station_property_get_state(struct l_dbus *dbus, case STATION_STATE_ROAMING: case STATION_STATE_FT_ROAMING: case STATION_STATE_FW_ROAMING: - statestr = "roaming"; + /* + * Stay in a connecting state if roaming before netconfig + * has finished + */ + if (station->netconfig_after_roam) + statestr = "connecting"; + else + statestr = "roaming"; break; } @@ -5031,8 +5090,10 @@ static struct l_dbus_message *station_debug_scan(struct l_dbus *dbus, if (station->dbus_scan_id) return dbus_error_busy(message); - if (station->state == STATION_STATE_CONNECTING || - station->state == STATION_STATE_CONNECTING_AUTO) + if (L_IN_SET(station->state, STATION_STATE_CONNECTING, + STATION_STATE_CONNECTING_AUTO, + STATION_STATE_NETCONFIG) || + station_is_roaming(station)) return dbus_error_busy(message); if (!l_dbus_message_get_arguments(message, "aq", &iter)) diff --git a/src/station.h b/src/station.h @@ -45,6 +45,7 @@ enum station_state { STATION_STATE_ROAMING, /* Reassociation */ STATION_STATE_FT_ROAMING, /* Fast transition */ STATION_STATE_FW_ROAMING, /* Firmware roamed by itself */ + STATION_STATE_NETCONFIG, }; enum station_event { diff --git a/src/wiphy.c b/src/wiphy.c @@ -248,6 +248,9 @@ static bool wiphy_can_connect_sae(struct wiphy *wiphy) * * TODO: No support for CMD_EXTERNAL_AUTH yet. */ + l_warn("SAE unsupported: %s needs CMD_EXTERNAL_AUTH for SAE", + wiphy->driver_str); + return false; } @@ -312,8 +315,10 @@ enum ie_rsn_akm_suite wiphy_select_akm(struct wiphy *wiphy, if (ie_rsne_is_wpa3_personal(info)) { l_debug("Network is WPA3-Personal..."); - if (!wiphy_can_connect_sae(wiphy)) + if (!wiphy_can_connect_sae(wiphy)) { + l_debug("Can't use SAE, trying WPA2"); goto wpa2_personal; + } if (info->akm_suites & IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256) diff --git a/src/wsc.c b/src/wsc.c @@ -382,7 +382,9 @@ static int wsc_enrollee_connect(struct wsc_enrollee *wsce, struct scan_bss *bss, if (ies_num) memcpy(ie_iov + 1, ies, sizeof(struct iovec) * ies_num); - r = netdev_connect(wsce->netdev, bss, hs, ie_iov, 1 + ies_num, + handshake_state_set_vendor_ies(hs, ie_iov, 1 + ies_num); + + r = netdev_connect(wsce->netdev, bss, hs, wsc_enrollee_netdev_event, wsc_enrollee_connect_cb, wsce); l_free(ie_iov[0].iov_base); @@ -652,6 +654,7 @@ static void wsc_check_can_connect(struct wsc_station_dbus *wsc, case STATION_STATE_CONNECTING: case STATION_STATE_CONNECTING_AUTO: case STATION_STATE_CONNECTED: + case STATION_STATE_NETCONFIG: if (station_disconnect(wsc->station) < 0) goto error; diff --git a/tools/runner.py b/tools/runner.py @@ -552,7 +552,12 @@ class UmlRunner(RunnerAbstract): kern_log = "ignore_loglevel" if "kernel" in args.verbose else "quiet" - cmd = [args.kernel, 'rootfstype=hostfs', 'ro', 'mem=256M', 'mac80211_hwsim.radios=0', + if self.args.valgrind: + ram = 512 + else: + ram = 256 + + cmd = [args.kernel, 'rootfstype=hostfs', 'ro', f'mem={ram}M', 'mac80211_hwsim.radios=0', 'time-travel=inf-cpu', 'eth0=mcast', 'eth1=mcast', '%s' % kern_log, 'init=%s' % self.init] cmd.extend(args.to_cmd().split(' ')) diff --git a/tools/utils.py b/tools/utils.py @@ -34,6 +34,9 @@ class Process(subprocess.Popen): logfile = args[0] + if not shutil.which(args[0]): + raise Exception("%s is not found on system" % args[0]) + if Process.is_verbose(args[0], log=False): self.verbose = True diff --git a/unit/gencerts.cnf b/unit/gencerts.cnf @@ -16,7 +16,6 @@ authorityKeyIdentifier = keyid:always,issuer:always [ cert_ext ] basicConstraints = CA:FALSE subjectKeyIdentifier = hash -authorityKeyIdentifier = keyid:always,issuer:always [ server_ext ] basicConstraints = CA:FALSE diff --git a/unit/test-eapol.c b/unit/test-eapol.c @@ -3493,7 +3493,7 @@ static void eapol_ft_handshake_test(const void *data) handshake_state_set_supplicant_ie(hs, own_rsne); handshake_state_set_authenticator_ie(hs, ap_rsne); handshake_state_set_mde(hs, mde); - handshake_state_set_fte(hs, fte); + handshake_state_set_authenticator_fte(hs, fte); handshake_state_set_kh_ids(hs, r0khid, strlen((void *) r0khid), r1khid); eapol_start(sm);