commit e8d7b3f1ce34de2ca411b2a8d9ae726ab92f3c98
parent ad2d135eeb2fa6a4ea605188d9eb30bb1e7c75bd
Author: illiliti <illiliti@protonmail.com>
Date: Wed, 9 Oct 2024 11:46:47 +0300
Merge tag '2.22'
Release 2.22
Diffstat:
99 files changed, 3593 insertions(+), 879 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -66,6 +66,7 @@ unit/test-p2p
unit/test-band
unit/test-dpp
unit/test-json
+unit/test-nl80211util
unit/cert-*.pem
unit/cert-*.csr
unit/cert-*.srl
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,35 @@
+ver 2.22:
+ Fix issue with handling the Affinities property.
+ Fix issue with handling ConnectedAccessPoint signal when roaming.
+
+ver 2.21:
+ Fix issue with pending scan requests after regdom update.
+ Fix issue with handling the rearming of the roaming timeout.
+ Fix issue with survey request and externally triggered scans.
+ Fix issue with RSSI fallback when setting CQM threshold fails.
+ Fix issue with FT-over-Air without offchannel support.
+ Add support for per station Affinities property.
+
+ver 2.20:
+ Fix issue with PKEX timeout and number of frequencies used.
+ Fix issue with handling logic for handshake failures.
+ Fix issue with handling ConnectedAccessPoint signal.
+
+ver 2.19:
+ Fix issue with handling flush flag for external scans.
+ Fix issue with handling SNR calculation in ranking.
+
+ver 2.18:
+ Fix issue with handling BSS with invalid HE capabilities.
+ Fix issue with neighbor reports with invalid country codes.
+ Fix issue with EAP-TTLS Start packets with L flag set.
+ Add support for enabling SAE for AP mode operation.
+
+ver 2.17:
+ Fix issue with handling deauthenticate on disconnect.
+ Fix issue with handling of rate estimation errors.
+ Fix issue with handling EAPOL frame listeners.
+
ver 2.16:
Fix issue with uninitialized variable and DPP encrypt.
Fix issue with Access Point mode and ATTR_MAC validation.
diff --git a/Makefile.am b/Makefile.am
@@ -64,7 +64,8 @@ ell_headers = ell/util.h \
ell/acd.h \
ell/cleanup.h \
ell/netconfig.h \
- ell/sysctl.h
+ ell/sysctl.h \
+ ell/notifylist.h
ell_sources = ell/private.h \
ell/missing.h \
@@ -145,7 +146,8 @@ ell_sources = ell/private.h \
ell/dhcp6-transport.c \
ell/acd.c \
ell/netconfig.c \
- ell/sysctl.c
+ ell/sysctl.c \
+ ell/notifylist.c
ell_shared = ell/useful.h ell/asn1-private.h
@@ -213,7 +215,8 @@ eap_sources = src/eap.c src/eap.h src/eap-private.h \
if DAEMON
libexec_PROGRAMS += src/iwd
-src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h src/missing.h \
+src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h \
+ src/missing.h src/defs.h \
src/netdev.h src/netdev.c \
src/wiphy.h src/wiphy.c \
src/device.c \
@@ -266,6 +269,7 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h src/missing.h \
src/dpp-util.h src/dpp-util.c \
src/json.h src/json.c \
src/dpp.c \
+ src/udev.c \
$(eap_sources) \
$(builtin_sources)
@@ -317,6 +321,7 @@ client_iwctl_SOURCES = client/main.c \
client/daemon.c client/daemon.h \
client/dpp.c client/dpp-pkex.c \
client/station-debug.c \
+ client/bss.c \
src/util.c src/util.h \
src/band.c src/band.h
@@ -433,7 +438,7 @@ unit_tests += unit/test-cmac-aes \
unit/test-ie unit/test-util unit/test-ssid-security \
unit/test-arc4 unit/test-wsc unit/test-eap-mschapv2 \
unit/test-eap-sim unit/test-sae unit/test-p2p unit/test-band \
- unit/test-dpp unit/test-json
+ unit/test-dpp unit/test-json unit/test-nl80211util
endif
if CLIENT
@@ -582,6 +587,13 @@ unit_test_dpp_LDADD = $(ell_ldadd)
unit_test_json_SOURCES = unit/test-json.c src/json.h src/json.c shared/jsmn.h
unit_test_json_LDADD = $(ell_ldadd)
+
+unit_test_nl80211util_SOURCES = unit/test-nl80211util.c \
+ src/nl80211util.h src/nl80211util.c \
+ src/band.h src/band.c \
+ src/ie.h src/ie.c \
+ src/util.h src/util.c
+unit_test_nl80211util_LDADD = $(ell_ldadd)
endif
if CLIENT
@@ -717,6 +729,7 @@ ell/internal: Makefile
done > $@
ell/ell.h: Makefile
+ $(AM_V_at)$(MKDIR_P) ell
$(AM_V_at)echo -n > $@
$(AM_V_GEN)for f in $(ell_headers) ; do \
echo "#include <$$f>" >> $@ ; \
diff --git a/autotests/testAffinity/TestFT.psk b/autotests/testAffinity/TestFT.psk
@@ -0,0 +1,2 @@
+[Security]
+Passphrase=EasilyGuessedPassword
diff --git a/autotests/testAffinity/ft-psk-ccmp-1.conf b/autotests/testAffinity/ft-psk-ccmp-1.conf
@@ -0,0 +1,41 @@
+hw_mode=g
+channel=1
+ssid=TestFT
+utf8_ssid=1
+ctrl_interface=/var/run/hostapd
+
+r1_key_holder=120000000001
+nas_identifier=dummy1
+
+wpa=2
+# Can support WPA-PSK and FT-PSK (space separated list) and/or EAP at the same
+# time but we want to force FT
+wpa_key_mgmt=FT-PSK
+wpa_pairwise=CCMP
+wpa_passphrase=EasilyGuessedPassword
+ieee80211w=0
+rsn_preauth=1
+rsn_preauth_interfaces=lo
+disable_pmksa_caching=0
+# Allow PMK cache to be shared opportunistically among configured interfaces
+# and BSSes (i.e., all configurations within a single hostapd process).
+okc=1
+mobility_domain=1234
+reassociation_deadline=60000
+r0kh=12:00:00:00:00:01 dummy1 000102030405060708090a0b0c0d0e0f
+r0kh=12:00:00:00:00:02 dummy2 000102030405060708090a0b0c0d0e0f
+r1kh=12:00:00:00:00:01 00:00:00:00:00:01 000102030405060708090a0b0c0d0e0f
+r1kh=12:00:00:00:00:02 00:00:00:00:00:02 000102030405060708090a0b0c0d0e0f
+# Push mode only needed for 8021x, not PSK mode since msk already known
+pmk_r1_push=0
+# Allow locally generated FT response so we don't have to configure push/pull
+# between BSSes running as separate hostapd processes as in the test-runner
+# case. Only works with FT-PSK, otherwise brctl needs to be installed and
+# CONFIG_BRIDGE enabled in the kernel.
+ft_psk_generate_local=1
+rkh_pull_timeout=50
+ft_over_ds=0
+ap_table_expiration_time=36000
+ap_table_max_size=10
+rrm_neighbor_report=1
+ocv=1
diff --git a/autotests/testAffinity/ft-psk-ccmp-2.conf b/autotests/testAffinity/ft-psk-ccmp-2.conf
@@ -0,0 +1,41 @@
+hw_mode=g
+channel=2
+ssid=TestFT
+utf8_ssid=1
+ctrl_interface=/var/run/hostapd
+
+r1_key_holder=120000000002
+nas_identifier=dummy2
+
+wpa=2
+# Can support WPA-PSK and FT-PSK (space separated list) and/or EAP at the same
+# time but we want to force FT
+wpa_key_mgmt=FT-PSK
+wpa_pairwise=CCMP
+wpa_passphrase=EasilyGuessedPassword
+ieee80211w=0
+rsn_preauth=1
+rsn_preauth_interfaces=lo
+disable_pmksa_caching=0
+# Allow PMK cache to be shared opportunistically among configured interfaces
+# and BSSes (i.e., all configurations within a single hostapd process).
+okc=1
+mobility_domain=1234
+reassociation_deadline=60000
+r0kh=12:00:00:00:00:01 dummy1 000102030405060708090a0b0c0d0e0f
+r0kh=12:00:00:00:00:02 dummy2 000102030405060708090a0b0c0d0e0f
+r1kh=12:00:00:00:00:01 00:00:00:00:00:01 000102030405060708090a0b0c0d0e0f
+r1kh=12:00:00:00:00:02 00:00:00:00:00:02 000102030405060708090a0b0c0d0e0f
+# Push mode only needed for 8021x, not PSK mode since msk already known
+pmk_r1_push=0
+# Allow locally generated FT response so we don't have to configure push/pull
+# between BSSes running as separate hostapd processes as in the test-runner
+# case. Only works with FT-PSK, otherwise brctl needs to be installed and
+# CONFIG_BRIDGE enabled in the kernel.
+ft_psk_generate_local=1
+rkh_pull_timeout=50
+ft_over_ds=0
+ap_table_expiration_time=36000
+ap_table_max_size=10
+rrm_neighbor_report=1
+ocv=1
diff --git a/autotests/testAffinity/hw.conf b/autotests/testAffinity/hw.conf
@@ -0,0 +1,8 @@
+[SETUP]
+num_radios=3
+start_iwd=0
+hwsim_medium=yes
+
+[HOSTAPD]
+rad0=ft-psk-ccmp-1.conf
+rad1=ft-psk-ccmp-2.conf
diff --git a/autotests/testPSK-roam/main.conf b/autotests/testAffinity/main.conf
diff --git a/autotests/testAffinity/test_set_affinity.py b/autotests/testAffinity/test_set_affinity.py
@@ -0,0 +1,216 @@
+#! /usr/bin/python3
+
+import unittest
+import sys, os
+import dbus
+
+sys.path.append('../util')
+from config import ctx
+import iwd
+from iwd import IWD, IWDDBusAbstract
+from iwd import NetworkType
+from hwsim import Hwsim
+from hostapd import HostapdCLI
+
+#
+# Separate client used to test DBus disconnects so we don't bring down the
+# entire IWD python library
+#
+class AffinityClient(IWDDBusAbstract):
+ def __init__(self, device_path):
+ self._bus = dbus.bus.BusConnection(address_or_type=ctx.dbus_address)
+ self._station_prop_if = dbus.Interface(
+ self._bus.get_object(iwd.IWD_SERVICE, device_path),
+ iwd.DBUS_PROPERTIES)
+
+ def set(self, values):
+ self._station_prop_if.Set(iwd.IWD_STATION_INTERFACE, 'Affinities', dbus.Array([dbus.ObjectPath(v) for v in values], signature="o"))
+
+ def close(self):
+ self._bus.close()
+
+class Test(unittest.TestCase):
+ def connect(self, device, hapd):
+ ordered_network = device.get_ordered_network('TestFT', full_scan=True)
+
+ self.assertEqual(ordered_network.type, NetworkType.psk)
+
+ condition = 'not obj.connected'
+ self.wd.wait_for_object_condition(ordered_network.network_object, condition)
+
+ device.connect_bssid(hapd.bssid)
+
+ condition = 'obj.state == DeviceState.connected'
+ self.wd.wait_for_object_condition(device, condition)
+
+ def test_set_affinity(self):
+ device = self.wd.list_devices(1)[0]
+
+ self.connect(device, self.bss_hostapd[0])
+
+ print(device.connected_bss)
+
+ device.affinities = [device.connected_bss]
+
+ # IWD should not attempt to roam
+ with self.assertRaises(TimeoutError):
+ device.wait_for_event("roam-scan-triggered")
+
+ device.affinities = []
+ device.wait_for_event("roam-scan-triggered")
+
+ def test_roam_below_critical(self):
+ device = self.wd.list_devices(1)[0]
+
+ self.connect(device, self.bss_hostapd[0])
+
+ device.affinities = [device.connected_bss]
+
+ # IWD should not attempt to roam
+ with self.assertRaises(TimeoutError):
+ device.wait_for_event("roam-scan-triggered")
+
+ # Lower signal past critical level
+ self.bss0_rule.signal = -9000
+
+ device.wait_for_event("roam-scan-triggered")
+
+ def test_error_conditions(self):
+ device = self.wd.list_devices(1)[0]
+
+ # Calling set while disconnected should fail
+ with self.assertRaises(iwd.NotConnectedEx):
+ device.affinities = ["/some/path"]
+
+ self.connect(device, self.bss_hostapd[0])
+
+ device.affinities = [device.connected_bss]
+
+ # An invalid path should fail
+ with self.assertRaises(iwd.InvalidArgumentsEx):
+ device.affinities = [device.connected_bss, "/an/invalid/path"]
+
+ def test_affinity_client_disconnect(self):
+ device = self.wd.list_devices(1)[0]
+
+ client = AffinityClient(device.device_path)
+
+ self.connect(device, self.bss_hostapd[0])
+
+ client.set([device.connected_bss])
+
+ with self.assertRaises(TimeoutError):
+ device.wait_for_event("roam-scan-triggered")
+
+ client._bus.close()
+
+ device.wait_for_event("roam-scan-triggered")
+
+ def test_affinity_client_reconnect_during_roam(self):
+ device = self.wd.list_devices(1)[0]
+
+ client = AffinityClient(device.device_path)
+
+ self.connect(device, self.bss_hostapd[0])
+
+ client.set([device.connected_bss])
+
+ # Lower signal past critical level
+ self.bss0_rule.signal = -9000
+
+ device.wait_for_event("roam-scan-triggered")
+
+ client.close()
+ del client
+ client = AffinityClient(device.device_path)
+ # setting here should get cleared after connecting
+ client.set([device.connected_bss])
+
+ device.wait_for_event("ft-authenticating")
+ device.wait_for_event("associating")
+ device.wait_for_event("connected")
+
+ # Affinity should be reset, and IWD should be trying to roam
+ device.wait_for_event("roam-scan-triggered")
+
+ def test_cleanup_with_connected_client(self):
+ device = self.wd.list_devices(1)[0]
+
+ client = AffinityClient(device.device_path)
+
+ self.connect(device, self.bss_hostapd[0])
+
+ client.set([device.connected_bss])
+ self.wd.stop()
+
+ def test_affinity_removed_after_roam(self):
+ device = self.wd.list_devices(1)[0]
+
+ self.connect(device, self.bss_hostapd[0])
+
+ device.affinities = [device.connected_bss]
+
+ # Lower signal past critical level
+ self.bss0_rule.signal = -9000
+
+ device.wait_for_event("roam-scan-triggered")
+
+ device.wait_for_event("ft-authenticating")
+ device.wait_for_event("associating")
+ device.wait_for_event("connected")
+
+ self.assertEqual(device.affinities, [])
+
+ def tearDown(self):
+ os.system('ip link set "' + self.bss_hostapd[0].ifname + '" down')
+ os.system('ip link set "' + self.bss_hostapd[1].ifname + '" down')
+ os.system('ip link set "' + self.bss_hostapd[0].ifname + '" up')
+ os.system('ip link set "' + self.bss_hostapd[1].ifname + '" up')
+
+ self.wd.stop()
+ self.wd = None
+
+ def setUp(self):
+ self.bss0_rule.signal = -8000
+ self.bss1_rule.signal = -8000
+
+ self.wd = IWD(True)
+
+ @classmethod
+ def setUpClass(cls):
+ hwsim = Hwsim()
+
+ IWD.copy_to_storage('TestFT.psk')
+
+ cls.bss_hostapd = [ HostapdCLI(config='ft-psk-ccmp-1.conf'),
+ HostapdCLI(config='ft-psk-ccmp-2.conf') ]
+
+ rad0 = hwsim.get_radio('rad0')
+ rad1 = hwsim.get_radio('rad1')
+
+ cls.bss0_rule = hwsim.rules.create()
+ cls.bss0_rule.source = rad0.addresses[0]
+ cls.bss0_rule.bidirectional = True
+ cls.bss0_rule.signal = -8000
+ cls.bss0_rule.enabled = True
+
+ cls.bss1_rule = hwsim.rules.create()
+ cls.bss1_rule.source = rad1.addresses[0]
+ cls.bss1_rule.bidirectional = True
+ cls.bss1_rule.signal = -8000
+ cls.bss1_rule.enabled = True
+
+ cls.bss_hostapd[0].set_address('12:00:00:00:00:01')
+ cls.bss_hostapd[1].set_address('12:00:00:00:00:02')
+
+ HostapdCLI.group_neighbors(*cls.bss_hostapd)
+
+ @classmethod
+ def tearDownClass(cls):
+ IWD.clear_storage()
+ cls.bss_hostapd = None
+ cls.bss0_rule.remove()
+ cls.bss1_rule.remove()
+
+if __name__ == '__main__':
+ unittest.main(exit=True)
diff --git a/autotests/testBasicServiceSet/basic_service_set_test.py b/autotests/testBasicServiceSet/basic_service_set_test.py
@@ -0,0 +1,98 @@
+#! /usr/bin/python3
+
+import unittest
+import sys, os
+
+sys.path.append('../util')
+import iwd
+from iwd import IWD
+from iwd import PSKAgent
+from iwd import NetworkType
+from hwsim import Hwsim
+from hostapd import HostapdCLI
+import testutil
+
+class Test(unittest.TestCase):
+ def test_bss_unregister(self):
+ device = self.wd.list_devices(1)[0]
+
+ ordered_network = device.get_ordered_network('ssidTKIP', full_scan=True)
+ network = ordered_network.network_object
+
+ self.assertEqual(len(network.extended_service_set), 2)
+
+ ends = [parts.split('/')[-1] for parts in network.extended_service_set]
+
+ self.assertIn(self.bss_hostapd[0].bssid.replace(':', ''), ends)
+ self.assertIn(self.bss_hostapd[1].bssid.replace(':', ''), ends)
+
+ self.rule_bss1.enabled = True
+
+ # Even with flushing, the kernel still seems to return the scan
+ # results
+ self.wd.wait(40)
+ ordered_network = device.get_ordered_network('ssidTKIP', full_scan=True)
+ network = ordered_network.network_object
+
+ ends = [parts.split('/')[-1] for parts in network.extended_service_set]
+
+ self.assertIn(self.bss_hostapd[0].bssid.replace(':', ''), ends)
+ self.assertNotIn(self.bss_hostapd[1].bssid.replace(':', ''), ends)
+
+ self.rule_bss0.enabled = True
+
+ self.wd.wait(40)
+ ordered_networks = device.get_ordered_networks('ssidTKIP', full_scan=True)
+ self.assertIsNone(ordered_networks)
+
+ self.rule_bss0.enabled = False
+
+ ordered_networks = device.get_ordered_networks('ssidTKIP', full_scan=True)
+ ends = [parts.split('/')[-1] for parts in network.extended_service_set]
+
+ self.assertIn(self.bss_hostapd[0].bssid.replace(':', ''), ends)
+ self.assertNotIn(self.bss_hostapd[1].bssid.replace(':', ''), ends)
+
+ def tearDown(self):
+ self.rule_bss0.enabled = False
+ self.rule_bss1.enabled = False
+
+ self.wd.stop()
+ self.wd.wait(10)
+ self.wd = None
+
+ def setUp(self):
+ self.wd = IWD(True)
+
+ @classmethod
+ def setUpClass(cls):
+ hwsim = Hwsim()
+
+ IWD.copy_to_storage('ssidTKIP.psk')
+
+ cls.bss_hostapd = [ HostapdCLI(config='ssidTKIP-1.conf'),
+ HostapdCLI(config='ssidTKIP-2.conf') ]
+
+
+ rad0 = hwsim.get_radio('rad0')
+ rad1 = hwsim.get_radio('rad1')
+
+ cls.rule_bss0 = hwsim.rules.create()
+ cls.rule_bss0.source = rad0.addresses[0]
+ cls.rule_bss0.bidirectional = True
+ cls.rule_bss0.drop = True
+
+ cls.rule_bss1 = hwsim.rules.create()
+ cls.rule_bss1.source = rad1.addresses[0]
+ cls.rule_bss1.bidirectional = True
+ cls.rule_bss1.drop = True
+
+ @classmethod
+ def tearDownClass(cls):
+ IWD.clear_storage()
+ cls.bss_hostapd = None
+ cls.rule_bss0.remove()
+ cls.rule_bss1.remove()
+
+if __name__ == '__main__':
+ unittest.main(exit=True)
diff --git a/autotests/testBasicServiceSet/hw.conf b/autotests/testBasicServiceSet/hw.conf
@@ -0,0 +1,8 @@
+[SETUP]
+num_radios=3
+hwsim_medium=yes
+start_iwd=no
+
+[HOSTAPD]
+rad0=ssidTKIP-1.conf
+rad1=ssidTKIP-2.conf
diff --git a/autotests/testBasicServiceSet/ssidTKIP-1.conf b/autotests/testBasicServiceSet/ssidTKIP-1.conf
@@ -0,0 +1,7 @@
+hw_mode=g
+channel=1
+ssid=ssidTKIP
+
+wpa=1
+wpa_pairwise=TKIP
+wpa_passphrase=secret123
diff --git a/autotests/testBasicServiceSet/ssidTKIP-2.conf b/autotests/testBasicServiceSet/ssidTKIP-2.conf
@@ -0,0 +1,7 @@
+hw_mode=g
+channel=2
+ssid=ssidTKIP
+
+wpa=1
+wpa_pairwise=TKIP
+wpa_passphrase=secret123
diff --git a/autotests/testBasicServiceSet/ssidTKIP.psk b/autotests/testBasicServiceSet/ssidTKIP.psk
@@ -0,0 +1,5 @@
+[Security]
+Passphrase=secret123
+
+[Settings]
+AutoConnect=False
diff --git a/autotests/testDPP/connection_test.py b/autotests/testDPP/connection_test.py
@@ -38,20 +38,18 @@ class Test(unittest.TestCase):
def test_iwd_as_enrollee_scan_after(self):
self.wpas.disconnect()
+ self.device.autoconnect = True
uri = self.device.dpp_start_enrollee()
self.wpas.dpp_configurator_create(uri)
self.wpas.dpp_configurator_start('ssidCCMP', 'secret123')
- self.hapd.reload()
-
with self.assertRaises(Exception):
self.device.get_ordered_network('ssidCCMP', scan_if_needed=False)
+ self.hapd.reload()
self.hapd.wait_for_event('AP-ENABLED')
- self.device.autoconnect = True
-
condition = 'obj.state == DeviceState.connected'
self.wd.wait_for_object_condition(self.device, condition)
diff --git a/autotests/testDPP/pkex_test.py b/autotests/testDPP/pkex_test.py
@@ -4,7 +4,7 @@ import unittest
import sys
sys.path.append('../util')
-from iwd import IWD, SharedCodeAgent
+from iwd import IWD, SharedCodeAgent, DeviceState
from iwd import DeviceProvisioning
from wpas import Wpas
from hostapd import HostapdCLI
@@ -160,10 +160,8 @@ class Test(unittest.TestCase):
def test_pkex_iwd_to_iwd(self):
self.start_iwd_pkex_configurator(self.device[0])
-
- self.device[1].dpp_pkex_enroll('secret123', identifier="test")
-
self.device[1].autoconnect = True
+ self.device[1].dpp_pkex_enroll('secret123', identifier="test")
condition = 'obj.state == DeviceState.connected'
self.wd.wait_for_object_condition(self.device[1], condition)
@@ -176,10 +174,8 @@ class Test(unittest.TestCase):
def test_pkex_configurator_with_agent(self):
self.start_iwd_pkex_configurator(self.device[0], agent=True)
-
- self.device[1].dpp_pkex_enroll('secret123', identifier="test")
-
self.device[1].autoconnect = True
+ self.device[1].dpp_pkex_enroll('secret123', identifier="test")
condition = 'obj.state == DeviceState.connected'
self.wd.wait_for_object_condition(self.device[1], condition)
@@ -198,8 +194,8 @@ class Test(unittest.TestCase):
self.start_iwd_pkex_configurator(self.device[0])
- self.device[1].dpp_pkex_enroll('secret123', identifier="test")
self.device[1].autoconnect = False
+ self.device[1].dpp_pkex_enroll('secret123', identifier="test")
condition = 'obj.state == DeviceState.connected'
self.wd.wait_for_object_condition(self.device[1], condition)
@@ -210,6 +206,24 @@ class Test(unittest.TestCase):
self.assertIn("SendHostname=true", settings)
+ def test_existing_incorrect_profile(self):
+ self.hapd.reload()
+ self.hapd.wait_for_event('AP-ENABLED')
+ IWD.copy_to_storage("existingProfile.psk", "/tmp/ns0/", "ssidCCMP.psk")
+
+ # Start connecting
+ self.device[1].autoconnect = True
+ self.wd.wait_for_object_condition(self.device[1], 'obj.state == DeviceState.connecting')
+
+ # We should be able to start DPP despite the connecting state
+ self.device[1].dpp_pkex_enroll('secret123', identifier="test")
+
+ self.start_iwd_pkex_configurator(self.device[0])
+ self.assertEqual(self.device[1].state, DeviceState.disconnected)
+
+ condition = 'obj.state == DeviceState.connected'
+ self.wd.wait_for_object_condition(self.device[1], condition)
+
def test_existing_hidden_network(self):
self.hapd_hidden.reload()
self.hapd_hidden.wait_for_event('AP-ENABLED')
@@ -222,8 +236,9 @@ class Test(unittest.TestCase):
self.start_iwd_pkex_configurator(self.device[0], profile='ssidHidden.psk')
- self.device[1].dpp_pkex_enroll('secret123', identifier="test")
self.device[1].autoconnect = False
+ self.device[1].dpp_pkex_enroll('secret123', identifier="test")
+
condition = 'obj.state == DeviceState.connected'
self.wd.wait_for_object_condition(self.device[1], condition)
@@ -239,8 +254,8 @@ class Test(unittest.TestCase):
self.hapd_hidden.wait_for_event('AP-ENABLED')
self.start_iwd_pkex_configurator(self.device[0], profile='ssidHidden.psk')
- self.device[1].dpp_pkex_enroll('secret123', identifier="test")
self.device[1].autoconnect = False
+ self.device[1].dpp_pkex_enroll('secret123', identifier="test")
condition = 'obj.state == DeviceState.connected'
self.wd.wait_for_object_condition(self.device[1], condition)
diff --git a/autotests/testDPP/state_change_test.py b/autotests/testDPP/state_change_test.py
@@ -0,0 +1,107 @@
+#!/usr/bin/python3
+
+import unittest
+import sys
+
+sys.path.append('../util')
+from iwd import IWD, SharedCodeAgent, DeviceState
+from iwd import DeviceProvisioning
+from wpas import Wpas
+from hostapd import HostapdCLI
+from hwsim import Hwsim
+from config import ctx
+from time import time
+import os
+
+class Test(unittest.TestCase):
+ def auto_connect(self):
+ IWD.copy_to_storage('ssidCCMP.psk')
+ self.device.autoconnect = True
+
+ condition = 'obj.state == DeviceState.connected'
+ self.wd.wait_for_object_condition(self.device, condition)
+
+ def test_configurator_stops_on_disconnect(self):
+ self.auto_connect()
+
+ self.device.dpp_start_configurator()
+
+ self.device.disconnect()
+
+ condition = 'obj.state == DeviceState.disconnected'
+ self.wd.wait_for_object_condition(self.device, condition)
+
+ self.assertEqual(self.device._device_provisioning.started, False)
+
+ def test_enrollee_stops_on_connect(self):
+ # Scan to get a list of networks
+ self.device.scan()
+ self.wd.wait_for_object_condition(self.device, 'obj.scanning == True')
+ self.wd.wait_for_object_condition(self.device, 'obj.scanning == False')
+
+ self.device.dpp_start_enrollee()
+
+ network = self.device.get_ordered_network("ssidCCMP")
+ network.network_object.connect()
+
+ condition = 'obj.state == DeviceState.connected'
+ self.wd.wait_for_object_condition(self.device, condition)
+
+ self.assertEqual(self.device._device_provisioning.started, False)
+
+ def test_enrollee_disconnects_automatically(self):
+ self.auto_connect()
+
+ self.device.dpp_start_enrollee()
+
+ condition = 'obj.state == DeviceState.disconnected'
+ self.wd.wait_for_object_condition(self.device, condition)
+
+ def test_enrollee_autoconnect_stays_on(self):
+ # Put in an autoconnecting state, no saved profile though
+ self.device.autoconnect = True
+
+ self.device.dpp_start_enrollee()
+
+ # DPP should set autoconnect false, but then re-enable after it stops
+ self.wd.wait_for_object_condition(self.device, "obj.autoconnect == False")
+ self.wd.wait_for_object_condition(self.device._device_provisioning, "obj.started == True")
+
+ # Stop DPP
+ self.device.dpp_stop()
+ self.wd.wait_for_object_condition(self.device, "obj.autoconnect == True")
+
+ def test_enrollee_autoconnect_stays_off(self):
+ # Autoconnect should be off by default
+
+ self.device.dpp_start_enrollee()
+
+ # DPP should set autoconnect false, but stay off after it stops
+ self.wd.wait_for_object_condition(self.device, "obj.autoconnect == False")
+ self.wd.wait_for_object_condition(self.device._device_provisioning, "obj.started == True")
+
+ # Stop DPP
+ self.device.dpp_stop()
+ self.wd.wait_for_object_condition(self.device, "obj.autoconnect == False")
+
+ def setUp(self):
+ self.wd = IWD(True)
+ self.device = self.wd.list_devices(1)[0]
+
+ def tearDown(self):
+ self.wd.stop()
+ self.wd = None
+
+ @classmethod
+ def setUpClass(cls):
+ hapd = HostapdCLI(config="hostapd.conf")
+ hapd.reload()
+
+ hapd.wait_for_event("AP-ENABLED")
+
+ @classmethod
+ def tearDownClass(cls):
+ pass
+
+if __name__ == '__main__':
+ unittest.main(exit=True)
+\ No newline at end of file
diff --git a/autotests/testEncryptedProfiles/ssidCCMP.psk b/autotests/testEncryptedProfiles/ssidCCMP.psk
@@ -1,2 +1,5 @@
[Security]
Passphrase=secret123
+
+[General]
+AutoConnect=false
diff --git a/autotests/testPSK-roam/disconnect_during_handshake_test.py b/autotests/testPSK-roam/disconnect_during_handshake_test.py
@@ -0,0 +1,112 @@
+#! /usr/bin/python3
+
+import unittest
+import sys, os
+
+sys.path.append('../util')
+import iwd
+from iwd import IWD
+from iwd import PSKAgent
+from iwd import NetworkType
+from hwsim import Hwsim
+from hostapd import HostapdCLI
+import testutil
+
+class Test(unittest.TestCase):
+ def validate_connection(self, wd):
+ device = wd.list_devices(1)[0]
+
+ ordered_network = device.get_ordered_network('TestFT', full_scan=True)
+
+ self.assertEqual(ordered_network.type, NetworkType.psk)
+
+ condition = 'not obj.connected'
+ wd.wait_for_object_condition(ordered_network.network_object, condition)
+
+ self.assertFalse(self.bss_hostapd[0].list_sta())
+ self.assertFalse(self.bss_hostapd[1].list_sta())
+
+ device.connect_bssid(self.bss_hostapd[0].bssid)
+
+ condition = 'obj.state == DeviceState.connected'
+ wd.wait_for_object_condition(device, condition)
+
+ self.bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % device.address)
+
+ testutil.test_iface_operstate(device.name)
+ testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name)
+ self.assertRaises(Exception, testutil.test_ifaces_connected,
+ (self.bss_hostapd[1].ifname, device.name, True, True))
+
+ self.rule0.enabled = True
+
+ device.roam(self.bss_hostapd[1].bssid)
+
+ device.clear_events()
+ device.wait_for_event("handshake-started")
+ self.bss_hostapd[1].deauthenticate(device.address, reason=15, test=1)
+
+ # Check that iwd is on BSS 1 once out of roaming state and doesn't
+ # go through 'disconnected', 'autoconnect', 'connecting' in between
+ from_condition = 'obj.state == DeviceState.roaming'
+ to_condition = 'obj.state == DeviceState.disconnected'
+ wd.wait_for_object_change(device, from_condition, to_condition)
+
+ def test_disconnect_during_handshake(self):
+ self.bss_hostapd[0].set_value('wpa_key_mgmt', 'WPA-PSK')
+ self.bss_hostapd[0].reload()
+ self.bss_hostapd[0].wait_for_event("AP-ENABLED")
+
+ self.bss_hostapd[1].set_value('wpa_key_mgmt', 'WPA-PSK')
+ self.bss_hostapd[1].reload()
+ self.bss_hostapd[1].wait_for_event("AP-ENABLED")
+
+ self.validate_connection(self.wd)
+
+ def tearDown(self):
+ os.system('ip link set "' + self.bss_hostapd[0].ifname + '" down')
+ os.system('ip link set "' + self.bss_hostapd[1].ifname + '" down')
+ os.system('ip link set "' + self.bss_hostapd[0].ifname + '" up')
+ os.system('ip link set "' + self.bss_hostapd[1].ifname + '" up')
+
+ for hapd in self.bss_hostapd:
+ hapd.default()
+
+ self.wd.stop()
+ self.wd = None
+
+ def setUp(self):
+ self.wd = IWD(True)
+
+ @classmethod
+ def setUpClass(cls):
+ hwsim = Hwsim()
+
+ IWD.copy_to_storage('TestFT.psk')
+
+ cls.bss_hostapd = [ HostapdCLI(config='ft-psk-ccmp-1.conf'),
+ HostapdCLI(config='ft-psk-ccmp-2.conf') ]
+
+ unused = HostapdCLI(config='ft-psk-ccmp-3.conf')
+ unused.disable()
+
+ cls.bss_hostapd[0].set_address('12:00:00:00:00:01')
+ cls.bss_hostapd[1].set_address('12:00:00:00:00:02')
+
+ rad1 = hwsim.get_radio('rad1')
+
+ cls.rule0 = hwsim.rules.create()
+ cls.rule0.destination = rad1.addresses[0]
+ cls.rule0.prefix = '08'
+ cls.rule0.drop = True
+
+ HostapdCLI.group_neighbors(*cls.bss_hostapd)
+
+ @classmethod
+ def tearDownClass(cls):
+ IWD.clear_storage()
+ cls.bss_hostapd = None
+ cls.rule0.remove()
+
+if __name__ == '__main__':
+ unittest.main(exit=True)
diff --git a/autotests/testPSK-roam/failed_roam_test.py b/autotests/testPSK-roam/failed_roam_test.py
@@ -149,6 +149,21 @@ class Test(unittest.TestCase):
condition = 'obj.state == DeviceState.disconnected'
self.wd.wait_for_object_condition(device, condition)
+ def test_ft_deauth_before_association(self):
+ self.rule2.enabled = True
+ self.rule3.enabled = True
+
+ device = self.wd.list_devices(1)[0]
+
+ self.connect(self.wd, device, self.bss_hostapd[0])
+
+ device.wait_for_event('ft-authenticating', timeout=60)
+
+ self.bss_hostapd[1].deauthenticate(device.address)
+
+ condition = 'obj.state == DeviceState.disconnected'
+ self.wd.wait_for_object_condition(device, condition)
+
def setUp(self):
self.wd = IWD(True)
@@ -232,6 +247,9 @@ class Test(unittest.TestCase):
cls.rule2.remove()
cls.rule3.remove()
cls.assoc_rule.remove()
+ cls.rule_bss0.remove()
+ cls.rule_bss1.remove()
+ cls.rule_bss2.remove()
if __name__ == '__main__':
unittest.main(exit=True)
diff --git a/autotests/testPSK-roam/ft-psk-ccmp-1.conf b/autotests/testPSK-roam/ft-psk-ccmp-1.conf
@@ -13,7 +13,7 @@ wpa=2
wpa_key_mgmt=FT-PSK
wpa_pairwise=CCMP
wpa_passphrase=EasilyGuessedPassword
-ieee80211w=1
+ieee80211w=0
rsn_preauth=1
rsn_preauth_interfaces=lo
disable_pmksa_caching=0
diff --git a/autotests/testPSK-roam/ft-psk-ccmp-2.conf b/autotests/testPSK-roam/ft-psk-ccmp-2.conf
@@ -13,7 +13,7 @@ wpa=2
wpa_key_mgmt=FT-PSK
wpa_pairwise=CCMP
wpa_passphrase=EasilyGuessedPassword
-ieee80211w=1
+ieee80211w=0
rsn_preauth=1
rsn_preauth_interfaces=lo
disable_pmksa_caching=0
diff --git a/autotests/testPSK-roam/ft-psk-ccmp-3.conf b/autotests/testPSK-roam/ft-psk-ccmp-3.conf
@@ -13,7 +13,7 @@ wpa=2
wpa_key_mgmt=FT-PSK
wpa_pairwise=CCMP
wpa_passphrase=EasilyGuessedPassword
-ieee80211w=1
+ieee80211w=0
rsn_preauth=1
rsn_preauth_interfaces=lo
disable_pmksa_caching=0
diff --git a/autotests/testPSK-roam/main.conf b/autotests/testPSK-roam/main.conf
@@ -3,3 +3,6 @@ DisableMacAddressRandomization=true
[General]
RoamRetryInterval=1
+
+# For disconnect_during_handshake_test
+ManagementFrameProtection=0
diff --git a/autotests/testPSK-roam/roam_ap_disconnect_test.py b/autotests/testPSK-roam/roam_ap_disconnect_test.py
@@ -81,12 +81,21 @@ class Test(unittest.TestCase):
cls.bss_hostapd[0].set_value('ocv', '0')
cls.bss_hostapd[0].set_value('ieee80211w', '0')
+ rad0 = hwsim.get_radio('rad0')
+ rad1 = hwsim.get_radio('rad1')
+
cls.rule0 = hwsim.rules.create()
- cls.rule0.source = 'any'
+ cls.rule0.source = rad0.addresses[0]
cls.rule0.bidirectional = True
cls.rule0.signal = -8000
cls.rule0.enabled = True
+ cls.rule1 = hwsim.rules.create()
+ cls.rule1.source = rad1.addresses[0]
+ cls.rule1.bidirectional = True
+ cls.rule1.signal = -8500
+ cls.rule1.enabled = True
+
cls.bss_hostapd[0].set_address('12:00:00:00:00:01')
cls.bss_hostapd[1].set_address('12:00:00:00:00:02')
@@ -95,6 +104,7 @@ class Test(unittest.TestCase):
IWD.clear_storage()
cls.bss_hostapd = None
cls.rule0.remove()
+ cls.rule1.remove()
if __name__ == '__main__':
unittest.main(exit=True)
diff --git a/autotests/testSAE/connection_test.py b/autotests/testSAE/connection_test.py
@@ -52,12 +52,6 @@ class Test(unittest.TestCase):
self.hostapd.wait_for_event("AP-ENABLED")
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
- self.hostapd.reload()
- self.hostapd.wait_for_event("AP-ENABLED")
- 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.reload()
@@ -88,7 +82,6 @@ class Test(unittest.TestCase):
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
@@ -13,7 +13,7 @@ import testutil
class Test(unittest.TestCase):
- def validate_connection(self, wd, rejected=False):
+ def validate_connection(self, wd, hostapd, rejected=False):
devices = wd.list_devices(1)
self.assertIsNotNone(devices)
device = devices[0]
@@ -29,14 +29,14 @@ 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)
if not rejected:
self.assertEqual(device.event_ocurred("ecc-group-rejected"), False)
- print(self.hostapd._get_status())
+ print(hostapd._get_status())
- sta_status = self.hostapd.sta_status(device.address)
+ sta_status = hostapd.sta_status(device.address)
print(sta_status)
@@ -51,22 +51,27 @@ class Test(unittest.TestCase):
# - 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, self.hostapd, rejected=True)
- self.validate_connection(self.wd, rejected=False)
+ self.validate_connection(self.wd, self.hostapd, 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)
+ self.validate_connection(self.wd, self.hostapd)
+
+ # Try group 19 first, with H2E
+ def test_default_group_enabled_h2e(self):
+ IWD.copy_to_storage("profiles/ssidSAE-H2E.psk.default_group", name="ssidSAE-H2E.psk")
+ self.validate_connection(self.wd, self.hostapd_h2e)
# 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)
+ self.validate_connection(self.wd, self.hostapd, rejected=True)
# IWD should then retry but use only group 19
- self.validate_connection(self.wd, rejected=True)
+ self.validate_connection(self.wd, self.hostapd, rejected=True)
def setUp(self):
self.hostapd.default()
@@ -88,6 +93,9 @@ class Test(unittest.TestCase):
cls.hostapd = HostapdCLI(config='ssidSAE.conf')
cls.hostapd.default()
+ cls.hostapd_h2e = HostapdCLI(config='ssidSAE-H2E.conf')
+ cls.hostapd_h2e.default()
+
@classmethod
def tearDownClass(cls):
pass
diff --git a/autotests/testSAE/hw.conf b/autotests/testSAE/hw.conf
@@ -1,9 +1,8 @@
[SETUP]
-num_radios=4
+num_radios=3
start_iwd=0
hwsim_medium=yes
[HOSTAPD]
rad0=ssidSAE.conf
rad1=ssidSAE-H2E.conf
-rad2=ssidSAE-default-group.conf
diff --git a/autotests/testSAE/profiles/ssidSAE-H2E.psk.default_group b/autotests/testSAE/profiles/ssidSAE-H2E.psk.default_group
@@ -0,0 +1,5 @@
+[Security]
+Passphrase=secret123
+
+[Settings]
+UseDefaultEccGroup=true
diff --git a/autotests/testSAE/ssidSAE-default-group.conf b/autotests/testSAE/ssidSAE-default-group.conf
@@ -1,12 +0,0 @@
-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/testWPA2/failure_test.py b/autotests/testWPA2/failure_test.py
@@ -8,11 +8,12 @@ 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 test_connection_success(self):
+ def test_incorrect_password(self):
wd = IWD(True)
psk_agent = PSKAgent("InvalidPassword")
@@ -34,6 +35,35 @@ class Test(unittest.TestCase):
wd.unregister_psk_agent(psk_agent)
+ def test_deauth_after_connection(self):
+ wd = IWD(True)
+ hostapd = HostapdCLI(config="ssidWPA2.conf")
+
+ psk_agent = PSKAgent("secret123")
+ wd.register_psk_agent(psk_agent)
+
+ devices = wd.list_devices(1)
+ self.assertIsNotNone(devices)
+ device = devices[0]
+
+ ordered_network = device.get_ordered_network('ssidWPA2')
+
+ 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(wait=False)
+
+ device.wait_for_event("authenticating")
+
+ # Trigger a deauth just after authenticating
+ hostapd.deauthenticate(device.address)
+
+ device.wait_for_event("disconnected")
+
+ wd.unregister_psk_agent(psk_agent)
+
@classmethod
def setUpClass(cls):
pass
diff --git a/autotests/util/hostapd.py b/autotests/util/hostapd.py
@@ -184,8 +184,12 @@ class HostapdCLI(object):
cmd = self.cmdline + ['wps_pin', 'any', pin]
ctx.start_process(cmd).wait()
- def deauthenticate(self, client_address):
+ def deauthenticate(self, client_address, reason=None, test=None):
cmd = self.cmdline + ['deauthenticate', client_address]
+
+ if reason:
+ cmd.append(f"reason={reason} test={test}")
+
ctx.start_process(cmd).wait()
def eapol_reauth(self, client_address):
diff --git a/autotests/util/iwd.py b/autotests/util/iwd.py
@@ -299,6 +299,9 @@ class StationDebug(IWDDBusAbstract):
return False
+ def clear_events(self):
+ self._events = []
+
def wait_for_event(self, event, timeout=10):
return ctx.non_block_wait(self._poll_event, timeout, event,
exception=TimeoutError("waiting for event"))
@@ -594,6 +597,11 @@ class Device(IWDDBusAbstract):
return props.get('ConnectedNetwork')
@property
+ def connected_bss(self):
+ props = self._station_properties()
+ return props.get('ConnectedAccessPoint')
+
+ @property
def powered(self):
'''
True if the interface is UP. If false, the device's radio is
@@ -627,6 +635,19 @@ class Device(IWDDBusAbstract):
self._station_debug._prop_proxy.Set(IWD_STATION_DEBUG_INTERFACE,
'AutoConnect', value)
+ @property
+ def affinities(self):
+ return self._station_properties()['Affinities']
+
+ @affinities.setter
+ def affinities(self, values):
+ self._station_properties()
+ self._station_prop_if.Set(
+ IWD_STATION_INTERFACE, 'Affinities',
+ dbus.Array([dbus.ObjectPath(v) for v in values], signature="o"),
+ reply_handler=self._success, error_handler=self._failure)
+ self._wait_for_async_op()
+
def scan(self, wait=True):
'''Schedule a network scan.
@@ -859,6 +880,9 @@ class Device(IWDDBusAbstract):
def wait_for_event(self, event, timeout=10):
self._station_debug.wait_for_event(event, timeout)
+ def clear_events(self):
+ self._station_debug.clear_events()
+
def event_ocurred(self, event):
return self._station_debug.event_ocurred(event)
@@ -969,6 +993,10 @@ class Network(IWDDBusAbstract):
'''
return bool(self._properties['Connected'])
+ @property
+ def extended_service_set(self):
+ return self._properties['ExtendedServiceSet']
+
def connect(self, wait=True):
'''
Connect to the network. Request the device implied by the object
diff --git a/client/bss.c b/client/bss.c
@@ -0,0 +1,109 @@
+/*
+ *
+ * Wireless daemon for Linux
+ *
+ * Copyright (C) 2024, Locus Robotics
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <ell/ell.h>
+#include "ell/useful.h"
+
+#include "client/dbus-proxy.h"
+#include "client/display.h"
+
+struct bss {
+ char *address;
+};
+
+static const char *get_address(const void *data)
+{
+ const struct bss *bss = data;
+
+ return bss->address;
+}
+
+static void update_address(void *data, struct l_dbus_message_iter *variant)
+{
+ struct bss *bss = data;
+ const char *value;
+
+ l_free(bss->address);
+
+ if (!l_dbus_message_iter_get_variant(variant, "s", &value)) {
+ bss->address = NULL;
+
+ return;
+ }
+
+ bss->address = l_strdup(value);
+}
+
+static const struct proxy_interface_property bss_properties[] = {
+ { "Address", "s", update_address, get_address },
+ { }
+};
+
+static void *bss_create(void)
+{
+ return l_new(struct bss, 1);
+}
+
+static void bss_destroy(void *data)
+{
+ struct bss *bss = data;
+
+ l_free(bss->address);
+ l_free(bss);
+}
+
+static void bss_display_inline(const char *margin, const void *data)
+{
+ const struct bss *bss = data;
+
+ display("%s%s\n", margin, bss->address);
+}
+
+static const struct proxy_interface_type_ops ops = {
+ .create = bss_create,
+ .destroy = bss_destroy,
+ .display = bss_display_inline,
+};
+
+static struct proxy_interface_type bss_interface_type = {
+ .interface = IWD_BSS_INTERFACE,
+ .properties = bss_properties,
+ .ops = &ops,
+};
+
+static int bss_interface_init(void)
+{
+ proxy_interface_type_register(&bss_interface_type);
+
+ return 0;
+}
+
+static void bss_interface_exit(void)
+{
+ proxy_interface_type_unregister(&bss_interface_type);
+}
+
+INTERFACE_TYPE(bss_interface_type, bss_interface_init, bss_interface_exit)
diff --git a/client/dbus-proxy.c b/client/dbus-proxy.c
@@ -47,10 +47,10 @@ static struct l_dbus *dbus;
static struct l_queue *proxy_interfaces;
static struct l_queue *proxy_interface_types;
-void proxy_properties_display(const struct proxy_interface *proxy,
- const char *caption, const char *margin,
- unsigned int name_column_width,
- unsigned int value_column_width)
+void proxy_properties_display_inline(const struct proxy_interface *proxy,
+ const char *margin,
+ unsigned int name_column_width,
+ unsigned int value_column_width)
{
const void *data;
const struct proxy_interface_property *properties;
@@ -59,11 +59,6 @@ void proxy_properties_display(const struct proxy_interface *proxy,
if (!proxy->type->properties)
return;
- display_table_header(caption, "%s%-*s %-*s %-*s", margin,
- 8, "Settable",
- name_column_width, "Property",
- value_column_width, "Value");
-
data = proxy_interface_get_data(proxy);
properties = proxy->type->properties;
@@ -82,6 +77,31 @@ void proxy_properties_display(const struct proxy_interface *proxy,
}
}
+void proxy_properties_display_header(const char *caption, const char *margin,
+ unsigned int name_column_width,
+ unsigned int value_column_width)
+{
+ display_table_header(caption, "%s%-*s %-*s %-*s", margin,
+ 8, "Settable",
+ name_column_width, "Property",
+ value_column_width, "Value");
+}
+
+void proxy_properties_display(const struct proxy_interface *proxy,
+ const char *caption, const char *margin,
+ unsigned int name_column_width,
+ unsigned int value_column_width)
+{
+ if (!proxy->type->properties)
+ return;
+
+ proxy_properties_display_header(caption, margin, name_column_width,
+ value_column_width);
+
+ proxy_properties_display_inline(proxy, margin, name_column_width,
+ value_column_width);
+}
+
static const void *proxy_interface_property_tostr(
const struct proxy_interface *proxy,
const char *name)
diff --git a/client/dbus-proxy.h b/client/dbus-proxy.h
@@ -41,6 +41,7 @@ struct proxy_interface;
#define IWD_DPP_INTERFACE "net.connman.iwd.DeviceProvisioning"
#define IWD_DPP_PKEX_INTERFACE \
"net.connman.iwd.SharedCodeDeviceProvisioning"
+#define IWD_BSS_INTERFACE "net.connman.iwd.BasicServiceSet"
typedef bool (*proxy_property_match_func_t) (const void *a, const void *b);
@@ -95,6 +96,13 @@ void proxy_properties_display(const struct proxy_interface *proxy,
const char *caption, const char *margin,
unsigned int name_column_width,
unsigned int value_column_width);
+void proxy_properties_display_inline(const struct proxy_interface *proxy,
+ const char *margin,
+ unsigned int name_column_width,
+ unsigned int value_column_width);
+void proxy_properties_display_header(const char *caption, const char *margin,
+ unsigned int name_column_width,
+ unsigned int value_column_width);
char *proxy_property_str_completion(const struct proxy_interface_type *type,
proxy_property_match_func_t function,
diff --git a/client/display.c b/client/display.c
@@ -194,7 +194,7 @@ void display_refresh_set_cmd(const char *family, const char *entity,
for (i = 0; i < argc; i++) {
bool needs_quotes = false;
- char *p = argv[i];
+ char *p;
for (p = argv[i]; *p != '\0'; p++) {
if (*p != ' ')
@@ -230,7 +230,8 @@ static void display_refresh_check_feasibility(void)
{
const struct winsize ws;
- ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
+ if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0)
+ return;
if (ws.ws_col < LINE_LEN - 1) {
if (display_refresh.enabled) {
@@ -564,8 +565,6 @@ void display_table_row(const char *margin, unsigned int ncolumns, ...)
str += entry_append(e, str);
}
- va_end(va);
-
display("%s\n", buf);
str = buf;
@@ -591,6 +590,8 @@ void display_table_row(const char *margin, unsigned int ncolumns, ...)
}
done:
+ va_end(va);
+
for (i = 0; i < ncolumns; i++) {
if (entries[i].color)
l_free(entries[i].color);
diff --git a/client/network.c b/client/network.c
@@ -35,6 +35,7 @@ struct network {
char *identity;
char *name;
char *type;
+ struct l_queue *bss_list;
const struct proxy_interface *device;
};
@@ -146,11 +147,58 @@ static void update_type(void *data, struct l_dbus_message_iter *variant)
network->type = l_strdup(value);
}
+static bool match_path(const void *a, const void *user_data)
+{
+ const char *path1 = a;
+ const char *path2 = user_data;
+
+ return !strcmp(path1, path2);
+}
+
+static void update_ess(void *data, struct l_dbus_message_iter *variant)
+{
+ struct network *network = data;
+ struct l_dbus_message_iter array;
+ const char *path;
+
+ if (!network->bss_list)
+ network->bss_list = l_queue_new();
+
+ if (!l_dbus_message_iter_get_variant(variant, "ao", &array))
+ return;
+
+ while (l_dbus_message_iter_next_entry(&array, &path)) {
+ l_free(l_queue_remove_if(network->bss_list, match_path, path));
+ l_queue_push_head(network->bss_list, l_strdup(path));
+ }
+}
+
+static const char *get_ess(const void *data)
+{
+ const struct network *network = data;
+ static char count[10];
+
+ snprintf(count, 10, "Count %u", l_queue_length(network->bss_list));
+
+ return count;
+}
+
+struct l_queue *network_get_bss_list(
+ const struct proxy_interface *network_proxy)
+{
+ const struct network *network = proxy_interface_get_data(network_proxy);
+ if (!network)
+ return NULL;
+
+ return network->bss_list;
+}
+
static const struct proxy_interface_property network_properties[] = {
{ "Name", "s", update_name, get_name },
{ "Connected", "b", update_connected},
{ "Device", "o", update_device},
{ "Type", "s", update_type},
+ { "ExtendedServiceSet", "ao", update_ess, get_ess },
{ }
};
@@ -186,6 +234,7 @@ static void network_destroy(void *data)
l_free(network->name);
l_free(network->type);
l_free(network->identity);
+ l_queue_destroy(network->bss_list, l_free);
network->device = NULL;
diff --git a/client/network.h b/client/network.h
@@ -37,3 +37,5 @@ char *network_name_completion(const struct proxy_interface *device,
struct l_queue *network_match_by_device_and_args(
const struct proxy_interface *device,
const struct network_args *args);
+struct l_queue *network_get_bss_list(
+ const struct proxy_interface *network_proxy);
diff --git a/client/station.c b/client/station.c
@@ -175,8 +175,8 @@ static void display_addresses(const char *device_name)
continue;
have_address = true;
- display("%s%*s %-*s%-*s\n", MARGIN, 8, "", 20,
- "IPv6 address", 47, addrstr);
+ display_table_row(MARGIN, 3, 8, "", 20,
+ "IPv6 address", 47, addrstr);
} else if (cur->ifa_addr->sa_family == AF_INET) {
struct sockaddr_in *si =
(struct sockaddr_in *) cur->ifa_addr;
@@ -283,28 +283,26 @@ static char *connect_cmd_arg_completion(const char *text, int state,
return network_name_completion(device, text, state);
}
-static enum cmd_status cmd_connect(const char *device_name,
- char **argv, int argc)
+static const struct proxy_interface *find_network(const char *device_name,
+ const char *name,
+ const char *type)
{
struct network_args network_args;
struct l_queue *match;
const struct proxy_interface *network_proxy;
const struct proxy_interface *device_proxy;
- if (argc < 1)
- return CMD_STATUS_INVALID_ARGS;
-
device_proxy = device_proxy_find_by_name(device_name);
if (!device_proxy)
- return CMD_STATUS_INVALID_VALUE;
+ return NULL;
- network_args.name = argv[0];
- network_args.type = argc >= 2 ? argv[1] : NULL;
+ network_args.name = name;
+ network_args.type = type;
match = network_match_by_device_and_args(device_proxy, &network_args);
if (!match) {
display("Invalid network name '%s'\n", network_args.name);
- return CMD_STATUS_INVALID_VALUE;
+ return NULL;
}
if (l_queue_length(match) > 1) {
@@ -315,11 +313,28 @@ static enum cmd_status cmd_connect(const char *device_name,
l_queue_destroy(match, NULL);
- return CMD_STATUS_INVALID_VALUE;
+ return NULL;
}
network_proxy = l_queue_pop_head(match);
l_queue_destroy(match, NULL);
+
+ return network_proxy;
+}
+
+static enum cmd_status cmd_connect(const char *device_name,
+ char **argv, int argc)
+{
+ const struct proxy_interface *network_proxy;
+
+ if (argc < 1)
+ return CMD_STATUS_INVALID_ARGS;
+
+ network_proxy = find_network(device_name, argv[0],
+ argc >= 2 ? argv[1] : NULL);
+ if (!network_proxy)
+ return CMD_STATUS_INVALID_VALUE;
+
network_connect(network_proxy);
return CMD_STATUS_TRIGGERED;
@@ -708,6 +723,55 @@ static enum cmd_status cmd_show(const char *device_name,
return CMD_STATUS_TRIGGERED;
}
+
+static enum cmd_status cmd_get_bsses(const char *device_name,
+ char **argv, int argc)
+{
+ const struct proxy_interface *station_i =
+ device_proxy_find(device_name, IWD_STATION_INTERFACE);
+ const struct station *station = proxy_interface_get_data(station_i);
+ struct l_queue *bss_list;
+ const struct l_queue_entry *e;
+ const struct proxy_interface *network_proxy;
+ char header[256];
+
+ if (argc > 0)
+ network_proxy = find_network(device_name, argv[0],
+ argc >= 2 ? argv[1] : NULL);
+ else
+ network_proxy = station->connected_network;
+
+ if (!network_proxy) {
+ display_error("Can't find network");
+ return CMD_STATUS_INVALID_ARGS;
+ }
+
+ bss_list = network_get_bss_list(network_proxy);
+ if (!bss_list) {
+ display_error("No BSS list for network");
+ return CMD_STATUS_FAILED;
+ }
+
+ sprintf(header, "%s BasicServiceSets", network_get_name(network_proxy));
+
+ proxy_properties_display_header(header, MARGIN, 10, 18);
+
+ for (e = l_queue_get_entries(bss_list); e; e = e->next) {
+ const char *path = e->data;
+ const struct proxy_interface *bss_i = proxy_interface_find(
+ IWD_BSS_INTERFACE, path);
+
+ if (!bss_i)
+ continue;
+
+ display_table_row(MARGIN, 1, strlen(path), path);
+ proxy_properties_display_inline(bss_i, MARGIN, 10, 18);
+ display_table_row(MARGIN, 1, 1, "");
+ }
+
+ return CMD_STATUS_DONE;
+}
+
static const struct command station_commands[] = {
{ NULL, "list", NULL, cmd_list, "List devices in Station mode", true },
{ "<wlan>", "connect",
@@ -732,6 +796,8 @@ static const struct command station_commands[] = {
"Get hidden APs", true },
{ "<wlan>", "scan", NULL, cmd_scan, "Scan for networks" },
{ "<wlan>", "show", NULL, cmd_show, "Show station info", true },
+ { "<wlan>", "get-bsses", "[network] [security]", cmd_get_bsses,
+ "Get BSS's for a network", true },
{ }
};
diff --git a/configure.ac b/configure.ac
@@ -1,5 +1,5 @@
AC_PREREQ([2.69])
-AC_INIT([iwd],[2.16])
+AC_INIT([iwd],[2.22])
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.63"
+ ell_min_version="0.69"
else
ell_min_version="0.5"
fi
diff --git a/doc/basic-service-set.txt b/doc/basic-service-set.txt
@@ -0,0 +1,10 @@
+Basic service set hierarchy
+=================
+
+Service net.connman.iwd
+Interface net.connman.iwd.BasicServiceSet
+Object path /net/connman/iwd/{phy0,phy1,...}/{1,2,...}/Xxx
+
+Properties string Address [readonly]
+
+ MAC address of BSS
diff --git a/doc/network-api.txt b/doc/network-api.txt
@@ -50,3 +50,8 @@ Properties string Name [readonly]
corresponding to this Network. If the network
is not provisioned or has not been connected to
before, the property is omitted.
+
+ array(object) ExtendedServiceSet [readonly]
+
+ Contains a list of paths of each individual
+ BasicServiceSet object.
diff --git a/doc/station-api.txt b/doc/station-api.txt
@@ -164,6 +164,29 @@ Properties string State [readonly]
for networks. net.connman.iwd.Network objects are
updated when this property goes from true to false.
+ object ConnectedAccessPoint [readonly, optional]
+
+ net.connman.iwd.BasicServiceSet object represeting the
+ BSS the device is currently connected to or to which
+ a connection is in progress.
+
+ ao Affinities [optional] [experimental]
+
+ Array of net.connman.iwd.BasicServiceSet object paths
+ that will be treated with higher affinity compared to
+ other BSS's. Currently the only allowed value to be
+ set in this array is the path to the currently connected
+ BasicServiceSet object, i.e.
+ Station.ConnectedAccessPoint.
+
+ Setting the affinity will lower the roaming threshold,
+ effectively locking IWD to the current BSS unless the
+ RSSI drops below the critical threshold set by
+ [General].CriticalRoamThreshold{5G} at which point
+ IWD will proceed with normal roaming behavior.
+
+ This property is cleared on roams/disconnections.
+
SignalLevelAgent hierarchy
==========================
diff --git a/monitor/main.c b/monitor/main.c
@@ -224,129 +224,42 @@ struct iwmon_interface {
char *ifname;
bool exists;
struct l_netlink *rtnl;
- struct l_netlink *genl;
+ struct l_genl *genl;
struct l_io *io;
};
static struct iwmon_interface monitor_interface = { };
-static void genl_parse(uint16_t type, const void *data, uint32_t len,
- const char *ifname)
+static void nl80211_appeared(const struct l_genl_family_info *info,
+ void *user_data)
{
- const struct genlmsghdr *genlmsg = data;
- const struct nlattr *nla;
- char name[GENL_NAMSIZ];
- uint16_t id = 0;
-
- if (nlmon)
- return;
-
- if (type != GENL_ID_CTRL)
- return;
-
- if (genlmsg->cmd != CTRL_CMD_NEWFAMILY)
- return;
-
- for (nla = data + GENL_HDRLEN; NLA_OK(nla, len);
- nla = NLA_NEXT(nla, len)) {
- switch (nla->nla_type & NLA_TYPE_MASK) {
- case CTRL_ATTR_FAMILY_ID:
- id = *((uint16_t *) NLA_DATA(nla));
- break;
- case CTRL_ATTR_FAMILY_NAME:
- strncpy(name, NLA_DATA(nla), GENL_NAMSIZ - 1);
- break;
- }
- }
-
- if (id == 0)
- return;
-
- if (strcmp(name, NL80211_GENL_NAME))
- return;
+ const char *ifname = user_data;
monitor_interface.io = open_packet(ifname);
if (!monitor_interface.io)
goto failed;
- nlmon = nlmon_open(id, writer_path, &config);
+ nlmon = nlmon_open(l_genl_family_info_get_id(info),
+ writer_path, &config);
if (!nlmon)
goto failed;
l_io_set_read_handler(monitor_interface.io, nlmon_receive, nlmon, NULL);
-
return;
failed:
l_main_quit();
}
-static void genl_notify(uint16_t type, const void *data,
- uint32_t len, void *user_data)
-{
- const char *ifname = user_data;
-
- genl_parse(type, data, len, ifname);
-}
-
-static void genl_callback(int error, uint16_t type, const void *data,
- uint32_t len, void *user_data)
-{
- const char *ifname = user_data;
-
- if (error < 0) {
- fprintf(stderr, "Failed to lookup nl80211 family\n");
- l_main_quit();
- return;
- }
-
- genl_parse(type, data, len, ifname);
-}
-
-static struct l_netlink *genl_lookup(const char *ifname)
+static struct l_genl *genl_lookup(const char *ifname)
{
- struct l_netlink *genl;
- char buf[GENL_HDRLEN + NLA_HDRLEN + GENL_NAMSIZ];
- struct genlmsghdr *genlmsg;
- struct nlattr *nla;
-
- genl = l_netlink_new(NETLINK_GENERIC);
-
- l_netlink_register(genl, GENL_ID_CTRL, genl_notify, NULL, NULL);
-
- genlmsg = (struct genlmsghdr *) buf;
- genlmsg->cmd = CTRL_CMD_GETFAMILY;
- genlmsg->version = 0;
- genlmsg->reserved = 0;
-
- nla = (struct nlattr *) (buf + GENL_HDRLEN);
- nla->nla_len = NLA_HDRLEN + GENL_NAMSIZ;
- nla->nla_type = CTRL_ATTR_FAMILY_NAME;
- strncpy(buf + GENL_HDRLEN + NLA_HDRLEN,
- NL80211_GENL_NAME, GENL_NAMSIZ);
-
- l_netlink_send(genl, GENL_ID_CTRL, 0, buf, sizeof(buf),
- genl_callback, (char *) ifname, NULL);
+ struct l_genl *genl = l_genl_new();
+ l_genl_request_family(genl, NL80211_GENL_NAME, nl80211_appeared,
+ (char *) ifname, NULL);
return genl;
}
-static size_t rta_add(void *rta_buf, unsigned short type, uint16_t len,
- const void *data)
-{
- unsigned short rta_len = RTA_LENGTH(len);
- struct rtattr *rta = rta_buf;
-
- memset(RTA_DATA(rta), 0, RTA_SPACE(len));
-
- rta->rta_len = rta_len;
- rta->rta_type = type;
- if (len)
- memcpy(RTA_DATA(rta), data, len);
-
- return RTA_SPACE(len);
-}
-
static bool rta_linkinfo_kind(struct rtattr *rta, unsigned short len,
const char* kind)
{
@@ -375,10 +288,9 @@ static struct l_netlink *rtm_interface_send_message(struct l_netlink *rtnl,
{
size_t nlmon_type_len = strlen(NLMON_TYPE);
unsigned short ifname_len = 0;
- size_t bufsize;
- struct ifinfomsg *rtmmsg;
- void *rta_buf;
- struct rtattr *linkinfo_rta;
+ struct l_netlink_message *nlm;
+ struct ifinfomsg ifi;
+ uint16_t flags = 0;
if (ifname) {
ifname_len = strlen(ifname) + 1;
@@ -387,64 +299,41 @@ static struct l_netlink *rtm_interface_send_message(struct l_netlink *rtnl,
return NULL;
}
+ if (!L_IN_SET(rtm_msg_type, RTM_NEWLINK, RTM_DELLINK, RTM_GETLINK))
+ return NULL;
+
if (!rtnl)
rtnl = l_netlink_new(NETLINK_ROUTE);
if (!rtnl)
return NULL;
- bufsize = NLMSG_LENGTH(sizeof(struct ifinfomsg)) +
- RTA_SPACE(ifname_len) + RTA_SPACE(0) +
- RTA_SPACE(nlmon_type_len);
-
- rtmmsg = l_malloc(bufsize);
- memset(rtmmsg, 0, bufsize);
-
- rtmmsg->ifi_family = AF_UNSPEC;
- rtmmsg->ifi_change = ~0;
-
- rta_buf = rtmmsg + 1;
-
- if (ifname)
- rta_buf += rta_add(rta_buf, IFLA_IFNAME, ifname_len, ifname);
-
- linkinfo_rta = rta_buf;
-
- rta_buf += rta_add(rta_buf, IFLA_LINKINFO, 0, NULL);
- rta_buf += rta_add(rta_buf, IFLA_INFO_KIND, nlmon_type_len, NLMON_TYPE);
-
- linkinfo_rta->rta_len = rta_buf - (void *) linkinfo_rta;
+ memset(&ifi, 0, sizeof(ifi));
+ ifi.ifi_family = AF_UNSPEC;
+ ifi.ifi_change = ~0;
switch (rtm_msg_type) {
case RTM_NEWLINK:
- rtmmsg->ifi_flags = IFF_UP | IFF_ALLMULTI | IFF_NOARP;
-
- l_netlink_send(rtnl, RTM_NEWLINK, NLM_F_CREATE|NLM_F_EXCL,
- rtmmsg, rta_buf - (void *) rtmmsg, callback,
- user_data, destroy);
- break;
-
- case RTM_DELLINK:
- rta_buf += rta_add(rta_buf, IFLA_IFNAME, ifname_len, ifname);
-
- l_netlink_send(rtnl, RTM_DELLINK, 0, rtmmsg,
- rta_buf - (void *)rtmmsg, callback, user_data,
- destroy);
+ ifi.ifi_flags = IFF_UP | IFF_ALLMULTI | IFF_NOARP;
+ flags = NLM_F_CREATE | NLM_F_EXCL;
break;
-
case RTM_GETLINK:
- l_netlink_send(rtnl, RTM_GETLINK, NLM_F_DUMP, rtmmsg,
- rta_buf - (void *)rtmmsg, callback, user_data,
- destroy);
- break;
-
- default:
- l_netlink_destroy(rtnl);
- rtnl = NULL;
+ flags = NLM_F_DUMP;
break;
}
- l_free(rtmmsg);
+ nlm = l_netlink_message_new(rtm_msg_type, flags);;
+ l_netlink_message_add_header(nlm, &ifi, sizeof(ifi));
+
+ if (ifname)
+ l_netlink_message_append(nlm, IFLA_IFNAME, ifname, ifname_len);
+
+ l_netlink_message_enter_nested(nlm, IFLA_LINKINFO);
+ l_netlink_message_append(nlm, IFLA_INFO_KIND,
+ NLMON_TYPE, nlmon_type_len);
+ l_netlink_message_leave_nested(nlm);
+
+ l_netlink_send(rtnl, nlm, callback, user_data, destroy);
return rtnl;
}
@@ -957,7 +846,7 @@ int main(int argc, char *argv[])
l_io_destroy(monitor_interface.io);
l_netlink_destroy(monitor_interface.rtnl);
- l_netlink_destroy(monitor_interface.genl);
+ l_genl_unref(monitor_interface.genl);
l_free(monitor_interface.ifname);
nlmon_close(nlmon);
diff --git a/monitor/nlmon.c b/monitor/nlmon.c
@@ -37,6 +37,7 @@
#include <linux/if.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
+#include <linux/if_link.h>
#include <linux/netlink.h>
#include <linux/genetlink.h>
#include <linux/rtnetlink.h>
@@ -47,6 +48,14 @@
#define ARPHRD_NETLINK 824
#endif
+#ifndef RMNET_FLAGS_INGRESS_MAP_CKSUMV5
+#define RMNET_FLAGS_INGRESS_MAP_CKSUMV5 (1U << 4)
+#endif
+
+#ifndef RMNET_FLAGS_EGRESS_MAP_CKSUMV5
+#define RMNET_FLAGS_EGRESS_MAP_CKSUMV5 (1U << 5)
+#endif
+
#include "linux/nl80211.h"
#include "ell/useful.h"
@@ -1689,7 +1698,7 @@ static void print_ie_he_capabilities(unsigned int level,
{
const uint8_t *ptr = data;
uint8_t width_set = bit_field((ptr + 6)[0], 1, 7);
- uint8_t mask = 0xff;
+ uint8_t mask = 0x3f;
const char *he_channel_width_bitfield[] = {
[0] = "40MHz supported (2.4GHz)",
@@ -2452,6 +2461,86 @@ static void print_reduced_neighbor_report(unsigned int level, const char *label,
}
}
+static void print_neighbor_report(unsigned int level, const char *label,
+ const void *data, uint16_t size)
+{
+ struct ie_tlv_iter iter;
+ struct ie_neighbor_report_info info;
+
+ const char *phy_type_table[] = {
+ [0] = NULL,
+ [1] = NULL,
+ [2] = "DSSS",
+ [3] = NULL,
+ [4] = "OFDM",
+ [5] = "HDRSSS",
+ [6] = "ERP",
+ [7] = "HT",
+ [8] = "DMG",
+ [9] = "VHT",
+ [10] = "TVHT",
+ [11] = "S1G",
+ [12] = "CDMG",
+ [13] = "CMMG",
+ [14] = "HE"
+ };
+
+ ie_tlv_iter_init(&iter, data - 2, size + 2);
+
+ if (!ie_tlv_iter_next(&iter))
+ return;
+
+ if (ie_parse_neighbor_report(&iter, &info) < 0) {
+ print_attr(level, "Invalid Neighbor report");
+ return;
+ }
+
+ print_attr(level, "Neighbor Report for "MAC, MAC_STR(info.addr));
+ print_attr(level + 1, "Operating Class: %u", info.oper_class);
+ print_attr(level + 1, "Channel Number: %u", info.channel_num);
+
+ if (info.phy_type <= 14 && phy_type_table[info.phy_type])
+ print_attr(level + 1, "Phy Type: %s",
+ phy_type_table[info.phy_type]);
+ else
+ print_attr(level + 1, "Phy Type: Unknown (%u)", info.phy_type);
+
+ if (info.bss_transition_pref_present)
+ print_attr(level + 1, "BSS Transition Preference: %u",
+ info.bss_transition_pref);
+
+ switch (info.reachable) {
+ case 1:
+ print_attr(level + 1, "Reachability: Not Reachable");
+ break;
+ case 2:
+ print_attr(level + 1, "Reachability: Unknown");
+ break;
+ case 3:
+ print_attr(level + 1, "Reachability: Reachable");
+ break;
+ default:
+ break;
+ }
+
+ print_attr(level + 1, "BSSID Information");
+
+ if (info.security)
+ print_attr(level + 2, "Security bit set");
+ if (info.key_scope)
+ print_attr(level + 2, "Key scope bit set");
+ if (info.spectrum_mgmt)
+ print_attr(level + 2, "Spectrum Mgmt bit set");
+ if (info.qos)
+ print_attr(level + 2, "QoS bit set");
+ if (info.apsd)
+ print_attr(level + 2, "APSD bit set");
+ if (info.md)
+ print_attr(level + 2, "MD bit set");
+ if (info.ht)
+ print_attr(level + 2, "HT bit set");
+}
+
static struct attr_entry ie_entry[] = {
{ IE_TYPE_SSID, "SSID",
ATTR_CUSTOM, { .function = print_ie_ssid } },
@@ -2520,6 +2609,8 @@ static struct attr_entry ie_entry[] = {
ATTR_CUSTOM, { .function = print_reduced_neighbor_report } },
{ IE_TYPE_RSNX, "RSNX",
ATTR_CUSTOM, { .function = print_rsnx } },
+ { IE_TYPE_NEIGHBOR_REPORT, "Neighbor Report",
+ ATTR_CUSTOM, { .function = print_neighbor_report } },
{ },
};
@@ -4979,6 +5070,7 @@ static void print_rm_action_frame(unsigned int level, const uint8_t *body,
print_rm_request(level + 1, body + 1, body_len - 1);
break;
case 1:
+ case 5:
print_rm_report(level + 1, body + 1, body_len - 1);
break;
}
@@ -5535,8 +5627,26 @@ static void print_cqm_event(unsigned int level, const char *label,
}
}
+static void print_cqm_thresholds(unsigned int level, const char *label,
+ const void *data, uint16_t size)
+{
+ const int32_t *thresholds = data;
+ unsigned int i;
+
+ if (size % 4) {
+ printf("malformed packet");
+ return;
+ }
+
+ print_attr(level, "%s:", label);
+
+ for (i = 0; i < size / 4; i++)
+ print_attr(level + 1, "Threshold: %d", thresholds[i]);
+
+}
static const struct attr_entry cqm_table[] = {
- { NL80211_ATTR_CQM_RSSI_THOLD, "RSSI threshold", ATTR_U32 },
+ { NL80211_ATTR_CQM_RSSI_THOLD, "RSSI thresholds", ATTR_CUSTOM,
+ { .function = print_cqm_thresholds } },
{ NL80211_ATTR_CQM_RSSI_HYST, "RSSI hysteresis", ATTR_U32 },
{ NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
"RSSI threshold event", ATTR_CUSTOM,
@@ -7153,8 +7263,10 @@ static void print_message(struct nlmon *nlmon, const struct timeval *tv,
if (nlmon->nowiphy && (cmd == NL80211_CMD_NEW_WIPHY))
return;
- if (nlmon->noscan && ((cmd == NL80211_CMD_NEW_SCAN_RESULTS) ||
- (cmd == NL80211_CMD_TRIGGER_SCAN)))
+ if (nlmon->noscan && L_IN_SET(cmd, NL80211_CMD_NEW_SCAN_RESULTS,
+ NL80211_CMD_NEW_SURVEY_RESULTS,
+ NL80211_CMD_TRIGGER_SCAN,
+ NL80211_CMD_GET_SURVEY))
return;
switch (type) {
@@ -7496,8 +7608,51 @@ static void flags_str(const struct flag_names *table,
pos += sprintf(str + pos, "]");
}
+static void print_rmnet_flags(unsigned int indent,
+ const char *label, uint32_t flags)
+{
+ if (flags & RMNET_FLAGS_INGRESS_DEAGGREGATION)
+ print_attr(indent, "%s: %s", label, "deaggregation");
+ if (flags & RMNET_FLAGS_INGRESS_MAP_COMMANDS)
+ print_attr(indent, "%s: %s", label, "map commands");
+ if (flags & RMNET_FLAGS_INGRESS_MAP_CKSUMV4)
+ print_attr(indent, "%s: %s", label, "ingress_mapv4");
+ if (flags & RMNET_FLAGS_EGRESS_MAP_CKSUMV4)
+ print_attr(indent, "%s: %s", label, "egress_mapv4");
+ if (flags & RMNET_FLAGS_INGRESS_MAP_CKSUMV5)
+ print_attr(indent, "%s: %s", label, "ingress_mapv5");
+ if (flags & RMNET_FLAGS_EGRESS_MAP_CKSUMV5)
+ print_attr(indent, "%s: %s", label, "egress_mapv5");
+}
+
+static void print_ifla_rmnet_flags(unsigned int indent, const char *str,
+ const void *buf, uint16_t size)
+{
+ struct ifla_rmnet_flags flags;
+
+ if (size != 8) {
+ printf("malformed packet\n");
+ return;
+ }
+
+ memcpy(&flags, buf, size);
+
+ print_attr(indent, "%s:", str);
+ print_rmnet_flags(indent + 1, "Flags", flags.flags);
+ print_rmnet_flags(indent + 1, "Mask", flags.mask);
+}
+
+static struct attr_entry link_info_data_entry[] = {
+ { IFLA_RMNET_MUX_ID, "RMNet Mux Id", ATTR_U16 },
+ { IFLA_RMNET_FLAGS, "RMNet Flags", ATTR_CUSTOM,
+ { .function = print_ifla_rmnet_flags } },
+ { },
+};
+
static struct attr_entry link_info_entry[] = {
{ IFLA_INFO_KIND, "Kind", ATTR_STRING },
+ { IFLA_INFO_DATA, "Info Data",
+ ATTR_NESTED, { link_info_data_entry } },
{ },
};
@@ -7654,7 +7809,7 @@ static void print_rtnl_attributes(int indent, const struct attr_entry *table,
return;
for (attr = rt_attr; RTA_OK(attr, len); attr = RTA_NEXT(attr, len)) {
- uint16_t rta_type = attr->rta_type;
+ uint16_t rta_type = attr->rta_type & NLA_TYPE_MASK;
enum attr_type type = ATTR_UNSPEC;
attr_func_t function;
const struct attr_entry *nested;
@@ -8202,7 +8357,8 @@ void nlmon_print_genl(struct nlmon *nlmon, const struct timeval *tv,
continue;
}
- if (!nlmon->read && nlmsg->nlmsg_type != nlmon->id)
+ if (nlmsg->nlmsg_type >= NLMSG_MIN_TYPE && !nlmon->read &&
+ nlmsg->nlmsg_type != nlmon->id)
continue;
nlmon_message(nlmon, tv, nlmsg);
diff --git a/src/ap.c b/src/ap.c
@@ -67,7 +67,7 @@ struct ap_state {
ap_stopped_func_t stopped_func;
void *user_data;
- char ssid[33];
+ char ssid[SSID_MAX_SIZE + 1];
char passphrase[64];
uint8_t psk[32];
enum band_freq band;
@@ -153,7 +153,7 @@ struct ap_wsc_pbc_probe_record {
};
struct ap_network {
- char ssid[33];
+ char ssid[SSID_MAX_SIZE + 1];
int16_t signal;
enum security security;
};
@@ -181,7 +181,7 @@ static int network_signal_compare(const void *a, const void *b, void *user)
static struct ap_network *ap_network_find(struct ap_state *ap,
struct scan_bss *bss)
{
- char ssid[33];
+ char ssid[SSID_MAX_SIZE + 1];
memcpy(ssid, bss->ssid, bss->ssid_len);
ssid[bss->ssid_len] = '\0';
@@ -3629,7 +3629,7 @@ static int ap_load_config(struct ap_state *ap, const struct l_settings *config,
return -ENOMSG;
len = strlen(strval);
- if (len < 1 || len > 32) {
+ if (len < 1 || len > SSID_MAX_SIZE) {
l_error("AP SSID length outside the [1, 32] range");
return -EINVAL;
}
diff --git a/src/band.c b/src/band.c
@@ -90,7 +90,7 @@ int band_estimate_nonht_rate(const struct band *band,
int i;
if (!supported_rates && !ext_supported_rates)
- return -EINVAL;
+ return -ENOTSUP;
/*
* Start at the back of the array. Rates are generally given in
@@ -607,7 +607,7 @@ int band_estimate_he_rx_rate(const struct band *band, const uint8_t *hec,
uint8_t width_set;
if (!hec || !band->he_capabilities)
- return -EBADMSG;
+ return -ENOTSUP;
for (entry = l_queue_get_entries(band->he_capabilities);
entry; entry = entry->next) {
@@ -678,7 +678,7 @@ int band_estimate_he_rx_rate(const struct band *band, const uint8_t *hec,
}
if (!rate)
- return -EBADMSG;
+ return -ENETUNREACH;
*out_data_rate = rate;
@@ -1485,15 +1485,48 @@ static const uint8_t oper_class_cn_to_global[] = {
/* 128 - 130 is a 1 to 1 mapping */
};
-enum band_freq band_oper_class_to_band(const uint8_t *country,
- uint8_t oper_class)
+/*
+ * Annex C describes the country string encoding.
+ *
+ * If it is a country, the first two octets of this string is the two character
+ * country code as described in document ISO 3166-1. The third octet is one of
+ * the following:
+ * 1. an ASCII space character, if the regulations under which the station is
+ * operating encompass all environments for the current frequency band in
+ * the country,
+ * 2. an ASCII 'O' character, if the regulations under which the station is
+ * operating are for an outdoor environment only, or
+ * 3. an ASCII 'I' character, if the regulations under which the station is
+ * operating are for an indoor environment only.
+ * 4. an ASCII 'X' character, if the station is operating under a noncountry
+ * entity. The first two octets of the noncountry entity is two ASCII 'XX'
+ * characters.
+ * 5. the hexadecimal representation of the Operating Class table number
+ * currently in use, from the set of tables defined in Annex E, e.g.,
+ * Table E-1 is represented as x'01'.
+ */
+static enum band_freq oper_class_to_band(const uint8_t *country,
+ uint8_t oper_class,
+ bool ignore_country3)
{
unsigned int i;
int table = 0;
- if (country && country[2] >= 1 && country[2] <= 5)
+ /*
+ * If a country is set, and the 3rd byte maps to some E-* table in the
+ * spec use that (case 5). Only caveat here is some APs erroneously set
+ * this 3rd byte. To work around we can fall back to case 1, where only
+ * the first two characters are used to lookup the table.
+ */
+ if (!ignore_country3 && country && country[2] >= 1 && country[2] <= 5)
table = country[2];
else if (country) {
+ /*
+ * Assuming case 1, although its unlikely you would handle
+ * cases 2 (O) or 3 (I) any differently. Case 4 (X) is unlikely
+ * and we really wouldn't have enough information to correctly
+ * determine the band in some obscure non-country domain.
+ */
for (i = 0; i < L_ARRAY_SIZE(oper_class_us_codes); i++)
if (!memcmp(oper_class_us_codes[i], country, 2)) {
/* Use table E-1 */
@@ -1542,6 +1575,25 @@ enum band_freq band_oper_class_to_band(const uint8_t *country,
return 0;
}
+enum band_freq band_oper_class_to_band(const uint8_t *country,
+ uint8_t oper_class)
+{
+ enum band_freq band = oper_class_to_band(country, oper_class, false);
+ if (!band) {
+ /* Fallback with no country string won't change anything */
+ if (!country)
+ return 0;
+
+ l_warn("Failed to find band with country string '%c%c %u' and "
+ "oper class %u, trying fallback",
+ country[0], country[1], country[2], oper_class);
+
+ return oper_class_to_band(country, oper_class, true);
+ }
+
+ return band;
+}
+
const char *band_chandef_width_to_string(enum band_chandef_width width)
{
switch (width) {
diff --git a/src/crypto.c b/src/crypto.c
@@ -35,6 +35,7 @@
#include "ell/useful.h"
#include "src/missing.h"
+#include "src/defs.h"
#include "src/crypto.h"
#define ARC4_MIN_KEY_SIZE 1
@@ -567,7 +568,7 @@ int crypto_psk_from_passphrase(const char *passphrase,
if (!crypto_passphrase_is_valid(passphrase))
return -ERANGE;
- if (ssid_len == 0 || ssid_len > 32)
+ if (ssid_len == 0 || ssid_len > SSID_MAX_SIZE)
return -ERANGE;
result = l_cert_pkcs5_pbkdf2(L_CHECKSUM_SHA1, passphrase,
diff --git a/src/dbus.c b/src/dbus.c
@@ -134,6 +134,12 @@ struct l_dbus_message *dbus_error_not_hidden(struct l_dbus_message *msg)
"Not hidden");
}
+struct l_dbus_message *dbus_error_permission_denied(struct l_dbus_message *msg)
+{
+ return l_dbus_message_new_error(msg, IWD_SERVICE ".PermissionDenied",
+ "Permission Denied");
+}
+
struct l_dbus_message *dbus_error_from_errno(int err,
struct l_dbus_message *msg)
{
diff --git a/src/dbus.h b/src/dbus.h
@@ -48,6 +48,7 @@
#define IWD_NETCONFIG_AGENT_INTERFACE \
"net.connman.iwd.NetworkConfigurationAgent"
#define IWD_SHARED_CODE_AGENT_INTERFACE "net.connman.iwd.SharedCodeAgent"
+#define IWD_BSS_INTERFACE "net.connman.iwd.BasicServiceSet"
#define IWD_BASE_PATH "/net/connman/iwd"
#define IWD_AGENT_MANAGER_PATH IWD_BASE_PATH
@@ -81,6 +82,7 @@ struct l_dbus_message *dbus_error_service_set_overlap(
struct l_dbus_message *dbus_error_already_provisioned(
struct l_dbus_message *msg);
struct l_dbus_message *dbus_error_not_hidden(struct l_dbus_message *msg);
+struct l_dbus_message *dbus_error_permission_denied(struct l_dbus_message *msg);
struct l_dbus_message *dbus_error_from_errno(int err,
struct l_dbus_message *msg);
diff --git a/src/defs.h b/src/defs.h
@@ -0,0 +1,13 @@
+/*
+ * Wireless daemon for Linux
+ * Copyright (C) 2024 Cruise, LLC
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#ifndef __DEFS_H__
+#define __DEFS_H__
+
+#define SSID_MAX_SIZE 32
+
+#endif
diff --git a/src/dpp-util.h b/src/dpp-util.h
@@ -19,6 +19,9 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
+
+#include "src/defs.h"
+
struct l_ecc_point;
struct l_ecc_scalar;
enum ie_rsn_akm_suite;
@@ -112,7 +115,7 @@ enum dpp_attribute_type {
};
struct dpp_configuration {
- char ssid[33];
+ char ssid[SSID_MAX_SIZE + 1];
size_t ssid_len;
uint32_t akm_suites;
char *passphrase;
diff --git a/src/dpp.c b/src/dpp.c
@@ -59,6 +59,7 @@
#define DPP_FRAME_RETRY_TIMEOUT 1
#define DPP_AUTH_PROTO_TIMEOUT 10
#define DPP_PKEX_PROTO_TIMEOUT 120
+#define DPP_PKEX_PROTO_PER_FREQ_TIMEOUT 10
static uint32_t netdev_watch;
static struct l_genl_family *nl80211;
@@ -193,6 +194,7 @@ struct dpp_sm {
bool roc_started : 1;
bool channel_switch : 1;
bool mutual_auth : 1;
+ bool autoconnect : 1;
};
static const char *dpp_role_to_string(enum dpp_capability role)
@@ -469,6 +471,8 @@ static void dpp_free_auth_data(struct dpp_sm *dpp)
static void dpp_reset(struct dpp_sm *dpp)
{
+ struct station *station = station_find(netdev_get_ifindex(dpp->netdev));
+
if (dpp->uri) {
l_free(dpp->uri);
dpp->uri = NULL;
@@ -549,12 +553,19 @@ static void dpp_reset(struct dpp_sm *dpp)
dpp_property_changed_notify(dpp);
dpp->interface = DPP_INTERFACE_UNBOUND;
+
+ if (station) {
+ if (dpp->station_watch)
+ station_remove_state_watch(station, dpp->station_watch);
+
+ /* Set the old autoconnect state back to what it was */
+ if (dpp->role == DPP_CAPABILITY_ENROLLEE)
+ station_set_autoconnect(station, dpp->autoconnect);
+ }
}
static void dpp_free(struct dpp_sm *dpp)
{
- struct station *station = station_find(netdev_get_ifindex(dpp->netdev));
-
dpp_reset(dpp);
if (dpp->own_asn1) {
@@ -572,13 +583,6 @@ static void dpp_free(struct dpp_sm *dpp)
dpp->boot_private = NULL;
}
- /*
- * Since this is called when the netdev goes down, station may already
- * be gone in which case the state watch will automatically go away.
- */
- if (station)
- station_remove_state_watch(station, dpp->station_watch);
-
known_networks_watch_remove(dpp->known_network_watch);
l_free(dpp);
@@ -1836,7 +1840,7 @@ static void dpp_send_pkex_exchange_request(struct dpp_sm *dpp)
l_put_le16(l_ecc_curve_get_ike_group(dpp->curve), &group);
- iov[0].iov_len = dpp_build_header(own_mac, broadcast,
+ iov[0].iov_len = dpp_build_header(own_mac, dpp->peer_addr,
DPP_FRAME_PKEX_VERSION1_XCHG_REQUEST, hdr);
iov[0].iov_base = hdr;
@@ -2368,7 +2372,7 @@ static void authenticate_response(struct dpp_sm *dpp, const uint8_t *from,
}
}
- if (status != DPP_STATUS_OK || !r_boot_hash || !r_proto ) {
+ if (status != DPP_STATUS_OK || !r_boot_hash || !r_proto || !wrapped) {
l_debug("Auth response bad status or missing attributes");
return;
}
@@ -2827,6 +2831,12 @@ static bool dpp_pkex_start_authentication(struct dpp_sm *dpp)
dpp_property_changed_notify(dpp);
+ /*
+ * No longer waiting for an arbitrary peer to respond, reduce the
+ * timeout now that we are proceeding to authentication
+ */
+ dpp_reset_protocol_timer(dpp, DPP_AUTH_PROTO_TIMEOUT);
+
if (dpp->role == DPP_CAPABILITY_ENROLLEE) {
dpp->new_freq = dpp->current_freq;
@@ -3721,6 +3731,9 @@ static void dpp_frame_watch(struct dpp_sm *dpp, uint16_t frame_type,
L_UINT_TO_PTR(frame_type), NULL);
}
+static void dpp_start_enrollee(struct dpp_sm *dpp);
+static bool dpp_start_pkex_enrollee(struct dpp_sm *dpp);
+
/*
* Station is unaware of DPP's state so we need to handle a few cases here so
* weird stuff doesn't happen:
@@ -3734,27 +3747,50 @@ static void dpp_frame_watch(struct dpp_sm *dpp, uint16_t frame_type,
* DPP finishes.
*
* Other conditions shouldn't ever happen i.e. configuring and going into a
- * connecting state or enrolling and going to a disconnected/roaming state.
+ * connecting state or enrolling and going to a roaming state.
*/
static void dpp_station_state_watch(enum station_state state, void *user_data)
{
struct dpp_sm *dpp = user_data;
- if (dpp->state == DPP_STATE_NOTHING)
+ if (dpp->state == DPP_STATE_NOTHING ||
+ dpp->interface == DPP_INTERFACE_UNBOUND)
return;
switch (state) {
case STATION_STATE_DISCONNECTED:
+ /* DPP-initiated disconnect, the enrollee can now start */
+ if (dpp->role == DPP_CAPABILITY_ENROLLEE) {
+ l_debug("Starting enrollee after disconnect");
+
+ if (dpp->interface == DPP_INTERFACE_DPP)
+ dpp_start_enrollee(dpp);
+ else
+ dpp_start_pkex_enrollee(dpp);
+
+ return;
+ }
+
+ break;
case STATION_STATE_DISCONNECTING:
+ /* Normal part of disconnecting prior to enrolling */
+ if (dpp->role == DPP_CAPABILITY_ENROLLEE)
+ return;
+
+ /* fall through */
case STATION_STATE_ROAMING:
case STATION_STATE_FT_ROAMING:
case STATION_STATE_FW_ROAMING:
+ /*
+ * An enrollee will always be disconnected prior to starting
+ * so a roaming condition should never happen.
+ */
if (L_WARN_ON(dpp->role == DPP_CAPABILITY_ENROLLEE))
- dpp_reset(dpp);
+ goto reset;
if (dpp->role == DPP_CAPABILITY_CONFIGURATOR) {
l_debug("Disconnected while configuring, stopping DPP");
- dpp_reset(dpp);
+ goto reset;
}
break;
@@ -3762,28 +3798,22 @@ static void dpp_station_state_watch(enum station_state state, void *user_data)
case STATION_STATE_CONNECTED:
case STATION_STATE_CONNECTING_AUTO:
case STATION_STATE_NETCONFIG:
- if (L_WARN_ON(dpp->role == DPP_CAPABILITY_CONFIGURATOR))
- dpp_reset(dpp);
-
- if (dpp->role == DPP_CAPABILITY_ENROLLEE) {
- l_debug("Connecting while enrolling, stopping DPP");
- dpp_reset(dpp);
- }
-
- break;
-
- /*
- * Autoconnect states are fine for enrollees. This makes it nicer for
- * the user since they don't need to explicity Disconnect() to disable
- * autoconnect, then re-enable it if DPP fails.
- */
case STATION_STATE_AUTOCONNECT_FULL:
case STATION_STATE_AUTOCONNECT_QUICK:
- if (L_WARN_ON(dpp->role == DPP_CAPABILITY_CONFIGURATOR))
- dpp_reset(dpp);
+ /*
+ * The user could have issued a connection request during
+ * enrolling, in which case DPP should be canceled. We should
+ * never hit this case as a configurator as a disconnect would
+ * need to come prior.
+ */
+ L_WARN_ON(dpp->role == DPP_CAPABILITY_CONFIGURATOR);
- break;
+ goto reset;
}
+
+reset:
+ l_debug("Resetting DPP after station state change (state=%u)", state);
+ dpp_reset(dpp);
}
static void dpp_create(struct netdev *netdev)
@@ -3793,7 +3823,6 @@ static void dpp_create(struct netdev *netdev)
uint8_t dpp_conf_response_prefix[] = { 0x04, 0x0b };
uint8_t dpp_conf_request_prefix[] = { 0x04, 0x0a };
uint64_t wdev_id = netdev_get_wdev_id(netdev);
- struct station *station = station_find(netdev_get_ifindex(netdev));
dpp->netdev = netdev;
dpp->state = DPP_STATE_NOTHING;
@@ -3839,8 +3868,6 @@ static void dpp_create(struct netdev *netdev)
sizeof(dpp_conf_request_prefix),
dpp_handle_config_request_frame, dpp, NULL);
- dpp->station_watch = station_add_state_watch(station,
- dpp_station_state_watch, dpp, NULL);
dpp->known_network_watch = known_networks_watch_add(
dpp_known_network_watch, dpp, NULL);
@@ -3927,43 +3954,77 @@ static void dpp_start_presence(struct dpp_sm *dpp, uint32_t *limit_freqs,
dpp_start_offchannel(dpp, dpp->current_freq);
}
-static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
- struct l_dbus_message *message,
- void *user_data)
+static int dpp_try_disconnect_station(struct dpp_sm *dpp,
+ bool *out_disconnect_started)
{
- struct dpp_sm *dpp = user_data;
- uint32_t freq = band_channel_to_freq(6, BAND_FREQ_2_4_GHZ);
struct station *station = station_find(netdev_get_ifindex(dpp->netdev));
+ int ret;
+ bool started = false;
- if (dpp->state != DPP_STATE_NOTHING ||
- dpp->interface != DPP_INTERFACE_UNBOUND)
- return dbus_error_busy(message);
+ /* Unusual case, but an enrollee could still be started */
+ if (!station)
+ goto done;
- /*
- * Station isn't actually required for DPP itself, although this will
- * prevent connecting to the network once configured.
- */
- if (station && station_get_connected_network(station)) {
- l_warn("cannot be enrollee while connected, please disconnect");
- return dbus_error_busy(message);
- } else if (!station)
- l_debug("No station device, continuing anyways...");
+ dpp->autoconnect = station_get_autoconnect(station);
+ station_set_autoconnect(station, false);
+
+ switch (station_get_state(station)) {
+ case STATION_STATE_AUTOCONNECT_QUICK:
+ case STATION_STATE_AUTOCONNECT_FULL:
+ /* Should never happen since we just set autoconnect false */
+ l_warn("Still in autoconnect state after setting false!");
+
+ /* fall through */
+ case STATION_STATE_DISCONNECTED:
+ break;
+ case STATION_STATE_ROAMING:
+ case STATION_STATE_FT_ROAMING:
+ case STATION_STATE_FW_ROAMING:
+ case STATION_STATE_CONNECTING:
+ case STATION_STATE_CONNECTING_AUTO:
+ case STATION_STATE_CONNECTED:
+ case STATION_STATE_NETCONFIG:
+ /*
+ * For any connected or connection in progress state, start a
+ * disconnect
+ */
+ ret = station_disconnect(station);
+ if (ret < 0) {
+ l_warn("failed to start disconnecting (%d)", ret);
+ station_set_autoconnect(station, dpp->autoconnect);
+
+ return ret;
+ }
+ /* fall through */
+ case STATION_STATE_DISCONNECTING:
+ l_debug("Delaying DPP start until after disconnect");
+ started = true;
+
+ break;
+ }
+
+ dpp->station_watch = station_add_state_watch(station,
+ dpp_station_state_watch,
+ dpp, NULL);
+done:
+ *out_disconnect_started = started;
+
+ return 0;
+}
+
+static void dpp_start_enrollee(struct dpp_sm *dpp)
+{
+ uint32_t freq = band_channel_to_freq(6, BAND_FREQ_2_4_GHZ);
dpp->uri = dpp_generate_uri(dpp->own_asn1, dpp->own_asn1_len, 2,
netdev_get_address(dpp->netdev), &freq,
1, NULL, NULL);
- dpp->state = DPP_STATE_PRESENCE;
- dpp->role = DPP_CAPABILITY_ENROLLEE;
- dpp->interface = DPP_INTERFACE_DPP;
-
l_ecdh_generate_key_pair(dpp->curve, &dpp->proto_private,
&dpp->own_proto_public);
l_debug("DPP Start Enrollee: %s", dpp->uri);
- dpp->pending = l_dbus_message_ref(message);
-
/*
* Going off spec here. Select a single channel to send presence
* announcements on. This will be advertised in the URI. The full
@@ -3972,6 +4033,39 @@ static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
dpp_start_presence(dpp, &freq, 1);
dpp_property_changed_notify(dpp);
+}
+
+static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
+ struct l_dbus_message *message,
+ void *user_data)
+{
+ struct dpp_sm *dpp = user_data;
+ bool wait_for_disconnect;
+ int ret;
+
+ if (dpp->state != DPP_STATE_NOTHING ||
+ dpp->interface != DPP_INTERFACE_UNBOUND)
+ return dbus_error_busy(message);
+
+ dpp->state = DPP_STATE_PRESENCE;
+ dpp->role = DPP_CAPABILITY_ENROLLEE;
+ dpp->interface = DPP_INTERFACE_DPP;
+
+ ret = dpp_try_disconnect_station(dpp, &wait_for_disconnect);
+ if (ret < 0) {
+ dpp_reset(dpp);
+ return dbus_error_from_errno(ret, message);
+ }
+
+ if (!wait_for_disconnect)
+ dpp_start_enrollee(dpp);
+
+ /*
+ * If a disconnect was started/in progress the enrollee will start once
+ * that has finished
+ */
+
+ dpp->pending = l_dbus_message_ref(message);
return NULL;
}
@@ -4105,6 +4199,9 @@ static struct l_dbus_message *dpp_start_configurator_common(
dpp_property_changed_notify(dpp);
+ dpp->station_watch = station_add_state_watch(station,
+ dpp_station_state_watch, dpp, NULL);
+
l_debug("DPP Start Configurator: %s", dpp->uri);
reply = l_dbus_message_new_method_return(message);
@@ -4190,6 +4287,19 @@ static uint32_t *dpp_default_freqs(struct dpp_sm *dpp, size_t *out_len)
return freqs_out;
}
+static void __dpp_pkex_start_enrollee(struct dpp_sm *dpp)
+{
+ uint32_t timeout = minsize(DPP_PKEX_PROTO_TIMEOUT,
+ dpp->freqs_len * DPP_PKEX_PROTO_PER_FREQ_TIMEOUT);
+ dpp->current_freq = dpp->freqs[0];
+
+ dpp_reset_protocol_timer(dpp, timeout);
+
+ l_debug("PKEX start enrollee (id=%s)", dpp->pkex_id ?: "unset");
+
+ dpp_start_offchannel(dpp, dpp->current_freq);
+}
+
static bool dpp_pkex_scan_notify(int err, struct l_queue *bss_list,
const struct scan_freq_set *freqs,
void *user_data)
@@ -4224,13 +4334,7 @@ static bool dpp_pkex_scan_notify(int err, struct l_queue *bss_list,
dpp->freqs = scan_freq_set_to_fixed_array(freq_set, &dpp->freqs_len);
start:
- dpp->current_freq = dpp->freqs[0];
-
- dpp_reset_protocol_timer(dpp, DPP_PKEX_PROTO_TIMEOUT);
-
- l_debug("PKEX start enrollee (id=%s)", dpp->pkex_id ?: "unset");
-
- dpp_start_offchannel(dpp, dpp->current_freq);
+ __dpp_pkex_start_enrollee(dpp);
return false;
@@ -4246,51 +4350,16 @@ static void dpp_pkex_scan_destroy(void *user_data)
dpp->pkex_scan_id = 0;
}
-static bool dpp_start_pkex_enrollee(struct dpp_sm *dpp, const char *key,
- const char *identifier)
+static bool dpp_start_pkex_enrollee(struct dpp_sm *dpp)
{
- _auto_(l_ecc_point_free) struct l_ecc_point *qi = NULL;
-
- if (identifier)
- dpp->pkex_id = l_strdup(identifier);
-
- dpp->pkex_key = l_strdup(key);
- memcpy(dpp->peer_addr, broadcast, 6);
- dpp->role = DPP_CAPABILITY_ENROLLEE;
- dpp->state = DPP_STATE_PKEX_EXCHANGE;
- dpp->interface = DPP_INTERFACE_PKEX;
- /*
- * In theory a driver could support a lesser duration than 200ms. This
- * complicates things since we would need to tack on additional
- * offchannel requests to meet the 200ms requirement. This could be done
- * but for now use max_roc or 200ms, whichever is less.
- */
- dpp->dwell = (dpp->max_roc < 200) ? dpp->max_roc : 200;
- /* "DPP R2 devices are expected to use PKEXv1 by default" */
- dpp->pkex_version = 1;
-
- if (!l_ecdh_generate_key_pair(dpp->curve, &dpp->pkex_private,
- &dpp->pkex_public))
- goto failed;
+ dpp_property_changed_notify(dpp);
- /*
- * "If Qi is the point-at-infinity, the code shall be deleted and the
- * user should be notified to provision a new code"
- */
- qi = dpp_derive_qi(dpp->curve, dpp->pkex_key, dpp->pkex_id,
- netdev_get_address(dpp->netdev));
- if (!qi || l_ecc_point_is_infinity(qi)) {
- l_debug("Cannot derive Qi, provision a new code");
- goto failed;
+ /* Already have a set (or single) frequency */
+ if (dpp->freqs) {
+ __dpp_pkex_start_enrollee(dpp);
+ return true;
}
- dpp->pkex_m = l_ecc_point_new(dpp->curve);
-
- if (!l_ecc_point_add(dpp->pkex_m, dpp->pkex_public, qi))
- goto failed;
-
- dpp_property_changed_notify(dpp);
-
/*
* The 'dpp_default_freqs' function returns the default frequencies
* outlined in section 5.6.1. For 2.4/5GHz this is only 3 frequencies
@@ -4320,13 +4389,17 @@ failed:
static bool dpp_parse_pkex_args(struct l_dbus_message *message,
const char **key_out,
- const char **id_out)
+ const char **id_out,
+ const char **mac_out,
+ uint32_t *freq_out)
{
struct l_dbus_message_iter iter;
struct l_dbus_message_iter variant;
const char *dict_key;
const char *key = NULL;
const char *id = NULL;
+ const char *mac = NULL;
+ uint32_t freq = 0;
if (!l_dbus_message_get_arguments(message, "a{sv}", &iter))
return false;
@@ -4340,6 +4413,14 @@ static bool dpp_parse_pkex_args(struct l_dbus_message *message,
if (!l_dbus_message_iter_get_variant(&variant, "s",
&id))
return false;
+ } else if (!strcmp(dict_key, "Address")) {
+ if (!l_dbus_message_iter_get_variant(&variant, "s",
+ &mac))
+ return false;
+ } else if (!strcmp(dict_key, "Frequency")) {
+ if (!l_dbus_message_iter_get_variant(&variant, "u",
+ &freq))
+ return false;
}
}
@@ -4352,9 +4433,49 @@ static bool dpp_parse_pkex_args(struct l_dbus_message *message,
*key_out = key;
*id_out = id;
+ if (mac_out)
+ *mac_out = mac;
+
+ if (freq_out)
+ *freq_out = freq;
+
return true;
}
+static bool dpp_pkex_derive_keys(struct dpp_sm *dpp)
+{
+ _auto_(l_ecc_point_free) struct l_ecc_point *qi = NULL;
+
+ /*
+ * In theory a driver could support a lesser duration than 200ms. This
+ * complicates things since we would need to tack on additional
+ * offchannel requests to meet the 200ms requirement. This could be done
+ * but for now use max_roc or 200ms, whichever is less.
+ */
+ dpp->dwell = (dpp->max_roc < 200) ? dpp->max_roc : 200;
+ /* "DPP R2 devices are expected to use PKEXv1 by default" */
+ dpp->pkex_version = 1;
+
+ if (!l_ecdh_generate_key_pair(dpp->curve, &dpp->pkex_private,
+ &dpp->pkex_public))
+ return false;
+
+ /*
+ * "If Qi is the point-at-infinity, the code shall be deleted and the
+ * user should be notified to provision a new code"
+ */
+ qi = dpp_derive_qi(dpp->curve, dpp->pkex_key, dpp->pkex_id,
+ netdev_get_address(dpp->netdev));
+ if (!qi || l_ecc_point_is_infinity(qi)) {
+ l_debug("Cannot derive Qi, provision a new code");
+ return false;
+ }
+
+ dpp->pkex_m = l_ecc_point_new(dpp->curve);
+
+ return l_ecc_point_add(dpp->pkex_m, dpp->pkex_public, qi);
+}
+
static struct l_dbus_message *dpp_dbus_pkex_start_enrollee(struct l_dbus *dbus,
struct l_dbus_message *message,
void *user_data)
@@ -4362,7 +4483,10 @@ static struct l_dbus_message *dpp_dbus_pkex_start_enrollee(struct l_dbus *dbus,
struct dpp_sm *dpp = user_data;
const char *key;
const char *id;
- struct station *station = station_find(netdev_get_ifindex(dpp->netdev));
+ const char *mac_str;
+ uint32_t freq;
+ bool wait_for_disconnect;
+ int ret;
l_debug("");
@@ -4370,15 +4494,48 @@ static struct l_dbus_message *dpp_dbus_pkex_start_enrollee(struct l_dbus *dbus,
dpp->interface != DPP_INTERFACE_UNBOUND)
return dbus_error_busy(message);
- if (station && station_get_connected_network(station))
- return dbus_error_busy(message);
+ if (!dpp_parse_pkex_args(message, &key, &id, &mac_str, &freq))
+ goto invalid_args;
- if (!dpp_parse_pkex_args(message, &key, &id))
+ if (mac_str && !util_string_to_address(mac_str, dpp->peer_addr))
goto invalid_args;
+ else if (!mac_str)
+ memcpy(dpp->peer_addr, broadcast, 6);
+
+ if (freq) {
+ dpp->freqs = l_new(uint32_t, 1);
+ dpp->freqs[0] = freq;
+ dpp->freqs_len = 1;
+ }
+
+ dpp->pkex_key = l_strdup(key);
+
+ if (id)
+ dpp->pkex_id = l_strdup(id);
+
+ dpp->role = DPP_CAPABILITY_ENROLLEE;
+ dpp->state = DPP_STATE_PKEX_EXCHANGE;
+ dpp->interface = DPP_INTERFACE_PKEX;
+
+ ret = dpp_try_disconnect_station(dpp, &wait_for_disconnect);
+ if (ret < 0) {
+ dpp_reset(dpp);
+ return dbus_error_from_errno(ret, message);
+ }
- if (!dpp_start_pkex_enrollee(dpp, key, id))
+ if (!dpp_pkex_derive_keys(dpp)) {
+ dpp_reset(dpp);
+ return dbus_error_failed(message);
+ }
+
+ if (!wait_for_disconnect && !dpp_start_pkex_enrollee(dpp))
goto invalid_args;
+ /*
+ * If a disconnect was started/in progress the PKEX enrollee will start
+ * once that has finished
+ */
+
return l_dbus_message_new_method_return(message);
invalid_args:
@@ -4426,11 +4583,9 @@ static struct l_dbus_message *dpp_start_pkex_configurator(struct dpp_sm *dpp,
dpp->interface != DPP_INTERFACE_UNBOUND)
return dbus_error_busy(message);
- if (!dpp->mcast_support) {
- l_debug("Multicast frame registration not supported, cannot "
- "start a configurator");
- return dbus_error_not_supported(message);
- }
+ if (!dpp->mcast_support)
+ l_debug("Multicast frame registration not supported, only "
+ "enrollees sending uncast will be supported");
if (!network || !bss)
return dbus_error_not_connected(message);
@@ -4462,6 +4617,9 @@ static struct l_dbus_message *dpp_start_pkex_configurator(struct dpp_sm *dpp,
dpp_reset_protocol_timer(dpp, DPP_PKEX_PROTO_TIMEOUT);
dpp_property_changed_notify(dpp);
+ dpp->station_watch = station_add_state_watch(station,
+ dpp_station_state_watch, dpp, NULL);
+
if (dpp->pkex_key)
l_debug("Starting PKEX configurator for single enrollee");
else
@@ -4481,7 +4639,7 @@ static struct l_dbus_message *dpp_dbus_pkex_configure_enrollee(
l_debug("");
- if (!dpp_parse_pkex_args(message, &key, &id))
+ if (!dpp_parse_pkex_args(message, &key, &id, NULL, NULL))
return dbus_error_invalid_args(message);
return dpp_start_pkex_configurator(dpp, key, id, NULL, message);
diff --git a/src/eap-mschapv2.c b/src/eap-mschapv2.c
@@ -445,7 +445,6 @@ static int eap_mschapv2_check_settings(struct l_settings *settings,
if (!identity) {
secret = l_queue_find(secrets, eap_secret_info_match, setting);
if (secret) {
- identity = l_strdup(secret->value);
password = l_strdup(secret->value +
strlen(secret->value) + 1);
@@ -532,6 +531,9 @@ static bool eap_mschapv2_load_settings(struct eap_state *eap,
snprintf(setting, sizeof(setting), "%sPassword-Hash", prefix);
hash = l_settings_get_bytes(settings, "Security", setting,
&hash_len);
+ if (!hash)
+ goto error;
+
memcpy(state->password_hash, hash, 16);
explicit_bzero(hash, 16);
l_free(hash);
diff --git a/src/eap-tls-common.c b/src/eap-tls-common.c
@@ -500,10 +500,9 @@ static int eap_tls_init_request_assembly(struct eap_state *eap,
tls_msg_len = l_get_be32(pkt);
len -= 4;
- if (!tls_msg_len || tls_msg_len > EAP_TLS_PDU_MAX_LEN) {
- l_warn("%s: Fragmented pkt size is outside of allowed"
- " boundaries [1, %u]", eap_get_method_name(eap),
- EAP_TLS_PDU_MAX_LEN);
+ if (tls_msg_len > EAP_TLS_PDU_MAX_LEN) {
+ l_warn("%s: Fragmented pkt size is larger than %u.",
+ eap_get_method_name(eap), EAP_TLS_PDU_MAX_LEN);
return -EINVAL;
}
diff --git a/src/eap-wsc.c b/src/eap-wsc.c
@@ -2067,7 +2067,7 @@ static bool eap_wsc_r_load_settings(struct eap_state *eap,
str = l_settings_get_string(settings, "WSC", "WPA2-SSID");
if (str) {
- if (strlen(str) > 32)
+ if (strlen(str) > SSID_MAX_SIZE)
goto bad_string;
wsc->m2->auth_type_flags |=
@@ -2113,7 +2113,7 @@ static bool eap_wsc_r_load_settings(struct eap_state *eap,
str = l_settings_get_string(settings, "WSC", "Open-SSID");
if (str) {
- if (strlen(str) > 32)
+ if (strlen(str) > SSID_MAX_SIZE)
goto bad_string;
wsc->m2->auth_type_flags |= WSC_AUTHENTICATION_TYPE_OPEN;
diff --git a/src/eapol.c b/src/eapol.c
@@ -387,6 +387,23 @@ error:
return NULL;
}
+static int padded_aes_wrap(const uint8_t *kek, uint8_t *key_data,
+ size_t *key_data_len,
+ struct eapol_key *out_frame, size_t mic_len)
+{
+ if (*key_data_len < 16 || *key_data_len % 8)
+ key_data[(*key_data_len)++] = 0xdd;
+ while (*key_data_len < 16 || *key_data_len % 8)
+ key_data[(*key_data_len)++] = 0x00;
+
+ if (!aes_wrap(kek, key_data, *key_data_len,
+ EAPOL_KEY_DATA(out_frame, mic_len)))
+ return -ENOPROTOOPT;
+
+ *key_data_len += 8;
+ return 0;
+}
+
/*
* Pad and encrypt the plaintext Key Data contents in @key_data using
* the encryption scheme required by @out_frame->key_descriptor_version,
@@ -395,12 +412,12 @@ error:
* Note that for efficiency @key_data is being modified, including in
* case of failure, so it must be sufficiently larger than @key_data_len.
*/
-static int eapol_encrypt_key_data(const uint8_t *kek, uint8_t *key_data,
- size_t key_data_len,
+static int eapol_encrypt_key_data(enum ie_rsn_akm_suite akm, const uint8_t *kek,
+ uint8_t *key_data, size_t key_data_len,
struct eapol_key *out_frame, size_t mic_len)
{
uint8_t key[32];
- bool ret;
+ int ret;
switch (out_frame->key_descriptor_version) {
case EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4:
@@ -426,18 +443,23 @@ static int eapol_encrypt_key_data(const uint8_t *kek, uint8_t *key_data,
break;
case EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES:
case EAPOL_KEY_DESCRIPTOR_VERSION_AES_128_CMAC_AES:
- if (key_data_len < 16 || key_data_len % 8)
- key_data[key_data_len++] = 0xdd;
- while (key_data_len < 16 || key_data_len % 8)
- key_data[key_data_len++] = 0x00;
-
- if (!aes_wrap(kek, key_data, key_data_len,
- EAPOL_KEY_DATA(out_frame, mic_len)))
- return -ENOPROTOOPT;
-
- key_data_len += 8;
+ ret = padded_aes_wrap(kek, key_data, &key_data_len,
+ out_frame, mic_len);
+ if (ret < 0)
+ return ret;
break;
+ case EAPOL_KEY_DESCRIPTOR_VERSION_AKM_DEFINED:
+ switch (akm) {
+ case IE_RSN_AKM_SUITE_SAE_SHA256:
+ ret = padded_aes_wrap(kek, key_data, &key_data_len,
+ out_frame, mic_len);
+ if (ret < 0)
+ return ret;
+ break;
+ default:
+ return -ENOTSUP;
+ }
}
l_put_be16(key_data_len, EAPOL_KEY_DATA(out_frame, mic_len) - 2);
@@ -1011,11 +1033,9 @@ static void eapol_install_igtk(struct eapol_sm *sm, uint16_t igtk_key_index,
static void __send_eapol_start(struct eapol_sm *sm, bool noencrypt)
{
- uint8_t buf[sizeof(struct eapol_frame)];
+ uint8_t buf[sizeof(struct eapol_frame)] = {};
struct eapol_frame *frame = (struct eapol_frame *) buf;
- handshake_event(sm->handshake, HANDSHAKE_EVENT_STARTED);
-
frame->header.protocol_version = EAPOL_PROTOCOL_VERSION_2001;
frame->header.packet_type = 1;
l_put_be16(0, &frame->header.packet_len);
@@ -1434,6 +1454,19 @@ static void eapol_send_ptk_3_of_4(struct eapol_sm *sm)
key_data_len += gtk_kde[1] + 2;
}
+ if (sm->handshake->mfp) {
+ enum crypto_cipher group_management_cipher =
+ ie_rsn_cipher_suite_to_cipher(
+ sm->handshake->group_management_cipher);
+ uint8_t *igtk_kde = key_data_buf + key_data_len;
+
+ handshake_util_build_igtk_kde(group_management_cipher,
+ sm->handshake->igtk,
+ sm->handshake->igtk_index,
+ igtk_kde);
+ key_data_len += igtk_kde[1] + 2;
+ }
+
if (sm->handshake->support_ip_allocation &&
!sm->handshake->client_ip_addr) {
handshake_event(sm->handshake, HANDSHAKE_EVENT_P2P_IP_REQUEST);
@@ -1467,8 +1500,9 @@ static void eapol_send_ptk_3_of_4(struct eapol_sm *sm)
}
kek = handshake_state_get_kek(sm->handshake);
- key_data_len = eapol_encrypt_key_data(kek, key_data_buf,
- key_data_len, ek, sm->mic_len);
+ key_data_len = eapol_encrypt_key_data(sm->handshake->akm_suite, kek,
+ key_data_buf, key_data_len, ek,
+ sm->mic_len);
explicit_bzero(key_data_buf, sizeof(key_data_buf));
if (key_data_len < 0)
@@ -1560,6 +1594,7 @@ static void eapol_handle_ptk_2_of_4(struct eapol_sm *sm,
size_t ptk_size;
const uint8_t *kck;
const uint8_t *aa = sm->handshake->aa;
+ enum l_checksum_type type;
l_debug("ifindex=%u", sm->handshake->ifindex);
@@ -1571,12 +1606,16 @@ static void eapol_handle_ptk_2_of_4(struct eapol_sm *sm,
ptk_size = handshake_state_get_ptk_size(sm->handshake);
+ type = L_CHECKSUM_SHA1;
+ if (sm->handshake->akm_suite == IE_RSN_AKM_SUITE_SAE_SHA256)
+ type = L_CHECKSUM_SHA256;
+
if (!crypto_derive_pairwise_ptk(sm->handshake->pmk,
sm->handshake->pmk_len,
sm->handshake->spa, aa,
sm->handshake->anonce, ek->key_nonce,
sm->handshake->ptk, ptk_size,
- L_CHECKSUM_SHA1))
+ type))
return;
kck = handshake_state_get_kck(sm->handshake);
@@ -2817,6 +2856,8 @@ bool eapol_start(struct eapol_sm *sm)
eap_set_peer_id(sm->eap, network_id);
}
+ handshake_event(sm->handshake, HANDSHAKE_EVENT_STARTED);
+
sm->started = true;
if (sm->require_handshake)
diff --git a/src/fils.c b/src/fils.c
@@ -489,7 +489,7 @@ static int fils_rx_associate(struct auth_proto *driver, const uint8_t *frame,
bool sha384 = (fils->hs->akm_suite & (IE_RSN_AKM_SUITE_FILS_SHA384 |
IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384));
uint8_t data[44];
- uint8_t *ptr = data;
+ uint8_t *ptr;
if (assoc->status_code != 0)
return L_CPU_TO_LE16(assoc->status_code);
diff --git a/src/handshake.c b/src/handshake.c
@@ -838,6 +838,21 @@ void handshake_state_set_gtk(struct handshake_state *s, const uint8_t *key,
memcpy(s->gtk_rsc, rsc, 6);
}
+void handshake_state_set_igtk(struct handshake_state *s, const uint8_t *key,
+ unsigned int key_index, const uint8_t *rsc)
+{
+ enum crypto_cipher cipher =
+ ie_rsn_cipher_suite_to_cipher(s->group_management_cipher);
+ int key_len = crypto_cipher_key_len(cipher);
+
+ if (!key_len)
+ return;
+
+ memcpy(s->igtk, key, key_len);
+ s->igtk_index = key_index;
+ memcpy(s->igtk_rsc, rsc, 6);
+}
+
/*
* This function performs a match of the RSN/WPA IE obtained from the scan
* results vs the RSN/WPA IE obtained as part of the 4-way handshake. If they
@@ -1027,6 +1042,25 @@ void handshake_util_build_gtk_kde(enum crypto_cipher cipher, const uint8_t *key,
memcpy(to, key, key_len);
}
+void handshake_util_build_igtk_kde(enum crypto_cipher cipher, const uint8_t *key,
+ unsigned int key_index, uint8_t *to)
+{
+ size_t key_len = crypto_cipher_key_len(cipher);
+
+ *to++ = IE_TYPE_VENDOR_SPECIFIC;
+ *to++ = 12 + key_len;
+ l_put_be32(HANDSHAKE_KDE_IGTK, to);
+ to += 4;
+ *to++ = key_index;
+ *to++ = 0;
+
+ /** Initialize PN to zero **/
+ memset(to, 0, 6);
+ to += 6;
+
+ memcpy(to, key, key_len);
+}
+
static const uint8_t *handshake_state_get_ft_fils_kek(struct handshake_state *s,
size_t *len)
{
diff --git a/src/handshake.h b/src/handshake.h
@@ -141,7 +141,7 @@ struct handshake_state {
bool supplicant_ocvc : 1;
bool ext_key_id_capable : 1;
bool force_default_ecc_group : 1;
- uint8_t ssid[32];
+ uint8_t ssid[SSID_MAX_SIZE];
size_t ssid_len;
char *passphrase;
char *password_identifier;
@@ -150,8 +150,11 @@ struct handshake_state {
uint8_t r1khid[6];
uint8_t gtk[32];
uint8_t gtk_rsc[6];
+ uint8_t igtk[32];
+ uint8_t igtk_rsc[6];
uint8_t proto_version : 2;
unsigned int gtk_index;
+ unsigned int igtk_index;
uint8_t active_tk_index;
struct erp_cache_entry *erp_cache;
bool support_ip_allocation : 1;
@@ -288,6 +291,9 @@ bool handshake_decode_fte_key(struct handshake_state *s, const uint8_t *wrapped,
void handshake_state_set_gtk(struct handshake_state *s, const uint8_t *key,
unsigned int key_index, const uint8_t *rsc);
+void handshake_state_set_igtk(struct handshake_state *s, const uint8_t *key,
+ unsigned int key_index, const uint8_t *rsc);
+
void handshake_state_set_chandef(struct handshake_state *s,
struct band_chandef *chandef);
int handshake_state_verify_oci(struct handshake_state *s, const uint8_t *oci,
@@ -307,5 +313,7 @@ const uint8_t *handshake_util_find_pmkid_kde(const uint8_t *data,
size_t data_len);
void handshake_util_build_gtk_kde(enum crypto_cipher cipher, const uint8_t *key,
unsigned int key_index, uint8_t *to);
+void handshake_util_build_igtk_kde(enum crypto_cipher cipher, const uint8_t *key,
+ unsigned int key_index, uint8_t *to);
DEFINE_CLEANUP_FUNC(handshake_state_free);
diff --git a/src/ie.c b/src/ie.c
@@ -1178,9 +1178,6 @@ static int build_ciphers_common(const struct ie_rsn_info *info, uint8_t *to,
countptr = to + pos;
pos += 2;
- akm_suite = IE_RSN_AKM_SUITE_8021X;
- count = 0;
-
for (count = 0, akm_suite = IE_RSN_AKM_SUITE_8021X;
akm_suite <= IE_RSN_AKM_SUITE_OSEN;
akm_suite <<= 1) {
@@ -1512,32 +1509,6 @@ bool is_ie_wpa_ie(const uint8_t *data, uint8_t len)
return false;
}
-/*
- * List of vendor OUIs (prefixed with a length byte) which require forcing
- * the default SAE group.
- */
-static const uint8_t use_default_sae_group_ouis[][5] = {
- { 0x04, 0xf4, 0xf5, 0xe8, 0x05 },
-};
-
-bool is_ie_default_sae_group_oui(const uint8_t *data, uint16_t len)
-{
- unsigned int i;
- const uint8_t *oui;
-
- for (i = 0; i < L_ARRAY_SIZE(use_default_sae_group_ouis); i++) {
- oui = use_default_sae_group_ouis[i];
-
- if (len < oui[0])
- continue;
-
- if (!memcmp(oui + 1, data, oui[0]))
- return true;
- }
-
- return false;
-}
-
int ie_parse_wpa(struct ie_tlv_iter *iter, struct ie_rsn_info *out_info)
{
const uint8_t *data = iter->data;
@@ -2671,7 +2642,7 @@ int ie_parse_owe_transition(const void *data, size_t len,
return -ENOMSG;
slen = l_get_u8(ie + 12);
- if (slen > 32)
+ if (slen > SSID_MAX_SIZE)
return -ENOMSG;
/*
diff --git a/src/ie.h b/src/ie.h
@@ -23,6 +23,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <unistd.h>
+#include "src/defs.h"
/*
* Information elements, IEEE Std 802.11-2012 ch. 8.4.2 and
@@ -361,6 +362,11 @@ enum ie_rsn_akm_suite {
IE_RSN_AKM_SUITE_OSEN = 0x40000,
};
+static inline bool IE_AKM_IS_OWE(uint32_t akm)
+{
+ return akm & (IE_RSN_AKM_SUITE_OWE);
+}
+
static inline bool IE_AKM_IS_SAE(uint32_t akm)
{
return akm & (IE_RSN_AKM_SUITE_SAE_SHA256 |
@@ -560,7 +566,7 @@ struct ie_fils_ip_addr_response_info {
struct ie_owe_transition_info {
uint8_t bssid[6];
- uint8_t ssid[32];
+ uint8_t ssid[SSID_MAX_SIZE];
size_t ssid_len;
uint8_t oper_class;
uint8_t channel;
@@ -634,7 +640,6 @@ int ie_parse_wpa_from_data(const uint8_t *data, size_t len,
struct ie_rsn_info *info);
bool is_ie_wfa_ie(const uint8_t *data, uint8_t len, uint8_t oi_type);
bool is_ie_wpa_ie(const uint8_t *data, uint8_t len);
-bool is_ie_default_sae_group_oui(const uint8_t *data, uint16_t len);
bool ie_build_wpa(const struct ie_rsn_info *info, uint8_t *to);
diff --git a/src/iwd.config.rst b/src/iwd.config.rst
@@ -74,7 +74,7 @@ The group ``[General]`` contains general settings.
``[Network]`` settings for additional settings related to network
configuration.
- * - UseDefaultInterface
+ * - UseDefaultInterface (**deprecated**)
- Values: true, **false**
Do not allow **iwd** to destroy / recreate wireless interfaces at
@@ -84,6 +84,9 @@ The group ``[General]`` contains general settings.
most users with an upstream driver it should be safe to omit/disable
this setting.
+ This setting is deprecated, please use [DriverQuirks].DefaultInterface
+ instead.
+
* - AddressRandomization
- Values: **disabled**, once, network
@@ -130,6 +133,22 @@ The group ``[General]`` contains general settings.
This value can be used to control how aggressively **iwd** roams when
connected to a 5GHz access point.
+ * - CriticalRoamThreshold
+ - Value: rssi dBm value, from -100 to -1, default: **-80**
+
+ The threshold (for 2.4GHz) at which IWD will roam regardless of the
+ affinity set to the current BSS. If the connected BSS has affinity
+ (set in Station's Affinities list) the roam threshold will be lowed to
+ this value and IWD will not attempt to roam (or roam scan) until either
+ the affinity is cleared, or the signal drops below this threshold.
+
+
+ * - CriticalRoamThreshold5G
+ - Value: rssi dBm value, from -100 to -1, default: **-82**
+
+ This has the same effect as ``CriticalRoamThreshold``, but for the 5GHz
+ band.
+
* - RoamRetryInterval
- Value: unsigned int value in seconds (default: **60**)
diff --git a/src/knownnetworks.h b/src/knownnetworks.h
@@ -20,6 +20,8 @@
*
*/
+#include "src/defs.h"
+
#define SETTINGS "Settings"
#define NET_HIDDEN SETTINGS, "Hidden"
#define NET_AUTOCONNECT SETTINGS, "AutoConnect"
@@ -84,7 +86,7 @@ struct network_config {
struct network_info {
const struct network_info_ops *ops;
- char ssid[33];
+ char ssid[SSID_MAX_SIZE + 1];
enum security type;
struct l_queue *known_frequencies;
int seen_count; /* Ref count for network.info */
diff --git a/src/main.c b/src/main.c
@@ -156,6 +156,7 @@ static void usage(void)
"\t-p, --phys Phys to manage\n"
"\t-P, --nophys Phys to ignore\n"
"\t-d, --debug Enable debug output\n"
+ "\t-l, --logger Override default stderr logging\n"
"\t-v, --version Show version\n"
"\t-h, --help Show help options\n");
}
@@ -535,6 +536,8 @@ int main(int argc, char *argv[])
else
l_log_set_stderr();
+ l_log_set_ident("iwd");
+
if (check_crypto() < 0)
return EXIT_FAILURE;
diff --git a/src/manager.c b/src/manager.c
@@ -894,8 +894,11 @@ static int manager_init(void)
}
if (!l_settings_get_bool(config, "General",
- "UseDefaultInterface", &use_default))
+ "UseDefaultInterface", &use_default)) {
+ l_warn("[General].UseDefaultInterface is deprecated, please "
+ "use [DriverQuirks].DefaultInterface instead");
use_default = false;
+ }
return 0;
diff --git a/src/netdev.c b/src/netdev.c
@@ -133,6 +133,7 @@ struct netdev {
uint32_t get_oci_cmd_id;
uint32_t get_link_cmd_id;
uint32_t power_save_cmd_id;
+ uint32_t set_cqm_cmd_id;
enum netdev_result result;
uint16_t last_code; /* reason or status, depending on result */
struct l_timeout *neighbor_report_timeout;
@@ -172,6 +173,9 @@ struct netdev {
struct netdev_ext_key_info *ext_key_info;
+ int low_signal_threshold;
+ int low_signal_threshold_5ghz;
+
bool connected : 1;
bool associated : 1;
bool operational : 1;
@@ -187,6 +191,7 @@ struct netdev {
bool retry_auth : 1;
bool in_reassoc : 1;
bool privacy : 1;
+ bool cqm_poll_fallback : 1;
};
struct netdev_preauth_state {
@@ -206,6 +211,11 @@ static struct l_genl_family *nl80211;
static struct l_queue *netdev_list;
static struct watchlist netdev_watches;
static bool mac_per_ssid;
+/* Threshold RSSI for roaming to trigger, configurable in main.conf */
+static int LOW_SIGNAL_THRESHOLD;
+static int LOW_SIGNAL_THRESHOLD_5GHZ;
+static int CRITICAL_SIGNAL_THRESHOLD;
+static int CRITICAL_SIGNAL_THRESHOLD_5GHZ;
static unsigned int iov_ie_append(struct iovec *iov,
unsigned int n_iov, unsigned int c,
@@ -642,6 +652,47 @@ static void netdev_set_rssi_level_idx(struct netdev *netdev)
netdev->cur_rssi_level_idx = new_level;
}
+static void netdev_cqm_event_rssi_value(struct netdev *netdev, int rssi_val)
+{
+ bool new_rssi_low;
+ uint8_t prev_rssi_level_idx = netdev->cur_rssi_level_idx;
+ int threshold = netdev->frequency > 4000 ?
+ netdev->low_signal_threshold_5ghz :
+ netdev->low_signal_threshold;
+
+ if (!netdev->connected)
+ return;
+
+ if (rssi_val > 127)
+ rssi_val = 127;
+ else if (rssi_val < -127)
+ rssi_val = -127;
+
+ netdev->cur_rssi = rssi_val;
+
+ if (!netdev->event_filter)
+ return;
+
+ new_rssi_low = rssi_val < threshold;
+ if (netdev->cur_rssi_low != new_rssi_low) {
+ int event = new_rssi_low ?
+ NETDEV_EVENT_RSSI_THRESHOLD_LOW :
+ NETDEV_EVENT_RSSI_THRESHOLD_HIGH;
+
+ netdev->cur_rssi_low = new_rssi_low;
+ netdev->event_filter(netdev, event, NULL, netdev->user_data);
+ }
+
+ if (!netdev->rssi_levels_num)
+ return;
+
+ netdev_set_rssi_level_idx(netdev);
+ if (netdev->cur_rssi_level_idx != prev_rssi_level_idx)
+ netdev->event_filter(netdev, NETDEV_EVENT_RSSI_LEVEL_NOTIFY,
+ &netdev->cur_rssi_level_idx,
+ netdev->user_data);
+}
+
static void netdev_rssi_poll_cb(struct l_genl_msg *msg, void *user_data)
{
struct netdev *netdev = user_data;
@@ -678,11 +729,16 @@ static void netdev_rssi_poll_cb(struct l_genl_msg *msg, void *user_data)
netdev->cur_rssi = info.cur_rssi;
/*
- * Note we don't have to handle LOW_SIGNAL_THRESHOLD here. The
- * CQM single threshold RSSI monitoring should work even if the
- * kernel driver doesn't support multiple thresholds. So the
- * polling only handles the client-supplied threshold list.
+ * If the CMD_SET_CQM call failed RSSI polling was started. In this case
+ * we should behave just like its a CQM event and check both the RSSI
+ * level indexes and the HIGH/LOW thresholds.
*/
+ if (netdev->cqm_poll_fallback) {
+ netdev_cqm_event_rssi_value(netdev, info.cur_rssi);
+ goto done;
+ }
+
+ /* Otherwise just update the level notifications, CQM events work */
netdev_set_rssi_level_idx(netdev);
if (netdev->cur_rssi_level_idx != prev_rssi_level_idx)
netdev->event_filter(netdev, NETDEV_EVENT_RSSI_LEVEL_NOTIFY,
@@ -835,6 +891,10 @@ static void netdev_connect_free(struct netdev *netdev)
l_genl_family_cancel(nl80211, netdev->get_oci_cmd_id);
netdev->get_oci_cmd_id = 0;
}
+
+ /* Reset thresholds back to default */
+ netdev->low_signal_threshold = LOW_SIGNAL_THRESHOLD;
+ netdev->low_signal_threshold_5ghz = LOW_SIGNAL_THRESHOLD_5GHZ;
}
static void netdev_connect_failed(struct netdev *netdev,
@@ -1019,6 +1079,11 @@ static void netdev_free(void *data)
netdev->get_station_cmd_id = 0;
}
+ if (netdev->set_cqm_cmd_id) {
+ l_genl_family_cancel(nl80211, netdev->set_cqm_cmd_id);
+ netdev->set_cqm_cmd_id = 0;
+ }
+
if (netdev->fw_roam_bss)
scan_bss_free(netdev->fw_roam_bss);
@@ -1027,6 +1092,9 @@ static void netdev_free(void *data)
netdev->get_link_cmd_id = 0;
}
+ if (netdev->rssi_poll_timeout)
+ l_timeout_remove(netdev->rssi_poll_timeout);
+
scan_wdev_remove(netdev->wdev_id);
watchlist_destroy(&netdev->station_watches);
@@ -1058,10 +1126,6 @@ struct netdev *netdev_find(int ifindex)
return l_queue_find(netdev_list, netdev_match, L_UINT_TO_PTR(ifindex));
}
-/* Threshold RSSI for roaming to trigger, configurable in main.conf */
-static int LOW_SIGNAL_THRESHOLD;
-static int LOW_SIGNAL_THRESHOLD_5GHZ;
-
static void netdev_cqm_event_rssi_threshold(struct netdev *netdev,
uint32_t rssi_event)
{
@@ -1085,46 +1149,6 @@ static void netdev_cqm_event_rssi_threshold(struct netdev *netdev,
netdev->event_filter(netdev, event, NULL, netdev->user_data);
}
-static void netdev_cqm_event_rssi_value(struct netdev *netdev, int rssi_val)
-{
- bool new_rssi_low;
- uint8_t prev_rssi_level_idx = netdev->cur_rssi_level_idx;
- int threshold = netdev->frequency > 4000 ? LOW_SIGNAL_THRESHOLD_5GHZ :
- LOW_SIGNAL_THRESHOLD;
-
- if (!netdev->connected)
- return;
-
- if (rssi_val > 127)
- rssi_val = 127;
- else if (rssi_val < -127)
- rssi_val = -127;
-
- netdev->cur_rssi = rssi_val;
-
- if (!netdev->event_filter)
- return;
-
- new_rssi_low = rssi_val < threshold;
- if (netdev->cur_rssi_low != new_rssi_low) {
- int event = new_rssi_low ?
- NETDEV_EVENT_RSSI_THRESHOLD_LOW :
- NETDEV_EVENT_RSSI_THRESHOLD_HIGH;
-
- netdev->cur_rssi_low = new_rssi_low;
- netdev->event_filter(netdev, event, NULL, netdev->user_data);
- }
-
- if (!netdev->rssi_levels_num)
- return;
-
- netdev_set_rssi_level_idx(netdev);
- if (netdev->cur_rssi_level_idx != prev_rssi_level_idx)
- netdev->event_filter(netdev, NETDEV_EVENT_RSSI_LEVEL_NOTIFY,
- &netdev->cur_rssi_level_idx,
- netdev->user_data);
-}
-
static void netdev_cqm_event(struct l_genl_msg *msg, struct netdev *netdev)
{
struct l_genl_attr attr;
@@ -1243,8 +1267,7 @@ static void netdev_disconnect_event(struct l_genl_msg *msg,
const void *data;
uint16_t reason_code = 0;
bool disconnect_by_ap = false;
- netdev_event_func_t event_filter;
- void *event_data;
+ enum netdev_event event;
l_debug("");
@@ -1282,19 +1305,11 @@ static void netdev_disconnect_event(struct l_genl_msg *msg,
l_info("Received Deauthentication event, reason: %hu, from_ap: %s",
reason_code, disconnect_by_ap ? "true" : "false");
- event_filter = netdev->event_filter;
- event_data = netdev->user_data;
- netdev_connect_free(netdev);
-
- if (!event_filter)
- return;
+ event = disconnect_by_ap ? NETDEV_EVENT_DISCONNECT_BY_AP :
+ NETDEV_EVENT_DISCONNECT_BY_SME;
- if (disconnect_by_ap)
- event_filter(netdev, NETDEV_EVENT_DISCONNECT_BY_AP,
- &reason_code, event_data);
- else
- event_filter(netdev, NETDEV_EVENT_DISCONNECT_BY_SME,
- &reason_code, event_data);
+ netdev_disconnected(netdev, NETDEV_RESULT_DISCONNECTED,
+ event, reason_code);
}
static void netdev_cmd_disconnect_cb(struct l_genl_msg *msg, void *user_data)
@@ -1328,12 +1343,10 @@ static void netdev_cmd_disconnect_cb(struct l_genl_msg *msg, void *user_data)
static void netdev_deauthenticate_event(struct l_genl_msg *msg,
struct netdev *netdev)
{
- struct l_genl_attr attr;
- uint16_t type, len;
- const void *data;
const struct mmpdu_header *hdr = NULL;
const struct mmpdu_deauthentication *deauth;
uint16_t reason_code;
+ struct iovec iov;
l_debug("");
@@ -1349,17 +1362,11 @@ static void netdev_deauthenticate_event(struct l_genl_msg *msg,
* deauthenticating immediately afterwards
*/
- if (L_WARN_ON(!l_genl_attr_init(&attr, msg)))
+ if (L_WARN_ON(nl80211_parse_attrs(msg, NL80211_ATTR_FRAME, &iov,
+ NL80211_ATTR_UNSPEC) < 0))
return;
- while (l_genl_attr_next(&attr, &type, &len, &data)) {
- switch (type) {
- case NL80211_ATTR_FRAME:
- hdr = mpdu_validate(data, len);
- break;
- }
- }
-
+ hdr = mpdu_validate(iov.iov_base, iov.iov_len);
if (L_WARN_ON(!hdr))
return;
@@ -2430,10 +2437,6 @@ static void netdev_driver_connected(struct netdev *netdev)
{
netdev->connected = true;
- if (netdev->event_filter)
- netdev->event_filter(netdev, NETDEV_EVENT_ASSOCIATING, NULL,
- netdev->user_data);
-
/*
* We register the eapol state machine here, in case the PAE
* socket receives EAPoL packets before the nl80211 socket
@@ -2896,6 +2899,15 @@ static bool kernel_will_retry_auth(uint16_t status_code,
return false;
}
+static void netdev_ensure_eapol_registered(struct netdev *netdev)
+{
+ if (netdev->sm)
+ return;
+
+ netdev->sm = eapol_sm_new(netdev->handshake);
+ eapol_register(netdev->sm);
+}
+
static void netdev_authenticate_event(struct l_genl_msg *msg,
struct netdev *netdev)
{
@@ -2918,6 +2930,10 @@ static void netdev_authenticate_event(struct l_genl_msg *msg,
return;
}
+ if (netdev->event_filter)
+ netdev->event_filter(netdev, NETDEV_EVENT_AUTHENTICATING,
+ NULL, netdev->user_data);
+
/*
* During Fast Transition we use the authenticate event to start the
* reassociation step because the FTE necessary before we can build
@@ -2982,7 +2998,12 @@ static void netdev_authenticate_event(struct l_genl_msg *msg,
NULL, netdev->user_data);
/* We have sent another CMD_AUTHENTICATE / CMD_ASSOCIATE */
- if (ret == 0 || ret == -EAGAIN)
+ if (ret == 0) {
+ netdev_ensure_eapol_registered(netdev);
+ return;
+ }
+
+ if (ret == -EAGAIN)
return;
retry = kernel_will_retry_auth(status_code,
@@ -3034,6 +3055,10 @@ static void netdev_associate_event(struct l_genl_msg *msg,
if (!netdev->connected || netdev->aborting)
return;
+ if (netdev->event_filter)
+ netdev->event_filter(netdev, NETDEV_EVENT_ASSOCIATING,
+ NULL, netdev->user_data);
+
if (!netdev->ap && !netdev->in_ft) {
netdev->associated = true;
netdev->in_reassoc = false;
@@ -3099,9 +3124,6 @@ static void netdev_associate_event(struct l_genl_msg *msg,
netdev->ap = NULL;
}
- netdev->sm = eapol_sm_new(netdev->handshake);
- eapol_register(netdev->sm);
-
/* Just in case this was a retry */
netdev->ignore_connect_event = false;
@@ -3587,8 +3609,9 @@ static struct l_genl_msg *netdev_build_cmd_cqm_rssi_update(
uint32_t hyst = 5;
int thold_count;
int32_t thold_list[levels_num + 2];
- int threshold = netdev->frequency > 4000 ? LOW_SIGNAL_THRESHOLD_5GHZ :
- LOW_SIGNAL_THRESHOLD;
+ int threshold = netdev->frequency > 4000 ?
+ netdev->low_signal_threshold_5ghz :
+ netdev->low_signal_threshold;
if (levels_num == 0) {
thold_list[0] = threshold;
@@ -3636,11 +3659,50 @@ static struct l_genl_msg *netdev_build_cmd_cqm_rssi_update(
static void netdev_cmd_set_cqm_cb(struct l_genl_msg *msg, void *user_data)
{
+ struct netdev *netdev = user_data;
int err = l_genl_msg_get_error(msg);
const char *ext_error;
- if (err >= 0)
+ netdev->set_cqm_cmd_id = 0;
+
+ if (err >= 0) {
+ /*
+ * Looking at some driver code it appears that the -ENOTSUP CQM
+ * failure could be transient. Just in case, reset the fallback
+ * flag if CQM happens to start working again.
+ */
+ if (netdev->cqm_poll_fallback) {
+ l_debug("CMD_SET_CQM succeeded, stop polling fallback");
+
+ if (netdev->rssi_poll_timeout) {
+ l_timeout_remove(netdev->rssi_poll_timeout);
+ netdev->rssi_poll_timeout = NULL;
+ }
+
+ netdev->cqm_poll_fallback = false;
+ }
+
return;
+ }
+
+ /*
+ * Some drivers enable beacon filtering but also use software CQM which
+ * mac80211 detects and returns -ENOTSUP. There is no way to check this
+ * ahead of time so if we see this start polling in order to get RSSI
+ * updates.
+ */
+ if (err == -ENOTSUP) {
+ l_debug("CMD_SET_CQM not supported, falling back to polling");
+ netdev->cqm_poll_fallback = true;
+
+ if (netdev->rssi_poll_timeout)
+ return;
+
+ netdev->rssi_poll_timeout = l_timeout_create(1,
+ netdev_rssi_poll, netdev, NULL);
+
+ return;
+ }
ext_error = l_genl_msg_get_extended_error(msg);
l_error("CMD_SET_CQM failed: %s",
@@ -3653,6 +3715,9 @@ static int netdev_cqm_rssi_update(struct netdev *netdev)
l_debug("");
+ if (netdev->set_cqm_cmd_id)
+ return -EBUSY;
+
if (!wiphy_has_ext_feature(netdev->wiphy,
NL80211_EXT_FEATURE_CQM_RSSI_LIST))
msg = netdev_build_cmd_cqm_rssi_update(netdev, NULL, 0);
@@ -3663,8 +3728,10 @@ static int netdev_cqm_rssi_update(struct netdev *netdev)
if (!msg)
return -EINVAL;
- if (!l_genl_family_send(nl80211, msg, netdev_cmd_set_cqm_cb,
- NULL, NULL)) {
+ netdev->set_cqm_cmd_id = l_genl_family_send(nl80211, msg,
+ netdev_cmd_set_cqm_cb,
+ netdev, NULL);
+ if (!netdev->set_cqm_cmd_id) {
l_genl_msg_unref(msg);
return -EIO;
}
@@ -3672,6 +3739,37 @@ static int netdev_cqm_rssi_update(struct netdev *netdev)
return 0;
}
+static int netdev_set_signal_thresholds(struct netdev *netdev, int threshold,
+ int threshold_5ghz)
+{
+ int current = netdev->frequency > 4000 ?
+ netdev->low_signal_threshold_5ghz :
+ netdev->low_signal_threshold;
+ int new = netdev->frequency > 4000 ? threshold_5ghz : threshold;
+
+ if (current == new)
+ return -EALREADY;
+
+ l_debug("changing low signal threshold to %d", new);
+
+ netdev->low_signal_threshold = threshold;
+ netdev->low_signal_threshold_5ghz = threshold_5ghz;
+
+ return netdev_cqm_rssi_update(netdev);
+}
+
+int netdev_lower_signal_threshold(struct netdev *netdev)
+{
+ return netdev_set_signal_thresholds(netdev, CRITICAL_SIGNAL_THRESHOLD,
+ CRITICAL_SIGNAL_THRESHOLD_5GHZ);
+}
+
+int netdev_raise_signal_threshold(struct netdev *netdev)
+{
+ return netdev_set_signal_thresholds(netdev, LOW_SIGNAL_THRESHOLD,
+ LOW_SIGNAL_THRESHOLD_5GHZ);
+}
+
static bool netdev_connection_work_ready(struct wiphy_radio_work_item *item)
{
struct netdev *netdev = l_container_of(item, struct netdev, work);
@@ -3778,7 +3876,8 @@ static int netdev_handshake_state_setup_connection_type(
case IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA256:
case IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384:
/* FILS has no offload in any upstream driver */
- if (softmac)
+ if (softmac && wiphy_has_ext_feature(wiphy,
+ NL80211_EXT_FEATURE_FILS_STA))
goto softmac;
return -ENOTSUP;
@@ -3828,6 +3927,20 @@ static void netdev_connect_common(struct netdev *netdev,
if (!is_rsn)
goto build_cmd_connect;
+ /* For OWE, always use the CMD_CONNECT path */
+ if (IE_AKM_IS_OWE(hs->akm_suite)) {
+ netdev->owe_sm = owe_sm_new(hs);
+ goto build_cmd_connect;
+ }
+
+ if (IE_AKM_IS_FILS(hs->akm_suite)) {
+ netdev->ap = fils_sm_new(hs, netdev_fils_tx_authenticate,
+ netdev_fils_tx_associate,
+ netdev_get_oci,
+ netdev);
+ goto done;
+ }
+
if (nhs->type != CONNECTION_TYPE_SOFTMAC)
goto build_cmd_connect;
@@ -3850,19 +3963,6 @@ static void netdev_connect_common(struct netdev *netdev,
}
break;
- case IE_RSN_AKM_SUITE_OWE:
- netdev->owe_sm = owe_sm_new(hs);
-
- goto build_cmd_connect;
- case IE_RSN_AKM_SUITE_FILS_SHA256:
- case IE_RSN_AKM_SUITE_FILS_SHA384:
- case IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA256:
- case IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384:
- netdev->ap = fils_sm_new(hs, netdev_fils_tx_authenticate,
- netdev_fils_tx_associate,
- netdev_get_oci,
- netdev);
- break;
default:
build_cmd_connect:
cmd_connect = netdev_build_cmd_connect(netdev, hs, prev_bssid);
@@ -3875,6 +3975,7 @@ build_cmd_connect:
}
}
+done:
netdev->connect_cmd = cmd_connect;
netdev->event_filter = event_filter;
netdev->connect_cb = cb;
@@ -3882,6 +3983,8 @@ build_cmd_connect:
netdev->handshake = hs;
netdev->sm = sm;
netdev->cur_rssi = bss->signal_strength / 100;
+ netdev->low_signal_threshold = LOW_SIGNAL_THRESHOLD;
+ netdev->low_signal_threshold_5ghz = LOW_SIGNAL_THRESHOLD_5GHZ;
if (netdev->rssi_levels_num)
netdev_set_rssi_level_idx(netdev);
@@ -3935,6 +4038,8 @@ int netdev_disconnect(struct netdev *netdev,
{
struct l_genl_msg *disconnect;
bool send_disconnect = true;
+ bool deauth = false;
+ uint8_t aa[6];
if (!(netdev->ifi_flags & IFF_UP))
return -ENETDOWN;
@@ -3953,8 +4058,8 @@ int netdev_disconnect(struct netdev *netdev,
* 1. We do not actually have a connect in progress (work.id
* is zero), then we can bail out early with an error.
* 2. We have sent CMD_CONNECT but not fully connected. The
- * CMD_CONNECT needs to be canceled and a disconnect should
- * be sent.
+ * CMD_CONNECT needs to be canceled and a disconnect or
+ * deauth should be sent.
* 3. Queued up the connect work, but haven't sent CMD_CONNECT
* to the kernel. This case we do not need to send a
* disconnect.
@@ -3969,6 +4074,11 @@ int netdev_disconnect(struct netdev *netdev,
netdev->work.id))
send_disconnect = false;
+ if (netdev->handshake && !netdev->associated) {
+ memcpy(aa, netdev->handshake->aa, 6);
+ deauth = true;
+ }
+
netdev_connect_failed(netdev, NETDEV_RESULT_ABORTED,
MMPDU_REASON_CODE_UNSPECIFIED);
} else {
@@ -3976,8 +4086,14 @@ int netdev_disconnect(struct netdev *netdev,
}
if (send_disconnect) {
- disconnect = nl80211_build_disconnect(netdev->index,
+ if (deauth)
+ disconnect = nl80211_build_deauthenticate(
+ netdev->index, aa,
+ MMPDU_REASON_CODE_DEAUTH_LEAVING);
+ else
+ disconnect = nl80211_build_disconnect(netdev->index,
MMPDU_REASON_CODE_DEAUTH_LEAVING);
+
netdev->disconnect_cmd_id = l_genl_family_send(nl80211,
disconnect, netdev_cmd_disconnect_cb,
netdev, NULL);
@@ -4242,6 +4358,8 @@ int netdev_ft_reassociate(struct netdev *netdev,
netdev->event_filter = event_filter;
netdev->connect_cb = cb;
netdev->user_data = user_data;
+ netdev->low_signal_threshold = LOW_SIGNAL_THRESHOLD;
+ netdev->low_signal_threshold_5ghz = LOW_SIGNAL_THRESHOLD_5GHZ;
/*
* Cancel commands that could be running because of EAPoL activity
@@ -4279,6 +4397,8 @@ int netdev_ft_reassociate(struct netdev *netdev,
if (netdev->sm) {
eapol_sm_free(netdev->sm);
netdev->sm = NULL;
+
+ netdev_ensure_eapol_registered(netdev);
}
msg = netdev_build_cmd_associate_common(netdev);
@@ -5246,8 +5366,10 @@ int netdev_set_rssi_report_levels(struct netdev *netdev, const int8_t *levels,
if (!cmd_set_cqm)
return -EINVAL;
- if (!l_genl_family_send(nl80211, cmd_set_cqm, netdev_cmd_set_cqm_cb,
- NULL, NULL)) {
+ netdev->set_cqm_cmd_id = l_genl_family_send(nl80211, cmd_set_cqm,
+ netdev_cmd_set_cqm_cb,
+ netdev, NULL);
+ if (!netdev->set_cqm_cmd_id) {
l_genl_msg_unref(cmd_set_cqm);
return -EIO;
}
@@ -6080,23 +6202,19 @@ error:
static void netdev_get_link(struct netdev *netdev)
{
- struct ifinfomsg *rtmmsg;
- size_t bufsize;
+ struct ifinfomsg ifi;
+ struct l_netlink_message *nlm =
+ l_netlink_message_new_sized(RTM_GETLINK, 0, sizeof(ifi));
- /* Query interface flags */
- bufsize = NLMSG_ALIGN(sizeof(struct ifinfomsg));
- rtmmsg = l_malloc(bufsize);
- memset(rtmmsg, 0, bufsize);
+ memset(&ifi, 0, sizeof(ifi));
+ ifi.ifi_family = AF_UNSPEC;
+ ifi.ifi_index = netdev->index;
- rtmmsg->ifi_family = AF_UNSPEC;
- rtmmsg->ifi_index = netdev->index;
+ l_netlink_message_add_header(nlm, &ifi, sizeof(ifi));
- netdev->get_link_cmd_id = l_netlink_send(rtnl, RTM_GETLINK, 0, rtmmsg,
- bufsize, netdev_getlink_cb,
+ netdev->get_link_cmd_id = l_netlink_send(rtnl, nlm, netdev_getlink_cb,
netdev, NULL);
L_WARN_ON(netdev->get_link_cmd_id == 0);
-
- l_free(rtmmsg);
}
struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,
@@ -6151,6 +6269,8 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,
l_strlcpy(netdev->name, ifname, IFNAMSIZ);
netdev->wiphy = wiphy;
netdev->pae_over_nl80211 = pae_io == NULL;
+ netdev->low_signal_threshold = LOW_SIGNAL_THRESHOLD;
+ netdev->low_signal_threshold_5ghz = LOW_SIGNAL_THRESHOLD_5GHZ;
if (set_mac)
memcpy(netdev->set_mac_once, set_mac, 6);
@@ -6252,16 +6372,24 @@ static int netdev_init(void)
goto fail_netlink;
}
- if (!l_settings_get_int(settings, "General", "RoamThreshold",
+ if (!l_settings_get_int(settings, NETDEV_ROAM_THRESHOLD,
&LOW_SIGNAL_THRESHOLD))
LOW_SIGNAL_THRESHOLD = -70;
- if (!l_settings_get_int(settings, "General", "RoamThreshold5G",
+ if (!l_settings_get_int(settings, NETDEV_ROAM_THRESHOLD_5G,
&LOW_SIGNAL_THRESHOLD_5GHZ))
LOW_SIGNAL_THRESHOLD_5GHZ = -76;
- rand_addr_str = l_settings_get_value(settings, "General",
- "AddressRandomization");
+ if (!l_settings_get_int(settings, NETDEV_CRITICAL_ROAM_THRESHOLD,
+ &CRITICAL_SIGNAL_THRESHOLD))
+ CRITICAL_SIGNAL_THRESHOLD = -80;
+
+ if (!l_settings_get_int(settings, NETDEV_CRITICAL_ROAM_THRESHOLD_5G,
+ &CRITICAL_SIGNAL_THRESHOLD_5GHZ))
+ CRITICAL_SIGNAL_THRESHOLD_5GHZ = -82;
+
+ rand_addr_str = l_settings_get_value(settings,
+ NETDEV_ADDRESS_RANDOMIZATION);
if (rand_addr_str && !strcmp(rand_addr_str, "network"))
mac_per_ssid = true;
diff --git a/src/netdev.h b/src/netdev.h
@@ -29,6 +29,13 @@ struct eapol_sm;
struct mmpdu_header;
struct diagnostic_station_info;
+#define GENERAL "General"
+#define NETDEV_ADDRESS_RANDOMIZATION GENERAL, "AddressRandomization"
+#define NETDEV_ROAM_THRESHOLD GENERAL, "RoamThreshold"
+#define NETDEV_ROAM_THRESHOLD_5G GENERAL, "RoamThreshold5G"
+#define NETDEV_CRITICAL_ROAM_THRESHOLD GENERAL, "CriticalRoamThreshold"
+#define NETDEV_CRITICAL_ROAM_THRESHOLD_5G GENERAL, "CriticalRoamThreshold5G"
+
enum netdev_result {
NETDEV_RESULT_OK,
NETDEV_RESULT_AUTHENTICATION_FAILED,
@@ -36,6 +43,7 @@ enum netdev_result {
NETDEV_RESULT_HANDSHAKE_FAILED,
NETDEV_RESULT_KEY_SETTING_FAILED,
NETDEV_RESULT_ABORTED,
+ NETDEV_RESULT_DISCONNECTED,
};
enum netdev_event {
@@ -86,6 +94,7 @@ typedef void (*netdev_command_cb_t)(struct netdev *netdev, int result,
* NETDEV_RESULT_HANDSHAKE_FAILED - MMPDU_REASON_CODE
* NETDEV_RESULT_KEY_SETTING_FAILED - unused
* NETDEV_RESULT_ABORTED - unused.
+ * NETDEV_RESULT_DISCONNECTED - MMPDU_REASON_CODE
*/
typedef void (*netdev_connect_cb_t)(struct netdev *netdev,
enum netdev_result result,
@@ -195,6 +204,8 @@ int netdev_neighbor_report_req(struct netdev *netdev,
int netdev_set_rssi_report_levels(struct netdev *netdev, const int8_t *levels,
size_t levels_num);
+int netdev_lower_signal_threshold(struct netdev *netdev);
+int netdev_raise_signal_threshold(struct netdev *netdev);
int netdev_get_station(struct netdev *netdev, const uint8_t *mac,
netdev_get_station_cb_t cb, void *user_data,
diff --git a/src/network.c b/src/network.c
@@ -63,7 +63,7 @@ static uint32_t known_networks_watch;
static uint32_t event_watch;
struct network {
- char ssid[33];
+ char ssid[SSID_MAX_SIZE + 1];
enum security security;
char *object_path;
struct station *station;
@@ -556,8 +556,7 @@ int network_handshake_setup(struct network *network, struct scan_bss *bss,
handshake_state_set_protocol_version(hs, eapol_proto_version);
}
- hs->force_default_ecc_group = network->force_default_ecc_group ||
- bss->force_default_sae_group;
+ hs->force_default_ecc_group = network->force_default_ecc_group;
/*
* The randomization options in the provisioning file are dependent on
@@ -1132,12 +1131,38 @@ bool network_update_known_frequencies(struct network *network)
return true;
}
+const char *__network_path_append_bss(const char *network_path,
+ const struct scan_bss *bss)
+{
+ static char path[256];
+
+ snprintf(path, sizeof(path), "%s/%02x%02x%02x%02x%02x%02x",
+ network_path, MAC_STR(bss->addr));
+
+ return path;
+}
+
+const char *network_bss_get_path(const struct network *network,
+ const struct scan_bss *bss)
+{
+ return __network_path_append_bss(network->object_path, bss);
+}
+
+void network_bss_list_clear(struct network *network)
+{
+ l_queue_destroy(network->bss_list, NULL);
+ network->bss_list = l_queue_new();
+}
+
bool network_bss_add(struct network *network, struct scan_bss *bss)
{
if (!l_queue_insert(network->bss_list, bss, scan_bss_rank_compare,
NULL))
return false;
+ l_dbus_property_changed(dbus_get_bus(), network->object_path,
+ IWD_NETWORK_INTERFACE, "ExtendedServiceSet");
+
/* Done if BSS is not HS20 or we already have network_info set */
if (!bss->hs20_capable)
return true;
@@ -1185,12 +1210,6 @@ bool network_bss_list_isempty(struct network *network)
return l_queue_isempty(network->bss_list);
}
-void network_bss_list_clear(struct network *network)
-{
- l_queue_destroy(network->bss_list, NULL);
- network->bss_list = l_queue_new();
-}
-
struct scan_bss *network_bss_list_pop(struct network *network)
{
return l_queue_pop_head(network->bss_list);
@@ -1866,6 +1885,28 @@ static bool network_property_get_known_network(struct l_dbus *dbus,
return true;
}
+static bool network_property_get_extended_service_set(struct l_dbus *dbus,
+ struct l_dbus_message *message,
+ struct l_dbus_message_builder *builder,
+ void *user_data)
+{
+ struct network *network = user_data;
+ const struct l_queue_entry *e;
+
+ l_dbus_message_builder_enter_array(builder, "o");
+
+ for (e = l_queue_get_entries(network->bss_list); e; e = e->next) {
+ struct scan_bss *bss = e->data;
+ const char *path = network_bss_get_path(network, bss);
+
+ l_dbus_message_builder_append_basic(builder, 'o', path);
+ }
+
+ l_dbus_message_builder_leave_array(builder);
+
+ return true;
+}
+
bool network_register(struct network *network, const char *path)
{
#ifdef HAVE_DBUS
@@ -2172,6 +2213,27 @@ static void setup_network_interface(struct l_dbus_interface *interface)
l_dbus_interface_property(interface, "KnownNetwork", 0, "o",
network_property_get_known_network, NULL);
+
+ l_dbus_interface_property(interface, "ExtendedServiceSet", 0, "ao",
+ network_property_get_extended_service_set, NULL);
+}
+
+static bool network_bss_property_get_address(struct l_dbus *dbus,
+ struct l_dbus_message *message,
+ struct l_dbus_message_builder *builder,
+ void *user_data)
+{
+ struct scan_bss *bss = user_data;
+
+ l_dbus_message_builder_append_basic(builder, 's',
+ util_address_to_string(bss->addr));
+ return true;
+}
+
+static void setup_bss_interface(struct l_dbus_interface *interface)
+{
+ l_dbus_interface_property(interface, "Address", 0, "s",
+ network_bss_property_get_address, NULL);
}
static int network_init(void)
@@ -2183,6 +2245,11 @@ static int network_init(void)
IWD_NETWORK_INTERFACE);
#endif
+ if (!l_dbus_register_interface(dbus_get_bus(), IWD_BSS_INTERFACE,
+ setup_bss_interface, NULL, false))
+ l_error("Unable to register %s interface",
+ IWD_BSS_INTERFACE);
+
known_networks_watch =
known_networks_watch_add(known_networks_changed, NULL, NULL);
@@ -2201,6 +2268,7 @@ static void network_exit(void)
#ifdef HAVE_DBUS
l_dbus_unregister_interface(dbus_get_bus(), IWD_NETWORK_INTERFACE);
+ l_dbus_unregister_interface(dbus_get_bus(), IWD_BSS_INTERFACE);
#endif
}
diff --git a/src/network.h b/src/network.h
@@ -30,6 +30,7 @@ struct network;
struct scan_bss;
struct handshake_state;
struct erp_cache_entry;
+struct scan_freq_set;
void network_connected(struct network *network);
void network_disconnected(struct network *network);
@@ -67,10 +68,16 @@ int network_can_connect_bss(struct network *network,
const struct scan_bss *bss);
int network_autoconnect(struct network *network, struct scan_bss *bss);
void network_connect_failed(struct network *network, bool in_handshake);
+void network_bss_list_clear(struct network *network);
bool network_bss_add(struct network *network, struct scan_bss *bss);
bool network_bss_update(struct network *network, struct scan_bss *bss);
+const char *network_bss_get_path(const struct network *network,
+ const struct scan_bss *bss);
bool network_bss_list_isempty(struct network *network);
-void network_bss_list_clear(struct network *network);
+
+const char *__network_path_append_bss(const char *network_path,
+ const struct scan_bss *bss);
+
struct scan_bss *network_bss_list_pop(struct network *network);
struct scan_bss *network_bss_find_by_addr(struct network *network,
const uint8_t *addr);
diff --git a/src/nl80211util.c b/src/nl80211util.c
@@ -37,6 +37,7 @@
#include "src/util.h"
typedef bool (*attr_handler)(const void *data, uint16_t len, void *o);
+typedef attr_handler (*handler_for_type)(int type);
static bool extract_ifindex(const void *data, uint16_t len, void *o)
{
@@ -131,6 +132,14 @@ static bool extract_iovec(const void *data, uint16_t len, void *o)
return true;
}
+static bool extract_ssid(const void *data, uint16_t len, void *o)
+{
+ if (!len || len > SSID_MAX_SIZE)
+ return false;
+
+ return extract_iovec(data, len, o);
+}
+
static bool extract_nested(const void *data, uint16_t len, void *o)
{
const struct l_genl_attr *outer = data;
@@ -150,7 +159,7 @@ static bool extract_u8(const void *data, uint16_t len, void *o)
return true;
}
-static attr_handler handler_for_type(enum nl80211_attrs type)
+static attr_handler handler_for_nl80211(int type)
{
switch (type) {
case NL80211_ATTR_IFINDEX:
@@ -158,6 +167,7 @@ static attr_handler handler_for_type(enum nl80211_attrs type)
case NL80211_ATTR_WIPHY:
case NL80211_ATTR_IFTYPE:
case NL80211_ATTR_KEY_TYPE:
+ case NL80211_ATTR_SCAN_FLAGS:
return extract_uint32;
case NL80211_ATTR_WDEV:
case NL80211_ATTR_COOKIE:
@@ -168,6 +178,7 @@ static attr_handler handler_for_type(enum nl80211_attrs type)
case NL80211_ATTR_REG_ALPHA2:
return extract_2_chars;
case NL80211_ATTR_MAC:
+ case NL80211_ATTR_BSSID:
return extract_mac;
case NL80211_ATTR_ACK:
return extract_flag;
@@ -177,10 +188,16 @@ static attr_handler handler_for_type(enum nl80211_attrs type)
case NL80211_ATTR_CHANNEL_WIDTH:
case NL80211_ATTR_CENTER_FREQ1:
case NL80211_ATTR_CENTER_FREQ2:
+ case NL80211_ATTR_AKM_SUITES:
+ case NL80211_ATTR_EXTERNAL_AUTH_ACTION:
return extract_uint32;
case NL80211_ATTR_FRAME:
return extract_iovec;
+ case NL80211_ATTR_SSID:
+ return extract_ssid;
case NL80211_ATTR_WIPHY_BANDS:
+ case NL80211_ATTR_SURVEY_INFO:
+ case NL80211_ATTR_KEY:
return extract_nested;
case NL80211_ATTR_KEY_IDX:
return extract_u8;
@@ -191,6 +208,32 @@ static attr_handler handler_for_type(enum nl80211_attrs type)
return NULL;
}
+static attr_handler handler_for_survey_info(int type)
+{
+ switch (type) {
+ case NL80211_SURVEY_INFO_NOISE:
+ return extract_u8;
+ case NL80211_SURVEY_INFO_FREQUENCY:
+ return extract_uint32;
+ default:
+ break;
+ }
+
+ return NULL;
+}
+
+static attr_handler handler_for_key(int type)
+{
+ switch (type) {
+ case NL80211_KEY_SEQ:
+ return extract_iovec;
+ default:
+ break;
+ }
+
+ return NULL;
+}
+
struct attr_entry {
uint16_t type;
void *data;
@@ -198,10 +241,9 @@ struct attr_entry {
bool present : 1;
};
-int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...)
+static int parse_attrs(struct l_genl_attr *attr, handler_for_type handler,
+ int tag, va_list args)
{
- struct l_genl_attr attr;
- va_list args;
struct l_queue *entries;
const struct l_queue_entry *e;
struct attr_entry *entry;
@@ -210,10 +252,6 @@ int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...)
const void *data;
int ret;
- if (!l_genl_attr_init(&attr, msg))
- return -EINVAL;
-
- va_start(args, tag);
entries = l_queue_new();
ret = -ENOSYS;
@@ -222,7 +260,7 @@ int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...)
entry->type = tag;
entry->data = va_arg(args, void *);
- entry->handler = handler_for_type(tag);
+ entry->handler = handler(tag);
l_queue_push_tail(entries, entry);
if (!entry->handler)
@@ -231,9 +269,7 @@ int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...)
tag = va_arg(args, enum nl80211_attrs);
}
- va_end(args);
-
- while (l_genl_attr_next(&attr, &type, &len, &data)) {
+ while (l_genl_attr_next(attr, &type, &len, &data)) {
for (e = l_queue_get_entries(entries); e; e = e->next) {
entry = e->data;
@@ -251,7 +287,7 @@ int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...)
/* For nested attributes use the outer attribute as data */
if (entry->handler == extract_nested)
- data = &attr;
+ data = attr;
if (!entry->handler(data, len, entry->data)) {
ret = -EINVAL;
@@ -284,6 +320,50 @@ done:
return ret;
}
+int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...)
+{
+ struct l_genl_attr attr;
+ va_list args;
+ int ret;
+
+ if (!l_genl_attr_init(&attr, msg))
+ return -EINVAL;
+
+ va_start(args, tag);
+
+ ret = parse_attrs(&attr, handler_for_nl80211, tag, args);
+
+ va_end(args);
+
+ return ret;
+}
+
+int nl80211_parse_nested(struct l_genl_attr *attr, int type, int tag, ...)
+{
+ handler_for_type handler;
+ va_list args;
+ int ret;
+
+ switch (type) {
+ case NL80211_ATTR_SURVEY_INFO:
+ handler = handler_for_survey_info;
+ break;
+ case NL80211_ATTR_KEY:
+ handler = handler_for_key;
+ break;
+ default:
+ return -ENOTSUP;
+ }
+
+ va_start(args, tag);
+
+ ret = parse_attrs(attr, handler, tag, args);
+
+ va_end(args);
+
+ return ret;
+}
+
struct l_genl_msg *nl80211_build_deauthenticate(uint32_t ifindex,
const uint8_t addr[static 6],
uint16_t reason_code)
@@ -517,46 +597,29 @@ struct l_genl_msg *nl80211_build_get_key(uint32_t ifindex, uint8_t key_index)
const void *nl80211_parse_get_key_seq(struct l_genl_msg *msg)
{
- struct l_genl_attr attr, nested;
- uint16_t type, len;
- const void *data;
+ struct l_genl_attr nested;
+ struct iovec iov;
- if (l_genl_msg_get_error(msg) < 0 || !l_genl_attr_init(&attr, msg)) {
+ if (l_genl_msg_get_error(msg) < 0 ||
+ nl80211_parse_attrs(msg, NL80211_ATTR_KEY, &nested,
+ NL80211_ATTR_UNSPEC) < 0) {
l_error("GET_KEY failed for the GTK: %i",
l_genl_msg_get_error(msg));
return NULL;
}
- while (l_genl_attr_next(&attr, &type, &len, &data)) {
- if (type != NL80211_ATTR_KEY)
- continue;
-
- break;
- }
-
- if (type != NL80211_ATTR_KEY || !l_genl_attr_recurse(&attr, &nested)) {
+ if (nl80211_parse_nested(&nested, NL80211_ATTR_KEY, NL80211_KEY_SEQ,
+ &iov, NL80211_ATTR_UNSPEC)) {
l_error("Can't recurse into ATTR_KEY in GET_KEY reply");
return NULL;
}
- while (l_genl_attr_next(&nested, &type, &len, &data)) {
- if (type != NL80211_KEY_SEQ)
- continue;
-
- break;
- }
-
- if (type != NL80211_KEY_SEQ) {
- l_error("KEY_SEQ not returned in GET_KEY reply");
- return NULL;
- }
-
- if (len != 6) {
+ if (iov.iov_len != 6) {
l_error("KEY_SEQ length != 6 in GET_KEY reply");
return NULL;
}
- return data;
+ return iov.iov_base;
}
struct l_genl_msg *nl80211_build_cmd_frame(uint32_t ifindex,
@@ -591,6 +654,21 @@ struct l_genl_msg *nl80211_build_cmd_frame(uint32_t ifindex,
return msg;
}
+struct l_genl_msg *nl80211_build_external_auth(uint32_t ifindex,
+ uint16_t status_code,
+ const uint8_t *ssid, size_t ssid_len,
+ const uint8_t bssid[static 6])
+{
+ struct l_genl_msg *msg = l_genl_msg_new(NL80211_CMD_EXTERNAL_AUTH);
+
+ l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex);
+ l_genl_msg_append_attr(msg, NL80211_ATTR_STATUS_CODE, 2, &status_code);
+ l_genl_msg_append_attr(msg, NL80211_ATTR_SSID, ssid_len, ssid);
+ l_genl_msg_append_attr(msg, NL80211_ATTR_BSSID, 6, bssid);
+
+ return msg;
+}
+
int nl80211_parse_chandef(struct l_genl_msg *msg, struct band_chandef *out)
{
struct band_chandef t;
diff --git a/src/nl80211util.h b/src/nl80211util.h
@@ -28,6 +28,7 @@ struct band_freq_attrs;
struct handshake_state;
int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...);
+int nl80211_parse_nested(struct l_genl_attr *attr, int type, int tag, ...);
struct l_genl_msg *nl80211_build_deauthenticate(uint32_t ifindex,
const uint8_t addr[static 6],
@@ -86,6 +87,11 @@ struct l_genl_msg *nl80211_build_cmd_frame(uint32_t ifindex,
struct iovec *iov,
size_t iov_len);
+struct l_genl_msg *nl80211_build_external_auth(uint32_t ifindex,
+ uint16_t status_code,
+ const uint8_t *ssid, size_t ssid_len,
+ const uint8_t bssid[static 6]);
+
int nl80211_parse_chandef(struct l_genl_msg *msg, struct band_chandef *out);
int nl80211_parse_supported_frequencies(struct l_genl_attr *band_freqs,
struct scan_freq_set *supported_list,
diff --git a/src/p2p.c b/src/p2p.c
@@ -1370,6 +1370,7 @@ static void p2p_netdev_connect_cb(struct netdev *netdev,
case NETDEV_RESULT_ASSOCIATION_FAILED:
case NETDEV_RESULT_HANDSHAKE_FAILED:
case NETDEV_RESULT_KEY_SETTING_FAILED:
+ case NETDEV_RESULT_DISCONNECTED:
/*
* In the AUTHENTICATION_FAILED and ASSOCIATION_FAILED
* cases there's nothing to disconnect. In the
@@ -2314,6 +2315,9 @@ static void p2p_device_go_negotiation_req_cb(const struct mmpdu_header *mpdu,
if (!peer)
return;
+ if (!dev->conn_peer)
+ return;
+
if (body_len < 8)
return;
@@ -2442,7 +2446,7 @@ static void p2p_device_go_negotiation_req_cb(const struct mmpdu_header *mpdu,
memcpy(dev->conn_peer_interface_addr, req_info.intended_interface_addr,
6);
- if (dev->is_go && dev->conn_peer) {
+ if (dev->is_go) {
p2p_set_group_id(dev);
dev->conn_config_delay =
diff --git a/src/p2putil.c b/src/p2putil.c
@@ -2638,7 +2638,7 @@ void p2p_get_random_string(char *buf, size_t len)
{
#define CHARSET "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" \
"0123456789"
- static const int set_size = strlen(CHARSET);
+ const int set_size = strlen(CHARSET);
l_getrandom(buf, len);
diff --git a/src/p2putil.h b/src/p2putil.h
@@ -22,6 +22,7 @@
#include <stdint.h>
+#include "src/defs.h"
#include "src/wscutil.h"
struct l_queue;
@@ -285,7 +286,7 @@ struct p2p_client_info_descriptor {
struct p2p_group_id_attr {
uint8_t device_addr[6];
- char ssid[33];
+ char ssid[SSID_MAX_SIZE + 1];
};
struct p2p_interface_attr {
diff --git a/src/rrm.c b/src/rrm.c
@@ -108,8 +108,8 @@ struct rrm_beacon_req_info {
uint8_t oper_class;
uint8_t channel; /* The single channel provided in request */
uint16_t duration;
- uint8_t bssid[6]; /* Request filtered by BSSID */
- char ssid[33]; /* Request filtered by SSID */
+ uint8_t bssid[6]; /* Request filtered by BSSID */
+ char ssid[SSID_MAX_SIZE + 1]; /* Request filtered by SSID */
bool has_ssid;
uint32_t scan_id;
uint64_t scan_start_time;
diff --git a/src/sae.c b/src/sae.c
@@ -152,39 +152,34 @@ static int sae_choose_next_group(struct sae_sm *sm)
{
const unsigned int *ecc_groups = l_ecc_supported_ike_groups();
bool reset = sm->group_retry >= 0;
+ unsigned int group;
- /*
- * If this is a buggy AP in which group negotiation is broken use the
- * default group 19 and fail if this is a retry.
- */
- if (sm->sae_type == CRYPTO_SAE_LOOPING && sm->force_default_group) {
- if (sm->group_retry != -1) {
- l_warn("Forced default group but was rejected!");
- return -ENOENT;
- }
-
- sae_debug("Forcing default SAE group 19");
+ /* Find the next group in the list */
+ while ((group = ecc_groups[++sm->group_retry])) {
+ /*
+ * Forcing the default group; only choose group 19. If we have
+ * already passed 19 (due to a retry) we will exhaust all other
+ * groups and should fail.
+ */
+ if (sm->force_default_group && group != 19)
+ continue;
- sm->group_retry++;
- sm->group = 19;
+ /* Ensure the PT was derived for this group */
+ if (sm->sae_type == CRYPTO_SAE_HASH_TO_ELEMENT &&
+ !sm->handshake->ecc_sae_pts[sm->group_retry])
+ continue;
- goto get_curve;
+ break;
}
- do {
- sm->group_retry++;
+ if (!group)
+ return -ENOENT;
- if (ecc_groups[sm->group_retry] == 0)
- return -ENOENT;
- } while (sm->sae_type != CRYPTO_SAE_LOOPING &&
- !sm->handshake->ecc_sae_pts[sm->group_retry]);
+ sm->group = group;
if (reset)
sae_reset_state(sm);
- sm->group = ecc_groups[sm->group_retry];
-
-get_curve:
sae_debug("Using group %u", sm->group);
sm->curve = l_ecc_curve_from_ike_group(sm->group);
@@ -682,10 +677,8 @@ static bool sae_send_confirm(struct sae_sm *sm)
return true;
}
-static int sae_process_commit(struct sae_sm *sm, const uint8_t *from,
- const uint8_t *frame, size_t len)
+static int sae_calculate_keys(struct sae_sm *sm)
{
- uint8_t *ptr = (uint8_t *) frame;
unsigned int nbytes = l_ecc_curve_get_scalar_bytes(sm->curve);
enum l_checksum_type hash =
crypto_sae_hash_from_ecc_prime_len(sm->sae_type, nbytes);
@@ -701,39 +694,6 @@ static int sae_process_commit(struct sae_sm *sm, const uint8_t *from,
struct l_ecc_scalar *tmp_scalar;
struct l_ecc_scalar *order;
- ptr += 2;
-
- sm->p_scalar = l_ecc_scalar_new(sm->curve, ptr, nbytes);
- if (!sm->p_scalar) {
- l_error("Server sent invalid P_Scalar during commit");
- return sae_reject(sm, SAE_STATE_COMMITTED,
- MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP);
- }
-
- ptr += nbytes;
-
- sm->p_element = l_ecc_point_from_data(sm->curve, L_ECC_POINT_TYPE_FULL,
- ptr, nbytes * 2);
- if (!sm->p_element) {
- l_error("Server sent invalid P_Element during commit");
- return sae_reject(sm, SAE_STATE_COMMITTED,
- MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP);
- }
-
- /*
- * If they match those sent as part of the protocol instance's own
- * SAE Commit message, the frame shall be silently discarded (because
- * it is evidence of a reflection attack) and the t0 (retransmission)
- * timer shall be set.
- */
- if (l_ecc_scalars_are_equal(sm->p_scalar, sm->scalar) ||
- l_ecc_points_are_equal(sm->p_element, sm->element)) {
- l_warn("peer scalar or element matched own, discarding frame");
- return -ENOMSG;
- }
-
- sm->sc++;
-
/*
* K = scalar-op(rand, (element-op(scalar-op(peer-commit-scalar, PWE),
* PEER-COMMIT-ELEMENT)))
@@ -822,6 +782,54 @@ static int sae_process_commit(struct sae_sm *sm, const uint8_t *from,
/* don't set the handshakes pmkid until confirm is verified */
memcpy(sm->pmkid, tmp, 16);
+ return 0;
+}
+
+
+static int sae_process_commit(struct sae_sm *sm, const uint8_t *from,
+ const uint8_t *frame, size_t len)
+{
+ uint8_t *ptr = (uint8_t *) frame;
+ unsigned int nbytes = l_ecc_curve_get_scalar_bytes(sm->curve);
+ int r;
+
+ ptr += 2;
+
+ sm->p_scalar = l_ecc_scalar_new(sm->curve, ptr, nbytes);
+ if (!sm->p_scalar) {
+ l_error("Server sent invalid P_Scalar during commit");
+ return sae_reject(sm, SAE_STATE_COMMITTED,
+ MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP);
+ }
+
+ ptr += nbytes;
+
+ sm->p_element = l_ecc_point_from_data(sm->curve, L_ECC_POINT_TYPE_FULL,
+ ptr, nbytes * 2);
+ if (!sm->p_element) {
+ l_error("Server sent invalid P_Element during commit");
+ return sae_reject(sm, SAE_STATE_COMMITTED,
+ MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP);
+ }
+
+ /*
+ * If they match those sent as part of the protocol instance's own
+ * SAE Commit message, the frame shall be silently discarded (because
+ * it is evidence of a reflection attack) and the t0 (retransmission)
+ * timer shall be set.
+ */
+ if (l_ecc_scalars_are_equal(sm->p_scalar, sm->scalar) ||
+ l_ecc_points_are_equal(sm->p_element, sm->element)) {
+ l_warn("peer scalar or element matched own, discarding frame");
+ return -ENOMSG;
+ }
+
+ sm->sc++;
+
+ r = sae_calculate_keys(sm);
+ if (r != 0)
+ return r;
+
if (!sae_send_confirm(sm))
return -EPROTO;
@@ -874,9 +882,14 @@ static int sae_process_confirm(struct sae_sm *sm, const uint8_t *from,
sm->state = SAE_STATE_ACCEPTED;
- sae_debug("Sending Associate to "MAC, MAC_STR(sm->handshake->aa));
-
- sm->tx_assoc(sm->user_data);
+ if (!sm->handshake->authenticator) {
+ sae_debug("Sending Associate to "
+ MAC, MAC_STR(sm->handshake->aa));
+ sm->tx_assoc(sm->user_data);
+ } else {
+ if (!sae_send_confirm(sm))
+ return -EPROTO;
+ }
return 0;
}
@@ -1026,16 +1039,37 @@ static int sae_verify_committed(struct sae_sm *sm, uint16_t transaction,
unsigned int skip;
struct ie_tlv_iter iter;
- /*
- * Upon receipt of a Con event...
- * Then the protocol instance checks the value of Sync. If it
- * is greater than dot11RSNASAESync, the protocol instance shall send a
- * Del event to the parent process and transition back to Nothing state.
- * If Sync is not greater than dot11RSNASAESync, the protocol instance
- * shall increment Sync, transmit the last SAE Commit message sent to
- * the peer...
- */
- if (transaction == SAE_STATE_CONFIRMED) {
+ if (sm->handshake->authenticator &&
+ transaction == SAE_STATE_CONFIRMED) {
+ enum l_checksum_type hash =
+ crypto_sae_hash_from_ecc_prime_len(sm->sae_type,
+ l_ecc_curve_get_scalar_bytes(sm->curve));
+ size_t hash_len = l_checksum_digest_length(hash);
+
+ if (len < hash_len + 2) {
+ l_error("SAE: Confirm packet too short");
+ return -EBADMSG;
+ }
+
+ /*
+ * TODO: Add extra functionality such as supporting
+ * anti-clogging tokens and tracking rejected groups. Note
+ * that the cryptographic confirm field value will be checked
+ * at a later point.
+ */
+
+ return 0;
+ } else if (transaction == SAE_STATE_CONFIRMED) {
+ /*
+ * Upon receipt of a Con event...
+ * Then the protocol instance checks the value of Sync. If it
+ * is greater than dot11RSNASAESync, the protocol instance
+ * shall send a Del event to the parent process and transition
+ * back to Nothing state.
+ * If Sync is not greater than dot11RSNASAESync, the protocol
+ * instance shall increment Sync, transmit the last SAE Commit
+ * message sent to the peer...
+ */
if (sm->sync > SAE_SYNC_MAX)
return -ETIMEDOUT;
diff --git a/src/scan.c b/src/scan.c
@@ -132,6 +132,18 @@ struct scan_context {
*/
unsigned int get_fw_scan_cmd_id;
struct wiphy *wiphy;
+
+ unsigned int get_survey_cmd_id;
+};
+
+struct scan_survey {
+ int8_t noise;
+};
+
+struct scan_survey_results {
+ struct scan_survey survey_2_4[14];
+ struct scan_survey survey_5[196];
+ struct scan_survey survey_6[233];
};
struct scan_results {
@@ -140,6 +152,9 @@ struct scan_results {
uint64_t time_stamp;
struct scan_request *sr;
struct scan_freq_set *freqs;
+ struct scan_survey_results survey;
+
+ bool survey_parsed : 1;
};
static bool start_next_scan_request(struct wiphy_radio_work_item *item);
@@ -217,6 +232,9 @@ static void scan_context_free(struct scan_context *sc)
if (sc->get_fw_scan_cmd_id && nl80211)
l_genl_family_cancel(nl80211, sc->get_fw_scan_cmd_id);
+ if (sc->get_survey_cmd_id && nl80211)
+ l_genl_family_cancel(nl80211, sc->get_survey_cmd_id);
+
wiphy_state_watch_remove(sc->wiphy, sc->wiphy_watch_id);
l_free(sc);
@@ -912,7 +930,7 @@ bool scan_cancel(uint64_t wdev_id, uint32_t id)
* Takes care of the following cases:
* 1. If TRIGGER_SCAN is in flight
* 2. TRIGGER_SCAN sent but bounced with -EBUSY
- * 3. Scan request is done but GET_SCAN is still pending
+ * 3. Scan request is done but GET_SCAN/GET_SURVEY is still pending
*
* For case 3, we can easily cancel the command and proceed with the
* other pending requests. For case 1 & 2, the subsequent pending
@@ -927,6 +945,9 @@ bool scan_cancel(uint64_t wdev_id, uint32_t id)
if (sc->start_cmd_id)
l_genl_family_cancel(nl80211, sc->start_cmd_id);
+ if (sc->get_survey_cmd_id)
+ l_genl_family_cancel(nl80211, sc->get_survey_cmd_id);
+
if (sc->get_scan_cmd_id)
l_genl_family_cancel(nl80211, sc->get_scan_cmd_id);
@@ -1242,9 +1263,6 @@ static void scan_parse_vendor_specific(struct scan_bss *bss, const void *data,
bss->cost_flags = cost_flags;
return;
}
-
- if (is_ie_default_sae_group_oui(data, len))
- bss->force_default_sae_group = true;
}
/*
@@ -1307,7 +1325,7 @@ static bool scan_parse_bss_information_elements(struct scan_bss *bss,
switch (tag) {
case IE_TYPE_SSID:
- if (iter.len > 32)
+ if (iter.len > SSID_MAX_SIZE)
return false;
memcpy(bss->ssid, iter.data, iter.len);
@@ -1329,6 +1347,8 @@ static bool scan_parse_bss_information_elements(struct scan_bss *bss,
NULL) < 0)
l_warn("Unable to parse BSS Load IE for "
MAC, MAC_STR(bss->addr));
+ else
+ bss->have_utilization = true;
break;
case IE_TYPE_VENDOR_SPECIFIC:
@@ -1518,7 +1538,6 @@ static struct scan_bss *scan_parse_attr_bss(struct l_genl_attr *attr,
size_t beacon_ies_len;
bss = l_new(struct scan_bss, 1);
- bss->utilization = 127;
bss->source_frame = SCAN_BSS_BEACON;
while (l_genl_attr_next(attr, &type, &len, &data)) {
@@ -1666,6 +1685,8 @@ static void scan_bss_compute_rank(struct scan_bss *bss)
{
static const double RANK_HIGH_UTILIZATION_FACTOR = 0.8;
static const double RANK_LOW_UTILIZATION_FACTOR = 1.2;
+ static const double RANK_HIGH_SNR_FACTOR = 1.2;
+ static const double RANK_LOW_SNR_FACTOR = 0.8;
double rank;
uint32_t irank;
/*
@@ -1687,10 +1708,19 @@ static void scan_bss_compute_rank(struct scan_bss *bss)
rank *= RANK_6G_FACTOR;
/* Rank loaded APs lower and lightly loaded APs higher */
- if (bss->utilization >= 192)
- rank *= RANK_HIGH_UTILIZATION_FACTOR;
- else if (bss->utilization <= 63)
- rank *= RANK_LOW_UTILIZATION_FACTOR;
+ if (bss->have_utilization) {
+ if (bss->utilization >= 192)
+ rank *= RANK_HIGH_UTILIZATION_FACTOR;
+ else if (bss->utilization <= 63)
+ rank *= RANK_LOW_UTILIZATION_FACTOR;
+ }
+
+ if (bss->have_snr) {
+ if (bss->snr <= 15)
+ rank *= RANK_LOW_SNR_FACTOR;
+ else if (bss->snr >= 30)
+ rank *= RANK_HIGH_SNR_FACTOR;
+ }
irank = rank;
@@ -1710,7 +1740,6 @@ struct scan_bss *scan_bss_new_from_probe_req(const struct mmpdu_header *mpdu,
bss = l_new(struct scan_bss, 1);
memcpy(bss->addr, mpdu->address_2, 6);
- bss->utilization = 127;
bss->source_frame = SCAN_BSS_PROBE_REQ;
bss->frequency = frequency;
bss->signal_strength = rssi;
@@ -1827,6 +1856,41 @@ int scan_bss_rank_compare(const void *a, const void *b, void *user_data)
return (bss->rank > new_bss->rank) ? 1 : -1;
}
+static bool scan_survey_get_snr(struct scan_results *results,
+ uint32_t freq, int32_t signal,
+ int8_t *snr)
+{
+ uint8_t channel;
+ enum band_freq band;
+ int8_t noise = 0;
+
+ if (!results->survey_parsed)
+ return false;
+
+ channel = band_freq_to_channel(freq, &band);
+ if (L_WARN_ON(!channel))
+ return false;
+
+ switch (band) {
+ case BAND_FREQ_2_4_GHZ:
+ noise = results->survey.survey_2_4[channel].noise;
+ break;
+ case BAND_FREQ_5_GHZ:
+ noise = results->survey.survey_5[channel].noise;
+ break;
+ case BAND_FREQ_6_GHZ:
+ noise = results->survey.survey_6[channel].noise;
+ break;
+ }
+
+ if (noise) {
+ *snr = signal - noise;
+ return true;
+ }
+
+ return false;
+}
+
static void get_scan_callback(struct l_genl_msg *msg, void *user_data)
{
struct scan_results *results = user_data;
@@ -1852,6 +1916,10 @@ static void get_scan_callback(struct l_genl_msg *msg, void *user_data)
bss->time_stamp = results->time_stamp -
seen_ms_ago * L_USEC_PER_MSEC;
+ bss->have_snr = scan_survey_get_snr(results, bss->frequency,
+ bss->signal_strength / 100,
+ &bss->snr);
+
scan_bss_compute_rank(bss);
l_queue_insert(results->bss_list, bss, scan_bss_rank_compare, NULL);
}
@@ -1928,11 +1996,91 @@ static void get_scan_done(void *user)
l_free(results);
}
+static void get_survey_callback(struct l_genl_msg *msg, void *user_data)
+{
+ struct scan_results *results = user_data;
+ struct scan_survey_results *survey = &results->survey;
+ struct l_genl_attr attr;
+ uint32_t freq;
+ int8_t noise;
+ uint8_t channel;
+ enum band_freq band;
+
+ if (nl80211_parse_attrs(msg, NL80211_ATTR_SURVEY_INFO, &attr,
+ NL80211_ATTR_UNSPEC) < 0)
+ return;
+
+ if (nl80211_parse_nested(&attr, NL80211_ATTR_SURVEY_INFO,
+ NL80211_SURVEY_INFO_FREQUENCY, &freq,
+ NL80211_SURVEY_INFO_NOISE, &noise,
+ NL80211_ATTR_UNSPEC) < 0)
+ return;
+
+ channel = band_freq_to_channel(freq, &band);
+ if (!channel)
+ return;
+
+ /* At least one frequency was surveyed */
+ results->survey_parsed = true;
+
+ switch (band) {
+ case BAND_FREQ_2_4_GHZ:
+ survey->survey_2_4[channel].noise = noise;
+ break;
+ case BAND_FREQ_5_GHZ:
+ survey->survey_5[channel].noise = noise;
+ break;
+ case BAND_FREQ_6_GHZ:
+ survey->survey_6[channel].noise = noise;
+ break;
+ }
+}
+
+static void get_results(struct scan_results *results)
+{
+ struct l_genl_msg *scan_msg;
+
+ scan_msg = l_genl_msg_new_sized(NL80211_CMD_GET_SCAN, 8);
+
+ l_genl_msg_append_attr(scan_msg, NL80211_ATTR_WDEV, 8,
+ &results->sc->wdev_id);
+ results->sc->get_scan_cmd_id = l_genl_family_dump(nl80211, scan_msg,
+ get_scan_callback,
+ results, get_scan_done);
+}
+
+static void get_survey_done(void *user_data)
+{
+ struct scan_results *results = user_data;
+ struct scan_context *sc = results->sc;
+
+ sc->get_survey_cmd_id = 0;
+
+ if (!results->sr->canceled)
+ get_results(results);
+ else
+ get_scan_done(user_data);
+}
+
+static bool scan_survey(struct scan_results *results)
+{
+ struct scan_context *sc = results->sc;
+ struct l_genl_msg *survey_msg;
+
+ survey_msg = l_genl_msg_new(NL80211_CMD_GET_SURVEY);
+ l_genl_msg_append_attr(survey_msg, NL80211_ATTR_WDEV, 8,
+ &sc->wdev_id);
+ sc->get_survey_cmd_id = l_genl_family_dump(nl80211, survey_msg,
+ get_survey_callback, results,
+ get_survey_done);
+
+ return sc->get_survey_cmd_id != 0;
+}
+
static void scan_get_results(struct scan_context *sc, struct scan_request *sr,
struct scan_freq_set *freqs)
{
struct scan_results *results;
- struct l_genl_msg *scan_msg;
results = l_new(struct scan_results, 1);
results->sc = sc;
@@ -1941,13 +2089,13 @@ static void scan_get_results(struct scan_context *sc, struct scan_request *sr,
results->bss_list = l_queue_new();
results->freqs = freqs;
- scan_msg = l_genl_msg_new_sized(NL80211_CMD_GET_SCAN, 8);
+ /* If there is no scan request (external scan), just get the results */
+ if (sr && scan_survey(results))
+ return;
+ else if (sr)
+ l_warn("failed to start a scan survey");
- l_genl_msg_append_attr(scan_msg, NL80211_ATTR_WDEV, 8,
- &sc->wdev_id);
- sc->get_scan_cmd_id = l_genl_family_dump(nl80211, scan_msg,
- get_scan_callback,
- results, get_scan_done);
+ get_results(results);
}
static void scan_wiphy_watch(struct wiphy *wiphy,
@@ -1974,6 +2122,22 @@ static void scan_wiphy_watch(struct wiphy *wiphy,
return;
/*
+ * If the regdom update finished with GET_SCAN/GET_SURVEY in flight
+ * don't try and get the results again and allow those calls to finish.
+ * For the non-6ghz case this has no downside as the results should not
+ * differ.
+ *
+ * If 6ghz was enabled by this regdom update there is still not much we
+ * can do since the scan itself is already completed. Appending to the
+ * command list won't do anything.
+ *
+ * TODO: Handle the 6ghz case by checking for this case in get_scan_done
+ * and continuing to iterate the sr->cmds array.
+ */
+ if (sc->get_scan_cmd_id || sc->get_survey_cmd_id)
+ return;
+
+ /*
* This update did not allow 6GHz, or the original request was
* not expecting 6GHz. The periodic scan should now be ended.
*/
@@ -2024,16 +2188,14 @@ static struct scan_context *scan_context_new(uint64_t wdev_id)
static bool scan_parse_flush_flag_from_msg(struct l_genl_msg *msg)
{
- struct l_genl_attr attr;
- uint16_t type, len;
- const void *data;
+ uint32_t flags;
- if (!l_genl_attr_init(&attr, msg))
+ if (nl80211_parse_attrs(msg, NL80211_ATTR_SCAN_FLAGS, &flags,
+ NL80211_ATTR_UNSPEC) < 0)
return false;
- while (l_genl_attr_next(&attr, &type, &len, &data))
- if (type == NL80211_SCAN_FLAG_FLUSH)
- return true;
+ if (flags & NL80211_SCAN_FLAG_FLUSH)
+ return true;
return false;
}
@@ -2347,28 +2509,24 @@ double scan_get_band_rank_modifier(enum band_freq band)
{
const struct l_settings *config = iwd_get_config();
double modifier;
- char *str, *str_legacy;
+ char *str;
switch (band) {
case BAND_FREQ_2_4_GHZ:
str = "BandModifier2_4GHz";
- str_legacy = "BandModifier2_4Ghz";
break;
case BAND_FREQ_5_GHZ:
str = "BandModifier5GHz";
- str_legacy = "BandModifier5Ghz";
break;
case BAND_FREQ_6_GHZ:
str = "BandModifier6GHz";
- str_legacy = "BandModifier6Ghz";
break;
default:
l_warn("Unhandled band %u", band);
return 0.0;
}
- if (!l_settings_get_double(config, "Rank", str, &modifier) &&
- !l_settings_get_double(config, "Rank", str_legacy, &modifier))
+ if (!l_settings_get_double(config, "Rank", str, &modifier))
modifier = 1.0;
return modifier;
diff --git a/src/scan.h b/src/scan.h
@@ -20,6 +20,8 @@
*
*/
+#include "src/defs.h"
+
struct scan_freq_set;
struct ie_rsn_info;
struct ie_owe_transition_info;
@@ -62,7 +64,7 @@ struct scan_bss {
};
struct ie_owe_transition_info *owe_trans;
uint8_t mde[3];
- uint8_t ssid[32];
+ uint8_t ssid[SSID_MAX_SIZE];
uint8_t ssid_len;
uint8_t utilization;
uint8_t cc[3];
@@ -75,6 +77,7 @@ struct scan_bss {
uint64_t parent_tsf;
uint8_t *wfd; /* Concatenated WFD IEs */
ssize_t wfd_size; /* Size of Concatenated WFD IEs */
+ int8_t snr;
bool mde_present : 1;
bool cc_present : 1;
bool cap_rm_neighbor_report : 1;
@@ -82,7 +85,6 @@ struct scan_bss {
bool vht_capable : 1;
bool anqp_capable : 1;
bool hs20_capable : 1;
- bool force_default_sae_group : 1;
bool proxy_arp : 1;
bool hs20_dgaf_disable : 1;
uint8_t cost_level : 3;
@@ -90,6 +92,8 @@ struct scan_bss {
bool dpp_configurator : 1;
bool sae_pw_id_used : 1;
bool sae_pw_id_exclusive : 1;
+ bool have_snr : 1;
+ bool have_utilization : 1;
};
struct scan_parameters {
diff --git a/src/station.c b/src/station.c
@@ -102,7 +102,6 @@ struct station {
struct l_queue *owe_hidden_scan_ids;
/* Roaming related members */
- struct timespec roam_min_time;
struct l_timeout *roam_trigger_timeout;
uint32_t roam_scan_id;
uint8_t preauth_bssid[6];
@@ -128,6 +127,10 @@ struct station {
uint64_t last_roam_scan;
+ struct l_queue *affinities;
+ unsigned int affinity_watch;
+ char *affinity_client;
+
bool preparing_roam : 1;
bool roam_scan_full : 1;
bool signal_low : 1;
@@ -341,10 +344,16 @@ static void network_free(void *data)
network_remove(network, -ESHUTDOWN);
}
+struct process_network_data {
+ struct station *station;
+ const struct scan_freq_set *freqs;
+};
+
static bool process_network(const void *key, void *data, void *user_data)
{
struct network *network = data;
- struct station *station = user_data;
+ struct process_network_data *process_data = user_data;
+ struct station *station = process_data->station;
if (!network_bss_list_isempty(network)) {
bool connected = network == station->connected_network;
@@ -404,6 +413,97 @@ static int bss_signal_strength_compare(const void *a, const void *b, void *user)
return (bss->signal_strength > new_bss->signal_strength) ? 1 : -1;
}
+static void station_print_scan_bss(const struct scan_bss *bss)
+{
+ uint32_t kbps100 = DIV_ROUND_CLOSEST(bss->data_rate, 100000);
+ char optional[64] = {0};
+ char *ptr = optional;
+
+ if (bss->have_snr)
+ ptr += sprintf(ptr, ", snr: %d", bss->snr);
+
+ if (bss->have_utilization)
+ ptr += sprintf(ptr, ", load: %u/255", bss->utilization);
+
+ l_debug("Processing BSS '%s' with SSID: %s, freq: %u, rank: %u, "
+ "strength: %i, data_rate: %u.%u%s",
+ util_address_to_string(bss->addr),
+ util_ssid_to_utf8(bss->ssid_len, bss->ssid),
+ bss->frequency, bss->rank, bss->signal_strength,
+ kbps100 / 10, kbps100 % 10,
+ optional);
+}
+
+static const char *station_get_bss_path(struct station *station,
+ struct scan_bss *bss)
+{
+ enum security security;
+ char ssid[33];
+ const char *network_path;
+
+ memcpy(ssid, bss->ssid, bss->ssid_len);
+ ssid[bss->ssid_len] = '\0';
+
+ if (scan_bss_get_security(bss, &security) < 0)
+ return NULL;
+
+ network_path = iwd_network_get_path(station, ssid, security);
+ if (!network_path)
+ return NULL;
+
+ return __network_path_append_bss(network_path, bss);
+}
+
+static bool match_bss_path(const void *data, const void *user_data)
+{
+ const char *path1 = data;
+ const char *path2 = user_data;
+
+ return !strcmp(path1, path2);
+}
+
+static bool station_unregister_bss(struct station *station,
+ struct scan_bss *bss)
+{
+ const char *path = station_get_bss_path(station, bss);
+
+ if (L_WARN_ON(!path))
+ return false;
+
+ l_queue_remove_if(station->affinities, match_bss_path, path);
+
+ return l_dbus_unregister_object(dbus_get_bus(), path);
+}
+
+static bool station_register_bss(struct network *network, struct scan_bss *bss)
+{
+ struct scan_bss *old;
+ const char *path = __network_path_append_bss(network_get_path(network),
+ bss);
+
+ if (L_WARN_ON(!path))
+ return false;
+
+ /*
+ * If we find this path in the object tree update the data to the new
+ * scan_bss pointer, as this one will be freed soon.
+ */
+ old = l_dbus_object_get_data(dbus_get_bus(), path, IWD_BSS_INTERFACE);
+ if (old)
+ return l_dbus_object_set_data(dbus_get_bus(), path,
+ IWD_BSS_INTERFACE, bss);
+
+ if (!l_dbus_object_add_interface(dbus_get_bus(), path,
+ IWD_BSS_INTERFACE, bss))
+ return false;
+
+ if (!l_dbus_object_add_interface(dbus_get_bus(), path,
+ L_DBUS_INTERFACE_PROPERTIES, bss))
+ return false;
+
+ return true;
+}
+
/*
* Returns the network object the BSS was added to or NULL if ignored.
*/
@@ -413,15 +513,9 @@ static struct network *station_add_seen_bss(struct station *station,
struct network *network;
enum security security;
const char *path;
- char ssid[33];
- uint32_t kbps100 = DIV_ROUND_CLOSEST(bss->data_rate, 100000);
+ char ssid[SSID_MAX_SIZE + 1];
- l_debug("Processing BSS '%s' with SSID: %s, freq: %u, rank: %u, "
- "strength: %i, data_rate: %u.%u",
- util_address_to_string(bss->addr),
- util_ssid_to_utf8(bss->ssid_len, bss->ssid),
- bss->frequency, bss->rank, bss->signal_strength,
- kbps100 / 10, kbps100 % 10);
+ station_print_scan_bss(bss);
if (util_ssid_is_hidden(bss->ssid_len, bss->ssid)) {
l_debug("BSS has hidden SSID");
@@ -497,6 +591,7 @@ static struct network *station_add_seen_bss(struct station *station,
}
network_bss_add(network, bss);
+ station_register_bss(network, bss);
return network;
}
@@ -519,6 +614,7 @@ struct bss_expiration_data {
struct scan_bss *connected_bss;
uint64_t now;
const struct scan_freq_set *freqs;
+ struct station *station;
};
#define SCAN_RESULT_BSS_RETENTION_TIME (30 * 1000000)
@@ -540,7 +636,9 @@ static bool bss_free_if_expired(void *data, void *user_data)
bss->time_stamp + SCAN_RESULT_BSS_RETENTION_TIME))
return false;
- bss_free(bss);
+ station_unregister_bss(expiration_data->station, bss);
+
+ scan_bss_free(bss);
return true;
}
@@ -552,6 +650,7 @@ static void station_bss_list_remove_expired_bsses(struct station *station,
.now = l_time_now(),
.connected_bss = station->connected_bss,
.freqs = freqs,
+ .station = station,
};
l_queue_foreach_remove(station->bss_list, bss_free_if_expired, &data);
@@ -799,6 +898,7 @@ static bool station_owe_transition_results(int err, struct l_queue *bss_list,
l_queue_push_tail(station->bss_list, bss);
network_bss_add(network, bss);
+ station_register_bss(network, bss);
continue;
@@ -926,6 +1026,7 @@ void station_set_scan_results(struct station *station,
{
const struct l_queue_entry *bss_entry;
struct network *network;
+ struct process_network_data data;
l_queue_foreach_remove(new_bss_list, bss_free_if_ssid_not_utf8, NULL);
@@ -949,7 +1050,7 @@ void station_set_scan_results(struct station *station,
if (old_bss == station->connected_bss)
station->connected_bss = new_bss;
- bss_free(old_bss);
+ scan_bss_free(old_bss);
continue;
}
@@ -976,12 +1077,17 @@ void station_set_scan_results(struct station *station,
if (!scan_freq_set_contains(freqs, bss->frequency))
continue;
+ station_register_bss(network, bss);
+
station_start_anqp(station, network, bss);
}
station->bss_list = new_bss_list;
- l_hashmap_foreach_remove(station->networks, process_network, station);
+ data.station = station;
+ data.freqs = freqs;
+
+ l_hashmap_foreach_remove(station->networks, process_network, &data);
station->autoconnect_can_start = trigger_autoconnect;
station_autoconnect_start(station);
@@ -1002,6 +1108,7 @@ static void station_handshake_event(struct handshake_state *hs,
switch (event) {
case HANDSHAKE_EVENT_STARTED:
l_debug("Handshaking");
+ station_debug_event(station, "handshake-started");
break;
case HANDSHAKE_EVENT_SETTING_KEYS:
l_debug("Setting keys");
@@ -1607,6 +1714,8 @@ static void station_enter_state(struct station *station,
#ifdef HAVE_DBUS
l_dbus_property_changed(dbus, netdev_get_path(station->netdev),
IWD_STATION_INTERFACE, "ConnectedNetwork");
+ l_dbus_property_changed(dbus, netdev_get_path(station->netdev),
+ IWD_STATION_INTERFACE, "ConnectedAccessPoint");
l_dbus_property_changed(dbus,
network_get_path(station->connected_network),
IWD_NETWORK_INTERFACE, "Connected");
@@ -1654,6 +1763,13 @@ static void station_enter_state(struct station *station,
station_set_evict_nocarrier(station, true);
station_set_drop_neighbor_discovery(station, false);
station_set_drop_unicast_l2_multicast(station, false);
+
+ if (station->affinity_watch) {
+ l_dbus_remove_watch(dbus_get_bus(),
+ station->affinity_watch);
+ station->affinity_watch = 0;
+ }
+
break;
case STATION_STATE_DISCONNECTING:
case STATION_STATE_NETCONFIG:
@@ -1661,6 +1777,15 @@ static void station_enter_state(struct station *station,
case STATION_STATE_ROAMING:
case STATION_STATE_FT_ROAMING:
case STATION_STATE_FW_ROAMING:
+ l_dbus_property_changed(dbus, netdev_get_path(station->netdev),
+ IWD_STATION_INTERFACE, "ConnectedAccessPoint");
+
+ if (station->affinity_watch) {
+ l_dbus_remove_watch(dbus_get_bus(),
+ station->affinity_watch);
+ station->affinity_watch = 0;
+ }
+
station_set_evict_nocarrier(station, false);
break;
}
@@ -1720,6 +1845,11 @@ bool station_set_autoconnect(struct station *station, bool autoconnect)
return true;
}
+bool station_get_autoconnect(struct station *station)
+{
+ return station->autoconnect;
+}
+
static void station_roam_state_clear(struct station *station)
{
l_debug("%u", netdev_get_ifindex(station->netdev));
@@ -1729,7 +1859,6 @@ static void station_roam_state_clear(struct station *station)
station->preparing_roam = false;
station->roam_scan_full = false;
station->signal_low = false;
- station->roam_min_time.tv_sec = 0;
station->netconfig_after_roam = false;
station->last_roam_scan = 0;
@@ -1779,6 +1908,8 @@ static void station_reset_connection_state(struct station *station)
#ifdef HAVE_DBUS
l_dbus_property_changed(dbus, netdev_get_path(station->netdev),
IWD_STATION_INTERFACE, "ConnectedNetwork");
+ l_dbus_property_changed(dbus, netdev_get_path(station->netdev),
+ IWD_STATION_INTERFACE, "ConnectedAccessPoint");
l_dbus_property_changed(dbus, network_get_path(network),
IWD_NETWORK_INTERFACE, "Connected");
l_dbus_object_remove_interface(dbus, netdev_get_path(station->netdev),
@@ -1814,36 +1945,87 @@ static void station_roam_timeout_rearm(struct station *station, int seconds);
static int station_roam_scan(struct station *station,
struct scan_freq_set *freq_set);
-static uint32_t station_freq_from_neighbor_report(const uint8_t *country,
- struct ie_neighbor_report_info *info, enum band_freq *out_band)
+static bool is_freq_band_supported(struct station *station, uint32_t freq,
+ enum band_freq band)
+{
+ const struct band_freq_attrs *attr;
+
+ if (!(band & wiphy_get_supported_bands(station->wiphy)))
+ return false;
+
+ /* Skip if frequency is not supported or disabled */
+ attr = wiphy_get_frequency_info(station->wiphy, freq);
+ if (!attr || attr->disabled)
+ return false;
+
+ return true;
+}
+
+/*
+ * Some Cisco APs report all operating class values as 0 in the Neighbor
+ * Report Responses. Historically we could be very sure what band the
+ * channel was associated with since there was no overlap between 2.4
+ * and 5GHz. With the addition of 6GHz this becomes more difficult as
+ * the 6GHz channel range overlaps both 2.4 and 5ghz.
+ *
+ * To cover all 3 bands, calculate a frequency for each and see what sticks.
+ */
+static void station_parse_zero_oper_class(struct station *station,
+ struct ie_neighbor_report_info *info,
+ struct scan_freq_set *freq_set)
+{
+ uint32_t freq_2g;
+ uint32_t freq_5g;
+ uint32_t freq_6g;
+
+ freq_2g = band_channel_to_freq(info->channel_num, BAND_FREQ_2_4_GHZ);
+ freq_5g = band_channel_to_freq(info->channel_num, BAND_FREQ_5_GHZ);
+ freq_6g = band_channel_to_freq(info->channel_num, BAND_FREQ_6_GHZ);
+
+ if (!freq_2g && !freq_5g && !freq_6g) {
+ l_debug("Ignored: 0 oper class with an unusual "
+ "channel number %u", info->channel_num);
+ return;
+ }
+
+ if (freq_2g && is_freq_band_supported(station, freq_2g,
+ BAND_FREQ_2_4_GHZ)) {
+ l_debug("adding frequency %u from invalid oper class", freq_2g);
+ scan_freq_set_add(freq_set, freq_2g);
+ }
+
+ if (freq_5g && is_freq_band_supported(station, freq_5g,
+ BAND_FREQ_5_GHZ)) {
+ l_debug("adding frequency %u from invalid oper class", freq_5g);
+ scan_freq_set_add(freq_set, freq_5g);
+ }
+
+ if (freq_6g && is_freq_band_supported(station, freq_6g,
+ BAND_FREQ_6_GHZ)) {
+ l_debug("adding frequency %u from invalid oper class", freq_6g);
+ scan_freq_set_add(freq_set, freq_6g);
+ }
+}
+
+static void station_add_neighbor_report_freqs(struct station *station,
+ struct ie_neighbor_report_info *info,
+ struct scan_freq_set *freq_set)
{
enum band_freq band;
uint32_t freq;
- if (info->oper_class == 0) {
- /*
- * Some Cisco APs report all operating class values as 0
- * in the Neighbor Report Responses. Work around this by
- * using the most likely operating class for the channel
- * number as the 2.4GHz and 5GHz bands happen to mostly
- * use channels in two disjoint ranges.
- */
- if (info->channel_num >= 1 && info->channel_num <= 14)
- band = BAND_FREQ_2_4_GHZ;
- else if (info->channel_num >= 36 && info->channel_num <= 169)
- band = BAND_FREQ_5_GHZ;
- else {
- l_debug("Ignored: 0 oper class with an unusual "
- "channel number");
+ const uint8_t *country = station->connected_bss->cc_present ?
+ station->connected_bss->cc : NULL;
- return 0;
- }
+ if (info->oper_class == 0) {
+ station_parse_zero_oper_class(station, info, freq_set);
+ return;
} else {
band = band_oper_class_to_band(country, info->oper_class);
if (!band) {
l_debug("Ignored: unsupported oper class");
- return 0;
+ return;
}
}
@@ -1851,13 +2033,14 @@ static uint32_t station_freq_from_neighbor_report(const uint8_t *country,
if (!freq) {
l_debug("Ignored: unsupported channel");
- return 0;
+ return;
}
- if (out_band)
- *out_band = band;
+ /* Skip if the band/frequency is not supported */
+ if (!is_freq_band_supported(station, freq, band))
+ return;
- return freq;
+ scan_freq_set_add(freq_set, freq);
}
static void parse_neighbor_report(struct station *station,
@@ -1866,9 +2049,8 @@ static void parse_neighbor_report(struct station *station,
struct scan_freq_set **set)
{
struct ie_tlv_iter iter;
- int count_md = 0, count_no_md = 0;
struct scan_freq_set *freq_set_md, *freq_set_no_md;
- uint32_t current_freq = 0;
+ uint32_t current_freq = station->connected_bss->frequency;
struct handshake_state *hs = netdev_get_handshake(station->netdev);
freq_set_md = scan_freq_set_new();
@@ -1879,10 +2061,6 @@ static void parse_neighbor_report(struct station *station,
/* First see if any of the reports contain the MD bit set */
while (ie_tlv_iter_next(&iter)) {
struct ie_neighbor_report_info info;
- uint32_t freq;
- enum band_freq band;
- const uint8_t *cc = NULL;
- const struct band_freq_attrs *attr;
if (ie_tlv_iter_get_tag(&iter) != IE_TYPE_NEIGHBOR_REPORT)
continue;
@@ -1896,22 +2074,6 @@ static void parse_neighbor_report(struct station *station,
(int) info.channel_num, (int) info.oper_class,
info.md ? "MD set" : "MD not set");
- if (station->connected_bss->cc_present)
- cc = station->connected_bss->cc;
-
- freq = station_freq_from_neighbor_report(cc, &info, &band);
- if (!freq)
- continue;
-
- /* Skip if the band is not supported */
- if (!(band & wiphy_get_supported_bands(station->wiphy)))
- continue;
-
- /* Skip if frequency is not supported or disabled */
- attr = wiphy_get_frequency_info(station->wiphy, freq);
- if (!attr || attr->disabled)
- continue;
-
if (!memcmp(info.addr,
station->connected_bss->addr, ETH_ALEN)) {
/*
@@ -1920,26 +2082,14 @@ static void parse_neighbor_report(struct station *station,
* its channel because it may still be the best ranked
* or the only visible AP.
*/
- current_freq = freq;
-
continue;
}
- /* Add the frequency to one of the lists */
- if (info.md && hs->mde) {
- scan_freq_set_add(freq_set_md, freq);
-
- count_md += 1;
- } else {
- scan_freq_set_add(freq_set_no_md, freq);
-
- count_no_md += 1;
- }
+ station_add_neighbor_report_freqs(station, &info,
+ info.md && hs->mde ?
+ freq_set_md : freq_set_no_md);
}
- if (!current_freq)
- current_freq = station->connected_bss->frequency;
-
/*
* If there are neighbor reports with the MD bit set then the bit
* is probably valid so scan only the frequencies of the neighbors
@@ -1961,11 +2111,11 @@ static void parse_neighbor_report(struct station *station,
* automatically fall back to the non-FT candidates and then to
* full scan.
*/
- if (count_md) {
+ if (!scan_freq_set_isempty(freq_set_md)) {
scan_freq_set_add(freq_set_md, current_freq);
*set = freq_set_md;
scan_freq_set_free(freq_set_no_md);
- } else if (count_no_md) {
+ } else if (!scan_freq_set_isempty(freq_set_no_md)) {
scan_freq_set_add(freq_set_no_md, current_freq);
*set = freq_set_no_md;
scan_freq_set_free(freq_set_md);
@@ -1997,7 +2147,8 @@ static void station_early_neighbor_report_cb(struct netdev *netdev, int err,
&station->roam_freqs);
}
-static bool station_can_fast_transition(struct handshake_state *hs,
+static bool station_can_fast_transition(struct station *station,
+ struct handshake_state *hs,
struct scan_bss *bss)
{
uint16_t mdid;
@@ -2025,6 +2176,16 @@ static bool station_can_fast_transition(struct handshake_state *hs,
return false;
}
+ /*
+ * FT-over-Air in its current form relies on CMD_REMAIN_ON_CHANNEL. Some
+ * drivers do not support this so only allow over-DS if this is the case
+ */
+ if (!(hs->mde[4] & 1) &&
+ !wiphy_supports_cmd_offchannel(station->wiphy)) {
+ l_debug("FT-over-Air needs offchannel, using reassociation");
+ return false;
+ }
+
return true;
}
@@ -2448,6 +2609,8 @@ static bool station_fast_transition(struct station *station,
goto done;
}
+ station_debug_event(station, "ft-authenticating");
+
if (station->connected_bss->frequency == bss->frequency) {
ft_authenticate_onchannel(netdev_get_ifindex(station->netdev),
bss);
@@ -2486,7 +2649,7 @@ static bool station_try_next_transition(struct station *station,
station->ap_directed_roaming = false;
/* Can we use Fast Transition? */
- if (station_can_fast_transition(hs, bss) && !no_ft)
+ if (station_can_fast_transition(station, hs, bss) && !no_ft)
return station_fast_transition(station, bss);
/* Non-FT transition */
@@ -2601,6 +2764,7 @@ static void station_update_roam_bss(struct station *station,
l_queue_remove_if(station->bss_list, bss_match, bss);
network_bss_update(network, bss);
+ station_register_bss(network, bss);
l_queue_push_tail(station->bss_list, bss);
if (old)
@@ -2669,15 +2833,9 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list,
while ((bss = l_queue_pop_head(bss_list))) {
double rank;
- uint32_t kbps100 = DIV_ROUND_CLOSEST(bss->data_rate, 100000);
struct roam_bss *rbss;
- l_debug("Processing BSS '%s' with SSID: %s, freq: %u, rank: %u,"
- " strength: %i, data_rate: %u.%u",
- util_address_to_string(bss->addr),
- util_ssid_to_utf8(bss->ssid_len, bss->ssid),
- bss->frequency, bss->rank, bss->signal_strength,
- kbps100 / 10, kbps100 % 10);
+ station_print_scan_bss(bss);
/* Skip the BSS we are connected to */
if (!memcmp(bss->addr, station->connected_bss->addr, 6))
@@ -2936,20 +3094,33 @@ static void station_roam_trigger_cb(struct l_timeout *timeout, void *user_data)
static void station_roam_timeout_rearm(struct station *station, int seconds)
{
- struct timespec now, min_timeout;
+ uint64_t remaining;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ if (!station->roam_trigger_timeout)
+ goto new_timeout;
- min_timeout = now;
- min_timeout.tv_sec += seconds;
+ /* If we cant get the remaining time just create a new timer */
+ if (L_WARN_ON(!l_timeout_remaining(station->roam_trigger_timeout,
+ &remaining))) {
+ l_timeout_remove(station->roam_trigger_timeout);
+ goto new_timeout;
+ }
- if (station->roam_min_time.tv_sec < min_timeout.tv_sec ||
- (station->roam_min_time.tv_sec == min_timeout.tv_sec &&
- station->roam_min_time.tv_nsec < min_timeout.tv_nsec))
- station->roam_min_time = min_timeout;
+ /* Our current timeout is less than the rearm, keep current */
+ if (l_time_before(remaining, seconds * L_USEC_PER_SEC)) {
+ l_debug("Keeping current roam timeout of %" PRIx64 " seconds",
+ l_time_to_secs(remaining));
+ return;
+ }
- seconds = station->roam_min_time.tv_sec - now.tv_sec +
- (station->roam_min_time.tv_nsec > now.tv_nsec ? 1 : 0);
+ l_debug("Rescheduling roam timeout from %" PRIx64" to %d seconds",
+ l_time_to_secs(remaining), seconds);
+ l_timeout_modify(station->roam_trigger_timeout, seconds);
+
+ return;
+
+new_timeout:
+ l_debug("Arming new roam timer for %d seconds", seconds);
station->roam_trigger_timeout =
l_timeout_create(seconds, station_roam_trigger_cb,
@@ -3107,7 +3278,6 @@ static void station_ok_rssi(struct station *station)
station->roam_trigger_timeout = NULL;
station->signal_low = false;
- station->roam_min_time.tv_sec = 0;
}
static void station_event_roamed(struct station *station, struct scan_bss *new)
@@ -3115,6 +3285,7 @@ static void station_event_roamed(struct station *station, struct scan_bss *new)
struct scan_bss *stale;
network_bss_update(station->connected_network, new);
+ station_register_bss(station->connected_network, new);
/* Remove new BSS if it exists in past scan results */
stale = l_queue_remove_if(station->bss_list, bss_match, new);
@@ -3314,6 +3485,7 @@ static void station_connect_cb(struct netdev *netdev, enum netdev_result result,
{
struct station *station = user_data;
bool continue_autoconnect;
+ uint16_t reason = MMPDU_REASON_CODE_UNSPECIFIED;
l_debug("%u, result: %d", netdev_get_ifindex(station->netdev), result);
@@ -3322,9 +3494,23 @@ static void station_connect_cb(struct netdev *netdev, enum netdev_result result,
blacklist_remove_bss(station->connected_bss->addr);
station_connect_ok(station);
return;
+ case NETDEV_RESULT_DISCONNECTED:
+ reason = l_get_u16(event_data);
+
+ iwd_notice(IWD_NOTICE_DISCONNECT_INFO, "reason: %u", reason);
+
+ /* Disconnected while connecting */
+ network_blacklist_add(station->connected_network,
+ station->connected_bss);
+ if (station_try_next_bss(station))
+ return;
+
+ break;
case NETDEV_RESULT_HANDSHAKE_FAILED:
+ reason = l_get_u16(event_data);
+
/* reason code in this case */
- if (station_retry_with_reason(station, l_get_u16(event_data)))
+ if (station_retry_with_reason(station, reason))
return;
break;
@@ -3356,7 +3542,13 @@ static void station_connect_cb(struct netdev *netdev, enum netdev_result result,
continue_autoconnect = station->state == STATION_STATE_CONNECTING_AUTO;
if (station->state == STATION_STATE_CONNECTING) {
- bool during_eapol = result == NETDEV_RESULT_HANDSHAKE_FAILED;
+ /*
+ * Either a handshake failure (generated internally) or a 4-way
+ * handshake timeout should trigger the PSK to be asked for
+ * again. Set during_eapol accordingly.
+ */
+ bool during_eapol = result == NETDEV_RESULT_HANDSHAKE_FAILED ||
+ reason == MMPDU_REASON_CODE_4WAY_HANDSHAKE_TIMEOUT;
network_connect_failed(station->connected_network,
during_eapol);
}
@@ -3385,17 +3577,12 @@ static void station_disconnect_event(struct station *station, void *event_data)
/*
* If we're connecting, AP deauthenticated us, most likely because
* we provided the wrong password or otherwise failed authentication
- * during the handshaking phase. Treat this as a connection failure
+ * during the handshaking phase. Connection failures should be handled
+ * within station_connect_cb/station_reassociate_cb apart from netconfig
+ * and FW roams.
*/
switch (station->state) {
- case STATION_STATE_CONNECTING:
- case STATION_STATE_CONNECTING_AUTO:
- station_connect_cb(station->netdev,
- NETDEV_RESULT_HANDSHAKE_FAILED,
- event_data, station);
- return;
case STATION_STATE_CONNECTED:
- case STATION_STATE_FT_ROAMING:
case STATION_STATE_FW_ROAMING:
case STATION_STATE_NETCONFIG:
iwd_notice(IWD_NOTICE_DISCONNECT_INFO, "reason: %u",
@@ -3436,14 +3623,17 @@ static void station_packets_lost(struct station *station, uint32_t num_pkts)
l_debug("Too many roam attempts in %u second timeframe, "
"delaying roam", LOSS_ROAM_RATE_LIMIT);
- if (station->roam_trigger_timeout)
- return;
-
station_roam_timeout_rearm(station, LOSS_ROAM_RATE_LIMIT);
return;
}
+ if (station->roam_trigger_timeout) {
+ l_debug("canceling roam timer to roam immediately");
+ l_timeout_remove(station->roam_trigger_timeout);
+ station->roam_trigger_timeout = NULL;
+ }
+
station_start_roam(station);
}
@@ -3456,9 +3646,6 @@ static void station_beacon_lost(struct station *station)
station_debug_event(station, "beacon-loss-roam");
- if (station->roam_trigger_timeout)
- return;
-
station_roam_timeout_rearm(station, LOSS_ROAM_RATE_LIMIT);
}
@@ -3491,10 +3678,10 @@ static void station_netdev_event(struct netdev *netdev, enum netdev_event event,
switch (event) {
case NETDEV_EVENT_AUTHENTICATING:
- l_debug("Authenticating");
+ station_debug_event(station, "authenticating");
break;
case NETDEV_EVENT_ASSOCIATING:
- l_debug("Associating");
+ station_debug_event(station, "associating");
break;
case NETDEV_EVENT_DISCONNECT_BY_AP:
case NETDEV_EVENT_DISCONNECT_BY_SME:
@@ -3806,7 +3993,7 @@ static struct l_dbus_message *station_dbus_connect_hidden_network(
if (!l_dbus_message_get_arguments(message, "s", &ssid))
return dbus_error_invalid_args(message);
- if (strlen(ssid) > 32)
+ if (strlen(ssid) > SSID_MAX_SIZE)
return dbus_error_invalid_args(message);
if (known_networks_find(ssid, SECURITY_PSK) ||
@@ -4339,6 +4526,23 @@ static bool station_property_get_connected_network(struct l_dbus *dbus,
return true;
}
+static bool station_property_get_connected_ap(struct l_dbus *dbus,
+ struct l_dbus_message *message,
+ struct l_dbus_message_builder *builder,
+ void *user_data)
+{
+ struct station *station = user_data;
+
+ if (!station->connected_network)
+ return false;
+
+ l_dbus_message_builder_append_basic(builder, 'o',
+ network_bss_get_path(station->connected_network,
+ station->connected_bss));
+
+ return true;
+}
+
static bool station_property_get_scanning(struct l_dbus *dbus,
struct l_dbus_message *message,
struct l_dbus_message_builder *builder,
@@ -4395,6 +4599,162 @@ static bool station_property_get_state(struct l_dbus *dbus,
return true;
}
+static bool station_property_get_affinities(struct l_dbus *dbus,
+ struct l_dbus_message *message,
+ struct l_dbus_message_builder *builder,
+ void *user_data)
+{
+ struct station *station = user_data;
+ const struct l_queue_entry *e;
+
+ if (!station->connected_network)
+ return false;
+
+ l_dbus_message_builder_enter_array(builder, "o");
+
+ for (e = l_queue_get_entries(station->affinities); e; e = e->next) {
+ const char *path = e->data;
+
+ l_dbus_message_builder_append_basic(builder, 'o', path);
+ }
+
+ l_dbus_message_builder_leave_array(builder);
+
+ return true;
+}
+
+static void station_affinity_disconnected_cb(struct l_dbus *dbus,
+ void *user_data)
+{
+ struct station *station = user_data;
+
+ l_dbus_remove_watch(dbus_get_bus(), station->affinity_watch);
+
+ l_debug("client that set affinity has disconnected");
+
+ /* The client who set the affinity disconnected, raise the threshold */
+ netdev_raise_signal_threshold(station->netdev);
+}
+
+static void station_affinity_watch_destroy(void *user_data)
+{
+ struct station *station = user_data;
+ bool empty = l_queue_length(station->affinities) == 0;
+
+ station->affinity_watch = 0;
+
+ l_free(station->affinity_client);
+ station->affinity_client = NULL;
+
+ l_queue_clear(station->affinities, l_free);
+
+ if (!empty)
+ l_dbus_property_changed(dbus_get_bus(),
+ netdev_get_path(station->netdev),
+ IWD_STATION_INTERFACE, "Affinities");
+}
+
+static struct l_dbus_message *station_property_set_affinities(
+ struct l_dbus *dbus,
+ struct l_dbus_message *message,
+ struct l_dbus_message_iter *new_value,
+ l_dbus_property_complete_cb_t complete,
+ void *user_data)
+{
+ struct station *station = user_data;
+ struct l_dbus_message_iter array;
+ const char *sender = l_dbus_message_get_sender(message);
+ char *old_path = l_queue_peek_head(station->affinities);
+ const char *new_path = NULL;
+ struct scan_bss *new_bss = NULL;
+ struct scan_bss *old_bss = NULL;
+ bool lower_threshold = false;
+
+ if (!station->connected_network)
+ return dbus_error_not_connected(message);
+
+ if (wiphy_supports_firmware_roam(station->wiphy))
+ return dbus_error_not_supported(message);
+
+ if (station->affinity_watch &&
+ strcmp(station->affinity_client, sender)) {
+ l_warn("Only one client may manage Affinities property");
+ return dbus_error_permission_denied(message);
+ }
+
+ if (!l_dbus_message_iter_get_variant(new_value, "ao", &array))
+ return dbus_error_invalid_args(message);
+
+ /* Get first entry, there should be only one */
+ l_dbus_message_iter_next_entry(&array, &new_path);
+
+ if (l_dbus_message_iter_next_entry(&array, &new_path))
+ return dbus_error_invalid_args(message);
+
+ old_path = l_queue_peek_head(station->affinities);
+ if (old_path)
+ old_bss = l_dbus_object_get_data(dbus_get_bus(),
+ old_path, IWD_BSS_INTERFACE);
+ if (new_path)
+ new_bss = l_dbus_object_get_data(dbus,
+ new_path, IWD_BSS_INTERFACE);
+
+ /* Either the same path, or both arrays are empty */
+ if (old_bss == new_bss) {
+ complete(dbus, message, NULL);
+ return NULL;
+ }
+
+ /*
+ * TODO: For now only allow the affinities array to contain a single
+ * value, the connected BSS path. Any other values will be
+ * rejected. This could change in the future.
+ */
+ if (new_bss && new_bss != station->connected_bss)
+ return dbus_error_invalid_args(message);
+
+ l_queue_clear(station->affinities, l_free);
+
+ /*
+ * Adding a new BSS, create a watch for this DBus client so if it
+ * disconnects we can clear the affinities list
+ */
+ if (new_path) {
+ l_queue_push_head(station->affinities, l_strdup(new_path));
+
+ lower_threshold = true;
+
+ if (!station->affinity_watch) {
+ station->affinity_client = l_strdup(sender);
+ station->affinity_watch = l_dbus_add_disconnect_watch(
+ dbus, sender,
+ station_affinity_disconnected_cb,
+ station,
+ station_affinity_watch_destroy);
+ }
+ /* The list was cleared, remove the watch */
+ } else if (station->affinity_watch)
+ l_dbus_remove_watch(dbus, station->affinity_watch);
+
+ /*
+ * If affinity was set to the current BSS, lower the roam threshold. If
+ * the connected BSS was not in the list raise the signal threshold.
+ * The threshold may already be raised, in which case netdev will detect
+ * this and do nothing.
+ */
+ if (lower_threshold)
+ netdev_lower_signal_threshold(station->netdev);
+ else
+ netdev_raise_signal_threshold(station->netdev);
+
+ complete(dbus, message, NULL);
+
+ l_dbus_property_changed(dbus, netdev_get_path(station->netdev),
+ IWD_STATION_INTERFACE, "Affinities");
+
+ return NULL;
+}
+
void station_foreach(station_foreach_func_t func, void *user_data)
{
const struct l_queue_entry *entry;
@@ -4631,6 +4991,7 @@ static struct station *station_create(struct netdev *netdev)
station_set_autoconnect(station, autoconnect);
station->roam_bss_list = l_queue_new();
+ station->affinities = l_queue_new();
return station;
}
@@ -4723,6 +5084,11 @@ static void station_free(struct station *station)
l_queue_destroy(station->roam_bss_list, l_free);
+ if (station->affinity_watch)
+ l_dbus_remove_watch(dbus_get_bus(), station->affinity_watch);
+
+ l_queue_destroy(station->affinities, l_free);
+
l_free(station);
}
@@ -4752,10 +5118,16 @@ static void station_setup_interface(struct l_dbus_interface *interface)
l_dbus_interface_property(interface, "ConnectedNetwork", 0, "o",
station_property_get_connected_network,
NULL);
+ l_dbus_interface_property(interface, "ConnectedAccessPoint", 0, "o",
+ station_property_get_connected_ap,
+ NULL);
l_dbus_interface_property(interface, "Scanning", 0, "b",
station_property_get_scanning, NULL);
l_dbus_interface_property(interface, "State", 0, "s",
station_property_get_state, NULL);
+ l_dbus_interface_property(interface, "Affinities", 0, "ao",
+ station_property_get_affinities,
+ station_property_set_affinities);
}
static void station_destroy_interface(void *user_data)
diff --git a/src/station.h b/src/station.h
@@ -88,6 +88,7 @@ uint32_t station_add_event_watch(station_event_watch_func_t func,
void station_remove_event_watch(uint32_t id);
bool station_set_autoconnect(struct station *station, bool autoconnect);
+bool station_get_autoconnect(struct station *station);
int __station_connect_network(struct station *station, struct network *network,
struct scan_bss *bss, enum station_state state);
diff --git a/src/storage.c b/src/storage.c
@@ -45,6 +45,7 @@
#include "ell/useful.h"
#include "src/missing.h"
+#include "src/defs.h"
#include "src/common.h"
#include "src/storage.h"
#include "src/crypto.h"
@@ -315,7 +316,7 @@ const char *storage_network_ssid_from_path(const char *path,
return NULL;
if (filename[0] != '=') {
- if (end == filename || end - filename > 32)
+ if (end == filename || end - filename > SSID_MAX_SIZE)
return NULL;
for (c = filename; c < end; c++)
diff --git a/src/udev.c b/src/udev.c
@@ -0,0 +1,285 @@
+/*
+ *
+ * Wireless daemon for Linux
+ *
+ * Copyright (C) 2024 Intel Corporation. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <linux/netlink.h>
+#include <linux/filter.h>
+#include <ell/ell.h>
+
+#include "src/module.h"
+
+static void receive_props(const void *buf, uint32_t len)
+{
+ const char *action = NULL;
+ const char *interface = NULL;
+ const char *ifindex = NULL;
+
+ while (len > 0) {
+ const char *s = buf;
+ size_t l = strlen(s);
+ const char *t;
+
+ if (l < 2)
+ break;
+
+ t = strchr(s, '=');
+ if (t) {
+ size_t p = t - s;
+
+ if (!strncmp(s, "ACTION", p))
+ action = t + 1;
+ else if (!strncmp(s, "INTERFACE", p))
+ interface = t + 1;
+ else if (!strncmp(s, "IFINDEX", p))
+ ifindex = t + 1;
+ }
+
+ buf += l + 1;
+ len -= l + 1;
+ }
+
+ if (action && !strcmp(action, "add"))
+ l_info("udev interface=%s ifindex=%s", interface, ifindex);
+}
+
+static struct l_io *udev_io;
+
+static int create_socket(uint32_t *pid)
+{
+ struct sockaddr_nl addr;
+ socklen_t addrlen = sizeof(addr);
+ int fd, pktinfo = 1;
+
+ fd = socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK,
+ NETLINK_KOBJECT_UEVENT);
+ if (fd < 0)
+ return -1;
+
+ memset(&addr, 0, sizeof(addr));
+ addr.nl_family = AF_NETLINK;
+
+ if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+ close(fd);
+ return -1;
+ }
+
+ if (getsockname(fd, (struct sockaddr *) &addr, &addrlen) < 0) {
+ close(fd);
+ return -1;
+ }
+
+ if (setsockopt(fd, SOL_NETLINK, NETLINK_PKTINFO,
+ &pktinfo, sizeof(pktinfo)) < 0) {
+ close(fd);
+ return -1;
+ }
+
+ if (pid)
+ *pid = addr.nl_pid;
+
+ return fd;
+}
+
+static struct sock_filter subsys_filter[] = {
+ { 0x20, 0, 0, 0x00000008 }, /* ldw #magic */
+ { 0x15, 0, 3, 0xfeedcafe }, /* jne #feedcafe, drop */
+ { 0x20, 0, 0, 0x00000018 }, /* ldw #subsys_hash */
+ { 0x15, 0, 1, 0xa74d3cc8 }, /* jne #net, drop */
+ { 0x06, 0, 0, 0xffffffff }, /* keep: ret #-1 */
+ { 0x06, 0, 0, 0000000000 }, /* drop: ret #0 */
+};
+
+static const struct sock_fprog subsys_fprog = { .len = 6,
+ .filter = subsys_filter };
+
+static bool attach_filter(struct l_io *io)
+{
+ int fd;
+
+ fd = l_io_get_fd(io);
+ if (fd < 0)
+ return false;
+
+ if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER,
+ &subsys_fprog, sizeof(subsys_fprog)) < 0)
+ return false;
+
+ return true;
+}
+
+static bool add_membership(struct l_io *io, uint32_t group)
+{
+ int fd, value = group;
+
+ fd = l_io_get_fd(io);
+ if (fd < 0)
+ return false;
+
+ if (setsockopt(fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP,
+ &value, sizeof(value)) < 0)
+ return false;
+
+ return true;
+}
+
+static bool drop_membership(struct l_io *io, uint32_t group)
+{
+ int fd, value = group;
+
+ fd = l_io_get_fd(io);
+ if (fd < 0)
+ return false;
+
+ if (setsockopt(fd, SOL_NETLINK, NETLINK_DROP_MEMBERSHIP,
+ &value, sizeof(value)) < 0)
+ return false;
+
+ return true;
+}
+
+static const uint8_t LIBUDEV_PREFIX[8] = { "libudev" };
+static uint32_t LIBUDEV_MAGIC = 0xfeedcafe;
+
+struct udev_hdr {
+ char prefix[8];
+ uint32_t magic;
+ uint32_t hdr_size;
+ uint32_t props_off;
+ uint32_t props_len;
+ uint32_t flt_subsys_hash;
+ uint32_t flt_devtype_hash;
+ uint32_t flt_tag_bloom_hi;
+ uint32_t flt_tag_bloom_lo;
+};
+
+static void receive_msg(const void *buf, uint32_t len)
+{
+ const struct udev_hdr *hdr = buf;
+
+ if (len < sizeof(struct udev_hdr))
+ return;
+
+ if (memcmp(hdr->prefix, LIBUDEV_PREFIX, 8))
+ return;
+
+ if (L_BE32_TO_CPU(hdr->magic) != LIBUDEV_MAGIC)
+ return;
+
+ if (hdr->hdr_size > len)
+ return;
+
+ if (hdr->props_off + hdr->props_len != len)
+ return;
+
+ receive_props(buf + hdr->props_off, hdr->props_len);
+}
+
+enum {
+ GROUP_NONE,
+ GROUP_KERNEL,
+ GROUP_UDEV,
+};
+
+static bool can_read_data(struct l_io *io, void *user_data)
+{
+ struct cmsghdr *cmsg;
+ struct msghdr msg;
+ struct iovec iov;
+ unsigned char buffer[4096];
+ unsigned char control[32];
+ uint32_t group = GROUP_NONE;
+ ssize_t len;
+ int fd;
+
+ memset(buffer, 0, sizeof(buffer));
+ memset(control, 0, sizeof(control));
+
+ fd = l_io_get_fd(io);
+
+ iov.iov_base = buffer;
+ iov.iov_len = sizeof(buffer);
+
+ memset(&msg, 0, sizeof(msg));
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_control = control;
+ msg.msg_controllen = sizeof(control);
+
+ len = recvmsg(fd, &msg, 0);
+ if (len < 0)
+ return false;
+
+ for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
+ cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+ struct nl_pktinfo *pktinfo;
+
+ if (cmsg->cmsg_level != SOL_NETLINK)
+ continue;
+
+ if (cmsg->cmsg_type != NETLINK_PKTINFO)
+ continue;
+
+ pktinfo = (void *) CMSG_DATA(cmsg);
+ group = pktinfo->group;
+ }
+
+ if (group == GROUP_UDEV)
+ receive_msg(buffer, len);
+
+ return true;
+}
+
+static int udev_init(void)
+{
+ int fd;
+
+ l_debug("");
+
+ fd = create_socket(NULL);
+ if (fd < 0)
+ return -EIO;
+
+ udev_io = l_io_new(fd);
+ l_io_set_close_on_destroy(udev_io, true);
+ l_io_set_read_handler(udev_io, can_read_data, NULL, NULL);
+ attach_filter(udev_io);
+ add_membership(udev_io, GROUP_UDEV);
+
+ return 0;
+}
+
+static void udev_exit(void)
+{
+ l_debug("");
+
+ drop_membership(udev_io, GROUP_UDEV);
+ l_io_destroy(udev_io);
+}
+
+IWD_MODULE(udev, udev_init, udev_exit);
+IWD_MODULE_DEPENDS(udev, netdev);
diff --git a/src/util.c b/src/util.c
@@ -34,6 +34,7 @@
#include <ell/ell.h>
#include "ell/useful.h"
+#include "src/defs.h"
#include "src/util.h"
#include "src/band.h"
@@ -45,7 +46,7 @@ const char *util_ssid_to_utf8(size_t len, const uint8_t *ssid)
memset(buf, 0, sizeof(buf));
- if (len > 32)
+ if (len > SSID_MAX_SIZE)
goto no_ssid;
while (i < len && !ssid[i])
@@ -84,7 +85,7 @@ no_ssid:
bool util_ssid_is_utf8(size_t len, const uint8_t *ssid)
{
- if (len > 32)
+ if (len > SSID_MAX_SIZE)
return false;
return l_utf8_validate((const char *)ssid, len, NULL);
diff --git a/src/watchlist.c b/src/watchlist.c
@@ -48,16 +48,6 @@ static void watchlist_item_free(struct watchlist *watchlist,
l_free(item);
}
-struct watchlist *watchlist_new(const struct watchlist_ops *ops)
-{
- struct watchlist *watchlist;
-
- watchlist = l_new(struct watchlist, 1);
- watchlist->items = l_queue_new();
- watchlist->ops = ops;
- return watchlist;
-}
-
void watchlist_init(struct watchlist *watchlist,
const struct watchlist_ops *ops)
{
@@ -137,13 +127,6 @@ void watchlist_destroy(struct watchlist *watchlist)
watchlist->items = NULL;
}
-void watchlist_free(struct watchlist *watchlist)
-{
- watchlist_clear(watchlist);
- l_queue_destroy(watchlist->items, NULL);
- l_free(watchlist);
-}
-
void __watchlist_prune_stale(struct watchlist *watchlist)
{
struct watchlist_item *item;
diff --git a/src/watchlist.h b/src/watchlist.h
@@ -42,7 +42,6 @@ struct watchlist {
const struct watchlist_ops *ops;
};
-struct watchlist *watchlist_new(const struct watchlist_ops *ops);
void watchlist_init(struct watchlist *watchlist,
const struct watchlist_ops *ops);
unsigned int watchlist_add(struct watchlist *watchlist, void *notify,
@@ -54,7 +53,6 @@ unsigned int watchlist_link(struct watchlist *watchlist,
watchlist_item_destroy_func_t destroy);
bool watchlist_remove(struct watchlist *watchlist, unsigned int id);
void watchlist_destroy(struct watchlist *watchlist);
-void watchlist_free(struct watchlist *watchlist);
void __watchlist_prune_stale(struct watchlist *watchlist);
diff --git a/src/wiphy.c b/src/wiphy.c
@@ -149,6 +149,7 @@ struct wiphy {
bool self_managed : 1;
bool ap_probe_resp_offload : 1;
bool supports_uapsd : 1;
+ bool supports_cmd_offchannel : 1;
};
static struct l_queue *wiphy_list = NULL;
@@ -276,7 +277,8 @@ enum ie_rsn_akm_suite wiphy_select_akm(struct wiphy *wiphy,
* for fast transitions. Otherwise use SHA256 version if present.
*/
if (security == SECURITY_8021X) {
- if (wiphy_has_feature(wiphy, NL80211_EXT_FEATURE_FILS_STA) &&
+ if (wiphy_has_ext_feature(wiphy, NL80211_EXT_FEATURE_FILS_STA) &&
+ wiphy->support_cmds_auth_assoc &&
fils_capable_hint) {
if ((info->akm_suites &
IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384) &&
@@ -938,6 +940,11 @@ bool wiphy_supports_uapsd(const struct wiphy *wiphy)
return wiphy->supports_uapsd;
}
+bool wiphy_supports_cmd_offchannel(const struct wiphy *wiphy)
+{
+ return wiphy->supports_cmd_offchannel;
+}
+
const uint8_t *wiphy_get_ht_capabilities(const struct wiphy *wiphy,
enum band_freq band,
size_t *size)
@@ -989,6 +996,7 @@ int wiphy_estimate_data_rate(struct wiphy *wiphy,
const void *he_capabilities = NULL;
const struct band *bandp;
enum band_freq band;
+ int ret;
if (band_freq_to_channel(bss->frequency, &band) == 0)
return -ENOTSUP;
@@ -1005,7 +1013,7 @@ int wiphy_estimate_data_rate(struct wiphy *wiphy,
switch (tag) {
case IE_TYPE_SUPPORTED_RATES:
if (iter.len > 8)
- return -EBADMSG;
+ continue;
supported_rates = iter.data - 2;
break;
@@ -1014,31 +1022,34 @@ int wiphy_estimate_data_rate(struct wiphy *wiphy,
break;
case IE_TYPE_HT_CAPABILITIES:
if (iter.len != 26)
- return -EBADMSG;
+ continue;
ht_capabilities = iter.data - 2;
break;
case IE_TYPE_HT_OPERATION:
if (iter.len != 22)
- return -EBADMSG;
+ continue;
ht_operation = iter.data - 2;
break;
case IE_TYPE_VHT_CAPABILITIES:
if (iter.len != 12)
- return -EBADMSG;
+ continue;
vht_capabilities = iter.data - 2;
break;
case IE_TYPE_VHT_OPERATION:
if (iter.len != 5)
- return -EBADMSG;
+ continue;
vht_operation = iter.data - 2;
break;
case IE_TYPE_HE_CAPABILITIES:
- if (!ie_validate_he_capabilities(iter.data, iter.len))
- return -EBADMSG;
+ if (!ie_validate_he_capabilities(iter.data, iter.len)) {
+ l_warn("invalid HE capabilities for "MAC,
+ MAC_STR(bss->addr));
+ continue;
+ }
he_capabilities = iter.data;
break;
@@ -1047,26 +1058,39 @@ int wiphy_estimate_data_rate(struct wiphy *wiphy,
}
}
- if (!band_estimate_he_rx_rate(bandp, he_capabilities,
+ ret = band_estimate_he_rx_rate(bandp, he_capabilities,
bss->signal_strength / 100,
- out_data_rate))
+ out_data_rate);
+ if (!ret)
return 0;
+ else if (ret != -ENOTSUP && ret != -ENETUNREACH)
+ l_warn("error parsing HE capabilities");
- if (!band_estimate_vht_rx_rate(bandp, vht_capabilities, vht_operation,
+ ret = band_estimate_vht_rx_rate(bandp, vht_capabilities, vht_operation,
ht_capabilities, ht_operation,
bss->signal_strength / 100,
- out_data_rate))
+ out_data_rate);
+ if (!ret)
return 0;
+ else if (ret != -ENOTSUP && ret != -ENETUNREACH)
+ l_warn("error parsing VHT capabilities");
- if (!band_estimate_ht_rx_rate(bandp, ht_capabilities, ht_operation,
+ ret = band_estimate_ht_rx_rate(bandp, ht_capabilities, ht_operation,
bss->signal_strength / 100,
- out_data_rate))
+ out_data_rate);
+ if (!ret)
return 0;
+ else if (ret != -ENOTSUP && ret != -ENETUNREACH)
+ l_warn("error parsing HT capabilities");
- return band_estimate_nonht_rate(bandp, supported_rates,
+ ret = band_estimate_nonht_rate(bandp, supported_rates,
ext_supported_rates,
bss->signal_strength / 100,
out_data_rate);
+ if (ret != 0 && ret != -ENOTSUP && ret != -ENETUNREACH)
+ l_warn("error parsing non-HT rates");
+
+ return ret;
}
bool wiphy_regdom_is_updating(struct wiphy *wiphy)
@@ -1367,6 +1391,9 @@ static void parse_supported_commands(struct wiphy *wiphy,
case NL80211_CMD_ASSOCIATE:
assoc = true;
break;
+ case NL80211_CMD_REMAIN_ON_CHANNEL:
+ wiphy->supports_cmd_offchannel = true;
+ break;
}
}
diff --git a/src/wiphy.h b/src/wiphy.h
@@ -141,6 +141,7 @@ bool wiphy_get_rsnxe(const struct wiphy *wiphy, uint8_t *buf, size_t len);
void wiphy_get_reg_domain_country(struct wiphy *wiphy, char *out);
bool wiphy_country_is_unknown(struct wiphy *wiphy);
bool wiphy_supports_uapsd(const struct wiphy *wiphy);
+bool wiphy_supports_cmd_offchannel(const struct wiphy *wiphy);
const uint8_t *wiphy_get_ht_capabilities(const struct wiphy *wiphy,
enum band_freq band,
diff --git a/src/wsc.h b/src/wsc.h
@@ -21,7 +21,7 @@
*/
struct wsc_credentials_info {
- char ssid[33];
+ char ssid[SSID_MAX_SIZE + 1];
enum security security;
union {
uint8_t psk[32];
diff --git a/src/wscutil.c b/src/wscutil.c
@@ -500,7 +500,7 @@ static bool extract_ssid(struct wsc_attr_iter *iter, void *data)
unsigned int len;
len = wsc_attr_iter_get_length(iter);
- if (len > 32)
+ if (len > SSID_MAX_SIZE)
return false;
ssid->iov_len = len;
diff --git a/src/wscutil.h b/src/wscutil.h
@@ -20,6 +20,8 @@
*
*/
+#include "src/defs.h"
+
struct iovec;
/* Wi-Fi Simple Configuration Technical Specification v2.0.5, Section 12 */
@@ -330,7 +332,7 @@ static inline unsigned int wsc_attr_iter_get_pos(struct wsc_attr_iter *iter)
}
struct wsc_credential {
- uint8_t ssid[32];
+ uint8_t ssid[SSID_MAX_SIZE];
uint8_t ssid_len;
uint16_t auth_type;
uint16_t encryption_type;
diff --git a/tools/run-tests b/tools/run-tests
@@ -899,12 +899,18 @@ def post_test(ctx, to_copy):
if ctx.args.valgrind:
for f in os.listdir('/tmp'):
- if f.startswith("valgrind.log."):
- dbg(f)
- with open('/tmp/' + f, 'r') as v:
- dbg(v.read())
+ if not f.startswith("valgrind.log."):
+ continue
+
+ with open('/tmp/' + f, 'r') as v:
+ result = v.read()
+
+ # Don't print out the result if there were no issues
+ if "0 errors from 0 contexts" not in result:
+ dbg(result)
dbg("\n")
- os.remove('/tmp/' + f)
+
+ os.remove('/tmp/' + f)
# Special case for when logging is enabled
if os.path.isfile('/tmp/iwd-tls-debug-server-cert.pem'):
diff --git a/tools/runner.py b/tools/runner.py
@@ -414,7 +414,7 @@ class QemuRunner(RunnerAbstract):
'-machine', 'type=q35,accel=kvm:tcg',
'-nodefaults', '-no-user-config', '-monitor', 'none',
'-display', 'none', '-m', '%dM' % ram, '-nographic', '-vga',
- 'none', '-no-acpi', '-no-hpet',
+ 'none',
'-no-reboot', '-fsdev',
'local,id=fsdev-root,path=/,readonly=on,security_model=none,multidevs=remap',
'-device',
diff --git a/unit/test-band.c b/unit/test-band.c
@@ -444,7 +444,7 @@ const struct he_test_data he_all_mcs_unsupported = {
.freq = BAND_FREQ_5_GHZ,
.rssi = -20,
.expected_rate = 1201000000ULL * 8ULL,
- .expected_return = -EBADMSG,
+ .expected_return = -ENETUNREACH,
.capabilities = {
.he_mcs_set = { MCS_UNSUP, MCS_UNSUP,
MCS_UNSUP, MCS_UNSUP,
@@ -670,6 +670,19 @@ static void test_conversions(const void *data)
assert(!band_channel_to_freq(192, BAND_FREQ_5_GHZ));
}
+static void test_conversion_fallback(const void *data)
+{
+ enum band_freq band;
+ const uint8_t cc[] = {'E', 'S', 0x04};
+
+ /*
+ * Without a fallback, this would fail. There is no operclass 3 in the
+ * global operating table (E-4)
+ */
+ band = band_oper_class_to_band(cc, 3);
+ assert(band == BAND_FREQ_5_GHZ);
+}
+
int main(int argc, char *argv[])
{
l_test_init(&argc, &argv);
@@ -736,6 +749,7 @@ int main(int argc, char *argv[])
l_test_add("/band/6ghz/freq", test_6ghz_freqs, NULL);
l_test_add("/band/conversions", test_conversions, NULL);
+ l_test_add("/band/conversion fallback", test_conversion_fallback, NULL);
return l_test_run();
}
diff --git a/unit/test-nl80211util.c b/unit/test-nl80211util.c
@@ -0,0 +1,63 @@
+
+#include <assert.h>
+#include <ell/ell.h>
+#include "src/nl80211util.h"
+#include "linux/nl80211.h"
+
+static void test_parse_attrs(const void *data)
+{
+ struct l_genl_msg *msg = l_genl_msg_new(NL80211_CMD_NEW_INTERFACE);
+ uint32_t ifindex = 1;
+ uint32_t freq = 2;
+ int ret;
+
+ l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex);
+ l_genl_msg_append_attr(msg, NL80211_ATTR_WIPHY_FREQ, 4, &freq);
+
+ ret = nl80211_parse_attrs(msg, NL80211_ATTR_IFINDEX, &ifindex,
+ NL80211_ATTR_WIPHY_FREQ, &freq,
+ NL80211_ATTR_UNSPEC);
+ l_genl_msg_unref(msg);
+ assert(ret == 0);
+}
+
+static void test_parse_nested(const void *data)
+{
+ struct l_genl_msg *msg = l_genl_msg_new(NL80211_CMD_NEW_INTERFACE);
+ uint32_t ifindex = 1;
+ uint32_t freq = 2;
+ uint8_t noise = 3;
+ uint8_t noise_out;
+ struct l_genl_attr nested;
+ int ret;
+ int ret_nested;
+
+ l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex);
+ l_genl_msg_append_attr(msg, NL80211_ATTR_WIPHY_FREQ, 4, &freq);
+
+ l_genl_msg_enter_nested(msg, NL80211_ATTR_SURVEY_INFO);
+ l_genl_msg_append_attr(msg, NL80211_SURVEY_INFO_NOISE, 1, &noise);
+ l_genl_msg_leave_nested(msg);
+
+ ret = nl80211_parse_attrs(msg, NL80211_ATTR_IFINDEX, &ifindex,
+ NL80211_ATTR_WIPHY_FREQ, &freq,
+ NL80211_ATTR_SURVEY_INFO, &nested,
+ NL80211_ATTR_UNSPEC);
+ ret_nested = nl80211_parse_nested(&nested, NL80211_ATTR_SURVEY_INFO,
+ NL80211_SURVEY_INFO_NOISE, &noise_out,
+ NL80211_ATTR_UNSPEC);
+ l_genl_msg_unref(msg);
+ assert(ret == 0);
+ assert(ret_nested == 0);
+ assert(noise_out == noise);
+}
+
+int main(int argc, char *argv[])
+{
+ l_test_init(&argc, &argv);
+
+ l_test_add("/nl80211util parse attrs", test_parse_attrs, NULL);
+ l_test_add("/nl80211util parse nested", test_parse_nested, NULL);
+
+ return l_test_run();
+}
diff --git a/unit/test-sae.c b/unit/test-sae.c
@@ -421,7 +421,6 @@ static void test_bad_confirm(const void *arg)
handshake_state_set_supplicant_address(hs2, aa);
handshake_state_set_authenticator_address(hs2, spa);
handshake_state_set_passphrase(hs2, passphrase);
- handshake_state_set_authenticator(hs2, true);
ap1 = sae_sm_new(hs1, end_to_end_tx_func, test_tx_assoc_func, td1);
ap2 = sae_sm_new(hs2, end_to_end_tx_func, test_tx_assoc_func, td2);
@@ -496,7 +495,6 @@ static void test_confirm_after_accept(const void *arg)
handshake_state_set_supplicant_address(hs2, aa);
handshake_state_set_authenticator_address(hs2, spa);
handshake_state_set_passphrase(hs2, passphrase);
- handshake_state_set_authenticator(hs2, true);
ap1 = sae_sm_new(hs1, end_to_end_tx_func, test_tx_assoc_func, td1);
ap2 = sae_sm_new(hs2, end_to_end_tx_func, test_tx_assoc_func, td2);
@@ -581,7 +579,6 @@ static void test_end_to_end(const void *arg)
handshake_state_set_supplicant_address(hs2, aa);
handshake_state_set_authenticator_address(hs2, spa);
handshake_state_set_passphrase(hs2, passphrase);
- handshake_state_set_authenticator(hs2, true);
ap1 = sae_sm_new(hs1, end_to_end_tx_func, test_tx_assoc_func, td1);
ap2 = sae_sm_new(hs2, end_to_end_tx_func, test_tx_assoc_func, td2);
diff --git a/unit/test-util.c b/unit/test-util.c
@@ -31,11 +31,12 @@
#include <arpa/inet.h>
#include <ell/ell.h>
+#include "src/defs.h"
#include "src/util.h"
struct ssid_test_data {
size_t len;
- uint8_t ssid[32];
+ uint8_t ssid[SSID_MAX_SIZE];
const char *string;
bool result;
};
diff --git a/wired/ethdev.c b/wired/ethdev.c
@@ -723,7 +723,8 @@ static void setup_adapter_interface(struct l_dbus_interface *interface)
bool ethdev_init(const char *whitelist, const char *blacklist)
{
- struct ifinfomsg msg;
+ struct ifinfomsg ifi;
+ struct l_netlink_message *nlm;
if (rtnl)
return false;
@@ -760,10 +761,11 @@ bool ethdev_init(const char *whitelist, const char *blacklist)
if (blacklist)
blacklist_filter = l_strsplit(blacklist, ',');
- memset(&msg, 0, sizeof(msg));
+ memset(&ifi, 0, sizeof(ifi));
+ nlm = l_netlink_message_new_sized(RTM_GETLINK, NLM_F_DUMP, sizeof(ifi));
+ l_netlink_message_add_header(nlm, &ifi, sizeof(ifi));
- l_netlink_send(rtnl, RTM_GETLINK, NLM_F_DUMP, &msg, sizeof(msg),
- getlink_callback, NULL, NULL);
+ l_netlink_send(rtnl, nlm, getlink_callback, NULL, NULL);
return true;
}