commit d48282da6a099150ab6a075cf4c55d9305339b48 parent 389b1ddd5de488d6b143328f3a2094b8ce1c9da6 Author: illiliti <illiliti@protonmail.com> Date: Mon, 18 Mar 2024 17:28:57 +0300 Merge tag '2.16' Release 2.16 Diffstat:
49 files changed, 648 insertions(+), 131 deletions(-)
diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,17 @@ +ver 2.16: + Fix issue with uninitialized variable and DPP encrypt. + Fix issue with Access Point mode and ATTR_MAC validation. + Fix issue with Access Point mode and frequency attributes. + Fix issue with P2P and handling client info description. + Fix issue with P2P and handling parsing of service info. + Fix issue with netconfig and handling domain list. + Add support for forcing a default ECC group. + +ver 2.15: + Fix issue with notice events for connection timeouts. + Fix issue with reason code and deauthenticate event. + Fix issue with handling basename() functionality. + ver 2.14: Fix issue with accepting PTK 4/4 after receiving PTK 2/4. Fix issue with frequency limit for quick scans. diff --git a/autotests/testFrameFuzzing/fake_ap.py b/autotests/testFrameFuzzing/fake_ap.py @@ -0,0 +1,72 @@ +import unittest +import sys +import sys +import os +from scapy.layers.dot11 import * +from scapy.arch import str2mac, get_if_raw_hwaddr +from time import time, sleep +from threading import Thread + +def if_hwaddr(iff): + return str2mac(get_if_raw_hwaddr(iff)[1]) + +def config_mon(iface, channel): + """set the interface in monitor mode and then change channel using iw""" + os.system("ip link set dev %s down" % iface) + os.system("iw dev %s set type monitor" % iface) + os.system("ip link set dev %s up" % iface) + os.system("iw dev %s set channel %d" % (iface, channel)) + +class AP: + def __init__(self, ssid, psk, mac=None, mode="stdio", iface="wlan0", channel=1): + self.channel = channel + self.iface = iface + self.mode = mode + if self.mode == "iface": + if not mac: + mac = if_hwaddr(iface) + config_mon(iface, channel) + if not mac: + raise Exception("Need a mac") + else: + self.mac = mac + self.boottime = time() + + def get_radiotap_header(self): + return RadioTap() + + def dot11_beacon(self, contents): + evil_packet = ( + self.get_radiotap_header() + / Dot11( + subtype=8, addr1="ff:ff:ff:ff:ff:ff", addr2=self.mac, addr3=self.mac + ) + / Dot11Beacon(cap=0x3101) + / contents + ) + self.sendp(evil_packet) + + def run(self, contents): + interval = 0.05 + num_beacons = 100 + + while num_beacons: + self.dot11_beacon(contents) + sleep(interval) + num_beacons -= 1 + + def start(self, contents): + self.thread = Thread(target=self.run, args=(contents,)) + self.thread.start() + + def stop(self): + self.thread.join() + + def sendp(self, packet, verbose=False): + if self.mode == "stdio": + x = packet.build() + sys.stdout.buffer.write(struct.pack("<L", len(x)) + x) + sys.stdout.buffer.flush() + return + assert self.mode == "iface" + sendp(packet, iface=self.iface, verbose=False) diff --git a/autotests/testFrameFuzzing/hw.conf b/autotests/testFrameFuzzing/hw.conf @@ -0,0 +1,7 @@ +[SETUP] +num_radios=2 +start_iwd=0 +hwsim_medium=yes + +[rad1] +reserve=true diff --git a/autotests/testFrameFuzzing/test_frame_fuzzing.py b/autotests/testFrameFuzzing/test_frame_fuzzing.py @@ -0,0 +1,37 @@ +#! /usr/bin/python3 + +import unittest +import sys +import sys +import os +from fake_ap import AP + +sys.path.append('../util') +from iwd import IWD + +# Probe frame that causes IWD to crash +beacon=b'\xdd\nPo\x9a\t\x0e\x00\x00\x19\x10\x00\xdd/Po\x9a\t\x0c\x02\x00\x00\xdd\x05\x03\x03\x03Po\x9a\x10\x00\x0b\x05\x0e\x00\x00\x00\x00\x0b\x05\x00\x00\x00\xdd\x05\x00\x03\x03\x03\x03\x00\x00\x00\xdd\x05\x03\x03\x03\x03\x03' + +class Test(unittest.TestCase): + def test_beacon_crash(self): + wd = IWD(True) + + devs = wd.list_devices() + + self.assertEqual(len(devs), 1) + + devs[0].autoconnect = True + + os.system("iw phy rad1 interface add wlan1 type managed") + + ap = AP("evilAP", "password1234", mode="iface", iface="wlan1", channel=4) + ap.start(beacon) + + condition = "obj.scanning == True" + wd.wait_for_object_condition(devs[0], condition) + + condition = "obj.scanning == False" + wd.wait_for_object_condition(devs[0], condition) + +if __name__ == '__main__': + unittest.main(exit=True) diff --git a/autotests/testNetconfig/slaac_test.py b/autotests/testNetconfig/slaac_test.py @@ -81,14 +81,21 @@ class Test(unittest.TestCase): self.assertEqual(expected_routes6, set(testutil.get_routes6(ifname))) rclog = open('/tmp/resolvconf.log', 'r') - entries = rclog.readlines() + entries = [l.strip() for l in rclog.readlines()[-7:]] rclog.close() - expected_rclog = ['-a %s.dns\n' % (ifname,), 'nameserver 192.168.1.2\n', - 'nameserver 3ffe:501:ffff:100::10\n', 'nameserver 3ffe:501:ffff:100::50\n', - '-a %s.domain\n' % (ifname,), 'search test1\n', 'search test2\n'] - # Every resolvconf -a run overwrites the previous settings. Check the last seven lines - # of our log since we care about the end result here. - self.assertEqual(expected_rclog, entries[-7:]) + expected_rclog = [ + '-a %s.dns' % (ifname,), + 'nameserver 192.168.1.2', + 'nameserver 3ffe:501:ffff:100::10', + 'nameserver 3ffe:501:ffff:100::50', + '-a %s.domain' % (ifname,), + 'search test1', + 'search test2' + ] + + for line in expected_rclog: + self.assertIn(line, entries) + expected_rclog.remove(line) device.disconnect() condition = 'not obj.connected' diff --git a/autotests/testOWE/connection_test.py b/autotests/testOWE/connection_test.py @@ -64,6 +64,39 @@ class Test(unittest.TestCase): self.assertRaises(Exception, testutil.test_ifaces_connected, (hapd0.ifname, device.name, True, True)) + def test_auto_default_group(self): + wd = IWD() + hapd = HostapdCLI(config='ssidOWE-1.conf') + + devices = wd.list_devices(1) + device = devices[0] + + device.get_ordered_network('ssidOWE') + + device.connect_bssid(hapd.bssid) + + condition = 'obj.state == DeviceState.connected' + wd.wait_for_object_condition(device, condition) + + # Should have rejected group 20, but still connected on 19 + self.assertEqual(device.event_ocurred("ecc-group-rejected"), True) + + testutil.test_iface_operstate() + testutil.test_ifaces_connected(device.name, hapd.ifname) + + device.disconnect() + + device.connect_bssid(hapd.bssid) + + condition = 'obj.state == DeviceState.connected' + wd.wait_for_object_condition(device, condition) + + # IWD should have used the default group, no rejection + self.assertEqual(device.event_ocurred("ecc-group-rejected"), False) + + testutil.test_iface_operstate() + testutil.test_ifaces_connected(device.name, hapd.ifname) + @classmethod def setUpClass(cls): pass diff --git a/autotests/testPSK-roam/failed_roam_test.py b/autotests/testPSK-roam/failed_roam_test.py @@ -221,6 +221,8 @@ class Test(unittest.TestCase): cls.rule_bss2 = hwsim.rules.create() cls.rule_bss2.source = hwsim.get_radio('rad2').addresses[0] + HostapdCLI.group_neighbors(*cls.bss_hostapd) + @classmethod def tearDownClass(cls): IWD.clear_storage() diff --git a/autotests/testSAE/autoconnect_test.py b/autotests/testSAE/autoconnect_test.py @@ -12,8 +12,7 @@ from hostapd import HostapdCLI class Test(unittest.TestCase): - def validate_connection(self, wd): - + def validate_connection(self, wd, ssid): devices = wd.list_devices(1) self.assertIsNotNone(devices) device = devices[0] @@ -25,7 +24,7 @@ class Test(unittest.TestCase): condition = 'obj.connected_network is not None' wd.wait_for_object_condition(device, condition) - ordered_network = device.get_ordered_network('ssidSAE') + ordered_network = device.get_ordered_network(ssid) self.assertTrue(ordered_network.network_object.connected) @@ -35,29 +34,27 @@ 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") + IWD.copy_to_storage("profiles/ssidSAE.psk.default", name="ssidSAE.psk") self.hostapd.wait_for_event("AP-ENABLED") wd = IWD(True) - self.validate_connection(wd) + self.validate_connection(wd, "ssidSAE") 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") + IWD.copy_to_storage("profiles/ssidSAE.psk.default", name="ssidSAE-H2E.psk") + self.hostapd_h2e.set_value('sae_groups', '20') + self.hostapd_h2e.reload() + self.hostapd_h2e.wait_for_event("AP-ENABLED") wd = IWD(True) - self.validate_connection(wd) + self.validate_connection(wd, "ssidSAE-H2E") 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() - self.hostapd.wait_for_event("AP-ENABLED") + IWD.copy_to_storage("profiles/ssidSAE.psk.identifier", name="ssidSAE-H2E.psk") + self.hostapd_h2e.set_value('sae_groups', '20') + self.hostapd_h2e.reload() + self.hostapd_h2e.wait_for_event("AP-ENABLED") wd = IWD(True) - self.validate_connection(wd) + self.validate_connection(wd, "ssidSAE-H2E") def setUp(self): self.hostapd.default() @@ -68,6 +65,7 @@ class Test(unittest.TestCase): @classmethod def setUpClass(cls): cls.hostapd = HostapdCLI(config='ssidSAE.conf') + cls.hostapd_h2e = HostapdCLI(config='ssidSAE-H2E.conf') if __name__ == '__main__': unittest.main(exit=True) diff --git a/autotests/testSAE/connection_test.py b/autotests/testSAE/connection_test.py @@ -13,7 +13,7 @@ import testutil class Test(unittest.TestCase): - def validate_connection(self, wd): + def validate_connection(self, wd, ssid, hostapd, expected_group): psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) @@ -23,11 +23,11 @@ class Test(unittest.TestCase): device.disconnect() - network = device.get_ordered_network('ssidSAE', full_scan=True) + network = device.get_ordered_network(ssid, full_scan=True) self.assertEqual(network.type, NetworkType.psk) - network.network_object.connect() + network.network_object.connect(wait=False) condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) @@ -35,7 +35,11 @@ class Test(unittest.TestCase): wd.wait(2) testutil.test_iface_operstate(intf=device.name) - testutil.test_ifaces_connected(if0=device.name, if1=self.hostapd.ifname) + testutil.test_ifaces_connected(if0=device.name, if1=hostapd.ifname) + + sta_status = hostapd.sta_status(device.address) + + self.assertEqual(int(sta_status["sae_group"]), expected_group) device.disconnect() @@ -46,37 +50,31 @@ class Test(unittest.TestCase): def test_SAE(self): self.hostapd.wait_for_event("AP-ENABLED") - self.validate_connection(self.wd) + self.validate_connection(self.wd, "ssidSAE", self.hostapd, 19) def test_SAE_force_group_19(self): # Vendor data from APs which require group 19 be used first - # TODO: (for all tests) verify the expected group was used - self.hostapd.set_value('vendor_elements', 'dd0cf4f5e8050500000000000000') self.hostapd.reload() self.hostapd.wait_for_event("AP-ENABLED") - self.validate_connection(self.wd) + self.validate_connection(self.wd, "ssidSAE-default-group", self.hostapd_defgroup, 19) def test_SAE_Group20(self): self.hostapd.set_value('sae_groups', '20') - self.hostapd.set_value('vendor_elements', '') self.hostapd.reload() self.hostapd.wait_for_event("AP-ENABLED") - self.validate_connection(self.wd) + self.validate_connection(self.wd, "ssidSAE", self.hostapd, 20) def test_SAE_H2E(self): - self.hostapd.set_value('sae_pwe', '1') - self.hostapd.set_value('vendor_elements', '') - self.hostapd.reload() - self.hostapd.wait_for_event("AP-ENABLED") - self.validate_connection(self.wd) + self.hostapd_h2e.set_value('sae_groups', '19') + self.hostapd_h2e.reload() + self.hostapd_h2e.wait_for_event("AP-ENABLED") + self.validate_connection(self.wd, "ssidSAE-H2E", self.hostapd_h2e, 19) def test_SAE_H2E_Group20(self): - self.hostapd.set_value('sae_pwe', '1') - self.hostapd.set_value('sae_groups', '20') - self.hostapd.set_value('vendor_elements', '') - self.hostapd.reload() - self.hostapd.wait_for_event("AP-ENABLED") - self.validate_connection(self.wd) + self.hostapd_h2e.set_value('sae_groups', '20') + self.hostapd_h2e.reload() + self.hostapd_h2e.wait_for_event("AP-ENABLED") + self.validate_connection(self.wd, "ssidSAE-H2E", self.hostapd_h2e, 20) def setUp(self): self.hostapd.default() @@ -89,6 +87,8 @@ class Test(unittest.TestCase): @classmethod def setUpClass(cls): cls.hostapd = HostapdCLI(config='ssidSAE.conf') + cls.hostapd_h2e = HostapdCLI(config='ssidSAE-H2E.conf') + cls.hostapd_defgroup = HostapdCLI(config='ssidSAE-default-group.conf') @classmethod def tearDownClass(cls): diff --git a/autotests/testSAE/default_group_test.py b/autotests/testSAE/default_group_test.py @@ -0,0 +1,96 @@ +#!/usr/bin/python3 + +import unittest +import sys +import os +sys.path.append('../util') +import iwd +from iwd import IWD +from iwd import PSKAgent +from iwd import NetworkType +from hostapd import HostapdCLI +import testutil + +class Test(unittest.TestCase): + + def validate_connection(self, wd, rejected=False): + devices = wd.list_devices(1) + self.assertIsNotNone(devices) + device = devices[0] + + device.autoconnect = True + + if rejected: + device.wait_for_event("ecc-group-rejected", timeout=60) + + condition = 'obj.state == DeviceState.connected' + wd.wait_for_object_condition(device, condition) + + wd.wait(2) + + testutil.test_iface_operstate(intf=device.name) + testutil.test_ifaces_connected(if0=device.name, if1=self.hostapd.ifname) + + if not rejected: + self.assertEqual(device.event_ocurred("ecc-group-rejected"), False) + + print(self.hostapd._get_status()) + + sta_status = self.hostapd.sta_status(device.address) + + print(sta_status) + + self.assertEqual(int(sta_status["sae_group"]), 19) + + device.disconnect() + + # IWD should: + # - Connect, fail with group 20 + # - Retry, succeed with group 19 + # - Disconnect + # - Connect, try only group 19 + def test_auto_selection(self): + IWD.copy_to_storage("profiles/ssidSAE.psk.default", name="ssidSAE.psk") + self.validate_connection(self.wd, rejected=True) + + self.validate_connection(self.wd, rejected=False) + + # Try group 19 first + def test_default_group_enabled(self): + IWD.copy_to_storage("profiles/ssidSAE.psk.default_group", name="ssidSAE.psk") + self.validate_connection(self.wd) + + # Same as auto-selection but won't retain the default group setting + def test_default_group_disabled(self): + IWD.copy_to_storage("profiles/ssidSAE.psk.most_secure", name="ssidSAE.psk") + self.validate_connection(self.wd, rejected=True) + + # IWD should then retry but use only group 19 + self.validate_connection(self.wd, rejected=True) + + def setUp(self): + self.hostapd.default() + self.hostapd.set_value('sae_groups', '19') + self.hostapd.set_value('sae_pwe', '0') + self.hostapd.reload() + self.hostapd.wait_for_event("AP-ENABLED") + self.wd = IWD(True) + + self.wd.clear_storage() + os.system("ls /tmp/iwd") + + def tearDown(self): + self.wd.clear_storage() + self.wd = None + + @classmethod + def setUpClass(cls): + cls.hostapd = HostapdCLI(config='ssidSAE.conf') + cls.hostapd.default() + + @classmethod + def tearDownClass(cls): + pass + +if __name__ == '__main__': + unittest.main(exit=True) diff --git a/autotests/testSAE/hw.conf b/autotests/testSAE/hw.conf @@ -1,7 +1,9 @@ [SETUP] -num_radios=2 +num_radios=4 start_iwd=0 hwsim_medium=yes [HOSTAPD] rad0=ssidSAE.conf +rad1=ssidSAE-H2E.conf +rad2=ssidSAE-default-group.conf diff --git a/autotests/testSAE/ssidSAE.psk.default b/autotests/testSAE/profiles/ssidSAE-H2E.psk.default diff --git a/autotests/testSAE/ssidSAE.psk.default b/autotests/testSAE/profiles/ssidSAE.psk.default diff --git a/autotests/testSAE/profiles/ssidSAE.psk.default_group b/autotests/testSAE/profiles/ssidSAE.psk.default_group @@ -0,0 +1,5 @@ +[Security] +Passphrase=secret123 + +[Settings] +UseDefaultEccGroup=true diff --git a/autotests/testSAE/ssidSAE.psk.identifier b/autotests/testSAE/profiles/ssidSAE.psk.identifier diff --git a/autotests/testSAE/profiles/ssidSAE.psk.most_secure b/autotests/testSAE/profiles/ssidSAE.psk.most_secure @@ -0,0 +1,5 @@ +[Security] +Passphrase=secret123 + +[Settings] +UseDefaultEccGroup=false +\ No newline at end of file diff --git a/autotests/testSAE/ssidSAE-H2E.conf b/autotests/testSAE/ssidSAE-H2E.conf @@ -0,0 +1,12 @@ +hw_mode=g +channel=1 +ssid=ssidSAE-H2E + +wpa=2 +wpa_key_mgmt=SAE +wpa_pairwise=CCMP +sae_password=secret123 +sae_password=withidentifier|id=myidentifier +sae_groups=19 +ieee80211w=2 +sae_pwe=1 diff --git a/autotests/testSAE/ssidSAE-default-group.conf b/autotests/testSAE/ssidSAE-default-group.conf @@ -0,0 +1,12 @@ +hw_mode=g +channel=1 +ssid=ssidSAE-default-group + +wpa=2 +wpa_key_mgmt=SAE +wpa_pairwise=CCMP +sae_password=secret123 +sae_groups=19 +ieee80211w=2 +sae_pwe=0 +vendor_elements=dd0cf4f5e8050500000000000000 diff --git a/autotests/testSAE/ssidSAE.conf b/autotests/testSAE/ssidSAE.conf @@ -6,7 +6,6 @@ wpa=2 wpa_key_mgmt=SAE wpa_pairwise=CCMP sae_password=secret123 -sae_password=withidentifier|id=myidentifier sae_groups=19 ieee80211w=2 sae_pwe=0 diff --git a/autotests/util/hostapd.py b/autotests/util/hostapd.py @@ -306,6 +306,22 @@ class HostapdCLI(object): return ret + def sta_status(self, address): + ret = {} + + cmd = self.cmdline + ['sta', address] + proc = ctx.start_process(cmd) + proc.wait() + status = proc.out.strip().split('\n') + + # Pop address + status.pop(0) + for kv in status: + k, v = kv.split('=', 1) + ret[k] = v + + return ret + @property def bssid(self): return self._get_status()['bssid[0]'] diff --git a/autotests/util/iwd.py b/autotests/util/iwd.py @@ -303,6 +303,9 @@ class StationDebug(IWDDBusAbstract): return ctx.non_block_wait(self._poll_event, timeout, event, exception=TimeoutError("waiting for event")) + def event_ocurred(self, event): + return self._poll_event(event) + class DeviceProvisioning(IWDDBusAbstract): ''' Class represents net.connman.iwd.DeviceProvisioning @@ -856,6 +859,9 @@ class Device(IWDDBusAbstract): def wait_for_event(self, event, timeout=10): self._station_debug.wait_for_event(event, timeout) + def event_ocurred(self, event): + return self._station_debug.event_ocurred(event) + def dpp_start_enrollee(self): ret = self._device_provisioning.start_enrollee() diff --git a/client/diagnostic.c b/client/diagnostic.c @@ -93,6 +93,7 @@ static const struct diagnostic_dict_mapping diagnostic_mapping[] = { { "RxMCS", 'y' }, { "TxMCS", 'y' }, { "Frequency", 'u' }, + { "Channel", 'q' }, { "Security", 's' }, { NULL } }; @@ -109,6 +110,7 @@ void diagnostic_display(struct l_dbus_message_iter *dict, while (l_dbus_message_iter_next_entry(dict, &key, &variant)) { const char *s_value; uint32_t u_value; + uint16_t q_value; int16_t n_value; uint8_t y_value; int bytes; @@ -145,6 +147,14 @@ void diagnostic_display(struct l_dbus_message_iter *dict, bytes = sprintf(display_text, "%u", u_value); break; + case 'q': + if (!l_dbus_message_iter_get_variant(&variant, "q", + &q_value)) + goto parse_error; + + bytes = sprintf(display_text, "%u", q_value); + break; + case 'n': if (!l_dbus_message_iter_get_variant(&variant, "n", &n_value)) diff --git a/configure.ac b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.69]) -AC_INIT([iwd],[2.14]) +AC_INIT([iwd],[2.16]) AC_CONFIG_HEADERS(config.h) AC_CONFIG_AUX_DIR(build-aux) @@ -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.62" + ell_min_version="0.63" else ell_min_version="0.5" fi diff --git a/doc/coding-style.txt b/doc/coding-style.txt @@ -317,6 +317,21 @@ Functions that are static should not be forward-declared. The only exception to this rule is if a circular dependency condition exists, and the forward declaration cannot be avoided. +M18: Use appropriate logging levels +=================================== +An appropriate log level should be used depending on the type of message +being logged. Logging is done using the l_log APIs in ELL: + +l_error An unexpected condition ocurred. These are generally fatal to the + current connection/protocol that is running but not generally to IWD's + overall operation. +l_warn An unexpected, but non-fatal condition ocurred +l_notice Should not be used directly. This log level is reserved for special + event type notifications which is handled by iwd_notice(). +l_info Information that is expected during normal operation. l_info's use + should be very limited so non-debug logs are concise +l_debug General debugging. These can be used relatively freely but should + provide some piece of useful information. O1: Shorten the name ==================== diff --git a/doc/station-diagnostic-api.txt b/doc/station-diagnostic-api.txt @@ -23,6 +23,8 @@ Methods dict GetDiagnostics() Frequency - Frequency of currently connected BSS. + Channel - The WLAN channel number of currently connected BSS. + Security - The chosen security for the connection. RSSI [optional] - The RSSI of the currently connected BSS. diff --git a/src/ap.c b/src/ap.c @@ -455,7 +455,8 @@ static void ap_del_station(struct sta_state *sta, uint16_t reason, sta->ip_alloc_lease = NULL; l_dhcp_server_expire_by_mac(ap->netconfig_dhcp, sta->addr); - ap_event_done(ap, prev); + if (ap_event_done(ap, prev)) + return; } /* @@ -1247,8 +1248,10 @@ static size_t ap_build_country_ie(struct ap_state *ap, uint8_t *out_buf, } /* finish final group */ - *pos++ = nchans; - *pos++ = last->tx_power; + if (last) { + *pos++ = nchans; + *pos++ = last->tx_power; + } len = pos - out_buf - 2; @@ -1482,7 +1485,7 @@ static void ap_handshake_event(struct handshake_state *hs, } case HANDSHAKE_EVENT_REKEY_COMPLETE: ap_set_sta_rekey_timer(ap, sta); - return; + break; default: break; } @@ -2961,7 +2964,7 @@ static void ap_handle_new_station(struct ap_state *ap, struct l_genl_msg *msg) uint16_t type; uint16_t len; const void *data; - uint8_t mac[6]; + const uint8_t *mac = NULL; uint8_t *assoc_rsne = NULL; if (!l_genl_attr_init(&attr, msg)) @@ -2981,12 +2984,12 @@ static void ap_handle_new_station(struct ap_state *ap, struct l_genl_msg *msg) if (len != 6) goto cleanup; - memcpy(mac, data, 6); + mac = data; break; } } - if (!assoc_rsne) + if (!assoc_rsne || !mac) goto cleanup; /* diff --git a/src/crypto.c b/src/crypto.c @@ -331,7 +331,7 @@ bool aes_siv_encrypt(const void *key, size_t key_len, const void *in, struct iovec iov[num_ad + 1]; uint8_t v[16]; - if (ad) + if (ad && num_ad) memcpy(iov, ad, sizeof(struct iovec) * num_ad); iov[num_ad].iov_base = (void *)in; @@ -390,7 +390,7 @@ bool aes_siv_decrypt(const void *key, size_t key_len, const void *in, if (in_len < 16) return false; - if (ad) + if (ad && num_ad) memcpy(iov, ad, sizeof(struct iovec) * num_ad); iov[num_ad].iov_base = (void *)out; diff --git a/src/eap-wsc.c b/src/eap-wsc.c @@ -695,6 +695,8 @@ static void eap_wsc_send_m5(struct eap_state *eap, size_t encrypted_len; bool r; + memset(m5.authenticator, 0, sizeof(m5.authenticator)); + memcpy(m5es.e_snonce1, wsc->local_snonce1, sizeof(wsc->local_snonce1)); pdu = wsc_build_m5_encrypted_settings(&m5es, &pdu_len); explicit_bzero(m5es.e_snonce1, sizeof(wsc->local_snonce1)); @@ -797,6 +799,8 @@ static void eap_wsc_send_m3(struct eap_state *eap, uint8_t *pdu; size_t pdu_len; + memset(m3.authenticator, 0, sizeof(m3.authenticator)); + len = strlen(wsc->device_password); /* WSC 2.0.5, Section 7.4: @@ -975,6 +979,8 @@ static void eap_wsc_r_send_m8(struct eap_state *eap, unsigned int auth_types = wsc->m1->auth_type_flags & wsc->m2->auth_type_flags; + memset(m8.authenticator, 0, sizeof(m8.authenticator)); + if (auth_types & WSC_AUTHENTICATION_TYPE_OPEN) memcpy(&creds[creds_cnt++], &wsc->open_cred, sizeof(struct wsc_credential)); @@ -1022,6 +1028,9 @@ static void eap_wsc_r_handle_m7(struct eap_state *eap, struct wsc_m7_encrypted_settings m7es; enum wsc_configuration_error error = WSC_CONFIGURATION_ERROR_NO_ERROR; + memset(m7es.authenticator, 0, sizeof(m7es.authenticator)); + memset(m7.authenticator, 0, sizeof(m7.authenticator)); + /* Spec unclear what to do here, see comments in eap_wsc_send_nack */ if (wsc_parse_m7(pdu, len, &m7, &encrypted) != 0) goto send_nack; @@ -1084,6 +1093,9 @@ static void eap_wsc_r_send_m6(struct eap_state *eap, size_t encrypted_len; bool r; + memset(m6es.authenticator, 0, sizeof(m6es.authenticator)); + memset(m6.authenticator, 0, sizeof(m6.authenticator)); + memcpy(m6es.r_snonce2, wsc->local_snonce2, sizeof(wsc->local_snonce2)); pdu = wsc_build_m6_encrypted_settings(&m6es, &pdu_len); explicit_bzero(m6es.r_snonce2, sizeof(wsc->local_snonce2)); @@ -1123,6 +1135,8 @@ static void eap_wsc_r_handle_m5(struct eap_state *eap, struct wsc_m5_encrypted_settings m5es; enum wsc_configuration_error error = WSC_CONFIGURATION_ERROR_NO_ERROR; + memset(m5es.authenticator, 0, sizeof(m5es.authenticator)); + /* Spec unclear what to do here, see comments in eap_wsc_send_nack */ if (wsc_parse_m5(pdu, len, &m5, &encrypted) != 0) goto send_nack; @@ -1188,6 +1202,9 @@ static void eap_wsc_r_send_m4(struct eap_state *eap, size_t len_half1; struct iovec iov[4]; + memset(m4es.authenticator, 0, sizeof(m4es.authenticator)); + memset(m4.authenticator, 0, sizeof(m4.authenticator)); + memcpy(m4es.r_snonce1, wsc->local_snonce1, sizeof(wsc->local_snonce1)); pdu = wsc_build_m4_encrypted_settings(&m4es, &pdu_len); explicit_bzero(m4es.r_snonce1, sizeof(wsc->local_snonce1)); diff --git a/src/handshake.h b/src/handshake.h @@ -140,7 +140,7 @@ struct handshake_state { bool authenticator_ocvc : 1; bool supplicant_ocvc : 1; bool ext_key_id_capable : 1; - bool force_default_owe_group : 1; + bool force_default_ecc_group : 1; uint8_t ssid[32]; size_t ssid_len; char *passphrase; diff --git a/src/iwd.h b/src/iwd.h @@ -42,3 +42,17 @@ const char *iwd_get_iface_blacklist(void); const char *iwd_get_phy_whitelist(void); const char *iwd_get_phy_blacklist(void); bool iwd_is_developer_mode(void); + +#define IWD_NOTICE_STATE "state" +#define IWD_NOTICE_CONNECT_INFO "connect-info" +#define IWD_NOTICE_ROAM_INFO "roam-info" +#define IWD_NOTICE_DISCONNECT_INFO "disconnect-info" +#define IWD_NOTICE_FT_ROAM_FAILED "ft-roam-failed" +#define IWD_NOTICE_CONNECT_FAILED "connect-failed" +#define IWD_NOTICE_AUTH_TIMEOUT "authentication-timeout" +#define IWD_NOTICE_ASSOC_TIMEOUT "association-timeout" +#define IWD_NOTICE_CONNECT_TIMEOUT "connect-timeout" +#define IWD_NOTICE_ROAM_SCAN "roam-scan" + +#define iwd_notice(event, ...) \ + l_notice("event: " event ", " __VA_ARGS__) diff --git a/src/iwd.network.rst b/src/iwd.network.rst @@ -174,6 +174,13 @@ The group ``[Settings]`` contains general settings. Properly configured Access Points will typically update this setting appropriately via Transition Disable indications. User customization of this value is thus typically not required. + * - UseDefaultEccGroup + - Values: true, false + + Forces the use of the default ECC group (19) for protocols using ECC + (WPA3 and OWE) if set true. If unset IWD will learn the capabilities of + the network based on its initial association and retain that setting for + the duration of its process lifetime. Network Authentication Settings ------------------------------- diff --git a/src/knownnetworks.c b/src/knownnetworks.c @@ -123,6 +123,17 @@ void __network_config_parse(const struct l_settings *settings, l_strfreev(modes); } + + if (l_settings_has_key(settings, NET_USE_DEFAULT_ECC_GROUP)) { + if (l_settings_get_bool(settings, + NET_USE_DEFAULT_ECC_GROUP, &b)) { + config->ecc_group = b ? KNOWN_NETWORK_ECC_GROUP_DEFAULT + : KNOWN_NETWORK_ECC_GROUP_MOST_SECURE; + } else + l_warn("[%s].%s is not a boolean value", + NET_USE_DEFAULT_ECC_GROUP); + } else + config->ecc_group = KNOWN_NETWORK_ECC_GROUP_AUTO; } void __network_info_init(struct network_info *info, diff --git a/src/knownnetworks.h b/src/knownnetworks.h @@ -27,6 +27,7 @@ #define NET_ADDRESS_OVERRIDE SETTINGS, "AddressOverride" #define NET_TRANSITION_DISABLE SETTINGS, "TransitionDisable" #define NET_TRANSITION_DISABLE_MODES SETTINGS, "DisabledTransitionModes" +#define NET_USE_DEFAULT_ECC_GROUP SETTINGS, "UseDefaultEccGroup" enum security; struct scan_freq_set; @@ -38,6 +39,12 @@ enum known_networks_event { KNOWN_NETWORKS_EVENT_UPDATED, }; +enum known_network_ecc_group { + KNOWN_NETWORK_ECC_GROUP_AUTO = 0, + KNOWN_NETWORK_ECC_GROUP_DEFAULT, + KNOWN_NETWORK_ECC_GROUP_MOST_SECURE, +}; + struct network_info_ops { struct l_settings *(*open)(struct network_info *info); int (*touch)(struct network_info *info); @@ -72,6 +79,7 @@ struct network_config { uint8_t sta_addr[6]; bool have_transition_disable : 1; uint8_t transition_disable; + enum known_network_ecc_group ecc_group; }; struct network_info { diff --git a/src/main.c b/src/main.c @@ -63,6 +63,7 @@ static const char *nointerfaces; static const char *phys; static const char *nophys; static const char *debugopt; +static const char *logger; static bool developeropt; static bool terminating; static bool nl80211_complete; @@ -166,6 +167,7 @@ static const struct option main_options[] = { { "nointerfaces", required_argument, NULL, 'I' }, { "phys", required_argument, NULL, 'p' }, { "nophys", required_argument, NULL, 'P' }, + { "logger", required_argument, NULL, 'l' }, { "debug", optional_argument, NULL, 'd' }, { "help", no_argument, NULL, 'h' }, { } @@ -478,7 +480,7 @@ int main(int argc, char *argv[]) for (;;) { int opt; - opt = getopt_long(argc, argv, "Ei:I:p:P:d::vh", + opt = getopt_long(argc, argv, "Ei:I:p:P:d::vhl:", main_options, NULL); if (opt < 0) break; @@ -507,6 +509,9 @@ int main(int argc, char *argv[]) else debugopt = "*"; break; + case 'l': + logger = optarg; + break; case 'v': printf("%s\n", VERSION); return EXIT_SUCCESS; @@ -523,7 +528,12 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - l_log_set_stderr(); + if (logger && !strcmp(logger, "syslog")) + l_log_set_syslog(); + else if (logger && !strcmp(logger, "journal")) + l_log_set_journal(); + else + l_log_set_stderr(); if (check_crypto() < 0) return EXIT_FAILURE; diff --git a/src/netconfig-commit.c b/src/netconfig-commit.c @@ -311,7 +311,7 @@ static void netconfig_domains_update(struct netconfig *netconfig) resolve_set_domains(netconfig->resolve, domains); l_strv_free(netconfig->domains); - netconfig->dns_list = l_steal_ptr(domains); + netconfig->domains = l_steal_ptr(domains); } static void netconfig_rtnl_commit(struct netconfig *netconfig, uint8_t family, diff --git a/src/netdev.c b/src/netdev.c @@ -1375,7 +1375,7 @@ static void netdev_deauthenticate_event(struct l_genl_msg *msg, MAC_STR(hdr->address_3), reason_code); netdev_connect_failed(netdev, NETDEV_RESULT_AUTHENTICATION_FAILED, - MMPDU_STATUS_CODE_UNSPECIFIED); + reason_code); } static void netdev_operstate_cb(int error, uint16_t type, @@ -2559,6 +2559,10 @@ static bool netdev_retry_owe(struct netdev *netdev) if (!owe_next_group(netdev->owe_sm)) return false; + if (netdev->event_filter) + netdev->event_filter(netdev, NETDEV_EVENT_ECC_GROUP_RETRY, + NULL, netdev->user_data); + connect_cmd = netdev_build_cmd_connect(netdev, netdev->handshake, NULL); netdev->connect_cmd_id = l_genl_family_send(nl80211, connect_cmd, @@ -2639,7 +2643,8 @@ static void netdev_connect_event(struct l_genl_msg *msg, struct netdev *netdev) } if (timeout) { - l_warn("connect event timed out, reason=%u", timeout_reason); + iwd_notice(IWD_NOTICE_CONNECT_TIMEOUT, "reason: %u", + timeout_reason); goto error; } @@ -2931,7 +2936,7 @@ static void netdev_authenticate_event(struct l_genl_msg *msg, while (l_genl_attr_next(&attr, &type, &len, &data)) { switch (type) { case NL80211_ATTR_TIMED_OUT: - l_warn("authentication event timed out"); + iwd_notice(IWD_NOTICE_AUTH_TIMEOUT); if (auth_proto_auth_timeout(netdev->ap)) return; @@ -2965,6 +2970,17 @@ static void netdev_authenticate_event(struct l_genl_msg *msg, ret = auth_proto_rx_authenticate(netdev->ap, frame, frame_len); + /* + * Allows station to persist settings so it does not retry + * the higher order ECC group again + */ + if (status_code == + MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP && + netdev->event_filter) + netdev->event_filter(netdev, + NETDEV_EVENT_ECC_GROUP_RETRY, + NULL, netdev->user_data); + /* We have sent another CMD_AUTHENTICATE / CMD_ASSOCIATE */ if (ret == 0 || ret == -EAGAIN) return; @@ -3032,7 +3048,7 @@ static void netdev_associate_event(struct l_genl_msg *msg, while (l_genl_attr_next(&attr, &type, &len, &data)) { switch (type) { case NL80211_ATTR_TIMED_OUT: - l_warn("association timed out"); + iwd_notice(IWD_NOTICE_ASSOC_TIMEOUT); if (auth_proto_assoc_timeout(netdev->ap)) return; @@ -3833,9 +3849,6 @@ static void netdev_connect_common(struct netdev *netdev, } } - if (bss->force_default_sae_group) - sae_sm_set_force_group_19(netdev->ap); - break; case IE_RSN_AKM_SUITE_OWE: netdev->owe_sm = owe_sm_new(hs); diff --git a/src/netdev.h b/src/netdev.h @@ -51,6 +51,7 @@ enum netdev_event { NETDEV_EVENT_RSSI_LEVEL_NOTIFY, NETDEV_EVENT_PACKET_LOSS_NOTIFY, NETDEV_EVENT_BEACON_LOSS_NOTIFY, + NETDEV_EVENT_ECC_GROUP_RETRY, }; enum netdev_watch_event { diff --git a/src/network.c b/src/network.c @@ -89,7 +89,7 @@ struct network { bool provisioning_hidden:1; uint8_t transition_disable; /* Temporary cache until info is set */ bool have_transition_disable:1; - bool force_default_owe_group:1; + bool force_default_ecc_group:1; int rank; /* Holds DBus Connect() message if it comes in before ANQP finishes */ struct l_dbus_message *connect_after_anqp; @@ -271,8 +271,12 @@ struct network *network_create(struct station *station, const char *ssid, network->security = security; network->info = known_networks_find(ssid, security); - if (network->info) + if (network->info) { network->info->seen_count++; + if (network->info->config.ecc_group == + KNOWN_NETWORK_ECC_GROUP_DEFAULT) + network->force_default_ecc_group = true; + } network->bss_list = l_queue_new(); network->blacklist = l_queue_new(); @@ -552,8 +556,8 @@ int network_handshake_setup(struct network *network, struct scan_bss *bss, handshake_state_set_protocol_version(hs, eapol_proto_version); } - if (hs->akm_suite == IE_RSN_AKM_SUITE_OWE) - hs->force_default_owe_group = network->force_default_owe_group; + hs->force_default_ecc_group = network->force_default_ecc_group || + bss->force_default_sae_group; /* * The randomization options in the provisioning file are dependent on @@ -820,14 +824,34 @@ void network_set_info(struct network *network, struct network_info *info) #endif } -void network_set_force_default_owe_group(struct network *network) +void network_set_force_default_ecc_group(struct network *network) { - network->force_default_owe_group = true; + /* No network info, likely a failed OWE connection */ + if (!network->info) { + network->force_default_ecc_group = true; + return; + } + + /* Profile explicitly wants to try the most secure group */ + if (network->info->config.ecc_group == + KNOWN_NETWORK_ECC_GROUP_MOST_SECURE) + return; + + l_debug("Forcing default group for %s", network->ssid); + + network->force_default_ecc_group = true; + network->info->config.ecc_group = KNOWN_NETWORK_ECC_GROUP_DEFAULT; } -bool network_get_force_default_owe_group(struct network *network) +bool network_get_force_default_ecc_group(struct network *network) { - return network->force_default_owe_group; + if (!network->info) + return network->force_default_ecc_group; + + if (network->info->config.ecc_group == KNOWN_NETWORK_ECC_GROUP_DEFAULT) + return true; + + return false; } int network_can_connect_bss(struct network *network, const struct scan_bss *bss) diff --git a/src/network.h b/src/network.h @@ -58,8 +58,8 @@ void network_sync_settings(struct network *network); const struct network_info *network_get_info(const struct network *network); 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); +void network_set_force_default_ecc_group(struct network *network); +bool network_get_force_default_ecc_group(struct network *network); bool network_update_known_frequencies(struct network *network); diff --git a/src/nl80211util.c b/src/nl80211util.c @@ -136,9 +136,7 @@ static bool extract_nested(const void *data, uint16_t len, void *o) const struct l_genl_attr *outer = data; struct l_genl_attr *nested = o; - l_genl_attr_recurse(outer, nested); - - return true; + return l_genl_attr_recurse(outer, nested); } static bool extract_u8(const void *data, uint16_t len, void *o) diff --git a/src/owe.c b/src/owe.c @@ -45,7 +45,7 @@ struct owe_sm { static bool owe_reset(struct owe_sm *owe) { - if (owe->hs->force_default_owe_group) { + if (owe->hs->force_default_ecc_group) { if (owe->retry != 0) { l_warn("Forced default OWE group but was rejected!"); return false; diff --git a/src/p2putil.c b/src/p2putil.c @@ -376,6 +376,9 @@ static bool extract_p2p_group_info(const uint8_t *attr, size_t len, desc = l_new(struct p2p_client_info_descriptor, 1); l_queue_push_tail(*out, desc); + if (desc_len < 24) + goto error; + memcpy(desc->device_addr, attr + 0, 6); memcpy(desc->interface_addr, attr + 6, 6); desc->device_caps = attr[12]; @@ -541,7 +544,8 @@ static void p2p_clear_advertised_service_descriptor(void *data) static bool extract_p2p_advertised_service_info(const uint8_t *attr, size_t len, void *data) { - struct l_queue **out = data; + struct l_queue **q = data; + struct l_queue *out = NULL; while (len) { struct p2p_advertised_service_descriptor *desc; @@ -557,11 +561,11 @@ static bool extract_p2p_advertised_service_info(const uint8_t *attr, size_t len, if (!l_utf8_validate((const char *) attr + 7, name_len, NULL)) goto error; - if (!*out) - *out = l_queue_new(); + if (!out) + out = l_queue_new(); desc = l_new(struct p2p_advertised_service_descriptor, 1); - l_queue_push_tail(*out, desc); + l_queue_push_tail(out, desc); desc->advertisement_id = l_get_le32(attr + 0); desc->wsc_config_methods = l_get_be16(attr + 4); @@ -572,10 +576,12 @@ static bool extract_p2p_advertised_service_info(const uint8_t *attr, size_t len, len -= 7 + name_len; } + *q = out; + return true; error: - l_queue_destroy(*out, p2p_clear_advertised_service_descriptor); + l_queue_destroy(out, p2p_clear_advertised_service_descriptor); return false; } @@ -773,7 +779,7 @@ done: /* Section 4.2.1 */ int p2p_parse_beacon(const uint8_t *pdu, size_t len, struct p2p_beacon *out) { - struct p2p_beacon d = {}; + struct p2p_beacon d = {0}; int r; r = p2p_parse_attrs(pdu, len, @@ -794,7 +800,7 @@ int p2p_parse_beacon(const uint8_t *pdu, size_t len, struct p2p_beacon *out) int p2p_parse_probe_req(const uint8_t *pdu, size_t len, struct p2p_probe_req *out) { - struct p2p_probe_req d = {}; + struct p2p_probe_req d = {0}; int r; r = p2p_parse_attrs(pdu, len, @@ -825,7 +831,7 @@ int p2p_parse_probe_req(const uint8_t *pdu, size_t len, int p2p_parse_probe_resp(const uint8_t *pdu, size_t len, struct p2p_probe_resp *out) { - struct p2p_probe_resp d = {}; + struct p2p_probe_resp d = {0}; int r; r = p2p_parse_attrs(pdu, len, @@ -850,7 +856,7 @@ int p2p_parse_probe_resp(const uint8_t *pdu, size_t len, int p2p_parse_association_req(const uint8_t *pdu, size_t len, struct p2p_association_req *out) { - struct p2p_association_req d = {}; + struct p2p_association_req d = {0}; int r; r = p2p_parse_attrs(pdu, len, @@ -873,7 +879,7 @@ int p2p_parse_association_req(const uint8_t *pdu, size_t len, int p2p_parse_association_resp(const uint8_t *pdu, size_t len, struct p2p_association_resp *out) { - struct p2p_association_resp d = {}; + struct p2p_association_resp d = {0}; int r; r = p2p_parse_attrs(pdu, len, @@ -936,7 +942,7 @@ int p2p_parse_disassociation(const uint8_t *pdu, size_t len, int p2p_parse_go_negotiation_req(const uint8_t *pdu, size_t len, struct p2p_go_negotiation_req *out) { - struct p2p_go_negotiation_req d = {}; + struct p2p_go_negotiation_req d = {0}; int r; struct p2p_go_intent_attr go_intent; uint8_t *wsc_data; @@ -998,7 +1004,7 @@ error: int p2p_parse_go_negotiation_resp(const uint8_t *pdu, size_t len, struct p2p_go_negotiation_resp *out) { - struct p2p_go_negotiation_resp d = {}; + struct p2p_go_negotiation_resp d = {0}; int r; struct p2p_go_intent_attr go_intent; uint8_t *wsc_data; @@ -1059,7 +1065,7 @@ error: int p2p_parse_go_negotiation_confirmation(const uint8_t *pdu, size_t len, struct p2p_go_negotiation_confirmation *out) { - struct p2p_go_negotiation_confirmation d = {}; + struct p2p_go_negotiation_confirmation d = {0}; int r; if (len < 1) @@ -1093,7 +1099,7 @@ error: int p2p_parse_invitation_req(const uint8_t *pdu, size_t len, struct p2p_invitation_req *out) { - struct p2p_invitation_req d = {}; + struct p2p_invitation_req d = {0}; int r; uint8_t *wsc_data; ssize_t wsc_len; @@ -1148,7 +1154,7 @@ error: int p2p_parse_invitation_resp(const uint8_t *pdu, size_t len, struct p2p_invitation_resp *out) { - struct p2p_invitation_resp d = {}; + struct p2p_invitation_resp d = {0}; int r; if (len < 1) @@ -1182,7 +1188,7 @@ error: int p2p_parse_device_disc_req(const uint8_t *pdu, size_t len, struct p2p_device_discoverability_req *out) { - struct p2p_device_discoverability_req d = {}; + struct p2p_device_discoverability_req d = {0}; int r; if (len < 1) @@ -1207,7 +1213,7 @@ int p2p_parse_device_disc_req(const uint8_t *pdu, size_t len, int p2p_parse_device_disc_resp(const uint8_t *pdu, size_t len, struct p2p_device_discoverability_resp *out) { - struct p2p_device_discoverability_resp d = {}; + struct p2p_device_discoverability_resp d = {0}; int r; if (len < 1) @@ -1231,7 +1237,7 @@ int p2p_parse_device_disc_resp(const uint8_t *pdu, size_t len, int p2p_parse_provision_disc_req(const uint8_t *pdu, size_t len, struct p2p_provision_discovery_req *out) { - struct p2p_provision_discovery_req d = {}; + struct p2p_provision_discovery_req d = {0}; int r; uint8_t *wsc_data; ssize_t wsc_len; @@ -1306,7 +1312,7 @@ error: int p2p_parse_provision_disc_resp(const uint8_t *pdu, size_t len, struct p2p_provision_discovery_resp *out) { - struct p2p_provision_discovery_resp d = {}; + struct p2p_provision_discovery_resp d = {0}; int r; uint8_t *wsc_data; ssize_t wsc_len; @@ -1386,7 +1392,7 @@ error: int p2p_parse_notice_of_absence(const uint8_t *pdu, size_t len, struct p2p_notice_of_absence *out) { - struct p2p_notice_of_absence d = {}; + struct p2p_notice_of_absence d = {0}; int r; if (len < 1) @@ -1408,7 +1414,7 @@ int p2p_parse_notice_of_absence(const uint8_t *pdu, size_t len, int p2p_parse_presence_req(const uint8_t *pdu, size_t len, struct p2p_presence_req *out) { - struct p2p_presence_req d = {}; + struct p2p_presence_req d = {0}; int r; if (len < 1) @@ -1434,7 +1440,7 @@ int p2p_parse_presence_req(const uint8_t *pdu, size_t len, int p2p_parse_presence_resp(const uint8_t *pdu, size_t len, struct p2p_presence_resp *out) { - struct p2p_presence_resp d = {}; + struct p2p_presence_resp d = {0}; int r; if (len < 1) diff --git a/src/sae.c b/src/sae.c @@ -1459,13 +1459,6 @@ bool sae_sm_is_h2e(struct auth_proto *ap) return sm->sae_type != CRYPTO_SAE_LOOPING; } -void sae_sm_set_force_group_19(struct auth_proto *ap) -{ - struct sae_sm *sm = l_container_of(ap, struct sae_sm, ap); - - sm->force_default_group = true; -} - static void sae_free(struct auth_proto *ap) { struct sae_sm *sm = l_container_of(ap, struct sae_sm, ap); @@ -1501,6 +1494,7 @@ struct auth_proto *sae_sm_new(struct handshake_state *hs, sm->user_data = user_data; sm->handshake = hs; sm->state = SAE_STATE_NOTHING; + sm->force_default_group = hs->force_default_ecc_group; sm->ap.start = sae_start; sm->ap.free = sae_free; diff --git a/src/sae.h b/src/sae.h @@ -30,8 +30,6 @@ typedef void (*sae_tx_associate_func_t)(void *user_data); bool sae_sm_is_h2e(struct auth_proto *ap); -void sae_sm_set_force_group_19(struct auth_proto *ap); - struct auth_proto *sae_sm_new(struct handshake_state *hs, sae_tx_authenticate_func_t tx_auth, sae_tx_associate_func_t tx_assoc, diff --git a/src/station.c b/src/station.c @@ -1565,9 +1565,9 @@ static void station_enter_state(struct station *station, bool disconnected; int ret; - l_debug("Old State: %s, new state: %s", - station_state_to_string(station->state), - station_state_to_string(state)); + iwd_notice(IWD_NOTICE_STATE, "old: %s, new: %s", + station_state_to_string(station->state), + station_state_to_string(state)); #ifdef HAVE_DBUS station_debug_event(station, station_state_to_string(state)); @@ -2366,12 +2366,16 @@ static bool station_ft_work_ready(struct wiphy_radio_work_item *item) roam_bss_rank_compare, NULL); station_debug_event(station, "ft-fallback-to-reassoc"); + iwd_notice(IWD_NOTICE_FT_ROAM_FAILED, "status: %d", + MMPDU_STATUS_CODE_INVALID_PMKID); station_transition_start(station); l_steal_ptr(rbss); break; case -ENOENT: station_debug_event(station, "ft-roam-failed"); + iwd_notice(IWD_NOTICE_FT_ROAM_FAILED, + "status: authentication timeout"); try_next: station_transition_start(station); break; @@ -2398,8 +2402,10 @@ disassociate: station_disassociated(station); break; default: - if (ret > 0) + if (ret > 0) { + iwd_notice(IWD_NOTICE_FT_ROAM_FAILED, "status: %d", ret); goto try_next; + } station_roam_failed(station); break; @@ -2471,8 +2477,10 @@ static bool station_try_next_transition(struct station *station, struct handshake_state *new_hs; struct ie_rsn_info cur_rsne, target_rsne; - l_debug("%u, target %s", netdev_get_ifindex(station->netdev), - util_address_to_string(bss->addr)); + iwd_notice(IWD_NOTICE_ROAM_INFO, "bss: "MAC", signal: %d, load: %d/255", + MAC_STR(bss->addr), + bss->signal_strength / 100, + bss->utilization); /* Reset AP roam flag, at this point the roaming behaves the same */ station->ap_directed_roaming = false; @@ -2539,6 +2547,8 @@ static void station_transition_start(struct station *station) while ((rbss = l_queue_peek_head(station->roam_bss_list))) { struct scan_bss *bss = network_bss_find_by_addr( station->connected_network, rbss->addr); + if (L_WARN_ON(!bss)) + continue; roaming = station_try_next_transition(station, bss, rbss->ft_failed); @@ -2575,6 +2585,7 @@ static void station_roam_scan_triggered(int err, void *user_data) } station_debug_event(station, "roam-scan-triggered"); + iwd_notice(IWD_NOTICE_ROAM_SCAN); /* * Do not update the Scanning property as we won't be updating the @@ -3157,7 +3168,7 @@ static bool station_retry_owe_default_group(struct station *station) return false; /* If we already forced group 19, allow the BSS to be blacklisted */ - if (network_get_force_default_owe_group(station->connected_network)) + if (network_get_force_default_ecc_group(station->connected_network)) return false; l_warn("Failed to connect to OWE BSS "MAC" possibly because the AP is " @@ -3165,7 +3176,7 @@ static bool station_retry_owe_default_group(struct station *station) "Retrying with group 19 as a workaround", MAC_STR(station->connected_bss->addr)); - network_set_force_default_owe_group(station->connected_network); + network_set_force_default_ecc_group(station->connected_network); return true; } @@ -3173,6 +3184,8 @@ static bool station_retry_owe_default_group(struct station *station) static bool station_retry_with_reason(struct station *station, uint16_t reason_code) { + iwd_notice(IWD_NOTICE_CONNECT_FAILED, "reason: %u", reason_code); + /* * We don't want to cause a retry and blacklist if the password was * incorrect. Otherwise we would just continue to fail. @@ -3223,6 +3236,8 @@ static bool station_retry_with_status(struct station *station, else blacklist_add_bss(station->connected_bss->addr); + iwd_notice(IWD_NOTICE_CONNECT_FAILED, "status: %u", status_code); + return station_try_next_bss(station); } @@ -3383,6 +3398,8 @@ static void station_disconnect_event(struct station *station, void *event_data) case STATION_STATE_FT_ROAMING: case STATION_STATE_FW_ROAMING: case STATION_STATE_NETCONFIG: + iwd_notice(IWD_NOTICE_DISCONNECT_INFO, "reason: %u", + l_get_u16(event_data)); station_disassociated(station); return; default: @@ -3455,6 +3472,18 @@ static void station_event_roaming(struct station *station) station_enter_state(station, STATION_STATE_FW_ROAMING); } +static void station_ecc_group_retry(struct station *station) +{ + struct network *network = station_get_connected_network(station); + + if (L_WARN_ON(!network)) + return; + + station_debug_event(station, "ecc-group-rejected"); + + network_set_force_default_ecc_group(network); +} + static void station_netdev_event(struct netdev *netdev, enum netdev_event event, void *event_data, void *user_data) { @@ -3496,6 +3525,9 @@ static void station_netdev_event(struct netdev *netdev, enum netdev_event event, case NETDEV_EVENT_BEACON_LOSS_NOTIFY: station_beacon_lost(station); break; + case NETDEV_EVENT_ECC_GROUP_RETRY: + station_ecc_group_retry(station); + break; } } @@ -3522,7 +3554,12 @@ int __station_connect_network(struct station *station, struct network *network, return r; } - l_debug("connecting to BSS "MAC, MAC_STR(bss->addr)); + iwd_notice(IWD_NOTICE_CONNECT_INFO, "ssid: %s, bss: "MAC", " + "signal: %d, load: %d/255", + network_get_ssid(network), + MAC_STR(bss->addr), + bss->signal_strength / 100, + bss->utilization); station->connected_bss = bss; station->connected_network = network; @@ -4736,12 +4773,16 @@ static void station_get_diagnostic_cb( struct l_dbus_message *reply; struct l_dbus_message_builder *builder; struct handshake_state *hs = netdev_get_handshake(station->netdev); + uint16_t channel_num; if (!info) { reply = dbus_error_aborted(station->get_station_pending); goto done; } + channel_num = band_freq_to_channel(station->connected_bss->frequency, + NULL); + reply = l_dbus_message_new_method_return(station->get_station_pending); builder = l_dbus_message_builder_new(reply); @@ -4752,6 +4793,10 @@ static void station_get_diagnostic_cb( util_address_to_string(info->addr)); dbus_append_dict_basic(builder, "Frequency", 'u', &station->connected_bss->frequency); + + if (channel_num != 0) + dbus_append_dict_basic(builder, "Channel", 'q', &channel_num); + dbus_append_dict_basic(builder, "Security", 's', diagnostic_akm_suite_to_security(hs->akm_suite, hs->wpa_ie)); diff --git a/src/wiphy.c b/src/wiphy.c @@ -1896,6 +1896,7 @@ static bool wiphy_get_driver_name(struct wiphy *wiphy) unsigned int j; const struct l_settings *config = iwd_get_config(); char **flag_list; + char *driver; driver_link = l_strdup_printf("/sys/class/ieee80211/%s/device/driver", wiphy->name); @@ -1907,7 +1908,9 @@ static bool wiphy_get_driver_name(struct wiphy *wiphy) } driver_path[len] = '\0'; - wiphy->driver_str = l_strdup(basename(driver_path)); + + driver = memrchr(driver_path, '/', len); + wiphy->driver_str = l_strdup(driver ? driver + 1 : driver_path); for (i = 0; i < L_ARRAY_SIZE(driver_infos); i++) if (!fnmatch(driver_infos[i].prefix, wiphy->driver_str, 0)) diff --git a/tools/run-tests b/tools/run-tests @@ -73,10 +73,10 @@ class Interface: Process(['ip', 'link', 'set', self.name, state], namespace=self.ns.name).wait() class Radio: - def __init__(self, name, default_ns): + def __init__(self, name, default_ns, used_by='iwd'): self.name = name # hostapd will reset this if this radio is used by it - self.use = 'iwd' + self.use = used_by self.interface = None self.ns = default_ns @@ -131,15 +131,18 @@ class VirtualRadio(Radio): self.hwsim = config.hwsim.Hwsim() + used_by = 'iwd' + if cfg: self.disable_iftype = cfg.get('iftype_disable', None) self.disable_cipher = cfg.get('cipher_disable', None) + used_by = cfg.get('reserve', 'iwd') self._radio = self.hwsim.radios.create(name, p2p_device=True, iftype_disable=self.disable_iftype, cipher_disable=self.disable_cipher) - super().__init__(self._radio.name, default_ns) + super().__init__(self._radio.name, default_ns, used_by) def __del__(self): super().__del__() diff --git a/tools/utils.py b/tools/utils.py @@ -6,6 +6,7 @@ import traceback import shutil import dbus +from datetime import datetime from gi.repository import GLib from weakref import WeakValueDictionary from re import fullmatch @@ -125,7 +126,11 @@ class Process(subprocess.Popen): @staticmethod def _write_io(instance, data, stdout=True): for f in instance.write_fds: - f.write(data) + for c in data: + f.write(c) + if c == '\n': + stamp = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S.%f") + f.write(stamp + ': ') # Write out a separator so multiple process calls per # test are easer to read. @@ -170,23 +175,27 @@ class Process(subprocess.Popen): def process_io(self, source, condition): if condition & GLib.IO_HUP: self.hup = True + self.wait() + bt = self.out.partition("++++++++ backtrace ++++++++") + if bt[1]: + raise Exception(f"Process {self.args[0]} crashed!\n{bt[1] + bt[2]}") data = source.read() if not data: - return True + return not self.hup try: data = data.decode('utf-8') except: - return True + return not self.hup # Save data away in case the caller needs it (e.g. list_sta) self.out += data self._write_io(self, data) - return True + return not self.hup def _append_outfile(self, file, append=True): gid = int(os.environ.get('SUDO_GID', os.getgid())) diff --git a/unit/test-dpp.c b/unit/test-dpp.c @@ -331,8 +331,10 @@ static void test_key_derivation(const void *data) if (vector->i_asn1) { HEX2BUF(vector->i_asn1, tmp, sizeof(tmp)); + l_free(asn1); asn1 = dpp_point_to_asn1(i_boot_public, &asn1_len); + l_free(from_asn1); from_asn1 = dpp_point_from_asn1(asn1, asn1_len); assert(l_ecc_points_are_equal(from_asn1, i_boot_public));