commit 3a35c5ebce416b145288d27820178af28b2ad9f4 parent 51f1c92d9019321862e8d15a80519029bb530dd8 Author: illiliti <illiliti@protonmail.com> Date: Fri, 17 Jun 2022 09:18:16 +0300 Merge tag '1.28' Release 1.28 Diffstat:
41 files changed, 448 insertions(+), 163 deletions(-)
diff --git a/AUTHORS b/AUTHORS @@ -36,3 +36,4 @@ Torsten Schmitz <noreply.torsten@gmail.com> Diederik de Haas <didi.debian@cknow.org> VladimĂr Dudr <vladimir@tango-dj.cz> Emmanuel VAUTRIN <Emmanuel.VAUTRIN@cpexterne.org> +Jesse Lentz <jesse@twosheds.org> diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,11 @@ +ver 1.28: + Fix issue with handling invalid EAPoL frames. + Fix issue with handling unexpectedly unencrypted EAP frames. + Fix issue with handling AlwaysRandomizeAddress/AddressOverride. + Fix issue with handling initial signal level notification. + Fix issue with handling sorting of scan requests. + Fix issue with handling frame type check in FT. + ver 1.27: Fix issue with hidden networks on connection error. Fix issue with directed roams if already trying to roam. diff --git a/Makefile.am b/Makefile.am @@ -86,6 +86,7 @@ ell_sources = ell/private.h \ ell/netlink-private.h \ ell/netlink.c \ ell/genl.c \ + ell/rtnl-private.h \ ell/rtnl.c \ ell/dbus-private.h \ ell/dbus.c \ diff --git a/autotests/misc/secrets/eap-user.text b/autotests/misc/secrets/eap-user.text @@ -20,3 +20,8 @@ "ttls-mschapv2-phase2@example.com" TTLS-MSCHAPV2 "Password" [2] "ttls-pap-phase2@example.com" TTLS-PAP "Password" [2] "112345678@phonesim.org" SIM [2] + +# TODO: Hostapd is broken with phase1 lookups for reauthentication. +# Allowing a wildcard phase1 for PEAP/TTLS is a stop gap until +# hostapd is actually fixed. +* PEAP,TTLS diff --git a/autotests/testAddressRandomization/connection_test.py b/autotests/testAddressRandomization/connection_test.py @@ -46,7 +46,7 @@ class Test(unittest.TestCase): perm_addr = device.address # 1. Test per-network deterministic MAC generation - os.system('cat pernetwork.psk > /tmp/iwd/ssidCCMP.psk') + IWD.copy_to_storage('pernetwork.psk', name='ssidCCMP.psk') new_addr = self.try_connection(wd) self.assertNotEqual(perm_addr, new_addr) # try again to ensure the generation was deterministic @@ -54,7 +54,7 @@ class Test(unittest.TestCase): self.assertEqual(new_addr, new_addr2) # 2. Test FullAddressRandomization - os.system('cat full_random.psk > /tmp/iwd/ssidCCMP.psk') + IWD.copy_to_storage('full_random.psk', name='ssidCCMP.psk') new_addr = self.try_connection(wd) self.assertNotEqual(perm_addr, new_addr) # try again to make sure the generation was random @@ -62,7 +62,7 @@ class Test(unittest.TestCase): self.assertNotEqual(new_addr, new_addr2) # 3. Test AddressOverride - os.system('cat override.psk > /tmp/iwd/ssidCCMP.psk') + IWD.copy_to_storage('override.psk', name='ssidCCMP.psk') new_addr = self.try_connection(wd) self.assertEqual(new_addr, 'e6:f6:38:a9:02:02') diff --git a/autotests/testDPP/connection_test.py b/autotests/testDPP/connection_test.py @@ -99,9 +99,9 @@ class Test(unittest.TestCase): self.wpas.wait_for_event('DPP-CONF-RECEIVED', timeout=30) def setUp(self): + self.wpas = Wpas('wpas.conf') self.wd = IWD(True) self.device = self.wd.list_devices(1)[0] - self.wpas = Wpas('wpas.conf') self.hapd = HostapdCLI('hostapd.conf') self.hapd.disable() self.hwsim = Hwsim() @@ -114,7 +114,6 @@ class Test(unittest.TestCase): self.rule0.drop = True def tearDown(self): - print("calling Disconnect()") self.device.disconnect() self.device.dpp_stop() self.wpas.dpp_configurator_remove() diff --git a/autotests/testEAP-PEAPv0-CryptoBinding/NoISK_test.py b/autotests/testEAP-PEAPv0-CryptoBinding/NoISK_test.py @@ -37,9 +37,6 @@ class Test(unittest.TestCase): hostapd.eapol_reauth(device.address) - hostapd.wait_for_event('CTRL-EVENT-EAP-STARTED') - hostapd.wait_for_event('CTRL-EVENT-EAP-SUCCESS') - condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) diff --git a/autotests/testEAP/connection_test.py b/autotests/testEAP/connection_test.py @@ -11,6 +11,8 @@ from iwd import PSKAgent from hlrauc import AuthCenter from ofono import Ofono from config import ctx +from hostapd import HostapdCLI + import testutil import traceback @@ -50,6 +52,8 @@ class Test(unittest.TestCase): testutil.test_iface_operstate() testutil.test_ifaces_connected() + self.hostapd.eapol_reauth(device.address) + if secrets: wd.unregister_psk_agent(psk_agent) @@ -251,6 +255,7 @@ class Test(unittest.TestCase): @classmethod def setUpClass(cls): cls.wd = IWD() + cls.hostapd = HostapdCLI() @classmethod def tearDownClass(cls): diff --git a/autotests/testEAPoL-spoofing/connection_test.py b/autotests/testEAPoL-spoofing/connection_test.py @@ -0,0 +1,77 @@ +#!/usr/bin/python3 + +import unittest +import sys + +sys.path.append('../util') +import iwd +from iwd import IWD +from iwd import PSKAgent +from iwd import NetworkType +from hwsim import Hwsim +from hostapd import HostapdCLI + +from time import sleep + +class Test(unittest.TestCase): + + def test_connection_success(self): + hwsim = Hwsim() + + hostapd = HostapdCLI(config='ssidCCMP.conf') + radio = hwsim.get_radio('rad0') + + wd = IWD() + + psk_agent = PSKAgent("secret123") + wd.register_psk_agent(psk_agent) + + devices = wd.list_devices(1) + device = devices[0] + + ordered_network = device.get_ordered_network('ssidCCMP') + + 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.connected' + wd.wait_for_object_condition(device, condition) + + # Ensure IWD is not scanning. This causes problems with mac80211_hwsim + # where CMD_FRAME will fail during a scan. This is due to the frame not + # having the same frequency as the radio (since hwsim is off-channel) + if device.scanning: + condition = 'not obj.scanning' + wd.wait_for_object_condition(device, condition) + + hwsim.spoof_eap_fail(radio, hostapd.frequency, device.address) + hwsim.spoof_invalid_ptk_1_of_4(radio, hostapd.frequency, device.address) + + with self.assertRaises(TimeoutError): + condition = 'obj.state == DeviceState.disconnected' + wd.wait_for_object_condition(device, condition, 4) + + condition = 'obj.state == DeviceState.connected' + wd.wait_for_object_condition(device, condition) + + device.disconnect() + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + wd.unregister_psk_agent(psk_agent) + + @classmethod + def setUpClass(cls): + pass + + @classmethod + def tearDownClass(cls): + IWD.clear_storage() + +if __name__ == '__main__': + unittest.main(exit=True) diff --git a/autotests/testEAPoL-spoofing/hw.conf b/autotests/testEAPoL-spoofing/hw.conf @@ -0,0 +1,6 @@ +[SETUP] +num_radios=2 +hwsim_medium=yes + +[HOSTAPD] +rad0=ssidCCMP.conf diff --git a/autotests/testEAPoL-spoofing/ssidCCMP.conf b/autotests/testEAPoL-spoofing/ssidCCMP.conf @@ -0,0 +1,12 @@ +hw_mode=g +channel=1 +ssid=ssidCCMP + +wpa=2 +wpa_pairwise=CCMP +wpa_passphrase=secret123 + +ieee80211w=2 +wpa_key_mgmt=WPA-PSK-SHA256 +beacon_int=10 +ocv=1 diff --git a/autotests/testNetconfig/main.conf b/autotests/testNetconfig/main.conf @@ -3,3 +3,4 @@ EnableNetworkConfiguration=true [Network] EnableIPv6=true +NameResolvingService=none diff --git a/autotests/testP2P/connection_test.py b/autotests/testP2P/connection_test.py @@ -29,8 +29,8 @@ class Test(unittest.TestCase): self.p2p_connect_test(preauthorize=True, go=True) def p2p_connect_test(self, preauthorize, go): - wd = IWD() wpas = self.wpas = Wpas(p2p=True) + wd = IWD() wpas_go_intent = 10 if not go else 1 # Not strictly necessary but prevents the station interface from queuing its scans diff --git a/autotests/testRSSIAgent/connection_test.py b/autotests/testRSSIAgent/connection_test.py @@ -56,7 +56,6 @@ class Test(unittest.TestCase): # at least) uses a moving-window average value over the last RSSI # measurements received from the driver and it changes gradually. # Normally 1 second is enough. - self.assertEqual(agent.calls, 0) for centre, level in rssi_pairs: rule.signal = centre agent.level = -1 diff --git a/autotests/testScan/remove_iface_test.py b/autotests/testScan/remove_iface_test.py @@ -18,7 +18,7 @@ class Test(unittest.TestCase): device.autoconnect = True device.scan(wait=False) - os.system('ifconfig %s down' % device.name) + os.system('ip link set dev %s down' % device.name) @classmethod def setUpClass(cls): diff --git a/autotests/util/ead.py b/autotests/util/ead.py @@ -3,9 +3,9 @@ from gi.repository import GLib import dbus import time -import collections import iwd +from collections.abc import Mapping from config import ctx EAD_SERVICE = 'net.connman.ead' @@ -38,7 +38,7 @@ class Adapter(iwd.IWDDBusAbstract): return self._properties['Authenticated'] -class AdapterList(collections.Mapping): +class AdapterList(Mapping): def __init__(self, ead): self._dict = {} diff --git a/autotests/util/hostapd.py b/autotests/util/hostapd.py @@ -163,8 +163,11 @@ class HostapdCLI(object): ctx.start_process(cmd).wait() def eapol_reauth(self, client_address): - cmd = 'IFNAME=' + self.ifname + ' EAPOL_REAUTH ' + client_address + self.events = [] + cmd = 'EAPOL_REAUTH ' + client_address self.ctrl_sock.sendall(cmd.encode('utf-8')) + self.wait_for_event('CTRL-EVENT-EAP-STARTED') + self.wait_for_event('CTRL-EVENT-EAP-SUCCESS') def reload(self): # Seemingly all three commands needed for the instance to notice diff --git a/autotests/util/hwsim.py b/autotests/util/hwsim.py @@ -1,11 +1,13 @@ #!/usr/bin/python3 import dbus import sys -import collections +from collections.abc import Mapping from weakref import WeakValueDictionary from abc import ABCMeta, abstractmethod from enum import Enum +from scapy.all import * +from scapy.contrib.wpa_eapol import WPA_key import iwd from config import ctx @@ -208,7 +210,7 @@ class Rule(HwsimDBusAbstract): prefix + '\tDelay:\t' + str(self.delay) + '\n' + \ prefix + '\tEnabled:\t' + str(self.enabled) + '\n' -class RuleSet(collections.Mapping): +class RuleSet(Mapping): def __init__(self, hwsim, objects): self._dict = {} self._rule_manager = hwsim.rule_manager @@ -273,7 +275,7 @@ class Radio(HwsimDBusAbstract): prefix + '\tName:\t\t' + self.name + '\n' + \ prefix + '\tAddresses:\t' + repr(self.destination) + '\n' -class RadioList(collections.Mapping): +class RadioList(Mapping): def __init__(self, hwsim, objects): self._dict = {} self._radio_manager = hwsim.radio_manager @@ -396,28 +398,59 @@ class Hwsim(iwd.AsyncOpAbstract): def object_manager(self): return self._object_manager_if - @staticmethod - def _convert_address(address): - first = int(address[0:2], base=16) - first |= 0x40 - first = format(first, 'x') + def spoof_disassociate(self, radio, freq, station): + ''' + Send a spoofed disassociate frame to a station + ''' + frame = Dot11()/Dot11Disas(reason=7) + frame[Dot11].addr1 = station + frame[Dot11].addr2 = radio.addresses[0] + frame[Dot11].addr3 = radio.addresses[0] - address = first + address[2:] + self.spoof_frame(radio, freq, station, raw(frame)) - return address + def spoof_deauthenticate(self, radio, freq, station): + ''' + Send a spoofed deauthenticate frame to a station + ''' + frame = Dot11()/Dot11Deauth(reason=6) + frame[Dot11].addr1 = station + frame[Dot11].addr2 = radio.addresses[0] + frame[Dot11].addr3 = radio.addresses[0] - def spoof_disassociate(self, radio, freq, station): + self.spoof_frame(radio, freq, station, raw(frame)) + + def spoof_eap_fail(self, radio, freq, station): ''' - Send a spoofed disassociate frame to a station + Send a spoofed EAP-Failure frame to a station ''' - dest = self._convert_address(radio.addresses[0].replace(':', '')) + frame = Dot11(type="Data", subtype=0) + frame[Dot11].addr1 = station + frame[Dot11].addr2 = radio.addresses[0] + frame[Dot11].addr3 = radio.addresses[0] + frame /= LLC()/SNAP()/EAPOL( version="802.1X-2001" ) + frame /= EAP( code="Failure" ) + + self.spoof_frame(radio, freq, station, raw(frame)) + + def spoof_invalid_ptk_1_of_4(self, radio, freq, station): + ''' + Send a spoofed PTK 1/4 frame to a station + ''' + frame = Dot11(type="Data", subtype=0) + frame[Dot11].addr1 = station + frame[Dot11].addr2 = radio.addresses[0] + frame[Dot11].addr3 = radio.addresses[0] + + # NOTE: Expected key_info is 0x008a, with the install flag + # this becomes 0x00ca. + eapol = WPA_key( descriptor_type = 2, + key_info = 0x00ca, # Includes an invalid install flag! + replay_counter = struct.pack(">Q", 100)) + frame /= LLC()/SNAP()/EAPOL(version="802.1X-2004", type="EAPOL-Key") + frame /= eapol - frame = 'a0 00 3a 01' - frame += station.replace(':', '') - frame += dest - frame += dest - frame += '30 01 07 00' - self.spoof_frame(radio, freq, station, frame) + self.spoof_frame(radio, freq, station, raw(frame)) def spoof_frame(self, radio, freq, station, frame): ''' @@ -442,7 +475,7 @@ class Hwsim(iwd.AsyncOpAbstract): HWSIM_INTERFACE_INTERFACE) iface.SendFrame(dbus.ByteArray.fromhex(station.replace(':', '')), - freq, -30, dbus.ByteArray.fromhex(frame)) + freq, -30, frame) def get_radio(self, name): for path in self.radios: diff --git a/autotests/util/iwd.py b/autotests/util/iwd.py @@ -8,10 +8,11 @@ import sys import os import threading import time -import collections +import collections.abc import datetime import weakref +from collections.abc import Mapping from abc import ABCMeta, abstractmethod from enum import Enum @@ -1018,7 +1019,7 @@ class P2PPeer(IWDDBusAbstract): self._iface.Disconnect() -class DeviceList(collections.Mapping): +class DeviceList(Mapping): def __init__(self, iwd): self._dict = {} self._p2p_dict = {} diff --git a/autotests/util/wpas.py b/autotests/util/wpas.py @@ -1,8 +1,10 @@ #!/usr/bin/python3 import os import socket +import shutil from gi.repository import GLib from config import ctx +from unittest import SkipTest import binascii @@ -11,7 +13,16 @@ from utils import Process ctrl_count = 0 class Wpas: + io_watch = None + sockets = {} + wpa_supplicant = None + cleanup_paths = [] + def _start_wpas(self, config_name=None, p2p=False): + if not shutil.which('wpa_supplicant'): + print('wpa_supplicant not found, skipping test') + raise SkipTest + main_interface = None for interface in ctx.wpas_interfaces: if config_name is None or interface.config == config_name: @@ -31,7 +42,6 @@ class Wpas: self.config_path = '/tmp/' + self.interface.config self.config = self._get_config() self.socket_path = self.config['ctrl_interface'] - self.io_watch = None cmd = ['wpa_supplicant', '-i', self.interface.name, '-c', self.config_path] if Process.is_verbose('wpa_supplicant-dbg'): @@ -40,7 +50,6 @@ class Wpas: self.wpa_supplicant = ctx.start_process(cmd) self.sockets = {} - self.cleanup_paths = [] self.io_watch = GLib.io_add_watch(self._get_socket(), GLib.IO_IN, self._handle_data_in) self.p2p_peers = {} diff --git a/configure.ac b/configure.ac @@ -1,5 +1,5 @@ -AC_PREREQ(2.60) -AC_INIT(iwd, 1.27) +AC_PREREQ([2.69]) +AC_INIT([iwd],[1.28]) AC_CONFIG_HEADERS(config.h) AC_CONFIG_AUX_DIR(build-aux) @@ -18,7 +18,7 @@ PKG_PROG_PKG_CONFIG COMPILER_FLAGS -AC_LANG_C +AC_LANG([C]) AC_PROG_CC AC_PROG_CC_PIE @@ -34,14 +34,14 @@ AC_SYS_LARGEFILE LT_PREREQ(2.2) LT_INIT([disable-static]) -AC_ARG_ENABLE(optimization, AC_HELP_STRING([--disable-optimization], +AC_ARG_ENABLE(optimization, AS_HELP_STRING([--disable-optimization], [disable code optimization through compiler]), [ if (test "${enableval}" = "no"); then CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -O0" fi ]) -AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], +AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug], [enable compiling with debugging information]), [ if (test "${enableval}" = "yes" && test "${ac_cv_prog_cc_g}" = "yes"); then @@ -49,7 +49,7 @@ AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], fi ]) -AC_ARG_ENABLE(pie, AC_HELP_STRING([--enable-pie], +AC_ARG_ENABLE(pie, AS_HELP_STRING([--enable-pie], [enable position independent executables flag]), [ if (test "${enableval}" = "yes" && test "${ac_cv_prog_cc_pie}" = "yes"); then @@ -62,7 +62,7 @@ save_LIBS=$LIBS AC_CHECK_LIB(asan, _init) LIBS=$save_LIBS -AC_ARG_ENABLE(asan, AC_HELP_STRING([--enable-asan], +AC_ARG_ENABLE(asan, AS_HELP_STRING([--enable-asan], [enable linking with address sanitizer]), [ if (test "${enableval}" = "yes" && test "${ac_cv_lib_asan__init}" = "yes" && @@ -76,7 +76,7 @@ save_LIBS=$LIBS AC_CHECK_LIB(lsan, _init) LIBS=$save_LIBS -AC_ARG_ENABLE(lsan, AC_HELP_STRING([--enable-lsan], +AC_ARG_ENABLE(lsan, AS_HELP_STRING([--enable-lsan], [enable linking with leak sanitizer]), [ if (test "${enableval}" = "yes" && test "${ac_cv_lib_lsan__init}" = "yes" && @@ -90,7 +90,7 @@ save_LIBS=$LIBS AC_CHECK_LIB(ubsan, _init) LIBS=$save_LIBS -AC_ARG_ENABLE(ubsan, AC_HELP_STRING([--enable-ubsan], +AC_ARG_ENABLE(ubsan, AS_HELP_STRING([--enable-ubsan], [enable linking with undefined behavior sanitizer]), [ if (test "${enableval}" = "yes" && test "${ac_cv_lib_ubsan__init}" = "yes" && @@ -144,17 +144,17 @@ if (test "${USE_MAINTAINER_MODE}" = yes); then ]) fi -AC_ARG_ENABLE([dbus], AC_HELP_STRING([--disable-dbus], +AC_ARG_ENABLE([dbus], AS_HELP_STRING([--disable-dbus], [don't provide dbus support]), [disable_dbus=${enableval}]) AM_CONDITIONAL(DBUS, test "${disable_dbus}" != "no") -AC_ARG_ENABLE([daemon], AC_HELP_STRING([--disable-daemon], +AC_ARG_ENABLE([daemon], AS_HELP_STRING([--disable-daemon], [don't install iwd system daemon]), [enable_daemon=${enableval}]) AM_CONDITIONAL(DAEMON, test "${enable_daemon}" != "no") -AC_ARG_ENABLE([client], AC_HELP_STRING([--disable-client], +AC_ARG_ENABLE([client], AS_HELP_STRING([--disable-client], [don't install iwctl client utility]), [enable_client=${enableval}]) if (test "${disable_dbus}" != "no" && test "${enable_client}" != "no"); then @@ -166,17 +166,17 @@ if (test "${disable_dbus}" != "no" && test "${enable_client}" != "no"); then fi AM_CONDITIONAL(CLIENT, test "${enable_client}" != "no" && test "${disable_dbus}" != "no") -AC_ARG_ENABLE([monitor], AC_HELP_STRING([--disable-monitor], +AC_ARG_ENABLE([monitor], AS_HELP_STRING([--disable-monitor], [don't install iwmon monitor utility]), [enable_monitor=${enableval}]) AM_CONDITIONAL(MONITOR, test "${enable_monitor}" != "no") -AC_ARG_ENABLE([dbus-policy], AC_HELP_STRING([--disable-dbus-policy], +AC_ARG_ENABLE([dbus-policy], AS_HELP_STRING([--disable-dbus-policy], [don't install D-Bus system policy files]), [enable_dbus_policy=${enableval}]) AM_CONDITIONAL(DBUS_POLICY, test "${enable_dbus_policy}" != "no" && test "${disable_dbus}" != "no") -AC_ARG_WITH([dbus-datadir], AC_HELP_STRING([--with-dbus-datadir=DIR], +AC_ARG_WITH([dbus-datadir], AS_HELP_STRING([--with-dbus-datadir=DIR], [path to D-Bus data directory]), [path_dbus_datadir=${withval}]) if (test "${disable_dbus}" != "no" && test "${enable_dbus_policy}" != "no" && test -z "${path_dbus_datadir}"); then @@ -192,12 +192,12 @@ if (test "${disable_dbus}" != "no" && test "${enable_dbus_policy}" != "no" && te fi AC_SUBST(DBUS_DATADIR, [${path_dbus_datadir}]) -AC_ARG_ENABLE([systemd-service], AC_HELP_STRING([--disable-systemd-service], +AC_ARG_ENABLE([systemd-service], AS_HELP_STRING([--disable-systemd-service], [don't install systemd service files]), [enable_systemd_service=${enableval}]) AM_CONDITIONAL(SYSTEMD_SERVICE, test "${enable_systemd_service}" != "no" && test "${disable_dbus}" != "no") -AC_ARG_ENABLE([manual-pages], AC_HELP_STRING([--disable-manual-pages], +AC_ARG_ENABLE([manual-pages], AS_HELP_STRING([--disable-manual-pages], [don't install manual pages]), [enable_manual_pages=${enableval}]) if (test "${enable_manual_pages}" != "no"); then @@ -206,7 +206,7 @@ fi AM_CONDITIONAL(MANUAL_PAGES, test "${enable_manual_pages}" != "no") AM_CONDITIONAL(RUN_RST2MAN, test "${enable_manual_pages}" != "no" && test "${RST2MAN}" != "no") -AC_ARG_WITH([dbus-busdir], AC_HELP_STRING([--with-dbus-busdir=DIR], +AC_ARG_WITH([dbus-busdir], AS_HELP_STRING([--with-dbus-busdir=DIR], [path to D-Bus bus services directory]), [path_dbus_busdir=${withval}]) if (test "${disable_dbus}" != "no" && test "${enable_dbus_policy}" != "no" && test -z "${path_dbus_busdir}"); then @@ -219,7 +219,7 @@ if (test "${disable_dbus}" != "no" && test "${enable_dbus_policy}" != "no" && te fi AC_SUBST(DBUS_BUSDIR, [${path_dbus_busdir}]) -AC_ARG_WITH([systemd-unitdir], AC_HELP_STRING([--with-systemd-unitdir=DIR], +AC_ARG_WITH([systemd-unitdir], AS_HELP_STRING([--with-systemd-unitdir=DIR], [path to systemd unit directory]), [path_systemd_unitdir=${withval}]) if (test "${disable_dbus}" != "no" && test "${enable_systemd_service}" != "no" && test -z "${path_systemd_unitdir}"); then @@ -232,7 +232,7 @@ if (test "${disable_dbus}" != "no" && test "${enable_systemd_service}" != "no" & fi AC_SUBST(SYSTEMD_UNITDIR, [${path_systemd_unitdir}]) -AC_ARG_WITH([systemd-networkdir], AC_HELP_STRING([--with-systemd-networkdir=DIR], +AC_ARG_WITH([systemd-networkdir], AS_HELP_STRING([--with-systemd-networkdir=DIR], [path to systemd network directory]), [path_systemd_networkdir=${withval}]) if (test "${disable_dbus}" != "no" && test "${enable_systemd_service}" != "no" && test -z "${path_systemd_networkdir}"); then @@ -246,7 +246,7 @@ if (test "${disable_dbus}" != "no" && test "${enable_systemd_service}" != "no" & fi AC_SUBST(SYSTEMD_NETWORKDIR, [${path_systemd_networkdir}]) -AC_ARG_WITH([systemd-modloaddir], AC_HELP_STRING([--with-systemd-modloaddir=DIR], +AC_ARG_WITH([systemd-modloaddir], AS_HELP_STRING([--with-systemd-modloaddir=DIR], [path to systemd modules load directory]), [path_systemd_modloaddir=${withval}]) if (test "${disable_dbus}" != "no" && test "${enable_systemd_service}" != "no" && test -z "${path_systemd_modloaddir}"); then @@ -259,7 +259,7 @@ if (test "${disable_dbus}" != "no" && test "${enable_systemd_service}" != "no" & fi AC_SUBST(SYSTEMD_MODLOADDIR, [${path_systemd_modloaddir}]) -AC_ARG_ENABLE([external_ell], AC_HELP_STRING([--enable-external-ell], +AC_ARG_ENABLE([external_ell], AS_HELP_STRING([--enable-external-ell], [enable external Embedded Linux library]), [enable_external_ell=${enableval}]) if (test "${enable_external_ell}" = "yes"); then @@ -268,7 +268,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.50" + ell_min_version="0.51" else ell_min_version="0.5" fi @@ -280,22 +280,22 @@ fi AM_CONDITIONAL(EXTERNAL_ELL, test "${enable_external_ell}" = "yes") -AC_ARG_ENABLE([wired], AC_HELP_STRING([--enable-wired], +AC_ARG_ENABLE([wired], AS_HELP_STRING([--enable-wired], [enable Ethernet authentication support]), [enable_wired=${enableval}]) AM_CONDITIONAL(WIRED, test "${enable_wired}" = "yes" && test "${disable_dbus}" != "no") -AC_ARG_ENABLE([hwsim], AC_HELP_STRING([--enable-hwsim], +AC_ARG_ENABLE([hwsim], AS_HELP_STRING([--enable-hwsim], [enable Wireless simulation utility]), [enable_hwsim=${enableval}]) AM_CONDITIONAL(HWSIM, test "${enable_hwsim}" = "yes" && test "${disable_dbus}" != "no") -AC_ARG_ENABLE([tools], AC_HELP_STRING([--enable-tools], +AC_ARG_ENABLE([tools], AS_HELP_STRING([--enable-tools], [enable internal testing utilities]), [enable_tools=${enableval}]) AM_CONDITIONAL(TOOLS, test "${enable_tools}" = "yes" && test "${disable_dbus}" != "no") -AC_ARG_ENABLE([ofono], AC_HELP_STRING([--enable-ofono], +AC_ARG_ENABLE([ofono], AS_HELP_STRING([--enable-ofono], [enable oFono SIM authentication support]), [enable_ofono=${enableval}]) AM_CONDITIONAL(OFONO, test "${enable_ofono}" = "yes" && test "${disable_dbus}" != "no") diff --git a/doc/station-api.txt b/doc/station-api.txt @@ -182,16 +182,17 @@ Methods void Release(object device) [noreply] void Changed(object device, uint8 level) [noreply] This method gets called when the signal strength - measurement for the device's connected network - changes enough to go from one level to another out - of the N ranges defined by the array of (N-1) - threshold values passed to RegisterSignalLevelAgent(). - The level parameter is in the range from 0 to N, - 0 being the strongest signal or above the first - threshold value in the array, and N being the - weakest and below the last threshold value. For - example if RegisterSignalLevelAgent was called with - the array [-40, -50, -60], the 'level' parameter of - 0 would mean signal is received at -40 or more dBm - and 3 would mean below -60 dBm and might correspond - to 1 out of 4 bars on a UI signal meter. + measurement for the device's connected network changes + enough to go from one level to another out of the N + ranges defined by the array of (N-1) threshold values + passed to RegisterSignalLevelAgent(). It also gets + called immediately after the signal level agent is + registered. The level parameter is in the range from 0 + to N, 0 being the strongest signal or above the first + threshold value in the array, and N being the weakest + and below the last threshold value. For example if + RegisterSignalLevelAgent was called with the array [-40, + -50, -60], the 'level' parameter of 0 would mean signal + is received at -40 or more dBm and 3 would mean below + -60 dBm and might correspond to 1 out of 4 bars on a UI + signal meter. diff --git a/doc/test-runner.txt b/doc/test-runner.txt @@ -50,6 +50,7 @@ In addition, the following Python packages are required: 3. python-pyroute2 0.5.14 4. python-gobject 3.38.0 5. python-dbus 1.2.16 + 6. scapy 2.4.5 Building Kernel =============== diff --git a/src/dpp-util.c b/src/dpp-util.c @@ -571,7 +571,8 @@ bool dpp_derive_r_auth(const void *i_nonce, const void *r_nonce, * R-auth = H(I-nonce | R-nonce | PI.x | PR.x | [ BI.x | ] BR.x | 0) */ return dpp_hash(type, r_auth, 6, i_nonce, nonce_len, r_nonce, nonce_len, - pix, keys_len, prx, keys_len, brx, keys_len, &zero, 1); + pix, keys_len, prx, keys_len, brx, keys_len, + &zero, (size_t) 1); } bool dpp_derive_i_auth(const void *r_nonce, const void *i_nonce, @@ -596,7 +597,8 @@ bool dpp_derive_i_auth(const void *r_nonce, const void *i_nonce, * I-auth = H(R-nonce | I-nonce | PR.x | PI.x | BR.x | [ BI.x | ] 1) */ return dpp_hash(type, i_auth, 6, r_nonce, nonce_len, i_nonce, nonce_len, - prx, keys_len, pix, keys_len, brx, keys_len, &one, 1); + prx, keys_len, pix, keys_len, brx, keys_len, + &one, (size_t) 1); } /* diff --git a/src/dpp.c b/src/dpp.c @@ -511,7 +511,7 @@ static void send_config_result(struct dpp_sm *dpp, const uint8_t *to) ptr += dpp_append_wrapped_data(hdr + 26, 6, attrs, 0, ptr, sizeof(attrs), dpp->ke, dpp->key_len, 2, - DPP_ATTR_STATUS, 1, &zero, + DPP_ATTR_STATUS, (size_t) 1, &zero, DPP_ATTR_ENROLLEE_NONCE, dpp->nonce_len, dpp->e_nonce); iov[1].iov_base = attrs; @@ -1146,7 +1146,7 @@ static void send_authenticate_response(struct dpp_sm *dpp) ptr, sizeof(attrs), dpp->k2, dpp->key_len, 4, DPP_ATTR_RESPONDER_NONCE, dpp->nonce_len, dpp->r_nonce, DPP_ATTR_INITIATOR_NONCE, dpp->nonce_len, dpp->i_nonce, - DPP_ATTR_RESPONDER_CAPABILITIES, 1, &dpp->role, + DPP_ATTR_RESPONDER_CAPABILITIES, (size_t) 1, &dpp->role, DPP_ATTR_WRAPPED_DATA, wrapped2_len, wrapped2); iov[1].iov_base = attrs; @@ -1313,7 +1313,8 @@ static void dpp_auth_request_failed(struct dpp_sm *dpp, ptr += dpp_append_wrapped_data(hdr + 26, 6, attrs, ptr - attrs, ptr, sizeof(attrs) - (ptr - attrs), k1, dpp->key_len, 2, DPP_ATTR_INITIATOR_NONCE, dpp->nonce_len, dpp->i_nonce, - DPP_ATTR_RESPONDER_CAPABILITIES, 1, &dpp->role); + DPP_ATTR_RESPONDER_CAPABILITIES, + (size_t) 1, &dpp->role); iov[1].iov_base = attrs; iov[1].iov_len = ptr - attrs; @@ -1404,7 +1405,8 @@ static bool dpp_send_authenticate_request(struct dpp_sm *dpp) ptr += dpp_append_wrapped_data(hdr + 26, 6, attrs, ptr - attrs, ptr, sizeof(attrs), dpp->k1, dpp->key_len, 2, DPP_ATTR_INITIATOR_NONCE, dpp->nonce_len, dpp->i_nonce, - DPP_ATTR_INITIATOR_CAPABILITIES, 1, &dpp->role); + DPP_ATTR_INITIATOR_CAPABILITIES, + (size_t) 1, &dpp->role); iov[1].iov_base = attrs; iov[1].iov_len = ptr - attrs; diff --git a/src/eap-tls-common.c b/src/eap-tls-common.c @@ -131,10 +131,13 @@ static void __eap_tls_common_state_reset(struct eap_tls_state *eap_tls) eap_tls->expecting_frag_ack = false; eap_tls->tunnel_ready = false; - if (eap_tls->tunnel) { - l_tls_free(eap_tls->tunnel); - eap_tls->tunnel = NULL; - } + /* + * Keep the tunnel instance to avoid losing the authentication + * settings that we may have loaded with l_tls_set_auth_data() + * since .reset_state is not supposed to clear settings. + */ + if (eap_tls->tunnel) + l_tls_reset(eap_tls->tunnel); eap_tls->tx_frag_offset = 0; eap_tls->tx_frag_last_len = 0; @@ -167,6 +170,10 @@ static void __eap_tls_common_state_free(struct eap_tls_state *eap_tls) l_key_free(eap_tls->client_key); l_strv_free(eap_tls->domain_mask); + + if (eap_tls->tunnel) + l_tls_free(eap_tls->tunnel); + l_free(eap_tls); } @@ -569,7 +576,7 @@ static bool eap_tls_tunnel_init(struct eap_state *eap) struct eap_tls_state *eap_tls = eap_get_data(eap); if (eap_tls->tunnel) - return false; + goto start; eap_tls->tunnel = l_tls_new(false, eap_tls_tunnel_data_received, eap_tls_tunnel_data_send, @@ -626,6 +633,7 @@ static bool eap_tls_tunnel_init(struct eap_state *eap) if (eap_tls->domain_mask) l_tls_set_domain_mask(eap_tls->tunnel, eap_tls->domain_mask); +start: if (!l_tls_start(eap_tls->tunnel)) { l_error("%s: Failed to start the TLS client", eap_get_method_name(eap)); diff --git a/src/eapol.c b/src/eapol.c @@ -1152,7 +1152,12 @@ static void eapol_handle_ptk_1_of_4(struct eapol_sm *sm, l_debug("ifindex=%u", sm->handshake->ifindex); if (!eapol_verify_ptk_1_of_4(ek, sm->mic_len)) - goto error_unspecified; + return; + + if (sm->handshake->ptk_complete && unencrypted) { + l_debug("Dropping unexpectedly unencrypted PTK 1/4 frame"); + return; + } pmkid = handshake_util_find_pmkid_kde(EAPOL_KEY_DATA(ek, sm->mic_len), EAPOL_KEY_DATA_LEN(ek, sm->mic_len)); @@ -1676,10 +1681,8 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm, l_debug("ifindex=%u", hs->ifindex); - if (!eapol_verify_ptk_3_of_4(ek, hs->wpa_ie, sm->mic_len)) { - handshake_failed(sm, MMPDU_REASON_CODE_UNSPECIFIED); + if (!eapol_verify_ptk_3_of_4(ek, hs->wpa_ie, sm->mic_len)) return; - } /* * 802.11-2016, Section 12.7.6.4: @@ -2086,10 +2089,8 @@ static void eapol_handle_gtk_1_of_2(struct eapol_sm *sm, l_debug("ifindex=%u", hs->ifindex); - if (!eapol_verify_gtk_1_of_2(ek, hs->wpa_ie, sm->mic_len)) { - handshake_failed(sm, MMPDU_REASON_CODE_UNSPECIFIED); + if (!eapol_verify_gtk_1_of_2(ek, hs->wpa_ie, sm->mic_len)) return; - } oci = handshake_util_find_kde(HANDSHAKE_KDE_OCI, decrypted_key_data, decrypted_key_data_size, &oci_len); @@ -2546,6 +2547,11 @@ static void eapol_rx_auth_packet(uint16_t proto, const uint8_t *from, if (proto != ETH_P_PAE || memcmp(from, sm->handshake->spa, 6)) return; + if (sm->handshake->ptk_complete && noencrypt) { + l_debug("Dropping unexpected unencrypted EAPoL frame"); + return; + } + switch (frame->header.packet_type) { case 0: /* EAPOL-EAP */ if (!sm->eap) { @@ -2619,6 +2625,11 @@ static void eapol_rx_packet(uint16_t proto, const uint8_t *from, switch (frame->header.packet_type) { case 0: /* EAPOL-EAP */ + if (sm->handshake->ptk_complete && unencrypted) { + l_debug("Dropping unexpected unencrypted EAP frame"); + return; + } + l_timeout_remove(sm->eapol_start_timeout); sm->eapol_start_timeout = 0; diff --git a/src/ft.c b/src/ft.c @@ -122,16 +122,11 @@ static bool ft_parse_authentication_resp_frame(const uint8_t *data, size_t len, uint16_t *out_status, const uint8_t **out_ies, size_t *out_ies_len) { - const uint16_t frame_type = 0x00b0; uint16_t status = 0; if (len < 30) return false; - /* Check FC == Management Frame -> Authentication */ - if (l_get_le16(data + 0) != frame_type) - return false; - if (memcmp(data + 4, addr1, 6)) return false; if (memcmp(data + 10, addr2, 6)) diff --git a/src/iwd-dbus.conf b/src/iwd-dbus.conf @@ -11,6 +11,7 @@ <allow own="net.connman.iwd"/> <allow send_destination="net.connman.iwd"/> <allow send_interface="net.connman.iwd.Agent"/> + <allow send_interface="net.connman.iwd.SignalLevelAgent"/> </policy> <policy group="wheel"> diff --git a/src/iwd.config.rst b/src/iwd.config.rst @@ -226,7 +226,7 @@ The group ``[Network]`` contains network configuration related settings. by default. This setting can also be overridden on a per-network basis. * - NameResolvingService - - Values: resolvconf, **systemd** + - Values: resolvconf, **systemd**, none Configures a DNS resolution method used by the system. @@ -236,6 +236,9 @@ The group ``[Network]`` contains network configuration related settings. If not specified, ``systemd`` is used as default. + If ``none`` is specified, then DNS and domain name information is + ignored. + * - RoutePriorityOffset - Values: uint32 value (default: **300**) diff --git a/src/iwd.debug.rst b/src/iwd.debug.rst @@ -40,6 +40,10 @@ ENVIRONMENT *$IWD_WSC_DEBUG_KEYS* set to ``1`` enables printing received WSC keys. +The granularity of the DHCP logging can also be tailored by setting +*$IWD_DHCP_DEBUG* to the maximum verbosity level, "debug", "info", "warn", or +"error". + SEE ALSO ======== diff --git a/src/netconfig.c b/src/netconfig.c @@ -1622,6 +1622,8 @@ struct netconfig *netconfig_new(uint32_t ifindex) struct netdev *netdev = netdev_find(ifindex); struct netconfig *netconfig; struct l_icmp6_client *icmp6; + const char *debug_level = NULL; + int dhcp_priority = L_LOG_INFO; if (!netconfig_list) return NULL; @@ -1641,9 +1643,22 @@ struct netconfig *netconfig_new(uint32_t ifindex) netconfig_ipv4_dhcp_event_handler, netconfig, NULL); - if (getenv("IWD_DHCP_DEBUG")) - l_dhcp_client_set_debug(netconfig->dhcp_client, do_debug, - "[DHCPv4] ", NULL); + debug_level = getenv("IWD_DHCP_DEBUG"); + if (debug_level != NULL) { + if (!strcmp("debug", debug_level)) + dhcp_priority = L_LOG_DEBUG; + else if (!strcmp("info", debug_level)) + dhcp_priority = L_LOG_INFO; + else if (!strcmp("warn", debug_level)) + dhcp_priority = L_LOG_WARNING; + else if (!strcmp("error", debug_level)) + dhcp_priority = L_LOG_ERR; + else /* Default for backwards compatibility */ + dhcp_priority = L_LOG_DEBUG; + } + + l_dhcp_client_set_debug(netconfig->dhcp_client, do_debug, + "[DHCPv4] ", NULL, dhcp_priority); netconfig->dhcp6_client = l_dhcp6_client_new(ifindex); l_dhcp6_client_set_event_handler(netconfig->dhcp6_client, diff --git a/src/netdev.c b/src/netdev.c @@ -450,6 +450,11 @@ const char *netdev_get_path(struct netdev *netdev) return path; } +uint8_t netdev_get_rssi_level_idx(struct netdev *netdev) +{ + return netdev->cur_rssi_level_idx; +} + static void netdev_set_powered_result(int error, uint16_t type, const void *data, uint32_t len, void *user_data) @@ -1020,12 +1025,6 @@ static void netdev_cqm_event_rssi_threshold(struct netdev *netdev, netdev->event_filter(netdev, event, NULL, netdev->user_data); } -static void netdev_rssi_level_init(struct netdev *netdev) -{ - if (netdev->connected && netdev->rssi_levels_num) - netdev_set_rssi_level_idx(netdev); -} - static void netdev_cqm_event_rssi_value(struct netdev *netdev, int rssi_val) { bool new_rssi_low; @@ -4038,7 +4037,10 @@ build_cmd_connect: netdev->handshake = hs; netdev->sm = sm; netdev->cur_rssi = bss->signal_strength / 100; - netdev_rssi_level_init(netdev); + + if (netdev->rssi_levels_num) + netdev_set_rssi_level_idx(netdev); + netdev_cqm_rssi_update(netdev); if (!wiphy_has_ext_feature(netdev->wiphy, @@ -5646,11 +5648,14 @@ int netdev_set_rssi_report_levels(struct netdev *netdev, const int8_t *levels, } done: - if (levels_num) + netdev->rssi_levels_num = levels_num; + + if (levels_num) { memcpy(netdev->rssi_levels, levels, levels_num); - netdev->rssi_levels_num = levels_num; - netdev_rssi_level_init(netdev); + if (netdev->connected) + netdev_set_rssi_level_idx(netdev); + } netdev_rssi_polling_update(netdev); diff --git a/src/netdev.h b/src/netdev.h @@ -145,6 +145,7 @@ bool netdev_get_4addr(struct netdev *netdev); const char *netdev_get_name(struct netdev *netdev); bool netdev_get_is_up(struct netdev *netdev); const char *netdev_get_path(struct netdev *netdev); +uint8_t netdev_get_rssi_level_idx(struct netdev *netdev); struct handshake_state *netdev_handshake_state_new(struct netdev *netdev); struct handshake_state *netdev_get_handshake(struct netdev *netdev); diff --git a/src/network.c b/src/network.c @@ -485,10 +485,12 @@ int network_handshake_setup(struct network *network, struct scan_bss *bss, struct station *station = network->station; struct wiphy *wiphy = station_get_wiphy(station); struct l_settings *settings = network->settings; + const struct l_settings *config = iwd_get_config(); struct network_info *info = network->info; uint32_t eapol_proto_version; uint8_t new_addr[ETH_ALEN]; int r; + const char *str; switch (network->security) { case SECURITY_PSK: @@ -524,6 +526,15 @@ int network_handshake_setup(struct network *network, struct scan_bss *bss, } /* + * The randomization options in the provisioning file are dependent on + * main.conf: [General].AddressRandomization=network. Any other value + * should disqualify the three network-specific settings below. + */ + str = l_settings_get_value(config, "General", "AddressRandomization"); + if (!(str && !strcmp(str, "network"))) + return 0; + + /* * We have three possible options here: * 1. per-network MAC generation (default, no option in network config) * 2. per-network full MAC randomization diff --git a/src/resolve.c b/src/resolve.c @@ -559,6 +559,38 @@ static const struct resolve_method_ops resolve_method_resolvconf_ops = { .alloc = resolve_resolvconf_alloc, }; +static void resolve_none_destroy(struct resolve *resolve) +{ + l_free(resolve); +} + +static struct resolve_ops none_ops = { + .destroy = resolve_none_destroy, +}; + +static int resolve_none_init(void) +{ + return 0; +} + +static void resolve_none_exit(void) +{ +} + +static struct resolve *resolve_none_alloc(uint32_t ifindex) +{ + struct resolve *r = l_new(struct resolve, 1); + + _resolve_init(r, ifindex, &none_ops); + return r; +} + +static const struct resolve_method_ops resolve_method_none_ops = { + .init = resolve_none_init, + .exit = resolve_none_exit, + .alloc = resolve_none_alloc, +}; + static const struct resolve_method_ops *configured_method; struct resolve *resolve_new(uint32_t ifindex) @@ -577,6 +609,7 @@ static const struct { { "systemd", &resolve_method_systemd_ops }, #endif { "resolvconf", &resolve_method_resolvconf_ops }, + { "none", &resolve_method_none_ops }, { } }; diff --git a/src/scan.c b/src/scan.c @@ -611,6 +611,17 @@ static struct scan_request *scan_request_new(struct scan_context *sc, return sr; } +static int insert_by_priority(const void *a, const void *b, void *user_data) +{ + const struct scan_request *cur = b; + int priority = L_PTR_TO_INT(user_data); + + if (cur->work.priority <= priority) + return 1; + + return -1; +} + static uint32_t scan_common(uint64_t wdev_id, bool passive, const struct scan_parameters *params, int priority, @@ -630,7 +641,12 @@ static uint32_t scan_common(uint64_t wdev_id, bool passive, scan_cmds_add(sr->cmds, sc, passive, params); - l_queue_push_tail(sc->requests, sr); + /* + * sr->work isn't initialized yet, it will be done by + * wiphy_radio_work_insert(). Pass the priority as user_data instead + */ + l_queue_insert(sc->requests, sr, insert_by_priority, + L_INT_TO_PTR(priority)); return wiphy_radio_work_insert(sc->wiphy, &sr->work, priority, &work_ops); @@ -801,7 +817,8 @@ uint32_t scan_owe_hidden(uint64_t wdev_id, struct l_queue *list, } done: - l_queue_push_tail(sc->requests, sr); + l_queue_insert(sc->requests, sr, insert_by_priority, + L_INT_TO_PTR(WIPHY_WORK_PRIORITY_SCAN)); return wiphy_radio_work_insert(sc->wiphy, &sr->work, WIPHY_WORK_PRIORITY_SCAN, &work_ops); diff --git a/src/station.c b/src/station.c @@ -1440,6 +1440,8 @@ static void station_set_drop_unicast_l2_multicast(struct station *station, "drop_unicast_in_l2_multicast", v); } +static void station_signal_agent_notify(struct station *station); + static void station_enter_state(struct station *station, enum station_state state) { @@ -1493,6 +1495,9 @@ static void station_enter_state(struct station *station, IWD_NETWORK_INTERFACE, "Connected"); #endif + if (station->signal_agent) + station_signal_agent_notify(station); + periodic_scan_stop(station); break; case STATION_STATE_CONNECTED: @@ -2768,9 +2773,6 @@ static void station_event_channel_switched(struct station *station, network_bss_update(network, station->connected_bss); } -static void station_rssi_level_changed(struct station *station, - uint8_t level_idx); - static bool station_try_next_bss(struct station *station) { struct scan_bss *next; @@ -3025,7 +3027,8 @@ static void station_netdev_event(struct netdev *netdev, enum netdev_event event, station_ok_rssi(station); break; case NETDEV_EVENT_RSSI_LEVEL_NOTIFY: - station_rssi_level_changed(station, l_get_u8(event_data)); + if (station->signal_agent) + station_signal_agent_notify(station); break; case NETDEV_EVENT_ROAMING: station_enter_state(station, STATION_STATE_ROAMING); @@ -3673,9 +3676,13 @@ struct signal_agent { unsigned int disconnect_watch; }; -static void station_signal_agent_notify(struct signal_agent *agent, - const char *device_path, uint8_t level) +static void station_signal_agent_notify(struct station *station) { + struct signal_agent *agent = station->signal_agent; + struct netdev *netdev = station->netdev; + const char *device_path = netdev_get_path(netdev); + uint8_t level = netdev_get_rssi_level_idx(netdev); + struct l_dbus_message *msg; msg = l_dbus_message_new_method_call(dbus_get_bus(), @@ -3688,18 +3695,6 @@ static void station_signal_agent_notify(struct signal_agent *agent, l_dbus_send(dbus_get_bus(), msg); } -static void station_rssi_level_changed(struct station *station, - uint8_t level_idx) -{ - struct netdev *netdev = station->netdev; - - if (!station->signal_agent) - return; - - station_signal_agent_notify(station->signal_agent, - netdev_get_path(netdev), level_idx); -} - static void station_signal_agent_release(struct signal_agent *agent, const char *device_path) { @@ -3744,6 +3739,7 @@ static struct l_dbus_message *station_dbus_signal_agent_register( { struct station *station = user_data; const char *path, *sender; + struct l_dbus_message *reply; struct l_dbus_message_iter level_iter; int8_t levels[16]; int err; @@ -3786,12 +3782,13 @@ static struct l_dbus_message *station_dbus_signal_agent_register( l_debug("agent %s path %s", sender, path); - /* - * TODO: send an initial notification in a oneshot idle callback, - * if state is connected. - */ + reply = l_dbus_message_new_method_return(message); + l_dbus_send(dbus, reply); - return l_dbus_message_new_method_return(message); + if (station->connected_network) + station_signal_agent_notify(station); + + return NULL; } static struct l_dbus_message *station_dbus_signal_agent_unregister( diff --git a/tools/run-tests b/tools/run-tests @@ -425,10 +425,13 @@ class TestContext(Namespace): return frequencies def start_wpas_interfaces(self): - if 'WPA_SUPPLICANT' not in self.hw_config: return + if not shutil.which('wpa_supplicant'): + print('wpa_supplicant not found, dependent tests will be skipped') + return + settings = self.hw_config['WPA_SUPPLICANT'] if self.args.hw: @@ -860,7 +863,7 @@ def post_test(ctx, to_copy): for f in to_copy: if os.path.isdir('/tmp/' + f): shutil.rmtree('/tmp/' + f) - else: + elif os.path.exists('/tmp/' + f): os.remove('/tmp/' + f) Process(['ip', 'link', 'set', 'lo', 'down']).wait() diff --git a/tools/runner.py b/tools/runner.py @@ -72,7 +72,10 @@ class RunnerNamespace(Namespace): if v in [None, False, [], '']: continue - ret += '%s=%s ' % (k, str(v)) + if type(v) is list: + ret += '%s=%s ' % (k, ','.join(v)) + else: + ret += '%s=%s ' % (k, str(v)) return ret.strip() @@ -89,7 +92,7 @@ class RunnerCoreArgParse(ArgumentParser): default=None, type=os.path.abspath) self.add_argument('--verbose', '-v', metavar='<list>', - type=str, + type=lambda x: x.split(','), help='Comma separated list of applications', dest='verbose', default=[]) @@ -289,7 +292,13 @@ class RunnerAbstract: # For QEMU/UML runners def _prepare_mounts(self, extra=[]): + mounted = [] + for entry in mounts_common + extra: + if entry.target in mounted: + print("%s already mounted, skipping" % entry.target) + continue + try: os.lstat(entry.target) except: @@ -298,6 +307,8 @@ class RunnerAbstract: mount(entry.source, entry.target, entry.fstype, entry.flags, entry.options) + mounted.append(entry.target) + for entry in dev_table: os.symlink(entry.target, entry.linkpath) @@ -305,17 +316,14 @@ class RunnerAbstract: # For QEMU/UML --log, --monitor, --result def _prepare_outfiles(self): - gid = None append_gid_uid = False - if os.environ.get('SUDO_GID', None): - uid = int(os.environ['SUDO_UID']) - gid = int(os.environ['SUDO_GID']) + uid = int(os.environ.get('SUDO_UID', os.getuid())) + gid = int(os.environ.get('SUDO_GID', os.getgid())) if self.args.log: - if os.getuid() != 0: - print("--log can only be used as root user") - quit() + if self.args.log == '/tmp': + raise Exception('Log directly cannot be /tmp') append_gid_uid = True @@ -326,24 +334,20 @@ class RunnerAbstract: os.chown(self.args.log, uid, gid) if self.args.monitor: - if os.getuid() != 0: - print("--monitor can only be used as root user") - quit() - append_gid_uid = True self.args.monitor_parent = os.path.abspath( os.path.join(self.args.monitor, os.pardir)) + if self.args.monitor_parent == '/tmp': + raise Exception('--monitor cannot be directly under /tmp') if self.args.result: - if os.getuid() != 0: - print("--result can only be used as root user") - quit() - append_gid_uid = True self.args.result_parent = os.path.abspath( os.path.join(self.args.result, os.pardir)) + if self.args.result_parent == '/tmp': + raise Exception('--result cannot be directly under /tmp') if append_gid_uid: self.args.SUDO_UID = uid @@ -433,6 +437,11 @@ class QemuRunner(RunnerAbstract): for addr in pci_adapters: qemu_cmdline.extend(['-device', 'vfio-pci,host=%s' % addr]) + qemu_cmdline.extend([ + '-virtfs', + 'local,path=%s,%s' % (args.testhome, mount_options('homedir')) + ]) + if args.log: # # Creates a virtfs device that can be mounted. This mount @@ -465,6 +474,9 @@ class QemuRunner(RunnerAbstract): def prepare_environment(self): mounts = [ MountInfo('debugfs', 'debugfs', '/sys/kernel/debug', '', 0) ] + mounts.append(MountInfo('9p', 'homedir', self.args.testhome, + 'trans=virtio,version=9p2000.L,msize=10240', 0)) + if self.args.log: mounts.append(MountInfo('9p', 'logdir', self.args.log, 'trans=virtio,version=9p2000.L,msize=10240', 0)) @@ -527,6 +539,9 @@ class UmlRunner(RunnerAbstract): mounts.append(MountInfo('hostfs', 'hostfs', self.args.result_parent, self.args.result_parent, 0)) + mounts.append(MountInfo('hostfs', 'hostfs', self.args.testhome, + self.args.testhome, 0)) + self._prepare_mounts(extra=mounts) super().prepare_environment() diff --git a/tools/utils.py b/tools/utils.py @@ -8,7 +8,7 @@ import dbus from gi.repository import GLib from weakref import WeakValueDictionary -from glob import glob +from re import match from runner import RunnerCoreArgParse @@ -95,10 +95,13 @@ class Process(subprocess.Popen): if process == 'valgrind' and 'iwd' in Process.testargs.verbose: return True - # Handle any glob matches + # Handle any regex matches for item in Process.testargs.verbose: - if process in glob(item): - return True + try: + if match(item, process): + return True + except Exception as e: + print("%s is not a valid regex" % item) return False