eiwd

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

commit 6d102318862f2bbc248f7f1326622fce7a198bcc
parent fe1a10ebac89ce523cd2822ac10b734adba08134
Author: illiliti <illiliti@protonmail.com>
Date:   Sat, 19 Nov 2022 12:37:29 +0300

Merge tag '2.0'

Release 2.0

Diffstat:
M.gitignore | 1+
MAUTHORS | 2++
MChangeLog | 16++++++++++++++++
MMakefile.am | 12+++++++-----
MREADME | 3++-
Aautotests/testAP-no-support/TestAP2.ap | 3+++
Mautotests/testAP-no-support/connection_test.py | 46++++++++++++++++++++++++++++++++++++++++++----
Mautotests/testAP-no-support/hw.conf | 7+++++--
Aautotests/testAP/TestAP2.ap | 2++
Mautotests/testAP/connection_test.py | 36+++++++++++++++++++++++++++++++-----
Aautotests/testAP/scan_test.py | 20++++++++++++++++++++
Mautotests/testAPRoam/connection_test.py | 43++++++++++++++++++++++++-------------------
Mautotests/testFILS/radius.conf | 2--
Mautotests/testFILS/ssidFILS-256.conf | 2--
Mautotests/testFILS/ssidFILS-384.conf | 2--
Mautotests/testFT-8021x-roam/connection_test.py | 3---
Mautotests/testFT-8021x-roam/ft-eap-ccmp-1.conf | 2--
Mautotests/testFT-8021x-roam/ft-eap-ccmp-2.conf | 2--
Mautotests/testFT-FILS/connection_test.py | 3---
Mautotests/testFT-FILS/ft-eap-ccmp-1.conf | 2--
Mautotests/testFT-FILS/ft-eap-ccmp-2.conf | 2--
Mautotests/testFT-FILS/radius.conf | 2--
Mautotests/testHiddenNetworks/connect_after_hidden_connect_test.py | 12+++++++++++-
Mautotests/testHiddenNetworks/exceptions_test.py | 11+++++++++++
Mautotests/testHiddenNetworks/open_network_test.py | 14++++++++++++++
Mautotests/testHiddenNetworks/wpa_network_test.py | 15+++++++++++++++
Aautotests/testNetconfig/slaac_test.py | 154+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aautotests/testNetconfig/stateless_test.py | 162+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mautotests/testOWE/connection_test.py | 3---
Mautotests/testPSK-roam/connection_test.py | 6------
Aautotests/testPSK-roam/failed_roam_test.py | 160+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mautotests/testPSK-roam/ft-psk-ccmp-1.conf | 2--
Mautotests/testPSK-roam/ft-psk-ccmp-2.conf | 2--
Mautotests/testPreauth-roam/connection_test.py | 3---
Mautotests/testPreauth-roam/eaptls-preauth-1.conf | 2--
Mautotests/testPreauth-roam/eaptls-preauth-2.conf | 2--
Mautotests/testRRM/connection_test.py | 24+++++++++++++++++++-----
Mautotests/testRoamRetry/fast_retry_test.py | 3---
Mautotests/testRoamRetry/stop_retry_test.py | 3---
Mautotests/testSAE-roam/connection_test.py | 3---
Mautotests/testSAE-roam/ft-psk-3.conf | 2--
Mautotests/testSAE-roam/ft-sae-1.conf | 2--
Mautotests/testSAE-roam/ft-sae-2.conf | 2--
Mautotests/testScan/hw.conf | 9++++-----
Mautotests/testScan/periodic_scan_test.py | 4++--
Mautotests/testScan/requested_scan_test.py | 6------
Dautotests/testScan/ssid_hidden_1.conf | 4----
Dautotests/testScan/ssid_hidden_1.open | 3---
Mautotests/testWPA2/connection_test.py | 42++++++++++++++++++++++++++++++++++++------
Mautotests/testWPA2/failure_test.py | 4++--
Mautotests/testWPA2/hw.conf | 3++-
Mautotests/testWPA2/password_test.py | 4++--
Dautotests/testWPA2/ssidCCMP.conf | 7-------
Aautotests/testWPA2/ssidWPA2.conf | 7+++++++
Mautotests/testWPA2withMFP/connection_test.py | 42++++++++++++++++++++++++++++++++++++------
Mautotests/testWPA2withMFP/hw.conf | 4+++-
Dautotests/testWPA2withMFP/ssidCCMP.conf | 10----------
Aautotests/testWPA2withMFP/ssidWPA2.conf | 10++++++++++
Mautotests/util/hostapd.py | 6+++++-
Mautotests/util/iwd.py | 148+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
Mautotests/util/wpas.py | 1-
Mclient/ap.c | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mclient/display.c | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
Mclient/main.c | 3+++
Mclient/station.c | 8+-------
Mconfigure.ac | 4++--
Mdoc/access-point-api.txt | 16++++++++++++++++
Mdoc/agent-api.txt | 123++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
Ddoc/ip-configuration-api.txt | 47-----------------------------------------------
Mdoc/station-diagnostic-api.txt | 8++++++++
Mlinux/nl80211.h | 459+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
Mmonitor/main.c | 32++++++--------------------------
Mmonitor/nlmon.c | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
Mmonitor/nlmon.h | 5+++--
Mshared/jsmn.h | 21++++++++++++---------
Msrc/agent.c | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/anqp.c | 1+
Msrc/ap.c | 266++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------
Msrc/crypto.c | 10+++++++++-
Msrc/crypto.h | 8+++++++-
Msrc/dbus.h | 2++
Msrc/dpp.c | 1+
Msrc/eap-tls-common.c | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/eap-tls-common.h | 7+++++++
Msrc/eap.c | 13+++++++++++++
Msrc/eap.h | 3+++
Msrc/eapol.c | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
Msrc/eapolutil.c | 44++++++++++++++++++++++++++++++++++++++++++++
Msrc/eapolutil.h | 6++++++
Msrc/frame-xchg.c | 2+-
Msrc/frame-xchg.h | 7+++++++
Msrc/ft.c | 630++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
Msrc/ft.h | 74+++++++++++++++++++++++---------------------------------------------------
Msrc/ie.c | 168++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
Msrc/ie.h | 36+++++++++++++++++++++++++++++++++++-
Msrc/iwd.ap.rst | 15+++++++++++++++
Msrc/iwd.config.rst | 19++++++++++++++++++-
Msrc/iwd.service.in | 1+
Msrc/json.c | 3+++
Msrc/json.h | 8++++----
Msrc/manager.c | 26++++++++++++++++++++++++++
Msrc/mpdu.h | 6+++---
Asrc/netconfig-commit.c | 711+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/netconfig.c | 1750+++++++++++++++++--------------------------------------------------------------
Msrc/netconfig.h | 41+++++++++++++++++++++++++++++++++++++++++
Msrc/netdev.c | 773++++++++++++++++++++++++++-----------------------------------------------------
Msrc/netdev.h | 12++----------
Msrc/nl80211util.c | 32+++++++++++++++++++++++---------
Msrc/nl80211util.h | 1+
Msrc/offchannel.c | 9++++-----
Msrc/offchannel.h | 6+++---
Msrc/p2p.c | 31++++++++++++++++---------------
Msrc/rrm.c | 14+++++++++-----
Msrc/sae.c | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
Msrc/scan.c | 51++++++++++++++++++++++++++++++++++++++++++++++++---
Msrc/station.c | 706+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
Msrc/station.h | 4+++-
Msrc/storage.c | 42++++++++++++++++++++++++++++++++++++++++++
Msrc/storage.h | 3+++
Msrc/wiphy.c | 102++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------
Msrc/wiphy.h | 14+++++++++-----
Msrc/wsc.c | 2++
Mtools/hwsim.c | 18+++++++++++++++---
Mtools/run-tests | 16++++++++++------
Mtools/utils.py | 3+++
Munit/test-arc4.c | 2++
Munit/test-ie.c | 2+-
Mwired/ead.service.in | 1+
128 files changed, 5166 insertions(+), 2913 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -4,6 +4,7 @@ .libs .deps .dirstamp +.cache tags cscope.* Makefile diff --git a/AUTHORS b/AUTHORS @@ -37,3 +37,5 @@ Diederik de Haas <didi.debian@cknow.org> VladimĂ­r Dudr <vladimir@tango-dj.cz> Emmanuel VAUTRIN <Emmanuel.VAUTRIN@cpexterne.org> Jesse Lentz <jesse@twosheds.org> +Pinghao Wu <xdavidwuph@gmail.com> +Neehar Vijay <env252525@gmail.com> diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,19 @@ +ver 2.0: + Fix issue with handling P2P and limiting ciphers to CCMP. + Fix issue with scanning before forced roaming action. + Fix issue with provided scan frequencies from RRM. + Fix issue with handling Michael MIC failure message. + Fix issue with handling timestamp size in MPDU frames. + Fix issue with handling enablement of OCVC for FT AKMs. + Fix issue with handling FT work as highest priority. + Fix issue with handling roaming events and Multi-BSS. + Add support for utilizing roaming candidates list. + Add support for utilizing TLS session caching. + Add support for ciphers with 256 bits key size. + Add support for Access Point mode with legacy TKIP. + Add support for MAC address changes while powered. + Add support for IPv4 and IPv6 network configuration. + ver 1.30: Fix issue with handling OWE if buggy AP is detected. Fix issue with handling quick scan and enabling 6GHz. diff --git a/Makefile.am b/Makefile.am @@ -62,7 +62,8 @@ ell_headers = ell/util.h \ ell/icmp6.h \ ell/dhcp6.h \ ell/acd.h \ - ell/cleanup.h + ell/cleanup.h \ + ell/netconfig.h ell_sources = ell/private.h \ ell/missing.h \ @@ -141,7 +142,8 @@ ell_sources = ell/private.h \ ell/icmp6-private.h \ ell/dhcp6-lease.c \ ell/dhcp6-transport.c \ - ell/acd.c + ell/acd.c \ + ell/netconfig.c ell_shared = ell/useful.h ell/asn1-private.h @@ -236,7 +238,8 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h src/missing.h \ src/anqp.h src/anqp.c \ src/anqputil.h src/anqputil.c \ src/netconfig.h src/netconfig.c\ - src/resolve.h src/resolve.c\ + src/netconfig-commit.c \ + src/resolve.h src/resolve.c \ src/hotspot.c \ src/p2p.h src/p2p.c \ src/p2putil.h src/p2putil.c \ @@ -588,8 +591,7 @@ EXTRA_DIST = src/genbuiltin src/iwd.service.in src/net.connman.iwd.service \ AM_CFLAGS = $(ell_cflags) -fvisibility=hidden \ -DUNITDIR=\""$(top_srcdir)/unit/"\" \ - -DCERTDIR=\""$(top_builddir)/unit/"\" \ - -DJSMN_PARENT_LINKS -DJSMN_STRICT + -DCERTDIR=\""$(top_builddir)/unit/"\" if DBUS AM_CFLAGS += -DHAVE_DBUS diff --git a/README b/README @@ -268,7 +268,8 @@ Information =========== Mailing list: - https://lists.01.org/postorius/lists/iwd.lists.01.org/ + https://lists.linux.dev/ + https://lore.kernel.org/iwd/ IRC: irc://irc.oftc.net/#iwd diff --git a/autotests/testAP-no-support/TestAP2.ap b/autotests/testAP-no-support/TestAP2.ap @@ -0,0 +1,3 @@ +[Security] +Passphrase=secret123 +PairwiseCiphers=CCMP diff --git a/autotests/testAP-no-support/connection_test.py b/autotests/testAP-no-support/connection_test.py @@ -5,20 +5,58 @@ import sys sys.path.append('../util') import iwd -from iwd import IWD +from iwd import IWD, NetworkType, PSKAgent class Test(unittest.TestCase): - def test_connection_success(self): - wd = IWD() + def test_no_ap_mode(self): + wd = IWD(True) dev = wd.list_devices(1)[0] with self.assertRaises(iwd.NotSupportedEx): dev.start_ap('TestAP2', 'Password2') + def test_only_tkip_support(self): + wd = IWD(True) + + devices = wd.list_devices(2) + + dev_sta = devices[0] + dev_ap = devices[1] + + dev_ap.start_ap('TestAP2', 'Password2') + + self.assertTrue(dev_ap.group_cipher == 'TKIP') + self.assertIn('TKIP', dev_ap.pairwise_ciphers) + + ordered_network = dev_sta.get_ordered_network('TestAP2') + + if ordered_network.type != NetworkType.psk: + raise Exception("Network type mismatch") + + psk_agent = PSKAgent('Password2') + wd.register_psk_agent(psk_agent) + + ordered_network.network_object.connect() + + condition = 'obj.state == DeviceState.connected' + wd.wait_for_object_condition(dev_sta, condition) + + wd.unregister_psk_agent(psk_agent) + + def test_no_ccmp_support(self): + wd = IWD(True) + + dev = wd.list_devices(2)[1] + + # Should fail to start since the radio doesn't support CCMP but the + # profile only lists CCMP as allowed. + with self.assertRaises(iwd.NotSupportedEx): + dev.start_ap('TestAP2') + @classmethod def setUpClass(cls): - pass + IWD.copy_to_ap('TestAP2.ap') @classmethod def tearDownClass(cls): diff --git a/autotests/testAP-no-support/hw.conf b/autotests/testAP-no-support/hw.conf @@ -1,6 +1,9 @@ [SETUP] -num_radios=1 -radio_confs=rad0 +num_radios=2 +start_iwd=0 [rad0] iftype_disable=ap + +[rad1] +cipher_disable=ccmp,bip_cmac,gcmp,gcmp_256,ccmp_256,bip_gmac,bip_gmac_256,bip_cmac_256 diff --git a/autotests/testAP/TestAP2.ap b/autotests/testAP/TestAP2.ap @@ -0,0 +1,2 @@ +[Security] +Passphrase=Password2 diff --git a/autotests/testAP/connection_test.py b/autotests/testAP/connection_test.py @@ -1,6 +1,7 @@ #! /usr/bin/python3 import unittest +import os from iwd import IWD from config import ctx @@ -8,6 +9,8 @@ from validation import validate, client_connect class Test(unittest.TestCase): def test_connection_success(self): + IWD.copy_to_storage('TestAP1.psk') + wd = IWD(True) dev1, dev2 = wd.list_devices(2) @@ -22,6 +25,8 @@ class Test(unittest.TestCase): client_connect(wd, dev1, 'TestAP1') def test_client_start_ap(self): + IWD.copy_to_storage('TestAP1.psk') + wd = IWD(True) dev1, dev2 = wd.list_devices(2) @@ -39,12 +44,33 @@ class Test(unittest.TestCase): validate(wd, dev2, dev1, 'TestAP2', 'Password2') - @classmethod - def setUpClass(cls): - IWD.copy_to_storage('TestAP1.psk') + def test_valid_ciphers(self): + ciphers = ['TKIP', 'CCMP-128', 'GCMP-128', 'CCMP-256', 'GCMP-256'] + + for group in ciphers: + for pairwise in ciphers: + IWD.copy_to_ap('TestAP2.ap') + os.system('echo "PairwiseCiphers=%s" >> /tmp/iwd/ap/TestAP2.ap' % pairwise) + os.system('echo "GroupCipher=%s" >> /tmp/iwd/ap/TestAP2.ap' % group) + + wd = IWD(True) + + dev1, dev2 = wd.list_devices(2) + + dev1.start_ap('TestAP2') + + self.assertTrue(dev1.group_cipher == group) + self.assertIn(pairwise, dev1.pairwise_ciphers) + + try: + validate(wd, dev2, dev1, 'TestAP2', 'Password2', ip_checks=False) + except: + raise Exception("Failed with pairwise=%s group=%s" % (pairwise, group)) + finally: + IWD.clear_storage() + del wd - @classmethod - def tearDownClass(cls): + def tearDown(self): IWD.clear_storage() if __name__ == '__main__': diff --git a/autotests/testAP/scan_test.py b/autotests/testAP/scan_test.py @@ -0,0 +1,20 @@ +#! /usr/bin/python3 + +import unittest + +from iwd import IWD + +class Test(unittest.TestCase): + def test_ap_scan(self): + wd = IWD(True) + + dev = wd.list_devices(1)[0] + + dev.start_ap('TestAP2', 'Password2') + + dev.scan() + + networks = dev.get_ordered_networks() + + self.assertTrue(len(networks) == 1) + self.assertTrue(networks[0]['Name'] == 'TestAP1') diff --git a/autotests/testAPRoam/connection_test.py b/autotests/testAPRoam/connection_test.py @@ -12,11 +12,7 @@ from hostapd import HostapdCLI class Test(unittest.TestCase): - def test_connection_success(self): - bss_hostapd = [ HostapdCLI(config='ssid1.conf'), - HostapdCLI(config='ssid2.conf'), - HostapdCLI(config='ssid3.conf') ] - + def validate(self, expect_roam=True): wd = IWD() devices = wd.list_devices(1) @@ -29,38 +25,47 @@ class Test(unittest.TestCase): condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) - device.connect_bssid(bss_hostapd[0].bssid) + device.connect_bssid(self.bss_hostapd[0].bssid) condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) - bss_hostapd[0].wait_for_event('AP-STA-CONNECTED') - - self.assertFalse(bss_hostapd[1].list_sta()) + self.bss_hostapd[0].wait_for_event('AP-STA-CONNECTED') - bss_hostapd[0].send_bss_transition(device.address, - [(bss_hostapd[1].bssid, '8f0000005102060603000000')]) + self.assertFalse(self.bss_hostapd[1].list_sta()) - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition) - - condition = 'obj.state != DeviceState.roaming' - wd.wait_for_object_condition(device, condition) + self.bss_hostapd[0].send_bss_transition(device.address, + [(self.bss_hostapd[1].bssid, '8f0000005102060603000000')], + disassoc_imminent=expect_roam) - condition = 'obj.state == DeviceState.connected' - wd.wait_for_object_condition(device, condition) + if expect_roam: + from_condition = 'obj.state == DeviceState.roaming' + to_condition = 'obj.state == DeviceState.connected' + wd.wait_for_object_change(device, from_condition, to_condition) - bss_hostapd[1].wait_for_event('AP-STA-CONNECTED %s' % device.address) + self.bss_hostapd[1].wait_for_event('AP-STA-CONNECTED %s' % device.address) + else: + device.wait_for_event("no-roam-candidates") device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) + def test_disassoc_imminent(self): + self.validate(expect_roam=True) + + def test_no_candidates(self): + self.validate(expect_roam=False) + @classmethod def setUpClass(cls): IWD.copy_to_storage('TestAPRoam.psk') + cls.bss_hostapd = [ HostapdCLI(config='ssid1.conf'), + HostapdCLI(config='ssid2.conf'), + HostapdCLI(config='ssid3.conf') ] + @classmethod def tearDownClass(cls): IWD.clear_storage() diff --git a/autotests/testFILS/radius.conf b/autotests/testFILS/radius.conf @@ -11,5 +11,3 @@ fils_realm=example.com disable_pmksa_caching=1 pwd_group=19 -wpa_group_rekey=30 -wpa_ptk_rekey=30 diff --git a/autotests/testFILS/ssidFILS-256.conf b/autotests/testFILS/ssidFILS-256.conf @@ -17,6 +17,4 @@ nas_identifier=nas.w1.fi fils_realm=example.com disable_pmksa_caching=1 -wpa_group_rekey=30 -wpa_ptk_rekey=30 ocv=1 diff --git a/autotests/testFILS/ssidFILS-384.conf b/autotests/testFILS/ssidFILS-384.conf @@ -17,6 +17,4 @@ nas_identifier=nas.w1.fi fils_realm=example.com disable_pmksa_caching=1 -wpa_group_rekey=30 -wpa_ptk_rekey=30 ocv=1 diff --git a/autotests/testFT-8021x-roam/connection_test.py b/autotests/testFT-8021x-roam/connection_test.py @@ -37,9 +37,6 @@ class Test(unittest.TestCase): device.roam(self.bss_hostapd[1].bssid) - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition) - # 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' diff --git a/autotests/testFT-8021x-roam/ft-eap-ccmp-1.conf b/autotests/testFT-8021x-roam/ft-eap-ccmp-1.conf @@ -17,8 +17,6 @@ eap_user_file=/tmp/secrets/eap-user.text ca_cert=/tmp/certs/cert-ca.pem server_cert=/tmp/certs/cert-server.pem private_key=/tmp/certs/cert-server-key.pem -wpa_ptk_rekey=30 -wpa_group_rekey=80 ieee80211w=1 rsn_preauth=1 disable_pmksa_caching=0 diff --git a/autotests/testFT-8021x-roam/ft-eap-ccmp-2.conf b/autotests/testFT-8021x-roam/ft-eap-ccmp-2.conf @@ -17,8 +17,6 @@ eap_user_file=/tmp/secrets/eap-user.text ca_cert=/tmp/certs/cert-ca.pem server_cert=/tmp/certs/cert-server.pem private_key=/tmp/certs/cert-server-key.pem -wpa_ptk_rekey=30 -wpa_group_rekey=80 ieee80211w=1 rsn_preauth=1 disable_pmksa_caching=0 diff --git a/autotests/testFT-FILS/connection_test.py b/autotests/testFT-FILS/connection_test.py @@ -70,9 +70,6 @@ class Test(unittest.TestCase): #rule0.signal = -8000 device.roam(self.bss_hostapd[1].bssid) - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition) - # 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' diff --git a/autotests/testFT-FILS/ft-eap-ccmp-1.conf b/autotests/testFT-FILS/ft-eap-ccmp-1.conf @@ -15,8 +15,6 @@ ieee8021x=1 fils_realm=example.com -wpa_ptk_rekey=30 -wpa_group_rekey=80 ieee80211w=1 rsn_preauth=1 disable_pmksa_caching=1 diff --git a/autotests/testFT-FILS/ft-eap-ccmp-2.conf b/autotests/testFT-FILS/ft-eap-ccmp-2.conf @@ -15,8 +15,6 @@ ieee8021x=1 fils_realm=example.com -wpa_ptk_rekey=30 -wpa_group_rekey=80 ieee80211w=1 rsn_preauth=1 disable_pmksa_caching=1 diff --git a/autotests/testFT-FILS/radius.conf b/autotests/testFT-FILS/radius.conf @@ -11,5 +11,3 @@ fils_realm=example.com disable_pmksa_caching=1 pwd_group=19 -wpa_group_rekey=30 -wpa_ptk_rekey=30 diff --git a/autotests/testHiddenNetworks/connect_after_hidden_connect_test.py b/autotests/testHiddenNetworks/connect_after_hidden_connect_test.py @@ -7,6 +7,7 @@ sys.path.append('../util') import iwd from iwd import IWD from iwd import PSKAgent +from hostapd import HostapdCLI import testutil import time @@ -67,11 +68,20 @@ class TestConnectionAfterHiddenNetwork(unittest.TestCase): @classmethod def setUpClass(cls): - pass + cls.disabled = [HostapdCLI('ssidHiddenOpen.conf'), + HostapdCLI('ssidHiddenWPA.conf'), + HostapdCLI('ssidOverlap1.conf'), + HostapdCLI('ssidOverlap2.conf')] + + for hapd in cls.disabled: + hapd.disable() @classmethod def tearDownClass(cls): IWD.clear_storage() + for hapd in cls.disabled: + hapd.reload() + if __name__ == '__main__': unittest.main(exit=True) diff --git a/autotests/testHiddenNetworks/exceptions_test.py b/autotests/testHiddenNetworks/exceptions_test.py @@ -8,6 +8,7 @@ import iwd import validation from validation import TestHiddenNetworks from iwd import IWD +from hostapd import HostapdCLI class TestWpaNetwork(unittest.TestCase): ''' @@ -34,9 +35,19 @@ class TestWpaNetwork(unittest.TestCase): def setUpClass(cls): IWD.copy_to_storage('ssidAlreadyKnown.open') + cls.disabled = [HostapdCLI('ssidHiddenOpen.conf'), + HostapdCLI('ssidHiddenWPA.conf'), + HostapdCLI('ssidSomeHidden.conf')] + + for hapd in cls.disabled: + hapd.disable() + @classmethod def tearDownClass(cls): IWD.clear_storage() + for hapd in cls.disabled: + hapd.reload() + if __name__ == '__main__': unittest.main(exit=True) diff --git a/autotests/testHiddenNetworks/open_network_test.py b/autotests/testHiddenNetworks/open_network_test.py @@ -8,6 +8,7 @@ import iwd import validation from validation import TestHiddenNetworks from iwd import IWD +from hostapd import HostapdCLI class TestOpenNetwork(unittest.TestCase): ''' @@ -25,8 +26,21 @@ class TestOpenNetwork(unittest.TestCase): tca.validate('ssidHiddenOpen', True) @classmethod + def setUpClass(cls): + cls.disabled = [HostapdCLI('ssidHiddenWPA.conf'), + HostapdCLI('ssidOpen.conf'), + HostapdCLI('ssidOverlap1.conf'), + HostapdCLI('ssidOverlap2.conf'), + HostapdCLI('ssidSomeHidden.conf')] + for hapd in cls.disabled: + hapd.disable() + + @classmethod def tearDownClass(cls): IWD.clear_storage() + for hapd in cls.disabled: + hapd.reload() + if __name__ == '__main__': unittest.main(exit=True) diff --git a/autotests/testHiddenNetworks/wpa_network_test.py b/autotests/testHiddenNetworks/wpa_network_test.py @@ -8,6 +8,7 @@ import iwd import validation from validation import TestHiddenNetworks from iwd import IWD +from hostapd import HostapdCLI class TestWpaNetwork(unittest.TestCase): ''' @@ -26,8 +27,22 @@ class TestWpaNetwork(unittest.TestCase): tca.validate('ssidHiddenWPA', True, None, True) @classmethod + def setUpClass(cls): + cls.disabled = [HostapdCLI('ssidHiddenOpen.conf'), + HostapdCLI('ssidOpen.conf'), + HostapdCLI('ssidOverlap1.conf'), + HostapdCLI('ssidOverlap2.conf'), + HostapdCLI('ssidSomeHidden.conf')] + + for hapd in cls.disabled: + hapd.disable() + + @classmethod def tearDownClass(cls): IWD.clear_storage() + for hapd in cls.disabled: + hapd.reload() + if __name__ == '__main__': unittest.main(exit=True) diff --git a/autotests/testNetconfig/slaac_test.py b/autotests/testNetconfig/slaac_test.py @@ -0,0 +1,154 @@ +#!/usr/bin/python3 + +import unittest +import sys + +sys.path.append('../util') +import iwd +from iwd import IWD +from iwd import PSKAgent +from iwd import NetworkType +from hostapd import HostapdCLI +import testutil +from config import ctx +import os +import socket + +class Test(unittest.TestCase): + + def test_connection_success(self): + def check_addr(device): + try: + testutil.test_ip_address_match(device.name, '3ffe:501:ffff:200::', 128, 64) + except: + return False + + return True + + def get_ll_addrs6(ns, ifname): + show_ip = ns.start_process(['ip', 'addr', 'show', ifname]) + show_ip.wait() + for l in show_ip.out.split('\n'): + if 'inet6 fe80::' in l: + return socket.inet_pton(socket.AF_INET6, l.split(None, 1)[1].split('/', 1)[0]) + return None + + IWD.copy_to_storage('auto.psk', name='ap-ns1.psk') + wd = IWD(True) + + psk_agent = PSKAgent("secret123") + wd.register_psk_agent(psk_agent) + + devices = wd.list_devices(1) + device = devices[0] + + ordered_network = device.get_ordered_network('ap-ns1') + + self.assertEqual(ordered_network.type, NetworkType.psk) + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + # Give the AP's interface time to set up addresses so that radvd can + # reply to our Router Solicitation immediately. + ctx.non_block_wait(lambda: False, 3, exception=False) + + ordered_network.network_object.connect() + + condition = 'obj.state == DeviceState.connected' + wd.wait_for_object_condition(device, condition) + + testutil.test_iface_operstate() + + ctx.non_block_wait(check_addr, 10, device, + exception=Exception("IPv6 address was not set")) + + # Cannot use test_ifaces_connected() across namespaces (implementation details) + testutil.test_ip_connected(('192.168.1.10', ctx), ('192.168.1.1', self.ns1)) + + ifname = str(device.name) + router_ll_addr = get_ll_addrs6(self.ns1, self.hapd.ifname) + expected_routes6 = { + # Default router + testutil.RouteInfo(gw=router_ll_addr, flags=3, ifname=ifname), + # On-link prefixes + testutil.RouteInfo(dst=socket.inet_pton(socket.AF_INET6, '3ffe:501:ffff:100::'), plen=64, + flags=1, ifname=ifname), + testutil.RouteInfo(dst=socket.inet_pton(socket.AF_INET6, '3ffe:501:ffff:200::'), plen=64, + flags=1, ifname=ifname), + } + self.maxDiff = None + self.assertEqual(expected_routes6, set(testutil.get_routes6(ifname))) + + rclog = open('/tmp/resolvconf.log', 'r') + entries = rclog.readlines() + rclog.close() + expected_rclog = ['-a %s.dns\n' % (ifname,), 'nameserver 192.168.1.2\n', + 'nameserver 3ffe:501:ffff:100::10\n', 'nameserver 3ffe:501:ffff:100::50\n', + '-a %s.domain\n' % (ifname,), 'search test1\n', 'search test2\n'] + # Every resolvconf -a run overwrites the previous settings. Check the last seven lines + # of our log since we care about the end result here. + self.assertEqual(expected_rclog, entries[-7:]) + + device.disconnect() + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + wd.unregister_psk_agent(psk_agent) + + @classmethod + def setUpClass(cls): + def remove_lease4(): + try: + os.remove('/tmp/dhcpd.leases') + os.remove('/tmp/dhcpd.leases~') + except: + pass + cls.ns1 = ctx.get_namespace('ns1') + cls.hapd = HostapdCLI('ap-ns1.conf') + cls.ns1.start_process(['ip', 'addr','add', '192.168.1.1/17', + 'dev', cls.hapd.ifname]).wait() + cls.ns1.start_process(['touch', '/tmp/dhcpd.leases']).wait() + cls.dhcpd_pid = cls.ns1.start_process(['dhcpd', '-f', '-d', '-cf', '/tmp/dhcpd.conf', + '-lf', '/tmp/dhcpd.leases', + cls.hapd.ifname], cleanup=remove_lease4) + + cls.ns1.start_process(['ip', 'addr', 'add', '3ffe:501:ffff:100::1/72', + 'dev', cls.hapd.ifname]).wait() + cls.ns1.start_process(['sysctl', + 'net.ipv6.conf.' + cls.hapd.ifname + '.forwarding=1']).wait() + config = open('/tmp/radvd.conf', 'w') + config.write('interface ' + cls.hapd.ifname + ''' { + AdvSendAdvert on; + # Trick radvd to accept MinDelayBetweenRAs values less than 3 seconds. + AdvHomeAgentFlag on; + # Don't throttle so we can test solicited RA reception before link-local addr DAD done. + # radvd may have sent an unsolicited RA just before our RS and would complain -- the + # test should succeed regardless but will take some extra seconds. + MinDelayBetweenRAs 0.05; + AdvManagedFlag off; + # Test that the prefix with longer lifetime is selected. + prefix 3ffe:501:ffff:100::/64 { AdvAutonomous on; }; + prefix 3ffe:501:ffff:200::/64 { AdvAutonomous on; AdvPreferredLifetime infinity; AdvValidLifetime infinity; }; + RDNSS 3ffe:501:ffff:100::10 3ffe:501:ffff:100::50 { AdvRDNSSLifetime 3600; }; + DNSSL test1 test2 { AdvDNSSLLifetime 3600; }; + };''') + config.close() + cls.radvd_pid = cls.ns1.start_process(['radvd', '-n', '-d5', + '-p', '/tmp/radvd.pid', '-C', '/tmp/radvd.conf']) + + cls.orig_path = os.environ['PATH'] + os.environ['PATH'] = '/tmp/test-bin:' + os.environ['PATH'] + IWD.copy_to_storage('resolvconf', '/tmp/test-bin') + + @classmethod + def tearDownClass(cls): + IWD.clear_storage() + cls.ns1.stop_process(cls.dhcpd_pid) + cls.dhcpd_pid = None + cls.ns1.stop_process(cls.radvd_pid) + cls.radvd_pid = None + os.system('rm -rf /tmp/radvd.conf /tmp/test-bin') + os.environ['PATH'] = cls.orig_path + +if __name__ == '__main__': + unittest.main(exit=True) diff --git a/autotests/testNetconfig/stateless_test.py b/autotests/testNetconfig/stateless_test.py @@ -0,0 +1,162 @@ +#!/usr/bin/python3 + +import unittest +import sys + +sys.path.append('../util') +import iwd +from iwd import IWD +from iwd import PSKAgent +from iwd import NetworkType +from hostapd import HostapdCLI +import testutil +from config import ctx +import os +import socket + +class Test(unittest.TestCase): + + def test_connection_success(self): + def check_addr(device): + try: + testutil.test_ip_address_match(device.name, '3ffe:501:ffff:100::', 128, 64) + except: + return False + + return True + + def get_ll_addrs6(ns, ifname): + show_ip = ns.start_process(['ip', 'addr', 'show', ifname]) + show_ip.wait() + for l in show_ip.out.split('\n'): + if 'inet6 fe80::' in l: + return socket.inet_pton(socket.AF_INET6, l.split(None, 1)[1].split('/', 1)[0]) + return None + + IWD.copy_to_storage('auto.psk', name='ap-ns1.psk') + wd = IWD(True) + + psk_agent = PSKAgent("secret123") + wd.register_psk_agent(psk_agent) + + devices = wd.list_devices(1) + device = devices[0] + + ordered_network = device.get_ordered_network('ap-ns1') + + self.assertEqual(ordered_network.type, NetworkType.psk) + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + # Give the AP's interface time to set up addresses so that radvd can + # reply to our Router Solicitation immediately. + ctx.non_block_wait(lambda: False, 3, exception=False) + + ordered_network.network_object.connect() + + condition = 'obj.state == DeviceState.connected' + wd.wait_for_object_condition(device, condition) + + testutil.test_iface_operstate() + + ctx.non_block_wait(check_addr, 10, device, + exception=Exception("IPv6 address was not set")) + + # Cannot use test_ifaces_connected() across namespaces (implementation details) + testutil.test_ip_connected(('192.168.1.10', ctx), ('192.168.1.1', self.ns1)) + + ifname = str(device.name) + router_ll_addr = get_ll_addrs6(self.ns1, self.hapd.ifname) + expected_routes6 = { + # Default router + testutil.RouteInfo(gw=router_ll_addr, flags=3, ifname=ifname), + # On-link prefixes + testutil.RouteInfo(dst=socket.inet_pton(socket.AF_INET6, '3ffe:501:ffff:100::'), plen=64, + flags=1, ifname=ifname), + testutil.RouteInfo(dst=socket.inet_pton(socket.AF_INET6, '3ffe:501:ffff:200::'), plen=64, + flags=1, ifname=ifname), + } + self.maxDiff = None + self.assertEqual(expected_routes6, set(testutil.get_routes6(ifname))) + + rclog = open('/tmp/resolvconf.log', 'r') + entries = rclog.readlines() + rclog.close() + expected_rclog = ['-a %s.dns\n' % (ifname,), 'nameserver 192.168.1.2\n', + 'nameserver 3ffe:501:ffff:100::2\n', + '-a %s.domain\n' % (ifname,), 'search test1\n', 'search test2\n'] + # Every resolvconf -a run overwrites the previous settings. Check the last six lines + # of our log since we care about the end result here. + self.assertEqual(expected_rclog, entries[-6:]) + + device.disconnect() + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + wd.unregister_psk_agent(psk_agent) + + @classmethod + def setUpClass(cls): + def remove_lease4(): + try: + os.remove('/tmp/dhcpd.leases') + os.remove('/tmp/dhcpd.leases~') + except: + pass + def remove_lease6(): + try: + os.remove('/tmp/dhcpd6.leases') + os.remove('/tmp/dhcpd6.leases~') + except: + pass + + cls.ns1 = ctx.get_namespace('ns1') + cls.hapd = HostapdCLI('ap-ns1.conf') + cls.ns1.start_process(['ip', 'addr','add', '192.168.1.1/17', + 'dev', cls.hapd.ifname]).wait() + cls.ns1.start_process(['touch', '/tmp/dhcpd.leases']).wait() + cls.dhcpd_pid = cls.ns1.start_process(['dhcpd', '-f', '-d', '-cf', '/tmp/dhcpd.conf', + '-lf', '/tmp/dhcpd.leases', + cls.hapd.ifname], cleanup=remove_lease4) + + cls.ns1.start_process(['ip', 'addr', 'add', '3ffe:501:ffff:100::1/72', + 'dev', cls.hapd.ifname]).wait() + cls.ns1.start_process(['touch', '/tmp/dhcpd6.leases']).wait() + cls.dhcpd6_pid = cls.ns1.start_process(['dhcpd', '-6', '-f', '-d', + '-cf', '/tmp/dhcpd-v6.conf', + '-lf', '/tmp/dhcpd6.leases', + cls.hapd.ifname], cleanup=remove_lease6) + cls.ns1.start_process(['sysctl', + 'net.ipv6.conf.' + cls.hapd.ifname + '.forwarding=1']).wait() + config = open('/tmp/radvd.conf', 'w') + config.write('interface ' + cls.hapd.ifname + ''' { + AdvSendAdvert on; + AdvManagedFlag off; + AdvOtherConfigFlag on; + # Test that the prefix with longer lifetime is selected. + prefix 3ffe:501:ffff:100::/64 { AdvAutonomous on; AdvPreferredLifetime 3605; }; + prefix 3ffe:501:ffff:200::/64 { AdvAutonomous on; AdvPreferredLifetime 3600; }; + DNSSL test1 test2 { AdvDNSSLLifetime 3600; }; + };''') + config.close() + cls.radvd_pid = cls.ns1.start_process(['radvd', '-n', '-d5', + '-p', '/tmp/radvd.pid', '-C', '/tmp/radvd.conf']) + + cls.orig_path = os.environ['PATH'] + os.environ['PATH'] = '/tmp/test-bin:' + os.environ['PATH'] + IWD.copy_to_storage('resolvconf', '/tmp/test-bin') + + @classmethod + def tearDownClass(cls): + IWD.clear_storage() + cls.ns1.stop_process(cls.dhcpd_pid) + cls.dhcpd_pid = None + cls.ns1.stop_process(cls.dhcpd6_pid) + cls.dhcpd6_pid = None + cls.ns1.stop_process(cls.radvd_pid) + cls.radvd_pid = None + os.system('rm -rf /tmp/radvd.conf /tmp/test-bin') + os.environ['PATH'] = cls.orig_path + +if __name__ == '__main__': + unittest.main(exit=True) diff --git a/autotests/testOWE/connection_test.py b/autotests/testOWE/connection_test.py @@ -53,9 +53,6 @@ class Test(unittest.TestCase): device.roam(hapd1.bssid) - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition) - from_condition = 'obj.state == DeviceState.roaming' to_condition = 'obj.state == DeviceState.connected' wd.wait_for_object_change(device, from_condition, to_condition) diff --git a/autotests/testPSK-roam/connection_test.py b/autotests/testPSK-roam/connection_test.py @@ -52,9 +52,6 @@ class Test(unittest.TestCase): else: device.roam(self.bss_hostapd[1].bssid) - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition) - # 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' @@ -76,9 +73,6 @@ class Test(unittest.TestCase): device.roam(self.bss_hostapd[0].bssid) - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition) - # Check that iwd is on BSS 0 once out of roaming state and doesn't # go through 'disconnected', 'autoconnect', 'connecting' in between from_condition = 'obj.state == DeviceState.roaming' diff --git a/autotests/testPSK-roam/failed_roam_test.py b/autotests/testPSK-roam/failed_roam_test.py @@ -0,0 +1,160 @@ +#! /usr/bin/python3 + +import unittest +import os, sys + +sys.path.append('../util') +from iwd import IWD +from iwd import NetworkType, DeviceState +from hwsim import Hwsim +from hostapd import HostapdCLI +import testutil + +class Test(unittest.TestCase): + def connect(self, wd, device, hostapd): + 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) + + device.connect_bssid(hostapd.bssid) + + condition = 'obj.state == DeviceState.connected' + wd.wait_for_object_condition(device, condition) + + hostapd.wait_for_event('AP-STA-CONNECTED %s' % device.address) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(hostapd.ifname, device.name) + + def verify_roam(self, wd, device, prev, new): + from_condition = 'obj.state == DeviceState.roaming' + to_condition = 'obj.state == DeviceState.connected' + wd.wait_for_object_change(device, from_condition, to_condition) + + new.wait_for_event('AP-STA-CONNECTED %s' % device.address) + + testutil.test_iface_operstate(device.name) + testutil.test_ifaces_connected(new.ifname, device.name) + self.assertRaises(Exception, testutil.test_ifaces_connected, + (prev.ifname, device.name, True, True)) + + + # FT-over-Air failure, should stay connected + def test_ft_over_air_failure(self): + self.bss_hostapd[0].set_value('wpa_key_mgmt', 'FT-PSK') + self.bss_hostapd[0].set_value('ft_over_ds', '0') + self.bss_hostapd[0].reload() + self.bss_hostapd[0].wait_for_event("AP-ENABLED") + + self.bss_hostapd[1].set_value('wpa_key_mgmt', 'FT-PSK') + self.bss_hostapd[1].set_value('ft_over_ds', '0') + self.bss_hostapd[1].reload() + self.bss_hostapd[1].wait_for_event("AP-ENABLED") + + wd = IWD(True) + + device = wd.list_devices(1)[0] + + self.connect(wd, device, self.bss_hostapd[0]) + + self.rule0.enabled = True + + device.roam(self.bss_hostapd[1].bssid) + + # Roam should fail... + device.wait_for_event('ft-over-air-roam-failed') + # ... but IWD should remain connected + self.assertTrue(device.state == DeviceState.connected) + + self.rule0.enabled = False + + # Try again once more + device.roam(self.bss_hostapd[1].bssid) + + self.verify_roam(wd, device, self.bss_hostapd[0], self.bss_hostapd[1]) + + self.bss_hostapd[1].deauthenticate(device.address) + condition = 'obj.state == DeviceState.disconnected' + wd.wait_for_object_condition(device, condition) + + # Network sets over-DS bit, but fails to authenticate. IWD should still be + # able to roam using FT-over-Air. + def test_fallback_to_over_air(self): + self.bss_hostapd[0].set_value('wpa_key_mgmt', 'FT-PSK') + self.bss_hostapd[0].set_value('ft_over_ds', '1') + self.bss_hostapd[0].reload() + self.bss_hostapd[0].wait_for_event("AP-ENABLED") + + self.bss_hostapd[1].set_value('wpa_key_mgmt', 'FT-PSK') + self.bss_hostapd[1].set_value('ft_over_ds', '1') + self.bss_hostapd[1].reload() + self.bss_hostapd[1].wait_for_event("AP-ENABLED") + + wd = IWD(True) + + device = wd.list_devices(1)[0] + + # Drop action frames, this will prevent FT-over-DS authentication + self.rule1.enabled = True + + self.connect(wd, device, self.bss_hostapd[0]) + + device.roam(self.bss_hostapd[1].bssid) + + self.rule1.enabled = False + + # FT-over-DS should fail, and over-Air should take over leading to a + # successful roam + device.wait_for_event('try-ft-over-air') + + self.verify_roam(wd, device, self.bss_hostapd[0], self.bss_hostapd[1]) + + self.bss_hostapd[1].deauthenticate(device.address) + condition = 'obj.state == DeviceState.disconnected' + wd.wait_for_object_condition(device, condition) + + 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.rule0.enabled = False + self.rule1.enabled = False + + @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') ] + + cls.bss_hostapd[0].set_address('12:00:00:00:00:01') + cls.bss_hostapd[1].set_address('12:00:00:00:00:02') + + # Drop Authenticate frames + cls.rule0 = hwsim.rules.create() + cls.rule0.bidirectional = True + cls.rule0.prefix = 'b0' + cls.rule0.drop = True + + # Drop Action frames + cls.rule1 = hwsim.rules.create() + cls.rule1.bidirectional = True + cls.rule1.prefix = 'd0' + cls.rule1.drop = True + + @classmethod + def tearDownClass(cls): + IWD.clear_storage() + cls.bss_hostapd = None + cls.rule0.remove() + cls.rule1.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,8 +13,6 @@ wpa=2 wpa_key_mgmt=FT-PSK wpa_pairwise=CCMP wpa_passphrase=EasilyGuessedPassword -wpa_ptk_rekey=30 -wpa_group_rekey=80 ieee80211w=1 rsn_preauth=1 rsn_preauth_interfaces=lo diff --git a/autotests/testPSK-roam/ft-psk-ccmp-2.conf b/autotests/testPSK-roam/ft-psk-ccmp-2.conf @@ -13,8 +13,6 @@ wpa=2 wpa_key_mgmt=FT-PSK wpa_pairwise=CCMP wpa_passphrase=EasilyGuessedPassword -wpa_ptk_rekey=30 -wpa_group_rekey=80 ieee80211w=1 rsn_preauth=1 rsn_preauth_interfaces=lo diff --git a/autotests/testPreauth-roam/connection_test.py b/autotests/testPreauth-roam/connection_test.py @@ -48,9 +48,6 @@ class Test(unittest.TestCase): device.roam(bss1_addr) - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition) - # TODO: verify that the PMK from preauthentication was used # Check that iwd is on BSS 1 once out of roaming state and doesn't diff --git a/autotests/testPreauth-roam/eaptls-preauth-1.conf b/autotests/testPreauth-roam/eaptls-preauth-1.conf @@ -7,8 +7,6 @@ wpa=2 wpa_key_mgmt=WPA-EAP wpa_pairwise=CCMP ieee8021x=1 -wpa_ptk_rekey=30 -wpa_group_rekey=80 ieee80211w=1 # Run the RADIUS server in the BSS 0 hostapd only, listen for BSS 1 connections diff --git a/autotests/testPreauth-roam/eaptls-preauth-2.conf b/autotests/testPreauth-roam/eaptls-preauth-2.conf @@ -7,8 +7,6 @@ wpa=2 wpa_key_mgmt=WPA-EAP wpa_pairwise=CCMP ieee8021x=1 -wpa_ptk_rekey=30 -wpa_group_rekey=80 ieee80211w=1 # For EAP connect to the RADIUS server in the BSS 0 diff --git a/autotests/testRRM/connection_test.py b/autotests/testRRM/connection_test.py @@ -21,6 +21,8 @@ beacon_passive = '510b0000000000ffffffffffff020100' beacon_active = '510b0000000001ffffffffffff020100' # Passive beacon with duration set beacon_passive_duration = '510b0000c80000ffffffffffff020100' +# Passive beacon on disabled frequency (disallowed in US) +beacon_passive_disabled = '520e0000c80000ffffffffffff020100' class Test(unittest.TestCase): @@ -57,13 +59,15 @@ class Test(unittest.TestCase): hapd.req_beacon(device.address, basic_beacon) for e in ['BEACON-RESP-RX', 'BEACON-RESP-RX']: - hapd.wait_for_event(e) + event = hapd.wait_for_event(e).split(' ') + self.assertTrue(event[3] == '00') wd.wait(1) # This should return just ssidRRM hapd.req_beacon(device.address, beacon_with_ssid) - hapd.wait_for_event('BEACON-RESP-RX') + event = hapd.wait_for_event('BEACON-RESP-RX').split(' ') + self.assertTrue(event[3] == '00') wd.wait(1) @@ -71,7 +75,8 @@ class Test(unittest.TestCase): hapd.req_beacon(device.address, beacon_passive) # TODO: See if we are scanning here (scan not initiated from station) - hapd.wait_for_event('BEACON-RESP-RX') + event = hapd.wait_for_event('BEACON-RESP-RX').split(' ') + self.assertTrue(event[3] == '00') wd.wait(1) @@ -79,7 +84,8 @@ class Test(unittest.TestCase): hapd.req_beacon(device.address, beacon_active) # TODO: See if we are scanning here (scan not initiated from station) - hapd.wait_for_event('BEACON-RESP-RX') + event = hapd.wait_for_event('BEACON-RESP-RX').split(' ') + self.assertTrue(event[3] == '00') wd.wait(1) @@ -87,7 +93,15 @@ class Test(unittest.TestCase): hapd.req_beacon(device.address, beacon_passive_duration) # TODO: See if we are scanning here (scan not initiated from station) - hapd.wait_for_event('BEACON-RESP-RX') + event = hapd.wait_for_event('BEACON-RESP-RX').split(' ') + self.assertTrue(event[3] == '00') + + wd.wait(1) + + hapd.req_beacon(device.address, beacon_passive_disabled) + + event = hapd.wait_for_event('BEACON-RESP-RX').split(' ') + self.assertTrue(event[3] != '00') device.disconnect() diff --git a/autotests/testRoamRetry/fast_retry_test.py b/autotests/testRoamRetry/fast_retry_test.py @@ -91,9 +91,6 @@ class Test(unittest.TestCase): rule0.signal = -8000 rule1.signal = -2000 - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition) - # 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' diff --git a/autotests/testRoamRetry/stop_retry_test.py b/autotests/testRoamRetry/stop_retry_test.py @@ -67,9 +67,6 @@ class Test(unittest.TestCase): # connects to BSS 1 rule0.signal = -8000 - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition) - # 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' diff --git a/autotests/testSAE-roam/connection_test.py b/autotests/testSAE-roam/connection_test.py @@ -39,9 +39,6 @@ class Test(unittest.TestCase): device.roam(self.bss_hostapd[1].bssid) - condition = 'obj.state == DeviceState.roaming' - wd.wait_for_object_condition(device, condition) - # 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' diff --git a/autotests/testSAE-roam/ft-psk-3.conf b/autotests/testSAE-roam/ft-psk-3.conf @@ -13,8 +13,6 @@ wpa=2 wpa_key_mgmt=FT-PSK wpa_pairwise=CCMP wpa_passphrase=EasilyGuessedPassword -wpa_ptk_rekey=30 -wpa_group_rekey=80 ieee80211w=2 disable_pmksa_caching=0 # Allow PMK cache to be shared opportunistically among configured interfaces diff --git a/autotests/testSAE-roam/ft-sae-1.conf b/autotests/testSAE-roam/ft-sae-1.conf @@ -13,8 +13,6 @@ wpa=2 wpa_key_mgmt=FT-SAE SAE sae_password=EasilyGuessedPassword|mac=ff:ff:ff:ff:ff:ff wpa_pairwise=CCMP -wpa_ptk_rekey=30 -wpa_group_rekey=80 ieee80211w=2 disable_pmksa_caching=0 # Allow PMK cache to be shared opportunistically among configured interfaces diff --git a/autotests/testSAE-roam/ft-sae-2.conf b/autotests/testSAE-roam/ft-sae-2.conf @@ -13,8 +13,6 @@ wpa=2 wpa_key_mgmt=FT-SAE SAE sae_password=EasilyGuessedPassword|mac=ff:ff:ff:ff:ff:ff wpa_pairwise=CCMP -wpa_ptk_rekey=30 -wpa_group_rekey=80 ieee80211w=2 disable_pmksa_caching=0 # Allow PMK cache to be shared opportunistically among configured interfaces diff --git a/autotests/testScan/hw.conf b/autotests/testScan/hw.conf @@ -1,10 +1,9 @@ [SETUP] -num_radios=6 +num_radios=5 start_iwd=0 [HOSTAPD] rad0=ssid_hidden_0.conf -rad1=ssid_hidden_1.conf -rad2=ssid_open.conf -rad3=ssid_8021x.conf -rad4=ssid_psk.conf +rad1=ssid_open.conf +rad2=ssid_8021x.conf +rad3=ssid_psk.conf diff --git a/autotests/testScan/periodic_scan_test.py b/autotests/testScan/periodic_scan_test.py @@ -12,7 +12,7 @@ class Test(unittest.TestCase): 'ssid_open': False, 'ssid_psk': False, 'ssid_8021x': False, - 'ssid_hidden_1': False, + 'ssid_hidden_0': False, } def set_network(self, ssid): @@ -58,7 +58,7 @@ class Test(unittest.TestCase): @classmethod def setUpClass(cls): - IWD.copy_to_storage('ssid_hidden_1.open') + IWD.copy_to_storage('ssid_hidden_0.open') @classmethod def tearDownClass(cls): diff --git a/autotests/testScan/requested_scan_test.py b/autotests/testScan/requested_scan_test.py @@ -30,12 +30,6 @@ class Test(unittest.TestCase): devices = wd.list_devices(1) self.assertIsNotNone(devices) device = devices[0] - device.autoconnect = True - - condition = 'obj.scanning' - wd.wait_for_object_condition(device, condition) - condition = 'not obj.scanning' - wd.wait_for_object_condition(device, condition) device.scan() diff --git a/autotests/testScan/ssid_hidden_1.conf b/autotests/testScan/ssid_hidden_1.conf @@ -1,4 +0,0 @@ -ssid=ssid_hidden_1 -hw_mode=g -channel=1 -ignore_broadcast_ssid=1 diff --git a/autotests/testScan/ssid_hidden_1.open b/autotests/testScan/ssid_hidden_1.open @@ -1,3 +0,0 @@ -[Settings] -AutoConnect=false -Hidden=true diff --git a/autotests/testWPA2/connection_test.py b/autotests/testWPA2/connection_test.py @@ -8,20 +8,19 @@ 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): - wd = IWD() - + def validate_connection_success(self, wd): psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) device = devices[0] - ordered_network = device.get_ordered_network('ssidCCMP') + ordered_network = device.get_ordered_network('ssidWPA2') self.assertEqual(ordered_network.type, NetworkType.psk) @@ -43,13 +42,44 @@ class Test(unittest.TestCase): wd.unregister_psk_agent(psk_agent) + def test_ccmp(self): + self.hostapd.set_value('rsn_pairwise', 'CCMP') + self.hostapd.reload() + self.hostapd.wait_for_event("AP-ENABLED") + self.validate_connection_success(self.wd) + + def test_gcmp(self): + self.hostapd.set_value('rsn_pairwise', 'GCMP') + self.hostapd.reload() + self.hostapd.wait_for_event("AP-ENABLED") + self.validate_connection_success(self.wd) + + def test_gcmp_256(self): + self.hostapd.set_value('rsn_pairwise', 'GCMP-256') + self.hostapd.reload() + self.hostapd.wait_for_event("AP-ENABLED") + self.validate_connection_success(self.wd) + + def test_ccmp_256(self): + self.hostapd.set_value('rsn_pairwise', 'CCMP-256') + self.hostapd.reload() + self.hostapd.wait_for_event("AP-ENABLED") + self.validate_connection_success(self.wd) + + def setUp(self): + self.wd = IWD(True) + + def tearDown(self): + self.wd.clear_storage() + self.wd = None + @classmethod def setUpClass(cls): - pass + cls.hostapd = HostapdCLI(config='ssidWPA2.conf') @classmethod def tearDownClass(cls): - IWD.clear_storage() + pass if __name__ == '__main__': unittest.main(exit=True) diff --git a/autotests/testWPA2/failure_test.py b/autotests/testWPA2/failure_test.py @@ -13,7 +13,7 @@ import testutil class Test(unittest.TestCase): def test_connection_success(self): - wd = IWD() + wd = IWD(True) psk_agent = PSKAgent("InvalidPassword") wd.register_psk_agent(psk_agent) @@ -22,7 +22,7 @@ class Test(unittest.TestCase): self.assertIsNotNone(devices) device = devices[0] - ordered_network = device.get_ordered_network('ssidCCMP') + ordered_network = device.get_ordered_network('ssidWPA2') self.assertEqual(ordered_network.type, NetworkType.psk) diff --git a/autotests/testWPA2/hw.conf b/autotests/testWPA2/hw.conf @@ -1,5 +1,6 @@ [SETUP] num_radios=2 +start_iwd=0 [HOSTAPD] -rad0=ssidCCMP.conf +rad0=ssidWPA2.conf diff --git a/autotests/testWPA2/password_test.py b/autotests/testWPA2/password_test.py @@ -13,7 +13,7 @@ import testutil class Test(unittest.TestCase): def test_connection_success(self): - wd = IWD() + wd = IWD(True) devices = wd.list_devices(1) device = devices[0] @@ -22,7 +22,7 @@ class Test(unittest.TestCase): condition = 'obj.state == DeviceState.disconnected' wd.wait_for_object_condition(device, condition) - ordered_network = device.get_ordered_network("ssidCCMP") + ordered_network = device.get_ordered_network("ssidWPA2") self.assertEqual(ordered_network.type, NetworkType.psk) network = ordered_network.network_object diff --git a/autotests/testWPA2/ssidCCMP.conf b/autotests/testWPA2/ssidCCMP.conf @@ -1,7 +0,0 @@ -hw_mode=g -channel=1 -ssid=ssidCCMP - -wpa=2 -wpa_pairwise=CCMP -wpa_passphrase=secret123 diff --git a/autotests/testWPA2/ssidWPA2.conf b/autotests/testWPA2/ssidWPA2.conf @@ -0,0 +1,7 @@ +hw_mode=g +channel=1 +ssid=ssidWPA2 + +wpa=2 +wpa_pairwise=CCMP +wpa_passphrase=secret123 diff --git a/autotests/testWPA2withMFP/connection_test.py b/autotests/testWPA2withMFP/connection_test.py @@ -8,19 +8,18 @@ import iwd from iwd import IWD from iwd import PSKAgent from iwd import NetworkType +from hostapd import HostapdCLI class Test(unittest.TestCase): - def test_connection_success(self): - wd = IWD() - + def validate_connection_success(self, wd): psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) device = devices[0] - ordered_network = device.get_ordered_network('ssidCCMP') + ordered_network = device.get_ordered_network('ssidWPA2') self.assertEqual(ordered_network.type, NetworkType.psk) @@ -39,13 +38,44 @@ class Test(unittest.TestCase): wd.unregister_psk_agent(psk_agent) + def test_cmac(self): + self.hostapd.set_value('group_mgmt_cipher', 'AES-128-CMAC') + self.hostapd.reload() + self.hostapd.wait_for_event("AP-ENABLED") + self.validate_connection_success(self.wd) + + def test_gmac(self): + self.hostapd.set_value('group_mgmt_cipher', 'BIP-128-GMAC') + self.hostapd.reload() + self.hostapd.wait_for_event("AP-ENABLED") + self.validate_connection_success(self.wd) + + def test_gmac_256(self): + self.hostapd.set_value('group_mgmt_cipher', 'BIP-256-GMAC') + self.hostapd.reload() + self.hostapd.wait_for_event("AP-ENABLED") + self.validate_connection_success(self.wd) + + def test_cmac_256(self): + self.hostapd.set_value('group_mgmt_cipher', 'BIP-256-CMAC') + self.hostapd.reload() + self.hostapd.wait_for_event("AP-ENABLED") + self.validate_connection_success(self.wd) + + def setUp(self): + self.wd = IWD(True) + + def tearDown(self): + self.wd.clear_storage() + self.wd = None + @classmethod def setUpClass(cls): - pass + cls.hostapd = HostapdCLI(config='ssidWPA2.conf') @classmethod def tearDownClass(cls): - IWD.clear_storage() + pass if __name__ == '__main__': unittest.main(exit=True) diff --git a/autotests/testWPA2withMFP/hw.conf b/autotests/testWPA2withMFP/hw.conf @@ -1,5 +1,7 @@ [SETUP] num_radios=2 +start_iwd=0 [HOSTAPD] -rad0=ssidCCMP.conf +rad0=ssidWPA2.conf + diff --git a/autotests/testWPA2withMFP/ssidCCMP.conf b/autotests/testWPA2withMFP/ssidCCMP.conf @@ -1,10 +0,0 @@ -hw_mode=g -channel=1 -ssid=ssidCCMP - -wpa=2 -wpa_pairwise=CCMP -wpa_passphrase=secret123 - -ieee80211w=2 -wpa_key_mgmt=WPA-PSK-SHA256 diff --git a/autotests/testWPA2withMFP/ssidWPA2.conf b/autotests/testWPA2withMFP/ssidWPA2.conf @@ -0,0 +1,10 @@ +hw_mode=g +channel=1 +ssid=ssidWPA2 + +wpa=2 +wpa_pairwise=CCMP +wpa_passphrase=secret123 + +ieee80211w=2 +wpa_key_mgmt=WPA-PSK-SHA256 diff --git a/autotests/util/hostapd.py b/autotests/util/hostapd.py @@ -199,7 +199,7 @@ class HostapdCLI(object): cmd = self.cmdline + ['remove_neighbor', addr] ctx.start_process(cmd).wait() - def send_bss_transition(self, device, nr_list): + def send_bss_transition(self, device, nr_list, disassoc_imminent=True): # Send a BSS transition to a station (device). nr_list should be an # array of tuples containing the BSS address and neighbor report. # Parsing the neighbor report is a bit ugly but it makes it more @@ -207,6 +207,10 @@ class HostapdCLI(object): # string could be used in both API's. pref = 1 cmd = self.cmdline + ['bss_tm_req', device] + + if disassoc_imminent: + cmd.append('disassoc_imminent=1') + for i in nr_list: addr = i[0] nr = i[1] diff --git a/autotests/util/iwd.py b/autotests/util/iwd.py @@ -299,6 +299,69 @@ class DeviceProvisioning(IWDDBusAbstract): def role(self): return self._properties['Role'] +class AccessPointDevice(IWDDBusAbstract): + ''' + Class represents net.connman.iwd.AccessPoint + ''' + _iface_name = IWD_AP_INTERFACE + + def start(self, ssid, psk): + self._iface.Start(ssid, psk, reply_handler=self._success, + error_handler=self._failure) + self._wait_for_async_op() + + IWD._wait_for_object_condition(self, 'obj.started == True') + + def start_profile(self, ssid): + self._iface.StartProfile(ssid, reply_handler=self._success, + error_handler=self._failure) + self._wait_for_async_op() + + IWD._wait_for_object_condition(self, 'obj.started == True') + + def stop(self): + self._iface.Stop(reply_handler=self._success, + error_handler=self._failure) + self._wait_for_async_op() + + IWD._wait_for_object_condition(self, 'obj.started == False') + + def scan(self): + self._iface.Scan(reply_handler=self._success, + error_handler=self._failure) + self._wait_for_async_op() + + IWD._wait_for_object_condition(self, 'obj.scanning == True') + IWD._wait_for_object_condition(self, 'obj.scanning == False') + + def get_ordered_networks(self): + return self._iface.GetOrderedNetworks() + + @property + def started(self): + return self._properties['Started'] + + @property + def name(self): + return self._properties['Name'] + + @property + def scanning(self): + return self._properties['Scanning'] + + @property + def frequency(self): + return self._properties['Frequency'] + + @property + def pairwise_ciphers(self): + return self._properties['PairwiseCiphers'] + + @property + def group_cipher(self): + return self._properties['GroupCipher'] + + class Device(IWDDBusAbstract): ''' Class represents a network device object: net.connman.iwd.Device @@ -312,6 +375,7 @@ class Device(IWDDBusAbstract): self._station_props = None self._station_debug_obj = None self._dpp_obj = None + self._ap_obj = None IWDDBusAbstract.__init__(self, *args, **kwargs) @@ -354,6 +418,17 @@ class Device(IWDDBusAbstract): return self._station_debug_obj + @property + def _ap(self): + if self._properties['Mode'] != 'ap': + self._prop_proxy.Set(IWD_DEVICE_INTERFACE, 'Mode', 'ap') + + if self._ap_obj is None: + self._ap_obj = AccessPointDevice(object_path=self._object_path, + namespace=self._namespace) + + return self._ap_obj + def _station_properties(self): if self._station_props is not None: return self._station_props @@ -446,13 +521,16 @@ class Device(IWDDBusAbstract): def scanning(self): ''' Reflects whether the device is currently scanning - for networks. net.connman.iwd.Network objects are - updated when this property goes from true to false. + for networks. For station devices net.connman.iwd.Network + objects are updated when this property goes from true to false @rtype: boolean ''' - props = self._station_properties() - return bool(props['Scanning']) + if self._properties['Mode'] == 'station': + props = self._station_properties() + return bool(props['Scanning']) + else: + return bool(self._ap.scanning) @property def autoconnect(self): @@ -469,12 +547,14 @@ class Device(IWDDBusAbstract): Possible exception: BusyEx FailedEx ''' - self._iface.Scan(dbus_interface=IWD_STATION_INTERFACE, + if self._properties['Mode'] == 'station': + self._iface.Scan(dbus_interface=IWD_STATION_INTERFACE, reply_handler=self._success, error_handler=self._failure) - - if wait: - self._wait_for_async_op() + if wait: + self._wait_for_async_op() + else: + self._ap.scan() def disconnect(self): '''Disconnect from the network @@ -501,6 +581,9 @@ class Device(IWDDBusAbstract): groups the maximum relative signal-strength is the main sorting factor. ''' + if self._properties['Mode'] == 'ap': + return self._ap.get_ordered_networks() + ordered_networks = [] if not full_scan: for bus_obj in self._station.GetOrderedNetworks(): @@ -519,7 +602,8 @@ class Device(IWDDBusAbstract): IWD._wait_for_object_condition(self, condition) try: - if full_scan: + # Do a full scan if instructed or if hostapd isn't being used + if full_scan or not ctx.hostapd: self.scan() else: self.debug_scan(ctx.get_frequencies()) @@ -604,20 +688,30 @@ class Device(IWDDBusAbstract): except Exception as e: raise _convert_dbus_ex(e) - self._ap_iface = dbus.Interface(self._bus.get_object(IWD_SERVICE, - self.device_path), - IWD_AP_INTERFACE) if psk: - self._ap_iface.Start(ssid, psk, reply_handler=self._success, - error_handler=self._failure) + self._ap.start(ssid, psk) else: - self._ap_iface.StartProfile(ssid, reply_handler=self._success, - error_handler=self._failure) - self._wait_for_async_op() + self._ap.start_profile(ssid) def stop_ap(self): self._prop_proxy.Set(IWD_DEVICE_INTERFACE, 'Mode', 'station') + IWD._wait_for_object_condition(self, "obj._properties['Mode'] == 'station'") + + @property + def group_cipher(self): + if self._properties['Mode'] != 'ap': + raise Exception('group_cipher only supported in AP mode') + + return self._ap.group_cipher + + @property + def pairwise_ciphers(self): + if self._properties['Mode'] != 'ap': + raise Exception('pairwise_cipher only supported in AP mode') + + return self._ap.pairwise_ciphers + def connect_hidden_network(self, name): '''Connect to a hidden network Possible exception: BusyEx @@ -689,14 +783,17 @@ class Device(IWDDBusAbstract): return self._device_provisioning.stop() def __str__(self, prefix = ''): - return prefix + 'Device: ' + self.device_path + '\n'\ + s = prefix + 'Device: ' + self.device_path + '\n'\ + prefix + '\tName:\t\t' + self.name + '\n'\ - + prefix + '\tAddress:\t' + self.address + '\n'\ - + prefix + '\tState:\t\t' + str(self.state) + '\n'\ + + prefix + '\tAddress:\t' + self.address + '\n' \ + prefix + '\tPowered:\t' + str(self.powered) + '\n'\ - + prefix + '\tConnected net:\t' + str(self.connected_network) +\ - '\n' + + prefix + '\tMode:\t\t' + self._properties['Mode'] + '\n' + + if self._properties['Mode'] == 'station': + s += prefix + '\tState:\t\t' + str(self.state) + '\n'\ + + prefix + '\tConnected net:\t' + str(self.connected_network) + '\n' + return s class Network(IWDDBusAbstract): '''Class represents a network object: net.connman.iwd.Network''' @@ -1160,7 +1257,7 @@ class IWD(AsyncOpAbstract): def wait_for_object_change(self, obj, from_str, to_str, max_wait = 50): ''' - Expects condition 'from_str' to evaluate true while waiting for 'to_str'. If + Wait for 'from_str' to evaluate true then waits for 'to_str'. If at any point during the wait 'from_str' evaluates false, an exception is raised. @@ -1180,9 +1277,8 @@ class IWD(AsyncOpAbstract): return False - # Does initial condition pass? - if not eval(from_str): - raise Exception("initial condition [%s] not met" % from_str) + # wait for initial condition + self._wait_for_object_condition(obj, from_str) ctx.non_block_wait(_eval_from_to, max_wait, obj, from_str, to_str, exception=TimeoutError('[' + to_str + ']'\ diff --git a/autotests/util/wpas.py b/autotests/util/wpas.py @@ -72,7 +72,6 @@ class Wpas: def _check_event(self, event): if not event and len(self._rx_data) >= 1: - print("returning %s" % self._rx_data[0]) return self._rx_data[0] for e in self._rx_data: diff --git a/client/ap.c b/client/ap.c @@ -36,6 +36,9 @@ struct ap { bool started; char *name; bool scanning; + uint32_t freq; + char *pairwise; + char *group; }; static void *ap_create(void) @@ -50,6 +53,12 @@ static void ap_destroy(void *data) if (ap->name) l_free(ap->name); + if (ap->pairwise) + l_free(ap->pairwise); + + if (ap->group) + l_free(ap->group); + l_free(ap); } @@ -126,10 +135,91 @@ static const char *get_scanning_tostr(const void *data) return ap->scanning ? "yes" : "no"; } +static void update_freq(void *data, struct l_dbus_message_iter *variant) +{ + struct ap *ap = data; + uint32_t value; + + if (!l_dbus_message_iter_get_variant(variant, "u", &value)) { + ap->freq = 0; + + return; + } + + ap->freq = value; +} + +static const char *get_freq_tostr(const void *data) +{ + const struct ap *ap = data; + static char str[5]; + + sprintf(str, "%u", ap->freq); + + return str; +} + +static void update_pairwise(void *data, struct l_dbus_message_iter *variant) +{ + struct ap *ap = data; + char *value; + + if (ap->pairwise) + l_free(ap->pairwise); + + if (!l_dbus_message_iter_get_variant(variant, "s", &value)) { + ap->pairwise = NULL; + + return; + } + + ap->pairwise = l_strdup(value); +} + +static const char *get_pairwise_tostr(const void *data) +{ + const struct ap *ap = data; + + if (!ap->pairwise) + return ""; + + return ap->pairwise; +} + +static void update_group(void *data, struct l_dbus_message_iter *variant) +{ + struct ap *ap = data; + char *value; + + if (ap->group) + l_free(ap->group); + + if (!l_dbus_message_iter_get_variant(variant, "s", &value)) { + ap->group = NULL; + + return; + } + + ap->group = l_strdup(value); +} + +static const char *get_group_tostr(const void *data) +{ + const struct ap *ap = data; + + if (!ap->group) + return ""; + + return ap->group; +} + static const struct proxy_interface_property ap_properties[] = { { "Started", "b", update_started, get_started_tostr }, { "Name", "s", update_name, get_name_tostr }, { "Scanning", "b", update_scanning, get_scanning_tostr }, + { "Frequency", "u", update_freq, get_freq_tostr }, + { "PairwiseCiphers", "s", update_pairwise, get_pairwise_tostr }, + { "GroupCipher", "s", update_group, get_group_tostr }, { } }; diff --git a/client/display.c b/client/display.c @@ -30,6 +30,7 @@ #include <sys/stat.h> #include <sys/ioctl.h> #include <unistd.h> +#include <wchar.h> #include <readline/history.h> #include <readline/readline.h> @@ -387,39 +388,72 @@ static unsigned int color_end(char *s) } /* - * Finds last space in 's' before 'max' characters, terminates at that index, + * Finds last space in 's' before 'width' characters, terminates at that index, * and returns a new string to be printed on the next line. * - * 'max' should be set to the column width, but is also an out parameter since - * this width can be updated if colored escapes are detected. + * 'new_width' will be updated to include extra bytes for color escapes or + * wide characters if found. * * Any colored escapes found are set to 'color_out' so they can be re-enabled * on the next line. */ -static char* next_line(char *s, unsigned int *max, char **color_out) +static char* next_line(char *s, unsigned int width, unsigned int *new_width, + char **color_out) { - unsigned int i; + unsigned int i = 0; int last_space = -1; int last_color = -1; + unsigned int s_len = strlen(s); + unsigned int color_adjust = 0; + char *ret; + + *new_width = width; + *color_out = NULL; /* Find the last space before 'max', as well as any color */ - for (i = 0; i <= *max && s[i] != '\0'; i++) { - if (s[i] == ' ') - last_space = i; - else if (s[i] == 0x1b) { + while (i <= *new_width && i < s_len) { + int sequence_len; + int sequence_columns; + wchar_t w; + + if (s[i] == 0x1b) { + sequence_len = color_end(s + i); /* color escape won't count for column width */ - *max += color_end(s + i); + sequence_columns = 0; last_color = i; + + /* + * Color after a space. If the line gets broken this + * will need to be removed off new_width since it will + * appear on the next line. + */ + if (last_space != -1) + color_adjust += sequence_len; + + } else { + if (s[i] == ' ') { + last_space = i; + /* Any past colors will appear on this line */ + color_adjust = 0; + } + + sequence_len = l_utf8_get_codepoint(&s[i], s_len - i, + &w); + sequence_columns = wcwidth(w); } + + /* Compensate max bytes */ + *new_width += sequence_len - sequence_columns; + i += sequence_len; } /* Reached the end of the string within the column bounds */ - if (i <= *max) + if (i <= *new_width) return NULL; /* Not anywhere nice to split the line */ if (last_space == -1) - last_space = *max - 1; + last_space = *new_width; /* * Only set the color if it occurred prior to the last space. If after, @@ -428,12 +462,14 @@ static char* next_line(char *s, unsigned int *max, char **color_out) if (last_color != -1 && last_space >= last_color) *color_out = l_strndup(s + last_color, color_end(s + last_color)); - else - *color_out = NULL; + else if (last_color != -1 && last_space < last_color) + *new_width -= color_adjust; - s[last_space] = '\0'; + ret = l_strdup(s + last_space + 1); - return l_strdup(s + last_space + 1); + s[last_space + 1] = '\0'; + + return ret; } struct table_entry { @@ -450,7 +486,7 @@ static int entry_append(struct table_entry *e, char *line_buf) { char *value = e->next; unsigned int ret = 0; - unsigned int width = e->width; + unsigned int new_width; /* Empty line */ if (!value) @@ -464,10 +500,10 @@ static int entry_append(struct table_entry *e, char *line_buf) } /* Advance entry to next line, and terminate current */ - e->next = next_line(value, &width, &e->color); + e->next = next_line(value, e->width, &new_width, &e->color); /* Append current line */ - ret += sprintf(line_buf + ret, "%-*s ", width, value); + ret += sprintf(line_buf + ret, "%-*s ", new_width, value); l_free(value); @@ -513,9 +549,17 @@ void display_table_row(const char *margin, unsigned int ncolumns, ...) for (i = 0; i < ncolumns; i++) { struct table_entry *e = &entries[i]; + char *v; e->width = va_arg(va, unsigned int); - e->next = l_strdup(va_arg(va, char*)); + v = va_arg(va, char *); + + if (!l_utf8_validate(v, strlen(v), NULL)) { + display_error("Invalid utf-8 string!"); + goto done; + } + + e->next = l_strdup(v); str += entry_append(e, str); } @@ -546,9 +590,13 @@ void display_table_row(const char *margin, unsigned int ncolumns, ...) str = buf; } +done: for (i = 0; i < ncolumns; i++) { if (entries[i].color) l_free(entries[i].color); + + if (entries[i].next) + l_free(entries[i].next); } } diff --git a/client/main.c b/client/main.c @@ -25,6 +25,7 @@ #endif #include <errno.h> +#include <locale.h> #include <signal.h> #include <ell/ell.h> @@ -50,6 +51,8 @@ int main(int argc, char *argv[]) { bool all_done; + setlocale(LC_CTYPE, ""); + if (!l_main_init()) return EXIT_FAILURE; diff --git a/client/station.c b/client/station.c @@ -217,15 +217,9 @@ static void display_station(const char *device_name, 47, network_get_name(station->connected_network)); display_addresses(device_name); - - /* - * If connected the diagnostic interface is presumably up so - * don't add the table footer just yet. - */ - return; } - display_table_footer(); + /* The table footer is handled by cmd_show. */ } static void display_station_inline(const char *margin, const void *data) diff --git a/configure.ac b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.69]) -AC_INIT([iwd],[1.30]) +AC_INIT([iwd],[2.0]) AC_CONFIG_HEADERS(config.h) AC_CONFIG_AUX_DIR(build-aux) @@ -268,7 +268,7 @@ if (test "${enable_external_ell}" = "yes"); then test "${enable_monitor}" != "no" || test "${enable_wired}" = "yes" || test "${enable_hwsim}" = "yes"); then - ell_min_version="0.53" + ell_min_version="0.54" else ell_min_version="0.5" fi diff --git a/doc/access-point-api.txt b/doc/access-point-api.txt @@ -67,3 +67,19 @@ Properties boolean Started [readonly] boolean Scanning [readonly] Reflects whether the access point is scanning. + + uint32 Frequency [readonly, optional] + + The frequency that the Access Point is operating on. + + array{string} PairwiseCiphers [readonly, optional] + + List of pairwise ciphers the access point supports. + The same format as setting a list of ciphers for an AP + profile, i.e. TKIP, CCMP-128, GCMP-128, CCMP-256 etc. + + string GroupCipher [readonly, optional] + + The group cipher suite the access point is using. + Possible values are the same as what could be included + in the PairwiseCiphers list. diff --git a/doc/agent-api.txt b/doc/agent-api.txt @@ -145,50 +145,121 @@ Methods void Release() [noreply] agent, because when this method gets called it has already been unregistered. - void ConfigureIPv4(object device, string interface, dict config) - - This method gets called during a connection setup - when a new set of IPv4 configuration values is to - be written to a network interface. The connection - is aborted if the method call returns an error or - times out. The 'config' dictionary (a{sv}) maps - string keys to values of types defined per key. - - The following key/value pairs are used, but more + void ConfigureIPv4(object device, dict config) + + This method gets called during connection setup + and later while the connection is operational + whenever a new set of IPv4 configuration values is to + be written to a network interface. The connection is + aborted if the method call returns an error or times + out. + + In case of a station-mode connection, the 'device' + parameter points at an object with a + net.connman.iwd.Device interface whose Name property + contains the name of network interface. In case of a + P2P connection, the object will have + a net.connman.iwd.p2p.Peer interface whose + ConnectectedInterface property contains the name of + the target network interface. + + The 'config' dictionary (a{sv}) maps string keys to + values of types defined per key. Each call receives + the full set of values which supersede those from + previous calls. + + The following key/value pairs are defined, but more may be added in future versions. string Method - Indicates whether the local address was set statically (value "static") or obtained automatically such as through DHCP (value "auto"). - Even when the address was obtained from the remote + Even when addresses were obtained from the remote end some configuration bits, such as DNS addresses, may have been overridden locally. - string Address - Local IP address string. - - byte PrefixLength - Holds the prefix-length of the - local subnet. For IPv4 this maps to the netmask. + array(dict) Addresses - Local IP addresses. Each + address is described by a set of key/value properties + as documented further down. - string Gateway [optional] - Local subnet's gateway - address if one exists. + array(dict) Routes - Routes for on-link and off-link + prefixes/subnets and default routers. Each route is + described by a set of key/value properties as + documented further down. array(string) DomainNameServers [optional] - Holds - the list of DNS addresses configured if any exist. + the list of DNS server addresses configured if any + exist. array(string) DomainNames [optional] - Holds the network's local domain names if any exist. + string MDNS [optional] - One of "true", "false" and + "resolve". Controls whether Multicast DNS support is + to be enabled on the link. When set to "resolve", + only resolution is enabled, but not host or service + registration and announcement (see systemd.network(5).) + + The following properties are defined for local + addresses, but more may be added in the future: + + string Address - Holds the IP address string. + + byte PrefixLength [optional] - Prefix length + associated with the address's subnet (IPv4 only). + + string Broadcast [optional] - Broadcast address + associated with the address's subnet (IPv4 only). + + uint32 ValidLifetime [optional] - Remaining validity + and ownership time for this address assignment/lease, + in seconds at the time of the method call. + If absent the address doesn't expire. + + uint32 PreferredLifetime [optional] - Number of + seconds left at the time of the method call for this + address to be preferred over other addresses. + + The following properties are defined for routes, + but more may be added in the future: + + string, byte Destination [optional] - Holds the + route's destination IP prefix string and the prefix + length in bits. Absent for default routes. + + string Router [optional] - Holds the router's IP + address. Absent for on-link routes. + + string PreferredSource [optional] - Route source IP + address. + + uint32 Lifetime [optional] - Remaining route validity + time in seconds at the time of the method call. + If absent the route doesn't expire. + + uint32 Priority - Relative route priority. + + byte Preference [optional] - ICMPv6 route preference: + 0 for medium, 1 for high and 3 for low. + + uint32 MTU [optional] - Router MTU. + Possible Errors: net.connman.iwd.Agent.Error.Canceled + net.connman.iwd.Agent.Error.Failed - void ConfigureIPv6(object device, string interface, dict config) + void ConfigureIPv6(object device, dict config) Same as ConfigureIPv4 above but for IPv6. - void Cancel(object device, string interface, - string reason) [noreply] + void CancelIPv4(object device, string reason) [noreply] - This method gets called to indicate that the connection - request failed before a reply was returned. The - argument will indicate why the request is being - cancelled and may be "out-of-range", "user-canceled", - "timed-out" or "shutdown". + This method gets called to indicate that the network + configuration was aborted before a reply was received + for an ongoing ConfigureIPv4 or ConfigureIPv6 call. + The last argument will indicate why the request is being + cancelled and may be one of: "aborted", "superseded", + "timed-out". + + void CancelIPv6(object device, string reason) [noreply] + + Same as CancelIPv4 above but for IPv6. diff --git a/doc/ip-configuration-api.txt b/doc/ip-configuration-api.txt @@ -1,47 +0,0 @@ -IP Configuration hierarchy -=============================== - -Service net.connman.iwd -Interface net.connman.iwd.IPv4Configuration [Experimental] -Interface net.connman.iwd.IPv6Configuration [Experimental] -Object path /net/connman/iwd/{phy0,phy1,...}/{1,2,...} -Object path /net/connman/iwd/{phy0,phy1,...}/p2p_peers/{aa_bb_cc_dd_ee_ff} - -The interfaces net.connman.iwd.IPv4Configuration and -net.connman.iwd.IPv6Configuration currently have the same sets of methods, -signals and properties. In station mode, when network configuration is -enabled there may be one or both interfaces present on a device object in -connected state depending on if IPv4 and IPv6 addresses have both been -configured. In P2P mode only net.connman.iwd.IPv4Configuration is used. - -Properties string Method [readonly] - - Indicates whether the local address was set - statically (value "static") or obtained automatically - such as through DHCP (value "auto"). Even when the - address was obtained from the remote end some - configuration bits, such as DNS addresses, may have - been overridden locally. - - string Address [readonly] - - Holds the local IP address. - - byte PrefixLength [readonly] - - Holds the prefix-length of the local subnet. For - IPv4 this maps to the netmask. - - string Gateway [readonly, optional] - - Holds the gateway address for the subnet if one - exists. - - array(string) DomainNameServers [readonly, optional] - - Holds the list of domain name server addresses - configured if any. - - array(string) DomainNames [readonly, optional] - - Holds the network's local domain names if any exist. diff --git a/doc/station-diagnostic-api.txt b/doc/station-diagnostic-api.txt @@ -43,6 +43,14 @@ Methods dict GetDiagnostics() TxMCS [optional] - Transmitting MCS index + PairwiseCipher [optional] - The pairwise cipher chosen + for this connection. Possible values are: + - CCMP-128 + - TKIP + - GCMP-128 + - GCMP-256 + - CCMP-256 + Possible errors: net.connman.iwd.Busy net.connman.iwd.Failed net.connman.iwd.NotConnected diff --git a/linux/nl80211.h b/linux/nl80211.h @@ -11,7 +11,7 @@ * Copyright 2008 Jouni Malinen <jouni.malinen@atheros.com> * Copyright 2008 Colin McCabe <colin@cozybit.com> * Copyright 2015-2017 Intel Deutschland GmbH - * Copyright (C) 2018-2020 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -301,6 +301,40 @@ */ /** + * DOC: FILS shared key crypto offload + * + * This feature is applicable to drivers running in AP mode. + * + * FILS shared key crypto offload can be advertised by drivers by setting + * @NL80211_EXT_FEATURE_FILS_CRYPTO_OFFLOAD flag. The drivers that support + * FILS shared key crypto offload should be able to encrypt and decrypt + * association frames for FILS shared key authentication as per IEEE 802.11ai. + * With this capability, for FILS key derivation, drivers depend on userspace. + * + * After FILS key derivation, userspace shares the FILS AAD details with the + * driver and the driver stores the same to use in decryption of association + * request and in encryption of association response. The below parameters + * should be given to the driver in %NL80211_CMD_SET_FILS_AAD. + * %NL80211_ATTR_MAC - STA MAC address, used for storing FILS AAD per STA + * %NL80211_ATTR_FILS_KEK - Used for encryption or decryption + * %NL80211_ATTR_FILS_NONCES - Used for encryption or decryption + * (STA Nonce 16 bytes followed by AP Nonce 16 bytes) + * + * Once the association is done, the driver cleans the FILS AAD data. + */ + +/** + * DOC: Multi-Link Operation + * + * In Multi-Link Operation, a connection between to MLDs utilizes multiple + * links. To use this in nl80211, various commands and responses now need + * to or will include the new %NL80211_ATTR_MLO_LINKS attribute. + * Additionally, various commands that need to operate on a specific link + * now need to be given the %NL80211_ATTR_MLO_LINK_ID attribute, e.g. to + * use %NL80211_CMD_START_AP or similar functions. + */ + +/** * enum nl80211_commands - supported nl80211 commands * * @NL80211_CMD_UNSPEC: unspecified command to catch errors @@ -337,17 +371,28 @@ * @NL80211_CMD_DEL_INTERFACE: Virtual interface was deleted, has attributes * %NL80211_ATTR_IFINDEX and %NL80211_ATTR_WIPHY. Can also be sent from * userspace to request deletion of a virtual interface, then requires - * attribute %NL80211_ATTR_IFINDEX. + * attribute %NL80211_ATTR_IFINDEX. If multiple BSSID advertisements are + * enabled using %NL80211_ATTR_MBSSID_CONFIG, %NL80211_ATTR_MBSSID_ELEMS, + * and if this command is used for the transmitting interface, then all + * the non-transmitting interfaces are deleted as well. * * @NL80211_CMD_GET_KEY: Get sequence counter information for a key specified - * by %NL80211_ATTR_KEY_IDX and/or %NL80211_ATTR_MAC. + * by %NL80211_ATTR_KEY_IDX and/or %NL80211_ATTR_MAC. %NL80211_ATTR_MAC + * represents peer's MLD address for MLO pairwise key. For MLO group key, + * the link is identified by %NL80211_ATTR_MLO_LINK_ID. * @NL80211_CMD_SET_KEY: Set key attributes %NL80211_ATTR_KEY_DEFAULT, * %NL80211_ATTR_KEY_DEFAULT_MGMT, or %NL80211_ATTR_KEY_THRESHOLD. + * For MLO connection, the link to set default key is identified by + * %NL80211_ATTR_MLO_LINK_ID. * @NL80211_CMD_NEW_KEY: add a key with given %NL80211_ATTR_KEY_DATA, * %NL80211_ATTR_KEY_IDX, %NL80211_ATTR_MAC, %NL80211_ATTR_KEY_CIPHER, - * and %NL80211_ATTR_KEY_SEQ attributes. + * and %NL80211_ATTR_KEY_SEQ attributes. %NL80211_ATTR_MAC represents + * peer's MLD address for MLO pairwise key. The link to add MLO + * group key is identified by %NL80211_ATTR_MLO_LINK_ID. * @NL80211_CMD_DEL_KEY: delete a key identified by %NL80211_ATTR_KEY_IDX - * or %NL80211_ATTR_MAC. + * or %NL80211_ATTR_MAC. %NL80211_ATTR_MAC represents peer's MLD address + * for MLO pairwise key. The link to delete group key is identified by + * %NL80211_ATTR_MLO_LINK_ID. * * @NL80211_CMD_GET_BEACON: (not used) * @NL80211_CMD_SET_BEACON: change the beacon on an access point interface @@ -727,6 +772,13 @@ * %NL80211_ATTR_CSA_C_OFFSETS_TX is an array of offsets to CSA * counters which will be updated to the current value. This attribute * is used during CSA period. + * For TX on an MLD, the frequency can be omitted and the link ID be + * specified, or if transmitting to a known peer MLD (with MLD addresses + * in the frame) both can be omitted and the link will be selected by + * lower layers. + * For RX notification, %NL80211_ATTR_RX_HW_TIMESTAMP may be included to + * indicate the frame RX timestamp and %NL80211_ATTR_TX_HW_TIMESTAMP may + * be included to indicate the ack TX timestamp. * @NL80211_CMD_FRAME_WAIT_CANCEL: When an off-channel TX was requested, this * command may be used with the corresponding cookie to cancel the wait * time if it is known that it is no longer necessary. This command is @@ -737,7 +789,9 @@ * transmitted with %NL80211_CMD_FRAME. %NL80211_ATTR_COOKIE identifies * the TX command and %NL80211_ATTR_FRAME includes the contents of the * frame. %NL80211_ATTR_ACK flag is included if the recipient acknowledged - * the frame. + * the frame. %NL80211_ATTR_TX_HW_TIMESTAMP may be included to indicate the + * tx timestamp and %NL80211_ATTR_RX_HW_TIMESTAMP may be included to + * indicate the ack RX timestamp. * @NL80211_CMD_ACTION_TX_STATUS: Alias for @NL80211_CMD_FRAME_TX_STATUS for * backward compatibility. * @@ -1082,6 +1136,12 @@ * has been received. %NL80211_ATTR_FRAME is used to specify the * frame contents. The frame is the raw EAPoL data, without ethernet or * 802.11 headers. + * For an MLD transmitter, the %NL80211_ATTR_MLO_LINK_ID may be given and + * its effect will depend on the destination: If the destination is known + * to be an MLD, this will be used as a hint to select the link to transmit + * the frame on. If the destination is not an MLD, this will select both + * the link to transmit on and the source address will be set to the link + * address of that link. * When used as an event indication %NL80211_ATTR_CONTROL_PORT_ETHERTYPE, * %NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT and %NL80211_ATTR_MAC are added * indicating the protocol type of the received frame; whether the frame @@ -1185,6 +1245,42 @@ * passed using %NL80211_ATTR_SAR_SPEC. %NL80211_ATTR_WIPHY is used to * specify the wiphy index to be applied to. * + * @NL80211_CMD_OBSS_COLOR_COLLISION: This notification is sent out whenever + * mac80211/drv detects a bss color collision. + * + * @NL80211_CMD_COLOR_CHANGE_REQUEST: This command is used to indicate that + * userspace wants to change the BSS color. + * + * @NL80211_CMD_COLOR_CHANGE_STARTED: Notify userland, that a color change has + * started + * + * @NL80211_CMD_COLOR_CHANGE_ABORTED: Notify userland, that the color change has + * been aborted + * + * @NL80211_CMD_COLOR_CHANGE_COMPLETED: Notify userland that the color change + * has completed + * + * @NL80211_CMD_SET_FILS_AAD: Set FILS AAD data to the driver using - + * &NL80211_ATTR_MAC - for STA MAC address + * &NL80211_ATTR_FILS_KEK - for KEK + * &NL80211_ATTR_FILS_NONCES - for FILS Nonces + * (STA Nonce 16 bytes followed by AP Nonce 16 bytes) + * + * @NL80211_CMD_ASSOC_COMEBACK: notification about an association + * temporal rejection with comeback. The event includes %NL80211_ATTR_MAC + * to describe the BSSID address of the AP and %NL80211_ATTR_TIMEOUT to + * specify the timeout value. + * + * @NL80211_CMD_ADD_LINK: Add a new link to an interface. The + * %NL80211_ATTR_MLO_LINK_ID attribute is used for the new link. + * @NL80211_CMD_REMOVE_LINK: Remove a link from an interface. This may come + * without %NL80211_ATTR_MLO_LINK_ID as an easy way to remove all links + * in preparation for e.g. roaming to a regular (non-MLO) AP. + * + * @NL80211_CMD_ADD_LINK_STA: Add a link to an MLD station + * @NL80211_CMD_MODIFY_LINK_STA: Modify a link of an MLD station + * @NL80211_CMD_REMOVE_LINK_STA: Remove a link of an MLD station + * * @NL80211_CMD_MAX: highest used command number * @__NL80211_CMD_AFTER_LAST: internal use */ @@ -1417,6 +1513,25 @@ enum nl80211_commands { NL80211_CMD_SET_SAR_SPECS, + NL80211_CMD_OBSS_COLOR_COLLISION, + + NL80211_CMD_COLOR_CHANGE_REQUEST, + + NL80211_CMD_COLOR_CHANGE_STARTED, + NL80211_CMD_COLOR_CHANGE_ABORTED, + NL80211_CMD_COLOR_CHANGE_COMPLETED, + + NL80211_CMD_SET_FILS_AAD, + + NL80211_CMD_ASSOC_COMEBACK, + + NL80211_CMD_ADD_LINK, + NL80211_CMD_REMOVE_LINK, + + NL80211_CMD_ADD_LINK_STA, + NL80211_CMD_MODIFY_LINK_STA, + NL80211_CMD_REMOVE_LINK_STA, + /* add new commands above here */ /* used to define NL80211_CMD_MAX below */ @@ -2276,8 +2391,10 @@ enum nl80211_commands { * * @NL80211_ATTR_IFTYPE_EXT_CAPA: Nested attribute of the following attributes: * %NL80211_ATTR_IFTYPE, %NL80211_ATTR_EXT_CAPA, - * %NL80211_ATTR_EXT_CAPA_MASK, to specify the extended capabilities per - * interface type. + * %NL80211_ATTR_EXT_CAPA_MASK, to specify the extended capabilities and + * other interface-type specific capabilities per interface type. For MLO, + * %NL80211_ATTR_EML_CAPABILITY and %NL80211_ATTR_MLD_CAPA_AND_OPS are + * present. * * @NL80211_ATTR_MU_MIMO_GROUP_DATA: array of 24 bytes that defines a MU-MIMO * groupID for monitor mode. @@ -2413,7 +2530,9 @@ enum nl80211_commands { * space supports external authentication. This attribute shall be used * with %NL80211_CMD_CONNECT and %NL80211_CMD_START_AP request. The driver * may offload authentication processing to user space if this capability - * is indicated in the respective requests from the user space. + * is indicated in the respective requests from the user space. (This flag + * attribute deprecated for %NL80211_CMD_START_AP, use + * %NL80211_ATTR_AP_SETTINGS_FLAGS) * * @NL80211_ATTR_NSS: Station's New/updated RX_NSS value notified using this * u8 attribute. This is used with %NL80211_CMD_STA_OPMODE_CHANGED. @@ -2560,6 +2679,76 @@ enum nl80211_commands { * disassoc events to indicate that an immediate reconnect to the AP * is desired. * + * @NL80211_ATTR_OBSS_COLOR_BITMAP: bitmap of the u64 BSS colors for the + * %NL80211_CMD_OBSS_COLOR_COLLISION event. + * + * @NL80211_ATTR_COLOR_CHANGE_COUNT: u8 attribute specifying the number of TBTT's + * until the color switch event. + * @NL80211_ATTR_COLOR_CHANGE_COLOR: u8 attribute specifying the color that we are + * switching to + * @NL80211_ATTR_COLOR_CHANGE_ELEMS: Nested set of attributes containing the IE + * information for the time while performing a color switch. + * + * @NL80211_ATTR_MBSSID_CONFIG: Nested attribute for multiple BSSID + * advertisements (MBSSID) parameters in AP mode. + * Kernel uses this attribute to indicate the driver's support for MBSSID + * and enhanced multi-BSSID advertisements (EMA AP) to the userspace. + * Userspace should use this attribute to configure per interface MBSSID + * parameters. + * See &enum nl80211_mbssid_config_attributes for details. + * + * @NL80211_ATTR_MBSSID_ELEMS: Nested parameter to pass multiple BSSID elements. + * Mandatory parameter for the transmitting interface to enable MBSSID. + * Optional for the non-transmitting interfaces. + * + * @NL80211_ATTR_RADAR_BACKGROUND: Configure dedicated offchannel chain + * available for radar/CAC detection on some hw. This chain can't be used + * to transmit or receive frames and it is bounded to a running wdev. + * Background radar/CAC detection allows to avoid the CAC downtime + * switching on a different channel during CAC detection on the selected + * radar channel. + * + * @NL80211_ATTR_AP_SETTINGS_FLAGS: u32 attribute contains ap settings flags, + * enumerated in &enum nl80211_ap_settings_flags. This attribute shall be + * used with %NL80211_CMD_START_AP request. + * + * @NL80211_ATTR_EHT_CAPABILITY: EHT Capability information element (from + * association request when used with NL80211_CMD_NEW_STATION). Can be set + * only if %NL80211_STA_FLAG_WME is set. + * + * @NL80211_ATTR_MLO_LINK_ID: A (u8) link ID for use with MLO, to be used with + * various commands that need a link ID to operate. + * @NL80211_ATTR_MLO_LINKS: A nested array of links, each containing some + * per-link information and a link ID. + * @NL80211_ATTR_MLD_ADDR: An MLD address, used with various commands such as + * authenticate/associate. + * + * @NL80211_ATTR_MLO_SUPPORT: Flag attribute to indicate user space supports MLO + * connection. Used with %NL80211_CMD_CONNECT. If this attribute is not + * included in NL80211_CMD_CONNECT drivers must not perform MLO connection. + * + * @NL80211_ATTR_MAX_NUM_AKM_SUITES: U16 attribute. Indicates maximum number of + * AKM suites allowed for %NL80211_CMD_CONNECT, %NL80211_CMD_ASSOCIATE and + * %NL80211_CMD_START_AP in %NL80211_CMD_GET_WIPHY response. If this + * attribute is not present userspace shall consider maximum number of AKM + * suites allowed as %NL80211_MAX_NR_AKM_SUITES which is the legacy maximum + * number prior to the introduction of this attribute. + * + * @NL80211_ATTR_EML_CAPABILITY: EML Capability information (u16) + * @NL80211_ATTR_MLD_CAPA_AND_OPS: MLD Capabilities and Operations (u16) + * + * @NL80211_ATTR_TX_HW_TIMESTAMP: Hardware timestamp for TX operation in + * nanoseconds (u64). This is the device clock timestamp so it will + * probably reset when the device is stopped or the firmware is reset. + * When used with %NL80211_CMD_FRAME_TX_STATUS, indicates the frame TX + * timestamp. When used with %NL80211_CMD_FRAME RX notification, indicates + * the ack TX timestamp. + * @NL80211_ATTR_RX_HW_TIMESTAMP: Hardware timestamp for RX operation in + * nanoseconds (u64). This is the device clock timestamp so it will + * probably reset when the device is stopped or the firmware is reset. + * When used with %NL80211_CMD_FRAME_TX_STATUS, indicates the ack RX + * timestamp. When used with %NL80211_CMD_FRAME RX notification, indicates + * the incoming frame RX timestamp. * @NUM_NL80211_ATTR: total number of nl80211_attrs available * @NL80211_ATTR_MAX: highest attribute number currently defined * @__NL80211_ATTR_AFTER_LAST: internal use @@ -3057,6 +3246,37 @@ enum nl80211_attrs { NL80211_ATTR_DISABLE_HE, + NL80211_ATTR_OBSS_COLOR_BITMAP, + + NL80211_ATTR_COLOR_CHANGE_COUNT, + NL80211_ATTR_COLOR_CHANGE_COLOR, + NL80211_ATTR_COLOR_CHANGE_ELEMS, + + NL80211_ATTR_MBSSID_CONFIG, + NL80211_ATTR_MBSSID_ELEMS, + + NL80211_ATTR_RADAR_BACKGROUND, + + NL80211_ATTR_AP_SETTINGS_FLAGS, + + NL80211_ATTR_EHT_CAPABILITY, + + NL80211_ATTR_DISABLE_EHT, + + NL80211_ATTR_MLO_LINKS, + NL80211_ATTR_MLO_LINK_ID, + NL80211_ATTR_MLD_ADDR, + + NL80211_ATTR_MLO_SUPPORT, + + NL80211_ATTR_MAX_NUM_AKM_SUITES, + + NL80211_ATTR_EML_CAPABILITY, + NL80211_ATTR_MLD_CAPA_AND_OPS, + + NL80211_ATTR_TX_HW_TIMESTAMP, + NL80211_ATTR_RX_HW_TIMESTAMP, + /* add attributes here, update the policy in nl80211.c */ __NL80211_ATTR_AFTER_LAST, @@ -3111,7 +3331,14 @@ enum nl80211_attrs { #define NL80211_HE_MIN_CAPABILITY_LEN 16 #define NL80211_HE_MAX_CAPABILITY_LEN 54 #define NL80211_MAX_NR_CIPHER_SUITES 5 + +/* + * NL80211_MAX_NR_AKM_SUITES is obsolete when %NL80211_ATTR_MAX_NUM_AKM_SUITES + * present in %NL80211_CMD_GET_WIPHY response. + */ #define NL80211_MAX_NR_AKM_SUITES 2 +#define NL80211_EHT_MIN_CAPABILITY_LEN 13 +#define NL80211_EHT_MAX_CAPABILITY_LEN 51 #define NL80211_MIN_REMAIN_ON_CHANNEL_TIME 10 @@ -3139,7 +3366,7 @@ enum nl80211_attrs { * and therefore can't be created in the normal ways, use the * %NL80211_CMD_START_P2P_DEVICE and %NL80211_CMD_STOP_P2P_DEVICE * commands to create and destroy one - * @NL80211_IF_TYPE_OCB: Outside Context of a BSS + * @NL80211_IFTYPE_OCB: Outside Context of a BSS * This mode corresponds to the MIB variable dot11OCBActivated=true * @NL80211_IFTYPE_NAN: NAN device interface type (not a netdev) * @NL80211_IFTYPE_MAX: highest interface type number currently defined @@ -3281,6 +3508,56 @@ enum nl80211_he_ru_alloc { }; /** + * enum nl80211_eht_gi - EHT guard interval + * @NL80211_RATE_INFO_EHT_GI_0_8: 0.8 usec + * @NL80211_RATE_INFO_EHT_GI_1_6: 1.6 usec + * @NL80211_RATE_INFO_EHT_GI_3_2: 3.2 usec + */ +enum nl80211_eht_gi { + NL80211_RATE_INFO_EHT_GI_0_8, + NL80211_RATE_INFO_EHT_GI_1_6, + NL80211_RATE_INFO_EHT_GI_3_2, +}; + +/** + * enum nl80211_eht_ru_alloc - EHT RU allocation values + * @NL80211_RATE_INFO_EHT_RU_ALLOC_26: 26-tone RU allocation + * @NL80211_RATE_INFO_EHT_RU_ALLOC_52: 52-tone RU allocation + * @NL80211_RATE_INFO_EHT_RU_ALLOC_52P26: 52+26-tone RU allocation + * @NL80211_RATE_INFO_EHT_RU_ALLOC_106: 106-tone RU allocation + * @NL80211_RATE_INFO_EHT_RU_ALLOC_106P26: 106+26 tone RU allocation + * @NL80211_RATE_INFO_EHT_RU_ALLOC_242: 242-tone RU allocation + * @NL80211_RATE_INFO_EHT_RU_ALLOC_484: 484-tone RU allocation + * @NL80211_RATE_INFO_EHT_RU_ALLOC_484P242: 484+242 tone RU allocation + * @NL80211_RATE_INFO_EHT_RU_ALLOC_996: 996-tone RU allocation + * @NL80211_RATE_INFO_EHT_RU_ALLOC_996P484: 996+484 tone RU allocation + * @NL80211_RATE_INFO_EHT_RU_ALLOC_996P484P242: 996+484+242 tone RU allocation + * @NL80211_RATE_INFO_EHT_RU_ALLOC_2x996: 2x996-tone RU allocation + * @NL80211_RATE_INFO_EHT_RU_ALLOC_2x996P484: 2x996+484 tone RU allocation + * @NL80211_RATE_INFO_EHT_RU_ALLOC_3x996: 3x996-tone RU allocation + * @NL80211_RATE_INFO_EHT_RU_ALLOC_3x996P484: 3x996+484 tone RU allocation + * @NL80211_RATE_INFO_EHT_RU_ALLOC_4x996: 4x996-tone RU allocation + */ +enum nl80211_eht_ru_alloc { + NL80211_RATE_INFO_EHT_RU_ALLOC_26, + NL80211_RATE_INFO_EHT_RU_ALLOC_52, + NL80211_RATE_INFO_EHT_RU_ALLOC_52P26, + NL80211_RATE_INFO_EHT_RU_ALLOC_106, + NL80211_RATE_INFO_EHT_RU_ALLOC_106P26, + NL80211_RATE_INFO_EHT_RU_ALLOC_242, + NL80211_RATE_INFO_EHT_RU_ALLOC_484, + NL80211_RATE_INFO_EHT_RU_ALLOC_484P242, + NL80211_RATE_INFO_EHT_RU_ALLOC_996, + NL80211_RATE_INFO_EHT_RU_ALLOC_996P484, + NL80211_RATE_INFO_EHT_RU_ALLOC_996P484P242, + NL80211_RATE_INFO_EHT_RU_ALLOC_2x996, + NL80211_RATE_INFO_EHT_RU_ALLOC_2x996P484, + NL80211_RATE_INFO_EHT_RU_ALLOC_3x996, + NL80211_RATE_INFO_EHT_RU_ALLOC_3x996P484, + NL80211_RATE_INFO_EHT_RU_ALLOC_4x996, +}; + +/** * enum nl80211_rate_info - bitrate information * * These attribute types are used with %NL80211_STA_INFO_TXRATE @@ -3319,6 +3596,13 @@ enum nl80211_he_ru_alloc { * @NL80211_RATE_INFO_HE_DCM: HE DCM value (u8, 0/1) * @NL80211_RATE_INFO_RU_ALLOC: HE RU allocation, if not present then * non-OFDMA was used (u8, see &enum nl80211_he_ru_alloc) + * @NL80211_RATE_INFO_320_MHZ_WIDTH: 320 MHz bitrate + * @NL80211_RATE_INFO_EHT_MCS: EHT MCS index (u8, 0-15) + * @NL80211_RATE_INFO_EHT_NSS: EHT NSS value (u8, 1-8) + * @NL80211_RATE_INFO_EHT_GI: EHT guard interval identifier + * (u8, see &enum nl80211_eht_gi) + * @NL80211_RATE_INFO_EHT_RU_ALLOC: EHT RU allocation, if not present then + * non-OFDMA was used (u8, see &enum nl80211_eht_ru_alloc) * @__NL80211_RATE_INFO_AFTER_LAST: internal use */ enum nl80211_rate_info { @@ -3340,6 +3624,11 @@ enum nl80211_rate_info { NL80211_RATE_INFO_HE_GI, NL80211_RATE_INFO_HE_DCM, NL80211_RATE_INFO_HE_RU_ALLOC, + NL80211_RATE_INFO_320_MHZ_WIDTH, + NL80211_RATE_INFO_EHT_MCS, + NL80211_RATE_INFO_EHT_NSS, + NL80211_RATE_INFO_EHT_GI, + NL80211_RATE_INFO_EHT_RU_ALLOC, /* keep last */ __NL80211_RATE_INFO_AFTER_LAST, @@ -3650,11 +3939,20 @@ enum nl80211_mpath_info { * capabilities IE * @NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE: HE PPE thresholds information as * defined in HE capabilities IE - * @NL80211_BAND_IFTYPE_ATTR_MAX: highest band HE capability attribute currently - * defined * @NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA: HE 6GHz band capabilities (__le16), * given for all 6 GHz band channels + * @NL80211_BAND_IFTYPE_ATTR_VENDOR_ELEMS: vendor element capabilities that are + * advertised on this band/for this iftype (binary) + * @NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC: EHT MAC capabilities as in EHT + * capabilities element + * @NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY: EHT PHY capabilities as in EHT + * capabilities element + * @NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET: EHT supported NSS/MCS as in EHT + * capabilities element + * @NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE: EHT PPE thresholds information as + * defined in EHT capabilities element * @__NL80211_BAND_IFTYPE_ATTR_AFTER_LAST: internal use + * @NL80211_BAND_IFTYPE_ATTR_MAX: highest band attribute currently defined */ enum nl80211_band_iftype_attr { __NL80211_BAND_IFTYPE_ATTR_INVALID, @@ -3665,6 +3963,11 @@ enum nl80211_band_iftype_attr { NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA, + NL80211_BAND_IFTYPE_ATTR_VENDOR_ELEMS, + NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC, + NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY, + NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET, + NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE, /* keep last */ __NL80211_BAND_IFTYPE_ATTR_AFTER_LAST, @@ -3809,6 +4112,10 @@ enum nl80211_wmm_rule { * on this channel in current regulatory domain. * @NL80211_FREQUENCY_ATTR_16MHZ: 16 MHz operation is allowed * on this channel in current regulatory domain. + * @NL80211_FREQUENCY_ATTR_NO_320MHZ: any 320 MHz channel using this channel + * as the primary or any of the secondary channels isn't possible + * @NL80211_FREQUENCY_ATTR_NO_EHT: EHT operation is not allowed on this channel + * in current regulatory domain. * @NL80211_FREQUENCY_ATTR_MAX: highest frequency attribute number * currently defined * @__NL80211_FREQUENCY_ATTR_AFTER_LAST: internal use @@ -3845,6 +4152,8 @@ enum nl80211_frequency_attr { NL80211_FREQUENCY_ATTR_4MHZ, NL80211_FREQUENCY_ATTR_8MHZ, NL80211_FREQUENCY_ATTR_16MHZ, + NL80211_FREQUENCY_ATTR_NO_320MHZ, + NL80211_FREQUENCY_ATTR_NO_EHT, /* keep last */ __NL80211_FREQUENCY_ATTR_AFTER_LAST, @@ -4043,6 +4352,7 @@ enum nl80211_sched_scan_match_attr { * @NL80211_RRF_NO_80MHZ: 80MHz operation not allowed * @NL80211_RRF_NO_160MHZ: 160MHz operation not allowed * @NL80211_RRF_NO_HE: HE operation not allowed + * @NL80211_RRF_NO_320MHZ: 320MHz operation not allowed */ enum nl80211_reg_rule_flags { NL80211_RRF_NO_OFDM = 1<<0, @@ -4061,6 +4371,7 @@ enum nl80211_reg_rule_flags { NL80211_RRF_NO_80MHZ = 1<<15, NL80211_RRF_NO_160MHZ = 1<<16, NL80211_RRF_NO_HE = 1<<17, + NL80211_RRF_NO_320MHZ = 1<<18, }; #define NL80211_RRF_PASSIVE_SCAN NL80211_RRF_NO_IR @@ -4558,6 +4869,8 @@ enum nl80211_key_mode { * @NL80211_CHAN_WIDTH_4: 4 MHz OFDM channel * @NL80211_CHAN_WIDTH_8: 8 MHz OFDM channel * @NL80211_CHAN_WIDTH_16: 16 MHz OFDM channel + * @NL80211_CHAN_WIDTH_320: 320 MHz channel, the %NL80211_ATTR_CENTER_FREQ1 + * attribute must be provided as well */ enum nl80211_chan_width { NL80211_CHAN_WIDTH_20_NOHT, @@ -4573,6 +4886,7 @@ enum nl80211_chan_width { NL80211_CHAN_WIDTH_4, NL80211_CHAN_WIDTH_8, NL80211_CHAN_WIDTH_16, + NL80211_CHAN_WIDTH_320, }; /** @@ -4644,6 +4958,8 @@ enum nl80211_bss_scan_width { * Contains a nested array of signal strength attributes (u8, dBm), * using the nesting index as the antenna number. * @NL80211_BSS_FREQUENCY_OFFSET: frequency offset in KHz + * @NL80211_BSS_MLO_LINK_ID: MLO link ID of the BSS (u8). + * @NL80211_BSS_MLD_ADDR: MLD address of this BSS if connected to it. * @__NL80211_BSS_AFTER_LAST: internal * @NL80211_BSS_MAX: highest BSS attribute */ @@ -4669,6 +4985,8 @@ enum nl80211_bss { NL80211_BSS_PARENT_BSSID, NL80211_BSS_CHAIN_SIGNAL, NL80211_BSS_FREQUENCY_OFFSET, + NL80211_BSS_MLO_LINK_ID, + NL80211_BSS_MLD_ADDR, /* keep last */ __NL80211_BSS_AFTER_LAST, @@ -4887,6 +5205,7 @@ enum nl80211_txrate_gi { * @NL80211_BAND_60GHZ: around 60 GHz band (58.32 - 69.12 GHz) * @NL80211_BAND_6GHZ: around 6 GHz band (5.9 - 7.2 GHz) * @NL80211_BAND_S1GHZ: around 900MHz, supported by S1G PHYs + * @NL80211_BAND_LC: light communication band (placeholder) * @NUM_NL80211_BANDS: number of bands, avoid using this in userspace * since newer kernel versions may support more bands */ @@ -4896,6 +5215,7 @@ enum nl80211_band { NL80211_BAND_60GHZ, NL80211_BAND_6GHZ, NL80211_BAND_S1GHZ, + NL80211_BAND_LC, NUM_NL80211_BANDS, }; @@ -5462,7 +5782,7 @@ enum nl80211_iface_limit_attrs { * => allows 8 of AP/GO that can have BI gcd >= min gcd * * numbers = [ #{STA} <= 2 ], channels = 2, max = 2 - * => allows two STAs on different channels + * => allows two STAs on the same or on different channels * * numbers = [ #{STA} <= 1, #{P2P-client,P2P-GO} <= 3 ], max = 4 * => allows a STA plus three P2P interfaces @@ -5507,7 +5827,7 @@ enum nl80211_if_combination_attrs { * @NL80211_PLINK_ESTAB: mesh peer link is established * @NL80211_PLINK_HOLDING: mesh peer link is being closed or cancelled * @NL80211_PLINK_BLOCKED: all frames transmitted from this mesh - * plink are discarded + * plink are discarded, except for authentication frames * @NUM_NL80211_PLINK_STATES: number of peer link states * @MAX_NL80211_PLINK_STATES: highest numerical value of plink states */ @@ -5644,13 +5964,15 @@ enum nl80211_tdls_operation { NL80211_TDLS_DISABLE_LINK, }; -/* +/** * enum nl80211_ap_sme_features - device-integrated AP features - * Reserved for future use, no bits are defined in - * NL80211_ATTR_DEVICE_AP_SME yet. + * @NL80211_AP_SME_SA_QUERY_OFFLOAD: SA Query procedures offloaded to driver + * when user space indicates support for SA Query procedures offload during + * "start ap" with %NL80211_AP_SETTINGS_SA_QUERY_OFFLOAD_SUPPORT. + */ enum nl80211_ap_sme_features { + NL80211_AP_SME_SA_QUERY_OFFLOAD = 1 << 0, }; - */ /** * enum nl80211_feature_flags - device/driver features @@ -5661,7 +5983,7 @@ enum nl80211_ap_sme_features { * @NL80211_FEATURE_INACTIVITY_TIMER: This driver takes care of freeing up * the connected inactive stations in AP mode. * @NL80211_FEATURE_CELL_BASE_REG_HINTS: This driver has been tested - * to work properly to suppport receiving regulatory hints from + * to work properly to support receiving regulatory hints from * cellular base stations. * @NL80211_FEATURE_P2P_DEVICE_NEEDS_CHANNEL: (no longer available, only * here to reserve the value for API/ABI compatibility) @@ -5950,6 +6272,25 @@ enum nl80211_feature_flags { * frame protection for all management frames exchanged during the * negotiation and range measurement procedure. * + * @NL80211_EXT_FEATURE_BSS_COLOR: The driver supports BSS color collision + * detection and change announcemnts. + * + * @NL80211_EXT_FEATURE_FILS_CRYPTO_OFFLOAD: Driver running in AP mode supports + * FILS encryption and decryption for (Re)Association Request and Response + * frames. Userspace has to share FILS AAD details to the driver by using + * @NL80211_CMD_SET_FILS_AAD. + * + * @NL80211_EXT_FEATURE_RADAR_BACKGROUND: Device supports background radar/CAC + * detection. + * + * @NL80211_EXT_FEATURE_POWERED_ADDR_CHANGE: Device can perform a MAC address + * change without having to bring the underlying network device down + * first. For example, in station mode this can be used to vary the + * origin MAC address prior to a connection to a new AP for privacy + * or other reasons. Note that certain driver specific restrictions + * might apply, e.g. no scans in progress, no offchannel operations + * in progress, and no active connections. + * * @NUM_NL80211_EXT_FEATURES: number of extended features. * @MAX_NL80211_EXT_FEATURES: highest extended feature index. */ @@ -6014,6 +6355,10 @@ enum nl80211_ext_feature_index { NL80211_EXT_FEATURE_SECURE_LTF, NL80211_EXT_FEATURE_SECURE_RTT, NL80211_EXT_FEATURE_PROT_RANGE_NEGO_AND_MEASURE, + NL80211_EXT_FEATURE_BSS_COLOR, + NL80211_EXT_FEATURE_FILS_CRYPTO_OFFLOAD, + NL80211_EXT_FEATURE_RADAR_BACKGROUND, + NL80211_EXT_FEATURE_POWERED_ADDR_CHANGE, /* add new features before the definition below */ NUM_NL80211_EXT_FEATURES, @@ -6912,6 +7257,9 @@ enum nl80211_peer_measurement_ftm_capa { * @NL80211_PMSR_FTM_REQ_ATTR_LMR_FEEDBACK: negotiate for LMR feedback. Only * valid if either %NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED or * %NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED is set. + * @NL80211_PMSR_FTM_REQ_ATTR_BSS_COLOR: optional. The BSS color of the + * responder. Only valid if %NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED + * or %NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED is set. * * @NUM_NL80211_PMSR_FTM_REQ_ATTR: internal * @NL80211_PMSR_FTM_REQ_ATTR_MAX: highest attribute number @@ -6931,6 +7279,7 @@ enum nl80211_peer_measurement_ftm_req { NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED, NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED, NL80211_PMSR_FTM_REQ_ATTR_LMR_FEEDBACK, + NL80211_PMSR_FTM_REQ_ATTR_BSS_COLOR, /* keep last */ NUM_NL80211_PMSR_FTM_REQ_ATTR, @@ -7299,4 +7648,76 @@ enum nl80211_sar_specs_attrs { NL80211_SAR_ATTR_SPECS_MAX = __NL80211_SAR_ATTR_SPECS_LAST - 1, }; +/** + * enum nl80211_mbssid_config_attributes - multiple BSSID (MBSSID) and enhanced + * multi-BSSID advertisements (EMA) in AP mode. + * Kernel uses some of these attributes to advertise driver's support for + * MBSSID and EMA. + * Remaining attributes should be used by the userspace to configure the + * features. + * + * @__NL80211_MBSSID_CONFIG_ATTR_INVALID: Invalid + * + * @NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES: Used by the kernel to advertise + * the maximum number of MBSSID interfaces supported by the driver. + * Driver should indicate MBSSID support by setting + * wiphy->mbssid_max_interfaces to a value more than or equal to 2. + * + * @NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY: Used by the kernel + * to advertise the maximum profile periodicity supported by the driver + * if EMA is enabled. Driver should indicate EMA support to the userspace + * by setting wiphy->ema_max_profile_periodicity to + * a non-zero value. + * + * @NL80211_MBSSID_CONFIG_ATTR_INDEX: Mandatory parameter to pass the index of + * this BSS (u8) in the multiple BSSID set. + * Value must be set to 0 for the transmitting interface and non-zero for + * all non-transmitting interfaces. The userspace will be responsible + * for using unique indices for the interfaces. + * Range: 0 to wiphy->mbssid_max_interfaces-1. + * + * @NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX: Mandatory parameter for + * a non-transmitted profile which provides the interface index (u32) of + * the transmitted profile. The value must match one of the interface + * indices advertised by the kernel. Optional if the interface being set up + * is the transmitting one, however, if provided then the value must match + * the interface index of the same. + * + * @NL80211_MBSSID_CONFIG_ATTR_EMA: Flag used to enable EMA AP feature. + * Setting this flag is permitted only if the driver advertises EMA support + * by setting wiphy->ema_max_profile_periodicity to non-zero. + * + * @__NL80211_MBSSID_CONFIG_ATTR_LAST: Internal + * @NL80211_MBSSID_CONFIG_ATTR_MAX: highest attribute + */ +enum nl80211_mbssid_config_attributes { + __NL80211_MBSSID_CONFIG_ATTR_INVALID, + + NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES, + NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY, + NL80211_MBSSID_CONFIG_ATTR_INDEX, + NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX, + NL80211_MBSSID_CONFIG_ATTR_EMA, + + /* keep last */ + __NL80211_MBSSID_CONFIG_ATTR_LAST, + NL80211_MBSSID_CONFIG_ATTR_MAX = __NL80211_MBSSID_CONFIG_ATTR_LAST - 1, +}; + +/** + * enum nl80211_ap_settings_flags - AP settings flags + * + * @NL80211_AP_SETTINGS_EXTERNAL_AUTH_SUPPORT: AP supports external + * authentication. + * @NL80211_AP_SETTINGS_SA_QUERY_OFFLOAD_SUPPORT: Userspace supports SA Query + * procedures offload to driver. If driver advertises + * %NL80211_AP_SME_SA_QUERY_OFFLOAD in AP SME features, userspace shall + * ignore SA Query procedures and validations when this flag is set by + * userspace. + */ +enum nl80211_ap_settings_flags { + NL80211_AP_SETTINGS_EXTERNAL_AUTH_SUPPORT = 1 << 0, + NL80211_AP_SETTINGS_SA_QUERY_OFFLOAD_SUPPORT = 1 << 1, +}; + #endif /* __LINUX_NL80211_H */ diff --git a/monitor/main.c b/monitor/main.c @@ -451,7 +451,7 @@ static int analyze_pcap(const char *pathname) while (pcap_read(pcap, &tv, buf, snaplen, &len, &real_len)) { struct nlmsghdr *nlmsg; - uint32_t aligned_len; + int64_t aligned_len; uint16_t arphrd_type; uint16_t proto_type; @@ -569,7 +569,7 @@ done: return exit_status; } -static int process_pcap(struct pcap *pcap, uint16_t id) +static int process_pcap(struct pcap *pcap, const struct nlmon_config *config) { struct nlmon *nlmon = NULL; struct timeval tv; @@ -586,7 +586,7 @@ static int process_pcap(struct pcap *pcap, uint16_t id) return EXIT_FAILURE; } - nlmon = nlmon_create(id); + nlmon = nlmon_create(0, config); while (pcap_read(pcap, &tv, buf, snaplen, &len, &real_len)) { uint16_t arphrd_type; @@ -695,13 +695,12 @@ int main(int argc, char *argv[]) const char *reader_path = NULL; const char *analyze_path = NULL; const char *ifname = NULL; - uint16_t nl80211_family = 0; int exit_status; for (;;) { int opt; - opt = getopt_long(argc, argv, "r:w:a:F:i:nvhyse", + opt = getopt_long(argc, argv, "r:w:a:i:nvhyse", main_options, NULL); if (opt < 0) break; @@ -709,6 +708,7 @@ int main(int argc, char *argv[]) switch (opt) { case 'r': reader_path = optarg; + config.read_only = true; break; case 'w': writer_path = optarg; @@ -716,26 +716,6 @@ int main(int argc, char *argv[]) case 'a': analyze_path = optarg; break; - case 'F': - if (strlen(optarg) > 3) { - if (!strncasecmp(optarg, "0x", 2) && - !isxdigit(optarg[2])) { - usage(); - return EXIT_FAILURE; - } - nl80211_family = strtoul(optarg + 2, NULL, 16); - } else { - if (!isdigit(optarg[0])) { - usage(); - return EXIT_FAILURE; - } - nl80211_family = strtoul(optarg, NULL, 10); - } - if (nl80211_family == 0) { - usage(); - return EXIT_FAILURE; - } - break; case 'i': ifname = optarg; break; @@ -797,7 +777,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Invalid packet format\n"); exit_status = EXIT_FAILURE; } else - exit_status = process_pcap(pcap, nl80211_family); + exit_status = process_pcap(pcap, &config); pcap_close(pcap); diff --git a/monitor/nlmon.c b/monitor/nlmon.c @@ -104,6 +104,7 @@ struct nlmon { bool nowiphy; bool noscan; bool noies; + bool read; }; struct nlmon_req { @@ -4724,6 +4725,36 @@ static void print_anqp_frame(unsigned int level, const uint8_t *anqp, } } +static void print_dpp_public_action_frame(unsigned int level, + const uint8_t *data, size_t len) +{ + print_attr(level, "DPP Action Frame"); + + print_attr(level + 1, "Crypto Suite: %u", *data); + data++; + + switch (*data) { + case 0: + print_attr(level + 1, "Type: Authentication Request"); + break; + case 1: + print_attr(level + 1, "Type: Authentication Response"); + break; + case 2: + print_attr(level + 1, "Type: Authentication Confirm"); + break; + case 11: + print_attr(level + 1, "Type: Configuration Result"); + break; + case 13: + print_attr(level + 1, "Type: Presence Announcement"); + break; + default: + print_attr(level + 1, "Type: Unknown (%u)", *data); + break; + } +} + static void print_public_action_frame(unsigned int level, const uint8_t *body, size_t body_len) { @@ -4791,6 +4822,12 @@ static void print_public_action_frame(unsigned int level, const uint8_t *body, print_p2p_public_action_frame(level + 1, body + 5, body_len - 5); + } else if (!memcmp(oui, wifi_alliance_oui, 3) && oui[3] == 0x1a) { + if (!print_oui(level, oui)) + return; + + print_dpp_public_action_frame(level + 1, body + 5, + body_len - 5); } else if (body[0] == 0x0a) { if (body_len < 9) return; @@ -5018,6 +5055,16 @@ static void print_action_mgmt_frame(unsigned int level, print_mmpdu_header(level + 1, mmpdu); } +static void print_probe_response(unsigned int level, + const struct mmpdu_header *mmpdu, size_t len) +{ + const struct mmpdu_probe_response *resp = mmpdu_body(mmpdu); + + print_attr(level, "Subtype: Probe Response"); + print_ie(level + 1, "Probe Response IEs", resp->ies, + (const uint8_t *) mmpdu + len - resp->ies); +} + static void print_frame_type(unsigned int level, const char *label, const void *data, uint16_t size) { @@ -5063,7 +5110,10 @@ static void print_frame_type(unsigned int level, const char *label, str = "Probe request"; break; case 0x05: - str = "Probe response"; + if (mpdu) + print_probe_response(level + 1, mpdu, size); + else + str = "Probe response"; break; case 0x06: str = "Timing Advertisement"; @@ -7153,7 +7203,7 @@ static void nlmon_message(struct nlmon *nlmon, const struct timeval *tv, return; } - if (nlmsg->nlmsg_type != nlmon->id) { + if (!nlmon->read && nlmsg->nlmsg_type != nlmon->id) { if (nlmsg->nlmsg_type == GENL_ID_CTRL) store_message(nlmon, tv, nlmsg); return; @@ -7204,7 +7254,7 @@ static void nlmon_message(struct nlmon *nlmon, const struct timeval *tv, } } -struct nlmon *nlmon_create(uint16_t id) +struct nlmon *nlmon_create(uint16_t id, const struct nlmon_config *config) { struct nlmon *nlmon; @@ -7212,6 +7262,11 @@ struct nlmon *nlmon_create(uint16_t id) nlmon->id = id; nlmon->req_list = l_queue_new(); + nlmon->nortnl = config->nortnl; + nlmon->nowiphy = config->nowiphy; + nlmon->noscan = config->noscan; + nlmon->noies = config->noies; + nlmon->read = config->read_only; return nlmon; } @@ -7939,7 +7994,7 @@ static void print_nlmsghdr(const struct timeval *tv, nlmsg->nlmsg_flags); print_field("Sequence number: %u (0x%08x)", nlmsg->nlmsg_seq, nlmsg->nlmsg_seq); - print_field("Port ID: %d", nlmsg->nlmsg_pid); + print_field("Port ID: %u", nlmsg->nlmsg_pid); } static void print_nlmsg(const struct timeval *tv, const struct nlmsghdr *nlmsg) @@ -8031,9 +8086,12 @@ static void print_rtnl_msg(const struct timeval *tv, void nlmon_print_rtnl(struct nlmon *nlmon, const struct timeval *tv, const void *data, uint32_t size) { - uint32_t aligned_size = NLMSG_ALIGN(size); + int64_t aligned_size = NLMSG_ALIGN(size); const struct nlmsghdr *nlmsg; + if (nlmon->nortnl) + return; + update_time_offset(tv); for (nlmsg = data; NLMSG_OK(nlmsg, aligned_size); @@ -8063,7 +8121,7 @@ void nlmon_print_rtnl(struct nlmon *nlmon, const struct timeval *tv, } void nlmon_print_genl(struct nlmon *nlmon, const struct timeval *tv, - const void *data, uint32_t size) + const void *data, int64_t size) { const struct nlmsghdr *nlmsg; @@ -8095,7 +8153,7 @@ static bool nlmon_receive(struct l_io *io, void *user_data) unsigned char buf[8192]; unsigned char control[32]; ssize_t bytes_read; - uint32_t nlmsg_len; + int64_t nlmsg_len; int fd; fd = l_io_get_fd(io); @@ -8152,9 +8210,7 @@ static bool nlmon_receive(struct l_io *io, void *user_data) case NETLINK_ROUTE: store_netlink(nlmon, tv, proto_type, nlmsg); - if (!nlmon->nortnl) - nlmon_print_rtnl(nlmon, tv, nlmsg, - nlmsg->nlmsg_len); + nlmon_print_rtnl(nlmon, tv, nlmsg, nlmsg->nlmsg_len); break; case NETLINK_GENERIC: nlmon_message(nlmon, tv, tp, nlmsg); @@ -8400,17 +8456,12 @@ struct nlmon *nlmon_open(const char *ifname, uint16_t id, const char *pathname, } else pcap = NULL; - nlmon = l_new(struct nlmon, 1); - nlmon->id = id; + nlmon = nlmon_create(id, config); + nlmon->io = io; nlmon->pae_io = pae_io; - nlmon->req_list = l_queue_new(); nlmon->pcap = pcap; - nlmon->nortnl = config->nortnl; - nlmon->nowiphy = config->nowiphy; - nlmon->noscan = config->noscan; - nlmon->noies = config->noies; l_io_set_read_handler(nlmon->io, nlmon_receive, nlmon, NULL); l_io_set_read_handler(nlmon->pae_io, pae_receive, nlmon, NULL); diff --git a/monitor/nlmon.h b/monitor/nlmon.h @@ -30,18 +30,19 @@ struct nlmon_config { bool nowiphy; bool noscan; bool noies; + bool read_only; }; struct nlmon *nlmon_open(const char *ifname, uint16_t id, const char *pathname, const struct nlmon_config *config); void nlmon_close(struct nlmon *nlmon); -struct nlmon *nlmon_create(uint16_t id); +struct nlmon *nlmon_create(uint16_t id, const struct nlmon_config *config); void nlmon_destroy(struct nlmon *nlmon); void nlmon_print_rtnl(struct nlmon *nlmon, const struct timeval *tv, const void *data, uint32_t size); void nlmon_print_genl(struct nlmon *nlmon, const struct timeval *tv, - const void *data, uint32_t size); + const void *data, int64_t size); void nlmon_print_pae(struct nlmon *nlmon, const struct timeval *tv, uint8_t type, int index, const void *data, uint32_t size); diff --git a/shared/jsmn.h b/shared/jsmn.h @@ -45,10 +45,10 @@ extern "C" { */ typedef enum { JSMN_UNDEFINED = 0, - JSMN_OBJECT = 1, - JSMN_ARRAY = 2, - JSMN_STRING = 3, - JSMN_PRIMITIVE = 4 + JSMN_OBJECT = 1 << 0, + JSMN_ARRAY = 1 << 1, + JSMN_STRING = 1 << 2, + JSMN_PRIMITIVE = 1 << 3 } jsmntype_t; enum jsmnerr { @@ -66,7 +66,7 @@ enum jsmnerr { * start start position in JSON data string * end end position in JSON data string */ -typedef struct { +typedef struct jsmntok { jsmntype_t type; int start; int end; @@ -80,7 +80,7 @@ typedef struct { * JSON parser. Contains an array of token blocks available. Also stores * the string being parsed now and current position in that string. */ -typedef struct { +typedef struct jsmn_parser { unsigned int pos; /* offset in the JSON string */ unsigned int toknext; /* next token to allocate */ int toksuper; /* superior token node, e.g. parent object or array */ @@ -154,6 +154,9 @@ static int jsmn_parse_primitive(jsmn_parser *parser, const char *js, case ']': case '}': goto found; + default: + /* to quiet a warning from gcc*/ + break; } if (js[parser->pos] < 32 || js[parser->pos] >= 127) { parser->pos = start; @@ -193,10 +196,10 @@ static int jsmn_parse_string(jsmn_parser *parser, const char *js, jsmntok_t *token; int start = parser->pos; - - parser->pos++; - + /* Skip starting quote */ + parser->pos++; + for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { char c = js[parser->pos]; diff --git a/src/agent.c b/src/agent.c @@ -28,6 +28,7 @@ #include <ell/ell.h> #include "src/dbus.h" +#include "src/netconfig.h" #include "src/agent.h" #include "src/iwd.h" #include "src/module.h" @@ -623,6 +624,60 @@ static struct l_dbus_message *agent_unregister(struct l_dbus *dbus, return reply; } +static struct l_dbus_message *netconfig_agent_register(struct l_dbus *dbus, + struct l_dbus_message *message, + void *user_data) +{ + struct l_dbus_message *reply; + const char *path; + int r; + + l_debug(""); + + if (!l_dbus_message_get_arguments(message, "o", &path)) + return dbus_error_invalid_args(message); + + if (!netconfig_enabled()) + return dbus_error_not_supported(message); + + r = netconfig_register_agent(l_dbus_message_get_sender(message), path); + if (r) + return dbus_error_from_errno(r, message); + + l_debug("agent %s path %s", + l_dbus_message_get_sender(message), path); + + reply = l_dbus_message_new_method_return(message); + l_dbus_message_set_arguments(reply, ""); + return reply; +} + +static struct l_dbus_message *netconfig_agent_unregister(struct l_dbus *dbus, + struct l_dbus_message *message, + void *user_data) +{ + struct l_dbus_message *reply; + const char *path; + int r; + + l_debug(""); + + if (!l_dbus_message_get_arguments(message, "o", &path)) + return dbus_error_invalid_args(message); + + if (!netconfig_enabled()) + return dbus_error_not_supported(message); + + r = netconfig_unregister_agent(l_dbus_message_get_sender(message), + path); + if (r) + return dbus_error_from_errno(r, message); + + reply = l_dbus_message_new_method_return(message); + l_dbus_message_set_arguments(reply, ""); + return reply; +} + static void setup_agent_interface(struct l_dbus_interface *interface) { l_dbus_interface_method(interface, "RegisterAgent", 0, @@ -631,6 +686,13 @@ static void setup_agent_interface(struct l_dbus_interface *interface) l_dbus_interface_method(interface, "UnregisterAgent", 0, agent_unregister, "", "o", "path"); + + l_dbus_interface_method(interface, + "RegisterNetworkConfigurationAgent", 0, + netconfig_agent_register, "", "o", "path"); + l_dbus_interface_method(interface, + "UnregisterNetworkConfigurationAgent", 0, + netconfig_agent_unregister, "", "o", "path"); } #endif diff --git a/src/anqp.c b/src/anqp.c @@ -156,6 +156,7 @@ static bool anqp_response_frame_event(const struct mmpdu_header *hdr, } static const struct frame_xchg_prefix anqp_frame_prefix = { + .frame_type = 0x00d0, .data = (uint8_t []) { 0x04, 0x0b, }, diff --git a/src/ap.c b/src/ap.c @@ -699,7 +699,7 @@ static size_t ap_write_wsc_ie(struct ap_state *ap, size_t len = 0; /* WSC IE */ - if (type == MPDU_MANAGEMENT_SUBTYPE_PROBE_RESPONSE) { + if (type == MPDU_MANAGEMENT_SUBTYPE_PROBE_RESPONSE && client_frame) { const uint8_t *from = client_frame->address_2; struct wsc_probe_response wsc_pr = {}; const struct mmpdu_probe_request *req = @@ -2416,6 +2416,8 @@ static struct l_genl_msg *ap_build_cmd_start_ap(struct ap_state *ap) 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + static const uint8_t zero_addr[6] = { 0 }; + for (i = 0, nl_ciphers_cnt = 0; i < 8; i++) if (ap->ciphers & (1 << i)) nl_ciphers[nl_ciphers_cnt++] = @@ -2458,6 +2460,21 @@ static struct l_genl_msg *ap_build_cmd_start_ap(struct ap_state *ap) l_genl_msg_append_attr(cmd, NL80211_ATTR_WIPHY_FREQ, 4, &ch_freq); l_genl_msg_append_attr(cmd, NL80211_ATTR_CHANNEL_WIDTH, 4, &ch_width); + if (wiphy_supports_probe_resp_offload(wiphy)) { + uint8_t probe_resp[head_len + tail_len]; + uint8_t *ptr = probe_resp; + + ptr += ap_build_beacon_pr_head(ap, + MPDU_MANAGEMENT_SUBTYPE_PROBE_RESPONSE, + zero_addr, ptr, sizeof(probe_resp)); + ptr += ap_build_beacon_pr_tail(ap, + MPDU_MANAGEMENT_SUBTYPE_PROBE_RESPONSE, + NULL, 0, ptr); + + l_genl_msg_append_attr(cmd, NL80211_ATTR_PROBE_RESP, + ptr - probe_resp, probe_resp); + } + if (wiphy_has_ext_feature(wiphy, NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) { l_genl_msg_append_attr(cmd, NL80211_ATTR_SOCKET_OWNER, 0, NULL); @@ -3115,12 +3132,54 @@ static bool ap_load_psk(struct ap_state *ap, const struct l_settings *config) return true; } +/* + * Note: only PTK/GTK ciphers are supported here since this is all these are + * used for. + */ +static enum ie_rsn_cipher_suite ap_string_to_cipher(const char *str) +{ + if (!strcmp(str, "UseGroupCipher")) + return IE_RSN_CIPHER_SUITE_USE_GROUP_CIPHER; + else if (!strcmp(str, "TKIP")) + return IE_RSN_CIPHER_SUITE_TKIP; + else if (!strcmp(str, "CCMP-128") || !strcmp(str, "CCMP")) + return IE_RSN_CIPHER_SUITE_CCMP; + else if (!strcmp(str, "GCMP-128") || !strcmp(str, "GCMP")) + return IE_RSN_CIPHER_SUITE_GCMP; + else if (!strcmp(str, "GCMP-256")) + return IE_RSN_CIPHER_SUITE_GCMP_256; + else if (!strcmp(str, "CCMP-256")) + return IE_RSN_CIPHER_SUITE_CCMP_256; + else + return 0; +} + +static char **ap_ciphers_to_strv(uint16_t ciphers) +{ + uint16_t i; + char **list = l_strv_new(); + + for (i = 0; i < 16; i++) { + if (!(ciphers & (1 << i))) + continue; + + list = l_strv_append(list, + ie_rsn_cipher_suite_to_string(1 << i)); + } + + return list; +} + static int ap_load_config(struct ap_state *ap, const struct l_settings *config, bool *out_cck_rates) { + struct wiphy *wiphy = netdev_get_wiphy(ap->netdev); size_t len; L_AUTO_FREE_VAR(char *, strval) = NULL; + _auto_(l_strv_free) char **ciphers_str = NULL; + uint16_t cipher_mask; int err; + int i; strval = l_settings_get_string(config, "General", "SSID"); if (L_WARN_ON(!strval)) @@ -3195,6 +3254,8 @@ static int ap_load_config(struct ap_state *ap, const struct l_settings *config, l_error("AP [WSC].PrimaryDeviceType format unknown"); return -EINVAL; } + + l_free(l_steal_ptr(strval)); } else { /* Make ourselves a WFA standard PC by default */ ap->wsc_primary_device_type.category = 1; @@ -3243,6 +3304,61 @@ static int ap_load_config(struct ap_state *ap, const struct l_settings *config, } else *out_cck_rates = true; + cipher_mask = wiphy_get_supported_ciphers(wiphy, IE_GROUP_CIPHERS); + + /* If the config sets a group cipher use that directly */ + strval = l_settings_get_string(config, "Security", "GroupCipher"); + if (strval) { + enum ie_rsn_cipher_suite cipher = ap_string_to_cipher(strval); + + if (!cipher || !(cipher & cipher_mask)) { + l_error("Unsupported or unknown group cipher %s", + strval); + return -ENOTSUP; + } + + ap->group_cipher = cipher; + l_free(l_steal_ptr(strval)); + } else { + /* No config override, use CCMP (or TKIP if not supported) */ + if (cipher_mask & IE_RSN_CIPHER_SUITE_CCMP) + ap->group_cipher = IE_RSN_CIPHER_SUITE_CCMP; + else + ap->group_cipher = IE_RSN_CIPHER_SUITE_TKIP; + } + + cipher_mask = wiphy_get_supported_ciphers(wiphy, IE_PAIRWISE_CIPHERS); + + ciphers_str = l_settings_get_string_list(config, "Security", + "PairwiseCiphers", ','); + for (i = 0; ciphers_str && ciphers_str[i]; i++) { + enum ie_rsn_cipher_suite cipher = + ap_string_to_cipher(ciphers_str[i]); + + /* + * Constrain list to only values in both supported ciphers and + * the cipher list provided. + */ + if (!cipher || !(cipher & cipher_mask)) { + l_error("Unsupported or unknown pairwise cipher %s", + ciphers_str[i]); + return -ENOTSUP; + } + + ap->ciphers |= cipher; + } + + if (!ap->ciphers) { + /* + * Default behavior if no ciphers are specified, disable TKIP + * for security if CCMP is available + */ + if (cipher_mask & IE_RSN_CIPHER_SUITE_CCMP) + cipher_mask &= ~IE_RSN_CIPHER_SUITE_TKIP; + + ap->ciphers = cipher_mask; + } + return 0; } @@ -3285,9 +3401,6 @@ struct ap_state *ap_start(struct netdev *netdev, struct l_settings *config, err = -EINVAL; - /* TODO: Add all ciphers supported by wiphy */ - ap->ciphers = wiphy_select_cipher(wiphy, 0xffff); - ap->group_cipher = wiphy_select_cipher(wiphy, 0xffff); ap->beacon_interval = 100; ap->networks = l_queue_new(); @@ -3321,10 +3434,12 @@ struct ap_state *ap_start(struct netdev *netdev, struct l_settings *config, NULL, 0, ap_reassoc_req_cb, ap, NULL)) goto error; - if (!frame_watch_add(wdev_id, 0, 0x0000 | + if (!wiphy_supports_probe_resp_offload(wiphy)) { + if (!frame_watch_add(wdev_id, 0, 0x0000 | (MPDU_MANAGEMENT_SUBTYPE_PROBE_REQUEST << 4), NULL, 0, ap_probe_req_cb, ap, NULL)) - goto error; + goto error; + } if (!frame_watch_add(wdev_id, 0, 0x0000 | (MPDU_MANAGEMENT_SUBTYPE_DISASSOCIATION << 4), @@ -3554,6 +3669,28 @@ struct ap_if_data { struct l_dbus_message *pending; }; +static void ap_properties_changed(struct ap_if_data *ap_if) +{ + l_dbus_property_changed(dbus_get_bus(), + netdev_get_path(ap_if->netdev), + IWD_AP_INTERFACE, "Started"); + l_dbus_property_changed(dbus_get_bus(), + netdev_get_path(ap_if->netdev), + IWD_AP_INTERFACE, "Name"); + l_dbus_property_changed(dbus_get_bus(), + netdev_get_path(ap_if->netdev), + IWD_AP_INTERFACE, "Frequency"); + l_dbus_property_changed(dbus_get_bus(), + netdev_get_path(ap_if->netdev), + IWD_AP_INTERFACE, "PairwiseCiphers"); + l_dbus_property_changed(dbus_get_bus(), + netdev_get_path(ap_if->netdev), + IWD_AP_INTERFACE, "GroupCipher"); + l_dbus_property_changed(dbus_get_bus(), + netdev_get_path(ap_if->netdev), + IWD_AP_INTERFACE, "Scanning"); +} + static void ap_if_event_func(enum ap_event_type type, const void *event_data, void *user_data) { @@ -3585,12 +3722,8 @@ static void ap_if_event_func(enum ap_event_type type, const void *event_data, reply = l_dbus_message_new_method_return(ap_if->pending); dbus_pending_reply(&ap_if->pending, reply); - l_dbus_property_changed(dbus_get_bus(), - netdev_get_path(ap_if->netdev), - IWD_AP_INTERFACE, "Started"); - l_dbus_property_changed(dbus_get_bus(), - netdev_get_path(ap_if->netdev), - IWD_AP_INTERFACE, "Name"); + + ap_properties_changed(ap_if); l_rtnl_set_linkmode_and_operstate(rtnl, netdev_get_ifindex(ap_if->netdev), @@ -3603,12 +3736,7 @@ static void ap_if_event_func(enum ap_event_type type, const void *event_data, netdev_get_path(ap_if->netdev), IWD_AP_DIAGNOSTIC_INTERFACE); - l_dbus_property_changed(dbus_get_bus(), - netdev_get_path(ap_if->netdev), - IWD_AP_INTERFACE, "Started"); - l_dbus_property_changed(dbus_get_bus(), - netdev_get_path(ap_if->netdev), - IWD_AP_INTERFACE, "Name"); + ap_properties_changed(ap_if); l_rtnl_set_linkmode_and_operstate(rtnl, netdev_get_ifindex(ap_if->netdev), @@ -3941,6 +4069,70 @@ static bool ap_dbus_property_get_scanning(struct l_dbus *dbus, return true; } +static bool ap_dbus_property_get_freq(struct l_dbus *dbus, + struct l_dbus_message *message, + struct l_dbus_message_builder *builder, + void *user_data) +{ + struct ap_if_data *ap_if = user_data; + uint32_t freq; + + if (!ap_if->ap || !ap_if->ap->started) + return false; + + freq = band_channel_to_freq(ap_if->ap->channel, BAND_FREQ_2_4_GHZ); + + l_dbus_message_builder_append_basic(builder, 'u', &freq); + + return true; +} + +static bool ap_dbus_property_get_pairwise(struct l_dbus *dbus, + struct l_dbus_message *message, + struct l_dbus_message_builder *builder, + void *user_data) +{ + struct ap_if_data *ap_if = user_data; + char **ciphers; + size_t i; + + if (!ap_if->ap || !ap_if->ap->started) + return false; + + ciphers = ap_ciphers_to_strv(ap_if->ap->ciphers); + + l_dbus_message_builder_enter_array(builder, "s"); + + for (i = 0; ciphers[i]; i++) + l_dbus_message_builder_append_basic(builder, 's', ciphers[i]); + + l_dbus_message_builder_leave_array(builder); + + l_strv_free(ciphers); + + return true; +} + +static bool ap_dbus_property_get_group(struct l_dbus *dbus, + struct l_dbus_message *message, + struct l_dbus_message_builder *builder, + void *user_data) +{ + struct ap_if_data *ap_if = user_data; + char **cipher; + + if (!ap_if->ap || !ap_if->ap->started) + return false; + + cipher = ap_ciphers_to_strv(ap_if->ap->group_cipher); + + /* Group cipher will only ever be a single value */ + l_dbus_message_builder_append_basic(builder, 's', cipher[0]); + l_strv_free(cipher); + + return true; +} + static void ap_setup_interface(struct l_dbus_interface *interface) { l_dbus_interface_method(interface, "Start", 0, ap_dbus_start, "", @@ -3960,6 +4152,12 @@ static void ap_setup_interface(struct l_dbus_interface *interface) ap_dbus_property_get_name, NULL); l_dbus_interface_property(interface, "Scanning", 0, "b", ap_dbus_property_get_scanning, NULL); + l_dbus_interface_property(interface, "Frequency", 0, "u", + ap_dbus_property_get_freq, NULL); + l_dbus_interface_property(interface, "PairwiseCiphers", 0, "as", + ap_dbus_property_get_pairwise, NULL); + l_dbus_interface_property(interface, "GroupCipher", 0, "s", + ap_dbus_property_get_group, NULL); } static void ap_destroy_interface(void *user_data) @@ -4128,32 +4326,14 @@ static int ap_init(void) * [General].EnableNetworkConfiguration is true. */ if (netconfig_enabled()) { - if (l_settings_get_value(settings, "IPv4", "APAddressPool")) { - global_addr4_strs = l_settings_get_string_list(settings, - "IPv4", - "APAddressPool", - ','); - if (!global_addr4_strs || !*global_addr4_strs) { - l_error("Can't parse the [IPv4].APAddressPool " + global_addr4_strs = + l_settings_get_string_list(settings, "IPv4", + "APAddressPool", ','); + if (global_addr4_strs && !global_addr4_strs[0]) { + l_error("Can't parse the [IPv4].APAddressPool " "setting as a string list"); - l_strv_free(global_addr4_strs); - global_addr4_strs = NULL; - } - } else if (l_settings_get_value(settings, - "General", "APRanges")) { - l_warn("The [General].APRanges setting is deprecated, " - "use [IPv4].APAddressPool instead"); - - global_addr4_strs = l_settings_get_string_list(settings, - "General", - "APRanges", - ','); - if (!global_addr4_strs || !*global_addr4_strs) { - l_error("Can't parse the [General].APRanges " - "setting as a string list"); - l_strv_free(global_addr4_strs); - global_addr4_strs = NULL; - } + l_strv_free(global_addr4_strs); + global_addr4_strs = NULL; } /* Fall back to 192.168.0.0/16 */ diff --git a/src/crypto.c b/src/crypto.c @@ -500,9 +500,17 @@ int crypto_cipher_key_len(enum crypto_cipher cipher) case CRYPTO_CIPHER_TKIP: return 32; case CRYPTO_CIPHER_CCMP: + case CRYPTO_CIPHER_GCMP: return 16; - case CRYPTO_CIPHER_BIP: + case CRYPTO_CIPHER_CCMP_256: + case CRYPTO_CIPHER_GCMP_256: + return 32; + case CRYPTO_CIPHER_BIP_CMAC: + case CRYPTO_CIPHER_BIP_GMAC: return 16; + case CRYPTO_CIPHER_BIP_CMAC_256: + case CRYPTO_CIPHER_BIP_GMAC_256: + return 32; } return 0; diff --git a/src/crypto.h b/src/crypto.h @@ -30,7 +30,13 @@ enum crypto_cipher { CRYPTO_CIPHER_WEP104 = 0x000fac05, CRYPTO_CIPHER_TKIP = 0x000fac02, CRYPTO_CIPHER_CCMP = 0x000fac04, - CRYPTO_CIPHER_BIP = 0x000fac06, + CRYPTO_CIPHER_BIP_CMAC = 0x000fac06, + CRYPTO_CIPHER_GCMP = 0x000fac08, + CRYPTO_CIPHER_GCMP_256 = 0x000fac09, + CRYPTO_CIPHER_CCMP_256 = 0x000fac0a, + CRYPTO_CIPHER_BIP_GMAC = 0x000fac0b, + CRYPTO_CIPHER_BIP_GMAC_256 = 0x000fac0c, + CRYPTO_CIPHER_BIP_CMAC_256 = 0x000fac0d, }; enum crypto_akm { diff --git a/src/dbus.h b/src/dbus.h @@ -44,6 +44,8 @@ #define IWD_AP_DIAGNOSTIC_INTERFACE "net.connman.iwd.AccessPointDiagnostic" #define IWD_STATION_DEBUG_INTERFACE "net.connman.iwd.StationDebug" #define IWD_DPP_INTERFACE "net.connman.iwd.DeviceProvisioning" +#define IWD_NETCONFIG_AGENT_INTERFACE \ + "net.connman.iwd.NetworkConfigurationAgent" #define IWD_BASE_PATH "/net/connman/iwd" #define IWD_AGENT_MANAGER_PATH IWD_BASE_PATH diff --git a/src/dpp.c b/src/dpp.c @@ -1622,6 +1622,7 @@ static void dpp_start_offchannel(struct dpp_sm *dpp, uint32_t freq) * called). */ uint32_t id = offchannel_start(netdev_get_wdev_id(dpp->netdev), + WIPHY_WORK_PRIORITY_OFFCHANNEL, freq, dpp->dwell, dpp_roc_started, dpp, dpp_presence_timeout); diff --git a/src/eap-tls-common.c b/src/eap-tls-common.c @@ -28,7 +28,9 @@ #include <errno.h> #include <ell/ell.h> +#include "ell/useful.h" #include "src/missing.h" +#include "src/module.h" #include "src/eap.h" #include "src/eap-private.h" #include "src/eap-tls-common.h" @@ -123,6 +125,10 @@ struct eap_tls_state { void *variant_data; }; +static struct l_settings *eap_tls_session_cache; +static eap_tls_session_cache_load_func_t eap_tls_session_cache_load; +static eap_tls_session_cache_sync_func_t eap_tls_session_cache_sync; + static void __eap_tls_common_state_reset(struct eap_tls_state *eap_tls) { eap_tls->version_negotiated = EAP_TLS_VERSION_NOT_NEGOTIATED; @@ -571,6 +577,15 @@ static int eap_tls_handle_fragmented_request(struct eap_state *eap, return r; } +static void eap_tls_session_cache_update(void *user_data) +{ + if (L_WARN_ON(!eap_tls_session_cache_sync) || + L_WARN_ON(!eap_tls_session_cache)) + return; + + eap_tls_session_cache_sync(eap_tls_session_cache); +} + static bool eap_tls_tunnel_init(struct eap_state *eap) { struct eap_tls_state *eap_tls = eap_get_data(eap); @@ -633,6 +648,17 @@ static bool eap_tls_tunnel_init(struct eap_state *eap) if (eap_tls->domain_mask) l_tls_set_domain_mask(eap_tls->tunnel, eap_tls->domain_mask); + if (!eap_tls_session_cache_load) + goto start; + + if (!eap_tls_session_cache) + eap_tls_session_cache = eap_tls_session_cache_load(); + + l_tls_set_session_cache(eap_tls->tunnel, eap_tls_session_cache, + eap_get_peer_id(eap), + 24 * 3600 * L_USEC_PER_SEC, 0, + eap_tls_session_cache_update, NULL); + start: if (!l_tls_start(eap_tls->tunnel)) { l_error("%s: Failed to start the TLS client", @@ -1085,3 +1111,35 @@ void eap_tls_common_tunnel_close(struct eap_state *eap) l_tls_close(eap_tls->tunnel); } + +void eap_tls_set_session_cache_ops(eap_tls_session_cache_load_func_t load, + eap_tls_session_cache_sync_func_t sync) +{ + eap_tls_session_cache_load = load; + eap_tls_session_cache_sync = sync; +} + +void eap_tls_forget_peer(const char *peer_id) +{ + if (L_WARN_ON(!eap_tls_session_cache_sync)) + return; + + if (!eap_tls_session_cache) + eap_tls_session_cache = eap_tls_session_cache_load(); + + if (l_settings_remove_group(eap_tls_session_cache, peer_id)) + eap_tls_session_cache_sync(eap_tls_session_cache); +} + +static int eap_tls_common_init(void) +{ + return 0; +} + +static void eap_tls_common_exit(void) +{ + l_settings_free(eap_tls_session_cache); + eap_tls_session_cache = NULL; +} + +IWD_MODULE(eap_tls_common, eap_tls_common_init, eap_tls_common_exit); diff --git a/src/eap-tls-common.h b/src/eap-tls-common.h @@ -20,6 +20,9 @@ * */ +typedef struct l_settings *(*eap_tls_session_cache_load_func_t)(void); +typedef void (*eap_tls_session_cache_sync_func_t)(const struct l_settings *); + enum eap_tls_version { EAP_TLS_VERSION_0 = 0x00, EAP_TLS_VERSION_1 = 0x01, @@ -81,3 +84,7 @@ bool eap_tls_common_tunnel_prf_get_bytes(struct eap_state *eap, void eap_tls_common_tunnel_send(struct eap_state *eap, const uint8_t *data, size_t data_len); void eap_tls_common_tunnel_close(struct eap_state *eap); + +void eap_tls_set_session_cache_ops(eap_tls_session_cache_load_func_t load, + eap_tls_session_cache_sync_func_t sync); +void eap_tls_forget_peer(const char *peer_id); diff --git a/src/eap.c b/src/eap.c @@ -59,6 +59,7 @@ struct eap_state { char *identity; char *identity_setting; bool authenticator; + char *peer_id; int last_id; void *method_state; @@ -154,6 +155,7 @@ void eap_free(struct eap_state *eap) eap_free_common(eap); l_timeout_remove(eap->complete_timeout); + eap_set_peer_id(eap, NULL); l_free(eap); } @@ -837,6 +839,17 @@ err: return false; } +void eap_set_peer_id(struct eap_state *eap, const char *id) +{ + l_free(eap->peer_id); + eap->peer_id = l_strdup(id); +} + +const char *eap_get_peer_id(struct eap_state *eap) +{ + return eap->peer_id; +} + void eap_set_data(struct eap_state *eap, void *data) { eap->method_state = data; diff --git a/src/eap.h b/src/eap.h @@ -94,6 +94,9 @@ const char *eap_get_identity(struct eap_state *eap); void eap_rx_packet(struct eap_state *eap, const uint8_t *pkt, size_t len); +void eap_set_peer_id(struct eap_state *eap, const char *id); +const char *eap_get_peer_id(struct eap_state *eap); + void __eap_set_config(struct l_settings *config); int eap_init(void); diff --git a/src/eapol.c b/src/eapol.c @@ -390,11 +390,31 @@ static int eapol_encrypt_key_data(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; + switch (out_frame->key_descriptor_version) { case EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4: - /* Not supported */ - return -ENOTSUP; + /* + * Not following the spec to generate the IV. The spec outlines + * a procedure where a 32 byte buffer is held and incremented + * each time nonces are created, and the IV comes from this + * buffer. In the end randomizing the IV every time should be + * just as good. This is how we handle the GTK in AP mode. + */ + l_getrandom(out_frame->eapol_key_iv, 16); + + memcpy(key, out_frame->eapol_key_iv, 16); + memcpy(key + 16, kek, 16); + ret = arc4_skip(key, 32, 256, key_data, key_data_len, + EAPOL_KEY_DATA(out_frame, mic_len)); + explicit_bzero(key, sizeof(key)); + + if (!ret) + return -ENOTSUP; + + 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) @@ -1062,6 +1082,7 @@ static void eapol_send_ptk_1_of_4(struct eapol_sm *sm) enum crypto_cipher cipher = ie_rsn_cipher_suite_to_cipher( sm->handshake->pairwise_cipher); uint8_t pmkid[16]; + uint8_t key_descriptor_version; handshake_state_new_anonce(sm->handshake); @@ -1073,8 +1094,11 @@ static void eapol_send_ptk_1_of_4(struct eapol_sm *sm) ek->header.protocol_version = sm->protocol_version; ek->header.packet_type = 0x3; ek->descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211; - /* Must be HMAC-SHA1-128 + AES when using CCMP with PSK or 8021X */ - ek->key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES; + L_WARN_ON(eapol_key_descriptor_version_from_akm( + sm->handshake->akm_suite, + sm->handshake->pairwise_cipher, + &key_descriptor_version) < 0); + ek->key_descriptor_version = key_descriptor_version; ek->key_type = true; ek->key_ack = true; ek->key_length = L_CPU_TO_BE16(crypto_cipher_key_len(cipher)); @@ -1358,6 +1382,7 @@ static void eapol_send_ptk_3_of_4(struct eapol_sm *sm) sm->handshake->group_cipher); const uint8_t *kck; const uint8_t *kek; + uint8_t key_descriptor_version; sm->replay_counter++; @@ -1365,8 +1390,11 @@ static void eapol_send_ptk_3_of_4(struct eapol_sm *sm) ek->header.protocol_version = sm->protocol_version; ek->header.packet_type = 0x3; ek->descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211; - /* Must be HMAC-SHA1-128 + AES when using CCMP with PSK or 8021X */ - ek->key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES; + L_WARN_ON(eapol_key_descriptor_version_from_akm( + sm->handshake->akm_suite, + sm->handshake->pairwise_cipher, + &key_descriptor_version) < 0); + ek->key_descriptor_version = key_descriptor_version; ek->key_type = true; ek->install = true; ek->key_ack = true; @@ -2238,12 +2266,14 @@ static void eapol_key_handle(struct eapol_sm *sm, const struct eapol_frame *frame, bool unencrypted) { + struct handshake_state *hs = sm->handshake; const struct eapol_key *ek; const uint8_t *kck; const uint8_t *kek; uint8_t *decrypted_key_data = NULL; size_t key_data_len = 0; uint64_t replay_counter; + uint8_t expected_key_descriptor_version; ek = eapol_key_validate((const uint8_t *) frame, sizeof(struct eapol_header) + @@ -2256,11 +2286,19 @@ static void eapol_key_handle(struct eapol_sm *sm, if (!ek->key_ack) return; + if (L_WARN_ON(eapol_key_descriptor_version_from_akm(hs->akm_suite, + hs->pairwise_cipher, + &expected_key_descriptor_version) < 0)) + return; + + if (L_WARN_ON(expected_key_descriptor_version != + ek->key_descriptor_version)) + return; + /* Further Descriptor Type check */ - if (!sm->handshake->wpa_ie && - ek->descriptor_type != EAPOL_DESCRIPTOR_TYPE_80211) + if (!hs->wpa_ie && ek->descriptor_type != EAPOL_DESCRIPTOR_TYPE_80211) return; - else if (sm->handshake->wpa_ie && + else if (hs->wpa_ie && ek->descriptor_type != EAPOL_DESCRIPTOR_TYPE_WPA) return; @@ -2293,31 +2331,30 @@ static void eapol_key_handle(struct eapol_sm *sm, if (sm->have_replay && sm->replay_counter >= replay_counter) return; - kck = handshake_state_get_kck(sm->handshake); + kck = handshake_state_get_kck(hs); if (ek->key_mic) { /* Haven't received step 1 yet, so no ptk */ - if (!sm->handshake->have_snonce) + if (!hs->have_snonce) return; - if (!eapol_verify_mic(sm->handshake->akm_suite, kck, ek, - sm->mic_len)) + if (!eapol_verify_mic(hs->akm_suite, kck, ek, sm->mic_len)) return; } - if ((ek->encrypted_key_data && !sm->handshake->wpa_ie) || - (ek->key_type == 0 && sm->handshake->wpa_ie)) { + if ((ek->encrypted_key_data && !hs->wpa_ie) || + (ek->key_type == 0 && hs->wpa_ie)) { /* * If using a MIC (non-FILS) but haven't received step 1 yet * we disregard since there will be no ptk */ - if (sm->mic_len && !sm->handshake->have_snonce) + if (sm->mic_len && !hs->have_snonce) return; - kek = handshake_state_get_kek(sm->handshake); + kek = handshake_state_get_kek(hs); decrypted_key_data = eapol_decrypt_key_data( - sm->handshake->akm_suite, kek, + hs->akm_suite, kek, ek, &key_data_len, sm->mic_len); if (!decrypted_key_data) return; @@ -2326,11 +2363,10 @@ static void eapol_key_handle(struct eapol_sm *sm, if (ek->key_type == 0) { /* GTK handshake allowed only after PTK handshake complete */ - if (!sm->handshake->ptk_complete) + if (!hs->ptk_complete) goto done; - if (sm->handshake->group_cipher == - IE_RSN_CIPHER_SUITE_NO_GROUP_TRAFFIC) + if (hs->group_cipher == IE_RSN_CIPHER_SUITE_NO_GROUP_TRAFFIC) goto done; if (!decrypted_key_data) @@ -2734,6 +2770,8 @@ void eapol_register(struct eapol_sm *sm) bool eapol_start(struct eapol_sm *sm) { if (sm->handshake->settings_8021x) { + _auto_(l_free) char *network_id = NULL; + sm->eap = eap_new(eapol_eap_msg_cb, eapol_eap_complete_cb, sm); if (!sm->eap) @@ -2749,6 +2787,10 @@ bool eapol_start(struct eapol_sm *sm) eap_set_key_material_func(sm->eap, eapol_eap_results_cb); eap_set_event_func(sm->eap, eapol_eap_event_cb); + + network_id = l_util_hexstring(sm->handshake->ssid, + sm->handshake->ssid_len); + eap_set_peer_id(sm->eap, network_id); } sm->started = true; diff --git a/src/eapolutil.c b/src/eapolutil.c @@ -25,9 +25,11 @@ #endif #include <stdio.h> +#include <errno.h> #include <ell/ell.h> #include "src/eapolutil.h" +#include "src/ie.h" const struct eapol_key *eapol_key_validate(const uint8_t *frame, size_t len, size_t mic_len) @@ -80,3 +82,45 @@ const struct eapol_key *eapol_key_validate(const uint8_t *frame, size_t len, return ek; } + +int eapol_key_descriptor_version_from_akm(enum ie_rsn_akm_suite akm, + enum ie_rsn_cipher_suite pairwise, + uint8_t *outv) +{ + /* 802.11-2020 Section 12.7.2 */ + switch (akm) { + case IE_RSN_AKM_SUITE_8021X: + case IE_RSN_AKM_SUITE_PSK: + if (pairwise == IE_RSN_CIPHER_SUITE_USE_GROUP_CIPHER || + pairwise == IE_RSN_CIPHER_SUITE_TKIP) + *outv = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4; + else + *outv = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES; + + return 0; + case IE_RSN_AKM_SUITE_FT_OVER_8021X: + case IE_RSN_AKM_SUITE_FT_USING_PSK: + case IE_RSN_AKM_SUITE_8021X_SHA256: + case IE_RSN_AKM_SUITE_PSK_SHA256: + *outv = EAPOL_KEY_DESCRIPTOR_VERSION_AES_128_CMAC_AES; + return 0; + case IE_RSN_AKM_SUITE_SAE_SHA256: + case IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256: + case IE_RSN_AKM_SUITE_8021X_SUITE_B_SHA256: + case IE_RSN_AKM_SUITE_8021X_SUITE_B_SHA384: + case IE_RSN_AKM_SUITE_FT_OVER_8021X_SHA384: + 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: + case IE_RSN_AKM_SUITE_OWE: + case IE_RSN_AKM_SUITE_OSEN: + *outv = EAPOL_KEY_DESCRIPTOR_VERSION_AKM_DEFINED; + return 0; + case IE_RSN_AKM_SUITE_TDLS: + case IE_RSN_AKM_SUITE_AP_PEER_KEY_SHA256: + break; + } + + return -ENOTSUP; +}; diff --git a/src/eapolutil.h b/src/eapolutil.h @@ -25,6 +25,9 @@ #include <asm/byteorder.h> #include <linux/types.h> +enum ie_rsn_akm_suite; +enum ie_rsn_cipher_suite; + enum eapol_protocol_version { EAPOL_PROTOCOL_VERSION_2001 = 1, EAPOL_PROTOCOL_VERSION_2004 = 2, @@ -116,3 +119,6 @@ struct eapol_key { const struct eapol_key *eapol_key_validate(const uint8_t *frame, size_t len, size_t mic_len); +int eapol_key_descriptor_version_from_akm(enum ie_rsn_akm_suite akm, + enum ie_rsn_cipher_suite pairwise, + uint8_t *out_version); diff --git a/src/frame-xchg.c b/src/frame-xchg.c @@ -1193,7 +1193,7 @@ uint32_t frame_xchg_startv(uint64_t wdev_id, struct iovec *frame, uint32_t freq, watch = l_new(struct frame_xchg_watch_data, 1); watch->prefix = prefix; watch->cb = va_arg(resp_args, void *); - frame_watch_add(wdev_id, group_id, 0x00d0, + frame_watch_add(wdev_id, group_id, prefix->frame_type, prefix->data, prefix->len, frame_xchg_resp_cb, fx, NULL); diff --git a/src/frame-xchg.h b/src/frame-xchg.h @@ -32,10 +32,17 @@ typedef void (*frame_xchg_cb_t)(int err, void *user_data); typedef void (*frame_xchg_destroy_func_t)(void *user_data); struct frame_xchg_prefix { + uint16_t frame_type; const uint8_t *data; size_t len; }; +enum frame_xchg_group { + FRAME_GROUP_DEFAULT = 0, + FRAME_GROUP_P2P_LISTEN, + FRAME_GROUP_P2P_CONNECT, +}; + bool frame_watch_add(uint64_t wdev_id, uint32_t group, uint16_t frame_type, const uint8_t *prefix, size_t prefix_len, frame_watch_cb_t handler, void *user_data, diff --git a/src/ft.c b/src/ft.c @@ -33,18 +33,32 @@ #include "src/mpdu.h" #include "src/auth-proto.h" #include "src/band.h" - -struct ft_sm { - struct auth_proto ap; - struct handshake_state *hs; - - ft_tx_authenticate_func_t tx_auth; - ft_tx_associate_func_t tx_assoc; - ft_get_oci get_oci; - - void *user_data; - - bool over_ds : 1; +#include "src/scan.h" +#include "src/util.h" +#include "src/netdev.h" +#include "src/module.h" +#include "src/offchannel.h" +#include "src/wiphy.h" + +static ft_tx_frame_func_t tx_frame = NULL; +static ft_tx_associate_func_t tx_assoc = NULL; +static struct l_queue *info_list = NULL; + +struct ft_info { + uint32_t ifindex; + uint8_t spa[6]; + uint8_t aa[6]; + uint8_t snonce[32]; + uint8_t mde[3]; + uint8_t *fte; + uint8_t *authenticator_ie; + uint8_t prev_bssid[6]; + uint32_t frequency; + uint32_t offchannel_id; + + struct ie_ft_info ft_info; + + bool parsed : 1; }; /* @@ -202,11 +216,13 @@ static bool ft_parse_associate_resp_frame(const uint8_t *frame, size_t frame_len return true; } -static int ft_tx_reassociate(struct ft_sm *ft) +static int ft_tx_reassociate(uint32_t ifindex, uint32_t freq, + const uint8_t *prev_bssid) { + struct netdev *netdev = netdev_find(ifindex); + struct handshake_state *hs = netdev_get_handshake(netdev); struct iovec iov[3]; int iov_elems = 0; - struct handshake_state *hs = ft->hs; uint32_t kck_len = handshake_state_get_kck_len(hs); bool is_rsn = hs->supplicant_ie != NULL; uint8_t *rsne = NULL; @@ -233,9 +249,8 @@ static int ft_tx_reassociate(struct ft_sm *ft) rsn_info.num_pmkids = 1; rsn_info.pmkids = hs->pmk_r1_name; - /* Always set OCVC false for FT-over-DS */ - if (ft->over_ds) - rsn_info.ocvc = false; + /* Always set OCVC false for FT for now */ + rsn_info.ocvc = false; rsne = alloca(256); ie_build_rsne(&rsn_info, rsne); @@ -306,7 +321,7 @@ static int ft_tx_reassociate(struct ft_sm *ft) iov_elems += 1; } - return ft->tx_assoc(iov, iov_elems, ft->user_data); + return tx_assoc(ifindex, freq, prev_bssid, iov, iov_elems); error: return -EINVAL; @@ -348,7 +363,7 @@ static bool ft_verify_rsne(const uint8_t *rsne, const uint8_t *pmk_r0_name, return true; } -static int ft_parse_ies(struct handshake_state *hs, +static int parse_ies(struct handshake_state *hs, const uint8_t *authenticator_ie, const uint8_t *ies, size_t ies_len, const uint8_t **mde_out, @@ -471,91 +486,25 @@ static bool mde_equal(const uint8_t *mde1, const uint8_t *mde2) return memcmp(mde1, mde1, mde1[1] + 2) == 0; } -bool ft_over_ds_parse_action_ies(struct ft_ds_info *info, - struct handshake_state *hs, - const uint8_t *ies, - size_t ies_len) -{ - const uint8_t *mde = NULL; - const uint8_t *fte = NULL; - bool is_rsn = hs->supplicant_ie != NULL; - - if (ft_parse_ies(hs, info->authenticator_ie, ies, ies_len, - &mde, &fte) < 0) - return false; - - if (!mde_equal(info->mde, mde)) - goto ft_error; - - if (is_rsn) { - if (!ft_parse_fte(hs, info->snonce, fte, &info->ft_info)) - goto ft_error; - - info->fte = l_memdup(fte, fte[1] + 2); - } else if (fte) - goto ft_error; - - return true; - -ft_error: - return false; -} - -static int ft_process_ies(struct handshake_state *hs, const uint8_t *ies, - size_t ies_len) -{ - const uint8_t *mde = NULL; - const uint8_t *fte = NULL; - bool is_rsn = hs->supplicant_ie != NULL; - - /* Check 802.11r IEs */ - if (!ies) - goto ft_error; - - if (ft_parse_ies(hs, hs->authenticator_ie, ies, ies_len, - &mde, &fte) < 0) - goto ft_error; - - if (!mde_equal(hs->mde, mde)) - goto ft_error; - - if (is_rsn) { - struct ie_ft_info ft_info; - - if (!ft_parse_fte(hs, hs->snonce, fte, &ft_info)) - goto ft_error; - - handshake_state_set_fte(hs, fte); - - handshake_state_set_anonce(hs, ft_info.anonce); - - handshake_state_set_kh_ids(hs, ft_info.r0khid, - ft_info.r0khid_len, - ft_info.r1khid); - - handshake_state_derive_ptk(hs); - } else if (fte) - goto ft_error; - - return 0; - -ft_error: - return -EBADMSG; -} - -int ft_over_ds_parse_action_response(const uint8_t *frame, size_t frame_len, +static int ft_over_ds_parse_action_response(const uint8_t *frame, + size_t frame_len, const uint8_t **spa_out, const uint8_t **aa_out, const uint8_t **ies_out, size_t *ies_len) { + struct mmpdu_header *hdr = (struct mmpdu_header *)frame; + size_t hdr_len = mmpdu_header_len(hdr); uint16_t status; const uint8_t *aa; const uint8_t *spa; - if (frame_len < 16) + if (frame_len < hdr_len + 16) return -EINVAL; + frame += hdr_len; + frame_len -= hdr_len; + /* Category FT */ if (frame[0] != 6) return -EINVAL; @@ -567,6 +516,9 @@ int ft_over_ds_parse_action_response(const uint8_t *frame, size_t frame_len, spa = frame + 2; aa = frame + 8; + if (memcmp(spa, hdr->address_1, 6)) + return -EINVAL; + status = l_get_le16(frame + 14); if (status != 0) return (int)status; @@ -585,80 +537,10 @@ int ft_over_ds_parse_action_response(const uint8_t *frame, size_t frame_len, return 0; } -bool ft_over_ds_prepare_handshake(struct ft_ds_info *info, - struct handshake_state *hs) +int __ft_rx_associate(uint32_t ifindex, const uint8_t *frame, size_t frame_len) { - if (!hs->supplicant_ie) - return true; - - memcpy(hs->snonce, info->snonce, sizeof(hs->snonce)); - - handshake_state_set_fte(hs, info->fte); - - handshake_state_set_anonce(hs, info->ft_info.anonce); - - handshake_state_set_kh_ids(hs, info->ft_info.r0khid, - info->ft_info.r0khid_len, - info->ft_info.r1khid); - - handshake_state_derive_ptk(hs); - - return true; -} - -void ft_ds_info_free(struct ft_ds_info *info) -{ - __typeof__(info->free) destroy = info->free; - - if (info->fte) - l_free(info->fte); - - if (info->authenticator_ie) - l_free(info->authenticator_ie); - - if (destroy) - destroy(info); -} - -static int ft_rx_authenticate(struct auth_proto *ap, const uint8_t *frame, - size_t frame_len) -{ - struct ft_sm *ft = l_container_of(ap, struct ft_sm, ap); - uint16_t status_code = MMPDU_STATUS_CODE_UNSPECIFIED; - const uint8_t *ies = NULL; - size_t ies_len; - int ret; - - /* - * Parse the Authentication Response and validate the contents - * according to 12.5.2 / 12.5.4: RSN or non-RSN Over-the-air - * FT Protocol. - */ - if (!ft_parse_authentication_resp_frame(frame, frame_len, ft->hs->spa, - ft->hs->aa, ft->hs->aa, - 2, &status_code, - &ies, &ies_len)) - goto auth_error; - - /* AP Rejected the authenticate / associate */ - if (status_code != 0) - goto auth_error; - - ret = ft_process_ies(ft->hs, ies, ies_len); - if (ret < 0) - goto auth_error; - - return ft->get_oci(ft->user_data); - -auth_error: - return (int)status_code; -} - -static int ft_rx_associate(struct auth_proto *ap, const uint8_t *frame, - size_t frame_len) -{ - struct ft_sm *ft = l_container_of(ap, struct ft_sm, ap); - struct handshake_state *hs = ft->hs; + struct netdev *netdev = netdev_find(ifindex); + struct handshake_state *hs = netdev_get_handshake(netdev); uint32_t kck_len = handshake_state_get_kck_len(hs); const uint8_t *rsne = NULL; const uint8_t *mde = NULL; @@ -671,6 +553,9 @@ static int ft_rx_associate(struct auth_proto *ap, const uint8_t *frame, &mde, &fte)) return -EBADMSG; + if (out_status != 0) + return (int)out_status; + /* * During a transition in an RSN, check for an RSNE containing the * PMK-R1-Name and the remaining fields same as in the advertised @@ -785,34 +670,13 @@ static int ft_rx_associate(struct auth_proto *ap, const uint8_t *frame, ft_info.igtk_ipn); } - handshake_state_install_ptk(ft->hs); + handshake_state_install_ptk(hs); } return 0; } -static int ft_rx_oci(struct auth_proto *ap) -{ - struct ft_sm *ft = l_container_of(ap, struct ft_sm, ap); - - return ft_tx_reassociate(ft); -} - -static void ft_sm_free(struct auth_proto *ap) -{ - struct ft_sm *ft = l_container_of(ap, struct ft_sm, ap); - - l_free(ft); -} - -static bool ft_over_ds_start(struct auth_proto *ap) -{ - struct ft_sm *ft = l_container_of(ap, struct ft_sm, ap); - - return ft_tx_reassociate(ft) == 0; -} - -bool ft_build_authenticate_ies(struct handshake_state *hs, bool ocvc, +static bool ft_build_authenticate_ies(struct handshake_state *hs, bool ocvc, const uint8_t *new_snonce, uint8_t *buf, size_t *len) { @@ -884,63 +748,371 @@ bool ft_build_authenticate_ies(struct handshake_state *hs, bool ocvc, return true; } -static bool ft_start(struct auth_proto *ap) +void __ft_set_tx_frame_func(ft_tx_frame_func_t func) { - struct ft_sm *ft = l_container_of(ap, struct ft_sm, ap); - struct handshake_state *hs = ft->hs; - struct iovec iov; - uint8_t buf[512]; - size_t len; + tx_frame = func; +} - if (!ft_build_authenticate_ies(hs, hs->supplicant_ocvc, hs->snonce, - buf, &len)) +void __ft_set_tx_associate_func(ft_tx_associate_func_t func) +{ + tx_assoc = func; +} + +static bool ft_parse_ies(struct ft_info *info, struct handshake_state *hs, + const uint8_t *ies, size_t ies_len) +{ + const uint8_t *mde = NULL; + const uint8_t *fte = NULL; + bool is_rsn = hs->supplicant_ie != NULL; + + if (parse_ies(hs, info->authenticator_ie, ies, ies_len, + &mde, &fte) < 0) return false; - iov.iov_base = buf; - iov.iov_len = len; + if (!mde_equal(info->mde, mde)) + goto ft_error; - ft->tx_auth(&iov, 1, ft->user_data); + if (is_rsn) { + if (!ft_parse_fte(hs, info->snonce, fte, &info->ft_info)) + goto ft_error; + + info->fte = l_memdup(fte, fte[1] + 2); + } else if (fte) + goto ft_error; return true; + +ft_error: + return false; } -struct auth_proto *ft_over_air_sm_new(struct handshake_state *hs, - ft_tx_authenticate_func_t tx_auth, - ft_tx_associate_func_t tx_assoc, - ft_get_oci get_oci, - void *user_data) +static struct ft_info *ft_info_find(uint32_t ifindex, const uint8_t *aa) { - struct ft_sm *ft = l_new(struct ft_sm, 1); + const struct l_queue_entry *e; - ft->tx_auth = tx_auth; - ft->tx_assoc = tx_assoc; - ft->get_oci = get_oci; - ft->hs = hs; - ft->user_data = user_data; + for (e = l_queue_get_entries(info_list); e; e = e->next) { + struct ft_info *info = e->data; - ft->ap.rx_authenticate = ft_rx_authenticate; - ft->ap.rx_associate = ft_rx_associate; - ft->ap.start = ft_start; - ft->ap.free = ft_sm_free; - ft->ap.rx_oci = ft_rx_oci; + if (info->ifindex != ifindex) + continue; - return &ft->ap; + if (aa && memcmp(info->aa, aa, 6)) + continue; + + return info; + } + + return NULL; +} + +void __ft_rx_action(uint32_t ifindex, const uint8_t *frame, size_t frame_len) +{ + struct netdev *netdev = netdev_find(ifindex); + struct handshake_state *hs = netdev_get_handshake(netdev); + struct ft_info *info; + int ret; + const uint8_t *aa = NULL; + const uint8_t *spa = NULL; + const uint8_t *ies = NULL; + size_t ies_len = 0; + + ret = ft_over_ds_parse_action_response(frame, frame_len, &spa, &aa, + &ies, &ies_len); + if (ret != 0) + return; + + info = ft_info_find(ifindex, aa); + if (!info) + return; + + if (!ft_parse_ies(info, hs, ies, ies_len)) + goto ft_error; + + info->parsed = true; + + return; + +ft_error: + l_debug("FT-over-DS authenticate to "MAC" failed", MAC_STR(info->aa)); +} + +static struct ft_info *ft_info_new(struct handshake_state *hs, + const struct scan_bss *target_bss) +{ + struct ft_info *info = l_new(struct ft_info, 1); + + info->ifindex = hs->ifindex; + memcpy(info->spa, hs->spa, 6); + memcpy(info->aa, target_bss->addr, 6); + memcpy(info->mde, target_bss->mde, sizeof(info->mde)); + memcpy(info->prev_bssid, hs->aa, 6); + + info->frequency = target_bss->frequency; + + if (target_bss->rsne) + info->authenticator_ie = l_memdup(target_bss->rsne, + target_bss->rsne[1] + 2); + + l_getrandom(info->snonce, 32); + + return info; +} + +static void ft_info_destroy(void *data) +{ + struct ft_info *info = data; + + if (info->fte) + l_free(info->fte); + + if (info->authenticator_ie) + l_free(info->authenticator_ie); + + l_free(info); +} + +static void ft_prepare_handshake(struct ft_info *info, + struct handshake_state *hs) +{ + handshake_state_set_authenticator_address(hs, info->aa); + + memcpy(hs->mde + 2, info->mde, 3); + + handshake_state_set_chandef(hs, NULL); + + if (!hs->supplicant_ie) + return; + + if (info->authenticator_ie) + handshake_state_set_authenticator_ie(hs, + info->authenticator_ie); + + memcpy(hs->snonce, info->snonce, sizeof(hs->snonce)); + + handshake_state_set_fte(hs, info->fte); + + handshake_state_set_anonce(hs, info->ft_info.anonce); + + handshake_state_set_kh_ids(hs, info->ft_info.r0khid, + info->ft_info.r0khid_len, + info->ft_info.r1khid); + + handshake_state_derive_ptk(hs); +} + +int ft_action(uint32_t ifindex, uint32_t freq, const struct scan_bss *target) +{ + struct netdev *netdev = netdev_find(ifindex); + struct handshake_state *hs = netdev_get_handshake(netdev); + struct ft_info *info; + uint8_t ft_req[14]; + struct iovec iov[5]; + uint8_t ies[512]; + size_t len; + int ret = -EINVAL; + + info = ft_info_new(hs, target); + + ft_req[0] = 6; /* FT category */ + ft_req[1] = 1; /* FT Request action */ + memcpy(ft_req + 2, info->spa, 6); + memcpy(ft_req + 8, info->aa, 6); + + if (!ft_build_authenticate_ies(hs, hs->supplicant_ocvc, info->snonce, + ies, &len)) + goto failed; + + iov[0].iov_base = ft_req; + iov[0].iov_len = sizeof(ft_req); + + iov[1].iov_base = ies; + iov[1].iov_len = len; + + ret = tx_frame(hs->ifindex, 0x00d0, freq, hs->aa, iov, 2); + if (ret < 0) + goto failed; + + l_queue_push_tail(info_list, info); + + return 0; + +failed: + l_free(info); + return ret; +} + +void __ft_rx_authenticate(uint32_t ifindex, const uint8_t *frame, + size_t frame_len) +{ + struct netdev *netdev = netdev_find(ifindex); + struct handshake_state *hs = netdev_get_handshake(netdev); + struct ft_info *info; + uint16_t status; + const uint8_t *ies; + size_t ies_len; + + info = ft_info_find(ifindex, NULL); + if (!info) + return; + + if (!ft_parse_authentication_resp_frame(frame, frame_len, + info->spa, info->aa, info->aa, 2, + &status, &ies, &ies_len)) + return; + + if (status != 0) + goto cancel; + + if (!ft_parse_ies(info, hs, ies, ies_len)) + goto cancel; + + info->parsed = true; + +cancel: + /* Verified to be expected target, offchannel can be canceled */ + offchannel_cancel(netdev_get_wdev_id(netdev), info->offchannel_id); +} + +static void ft_send_authenticate(void *user_data) +{ + struct ft_info *info = user_data; + struct netdev *netdev = netdev_find(info->ifindex); + struct handshake_state *hs = netdev_get_handshake(netdev); + uint8_t ies[256]; + size_t len; + struct iovec iov[2]; + struct mmpdu_authentication auth; + + /* Authentication body */ + auth.algorithm = L_CPU_TO_LE16(MMPDU_AUTH_ALGO_FT); + auth.transaction_sequence = L_CPU_TO_LE16(1); + auth.status = L_CPU_TO_LE16(0); + + iov[0].iov_base = &auth; + iov[0].iov_len = sizeof(struct mmpdu_authentication); + + if (!ft_build_authenticate_ies(hs, hs->supplicant_ocvc, info->snonce, + ies, &len)) + return; + + iov[1].iov_base = ies; + iov[1].iov_len = len; + + tx_frame(info->ifindex, 0x00b0, info->frequency, info->aa, iov, 2); +} + +static void ft_authenticate_destroy(int error, void *user_data) +{ + struct ft_info *info = user_data; + + info->offchannel_id = 0; + + if (!info->parsed) { + l_queue_remove(info_list, info); + ft_info_destroy(info); + } +} + +/* + * There is no callback here because its assumed that another work item will + * be inserted following this call which will check if authentication succeeded + * via ft_associate. + * + * If the netdev goes away while authentication is in-flight station will clear + * the authentications during cleanup, and in turn cancel the offchannel + * request. + */ +int ft_authenticate(uint32_t ifindex, const struct scan_bss *target) +{ + struct netdev *netdev = netdev_find(ifindex); + struct handshake_state *hs = netdev_get_handshake(netdev); + struct ft_info *info = ft_info_new(hs, target); + + info->offchannel_id = offchannel_start(netdev_get_wdev_id(netdev), + WIPHY_WORK_PRIORITY_FT, + target->frequency, + 200, ft_send_authenticate, info, + ft_authenticate_destroy); + + l_queue_push_tail(info_list, info); + + return 0; } -struct auth_proto *ft_over_ds_sm_new(struct handshake_state *hs, - ft_tx_associate_func_t tx_assoc, - void *user_data) +int ft_associate(uint32_t ifindex, const uint8_t *addr) { - struct ft_sm *ft = l_new(struct ft_sm, 1); + struct netdev *netdev = netdev_find(ifindex); + struct handshake_state *hs = netdev_get_handshake(netdev); + struct ft_info *info; + int ret; + + /* + * TODO: Since FT-over-DS is done early, before the time of roaming, it + * may end up that a completely new BSS is the best candidate and + * we haven't yet authenticated. We could actually authenticate + * at this point, but for now just assume the caller will choose + * a different BSS. + */ + info = ft_info_find(ifindex, addr); + if (!info) + return -ENOENT; + + /* + * Either failed or no response. This may have been an FT-over-DS + * attempt so clear out the entry so FT-over-Air can try again. + */ + if (!info->parsed) { + l_queue_remove(info_list, info); + ft_info_destroy(info); + + return -ENOENT; + } + + ft_prepare_handshake(info, hs); - ft->tx_assoc = tx_assoc; - ft->hs = hs; - ft->user_data = user_data; - ft->over_ds = true; + ret = ft_tx_reassociate(ifindex, info->frequency, info->prev_bssid); - ft->ap.rx_associate = ft_rx_associate; - ft->ap.start = ft_over_ds_start; - ft->ap.free = ft_sm_free; + /* After this no previous auths will be valid */ + ft_clear_authentications(ifindex); - return &ft->ap; + return ret; } + +static bool remove_ifindex(void *data, void *user_data) +{ + struct ft_info *info = data; + uint32_t ifindex = L_PTR_TO_UINT(user_data); + + if (info->ifindex != ifindex) + return false; + + if (info->offchannel_id) + offchannel_cancel(netdev_get_wdev_id(netdev_find(ifindex)), + info->offchannel_id); + + ft_info_destroy(info); + return true; +} + +void ft_clear_authentications(uint32_t ifindex) +{ + l_queue_foreach_remove(info_list, remove_ifindex, + L_UINT_TO_PTR(ifindex)); +} + +static int ft_init(void) +{ + info_list = l_queue_new(); + + return 0; +} + +static void ft_exit(void) +{ + if (!l_queue_isempty(info_list)) + l_warn("stale FT info objects found!"); + + l_queue_destroy(info_list, ft_info_destroy); +} + +IWD_MODULE(ft, ft_init, ft_exit); diff --git a/src/ft.h b/src/ft.h @@ -20,54 +20,26 @@ * */ -struct handshake_state; - -typedef void (*ft_tx_authenticate_func_t)(struct iovec *iov, size_t iov_len, - void *user_data); -typedef int (*ft_tx_associate_func_t)(struct iovec *ie_iov, size_t iov_len, - void *user_data); -typedef int (*ft_get_oci)(void *user_data); - -typedef void (*ft_ds_free_func_t)(void *user_data); - -struct ft_ds_info { - uint8_t spa[6]; - uint8_t aa[6]; - uint8_t snonce[32]; - uint8_t mde[3]; - uint8_t *fte; - uint8_t *authenticator_ie; - - struct ie_ft_info ft_info; - - void (*free)(struct ft_ds_info *s); -}; - -void ft_ds_info_free(struct ft_ds_info *info); - -bool ft_build_authenticate_ies(struct handshake_state *hs, bool ocvc, - const uint8_t *new_snonce, uint8_t *buf, - size_t *len); - -int ft_over_ds_parse_action_response(const uint8_t *frame, size_t frame_len, - const uint8_t **spa_out, - const uint8_t **aa_out, - const uint8_t **ies_out, - size_t *ies_len); -bool ft_over_ds_parse_action_ies(struct ft_ds_info *info, - struct handshake_state *hs, - const uint8_t *ies, - size_t ies_len); - -struct auth_proto *ft_over_air_sm_new(struct handshake_state *hs, - ft_tx_authenticate_func_t tx_auth, - ft_tx_associate_func_t tx_assoc, - ft_get_oci get_oci, - void *user_data); - -struct auth_proto *ft_over_ds_sm_new(struct handshake_state *hs, - ft_tx_associate_func_t tx_assoc, - void *user_data); - -bool ft_over_ds_prepare_handshake(struct ft_ds_info *info, - struct handshake_state *hs); +struct scan_bss; + +typedef int (*ft_tx_frame_func_t)(uint32_t ifindex, uint16_t frame_type, + uint32_t frequency, + const uint8_t *dest, struct iovec *iov, + size_t iov_len); + +typedef int (*ft_tx_associate_func_t)(uint32_t ifindex, uint32_t freq, + const uint8_t *prev_bssid, + struct iovec *ie_iov, size_t iov_len); + +void __ft_set_tx_frame_func(ft_tx_frame_func_t func); +void __ft_set_tx_associate_func(ft_tx_associate_func_t func); +int __ft_rx_associate(uint32_t ifindex, const uint8_t *frame, + size_t frame_len); +void __ft_rx_action(uint32_t ifindex, const uint8_t *frame, size_t frame_len); +void __ft_rx_authenticate(uint32_t ifindex, const uint8_t *frame, + size_t frame_len); + +void ft_clear_authentications(uint32_t ifindex); +int ft_action(uint32_t ifindex, uint32_t freq, const struct scan_bss *target); +int ft_associate(uint32_t ifindex, const uint8_t *addr); +int ft_authenticate(uint32_t ifindex, const struct scan_bss *target); diff --git a/src/ie.c b/src/ie.c @@ -428,13 +428,59 @@ uint32_t ie_rsn_cipher_suite_to_cipher(enum ie_rsn_cipher_suite suite) return CRYPTO_CIPHER_WEP40; case IE_RSN_CIPHER_SUITE_WEP104: return CRYPTO_CIPHER_WEP104; - case IE_RSN_CIPHER_SUITE_BIP: - return CRYPTO_CIPHER_BIP; + case IE_RSN_CIPHER_SUITE_BIP_CMAC: + return CRYPTO_CIPHER_BIP_CMAC; + case IE_RSN_CIPHER_SUITE_GCMP: + return CRYPTO_CIPHER_GCMP; + case IE_RSN_CIPHER_SUITE_GCMP_256: + return CRYPTO_CIPHER_GCMP_256; + case IE_RSN_CIPHER_SUITE_CCMP_256: + return CRYPTO_CIPHER_CCMP_256; + case IE_RSN_CIPHER_SUITE_BIP_GMAC: + return CRYPTO_CIPHER_BIP_GMAC; + case IE_RSN_CIPHER_SUITE_BIP_GMAC_256: + return CRYPTO_CIPHER_BIP_GMAC_256; + case IE_RSN_CIPHER_SUITE_BIP_CMAC_256: + return CRYPTO_CIPHER_BIP_CMAC_256; default: return 0; } } +const char *ie_rsn_cipher_suite_to_string(enum ie_rsn_cipher_suite suite) +{ + switch (suite) { + case IE_RSN_CIPHER_SUITE_CCMP: + return "CCMP-128"; + case IE_RSN_CIPHER_SUITE_TKIP: + return "TKIP"; + case IE_RSN_CIPHER_SUITE_WEP40: + return "WEP-40"; + case IE_RSN_CIPHER_SUITE_WEP104: + return "WEP-104"; + case IE_RSN_CIPHER_SUITE_BIP_CMAC: + return "BIP-CMAC-128"; + case IE_RSN_CIPHER_SUITE_GCMP: + return "GCMP-128"; + case IE_RSN_CIPHER_SUITE_GCMP_256: + return "GCMP-256"; + case IE_RSN_CIPHER_SUITE_CCMP_256: + return "CCMP-256"; + case IE_RSN_CIPHER_SUITE_NO_GROUP_TRAFFIC: + return "NO-TRAFFIC"; + case IE_RSN_CIPHER_SUITE_USE_GROUP_CIPHER: + break; + case IE_RSN_CIPHER_SUITE_BIP_GMAC: + return "BIP-GMAC-128"; + case IE_RSN_CIPHER_SUITE_BIP_GMAC_256: + return "BIP-GMAC-256"; + case IE_RSN_CIPHER_SUITE_BIP_CMAC_256: + return "BIP-CMAC-256"; + } + + return NULL; +} + /* 802.11, Section 8.4.2.27.2 */ static bool ie_parse_cipher_suite(const uint8_t *data, enum ie_rsn_cipher_suite *out) @@ -462,11 +508,29 @@ static bool ie_parse_cipher_suite(const uint8_t *data, *out = IE_RSN_CIPHER_SUITE_WEP104; return true; case 6: - *out = IE_RSN_CIPHER_SUITE_BIP; + *out = IE_RSN_CIPHER_SUITE_BIP_CMAC; return true; case 7: *out = IE_RSN_CIPHER_SUITE_NO_GROUP_TRAFFIC; return true; + case 8: + *out = IE_RSN_CIPHER_SUITE_GCMP; + return true; + case 9: + *out = IE_RSN_CIPHER_SUITE_GCMP_256; + return true; + case 10: + *out = IE_RSN_CIPHER_SUITE_CCMP_256; + return true; + case 11: + *out = IE_RSN_CIPHER_SUITE_BIP_GMAC; + return true; + case 12: + *out = IE_RSN_CIPHER_SUITE_BIP_GMAC_256; + return true; + case 13: + *out = IE_RSN_CIPHER_SUITE_BIP_CMAC_256; + return true; default: return false; } @@ -580,6 +644,9 @@ static bool ie_parse_group_cipher(const uint8_t *data, case IE_RSN_CIPHER_SUITE_WEP104: case IE_RSN_CIPHER_SUITE_WEP40: case IE_RSN_CIPHER_SUITE_NO_GROUP_TRAFFIC: + case IE_RSN_CIPHER_SUITE_GCMP: + case IE_RSN_CIPHER_SUITE_GCMP_256: + case IE_RSN_CIPHER_SUITE_CCMP_256: break; default: return false; @@ -589,15 +656,14 @@ static bool ie_parse_group_cipher(const uint8_t *data, return true; } -static bool ie_parse_pairwise_cipher(const uint8_t *data, +static int ie_parse_pairwise_cipher(const uint8_t *data, enum ie_rsn_cipher_suite *out) { enum ie_rsn_cipher_suite tmp; - bool r = ie_parse_cipher_suite(data, &tmp); if (!r) - return r; + return -ENOENT; switch (tmp) { case IE_RSN_CIPHER_SUITE_CCMP: @@ -605,13 +671,16 @@ static bool ie_parse_pairwise_cipher(const uint8_t *data, case IE_RSN_CIPHER_SUITE_WEP104: case IE_RSN_CIPHER_SUITE_WEP40: case IE_RSN_CIPHER_SUITE_USE_GROUP_CIPHER: + case IE_RSN_CIPHER_SUITE_GCMP: + case IE_RSN_CIPHER_SUITE_GCMP_256: + case IE_RSN_CIPHER_SUITE_CCMP_256: break; default: - return false; + return -ERANGE; } *out = tmp; - return true; + return 0; } static bool ie_parse_group_management_cipher(const uint8_t *data, @@ -625,8 +694,11 @@ static bool ie_parse_group_management_cipher(const uint8_t *data, return r; switch (tmp) { - case IE_RSN_CIPHER_SUITE_BIP: + case IE_RSN_CIPHER_SUITE_BIP_CMAC: case IE_RSN_CIPHER_SUITE_NO_GROUP_TRAFFIC: + case IE_RSN_CIPHER_SUITE_BIP_GMAC: + case IE_RSN_CIPHER_SUITE_BIP_GMAC_256: + case IE_RSN_CIPHER_SUITE_BIP_CMAC_256: break; default: return false; @@ -682,9 +754,12 @@ static int parse_ciphers(const uint8_t *data, size_t len, /* Parse Pairwise Cipher Suite List field */ for (i = 0, out_info->pairwise_ciphers = 0; i < count; i++) { enum ie_rsn_cipher_suite suite; + int r = ie_parse_pairwise_cipher(data + i * 4, &suite); - if (!ie_parse_pairwise_cipher(data + i * 4, &suite)) - return -ERANGE; + if (r == -ENOENT) /* Skip unknown */ + continue; + else if (r < 0) + return r; out_info->pairwise_ciphers |= suite; } @@ -746,7 +821,8 @@ static int parse_ciphers(const uint8_t *data, size_t len, * management frame protection enabled */ if (out_info->mfpc) - out_info->group_management_cipher = IE_RSN_CIPHER_SUITE_BIP; + out_info->group_management_cipher = + IE_RSN_CIPHER_SUITE_BIP_CMAC; RSNE_ADVANCE(data, len, 2); @@ -884,38 +960,55 @@ int ie_parse_osen_from_data(const uint8_t *data, size_t len, static bool ie_build_cipher_suite(uint8_t *data, const uint8_t *oui, const enum ie_rsn_cipher_suite suite) { + uint8_t selector; + switch (suite) { case IE_RSN_CIPHER_SUITE_USE_GROUP_CIPHER: - memcpy(data, oui, 3); - data[3] = 0; - return true; + selector = 0; + goto done; case IE_RSN_CIPHER_SUITE_WEP40: - memcpy(data, oui, 3); - data[3] = 1; - return true; + selector = 1; + goto done; case IE_RSN_CIPHER_SUITE_TKIP: - memcpy(data, oui, 3); - data[3] = 2; - return true; + selector = 2; + goto done; case IE_RSN_CIPHER_SUITE_CCMP: - memcpy(data, oui, 3); - data[3] = 4; - return true; + selector = 4; + goto done; case IE_RSN_CIPHER_SUITE_WEP104: - memcpy(data, oui, 3); - data[3] = 5; - return true; - case IE_RSN_CIPHER_SUITE_BIP: - memcpy(data, oui, 3); - data[3] = 6; - return true; + selector = 5; + goto done; + case IE_RSN_CIPHER_SUITE_BIP_CMAC: + selector = 6; + goto done; case IE_RSN_CIPHER_SUITE_NO_GROUP_TRAFFIC: - memcpy(data, oui, 3); - data[3] = 7; - return true; + selector = 7; + goto done; + case IE_RSN_CIPHER_SUITE_GCMP: + selector = 8; + goto done; + case IE_RSN_CIPHER_SUITE_GCMP_256: + selector = 9; + goto done; + case IE_RSN_CIPHER_SUITE_CCMP_256: + selector = 10; + goto done; + case IE_RSN_CIPHER_SUITE_BIP_GMAC: + selector = 11; + goto done; + case IE_RSN_CIPHER_SUITE_BIP_GMAC_256: + selector = 12; + goto done; + case IE_RSN_CIPHER_SUITE_BIP_CMAC_256: + selector = 13; + goto done; } return false; +done: + memcpy(data, oui, 3); + data[3] = selector; + return true; } #define RETURN_AKM(data, oui, id) \ @@ -997,6 +1090,9 @@ static int build_ciphers_common(const struct ie_rsn_info *info, uint8_t *to, IE_RSN_CIPHER_SUITE_WEP104, IE_RSN_CIPHER_SUITE_WEP40, IE_RSN_CIPHER_SUITE_USE_GROUP_CIPHER, + IE_RSN_CIPHER_SUITE_GCMP, + IE_RSN_CIPHER_SUITE_GCMP_256, + IE_RSN_CIPHER_SUITE_CCMP_256, }; unsigned int pos = 0; unsigned int i; @@ -1115,7 +1211,7 @@ static int build_ciphers_common(const struct ie_rsn_info *info, uint8_t *to, else if (!info->mfpc) goto done; else if (info->group_management_cipher == - IE_RSN_CIPHER_SUITE_BIP) + IE_RSN_CIPHER_SUITE_BIP_CMAC) goto done; } @@ -1136,7 +1232,7 @@ static int build_ciphers_common(const struct ie_rsn_info *info, uint8_t *to, goto done; if (!force_group_mgmt_cipher && info->group_management_cipher == - IE_RSN_CIPHER_SUITE_BIP) + IE_RSN_CIPHER_SUITE_BIP_CMAC) goto done; /* Group Management Cipher Suite */ diff --git a/src/ie.h b/src/ie.h @@ -329,8 +329,14 @@ enum ie_rsn_cipher_suite { IE_RSN_CIPHER_SUITE_TKIP = 0x0004, IE_RSN_CIPHER_SUITE_CCMP = 0x0008, IE_RSN_CIPHER_SUITE_WEP104 = 0x0010, - IE_RSN_CIPHER_SUITE_BIP = 0x0020, + IE_RSN_CIPHER_SUITE_BIP_CMAC = 0x0020, IE_RSN_CIPHER_SUITE_NO_GROUP_TRAFFIC = 0x0040, + IE_RSN_CIPHER_SUITE_GCMP = 0x0080, + IE_RSN_CIPHER_SUITE_GCMP_256 = 0x0100, + IE_RSN_CIPHER_SUITE_CCMP_256 = 0x0200, + IE_RSN_CIPHER_SUITE_BIP_GMAC = 0x0400, + IE_RSN_CIPHER_SUITE_BIP_GMAC_256 = 0x0800, + IE_RSN_CIPHER_SUITE_BIP_CMAC_256 = 0x1000, }; enum ie_rsn_akm_suite { @@ -387,6 +393,33 @@ static inline bool IE_AKM_IS_8021X(uint32_t akm) IE_RSN_AKM_SUITE_FT_OVER_8021X_SHA384); } +static inline bool IE_CIPHER_IS_GCMP_CCMP(uint32_t cipher_suite) +{ + return cipher_suite & (IE_RSN_CIPHER_SUITE_CCMP | + IE_RSN_CIPHER_SUITE_CCMP_256 | + IE_RSN_CIPHER_SUITE_GCMP | + IE_RSN_CIPHER_SUITE_GCMP_256); +} + +#define IE_GROUP_CIPHERS \ +( \ + IE_RSN_CIPHER_SUITE_TKIP | \ + IE_RSN_CIPHER_SUITE_CCMP | \ + IE_RSN_CIPHER_SUITE_GCMP | \ + IE_RSN_CIPHER_SUITE_GCMP_256 | \ + IE_RSN_CIPHER_SUITE_CCMP_256 \ +) + +/* + * Since WEP is unsupported we can just use the group cipher list with + * "Use group cipher" appended + */ +#define IE_PAIRWISE_CIPHERS \ +( \ + IE_GROUP_CIPHERS | \ + IE_RSN_CIPHER_SUITE_USE_GROUP_CIPHER \ +) + #define IE_LEN(ie) \ ((ie) ? (ie)[1] + 2 : 0) @@ -586,6 +619,7 @@ unsigned char *ie_tlv_builder_finalize(struct ie_tlv_builder *builder, size_t *out_len); uint32_t ie_rsn_cipher_suite_to_cipher(enum ie_rsn_cipher_suite suite); +const char *ie_rsn_cipher_suite_to_string(enum ie_rsn_cipher_suite suite); int ie_parse_rsne(struct ie_tlv_iter *iter, struct ie_rsn_info *info); int ie_parse_rsne_from_data(const uint8_t *data, size_t len, diff --git a/src/iwd.ap.rst b/src/iwd.ap.rst @@ -82,6 +82,21 @@ configuration. Processed passphrase for this network in the form of a hex-encoded 32-byte pre-shared key. Either this or *Passphrase* must be present. + * - PairwiseCiphers + - Comma separated list of pairwise ciphers for the AP supports. + + Values can include: TKIP, CCMP, GCMP, GCMP-256, CCMP-256 + + The underlying hardware and IWD's AP implementation must also support the + ciphers listed + + * - GroupCipher + - Group cipher the AP uses + + A single cipher value the AP can use as the group cipher. Values are the + same as pairwise ciphers and the same restrictions apply (hardware and + IWD implementation must support the cipher) + IPv4 Network Configuration -------------------------- diff --git a/src/iwd.config.rst b/src/iwd.config.rst @@ -206,6 +206,16 @@ The group ``[General]`` contains general settings. required are LoadCredentialEncrypted or SetCredentialEncrypted, and the secret identifier should be named whatever SystemdEncrypt is set to. + * - Country + - Value: Country Code (ISO Alpha-2) + + Requests the country be set for the system. Note that setting this is + simply a **request** to set the country, and does not guarantee the + country will be set. For a self-managed wiphy it is never possible to set + the country from userspace. For other devices any regulatory domain + request is just a 'hint' and ultimately left up to the kernel to set the + country. + Network ------- @@ -218,7 +228,7 @@ The group ``[Network]`` contains network configuration related settings. :align: left * - EnableIPv6 - - Values: true, **false** + - Values: **true**, false Sets the global default that tells **iwd** whether it should configure IPv6 addresses and routes (either provided via static settings, @@ -300,6 +310,13 @@ autoconnect purposes. networks are highly RSSI sensitive, so it is still possible for IWD to prefer 2.4Ghz APs in certain circumstances. + * - BandModifier6Ghz + - Values: floating point value (default: **1.0**) + + Increase or decrease the preference for 6GHz access points by increasing + or decreasing the value of this modifier. Since 6GHz networks are highly + RSSI sensitive, this gives an option to prefer 6GHz APs over 5GHz APs. + Scan ---- diff --git a/src/iwd.service.in b/src/iwd.service.in @@ -1,5 +1,6 @@ [Unit] Description=Wireless service +Documentation=man:iwd(8) man:iwd.config(5) man:iwd.network(5) man:iwd.ap(5) After=network-pre.target Before=network.target Wants=network.target diff --git a/src/json.c b/src/json.c @@ -30,6 +30,9 @@ #include "src/json.h" +#define JSMN_STATIC +#define JSMN_STRICT +#define JSMN_PARENT_LINKS #include "shared/jsmn.h" /* Max number of tokens supported. Increase if larger objects are expected */ diff --git a/src/json.h b/src/json.h @@ -27,10 +27,10 @@ struct json_iter; */ enum json_type { JSON_UNDEFINED = 0, - JSON_OBJECT = 1, - JSON_ARRAY = 2, - JSON_STRING = 3, - JSON_PRIMITIVE = 4 + JSON_OBJECT = 1 << 0, + JSON_ARRAY = 1 << 1, + JSON_STRING = 1 << 2, + JSON_PRIMITIVE = 1 << 3, }; enum json_flag { diff --git a/src/manager.c b/src/manager.c @@ -800,6 +800,14 @@ static void manager_config_notify(struct l_genl_msg *msg, void *user_data) } } +static void manager_set_reg_cb(struct l_genl_msg *msg, void *user_data) +{ + int err = l_genl_msg_get_error(msg); + + if (err < 0) + l_error("Failed to set country (%d)", err); +} + static int manager_init(void) { struct l_genl *genl = iwd_get_genl(); @@ -810,6 +818,7 @@ static int manager_init(void) const char *randomize_str; const char *if_whitelist = iwd_get_iface_whitelist(); const char *if_blacklist = iwd_get_iface_blacklist(); + const char *cc; nl80211 = l_genl_family_new(genl, NL80211_GENL_NAME); @@ -853,6 +862,23 @@ static int manager_init(void) goto error; } + cc = l_settings_get_value(config, "General", "Country"); + if (cc) { + if (strlen(cc) != 2 || !l_ascii_isalpha(cc[0]) || + !l_ascii_isalpha(cc[1])) { + l_warn("[General].Country=%s is invalid. Country will " + "not be set", cc); + } else { + msg = l_genl_msg_new(NL80211_CMD_REQ_SET_REG); + l_genl_msg_append_attr(msg, NL80211_ATTR_REG_ALPHA2, + 2, cc); + if (!l_genl_family_send(nl80211, msg, + manager_set_reg_cb, + NULL, NULL)) + l_warn("Failed to set country"); + } + } + randomize_str = l_settings_get_value(config, "General", "AddressRandomization"); if (randomize_str) { diff --git a/src/mpdu.h b/src/mpdu.h @@ -374,7 +374,7 @@ struct mmpdu_probe_request { /* 802.11, Section 8.3.3.10 */ struct mmpdu_probe_response { - uint8_t timestamp; + __le64 timestamp; __le16 beacon_interval; struct mmpdu_field_capability capability; uint8_t ies[0]; @@ -382,14 +382,14 @@ struct mmpdu_probe_response { /* 802.11, Section 8.3.3.15 */ struct mmpdu_timing_advertisement { - uint8_t timestamp; + __le64 timestamp; struct mmpdu_field_capability capability; uint8_t ies[0]; } __attribute__ ((packed)); /* 802.11, Section 8.3.3.2 */ struct mmpdu_beacon { - uint8_t timestamp; + __le64 timestamp; __le16 beacon_interval; struct mmpdu_field_capability capability; uint8_t ies[0]; diff --git a/src/netconfig-commit.c b/src/netconfig-commit.c @@ -0,0 +1,711 @@ +/* + * + * Wireless daemon for Linux + * + * Copyright (C) 2022 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 <arpa/inet.h> +#include <netinet/if_ether.h> +#include <linux/icmpv6.h> + +#include <ell/ell.h> + +#include "ell/useful.h" +#include "src/iwd.h" +#include "src/common.h" +#include "src/util.h" +#include "src/netdev.h" +#include "src/ie.h" +#include "src/resolve.h" +#include "src/dbus.h" +#include "src/netconfig.h" + +struct netconfig_commit_ops { + bool (*init_data)(struct netconfig *netconfig); + void (*free_data)(struct netconfig *netconfig, const char *reasonstr); + void (*commit)(struct netconfig *netconfig, uint8_t family, + enum l_netconfig_event event); +}; + +static struct l_netlink *rtnl; + +static void netconfig_rtnl_commit(struct netconfig *netconfig, uint8_t family, + enum l_netconfig_event event); +static void netconfig_rtnl_free_data(struct netconfig *netconfig, + const char *reasonstr); + +/* Default backend */ +static struct netconfig_commit_ops netconfig_rtnl_ops = { + .commit = netconfig_rtnl_commit, + .free_data = netconfig_rtnl_free_data, +}; + +/* Same backend for all netconfig objects */ +static const struct netconfig_commit_ops *commit_ops = &netconfig_rtnl_ops; + +static struct l_queue *netconfig_list; + +void netconfig_commit_init(struct netconfig *netconfig) +{ + if (!rtnl) + rtnl = l_rtnl_get(); + + if (!netconfig_list) + netconfig_list = l_queue_new(); + + l_queue_push_tail(netconfig_list, netconfig); + + L_WARN_ON(netconfig->commit_data); + + if (commit_ops->init_data) + commit_ops->init_data(netconfig); +} + +void netconfig_commit_free(struct netconfig *netconfig, const char *reasonstr) +{ + if (commit_ops->free_data) + commit_ops->free_data(netconfig, reasonstr); + + L_WARN_ON(!l_queue_remove(netconfig_list, netconfig)); + + if (l_queue_isempty(netconfig_list)) + l_queue_destroy(l_steal_ptr(netconfig_list), NULL); +} + +static void netconfig_commit_print_addrs(const char *verb, + const struct l_queue_entry *addrs) +{ + for (; addrs; addrs = addrs->next) { + const struct l_rtnl_address *addr = addrs->data; + char str[INET6_ADDRSTRLEN]; + + if (l_rtnl_address_get_address(addr, str)) + l_debug("%s address: %s", verb, str); + } +} + +void netconfig_commit(struct netconfig *netconfig, uint8_t family, + enum l_netconfig_event event) +{ + const struct l_queue_entry *added; + const struct l_queue_entry *removed; + const struct l_queue_entry *expired; + + l_netconfig_get_addresses(netconfig->nc, &added, NULL, + &removed, &expired); + + /* Only print IP additions and removals to avoid cluttering the log */ + netconfig_commit_print_addrs("installing", added); + netconfig_commit_print_addrs("removing", removed); + netconfig_commit_print_addrs("expired", expired); + + commit_ops->commit(netconfig, family, event); + + if (event == L_NETCONFIG_EVENT_CONFIGURE) { + /* + * Done here instead of in ops->commit because the MACs are + * not considered part of the network configuration + * (particularly Network Manager's "level 3 config" or l3cfg) + * so we can handle this ourselves independent of the backend. + */ + if (family == AF_INET && + !netconfig->static_config[INDEX_FOR_AF(family)]) + netconfig_dhcp_gateway_to_arp(netconfig); + + if (!netconfig->connected[INDEX_FOR_AF(family)] && + netconfig_use_fils_addr(netconfig, family)) + netconfig_commit_fils_macs(netconfig, family); + } +} + +static void netconfig_switch_backend(const struct netconfig_commit_ops *new_ops) +{ + const struct l_queue_entry *entry; + + for (entry = l_queue_get_entries(netconfig_list); entry; + entry = entry->next) { + struct netconfig *netconfig = entry->data; + + if (commit_ops->free_data) + commit_ops->free_data(netconfig, ""); + + if (new_ops->init_data) + new_ops->init_data(netconfig); + } + + commit_ops = new_ops; +} + +/* + * Called by all backends when netconfig_commit finishes, synchronously or + * asynchronously. + */ +static void netconfig_commit_done(struct netconfig *netconfig, uint8_t family, + enum l_netconfig_event event, + bool success) +{ + bool connected = netconfig->connected[INDEX_FOR_AF(family)]; + + if (!success) { + netconfig->connected[INDEX_FOR_AF(family)] = false; + + if (netconfig->notify && family == AF_INET) + netconfig->notify(NETCONFIG_EVENT_FAILED, + netconfig->user_data); + return; + } + + switch (event) { + case L_NETCONFIG_EVENT_CONFIGURE: + case L_NETCONFIG_EVENT_UPDATE: + netconfig->connected[INDEX_FOR_AF(family)] = true; + + if (family == AF_INET && !connected && netconfig->notify) + netconfig->notify(NETCONFIG_EVENT_CONNECTED, + netconfig->user_data); + + break; + + case L_NETCONFIG_EVENT_UNCONFIGURE: + case L_NETCONFIG_EVENT_FAILED: + break; + } +} + +static void netconfig_set_neighbor_entry_cb(int error, + uint16_t type, const void *data, + uint32_t len, void *user_data) +{ + if (error) + l_error("l_rtnl_neighbor_set_hwaddr failed: %s (%i)", + strerror(-error), error); +} + +void netconfig_dhcp_gateway_to_arp(struct netconfig *netconfig) +{ + struct l_dhcp_client *dhcp = l_netconfig_get_dhcp_client(netconfig->nc); + const struct l_dhcp_lease *lease; + _auto_(l_free) char *server_id = NULL; + _auto_(l_free) char *gw = NULL; + const uint8_t *server_mac; + struct in_addr in_gw; + uint32_t ifindex = netdev_get_ifindex(netconfig->netdev); + + /* Can only do this for DHCP in certain network setups */ + if (netconfig->static_config[INDEX_FOR_AF(AF_INET)] || + netconfig->fils_override) + return; + + lease = l_dhcp_client_get_lease(dhcp); + if (!lease) + return; + + server_id = l_dhcp_lease_get_server_id(lease); + gw = l_dhcp_lease_get_gateway(lease); + server_mac = l_dhcp_lease_get_server_mac(lease); + + if (!gw || strcmp(server_id, gw) || !server_mac) + return; + + l_debug("Gateway MAC is known, setting into ARP cache"); + in_gw.s_addr = l_dhcp_lease_get_gateway_u32(lease); + + if (!l_rtnl_neighbor_set_hwaddr(rtnl, ifindex, AF_INET, + &in_gw, server_mac, ETH_ALEN, + netconfig_set_neighbor_entry_cb, NULL, + NULL)) + l_debug("l_rtnl_neighbor_set_hwaddr failed"); +} + +void netconfig_commit_fils_macs(struct netconfig *netconfig, uint8_t family) +{ + const struct ie_fils_ip_addr_response_info *fils = + netconfig->fils_override; + const void *addr; + const void *hwaddr; + size_t addr_len = (family == AF_INET ? 4 : 16); + uint32_t ifindex = netdev_get_ifindex(netconfig->netdev); + + if (!fils) + return; + + /* + * Attempt to use the gateway/DNS MAC addressed received from the AP + * by writing the mapping directly into the netdev's ARP table so as + * to save one data frame roundtrip before first IP connections are + * established. This is very low-priority but print error messages + * just because they may indicate bigger problems. + */ + + addr = (family == AF_INET ? (void *) &fils->ipv4_gateway : + (void *) &fils->ipv6_gateway); + hwaddr = (family == AF_INET ? + &fils->ipv4_gateway_mac : &fils->ipv6_gateway_mac); + + if (!l_memeqzero(addr, addr_len) && !l_memeqzero(hwaddr, ETH_ALEN) && + unlikely(!l_rtnl_neighbor_set_hwaddr(rtnl, ifindex, + family, addr, hwaddr, ETH_ALEN, + netconfig_set_neighbor_entry_cb, + NULL, NULL))) + l_debug("l_rtnl_neighbor_set_hwaddr(%s, gateway) failed", + family == AF_INET ? "AF_INET" : "AF_INET6"); + + addr = (family == AF_INET ? (void *) &fils->ipv4_dns : + (void *) &fils->ipv6_dns); + hwaddr = (family == AF_INET ? + &fils->ipv4_dns_mac : &fils->ipv6_dns_mac); + + if (!l_memeqzero(addr, addr_len) && !l_memeqzero(hwaddr, ETH_ALEN) && + unlikely(!l_rtnl_neighbor_set_hwaddr(rtnl, ifindex, + family, addr, hwaddr, ETH_ALEN, + netconfig_set_neighbor_entry_cb, + NULL, NULL))) + l_debug("l_rtnl_neighbor_set_hwaddr(%s, DNS) failed", + family == AF_INET ? "AF_INET" : "AF_INET6"); +} + +static void netconfig_dns_list_update(struct netconfig *netconfig) +{ + _auto_(l_strv_free) char **dns_list = + l_netconfig_get_dns_list(netconfig->nc); + + if (l_strv_eq(netconfig->dns_list, dns_list)) + return; + + if (netconfig->resolve && dns_list) + resolve_set_dns(netconfig->resolve, dns_list); + + l_strv_free(netconfig->dns_list); + netconfig->dns_list = l_steal_ptr(dns_list); +} + +static void netconfig_domains_update(struct netconfig *netconfig) +{ + _auto_(l_strv_free) char **domains = + l_netconfig_get_domain_names(netconfig->nc); + + if (l_strv_eq(netconfig->domains, domains)) + return; + + if (netconfig->resolve && domains) + resolve_set_domains(netconfig->resolve, domains); + + l_strv_free(netconfig->domains); + netconfig->dns_list = l_steal_ptr(domains); +} + +static void netconfig_rtnl_commit(struct netconfig *netconfig, uint8_t family, + enum l_netconfig_event event) +{ + l_netconfig_apply_rtnl(netconfig->nc); + + netconfig_dns_list_update(netconfig); + netconfig_domains_update(netconfig); + + if (event == L_NETCONFIG_EVENT_CONFIGURE && family == AF_INET) + /* + * netconfig->mdns is currently only loaded in + * netconfig_load_settings() so we can set it once on + * the CONFIGURE event. + */ + resolve_set_mdns(netconfig->resolve, netconfig->mdns); + + if (event == L_NETCONFIG_EVENT_UNCONFIGURE && family == AF_INET) { + l_strv_free(l_steal_ptr(netconfig->dns_list)); + l_strv_free(l_steal_ptr(netconfig->domains)); + resolve_revert(netconfig->resolve); + } + + netconfig_commit_done(netconfig, family, event, true); +} + +static void netconfig_rtnl_free_data(struct netconfig *netconfig, + const char *reasonstr) +{ + l_strv_free(l_steal_ptr(netconfig->dns_list)); + l_strv_free(l_steal_ptr(netconfig->domains)); +} + + +struct netconfig_agent_data { + uint32_t pending_id[2]; +}; + +struct netconfig_agent_call_data { + struct netconfig *netconfig; + uint8_t family; + enum l_netconfig_event event; +}; + +static char *netconfig_agent_name; +static char *netconfig_agent_path; +static unsigned int netconfig_agent_watch; + +static void netconfig_agent_cancel(struct netconfig *netconfig, uint8_t family, + const char *reasonstr) +{ + struct netconfig_agent_data *data = netconfig->commit_data; + struct l_dbus *dbus = dbus_get_bus(); + const char *dev_path = netdev_get_path(netconfig->netdev); + struct l_dbus_message *message; + const char *method; + + if (!data || !data->pending_id[INDEX_FOR_AF(family)]) + return; + + l_dbus_cancel(dbus, data->pending_id[INDEX_FOR_AF(family)]); + data->pending_id[INDEX_FOR_AF(family)] = 0; + + method = (family == AF_INET ? "CancelIPv4" : "CancelIPv6"); + l_debug("sending a %s(%s, %s) to %s %s", method, dev_path, reasonstr, + netconfig_agent_name, netconfig_agent_path); + + message = l_dbus_message_new_method_call(dbus, netconfig_agent_name, + netconfig_agent_path, + IWD_NETCONFIG_AGENT_INTERFACE, + method); + l_dbus_message_set_arguments(message, "os", dev_path, reasonstr); + l_dbus_message_set_no_reply(message, true); + l_dbus_send(dbus, message); +} + +static void netconfig_agent_receive_reply(struct l_dbus_message *reply, + void *user_data) +{ + struct netconfig_agent_call_data *cd = user_data; + struct netconfig_agent_data *data = cd->netconfig->commit_data; + const char *error, *text; + bool success = true; + + l_debug("agent reply from %s", l_dbus_message_get_sender(reply)); + + data->pending_id[INDEX_FOR_AF(cd->family)] = 0; + + if (!cd->netconfig->started) + return; + + if (l_dbus_message_get_error(reply, &error, &text)) { + success = false; + l_error("netconfig agent call returned %s(\"%s\")", + error, text); + } else if (!l_dbus_message_get_arguments(reply, "")) { + success = false; + l_error("netconfig agent call reply signature wrong: %s", + l_dbus_message_get_signature(reply)); + } + + netconfig_commit_done(cd->netconfig, cd->family, cd->event, success); +} + +#define IS_IPV6_STR_FAST(str) (strchr(str, ':') != NULL) + +typedef void (*netconfig_build_entry_fn)(struct l_dbus_message_builder *builder, + const void *data, uint8_t family); + +static void netconfig_agent_append_dict_dict_array( + struct l_dbus_message_builder *builder, + const char *key, + const struct l_queue_entry *value, + netconfig_build_entry_fn build_entry, + uint8_t family) +{ + l_dbus_message_builder_enter_dict(builder, "sv"); + l_dbus_message_builder_append_basic(builder, 's', key); + l_dbus_message_builder_enter_variant(builder, "aa{sv}"); + l_dbus_message_builder_enter_array(builder, "a{sv}"); + + for (; value; value = value->next) + build_entry(builder, value->data, family); + + l_dbus_message_builder_leave_array(builder); + l_dbus_message_builder_leave_variant(builder); + l_dbus_message_builder_leave_dict(builder); +} + +static void netconfig_agent_append_dict_strv( + struct l_dbus_message_builder *builder, + const char *key, char **value, + uint8_t family) +{ + if (!value) + return; + + l_dbus_message_builder_enter_dict(builder, "sv"); + l_dbus_message_builder_append_basic(builder, 's', key); + l_dbus_message_builder_enter_variant(builder, "as"); + l_dbus_message_builder_enter_array(builder, "s"); + + for (; *value; value++) { + uint8_t value_family = IS_IPV6_STR_FAST((char *) *value) ? + AF_INET6 : AF_INET; + + if (family == AF_UNSPEC || value_family == family) + l_dbus_message_builder_append_basic(builder, 's', + *value); + } + + l_dbus_message_builder_leave_array(builder); + l_dbus_message_builder_leave_variant(builder); + l_dbus_message_builder_leave_dict(builder); +} + +static void netconfig_agent_append_address( + struct l_dbus_message_builder *builder, + const void *data, uint8_t family) +{ + const struct l_rtnl_address *addr = data; + char addr_str[INET6_ADDRSTRLEN]; + uint64_t valid_expiry_time; + uint64_t preferred_expiry_time; + uint64_t now = l_time_now(); + + if (l_rtnl_address_get_family(addr) != family) + return; + + l_dbus_message_builder_enter_array(builder, "{sv}"); + + l_rtnl_address_get_address(addr, addr_str); + dbus_append_dict_basic(builder, "Address", 's', addr_str); + + if (family == AF_INET) { + uint8_t plen = l_rtnl_address_get_prefix_length(addr); + dbus_append_dict_basic(builder, "PrefixLength", 'y', &plen); + + if (l_rtnl_address_get_broadcast(addr, addr_str) && + strcmp(addr_str, "0.0.0.0")) + dbus_append_dict_basic(builder, "Broadcast", 's', + addr_str); + } + + l_rtnl_address_get_expiry(addr, &preferred_expiry_time, + &valid_expiry_time); + + if (valid_expiry_time > now) { + uint32_t lt = l_time_to_secs(valid_expiry_time - now); + + dbus_append_dict_basic(builder, "ValidLifetime", 'u', &lt); + } + + if (preferred_expiry_time > now) { + uint32_t lt = l_time_to_secs(preferred_expiry_time - now); + + dbus_append_dict_basic(builder, "PreferredLifetime", 'u', &lt); + } + + l_dbus_message_builder_leave_array(builder); +} + +static void netconfig_agent_append_route(struct l_dbus_message_builder *builder, + const void *data, + uint8_t family) +{ + const struct l_rtnl_route *rt = data; + char addr_str[INET6_ADDRSTRLEN]; + uint8_t prefix_len; + uint64_t expiry_time; + uint64_t now = l_time_now(); + uint32_t priority; + uint8_t preference; + uint32_t mtu; + + if (l_rtnl_route_get_family(rt) != family) + return; + + l_dbus_message_builder_enter_array(builder, "{sv}"); + + if (l_rtnl_route_get_dst(rt, addr_str, &prefix_len) && prefix_len) { + l_dbus_message_builder_enter_dict(builder, "sv"); + l_dbus_message_builder_append_basic(builder, 's', + "Destination"); + l_dbus_message_builder_enter_variant(builder, "(sy)"); + l_dbus_message_builder_enter_struct(builder, "sy"); + l_dbus_message_builder_append_basic(builder, 's', addr_str); + l_dbus_message_builder_append_basic(builder, 'y', &prefix_len); + l_dbus_message_builder_leave_struct(builder); + l_dbus_message_builder_leave_variant(builder); + l_dbus_message_builder_leave_dict(builder); + } + + if (l_rtnl_route_get_gateway(rt, addr_str)) + dbus_append_dict_basic(builder, "Router", 's', addr_str); + + if (l_rtnl_route_get_prefsrc(rt, addr_str)) + dbus_append_dict_basic(builder, "PreferredSource", 's', + addr_str); + + expiry_time = l_rtnl_route_get_expiry(rt); + if (expiry_time > now) { + uint32_t lt = l_time_to_secs(expiry_time - now); + + dbus_append_dict_basic(builder, "Lifetime", 'u', &lt); + } + + priority = l_rtnl_route_get_priority(rt); + dbus_append_dict_basic(builder, "Priority", 'u', &priority); + + /* + * ICMPV6_ROUTER_PREF_MEDIUM is returned by default even for IPv4 + * routes where this property doesn't make sense so filter those out. + */ + preference = l_rtnl_route_get_preference(rt); + if (preference != ICMPV6_ROUTER_PREF_INVALID && family == AF_INET6) + dbus_append_dict_basic(builder, "Preference", 'y', &preference); + + mtu = l_rtnl_route_get_mtu(rt); + if (mtu) + dbus_append_dict_basic(builder, "Priority", 'u', &mtu); + + l_dbus_message_builder_leave_array(builder); +} + +static void netconfig_agent_commit(struct netconfig *netconfig, uint8_t family, + enum l_netconfig_event event) +{ + struct netconfig_agent_data *data; + struct netconfig_agent_call_data *cd; + struct l_dbus *dbus = dbus_get_bus(); + struct l_dbus_message *message; + struct l_dbus_message_builder *builder; + const char *dev_path = netdev_get_path(netconfig->netdev); + const char *dbus_method = + (family == AF_INET ? "ConfigureIPv4" : "ConfigureIPv6"); + const char *cfg_method = + netconfig->static_config[INDEX_FOR_AF(family)] ? + "static" : "auto"; + _auto_(l_strv_free) char **dns_list = NULL; + _auto_(l_strv_free) char **domains = NULL; + + if (!netconfig->commit_data) + netconfig->commit_data = l_new(struct netconfig_agent_data, 1); + + netconfig_agent_cancel(netconfig, family, "superseded"); + + l_debug("sending a %s(%s, ...) to %s %s", dbus_method, dev_path, + netconfig_agent_name, netconfig_agent_path); + + message = l_dbus_message_new_method_call(dbus, netconfig_agent_name, + netconfig_agent_path, + IWD_NETCONFIG_AGENT_INTERFACE, + dbus_method); + + /* + * Build the call arguments: the Device object path and + * the complicated config dict. + */ + builder = l_dbus_message_builder_new(message); + l_dbus_message_builder_append_basic(builder, 'o', dev_path); + l_dbus_message_builder_enter_array(builder, "{sv}"); + dbus_append_dict_basic(builder, "Method", 's', cfg_method); + + netconfig_agent_append_dict_dict_array(builder, "Addresses", + l_netconfig_get_addresses(netconfig->nc, + NULL, NULL, NULL, NULL), + netconfig_agent_append_address, family); + + netconfig_agent_append_dict_dict_array(builder, "Routes", + l_netconfig_get_routes(netconfig->nc, + NULL, NULL, NULL, NULL), + netconfig_agent_append_route, family); + + dns_list = l_netconfig_get_dns_list(netconfig->nc); + netconfig_agent_append_dict_strv(builder, "DomainNameServers", + dns_list, family); + + domains = l_netconfig_get_domain_names(netconfig->nc); + netconfig_agent_append_dict_strv(builder, "DomainNames", + domains, AF_UNSPEC); + + l_dbus_message_builder_leave_array(builder); + l_dbus_message_builder_finalize(builder); + l_dbus_message_builder_destroy(builder); + + cd = l_new(struct netconfig_agent_call_data, 1); + cd->netconfig = netconfig; + cd->family = family; + cd->event = event; + data = netconfig->commit_data; + data->pending_id[INDEX_FOR_AF(family)] = + l_dbus_send_with_reply(dbus, message, + netconfig_agent_receive_reply, + cd, l_free); +} + +static void netconfig_agent_free_data(struct netconfig *netconfig, + const char *reasonstr) +{ + if (!netconfig->commit_data) + return; + + netconfig_agent_cancel(netconfig, AF_INET, reasonstr); + netconfig_agent_cancel(netconfig, AF_INET6, reasonstr); + l_free(l_steal_ptr(netconfig->commit_data)); +} + +static struct netconfig_commit_ops netconfig_agent_ops = { + .commit = netconfig_agent_commit, + .free_data = netconfig_agent_free_data, +}; + +static void netconfig_agent_disconnect_handle(void *user_data) +{ + netconfig_unregister_agent(netconfig_agent_name, netconfig_agent_path); +} + +static void netconfig_agent_disconnect_cb(struct l_dbus *dbus, void *user_data) +{ + l_debug(""); + l_idle_oneshot(netconfig_agent_disconnect_handle, NULL, NULL); +} + +int netconfig_register_agent(const char *name, const char *path) +{ + if (netconfig_agent_path) + return -EEXIST; + + netconfig_agent_name = l_strdup(name); + netconfig_agent_path = l_strdup(path); + netconfig_agent_watch = l_dbus_add_disconnect_watch(dbus_get_bus(), + name, + netconfig_agent_disconnect_cb, + NULL, NULL); + + netconfig_switch_backend(&netconfig_agent_ops); + + return 0; +} + +int netconfig_unregister_agent(const char *name, const char *path) +{ + if (!netconfig_agent_path || strcmp(netconfig_agent_path, path)) + return -ENOENT; + + if (strcmp(netconfig_agent_name, name)) + return -EPERM; + + l_free(l_steal_ptr(netconfig_agent_name)); + l_free(l_steal_ptr(netconfig_agent_path)); + l_dbus_remove_watch(dbus_get_bus(), netconfig_agent_watch); + + netconfig_switch_backend(&netconfig_rtnl_ops); + return 0; +} diff --git a/src/netconfig.c b/src/netconfig.c @@ -27,9 +27,7 @@ #include <errno.h> #include <arpa/inet.h> #include <net/if_arp.h> -#include <netinet/if_ether.h> #include <netinet/in.h> -#include <linux/rtnetlink.h> #include <limits.h> #include <string.h> #include <fcntl.h> @@ -52,49 +50,13 @@ #include "src/netconfig.h" #include "src/sysfs.h" -struct netconfig { - uint32_t ifindex; - struct l_dhcp_client *dhcp_client; - struct l_dhcp6_client *dhcp6_client; - uint8_t rtm_protocol; - uint8_t rtm_v6_protocol; - struct l_rtnl_address *v4_address; - struct l_rtnl_address *v6_address; - char **dns4_overrides; - char **dns6_overrides; - char **dns4_list; - char **dns6_list; - char *mdns; - struct ie_fils_ip_addr_response_info *fils_override; - char *v4_gateway_str; - char *v6_gateway_str; - char *v4_domain; - char **v6_domains; - - const struct l_settings *active_settings; - - netconfig_notify_func_t notify; - void *user_data; - - struct resolve *resolve; - - struct l_acd *acd; - - uint32_t addr4_add_cmd_id; - uint32_t addr6_add_cmd_id; - uint32_t route4_add_gateway_cmd_id; - uint32_t route6_add_cmd_id; -}; - -static struct l_netlink *rtnl; -static struct l_queue *netconfig_list; - /* * Routing priority offset, configurable in main.conf. The route with lower * priority offset is preferred. */ static uint32_t ROUTE_PRIORITY_OFFSET; static bool ipv6_enabled; +static char *mdns_global; static void do_debug(const char *str, void *user_data) { @@ -105,81 +67,56 @@ static void do_debug(const char *str, void *user_data) static void netconfig_free_settings(struct netconfig *netconfig) { - l_rtnl_address_free(netconfig->v4_address); - netconfig->v4_address = NULL; - l_rtnl_address_free(netconfig->v6_address); - netconfig->v6_address = NULL; - - l_strfreev(netconfig->dns4_overrides); - netconfig->dns4_overrides = NULL; - l_strfreev(netconfig->dns6_overrides); - netconfig->dns6_overrides = NULL; + netconfig->enabled[0] = true; + netconfig->enabled[1] = false; + netconfig->static_config[0] = false; + netconfig->static_config[1] = false; + netconfig->gateway_overridden[0] = false; + netconfig->gateway_overridden[1] = false; + netconfig->dns_overridden[0] = false; + netconfig->dns_overridden[1] = false; + l_netconfig_reset_config(netconfig->nc); l_free(netconfig->mdns); netconfig->mdns = NULL; + + l_free(l_steal_ptr(netconfig->fils_override)); } static void netconfig_free(void *data) { struct netconfig *netconfig = data; - l_dhcp_client_destroy(netconfig->dhcp_client); - l_dhcp6_client_destroy(netconfig->dhcp6_client); - + l_netconfig_destroy(netconfig->nc); l_free(netconfig); } -static struct netconfig *netconfig_find(uint32_t ifindex) +static bool netconfig_addr_to_str(uint8_t af, const void *v4_addr, + const void *v6_addr, char *out_str, + bool *out_is_zero) { - const struct l_queue_entry *entry; - - for (entry = l_queue_get_entries(netconfig_list); entry; - entry = entry->next) { - struct netconfig *netconfig = entry->data; + const void *addr = (af == AF_INET ? v4_addr : v6_addr); + uint8_t bytes = (af == AF_INET ? 4 : 16); - if (netconfig->ifindex != ifindex) - continue; - - return netconfig; + if (l_memeqzero(addr, bytes)) { + *out_is_zero = true; + return true; } - return NULL; -} - -static inline char *netconfig_ipv4_to_string(uint32_t addr) -{ - struct in_addr in_addr = { .s_addr = addr }; - char *addr_str = l_malloc(INET_ADDRSTRLEN); + *out_is_zero = false; - if (L_WARN_ON(unlikely(!inet_ntop(AF_INET, &in_addr, addr_str, - INET_ADDRSTRLEN)))) { - l_free(addr_str); - return NULL; - } + if (L_WARN_ON(!inet_ntop(af, addr, out_str, INET6_ADDRSTRLEN))) + return false; - return addr_str; + return true; } -static inline char *netconfig_ipv6_to_string(const uint8_t *addr) +bool netconfig_use_fils_addr(struct netconfig *netconfig, int af) { - struct in6_addr in6_addr; - char *addr_str = l_malloc(INET6_ADDRSTRLEN); - - memcpy(in6_addr.s6_addr, addr, 16); - - if (L_WARN_ON(unlikely(!inet_ntop(AF_INET6, &in6_addr, addr_str, - INET6_ADDRSTRLEN)))) { - l_free(addr_str); - return NULL; - } - - return addr_str; -} + if (!netconfig->enabled[INDEX_FOR_AF(af)]) + return false; -static bool netconfig_use_fils_addr(struct netconfig *netconfig, int af) -{ - if ((af == AF_INET ? netconfig->rtm_protocol : - netconfig->rtm_v6_protocol) != RTPROT_DHCP) + if (netconfig->static_config[INDEX_FOR_AF(af)]) return false; if (!netconfig->fils_override) @@ -191,241 +128,10 @@ static bool netconfig_use_fils_addr(struct netconfig *netconfig, int af) return !l_memeqzero(netconfig->fils_override->ipv6_addr, 16); } -static bool netconfig_use_fils_gateway(struct netconfig *netconfig, int af) -{ - if ((af == AF_INET ? netconfig->rtm_protocol : - netconfig->rtm_v6_protocol) != RTPROT_DHCP) - return false; - - if (!netconfig->fils_override) - return false; - - if (af == AF_INET) - return !!netconfig->fils_override->ipv4_gateway; - - return !l_memeqzero(netconfig->fils_override->ipv6_gateway, 16); -} - -static char **netconfig_get_dns_list(struct netconfig *netconfig, int af, - const uint8_t **out_dns_mac) -{ - const struct ie_fils_ip_addr_response_info *fils = - netconfig->fils_override; - - if (af == AF_INET) { - const struct l_dhcp_lease *lease; - - if (netconfig->dns4_overrides) - return l_strv_copy(netconfig->dns4_overrides); - - if (netconfig->rtm_protocol != RTPROT_DHCP) - return NULL; - - if (fils && fils->ipv4_dns) { - char **dns_list = l_new(char *, 2); - - if (!l_memeqzero(fils->ipv4_dns_mac, 6) && - out_dns_mac && - util_ip_subnet_match( - fils->ipv4_prefix_len, - &fils->ipv4_addr, - &fils->ipv4_dns)) - *out_dns_mac = fils->ipv4_dns_mac; - - dns_list[0] = netconfig_ipv4_to_string(fils->ipv4_dns); - return dns_list; - } - - lease = l_dhcp_client_get_lease(netconfig->dhcp_client); - if (!lease) - return NULL; - - return l_dhcp_lease_get_dns(lease); - } else { - const struct l_dhcp6_lease *lease; - - if (netconfig->dns6_overrides) - return l_strv_copy(netconfig->dns6_overrides); - - if (netconfig->rtm_v6_protocol != RTPROT_DHCP) - return NULL; - - if (fils && !l_memeqzero(fils->ipv6_dns, 16)) { - char **dns_list = l_new(char *, 2); - - if (!l_memeqzero(fils->ipv6_dns_mac, 6) && - out_dns_mac && - util_ip_subnet_match( - fils->ipv6_prefix_len, - fils->ipv6_addr, - fils->ipv6_dns)) - *out_dns_mac = fils->ipv6_dns_mac; - - dns_list[0] = netconfig_ipv6_to_string(fils->ipv6_dns); - return dns_list; - } - - lease = l_dhcp6_client_get_lease(netconfig->dhcp6_client); - if (!lease) - return NULL; - - return l_dhcp6_lease_get_dns(lease); - } -} - -static void netconfig_set_neighbor_entry_cb(int error, - uint16_t type, const void *data, - uint32_t len, void *user_data) -{ - if (error) - l_error("l_rtnl_neighbor_set_hwaddr failed: %s (%i)", - strerror(-error), error); -} - -static void netconfig_set_dns(struct netconfig *netconfig) -{ - if (!netconfig->dns4_list && !netconfig->dns6_list) - return; - - if (netconfig->dns4_list && netconfig->dns6_list) { - unsigned int n_entries4 = l_strv_length(netconfig->dns4_list); - unsigned int n_entries6 = l_strv_length(netconfig->dns6_list); - char **dns_list = l_malloc(sizeof(char *) * - (n_entries4 + n_entries6 + 1)); - - memcpy(dns_list, netconfig->dns4_list, - sizeof(char *) * n_entries4); - memcpy(dns_list + n_entries4, netconfig->dns6_list, - sizeof(char *) * (n_entries6 + 1)); - resolve_set_dns(netconfig->resolve, dns_list); - l_free(dns_list); - return; - } - - resolve_set_dns(netconfig->resolve, - netconfig->dns4_list ?: netconfig->dns6_list); -} - -static bool netconfig_dns_list_update(struct netconfig *netconfig, uint8_t af) -{ - const uint8_t *fils_dns_mac = NULL; - char ***dns_list_ptr = af == AF_INET ? - &netconfig->dns4_list : &netconfig->dns6_list; - char **new_dns_list = netconfig_get_dns_list(netconfig, af, - &fils_dns_mac); - - if (l_strv_eq(*dns_list_ptr, new_dns_list)) { - l_strv_free(new_dns_list); - return false; - } - - l_strv_free(*dns_list_ptr); - *dns_list_ptr = new_dns_list; - - if (fils_dns_mac) { - const struct ie_fils_ip_addr_response_info *fils = - netconfig->fils_override; - const void *dns_ip = af == AF_INET ? - (const void *) &fils->ipv4_dns : - (const void *) &fils->ipv6_dns; - - if (!l_rtnl_neighbor_set_hwaddr(rtnl, netconfig->ifindex, af, - dns_ip, fils_dns_mac, 6, - netconfig_set_neighbor_entry_cb, - NULL, NULL)) - l_debug("l_rtnl_neighbor_set_hwaddr failed"); - } - - return true; -} - -static void append_domain(char **domains, unsigned int *n_domains, - size_t max, char *domain) -{ - unsigned int i; - - if (*n_domains == max) - return; - - for (i = 0; i < *n_domains; i++) - if (!strcmp(domains[i], domain)) - return; - - domains[*n_domains] = domain; - *n_domains += 1; -} - -static void netconfig_set_domains(struct netconfig *netconfig) -{ - char *domains[31]; - unsigned int n_domains = 0; - char **p; - - memset(domains, 0, sizeof(domains)); - - append_domain(domains, &n_domains, - L_ARRAY_SIZE(domains) - 1, netconfig->v4_domain); - - for (p = netconfig->v6_domains; p && *p; p++) - append_domain(domains, &n_domains, - L_ARRAY_SIZE(domains) - 1, *p); - - resolve_set_domains(netconfig->resolve, domains); -} - -static bool netconfig_domains_update(struct netconfig *netconfig, uint8_t af) -{ - bool changed = false; - - if (af == AF_INET) { - /* Allow to override the DHCP domain name with setting entry. */ - char *v4_domain = l_settings_get_string( - netconfig->active_settings, - "IPv4", "DomainName"); - - if (!v4_domain && netconfig->rtm_protocol == RTPROT_DHCP) { - const struct l_dhcp_lease *lease = - l_dhcp_client_get_lease(netconfig->dhcp_client); - - if (lease) - v4_domain = l_dhcp_lease_get_domain_name(lease); - } - - if (l_streq0(v4_domain, netconfig->v4_domain)) - l_free(v4_domain); - else { - l_free(netconfig->v4_domain); - netconfig->v4_domain = v4_domain; - changed = true; - } - } else { - char **v6_domains = NULL; - - if (netconfig->rtm_v6_protocol == RTPROT_DHCP) { - const struct l_dhcp6_lease *lease = - l_dhcp6_client_get_lease( - netconfig->dhcp6_client); - - if (lease) - v6_domains = l_dhcp6_lease_get_domains(lease); - } - - if (l_strv_eq(netconfig->v6_domains, v6_domains)) - l_strv_free(v6_domains); - else { - l_strv_free(netconfig->v6_domains); - netconfig->v6_domains = v6_domains; - changed = true; - } - } - - return changed; -} - static struct l_rtnl_address *netconfig_get_static4_address( const struct l_settings *active_settings) { - struct l_rtnl_address *ifaddr = NULL; + _auto_(l_rtnl_address_free) struct l_rtnl_address *ifaddr = NULL; L_AUTO_FREE_VAR(char *, ip) = NULL; L_AUTO_FREE_VAR(char *, netmask) = NULL; struct in_addr in_addr; @@ -433,13 +139,22 @@ static struct l_rtnl_address *netconfig_get_static4_address( uint32_t prefix_len; ip = l_settings_get_string(active_settings, "IPv4", "Address"); - if (!ip) + if (unlikely(!ip)) { + l_error("netconfig: Can't load IPv4.Address"); return NULL; + } + + if (l_settings_has_key(active_settings, "IPv4", "Netmask") && + !(netmask = l_settings_get_string(active_settings, + "IPv4", + "Netmask"))) { + l_error("netconfig: Can't load IPv4.Netmask"); + return NULL; + } - netmask = l_settings_get_string(active_settings, "IPv4", "Netmask"); if (netmask) { if (inet_pton(AF_INET, netmask, &in_addr) != 1) { - l_error("netconfig: Can't parse IPv4 Netmask"); + l_error("netconfig: Can't parse IPv4.Netmask"); return NULL; } @@ -447,14 +162,14 @@ static struct l_rtnl_address *netconfig_get_static4_address( if (ntohl(in_addr.s_addr) != util_netmask_from_prefix(prefix_len)) { - l_error("netconfig: Invalid IPv4 Netmask"); + l_error("netconfig: Invalid IPv4.Netmask"); return NULL; } } else prefix_len = 24; ifaddr = l_rtnl_address_new(ip, prefix_len); - if (!ifaddr) { + if (!ifaddr || l_rtnl_address_get_family(ifaddr) != AF_INET) { l_error("netconfig: Unable to parse IPv4.Address"); return NULL; } @@ -462,52 +177,10 @@ static struct l_rtnl_address *netconfig_get_static4_address( broadcast = l_settings_get_string(active_settings, "IPv4", "Broadcast"); if (broadcast && !l_rtnl_address_set_broadcast(ifaddr, broadcast)) { l_error("netconfig: Unable to parse IPv4.Broadcast"); - l_rtnl_address_free(ifaddr); return NULL; } - l_rtnl_address_set_noprefixroute(ifaddr, true); - return ifaddr; -} - -static char *netconfig_ipv4_get_gateway(struct netconfig *netconfig, - const uint8_t **out_mac) -{ - const struct l_dhcp_lease *lease; - char *gateway; - const struct ie_fils_ip_addr_response_info *fils = - netconfig->fils_override; - - switch (netconfig->rtm_protocol) { - case RTPROT_STATIC: - gateway = l_settings_get_string(netconfig->active_settings, - "IPv4", "Gateway"); - if (!gateway) - gateway = l_settings_get_string( - netconfig->active_settings, - "IPv4", "gateway"); - - return gateway; - - case RTPROT_DHCP: - if (netconfig_use_fils_gateway(netconfig, AF_INET)) { - gateway = netconfig_ipv4_to_string(fils->ipv4_gateway); - - if (gateway && out_mac && - !l_memeqzero(fils->ipv4_gateway_mac, 6)) - *out_mac = fils->ipv4_gateway_mac; - - return gateway; - } - - lease = l_dhcp_client_get_lease(netconfig->dhcp_client); - if (!lease) - return NULL; - - return l_dhcp_lease_get_gateway(lease); - } - - return NULL; + return l_steal_ptr(ifaddr); } static struct l_rtnl_address *netconfig_get_static6_address( @@ -516,12 +189,14 @@ static struct l_rtnl_address *netconfig_get_static6_address( L_AUTO_FREE_VAR(char *, ip); char *p; char *endp; - struct l_rtnl_address *ret; - uint32_t prefix_len = 128; + _auto_(l_rtnl_address_free) struct l_rtnl_address *ret = NULL; + uint32_t prefix_len = 64; ip = l_settings_get_string(active_settings, "IPv6", "Address"); - if (!ip) + if (unlikely(!ip)) { + l_error("netconfig: Can't load IPv6.Address"); return NULL; + } p = strrchr(ip, '/'); if (!p) @@ -542,967 +217,340 @@ static struct l_rtnl_address *netconfig_get_static6_address( no_prefix_len: ret = l_rtnl_address_new(ip, prefix_len); - if (!ret) - l_error("netconfig: Invalid IPv6 address %s is " - "provided in network configuration file.", ip); - - return ret; -} - -static struct l_rtnl_route *netconfig_get_static6_gateway( - struct netconfig *netconfig, - char **out_str, - const uint8_t **out_mac) -{ - L_AUTO_FREE_VAR(char *, gateway); - struct l_rtnl_route *ret; - const uint8_t *mac = NULL; - - gateway = l_settings_get_string(netconfig->active_settings, - "IPv6", "Gateway"); - if (!gateway && netconfig_use_fils_gateway(netconfig, AF_INET6)) { - gateway = netconfig_ipv6_to_string( - netconfig->fils_override->ipv6_gateway); - - if (!l_memeqzero(netconfig->fils_override->ipv6_gateway_mac, 6)) - mac = netconfig->fils_override->ipv6_gateway_mac; - } else if (!gateway) - return NULL; - - ret = l_rtnl_route_new_gateway(gateway); - if (!ret) { - l_error("netconfig: Invalid IPv6 gateway address %s is " - "provided in network configuration file.", - gateway); - return ret; - } - - l_rtnl_route_set_priority(ret, ROUTE_PRIORITY_OFFSET); - l_rtnl_route_set_protocol(ret, RTPROT_STATIC); - *out_str = l_steal_ptr(gateway); - *out_mac = mac; - - return ret; -} - -static struct l_rtnl_address *netconfig_get_dhcp4_address( - struct netconfig *netconfig) -{ - const struct l_dhcp_lease *lease = - l_dhcp_client_get_lease(netconfig->dhcp_client); - L_AUTO_FREE_VAR(char *, ip) = NULL; - L_AUTO_FREE_VAR(char *, broadcast) = NULL; - uint32_t prefix_len; - struct l_rtnl_address *ret; - - if (L_WARN_ON(!lease)) + if (!ret || l_rtnl_address_get_family(ret) != AF_INET6) { + l_error("netconfig: Invalid IPv6 address %s provided in " + "network configuration file.", ip); return NULL; - - ip = l_dhcp_lease_get_address(lease); - broadcast = l_dhcp_lease_get_broadcast(lease); - - prefix_len = l_dhcp_lease_get_prefix_length(lease); - if (!prefix_len) - prefix_len = 24; - - ret = l_rtnl_address_new(ip, prefix_len); - if (!ret) - return ret; - - if (broadcast) - l_rtnl_address_set_broadcast(ret, broadcast); - - l_rtnl_address_set_noprefixroute(ret, true); - return ret; -} - -static void netconfig_gateway_to_arp(struct netconfig *netconfig) -{ - const struct l_dhcp_lease *lease; - _auto_(l_free) char *server_id = NULL; - _auto_(l_free) char *gw = NULL; - const uint8_t *server_mac; - struct in_addr in_gw; - - /* Can only do this for DHCP in certain network setups */ - if (netconfig->rtm_protocol != RTPROT_DHCP) - return; - - lease = l_dhcp_client_get_lease(netconfig->dhcp_client); - if (!lease) - return; - - server_id = l_dhcp_lease_get_server_id(lease); - gw = l_dhcp_lease_get_gateway(lease); - server_mac = l_dhcp_lease_get_server_mac(lease); - - if (!gw || strcmp(server_id, gw) || !server_mac) - return; - - l_debug("Gateway MAC is known, setting into ARP cache"); - in_gw.s_addr = l_dhcp_lease_get_gateway_u32(lease); - - if (!l_rtnl_neighbor_set_hwaddr(rtnl, netconfig->ifindex, AF_INET, - &in_gw, server_mac, ETH_ALEN, - netconfig_set_neighbor_entry_cb, NULL, - NULL)) - l_debug("l_rtnl_neighbor_set_hwaddr failed"); -} - -static void netconfig_ifaddr_added(struct netconfig *netconfig, - const struct ifaddrmsg *ifa, - uint32_t len) -{ - L_AUTO_FREE_VAR(char *, label) = NULL; - L_AUTO_FREE_VAR(char *, ip) = NULL; - L_AUTO_FREE_VAR(char *, broadcast) = NULL; - - l_rtnl_ifaddr4_extract(ifa, len, &label, &ip, &broadcast); - l_debug("%s: ifaddr %s/%u broadcast %s", label, - ip, ifa->ifa_prefixlen, broadcast); -} - -static void netconfig_ifaddr_deleted(struct netconfig *netconfig, - const struct ifaddrmsg *ifa, - uint32_t len) -{ - L_AUTO_FREE_VAR(char *, ip); - - l_rtnl_ifaddr4_extract(ifa, len, NULL, &ip, NULL); - l_debug("ifaddr %s/%u", ip, ifa->ifa_prefixlen); -} - -static void netconfig_ifaddr_notify(uint16_t type, const void *data, - uint32_t len, void *user_data) -{ - const struct ifaddrmsg *ifa = data; - struct netconfig *netconfig; - uint32_t bytes; - - netconfig = netconfig_find(ifa->ifa_index); - if (!netconfig) - /* Ignore the interfaces which aren't managed by iwd. */ - return; - - bytes = len - NLMSG_ALIGN(sizeof(struct ifaddrmsg)); - - switch (type) { - case RTM_NEWADDR: - netconfig_ifaddr_added(netconfig, ifa, bytes); - break; - case RTM_DELADDR: - netconfig_ifaddr_deleted(netconfig, ifa, bytes); - break; - } -} - -static void netconfig_ifaddr_cmd_cb(int error, uint16_t type, - const void *data, uint32_t len, - void *user_data) -{ - if (error) { - l_error("netconfig: ifaddr command failure. " - "Error %d: %s", error, strerror(-error)); - return; - } - - if (type != RTM_NEWADDR) - return; - - netconfig_ifaddr_notify(type, data, len, user_data); -} - -static void netconfig_ifaddr_ipv6_added(struct netconfig *netconfig, - const struct ifaddrmsg *ifa, - uint32_t len) -{ - struct in6_addr in6; - L_AUTO_FREE_VAR(char *, ip) = NULL; - - if (ifa->ifa_flags & IFA_F_TENTATIVE) - return; - - l_rtnl_ifaddr6_extract(ifa, len, &ip); - - l_debug("ifindex %u: ifaddr %s/%u", netconfig->ifindex, - ip, ifa->ifa_prefixlen); - - if (netconfig->rtm_v6_protocol != RTPROT_DHCP || - netconfig_use_fils_addr(netconfig, AF_INET6)) - return; - - inet_pton(AF_INET6, ip, &in6); - if (!IN6_IS_ADDR_LINKLOCAL(&in6)) - return; - - l_dhcp6_client_set_link_local_address(netconfig->dhcp6_client, ip); - - if (l_dhcp6_client_start(netconfig->dhcp6_client)) - return; - - l_error("netconfig: Failed to start DHCPv6 client for " - "interface %u", netconfig->ifindex); -} - -static void netconfig_ifaddr_ipv6_deleted(struct netconfig *netconfig, - const struct ifaddrmsg *ifa, - uint32_t len) -{ - L_AUTO_FREE_VAR(char *, ip); - - l_rtnl_ifaddr6_extract(ifa, len, &ip); - l_debug("ifindex %u: ifaddr %s/%u", netconfig->ifindex, - ip, ifa->ifa_prefixlen); -} - -static void netconfig_ifaddr_ipv6_notify(uint16_t type, const void *data, - uint32_t len, void *user_data) -{ - const struct ifaddrmsg *ifa = data; - struct netconfig *netconfig; - uint32_t bytes; - - netconfig = netconfig_find(ifa->ifa_index); - if (!netconfig) - /* Ignore the interfaces which aren't managed by iwd. */ - return; - - bytes = len - NLMSG_ALIGN(sizeof(struct ifaddrmsg)); - - switch (type) { - case RTM_NEWADDR: - netconfig_ifaddr_ipv6_added(netconfig, ifa, bytes); - break; - case RTM_DELADDR: - netconfig_ifaddr_ipv6_deleted(netconfig, ifa, bytes); - break; } -} - -static void netconfig_ifaddr_ipv6_cmd_cb(int error, uint16_t type, - const void *data, uint32_t len, - void *user_data) -{ - if (error) { - l_error("netconfig: ifaddr IPv6 command failure. " - "Error %d: %s", error, strerror(-error)); - return; - } - - if (type != RTM_NEWADDR) - return; - - netconfig_ifaddr_ipv6_notify(type, data, len, user_data); -} -static void netconfig_route_generic_cb(int error, uint16_t type, - const void *data, uint32_t len, - void *user_data) -{ - if (error) { - l_error("netconfig: Failed to add route. Error %d: %s", - error, strerror(-error)); - return; - } + return l_steal_ptr(ret); } -static void netconfig_route_add_cmd_cb(int error, uint16_t type, - const void *data, uint32_t len, - void *user_data) +static bool netconfig_load_dns(struct netconfig *netconfig, + const struct l_settings *active_settings, + const char *group_name, uint8_t family) { - struct netconfig *netconfig = user_data; - - netconfig->route4_add_gateway_cmd_id = 0; - - if (error) { - l_error("netconfig: Failed to add route. Error %d: %s", - error, strerror(-error)); - return; - } - - if (!netconfig->notify) - return; - - netconfig->notify(NETCONFIG_EVENT_CONNECTED, netconfig->user_data); - netconfig->notify = NULL; -} - -static void netconfig_route6_add_cb(int error, uint16_t type, - const void *data, uint32_t len, - void *user_data) -{ - struct netconfig *netconfig = user_data; - - netconfig->route6_add_cmd_id = 0; - - if (error) { - l_error("netconfig: Failed to add route. Error %d: %s", - error, strerror(-error)); - return; - } -} + _auto_(l_strv_free) char **dns_str_list = NULL; -static bool netconfig_ipv4_subnet_route_install(struct netconfig *netconfig) -{ - struct in_addr in_addr; - char ip[INET_ADDRSTRLEN]; - char network[INET_ADDRSTRLEN]; - unsigned int prefix_len = - l_rtnl_address_get_prefix_length(netconfig->v4_address); - - if (!l_rtnl_address_get_address(netconfig->v4_address, ip) || - inet_pton(AF_INET, ip, &in_addr) < 1) - return false; - - in_addr.s_addr = in_addr.s_addr & - htonl(0xFFFFFFFFLU << (32 - prefix_len)); + if (!l_settings_has_key(active_settings, group_name, "DNS")) + return true; - if (!inet_ntop(AF_INET, &in_addr, network, INET_ADDRSTRLEN)) + dns_str_list = l_settings_get_string_list(active_settings, + group_name, "DNS", ' '); + if (unlikely(!dns_str_list)) { + l_error("netconfig: Can't load [%s].DNS", group_name); return false; + } - if (!l_rtnl_route4_add_connected(rtnl, netconfig->ifindex, - prefix_len, network, ip, - netconfig->rtm_protocol, - netconfig_route_generic_cb, - netconfig, NULL)) { - l_error("netconfig: Failed to add subnet route."); + if (unlikely(!l_netconfig_set_dns_override(netconfig->nc, family, + dns_str_list))) { + l_error("netconfig: l_netconfig_set_dns_override(%s) failed", + family == AF_INET ? "AF_INET" : "AF_INET6"); return false; } + netconfig->dns_overridden[INDEX_FOR_AF(family)] = true; return true; } -static bool netconfig_ipv4_gateway_route_install(struct netconfig *netconfig) +static bool netconfig_load_gateway(struct netconfig *netconfig, + const struct l_settings *active_settings, + const char *group_name, uint8_t family) { - L_AUTO_FREE_VAR(char *, gateway) = NULL; - const uint8_t *gateway_mac = NULL; - struct in_addr in_addr; - char ip[INET_ADDRSTRLEN]; - - gateway = netconfig_ipv4_get_gateway(netconfig, &gateway_mac); - if (!gateway) { - l_debug("No gateway obtained from %s.", - netconfig->rtm_protocol == RTPROT_STATIC ? - "setting file" : "DHCPv4 lease"); - - if (netconfig->notify) { - netconfig->notify(NETCONFIG_EVENT_CONNECTED, - netconfig->user_data); - netconfig->notify = NULL; - } + _auto_(l_free) char *gateway_str = NULL; + if (!l_settings_has_key(active_settings, group_name, "Gateway")) return true; - } - if (!l_rtnl_address_get_address(netconfig->v4_address, ip) || - inet_pton(AF_INET, ip, &in_addr) < 1) + gateway_str = l_settings_get_string(active_settings, group_name, + "Gateway"); + if (unlikely(!gateway_str)) { + l_error("netconfig: Can't load [%s].Gateway", group_name); return false; + } - netconfig->route4_add_gateway_cmd_id = - l_rtnl_route4_add_gateway(rtnl, netconfig->ifindex, gateway, ip, - ROUTE_PRIORITY_OFFSET, - netconfig->rtm_protocol, - netconfig_route_add_cmd_cb, - netconfig, NULL); - if (!netconfig->route4_add_gateway_cmd_id) { - l_error("netconfig: Failed to add route for: %s gateway.", - gateway); - + if (unlikely(!l_netconfig_set_gateway_override(netconfig->nc, family, + gateway_str))) { + l_error("netconfig: l_netconfig_set_gateway_override(%s) " + "failed", family == AF_INET ? "AF_INET" : "AF_INET6"); return false; } - /* - * Attempt to use the gateway MAC address received from the AP by - * writing the mapping directly into the netdev's ARP table so as - * to save one data frame roundtrip before first IP connections - * are established. This is very low-priority but print error - * messages just because they may indicate bigger problems. - */ - if (gateway_mac && !l_rtnl_neighbor_set_hwaddr(rtnl, netconfig->ifindex, - AF_INET, - &netconfig->fils_override->ipv4_gateway, - gateway_mac, 6, - netconfig_set_neighbor_entry_cb, NULL, - NULL)) - l_debug("l_rtnl_neighbor_set_hwaddr failed"); - + netconfig->gateway_overridden[INDEX_FOR_AF(family)] = true; return true; } -static void netconfig_ipv4_ifaddr_add_cmd_cb(int error, uint16_t type, - const void *data, uint32_t len, - void *user_data) -{ - struct netconfig *netconfig = user_data; - - netconfig->addr4_add_cmd_id = 0; - - if (error && error != -EEXIST) { - l_error("netconfig: Failed to add IP address. " - "Error %d: %s", error, strerror(-error)); - return; - } - - netconfig_gateway_to_arp(netconfig); - - if (!netconfig_ipv4_subnet_route_install(netconfig) || - !netconfig_ipv4_gateway_route_install(netconfig)) - return; - - netconfig_set_dns(netconfig); - netconfig_set_domains(netconfig); -} - -static void netconfig_ipv6_ifaddr_add_cmd_cb(int error, uint16_t type, - const void *data, uint32_t len, - void *user_data) -{ - struct netconfig *netconfig = user_data; - struct l_rtnl_route *gateway; - const uint8_t *gateway_mac; - - netconfig->addr6_add_cmd_id = 0; - - if (error && error != -EEXIST) { - l_error("netconfig: Failed to add IPv6 address. " - "Error %d: %s", error, strerror(-error)); - return; - } - - gateway = netconfig_get_static6_gateway(netconfig, - &netconfig->v6_gateway_str, - &gateway_mac); - if (gateway) { - netconfig->route6_add_cmd_id = l_rtnl_route_add(rtnl, - netconfig->ifindex, - gateway, - netconfig_route6_add_cb, - netconfig, NULL); - L_WARN_ON(unlikely(!netconfig->route6_add_cmd_id)); - l_rtnl_route_free(gateway); - - if (gateway_mac && !l_rtnl_neighbor_set_hwaddr(rtnl, - netconfig->ifindex, AF_INET6, - netconfig->fils_override->ipv6_gateway, - gateway_mac, 6, - netconfig_set_neighbor_entry_cb, NULL, - NULL)) - l_debug("l_rtnl_neighbor_set_hwaddr failed"); - } - - netconfig_set_dns(netconfig); - netconfig_set_domains(netconfig); -} - -static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, - const void *data, uint32_t len, - void *user_data) +bool netconfig_load_settings(struct netconfig *netconfig, + const struct l_settings *active_settings) { - if (error == -ENODEV) - /* The device is unplugged, we are done. */ - return; - - if (!error) - /* - * The kernel removes all of the routes associated with the - * deleted IP on its own. There is no need to explicitly remove - * them. - */ - return; + bool send_hostname = false; + char hostname[HOST_NAME_MAX + 1]; + _auto_(l_free) char *mdns = NULL; + bool success = true; + bool static_ipv4 = false; + bool static_ipv6 = false; + bool enable_ipv4 = true; + bool enable_ipv6 = ipv6_enabled; - l_error("netconfig: Failed to delete IP address. " - "Error %d: %s", error, strerror(-error)); -} + netconfig_free_settings(netconfig); -static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client, - enum l_dhcp_client_event event, - void *userdata) -{ - struct netconfig *netconfig = userdata; + /* + * Note we try to print errors and continue validating the + * configuration until we've gone through all the settings so + * as to make fixing the settings more efficient for the user. + */ - l_debug("DHCPv4 event %d", event); + if (l_settings_has_key(active_settings, "IPv4", "Address")) { + _auto_(l_rtnl_address_free) struct l_rtnl_address *addr = + netconfig_get_static4_address(active_settings); - switch (event) { - case L_DHCP_CLIENT_EVENT_IP_CHANGED: - L_WARN_ON(!l_rtnl_ifaddr_delete(rtnl, netconfig->ifindex, - netconfig->v4_address, - netconfig_ifaddr_del_cmd_cb, - netconfig, NULL)); - /* Fall through. */ - case L_DHCP_CLIENT_EVENT_LEASE_OBTAINED: - { - char *gateway_str; - struct l_rtnl_address *address; - - gateway_str = netconfig_ipv4_get_gateway(netconfig, NULL); - if (l_streq0(netconfig->v4_gateway_str, gateway_str)) - l_free(gateway_str); - else { - l_free(netconfig->v4_gateway_str); - netconfig->v4_gateway_str = gateway_str; + if (unlikely(!addr)) { + success = false; + goto ipv6_addr; } - address = netconfig_get_dhcp4_address(netconfig); - l_rtnl_address_free(netconfig->v4_address); - netconfig->v4_address = address; - - if (!netconfig->v4_address) { - l_error("netconfig: Failed to obtain IP addresses from " - "DHCPv4 lease."); - return; + if (!l_netconfig_set_static_addr(netconfig->nc, AF_INET, + addr)) { + l_error("netconfig: l_netconfig_set_static_addr(" + "AF_INET) failed"); + success = false; + goto ipv6_addr; } - netconfig_dns_list_update(netconfig, AF_INET); - netconfig_domains_update(netconfig, AF_INET); - - L_WARN_ON(!(netconfig->addr4_add_cmd_id = - l_rtnl_ifaddr_add(rtnl, netconfig->ifindex, - netconfig->v4_address, - netconfig_ipv4_ifaddr_add_cmd_cb, - netconfig, NULL))); - break; - } - case L_DHCP_CLIENT_EVENT_LEASE_RENEWED: - break; - case L_DHCP_CLIENT_EVENT_LEASE_EXPIRED: - L_WARN_ON(!l_rtnl_ifaddr_delete(rtnl, netconfig->ifindex, - netconfig->v4_address, - netconfig_ifaddr_del_cmd_cb, - netconfig, NULL)); - l_rtnl_address_free(netconfig->v4_address); - netconfig->v4_address = NULL; - l_free(l_steal_ptr(netconfig->v4_gateway_str)); - - /* Fall through. */ - case L_DHCP_CLIENT_EVENT_NO_LEASE: - /* - * The requested address is no longer available, try to restart - * the client. - */ - if (!l_dhcp_client_start(client)) - l_error("netconfig: Failed to re-start DHCPv4 client " - "for interface %u", netconfig->ifindex); - - break; - default: - l_error("netconfig: Received unsupported DHCPv4 event: %d", - event); + static_ipv4 = true; } -} -static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client, - enum l_dhcp6_client_event event, - void *userdata) -{ - struct netconfig *netconfig = userdata; +ipv6_addr: + if (l_settings_has_key(active_settings, "IPv6", "Address")) { + _auto_(l_rtnl_address_free) struct l_rtnl_address *addr = + netconfig_get_static6_address(active_settings); - switch (event) { - case L_DHCP6_CLIENT_EVENT_IP_CHANGED: - case L_DHCP6_CLIENT_EVENT_LEASE_OBTAINED: - case L_DHCP6_CLIENT_EVENT_LEASE_RENEWED: - { - const struct l_dhcp6_lease *lease = - l_dhcp6_client_get_lease(netconfig->dhcp6_client); - if (!lease) return; - _auto_(l_free) char *addr_str = - l_dhcp6_lease_get_address(lease); - struct l_rtnl_address *address; - struct l_icmp6_client *icmp6 = - l_dhcp6_client_get_icmp6(netconfig->dhcp6_client); - const struct l_icmp6_router *router = - l_icmp6_client_get_router(icmp6); - char *gateway_str = l_icmp6_router_get_address(router); - - if (l_streq0(netconfig->v6_gateway_str, gateway_str)) - l_free(gateway_str); - else { - l_free(netconfig->v6_gateway_str); - netconfig->v6_gateway_str = gateway_str; + if (unlikely(!addr)) { + success = false; + goto gateway; } - address = l_rtnl_address_new(addr_str, - l_dhcp6_lease_get_prefix_length(lease)); - l_rtnl_address_free(netconfig->v6_address); - netconfig->v6_address = address; + if (!l_netconfig_set_static_addr(netconfig->nc, AF_INET6, + addr)) { + l_error("netconfig: l_netconfig_set_static_addr(" + "AF_INET6) failed"); + success = false; + goto gateway; + } - netconfig_dns_list_update(netconfig, AF_INET6); - netconfig_domains_update(netconfig, AF_INET6); - netconfig_set_dns(netconfig); - netconfig_set_domains(netconfig); - break; - } - case L_DHCP6_CLIENT_EVENT_LEASE_EXPIRED: - l_debug("Lease for interface %u expired", netconfig->ifindex); - netconfig_dns_list_update(netconfig, AF_INET6); - netconfig_domains_update(netconfig, AF_INET6); - netconfig_set_dns(netconfig); - netconfig_set_domains(netconfig); - l_rtnl_address_free(netconfig->v6_address); - netconfig->v6_address = NULL; - l_free(l_steal_ptr(netconfig->v6_gateway_str)); - - /* Fall through */ - case L_DHCP6_CLIENT_EVENT_NO_LEASE: - if (!l_dhcp6_client_start(netconfig->dhcp6_client)) - l_error("netconfig: Failed to re-start DHCPv6 client " - "for interface %u", netconfig->ifindex); - break; + static_ipv6 = true; } -} - -static void netconfig_remove_v4_address(struct netconfig *netconfig) -{ - if (!netconfig->v4_address) - return; - L_WARN_ON(!l_rtnl_ifaddr_delete(rtnl, netconfig->ifindex, - netconfig->v4_address, - netconfig_ifaddr_del_cmd_cb, - netconfig, NULL)); - l_rtnl_address_free(netconfig->v4_address); - netconfig->v4_address = NULL; -} - -static void netconfig_reset_v4(struct netconfig *netconfig) -{ - if (netconfig->rtm_protocol) { - netconfig_remove_v4_address(netconfig); - - l_strv_free(l_steal_ptr(netconfig->dns4_overrides)); - l_strv_free(l_steal_ptr(netconfig->dns4_list)); +gateway: + if (!netconfig_load_gateway(netconfig, active_settings, + "IPv4", AF_INET)) + success = false; - l_dhcp_client_stop(netconfig->dhcp_client); - netconfig->rtm_protocol = 0; + if (!netconfig_load_gateway(netconfig, active_settings, + "IPv6", AF_INET6)) + success = false; - l_acd_destroy(netconfig->acd); - netconfig->acd = NULL; + if (!netconfig_load_dns(netconfig, active_settings, "IPv4", AF_INET)) + success = false; - l_free(l_steal_ptr(netconfig->v4_gateway_str)); + if (!netconfig_load_dns(netconfig, active_settings, "IPv6", AF_INET6)) + success = false; - l_free(l_steal_ptr(netconfig->v4_domain)); + if (l_settings_has_key(active_settings, "IPv6", "Enabled") && + !l_settings_get_bool(active_settings, "IPv6", "Enabled", + &enable_ipv6)) { + l_error("netconfig: Can't load IPv6.Enabled"); + success = false; + goto send_hostname; } -} - -static void netconfig_ipv4_acd_event(enum l_acd_event event, void *user_data) -{ - struct netconfig *netconfig = user_data; - switch (event) { - case L_ACD_EVENT_AVAILABLE: - L_WARN_ON(!(netconfig->addr4_add_cmd_id = - l_rtnl_ifaddr_add(rtnl, netconfig->ifindex, - netconfig->v4_address, - netconfig_ipv4_ifaddr_add_cmd_cb, - netconfig, NULL))); - return; - case L_ACD_EVENT_CONFLICT: - /* - * Conflict found, no IP was actually set so just free/unset - * anything we set prior to starting ACD. - */ - l_error("netconfig: statically configured address conflict!"); - l_rtnl_address_free(netconfig->v4_address); - netconfig->v4_address = NULL; - netconfig->rtm_protocol = 0; - break; - case L_ACD_EVENT_LOST: - /* - * Set IP but lost it some time after. Full (IPv4) reset in this - * case. - */ - l_error("netconfig: statically configured address was lost"); - netconfig_remove_v4_address(netconfig); - break; + if (!l_netconfig_set_family_enabled(netconfig->nc, AF_INET, + enable_ipv4) || + !l_netconfig_set_family_enabled(netconfig->nc, AF_INET6, + enable_ipv6)) { + l_error("netconfig: l_netconfig_set_family_enabled() failed"); + success = false; } -} - -static bool netconfig_ipv4_select_and_install(struct netconfig *netconfig) -{ - struct netdev *netdev = netdev_find(netconfig->ifindex); - bool set_address = (netconfig->rtm_protocol == RTPROT_STATIC); - - if (netconfig_use_fils_addr(netconfig, AF_INET)) { - L_AUTO_FREE_VAR(char *, addr_str) = netconfig_ipv4_to_string( - netconfig->fils_override->ipv4_addr); - uint8_t prefix_len = netconfig->fils_override->ipv4_prefix_len; - - if (unlikely(!addr_str)) - return false; - - netconfig->v4_address = l_rtnl_address_new(addr_str, - prefix_len); - if (L_WARN_ON(!netconfig->v4_address)) - return false; - l_rtnl_address_set_noprefixroute(netconfig->v4_address, true); - set_address = true; +send_hostname: + if (l_settings_has_key(active_settings, "IPv4", "SendHostname") && + !l_settings_get_bool(active_settings, "IPv4", + "SendHostname", + &send_hostname)) { + l_error("netconfig: Can't load [IPv4].SendHostname"); + success = false; + goto mdns; + } - /* - * TODO: If netconfig->fils_override->ipv4_lifetime is set, - * start a timeout to renew the address using FILS IP Address - * Assignment or perhaps just start the DHCP client at that - * time. - */ + if (send_hostname && gethostname(hostname, sizeof(hostname)) != 0) { + /* Warning only */ + l_warn("netconfig: Unable to get hostname. " + "Error %d: %s", errno, strerror(errno)); + goto mdns; } - if (set_address) { - char ip[INET6_ADDRSTRLEN]; + if (send_hostname && + !l_netconfig_set_hostname(netconfig->nc, hostname)) { + l_error("netconfig: l_netconfig_set_hostname() failed"); + success = false; + goto mdns; + } - if (L_WARN_ON(!netconfig->v4_address || - !l_rtnl_address_get_address( - netconfig->v4_address, - ip))) - return false; +mdns: + /* If the networks has this set take that over the global */ + if (l_settings_has_key(active_settings, "Network", "MulticastDNS")) { + mdns = l_settings_get_string(active_settings, "Network", + "MulticastDNS"); + if (!mdns) { + l_error("netconfig: Can't load Network.MulticastDNS"); + success = false; + } - netconfig_dns_list_update(netconfig, AF_INET); - netconfig_domains_update(netconfig, AF_INET); - - netconfig->acd = l_acd_new(netconfig->ifindex); - l_acd_set_event_handler(netconfig->acd, - netconfig_ipv4_acd_event, netconfig, - NULL); - if (getenv("IWD_ACD_DEBUG")) - l_acd_set_debug(netconfig->acd, do_debug, - "[ACD] ", NULL); - - if (!l_acd_start(netconfig->acd, ip)) { - l_error("failed to start ACD, continuing anyways"); - l_acd_destroy(netconfig->acd); - netconfig->acd = NULL; - - L_WARN_ON(!(netconfig->addr4_add_cmd_id = - l_rtnl_ifaddr_add(rtnl, netconfig->ifindex, - netconfig->v4_address, - netconfig_ipv4_ifaddr_add_cmd_cb, - netconfig, NULL))); + if (mdns && !L_IN_STRSET(mdns, "true", "false", "resolve")) { + l_error("netconfig: Bad profile Network.MulticastDNS " + "value '%s'", mdns); + success = false; } - return true; + if (!success) + goto check_config; } - l_dhcp_client_set_address(netconfig->dhcp_client, ARPHRD_ETHER, - netdev_get_address(netdev), ETH_ALEN); + if (!mdns && mdns_global) { + mdns = l_strdup(mdns_global); - if (l_dhcp_client_start(netconfig->dhcp_client)) - return true; - - l_error("netconfig: Failed to start DHCPv4 client for interface %u", - netconfig->ifindex); - return false; -} - -static bool netconfig_ipv6_select_and_install(struct netconfig *netconfig) -{ - struct netdev *netdev = netdev_find(netconfig->ifindex); - - if (netconfig->rtm_v6_protocol == RTPROT_UNSPEC) { - l_debug("IPV6 configuration disabled"); - return true; + if (!L_IN_STRSET(mdns, "true", "false", "resolve")) { + l_error("netconfig: Bad global Network.MulticastDNS " + "value '%s'", mdns); + success = false; + } } - sysfs_write_ipv6_setting(netdev_get_name(netdev), "disable_ipv6", "0"); - - if (netconfig_use_fils_addr(netconfig, AF_INET6)) { - uint8_t prefix_len = netconfig->fils_override->ipv6_prefix_len; - L_AUTO_FREE_VAR(char *, addr_str) = netconfig_ipv6_to_string( - netconfig->fils_override->ipv6_addr); - - if (unlikely(!addr_str)) - return false; - - netconfig->v6_address = l_rtnl_address_new(addr_str, - prefix_len); - if (L_WARN_ON(unlikely(!netconfig->v6_address))) - return false; - - l_rtnl_address_set_noprefixroute(netconfig->v6_address, true); - - /* - * TODO: If netconfig->fils_override->ipv6_lifetime is set, - * start a timeout to renew the address using FILS IP Address - * Assignment or perhaps just start the DHCP client at that - * time. - */ +check_config: + if (!l_netconfig_check_config(netconfig->nc)) { + l_error("netconfig: Invalid configuration"); + success = false; } - if (netconfig->v6_address) { - netconfig_dns_list_update(netconfig, AF_INET6); - - L_WARN_ON(!(netconfig->addr6_add_cmd_id = - l_rtnl_ifaddr_add(rtnl, netconfig->ifindex, - netconfig->v6_address, - netconfig_ipv6_ifaddr_add_cmd_cb, - netconfig, NULL))); + if (success) { + netconfig->active_settings = active_settings; + netconfig->static_config[INDEX_FOR_AF(AF_INET)] = static_ipv4; + netconfig->static_config[INDEX_FOR_AF(AF_INET6)] = static_ipv6; + netconfig->enabled[INDEX_FOR_AF(AF_INET)] = enable_ipv4; + netconfig->enabled[INDEX_FOR_AF(AF_INET6)] = enable_ipv6; + netconfig->mdns = l_steal_ptr(mdns); return true; } - /* DHCPv6 or RA, update MAC */ - l_dhcp6_client_set_address(netconfig->dhcp6_client, ARPHRD_ETHER, - netdev_get_address(netdev), ETH_ALEN); - - return true; -} - -static int validate_dns_list(int family, char **dns_list) -{ - unsigned int n_valid = 0; - struct in_addr in_addr; - struct in6_addr in6_addr; - char **p; - - for (p = dns_list; *p; p++) { - int r; - - if (family == AF_INET) - r = inet_pton(AF_INET, *p, &in_addr); - else if (family == AF_INET6) - r = inet_pton(AF_INET6, *p, &in6_addr); - else - r = -EAFNOSUPPORT; - - if (r > 0) { - n_valid += 1; - continue; - } - - l_error("netconfig: Invalid DNS address '%s'.", *p); - return -EINVAL; - } - - return n_valid; + l_netconfig_reset_config(netconfig->nc); + return false; } -bool netconfig_load_settings(struct netconfig *netconfig, - const struct l_settings *active_settings) +static bool netconfig_load_fils_settings(struct netconfig *netconfig, + uint8_t af) { - _auto_(l_free) char *mdns = NULL; - bool send_hostname; - bool v6_enabled; - char hostname[HOST_NAME_MAX + 1]; - _auto_(l_strv_free) char **dns4_overrides = NULL; - _auto_(l_strv_free) char **dns6_overrides = NULL; - _auto_(l_rtnl_address_free) struct l_rtnl_address *v4_address = NULL; - _auto_(l_rtnl_address_free) struct l_rtnl_address *v6_address = NULL; - - dns4_overrides = l_settings_get_string_list(active_settings, - "IPv4", "DNS", ' '); - if (dns4_overrides) { - int r = validate_dns_list(AF_INET, dns4_overrides); - - if (unlikely(r <= 0)) { - l_strfreev(dns4_overrides); - dns4_overrides = NULL; - - if (r < 0) - return false; - } - - if (r == 0) - l_error("netconfig: Empty IPv4.DNS entry, skipping..."); - } - - dns6_overrides = l_settings_get_string_list(active_settings, - "IPv6", "DNS", ' '); + struct ie_fils_ip_addr_response_info *fils = netconfig->fils_override; + char addr_str[INET6_ADDRSTRLEN]; + char gw_addr_str[INET6_ADDRSTRLEN]; + char dns_addr_str[INET6_ADDRSTRLEN]; + _auto_(l_rtnl_address_free) struct l_rtnl_address *rtnl_addr = NULL; + bool is_zero = false; + uint8_t prefix_len; - if (dns6_overrides) { - int r = validate_dns_list(AF_INET6, dns6_overrides); + if (!netconfig_addr_to_str(af, &fils->ipv4_addr, &fils->ipv6_addr, + addr_str, &is_zero) || is_zero) + return is_zero; - if (unlikely(r <= 0)) { - l_strfreev(dns6_overrides); - dns6_overrides = NULL; - - if (r < 0) - return false; - } + prefix_len = (af == AF_INET ? fils->ipv4_prefix_len : + fils->ipv6_prefix_len); - if (r == 0) - l_error("netconfig: Empty IPv6.DNS entry, skipping..."); - } + if (L_WARN_ON(!(rtnl_addr = l_rtnl_address_new(addr_str, prefix_len)))) + return false; - if (!l_settings_get_bool(active_settings, - "IPv4", "SendHostname", &send_hostname)) - send_hostname = false; + if (L_WARN_ON(!l_netconfig_set_static_addr(netconfig->nc, af, + rtnl_addr))) + return false; - if (send_hostname) { - if (gethostname(hostname, sizeof(hostname)) != 0) { - l_warn("netconfig: Unable to get hostname. " - "Error %d: %s", errno, strerror(errno)); - send_hostname = false; - } - } + if (af == AF_INET && + L_WARN_ON(!l_netconfig_set_acd_enabled(netconfig->nc, + false))) + return false; - mdns = l_settings_get_string(active_settings, - "Network", "MulticastDNS"); + /* + * Done with local address, move on to gateway and DNS. + * + * Since load_settings is called early, generally before the actual + * connection setup starts, and load_fils_settings is called after + * 802.11 Authentication & Association, we need to check if either + * the gateway or DNS settings were overridden in load_settings so + * as not to overwrite the user-provided values. Values received + * with FILS are expected to have the same weight as those from + * DHCP/SLAAC. + * + * TODO: If netconfig->fils_override->ipv{4,6}_lifetime is set, + * start a timeout to renew the address using FILS IP Address + * Assignment or perhaps just start the DHCP client after that + * time. + * + * TODO: validate gateway and/or DNS on local subnet, link-local, + * etc.? + */ - if (l_settings_has_key(active_settings, "IPv4", "Address")) { - v4_address = netconfig_get_static4_address(active_settings); + if (!netconfig_addr_to_str(af, &fils->ipv4_gateway, &fils->ipv6_gateway, + gw_addr_str, &is_zero)) + return false; - if (unlikely(!v4_address)) { - l_error("netconfig: Can't parse IPv4 address"); - return false; - } - } + if (!netconfig->gateway_overridden[INDEX_FOR_AF(af)] && !is_zero && + L_WARN_ON(!l_netconfig_set_gateway_override( + netconfig->nc, + af, + gw_addr_str))) + return false; - if (!l_settings_get_bool(active_settings, "IPv6", - "Enabled", &v6_enabled)) - v6_enabled = ipv6_enabled; + if (!netconfig_addr_to_str(af, &fils->ipv4_dns, &fils->ipv6_dns, + dns_addr_str, &is_zero)) + return is_zero; - if (l_settings_has_key(active_settings, "IPv6", "Address")) { - v6_address = netconfig_get_static6_address(active_settings); + if (!netconfig->dns_overridden[INDEX_FOR_AF(af)] && !is_zero) { + char *dns_list[2] = { dns_addr_str, NULL }; - if (unlikely(!v6_address)) { - l_error("netconfig: Can't parse IPv6 address"); + if (L_WARN_ON(!l_netconfig_set_dns_override(netconfig->nc, + af, dns_list))) return false; - } } - /* No more validation steps for now, commit new values */ - netconfig->rtm_protocol = v4_address ? RTPROT_STATIC : RTPROT_DHCP; - - if (!v6_enabled) - netconfig->rtm_v6_protocol = RTPROT_UNSPEC; - else if (v6_address) - netconfig->rtm_v6_protocol = RTPROT_STATIC; - else - netconfig->rtm_v6_protocol = RTPROT_DHCP; - - if (send_hostname) - l_dhcp_client_set_hostname(netconfig->dhcp_client, hostname); - - netconfig_free_settings(netconfig); - - if (netconfig->rtm_protocol == RTPROT_STATIC) - netconfig->v4_address = l_steal_ptr(v4_address); - - if (netconfig->rtm_v6_protocol == RTPROT_STATIC) - netconfig->v6_address = l_steal_ptr(v6_address); - - netconfig->active_settings = active_settings; - netconfig->dns4_overrides = l_steal_ptr(dns4_overrides); - netconfig->dns6_overrides = l_steal_ptr(dns6_overrides); - netconfig->mdns = l_steal_ptr(mdns); return true; } bool netconfig_configure(struct netconfig *netconfig, netconfig_notify_func_t notify, void *user_data) { + if (netconfig->started) + return false; + netconfig->notify = notify; netconfig->user_data = user_data; - if (unlikely(!netconfig_ipv4_select_and_install(netconfig))) + if (netconfig_use_fils_addr(netconfig, AF_INET) && + !netconfig_load_fils_settings(netconfig, AF_INET)) return false; - if (unlikely(!netconfig_ipv6_select_and_install(netconfig))) + if (netconfig_use_fils_addr(netconfig, AF_INET6) && + !netconfig_load_fils_settings(netconfig, AF_INET6)) return false; - resolve_set_mdns(netconfig->resolve, netconfig->mdns); + if (unlikely(!l_netconfig_start(netconfig->nc))) + return false; + netconfig->started = true; return true; } bool netconfig_reconfigure(struct netconfig *netconfig, bool set_arp_gw) { + if (!netconfig->started) + return false; + /* * Starting with kernel 4.20, ARP cache is flushed when the netdev * detects NO CARRIER. This can result in unnecessarily long delays @@ -1510,14 +558,23 @@ bool netconfig_reconfigure(struct netconfig *netconfig, bool set_arp_gw) * lost or delayed. Try to force the gateway into the ARP cache * to alleviate this */ - if (set_arp_gw) - netconfig_gateway_to_arp(netconfig); + if (set_arp_gw) { + netconfig_dhcp_gateway_to_arp(netconfig); - if (netconfig->rtm_protocol == RTPROT_DHCP) { + if (netconfig->connected[INDEX_FOR_AF(AF_INET)] && + netconfig_use_fils_addr(netconfig, AF_INET)) + netconfig_commit_fils_macs(netconfig, AF_INET); + + if (netconfig->connected[INDEX_FOR_AF(AF_INET6)] && + netconfig_use_fils_addr(netconfig, AF_INET6)) + netconfig_commit_fils_macs(netconfig, AF_INET6); + } + + if (!netconfig->static_config[INDEX_FOR_AF(AF_INET)]) { /* TODO l_dhcp_client sending a DHCP inform request */ } - if (netconfig->rtm_v6_protocol == RTPROT_DHCP) { + if (!netconfig->static_config[INDEX_FOR_AF(AF_INET6)]) { /* TODO l_dhcp_v6_client sending a DHCP inform request */ } @@ -1526,64 +583,30 @@ bool netconfig_reconfigure(struct netconfig *netconfig, bool set_arp_gw) bool netconfig_reset(struct netconfig *netconfig) { - struct netdev *netdev = netdev_find(netconfig->ifindex); - - if (netconfig->route4_add_gateway_cmd_id) { - l_netlink_cancel(rtnl, netconfig->route4_add_gateway_cmd_id); - netconfig->route4_add_gateway_cmd_id = 0; - } - - if (netconfig->route6_add_cmd_id) { - l_netlink_cancel(rtnl, netconfig->route6_add_cmd_id); - netconfig->route6_add_cmd_id = 0; - } - - if (netconfig->addr4_add_cmd_id) { - l_netlink_cancel(rtnl, netconfig->addr4_add_cmd_id); - netconfig->addr4_add_cmd_id = 0; - } - - if (netconfig->addr6_add_cmd_id) { - l_netlink_cancel(rtnl, netconfig->addr6_add_cmd_id); - netconfig->addr6_add_cmd_id = 0; - } - - if (netconfig->rtm_protocol || netconfig->rtm_v6_protocol) - resolve_revert(netconfig->resolve); - - netconfig_reset_v4(netconfig); - - if (netconfig->rtm_v6_protocol) { - l_rtnl_address_free(netconfig->v6_address); - netconfig->v6_address = NULL; - - l_strv_free(l_steal_ptr(netconfig->dns6_overrides)); - l_strv_free(l_steal_ptr(netconfig->dns6_list)); - - l_dhcp6_client_stop(netconfig->dhcp6_client); - netconfig->rtm_v6_protocol = 0; - - sysfs_write_ipv6_setting(netdev_get_name(netdev), - "disable_ipv6", "1"); - - l_free(l_steal_ptr(netconfig->v6_gateway_str)); + if (!netconfig->started) + return false; - l_strv_free(l_steal_ptr(netconfig->v6_domains)); - } + netconfig->started = false; + l_netconfig_unconfigure(netconfig->nc); + l_netconfig_stop(netconfig->nc); - l_free(l_steal_ptr(netconfig->fils_override)); + netconfig->connected[0] = false; + netconfig->connected[1] = false; + netconfig_free_settings(netconfig); return true; } char *netconfig_get_dhcp_server_ipv4(struct netconfig *netconfig) { + struct l_dhcp_client *client = + l_netconfig_get_dhcp_client(netconfig->nc); const struct l_dhcp_lease *lease; - if (!netconfig->dhcp_client) + if (!client) return NULL; - lease = l_dhcp_client_get_lease(netconfig->dhcp_client); + lease = l_dhcp_client_get_lease(client); if (!lease) return NULL; @@ -1599,15 +622,16 @@ bool netconfig_get_fils_ip_req(struct netconfig *netconfig, * configuration (usually DHCP). If we're configured with static * values return false to mean the IE should not be sent. */ - if (netconfig->rtm_protocol != RTPROT_DHCP && - netconfig->rtm_v6_protocol != RTPROT_DHCP) + if (netconfig->static_config[0] && netconfig->static_config[1]) return false; memset(info, 0, sizeof(*info)); - info->ipv4 = (netconfig->rtm_protocol == RTPROT_DHCP); - info->ipv6 = (netconfig->rtm_v6_protocol == RTPROT_DHCP); - info->dns = (info->ipv4 && !netconfig->dns4_overrides) || - (info->ipv6 && !netconfig->dns6_overrides); + info->ipv4 = !netconfig->static_config[INDEX_FOR_AF(AF_INET)]; + info->ipv6 = !netconfig->static_config[INDEX_FOR_AF(AF_INET6)]; + info->dns = (info->ipv4 && + !netconfig->dns_overridden[INDEX_FOR_AF(AF_INET)]) || + (info->ipv6 && + !netconfig->dns_overridden[INDEX_FOR_AF(AF_INET)]); return true; } @@ -1619,31 +643,65 @@ void netconfig_handle_fils_ip_resp(struct netconfig *netconfig, netconfig->fils_override = l_memdup(info, sizeof(*info)); } +static void netconfig_event_handler(struct l_netconfig *nc, uint8_t family, + enum l_netconfig_event event, + void *user_data) +{ + struct netconfig *netconfig = user_data; + + /* Once stopped, only commit a final L_NETCONFIG_EVENT_UNCONFIGURE */ + if (!netconfig->started && event != L_NETCONFIG_EVENT_UNCONFIGURE) + return; + + l_debug("l_netconfig event %d", event); + + netconfig_commit(netconfig, family, event); + + switch (event) { + case L_NETCONFIG_EVENT_CONFIGURE: + case L_NETCONFIG_EVENT_UPDATE: + break; + + case L_NETCONFIG_EVENT_UNCONFIGURE: + break; + + case L_NETCONFIG_EVENT_FAILED: + netconfig->connected[INDEX_FOR_AF(family)] = false; + + /* + * l_netconfig might have emitted an UNCONFIGURE before this + * but now it tells us it's given up on (re)establishing the + * IP setup. + */ + if (family == AF_INET && netconfig->notify) + netconfig->notify(NETCONFIG_EVENT_FAILED, + netconfig->user_data); + + break; + + default: + l_error("netconfig: Received unsupported l_netconfig event: %d", + event); + } +} + struct netconfig *netconfig_new(uint32_t ifindex) { struct netdev *netdev = netdev_find(ifindex); struct netconfig *netconfig; - struct l_icmp6_client *icmp6; const char *debug_level = NULL; int dhcp_priority = L_LOG_INFO; + struct l_dhcp6_client *dhcp6; + struct l_icmp6_client *icmp6; - if (!netconfig_list) - return NULL; - - l_debug("Starting netconfig for interface: %d", ifindex); - - netconfig = netconfig_find(ifindex); - if (netconfig) - return netconfig; + l_debug("Creating netconfig for interface: %d", ifindex); netconfig = l_new(struct netconfig, 1); - netconfig->ifindex = ifindex; + netconfig->nc = l_netconfig_new(ifindex); + netconfig->netdev = netdev; netconfig->resolve = resolve_new(ifindex); - netconfig->dhcp_client = l_dhcp_client_new(ifindex); - l_dhcp_client_set_event_handler(netconfig->dhcp_client, - netconfig_ipv4_dhcp_event_handler, - netconfig, NULL); + netconfig_commit_init(netconfig); debug_level = getenv("IWD_DHCP_DEBUG"); if (debug_level != NULL) { @@ -1659,43 +717,35 @@ struct netconfig *netconfig_new(uint32_t ifindex) dhcp_priority = L_LOG_DEBUG; } - l_dhcp_client_set_debug(netconfig->dhcp_client, do_debug, - "[DHCPv4] ", NULL, dhcp_priority); + l_netconfig_set_event_handler(netconfig->nc, netconfig_event_handler, + netconfig, NULL); - netconfig->dhcp6_client = l_dhcp6_client_new(ifindex); - l_dhcp6_client_set_event_handler(netconfig->dhcp6_client, - netconfig_dhcp6_event_handler, - netconfig, NULL); - l_dhcp6_client_set_lla_randomized(netconfig->dhcp6_client, true); - l_dhcp6_client_set_nodelay(netconfig->dhcp6_client, true); - l_dhcp6_client_set_rtnl(netconfig->dhcp6_client, rtnl); + l_dhcp_client_set_debug(l_netconfig_get_dhcp_client(netconfig->nc), + do_debug, "[DHCPv4] ", NULL, dhcp_priority); - if (getenv("IWD_DHCP_DEBUG")) - l_dhcp6_client_set_debug(netconfig->dhcp6_client, do_debug, - "[DHCPv6] ", NULL); + dhcp6 = l_netconfig_get_dhcp6_client(netconfig->nc); + l_dhcp6_client_set_lla_randomized(dhcp6, true); - icmp6 = l_dhcp6_client_get_icmp6(netconfig->dhcp6_client); - l_icmp6_client_set_rtnl(icmp6, rtnl); - l_icmp6_client_set_route_priority(icmp6, ROUTE_PRIORITY_OFFSET); + icmp6 = l_netconfig_get_icmp6_client(netconfig->nc); + l_icmp6_client_set_nodelay(icmp6, true); - l_queue_push_tail(netconfig_list, netconfig); + if (debug_level) { + l_dhcp6_client_set_debug(dhcp6, do_debug, "[DHCPv6] ", NULL); + l_icmp6_client_set_debug(icmp6, do_debug, "[ICMPv6] ", NULL); + } - sysfs_write_ipv6_setting(netdev_get_name(netdev), "accept_ra", "0"); - sysfs_write_ipv6_setting(netdev_get_name(netdev), "disable_ipv6", "1"); + l_netconfig_set_route_priority(netconfig->nc, ROUTE_PRIORITY_OFFSET); + l_netconfig_set_optimistic_dad_enabled(netconfig->nc, true); return netconfig; } void netconfig_destroy(struct netconfig *netconfig) { - if (!netconfig_list) - return; - l_debug(""); - l_queue_remove(netconfig_list, netconfig); - netconfig_reset(netconfig); + netconfig_commit_free(netconfig, "aborted"); resolve_free(netconfig->resolve); netconfig_free(netconfig); } @@ -1711,43 +761,6 @@ bool netconfig_enabled(void) static int netconfig_init(void) { - uint32_t r; - - if (netconfig_list) - return -EALREADY; - - rtnl = iwd_get_rtnl(); - - r = l_netlink_register(rtnl, RTNLGRP_IPV4_IFADDR, - netconfig_ifaddr_notify, NULL, NULL); - if (!r) { - l_error("netconfig: Failed to register for RTNL link address" - " notifications."); - goto error; - } - - r = l_rtnl_ifaddr4_dump(rtnl, netconfig_ifaddr_cmd_cb, NULL, NULL); - if (!r) { - l_error("netconfig: Failed to get addresses from RTNL link."); - goto error; - } - - r = l_netlink_register(rtnl, RTNLGRP_IPV6_IFADDR, - netconfig_ifaddr_ipv6_notify, NULL, NULL); - if (!r) { - l_error("netconfig: Failed to register for RTNL link IPv6 " - "address notifications."); - goto error; - } - - r = l_rtnl_ifaddr6_dump(rtnl, netconfig_ifaddr_ipv6_cmd_cb, NULL, - NULL); - if (!r) { - l_error("netconfig: Failed to get IPv6 addresses from RTNL" - " link."); - goto error; - } - if (!l_settings_get_uint(iwd_get_config(), "Network", "RoutePriorityOffset", &ROUTE_PRIORITY_OFFSET)) @@ -1756,26 +769,17 @@ static int netconfig_init(void) if (!l_settings_get_bool(iwd_get_config(), "Network", "EnableIPv6", &ipv6_enabled)) - ipv6_enabled = false; + ipv6_enabled = true; - netconfig_list = l_queue_new(); + mdns_global = l_settings_get_string(iwd_get_config(), "Network", + "MulticastDNS"); return 0; - -error: - rtnl = NULL; - - return r; } static void netconfig_exit(void) { - if (!netconfig_list) - return; - - rtnl = NULL; - - l_queue_destroy(netconfig_list, netconfig_free); + l_free(mdns_global); } IWD_MODULE(netconfig, netconfig_init, netconfig_exit) diff --git a/src/netconfig.h b/src/netconfig.h @@ -20,17 +20,47 @@ * */ +struct netdev; struct netconfig; struct ie_fils_ip_addr_request_info; struct ie_fils_ip_addr_response_info; enum netconfig_event { NETCONFIG_EVENT_CONNECTED, + NETCONFIG_EVENT_FAILED, }; typedef void (*netconfig_notify_func_t)(enum netconfig_event event, void *user_data); +struct netconfig { + struct l_netconfig *nc; + struct netdev *netdev; + + char *mdns; + struct ie_fils_ip_addr_response_info *fils_override; + bool enabled[2]; + bool static_config[2]; + bool gateway_overridden[2]; + bool dns_overridden[2]; + bool started; + bool connected[2]; + char **dns_list; + char **domains; + + const struct l_settings *active_settings; + + netconfig_notify_func_t notify; + void *user_data; + + struct resolve *resolve; + + void *commit_data; +}; + +/* 0 for AF_INET, 1 for AF_INET6 */ +#define INDEX_FOR_AF(af) ((af) != AF_INET) + bool netconfig_load_settings(struct netconfig *netconfig, const struct l_settings *active_settings); bool netconfig_configure(struct netconfig *netconfig, @@ -43,8 +73,19 @@ bool netconfig_get_fils_ip_req(struct netconfig *netconfig, struct ie_fils_ip_addr_request_info *info); void netconfig_handle_fils_ip_resp(struct netconfig *netconfig, const struct ie_fils_ip_addr_response_info *info); +bool netconfig_use_fils_addr(struct netconfig *netconfig, int af); struct netconfig *netconfig_new(uint32_t ifindex); void netconfig_destroy(struct netconfig *netconfig); bool netconfig_enabled(void); + +void netconfig_commit_init(struct netconfig *netconfig); +void netconfig_commit_free(struct netconfig *netconfig, const char *reasonstr); +void netconfig_commit(struct netconfig *netconfig, uint8_t family, + enum l_netconfig_event event); +int netconfig_register_agent(const char *name, const char *path); +int netconfig_unregister_agent(const char *name, const char *path); + +void netconfig_dhcp_gateway_to_arp(struct netconfig *netconfig); +void netconfig_commit_fils_macs(struct netconfig *netconfig, uint8_t family); diff --git a/src/netdev.c b/src/netdev.c @@ -96,13 +96,6 @@ struct netdev_handshake_state { enum connection_type type; }; -struct netdev_ft_over_ds_info { - struct ft_ds_info super; - struct netdev *netdev; - - bool parsed : 1; -}; - struct netdev_ext_key_info { uint16_t proto; bool noencrypt; @@ -145,7 +138,6 @@ struct netdev { struct l_timeout *sa_query_delay; struct l_timeout *group_handshake_timeout; uint16_t sa_query_id; - uint8_t prev_snonce[32]; int8_t rssi_levels[16]; uint8_t rssi_levels_num; uint8_t cur_rssi_level_idx; @@ -176,8 +168,6 @@ struct netdev { struct l_genl_msg *auth_cmd; struct wiphy_radio_work_item work; - struct l_queue *ft_ds_list; - struct netdev_ext_key_info *ext_key_info; bool connected : 1; @@ -752,13 +742,6 @@ static void netdev_preauth_destroy(void *data) l_free(state); } -static void netdev_ft_ds_entry_free(void *data) -{ - struct netdev_ft_over_ds_info *info = data; - - ft_ds_info_free(&info->super); -} - static void netdev_connect_free(struct netdev *netdev) { if (netdev->work.id) @@ -847,11 +830,6 @@ static void netdev_connect_free(struct netdev *netdev) l_genl_family_cancel(nl80211, netdev->get_oci_cmd_id); netdev->get_oci_cmd_id = 0; } - - if (netdev->ft_ds_list) { - l_queue_destroy(netdev->ft_ds_list, netdev_ft_ds_entry_free); - netdev->ft_ds_list = NULL; - } } static void netdev_connect_failed(struct netdev *netdev, @@ -962,11 +940,6 @@ static void netdev_free(void *data) if (netdev->fw_roam_bss) scan_bss_free(netdev->fw_roam_bss); - if (netdev->ft_ds_list) { - l_queue_destroy(netdev->ft_ds_list, netdev_ft_ds_entry_free); - netdev->ft_ds_list = NULL; - } - scan_wdev_remove(netdev->wdev_id); watchlist_destroy(&netdev->station_watches); @@ -1413,14 +1386,12 @@ static void netdev_connect_ok(struct netdev *netdev) scan_bss_free(netdev->fw_roam_bss); netdev->fw_roam_bss = NULL; - } - - if (netdev->ft_ds_list) { - l_queue_destroy(netdev->ft_ds_list, netdev_ft_ds_entry_free); - netdev->ft_ds_list = NULL; - } - - if (netdev->connect_cb) { + } else if (netdev->in_ft) { + if (netdev->event_filter) + netdev->event_filter(netdev, NETDEV_EVENT_FT_ROAMED, + NULL, netdev->user_data); + netdev->in_ft = false; + } else if (netdev->connect_cb) { netdev->connect_cb(netdev, NETDEV_RESULT_OK, NULL, netdev->user_data); netdev->connect_cb = NULL; @@ -1593,12 +1564,17 @@ static bool netdev_copy_tk(uint8_t *tk_buf, const uint8_t *tk, { switch (cipher) { case CRYPTO_CIPHER_CCMP: + case CRYPTO_CIPHER_GCMP: + case CRYPTO_CIPHER_GCMP_256: + case CRYPTO_CIPHER_CCMP_256: /* - * 802.11-2016 12.8.3 Mapping PTK to CCMP keys: + * 802.11-2020 12.8.3 Mapping PTK to CCMP keys: * "A STA shall use the temporal key as the CCMP key * for MPDUs between the two communicating STAs." + * + * Similar verbiage in 12.8.8 */ - memcpy(tk_buf, tk, 16); + memcpy(tk_buf, tk, crypto_cipher_key_len(cipher)); break; case CRYPTO_CIPHER_TKIP: /* @@ -1659,7 +1635,7 @@ static void netdev_set_gtk(struct handshake_state *hs, uint16_t key_index, nhs->gtk_installed = false; - l_debug("%d", netdev->index); + l_debug("ifindex=%d key_idx=%u", netdev->index, key_index); if (crypto_cipher_key_len(cipher) != gtk_len) { l_error("Unexpected key length: %d", gtk_len); @@ -1667,7 +1643,7 @@ static void netdev_set_gtk(struct handshake_state *hs, uint16_t key_index, return; } - if (!netdev_copy_tk(gtk_buf, gtk, cipher, false)) { + if (!netdev_copy_tk(gtk_buf, gtk, cipher, hs->authenticator)) { netdev_setting_keys_failed(nhs, -ENOENT); return; } @@ -1698,13 +1674,13 @@ static void netdev_set_igtk(struct handshake_state *hs, uint16_t key_index, { struct netdev_handshake_state *nhs = l_container_of(hs, struct netdev_handshake_state, super); - uint8_t igtk_buf[16]; + uint8_t igtk_buf[32]; struct netdev *netdev = nhs->netdev; struct l_genl_msg *msg; nhs->igtk_installed = false; - l_debug("%d", netdev->index); + l_debug("ifindex=%d key_idx=%u", netdev->index, key_index); if (crypto_cipher_key_len(cipher) != igtk_len) { l_error("Unexpected key length: %d", igtk_len); @@ -1713,8 +1689,11 @@ static void netdev_set_igtk(struct handshake_state *hs, uint16_t key_index, } switch (cipher) { - case CRYPTO_CIPHER_BIP: - memcpy(igtk_buf, igtk, 16); + case CRYPTO_CIPHER_BIP_CMAC: + case CRYPTO_CIPHER_BIP_GMAC: + case CRYPTO_CIPHER_BIP_GMAC_256: + case CRYPTO_CIPHER_BIP_CMAC_256: + memcpy(igtk_buf, igtk, igtk_len); break; default: l_error("Unexpected cipher: %x", cipher); @@ -2075,10 +2054,10 @@ static void netdev_set_tk(struct handshake_state *hs, uint8_t key_index, return; } - l_debug("%d", netdev->index); + l_debug("ifindex=%d key_idx=%u", netdev->index, key_index); err = -ENOENT; - if (!netdev_copy_tk(tk_buf, tk, cipher, false)) + if (!netdev_copy_tk(tk_buf, tk, cipher, hs->authenticator)) goto invalid_key; msg = netdev_build_cmd_new_key_pairwise(netdev, cipher, addr, tk_buf, @@ -2112,7 +2091,7 @@ static void netdev_set_ext_tk(struct handshake_state *hs, uint8_t key_idx, L_BE16_TO_CPU(step4->header.packet_len); err = -ENOENT; - if (!netdev_copy_tk(tk_buf, tk, cipher, false)) + if (!netdev_copy_tk(tk_buf, tk, cipher, hs->authenticator)) goto error; msg = netdev_build_cmd_new_rx_key_pairwise(netdev, cipher, addr, tk_buf, @@ -2548,6 +2527,44 @@ static unsigned int ie_rsn_akm_suite_to_nl80211(enum ie_rsn_akm_suite akm) return 0; } +static void netdev_append_nl80211_rsn_attributes(struct l_genl_msg *msg, + struct handshake_state *hs) +{ + uint32_t nl_cipher; + uint32_t nl_akm; + uint32_t wpa_version; + + nl_cipher = ie_rsn_cipher_suite_to_cipher(hs->pairwise_cipher); + L_WARN_ON(!nl_cipher); + l_genl_msg_append_attr(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, + 4, &nl_cipher); + + nl_cipher = ie_rsn_cipher_suite_to_cipher(hs->group_cipher); + L_WARN_ON(!nl_cipher); + l_genl_msg_append_attr(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, + 4, &nl_cipher); + + if (hs->mfp) { + uint32_t use_mfp = NL80211_MFP_REQUIRED; + + l_genl_msg_append_attr(msg, NL80211_ATTR_USE_MFP, 4, &use_mfp); + } + + nl_akm = ie_rsn_akm_suite_to_nl80211(hs->akm_suite); + L_WARN_ON(!nl_akm); + l_genl_msg_append_attr(msg, NL80211_ATTR_AKM_SUITES, 4, &nl_akm); + + if (IE_AKM_IS_SAE(hs->akm_suite)) + wpa_version = NL80211_WPA_VERSION_3; + else if (hs->wpa_ie) + wpa_version = NL80211_WPA_VERSION_1; + else + wpa_version = NL80211_WPA_VERSION_2; + + l_genl_msg_append_attr(msg, NL80211_ATTR_WPA_VERSIONS, + 4, &wpa_version); +} + static struct l_genl_msg *netdev_build_cmd_connect(struct netdev *netdev, struct handshake_state *hs, const uint8_t *prev_bssid, @@ -2604,49 +2621,18 @@ static struct l_genl_msg *netdev_build_cmd_connect(struct netdev *netdev, l_genl_msg_append_attr(msg, NL80211_ATTR_SOCKET_OWNER, 0, NULL); if (is_rsn) { - uint32_t nl_cipher; - uint32_t nl_akm; - uint32_t wpa_version; - - if (hs->pairwise_cipher == IE_RSN_CIPHER_SUITE_CCMP) - nl_cipher = CRYPTO_CIPHER_CCMP; - else - nl_cipher = CRYPTO_CIPHER_TKIP; - - l_genl_msg_append_attr(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, - 4, &nl_cipher); - - if (hs->group_cipher == IE_RSN_CIPHER_SUITE_CCMP) - nl_cipher = CRYPTO_CIPHER_CCMP; - else - nl_cipher = CRYPTO_CIPHER_TKIP; - - l_genl_msg_append_attr(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, - 4, &nl_cipher); - - if (hs->mfp) { - uint32_t use_mfp = NL80211_MFP_REQUIRED; - l_genl_msg_append_attr(msg, NL80211_ATTR_USE_MFP, - 4, &use_mfp); - } + netdev_append_nl80211_rsn_attributes(msg, hs); + c_iov = iov_ie_append(iov, n_iov, c_iov, hs->supplicant_ie); + } - nl_akm = ie_rsn_akm_suite_to_nl80211(hs->akm_suite); - if (nl_akm) - l_genl_msg_append_attr(msg, NL80211_ATTR_AKM_SUITES, - 4, &nl_akm); + if (is_rsn || hs->settings_8021x) { + l_genl_msg_append_attr(msg, NL80211_ATTR_CONTROL_PORT, + 0, NULL); - if (IE_AKM_IS_SAE(hs->akm_suite)) - wpa_version = NL80211_WPA_VERSION_3; - else if (hs->wpa_ie) - wpa_version = NL80211_WPA_VERSION_1; - else - wpa_version = NL80211_WPA_VERSION_2; - - l_genl_msg_append_attr(msg, NL80211_ATTR_WPA_VERSIONS, - 4, &wpa_version); - - l_genl_msg_append_attr(msg, NL80211_ATTR_CONTROL_PORT, 0, NULL); - c_iov = iov_ie_append(iov, n_iov, c_iov, hs->supplicant_ie); + if (netdev->pae_over_nl80211) + l_genl_msg_append_attr(msg, + NL80211_ATTR_CONTROL_PORT_OVER_NL80211, + 0, NULL); } if (netdev->owe_sm) { @@ -2654,11 +2640,6 @@ static struct l_genl_msg *netdev_build_cmd_connect(struct netdev *netdev, c_iov = iov_ie_append(iov, n_iov, c_iov, owe_dh_ie); } - if (netdev->pae_over_nl80211) - l_genl_msg_append_attr(msg, - NL80211_ATTR_CONTROL_PORT_OVER_NL80211, - 0, NULL); - c_iov = iov_ie_append(iov, n_iov, c_iov, hs->mde); c_iov = netdev_populate_common_ies(netdev, hs, msg, iov, n_iov, c_iov); @@ -2734,8 +2715,10 @@ static void netdev_connect_event(struct l_genl_msg *msg, struct netdev *netdev) size_t ies_len = 0; struct ie_tlv_iter iter; const uint8_t *resp_ies = NULL; - size_t resp_ies_len; + size_t resp_ies_len = 0; struct handshake_state *hs = netdev->handshake; + bool timeout = false; + uint32_t timeout_reason = 0; l_debug(""); @@ -2763,8 +2746,14 @@ static void netdev_connect_event(struct l_genl_msg *msg, struct netdev *netdev) while (l_genl_attr_next(&attr, &type, &len, &data)) { switch (type) { case NL80211_ATTR_TIMED_OUT: - l_warn("authentication timed out"); - goto error; + timeout = true; + break; + case NL80211_ATTR_TIMEOUT_REASON: + if (len != 4) + break; + + timeout_reason = l_get_u32(data); + break; case NL80211_ATTR_STATUS_CODE: if (len == sizeof(uint16_t)) status_code = data; @@ -2780,6 +2769,11 @@ static void netdev_connect_event(struct l_genl_msg *msg, struct netdev *netdev) } } + if (timeout) { + l_warn("connect event timed out, reason=%u", timeout_reason); + goto error; + } + if (netdev->expect_connect_failure) { /* * The kernel may think we are connected when we are actually @@ -2969,52 +2963,17 @@ static struct l_genl_msg *netdev_build_cmd_associate_common( l_genl_msg_append_attr(msg, NL80211_ATTR_SSID, hs->ssid_len, hs->ssid); l_genl_msg_append_attr(msg, NL80211_ATTR_SOCKET_OWNER, 0, NULL); - if (is_rsn) { - uint32_t nl_cipher; - uint32_t nl_akm; - uint32_t wpa_version; + if (is_rsn) + netdev_append_nl80211_rsn_attributes(msg, hs); - l_genl_msg_append_attr(msg, NL80211_ATTR_CONTROL_PORT, 0, NULL); + if (is_rsn || hs->settings_8021x) { + l_genl_msg_append_attr(msg, NL80211_ATTR_CONTROL_PORT, + 0, NULL); if (netdev->pae_over_nl80211) l_genl_msg_append_attr(msg, NL80211_ATTR_CONTROL_PORT_OVER_NL80211, 0, NULL); - - if (hs->pairwise_cipher == IE_RSN_CIPHER_SUITE_CCMP) - nl_cipher = CRYPTO_CIPHER_CCMP; - else - nl_cipher = CRYPTO_CIPHER_TKIP; - - l_genl_msg_append_attr(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, - 4, &nl_cipher); - - if (hs->group_cipher == IE_RSN_CIPHER_SUITE_CCMP) - nl_cipher = CRYPTO_CIPHER_CCMP; - else - nl_cipher = CRYPTO_CIPHER_TKIP; - - l_genl_msg_append_attr(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, - 4, &nl_cipher); - - if (hs->mfp) { - uint32_t use_mfp = NL80211_MFP_REQUIRED; - l_genl_msg_append_attr(msg, NL80211_ATTR_USE_MFP, - 4, &use_mfp); - } - - nl_akm = ie_rsn_akm_suite_to_nl80211(hs->akm_suite); - if (nl_akm) - l_genl_msg_append_attr(msg, NL80211_ATTR_AKM_SUITES, - 4, &nl_akm); - - if (hs->wpa_ie) - wpa_version = NL80211_WPA_VERSION_1; - else - wpa_version = NL80211_WPA_VERSION_2; - - l_genl_msg_append_attr(msg, NL80211_ATTR_WPA_VERSIONS, - 4, &wpa_version); } return msg; @@ -3106,7 +3065,7 @@ static void netdev_authenticate_event(struct l_genl_msg *msg, while (l_genl_attr_next(&attr, &type, &len, &data)) { switch (type) { case NL80211_ATTR_TIMED_OUT: - l_warn("authentication timed out"); + l_warn("authentication event timed out"); if (auth_proto_auth_timeout(netdev->ap)) return; @@ -3192,13 +3151,15 @@ static void netdev_associate_event(struct l_genl_msg *msg, const uint8_t *frame = NULL; uint16_t status_code = MMPDU_STATUS_CODE_UNSPECIFIED; int ret; + const struct mmpdu_header *hdr; + const struct mmpdu_association_response *assoc; l_debug(""); if (!netdev->connected || netdev->aborting) return; - if (!netdev->ap) { + if (!netdev->ap && !netdev->in_ft) { netdev->associated = true; netdev->in_reassoc = false; return; @@ -3238,61 +3199,58 @@ static void netdev_associate_event(struct l_genl_msg *msg, if (L_WARN_ON(!frame)) goto assoc_failed; - if (netdev->ap) { - const struct mmpdu_header *hdr; - const struct mmpdu_association_response *assoc; - - hdr = mpdu_validate(frame, frame_len); - if (L_WARN_ON(!hdr)) - goto assoc_failed; - - assoc = mmpdu_body(hdr); - status_code = L_CPU_TO_LE16(assoc->status_code); + hdr = mpdu_validate(frame, frame_len); + if (L_WARN_ON(!hdr)) + goto assoc_failed; - ret = auth_proto_rx_associate(netdev->ap, frame, frame_len); - if (ret == 0) { - bool fils = !!(netdev->handshake->akm_suite & - (IE_RSN_AKM_SUITE_FILS_SHA256 | - IE_RSN_AKM_SUITE_FILS_SHA384 | - IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384 | - IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA256)); + assoc = mmpdu_body(hdr); + status_code = L_CPU_TO_LE16(assoc->status_code); + if (netdev->ap) + ret = auth_proto_rx_associate(netdev->ap, frame, + frame_len); + else + ret = __ft_rx_associate(netdev->index, frame, + frame_len); + if (ret == 0) { + bool fils = !!(netdev->handshake->akm_suite & + (IE_RSN_AKM_SUITE_FILS_SHA256 | + IE_RSN_AKM_SUITE_FILS_SHA384 | + IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384 | + IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA256)); + + if (netdev->ap) { auth_proto_free(netdev->ap); 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; - - /* - * If in FT and/or FILS we don't force an initial 4-way - * handshake and instead just keep the EAPoL state - * machine for the rekeys. - */ - if (netdev->in_ft || fils) - eapol_sm_set_require_handshake(netdev->sm, - false); + netdev->sm = eapol_sm_new(netdev->handshake); + eapol_register(netdev->sm); - netdev->in_ft = false; - netdev->in_reassoc = false; - netdev->associated = true; - return; - } else if (ret == -EAGAIN) { - /* - * Here to support OWE retries. OWE will retry - * internally, but a connect event will still be emitted - */ - netdev->ignore_connect_event = true; - return; - } else if (ret > 0) - status_code = (uint16_t)ret; + /* Just in case this was a retry */ + netdev->ignore_connect_event = false; - goto assoc_failed; - } + /* + * If in FT and/or FILS we don't force an initial 4-way + * handshake and instead just keep the EAPoL state + * machine for the rekeys. + */ + if (netdev->in_ft || fils) + eapol_sm_set_require_handshake(netdev->sm, + false); - return; + netdev->in_reassoc = false; + netdev->associated = true; + return; + } else if (ret == -EAGAIN) { + /* + * Here to support OWE retries. OWE will retry + * internally, but a connect event will still be emitted + */ + netdev->ignore_connect_event = true; + return; + } else if (ret > 0) + status_code = (uint16_t)ret; assoc_failed: netdev->result = NETDEV_RESULT_ASSOCIATION_FAILED; @@ -3584,8 +3542,7 @@ failed: return -EIO; } -static void netdev_mac_change_failed(struct netdev *netdev, - struct rtnl_data *req, int error) +static void netdev_mac_change_failed(struct netdev *netdev, int error) { l_error("Error setting mac address on %d: %s", netdev->index, strerror(-error)); @@ -3601,12 +3558,8 @@ static void netdev_mac_change_failed(struct netdev *netdev, goto failed; } else { - /* - * If the interface is up we can still try and connect. This - * is a very rare case and most likely will never happen. - */ - l_info("Interface still up after failing to change the MAC, " - "continuing with connection"); + /* If the interface is up we can still try and connect */ + l_info("Failed to change the MAC, continuing with connection"); if (netdev_begin_connection(netdev) < 0) goto failed; @@ -3641,9 +3594,9 @@ static void netdev_mac_power_up_cb(int error, uint16_t type, netdev->mac_change_cmd_id = 0; if (error) { - l_error("Error taking interface %u up for per-network MAC " - "generation: %s", netdev->index, strerror(-error)); - netdev_mac_change_failed(netdev, req, error); + l_error("Error changing per-network MAC on interface %u: %s", + netdev->index, strerror(-error)); + netdev_mac_change_failed(netdev, error); return; } @@ -3669,18 +3622,16 @@ static void netdev_mac_power_down_cb(int error, uint16_t type, if (error) { l_error("Error taking interface %u down for per-network MAC " "generation: %s", netdev->index, strerror(-error)); - netdev_mac_change_failed(netdev, req, error); + netdev_mac_change_failed(netdev, error); return; } - l_debug("Setting generated address on ifindex: %d to: "MAC, - netdev->index, MAC_STR(req->addr)); netdev->mac_change_cmd_id = l_rtnl_set_mac(rtnl, netdev->index, req->addr, true, netdev_mac_power_up_cb, req, netdev_mac_destroy); if (!netdev->mac_change_cmd_id) { - netdev_mac_change_failed(netdev, req, -EIO); + netdev_mac_change_failed(netdev, -EIO); return; } @@ -3713,6 +3664,8 @@ static int netdev_start_powered_mac_change(struct netdev *netdev) { struct rtnl_data *req; uint8_t new_addr[6]; + bool powered = wiphy_has_ext_feature(netdev->wiphy, + NL80211_EXT_FEATURE_POWERED_ADDR_CHANGE); /* No address set in handshake, use per-network MAC generation */ if (l_memeqzero(netdev->handshake->spa, ETH_ALEN)) @@ -3734,9 +3687,16 @@ static int netdev_start_powered_mac_change(struct netdev *netdev) req->ref++; memcpy(req->addr, new_addr, sizeof(req->addr)); - netdev->mac_change_cmd_id = l_rtnl_set_powered(rtnl, netdev->index, - false, netdev_mac_power_down_cb, - req, netdev_mac_destroy); + if (powered) + netdev->mac_change_cmd_id = l_rtnl_set_mac(rtnl, netdev->index, + req->addr, false, + netdev_mac_power_up_cb, req, + netdev_mac_destroy); + else + netdev->mac_change_cmd_id = l_rtnl_set_powered(rtnl, + netdev->index, false, + netdev_mac_power_down_cb, req, + netdev_mac_destroy); if (!netdev->mac_change_cmd_id) { l_free(req); @@ -3744,6 +3704,10 @@ static int netdev_start_powered_mac_change(struct netdev *netdev) return -EIO; } + l_debug("Setting generated address on ifindex: %d to: "MAC" (%s)", + netdev->index, MAC_STR(req->addr), + powered ? "powered" : "power-down"); + return 0; } @@ -4332,6 +4296,7 @@ static uint32_t netdev_send_action_framev(struct netdev *netdev, { uint32_t id; struct l_genl_msg *msg = nl80211_build_cmd_frame(netdev->index, + 0x00d0, netdev->addr, to, freq, iov, iov_len); @@ -4360,53 +4325,44 @@ static uint32_t netdev_send_action_frame(struct netdev *netdev, user_data); } -static void netdev_cmd_authenticate_ft_cb(struct l_genl_msg *msg, - void *user_data) +static void netdev_ft_frame_cb(struct l_genl_msg *msg, void *user_data) { - struct netdev *netdev = user_data; - - netdev->connect_cmd_id = 0; - if (l_genl_msg_get_error(msg) < 0) - netdev_connect_failed(netdev, - NETDEV_RESULT_AUTHENTICATION_FAILED, - MMPDU_STATUS_CODE_UNSPECIFIED); + l_debug("Failed to send FT-Frame"); } -static void netdev_ft_tx_authenticate(struct iovec *iov, - size_t iov_len, void *user_data) +static int netdev_tx_ft_frame(uint32_t ifindex, uint16_t frame_type, + uint32_t frequency, const uint8_t *dest, + struct iovec *iov, size_t iov_len) { - struct netdev *netdev = user_data; - struct l_genl_msg *cmd_authenticate; + struct netdev *netdev = netdev_find(ifindex); + struct l_genl_msg *msg = nl80211_build_cmd_frame(netdev->index, + frame_type, + netdev->addr, dest, + frequency, + iov, iov_len); - cmd_authenticate = netdev_build_cmd_authenticate(netdev, - NL80211_AUTHTYPE_FT); - l_genl_msg_append_attrv(cmd_authenticate, NL80211_ATTR_IE, iov, - iov_len); + /* + * Even though the kernel is doing offchannel for Authentication this + * flag is still required otherwise the kernel gives -EBUSY. + */ + l_genl_msg_append_attr(msg, NL80211_ATTR_OFFCHANNEL_TX_OK, 0, NULL); - netdev->connect_cmd_id = l_genl_family_send(nl80211, - cmd_authenticate, - netdev_cmd_authenticate_ft_cb, - netdev, NULL); - if (!netdev->connect_cmd_id) { - l_genl_msg_unref(cmd_authenticate); - goto restore_snonce; + if (!l_genl_family_send(nl80211, msg, netdev_ft_frame_cb, + netdev, NULL)) { + l_genl_msg_unref(msg); + return -EIO; } - return; - -restore_snonce: - memcpy(netdev->handshake->snonce, netdev->prev_snonce, 32); - - netdev_connect_failed(netdev, NETDEV_RESULT_AUTHENTICATION_FAILED, - MMPDU_STATUS_CODE_UNSPECIFIED); + return 0; } -static int netdev_ft_tx_associate(struct iovec *ft_iov, size_t n_ft_iov, - void *user_data) +static int netdev_ft_tx_associate(uint32_t ifindex, uint32_t freq, + const uint8_t *prev_bssid, + struct iovec *ft_iov, size_t n_ft_iov) { - struct netdev *netdev = user_data; - struct auth_proto *ap = netdev->ap; + struct netdev *netdev = netdev_find(ifindex); + struct netdev_handshake_state *nhs; struct handshake_state *hs = netdev->handshake; struct l_genl_msg *msg; struct iovec iov[64]; @@ -4415,61 +4371,16 @@ static int netdev_ft_tx_associate(struct iovec *ft_iov, size_t n_ft_iov, enum mpdu_management_subtype subtype = MPDU_MANAGEMENT_SUBTYPE_REASSOCIATION_REQUEST; - msg = netdev_build_cmd_associate_common(netdev); - - c_iov = netdev_populate_common_ies(netdev, hs, msg, iov, n_iov, c_iov); - - if (!L_WARN_ON(n_iov - c_iov < n_ft_iov)) { - memcpy(iov + c_iov, ft_iov, sizeof(*ft_iov) * n_ft_iov); - c_iov += n_ft_iov; - } - - mpdu_sort_ies(subtype, iov, c_iov); - - l_genl_msg_append_attr(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, - ap->prev_bssid); - l_genl_msg_append_attrv(msg, NL80211_ATTR_IE, iov, c_iov); - - netdev->connect_cmd_id = l_genl_family_send(nl80211, msg, - netdev_cmd_ft_reassociate_cb, - netdev, NULL); - if (!netdev->connect_cmd_id) { - l_genl_msg_unref(msg); - - return -EIO; - } - - return 0; -} - -static void prepare_ft(struct netdev *netdev, const struct scan_bss *target_bss) -{ - struct netdev_handshake_state *nhs; - /* - * We reuse the handshake_state object and reset what's needed. - * Could also create a new object and copy most of the state but - * we would end up doing more work. + * At this point there is no going back with FT so reset all the flags + * needed to associate with a new BSS. */ - memcpy(netdev->prev_snonce, netdev->handshake->snonce, 32); - - netdev->frequency = target_bss->frequency; - - handshake_state_set_authenticator_address(netdev->handshake, - target_bss->addr); - - if (target_bss->rsne) - handshake_state_set_authenticator_ie(netdev->handshake, - target_bss->rsne); - memcpy(netdev->handshake->mde + 2, target_bss->mde, 3); - + netdev->frequency = freq; netdev->handshake->active_tk_index = 0; netdev->associated = false; netdev->operational = false; netdev->in_ft = true; - handshake_state_set_chandef(netdev->handshake, NULL); - /* * Cancel commands that could be running because of EAPoL activity * like re-keying, this way the callbacks for those commands don't @@ -4507,31 +4418,32 @@ static void prepare_ft(struct netdev *netdev, const struct scan_bss *target_bss) eapol_sm_free(netdev->sm); netdev->sm = NULL; } -} -static void netdev_ft_over_ds_auth_failed(struct netdev_ft_over_ds_info *info, - uint16_t status) -{ - l_queue_remove(info->netdev->ft_ds_list, info); - ft_ds_info_free(&info->super); -} + msg = netdev_build_cmd_associate_common(netdev); -struct ft_ds_finder { - const uint8_t *spa; - const uint8_t *aa; -}; + c_iov = netdev_populate_common_ies(netdev, hs, msg, iov, n_iov, c_iov); -static bool match_ft_ds_info(const void *a, const void *b) -{ - const struct netdev_ft_over_ds_info *info = a; - const struct ft_ds_finder *finder = b; + if (!L_WARN_ON(n_iov - c_iov < n_ft_iov)) { + memcpy(iov + c_iov, ft_iov, sizeof(*ft_iov) * n_ft_iov); + c_iov += n_ft_iov; + } - if (memcmp(info->super.spa, finder->spa, 6)) - return false; - if (memcmp(info->super.aa, finder->aa, 6)) - return false; + mpdu_sort_ies(subtype, iov, c_iov); - return true; + l_genl_msg_append_attr(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, + prev_bssid); + l_genl_msg_append_attrv(msg, NL80211_ATTR_IE, iov, c_iov); + + netdev->connect_cmd_id = l_genl_family_send(nl80211, msg, + netdev_cmd_ft_reassociate_cb, + netdev, NULL); + if (!netdev->connect_cmd_id) { + l_genl_msg_unref(msg); + + return -EIO; + } + + return 0; } static void netdev_ft_response_frame_event(const struct mmpdu_header *hdr, @@ -4539,49 +4451,25 @@ static void netdev_ft_response_frame_event(const struct mmpdu_header *hdr, int rssi, void *user_data) { struct netdev *netdev = user_data; - struct netdev_ft_over_ds_info *info; - int ret; - uint16_t status_code = MMPDU_STATUS_CODE_UNSPECIFIED; - const uint8_t *aa; - const uint8_t *spa; - const uint8_t *ies; - size_t ies_len; - struct ft_ds_finder finder; if (!netdev->connected) return; - ret = ft_over_ds_parse_action_response(body, body_len, &spa, &aa, - &ies, &ies_len); - if (ret < 0) - return; + __ft_rx_action(netdev->index, (const uint8_t *)hdr, + mmpdu_header_len(hdr) + body_len); +} - finder.spa = spa; - finder.aa = aa; +static void netdev_ft_auth_response_frame_event(const struct mmpdu_header *hdr, + const void *body, size_t body_len, + int rssi, void *user_data) +{ + struct netdev *netdev = user_data; - info = l_queue_find(netdev->ft_ds_list, match_ft_ds_info, &finder); - if (!info) + if (!netdev->connected) return; - /* Lookup successful, now check the status code */ - if (ret > 0) { - status_code = (uint16_t)ret; - goto ft_error; - } - - if (!ft_over_ds_parse_action_ies(&info->super, netdev->handshake, - ies, ies_len)) - goto ft_error; - - info->parsed = true; - - return; - -ft_error: - l_debug("FT-over-DS to "MAC" failed (%d)", MAC_STR(info->super.aa), - status_code); - - netdev_ft_over_ds_auth_failed(info, status_code); + __ft_rx_authenticate(netdev->index, (const uint8_t *)hdr, + mmpdu_header_len(hdr) + body_len); } static void netdev_qos_map_frame_event(const struct mmpdu_header *hdr, @@ -4606,185 +4494,6 @@ static void netdev_qos_map_frame_event(const struct mmpdu_header *hdr, netdev_send_qos_map_set(netdev, body + 4, body_len - 4); } -static bool netdev_ft_work_ready(struct wiphy_radio_work_item *item) -{ - struct netdev *netdev = l_container_of(item, struct netdev, work); - - if (!auth_proto_start(netdev->ap)) { - /* Restore original nonce */ - memcpy(netdev->handshake->snonce, netdev->prev_snonce, 32); - - netdev_connect_failed(netdev, NETDEV_RESULT_ABORTED, - MMPDU_STATUS_CODE_UNSPECIFIED); - return true; - } - - return false; -} - -static const struct wiphy_radio_work_item_ops ft_work_ops = { - .do_work = netdev_ft_work_ready, -}; - -int netdev_fast_transition(struct netdev *netdev, - const struct scan_bss *target_bss, - const struct scan_bss *orig_bss, - netdev_connect_cb_t cb) -{ - if (!netdev->operational) - return -ENOTCONN; - - if (!netdev->handshake->mde || !target_bss->mde_present || - l_get_le16(netdev->handshake->mde + 2) != - l_get_le16(target_bss->mde)) - return -EINVAL; - - prepare_ft(netdev, target_bss); - - handshake_state_new_snonce(netdev->handshake); - - netdev->connect_cb = cb; - - netdev->ap = ft_over_air_sm_new(netdev->handshake, - netdev_ft_tx_authenticate, - netdev_ft_tx_associate, - netdev_get_oci, netdev); - memcpy(netdev->ap->prev_bssid, orig_bss->addr, ETH_ALEN); - - wiphy_radio_work_insert(netdev->wiphy, &netdev->work, - WIPHY_WORK_PRIORITY_CONNECT, &ft_work_ops); - - return 0; -} - -int netdev_fast_transition_over_ds(struct netdev *netdev, - const struct scan_bss *target_bss, - const struct scan_bss *orig_bss, - netdev_connect_cb_t cb) -{ - struct netdev_ft_over_ds_info *info; - struct ft_ds_finder finder; - - if (!netdev->operational) - return -ENOTCONN; - - if (!netdev->handshake->mde || !target_bss->mde_present || - l_get_le16(netdev->handshake->mde + 2) != - l_get_le16(target_bss->mde)) - return -EINVAL; - - finder.spa = netdev->addr; - finder.aa = target_bss->addr; - - info = l_queue_find(netdev->ft_ds_list, match_ft_ds_info, &finder); - - if (!info || !info->parsed) - return -ENOENT; - - prepare_ft(netdev, target_bss); - - ft_over_ds_prepare_handshake(&info->super, netdev->handshake); - - netdev->connect_cb = cb; - - netdev->ap = ft_over_ds_sm_new(netdev->handshake, - netdev_ft_tx_associate, - netdev); - memcpy(netdev->ap->prev_bssid, orig_bss->addr, ETH_ALEN); - - wiphy_radio_work_insert(netdev->wiphy, &netdev->work, - WIPHY_WORK_PRIORITY_CONNECT, &ft_work_ops); - - return 0; -} - -static void netdev_ft_request_cb(struct l_genl_msg *msg, void *user_data) -{ - struct netdev_ft_over_ds_info *info = user_data; - - if (l_genl_msg_get_error(msg) < 0) { - l_error("Could not send CMD_FRAME for FT-over-DS"); - netdev_ft_over_ds_auth_failed(info, - MMPDU_STATUS_CODE_UNSPECIFIED); - } -} - -static void netdev_ft_ds_info_free(struct ft_ds_info *ft) -{ - struct netdev_ft_over_ds_info *info = l_container_of(ft, - struct netdev_ft_over_ds_info, super); - - l_free(info); -} - -int netdev_fast_transition_over_ds_action(struct netdev *netdev, - const struct scan_bss *target_bss) -{ - struct netdev_ft_over_ds_info *info; - uint8_t ft_req[14]; - struct handshake_state *hs = netdev->handshake; - struct iovec iovs[5]; - uint8_t buf[512]; - size_t len; - - if (!netdev->operational) - return -ENOTCONN; - - if (!netdev->handshake->mde || !target_bss->mde_present || - l_get_le16(netdev->handshake->mde + 2) != - l_get_le16(target_bss->mde)) - return -EINVAL; - - l_debug(""); - - info = l_new(struct netdev_ft_over_ds_info, 1); - info->netdev = netdev; - - memcpy(info->super.spa, hs->spa, ETH_ALEN); - memcpy(info->super.aa, target_bss->addr, ETH_ALEN); - memcpy(info->super.mde, target_bss->mde, sizeof(info->super.mde)); - - if (target_bss->rsne) - info->super.authenticator_ie = l_memdup(target_bss->rsne, - target_bss->rsne[1] + 2); - - l_getrandom(info->super.snonce, 32); - info->super.free = netdev_ft_ds_info_free; - - ft_req[0] = 6; /* FT category */ - ft_req[1] = 1; /* FT Request action */ - memcpy(ft_req + 2, netdev->addr, 6); - memcpy(ft_req + 8, info->super.aa, 6); - - iovs[0].iov_base = ft_req; - iovs[0].iov_len = sizeof(ft_req); - - if (!ft_build_authenticate_ies(hs, false, info->super.snonce, - buf, &len)) - goto failed; - - iovs[1].iov_base = buf; - iovs[1].iov_len = len; - - iovs[2].iov_base = NULL; - - if (!netdev->ft_ds_list) - netdev->ft_ds_list = l_queue_new(); - - l_queue_push_head(netdev->ft_ds_list, info); - - netdev_send_action_framev(netdev, netdev->handshake->aa, iovs, 2, - netdev->frequency, - netdev_ft_request_cb, - info); - - return 0; - -failed: - l_free(info); - return -EIO; -} - static void netdev_preauth_cb(const uint8_t *pmk, void *user_data) { struct netdev_preauth_state *preauth = user_data; @@ -5465,6 +5174,20 @@ static void netdev_channel_switch_event(struct l_genl_msg *msg, &netdev->frequency, netdev->user_data); } +static void netdev_michael_mic_failure(struct l_genl_msg *msg, + struct netdev *netdev) +{ + uint8_t idx; + uint32_t type; + + if (nl80211_parse_attrs(msg, NL80211_ATTR_KEY_IDX, &idx, + NL80211_ATTR_KEY_TYPE, &type, + NL80211_ATTR_UNSPEC) < 0) + return; + + l_debug("ifindex=%u key_idx=%u type=%u", netdev->index, idx, type); +} + static void netdev_mlme_notify(struct l_genl_msg *msg, void *user_data) { struct netdev *netdev = NULL; @@ -5515,6 +5238,9 @@ static void netdev_mlme_notify(struct l_genl_msg *msg, void *user_data) case NL80211_CMD_DEL_STATION: netdev_station_event(msg, netdev, false); break; + case NL80211_CMD_MICHAEL_MIC_FAILURE: + netdev_michael_mic_failure(msg, netdev); + break; } } @@ -5811,6 +5537,7 @@ static void netdev_add_station_frame_watches(struct netdev *netdev) static const uint8_t action_sa_query_resp_prefix[2] = { 0x08, 0x01 }; static const uint8_t action_sa_query_req_prefix[2] = { 0x08, 0x00 }; static const uint8_t action_ft_response_prefix[] = { 0x06, 0x02 }; + static const uint8_t auth_ft_response_prefix[] = { 0x02, 0x00 }; static const uint8_t action_qos_map_prefix[] = { 0x01, 0x04 }; uint64_t wdev = netdev->wdev_id; @@ -5831,6 +5558,10 @@ static void netdev_add_station_frame_watches(struct netdev *netdev) sizeof(action_ft_response_prefix), netdev_ft_response_frame_event, netdev, NULL); + frame_watch_add(wdev, 0, 0x00b0, auth_ft_response_prefix, + sizeof(auth_ft_response_prefix), + netdev_ft_auth_response_frame_event, netdev, NULL); + if (wiphy_supports_qos_set_map(netdev->wiphy)) frame_watch_add(wdev, 0, 0x00d0, action_qos_map_prefix, sizeof(action_qos_map_prefix), @@ -6636,6 +6367,9 @@ static int netdev_init(void) __eapol_set_tx_packet_func(netdev_control_port_frame); __eapol_set_install_pmk_func(netdev_set_pmk); + __ft_set_tx_frame_func(netdev_tx_ft_frame); + __ft_set_tx_associate_func(netdev_ft_tx_associate); + unicast_watch = l_genl_add_unicast_watch(genl, NL80211_GENL_NAME, netdev_unicast_notify, NULL, NULL); @@ -6700,3 +6434,4 @@ IWD_MODULE(netdev, netdev_init, netdev_exit); IWD_MODULE_DEPENDS(netdev, eapol); IWD_MODULE_DEPENDS(netdev, frame_xchg); IWD_MODULE_DEPENDS(netdev, wiphy); +IWD_MODULE_DEPENDS(netdev, ft); diff --git a/src/netdev.h b/src/netdev.h @@ -50,6 +50,7 @@ enum netdev_event { NETDEV_EVENT_RSSI_THRESHOLD_HIGH, NETDEV_EVENT_RSSI_LEVEL_NOTIFY, NETDEV_EVENT_PACKET_LOSS_NOTIFY, + NETDEV_EVENT_FT_ROAMED, }; enum netdev_watch_event { @@ -165,16 +166,7 @@ int netdev_reassociate(struct netdev *netdev, struct handshake_state *hs, netdev_event_func_t event_filter, netdev_connect_cb_t cb, void *user_data); -int netdev_fast_transition(struct netdev *netdev, - const struct scan_bss *target_bss, - const struct scan_bss *orig_bss, - netdev_connect_cb_t cb); -int netdev_fast_transition_over_ds_action(struct netdev *netdev, - const struct scan_bss *target_bss); -int netdev_fast_transition_over_ds(struct netdev *netdev, - const struct scan_bss *target_bss, - const struct scan_bss *orig_bss, - netdev_connect_cb_t cb); + int netdev_preauthenticate(struct netdev *netdev, const struct scan_bss *target_bss, netdev_preauthenticate_cb_t cb, diff --git a/src/nl80211util.c b/src/nl80211util.c @@ -139,6 +139,17 @@ static bool extract_nested(const void *data, uint16_t len, void *o) return true; } +static bool extract_u8(const void *data, uint16_t len, void *o) +{ + uint8_t *out = o; + + if (len != 1) + return false; + + *out = l_get_u8(data); + return true; +} + static attr_handler handler_for_type(enum nl80211_attrs type) { switch (type) { @@ -146,6 +157,7 @@ static attr_handler handler_for_type(enum nl80211_attrs type) return extract_ifindex; case NL80211_ATTR_WIPHY: case NL80211_ATTR_IFTYPE: + case NL80211_ATTR_KEY_TYPE: return extract_uint32; case NL80211_ATTR_WDEV: case NL80211_ATTR_COOKIE: @@ -170,6 +182,8 @@ static attr_handler handler_for_type(enum nl80211_attrs type) return extract_iovec; case NL80211_ATTR_WIPHY_BANDS: return extract_nested; + case NL80211_ATTR_KEY_IDX: + return extract_u8; default: break; } @@ -431,6 +445,7 @@ const void *nl80211_parse_get_key_seq(struct l_genl_msg *msg) } struct l_genl_msg *nl80211_build_cmd_frame(uint32_t ifindex, + uint16_t frame_type, const uint8_t *addr, const uint8_t *to, uint32_t freq, @@ -439,18 +454,17 @@ struct l_genl_msg *nl80211_build_cmd_frame(uint32_t ifindex, { struct l_genl_msg *msg; struct iovec iovs[iov_len + 1]; - const uint16_t frame_type = 0x00d0; - uint8_t action_frame[24]; + uint8_t hdr[24]; - memset(action_frame, 0, 24); + memset(hdr, 0, 24); - l_put_le16(frame_type, action_frame + 0); - memcpy(action_frame + 4, to, 6); - memcpy(action_frame + 10, addr, 6); - memcpy(action_frame + 16, to, 6); + l_put_le16(frame_type, hdr + 0); + memcpy(hdr + 4, to, 6); + memcpy(hdr + 10, addr, 6); + memcpy(hdr + 16, to, 6); - iovs[0].iov_base = action_frame; - iovs[0].iov_len = sizeof(action_frame); + iovs[0].iov_base = hdr; + iovs[0].iov_len = sizeof(hdr); memcpy(iovs + 1, iov, sizeof(*iov) * iov_len); msg = l_genl_msg_new_sized(NL80211_CMD_FRAME, 128 + 512); diff --git a/src/nl80211util.h b/src/nl80211util.h @@ -49,6 +49,7 @@ 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_msg *nl80211_build_cmd_frame(uint32_t ifindex, + uint16_t frame_type, const uint8_t *addr, const uint8_t *to, uint32_t freq, diff --git a/src/offchannel.c b/src/offchannel.c @@ -150,9 +150,9 @@ static const struct wiphy_radio_work_item_ops offchannel_work_ops = { .destroy = offchannel_work_destroy, }; -uint32_t offchannel_start(uint64_t wdev_id, uint32_t freq, uint32_t duration, - offchannel_started_cb_t started, void *user_data, - offchannel_destroy_cb_t destroy) +uint32_t offchannel_start(uint64_t wdev_id, int priority, uint32_t freq, + uint32_t duration, offchannel_started_cb_t started, + void *user_data, offchannel_destroy_cb_t destroy) { struct offchannel_info *info = l_new(struct offchannel_info, 1); @@ -169,8 +169,7 @@ uint32_t offchannel_start(uint64_t wdev_id, uint32_t freq, uint32_t duration, info->error = -ECANCELED; return wiphy_radio_work_insert(wiphy_find_by_wdev(wdev_id), &info->work, - WIPHY_WORK_PRIORITY_OFFCHANNEL, - &offchannel_work_ops); + priority, &offchannel_work_ops); } void offchannel_cancel(uint64_t wdev_id, uint32_t id) diff --git a/src/offchannel.h b/src/offchannel.h @@ -23,7 +23,7 @@ typedef void (*offchannel_started_cb_t)(void *user_data); typedef void (*offchannel_destroy_cb_t)(int error, void *user_data); -uint32_t offchannel_start(uint64_t wdev_id, uint32_t freq, uint32_t duration, - offchannel_started_cb_t started, void *user_data, - offchannel_destroy_cb_t destroy); +uint32_t offchannel_start(uint64_t wdev_id, int priority, uint32_t freq, + uint32_t duration, offchannel_started_cb_t started, + void *user_data, offchannel_destroy_cb_t destroy); void offchannel_cancel(uint64_t wdev_id, uint32_t id); diff --git a/src/p2p.c b/src/p2p.c @@ -190,12 +190,6 @@ static const int channels_scan_2_4_other[] = { 2, 3, 4, 5, 7, 8, 9, 10 }; */ #define P2P_GO_INTENT 2 -enum { - FRAME_GROUP_DEFAULT = 0, - FRAME_GROUP_LISTEN, - FRAME_GROUP_CONNECT, -}; - static bool p2p_device_match(const void *a, const void *b) { const struct p2p_device *dev = a; @@ -722,7 +716,7 @@ static void p2p_connection_reset(struct p2p_device *dev) netdev_watch_remove(dev->conn_netdev_watch_id); - frame_watch_group_remove(dev->wdev_id, FRAME_GROUP_CONNECT); + frame_watch_group_remove(dev->wdev_id, FRAME_GROUP_P2P_CONNECT); frame_xchg_stop_wdev(dev->wdev_id); if (!dev->enabled || (dev->enabled && dev->start_stop_cmd_id)) { @@ -824,6 +818,7 @@ static void p2p_peer_frame_xchg(struct p2p_peer *peer, struct iovec *tx_body, static const struct frame_xchg_prefix p2p_frame_go_neg_req = { /* Management -> Public Action -> P2P -> GO Negotiation Request */ + .frame_type = 0x00d0, .data = (uint8_t []) { 0x04, 0x09, 0x50, 0x6f, 0x9a, 0x09, P2P_ACTION_GO_NEGOTIATION_REQ @@ -833,6 +828,7 @@ static const struct frame_xchg_prefix p2p_frame_go_neg_req = { static const struct frame_xchg_prefix p2p_frame_go_neg_resp = { /* Management -> Public Action -> P2P -> GO Negotiation Response */ + .frame_type = 0x00d0, .data = (uint8_t []) { 0x04, 0x09, 0x50, 0x6f, 0x9a, 0x09, P2P_ACTION_GO_NEGOTIATION_RESP @@ -842,6 +838,7 @@ static const struct frame_xchg_prefix p2p_frame_go_neg_resp = { static const struct frame_xchg_prefix p2p_frame_go_neg_confirm = { /* Management -> Public Action -> P2P -> GO Negotiation Confirm */ + .frame_type = 0x00d0, .data = (uint8_t []) { 0x04, 0x09, 0x50, 0x6f, 0x9a, 0x09, P2P_ACTION_GO_NEGOTIATION_CONFIRM @@ -851,6 +848,7 @@ static const struct frame_xchg_prefix p2p_frame_go_neg_confirm = { static const struct frame_xchg_prefix p2p_frame_pd_resp = { /* Management -> Public Action -> P2P -> Provision Discovery Response */ + .frame_type = 0x00d0, .data = (uint8_t []) { 0x04, 0x09, 0x50, 0x6f, 0x9a, 0x09, P2P_ACTION_PROVISION_DISCOVERY_RESP @@ -1279,6 +1277,9 @@ static void p2p_group_start(struct p2p_device *dev) /* Enable netconfig, set maximum usable DHCP lease time */ l_settings_set_uint(config, "IPv4", "LeaseTime", 0x7fffffff); + l_settings_set_string(config, "Security", "PairwiseCiphers", "CCMP"); + l_settings_set_string(config, "Security", "GroupCipher", "CCMP"); + dev->capability.group_caps |= P2P_GROUP_CAP_GO; dev->capability.group_caps |= P2P_GROUP_CAP_GROUP_FORMATION; dev->capability.group_caps |= P2P_GROUP_CAP_IP_ALLOCATION; @@ -2527,13 +2528,13 @@ respond: if (status == P2P_STATUS_SUCCESS) p2p_peer_frame_xchg(peer, iov, dev->addr, 0, 600, 0, true, - FRAME_GROUP_CONNECT, + FRAME_GROUP_P2P_CONNECT, p2p_go_negotiation_resp_done, &p2p_frame_go_neg_confirm, p2p_go_negotiation_confirm_cb, NULL); else p2p_peer_frame_xchg(peer, iov, dev->addr, 0, 0, 0, true, - FRAME_GROUP_CONNECT, + FRAME_GROUP_P2P_CONNECT, p2p_go_negotiation_resp_err_done, NULL); l_debug("GO Negotiation Response sent with status %i", status); @@ -2804,7 +2805,7 @@ static bool p2p_go_negotiation_resp_cb(const struct mmpdu_header *mpdu, iov[iov_len].iov_base = NULL; p2p_peer_frame_xchg(dev->conn_peer, iov, dev->conn_peer->device_addr, - 0, 0, 0, false, FRAME_GROUP_CONNECT, + 0, 0, 0, false, FRAME_GROUP_P2P_CONNECT, p2p_go_negotiation_confirm_done, NULL); l_free(confirm_body); @@ -2893,7 +2894,7 @@ static void p2p_start_go_negotiation(struct p2p_device *dev) p2p_peer_frame_xchg(dev->conn_peer, iov, dev->conn_peer->device_addr, 100, resp_timeout, 256, false, - FRAME_GROUP_CONNECT, + FRAME_GROUP_P2P_CONNECT, p2p_go_negotiation_req_done, &p2p_frame_go_neg_resp, p2p_go_negotiation_resp_cb, NULL); @@ -3035,7 +3036,7 @@ static void p2p_start_provision_discovery(struct p2p_device *dev) * sent to the P2P Device Address of the P2P Group Owner" */ p2p_peer_frame_xchg(dev->conn_peer, iov, dev->conn_peer->device_addr, - 200, 600, 8, false, FRAME_GROUP_CONNECT, + 200, 600, 8, false, FRAME_GROUP_P2P_CONNECT, p2p_provision_disc_req_done, &p2p_frame_pd_resp, p2p_provision_disc_resp_cb, NULL); @@ -4167,9 +4168,9 @@ static void p2p_device_discovery_start(struct p2p_device *dev) dev->listen_channel = channels_social[l_getrandom_uint32() % L_ARRAY_SIZE(channels_social)]; - frame_watch_add(dev->wdev_id, FRAME_GROUP_LISTEN, 0x0040, + frame_watch_add(dev->wdev_id, FRAME_GROUP_P2P_LISTEN, 0x0040, (uint8_t *) "", 0, p2p_device_probe_cb, dev, NULL); - frame_watch_add(dev->wdev_id, FRAME_GROUP_LISTEN, 0x00d0, + frame_watch_add(dev->wdev_id, FRAME_GROUP_P2P_LISTEN, 0x00d0, p2p_frame_go_neg_req.data, p2p_frame_go_neg_req.len, p2p_device_go_negotiation_req_cb, dev, NULL); @@ -4187,7 +4188,7 @@ static void p2p_device_discovery_stop(struct p2p_device *dev) l_timeout_remove(dev->scan_timeout); p2p_device_roc_cancel(dev); - frame_watch_group_remove(dev->wdev_id, FRAME_GROUP_LISTEN); + frame_watch_group_remove(dev->wdev_id, FRAME_GROUP_P2P_LISTEN); } static void p2p_device_enable_cb(struct l_genl_msg *msg, void *user_data) diff --git a/src/rrm.c b/src/rrm.c @@ -194,7 +194,7 @@ static bool rrm_send_response(struct rrm_state *rrm, iov.iov_base = (void *)frame; iov.iov_len = len; - msg = nl80211_build_cmd_frame(rrm->ifindex, own_addr, bss->addr, + msg = nl80211_build_cmd_frame(rrm->ifindex, 0x00d0, own_addr, bss->addr, bss->frequency, &iov, 1); if (!l_genl_family_send(nl80211, msg, rrm_send_response_cb, @@ -443,6 +443,9 @@ static void rrm_handle_beacon_scan(struct rrm_state *rrm, freq = band_channel_to_freq(beacon->channel, band); scan_freq_set_add(freqs, freq); + if (!wiphy_constrain_freq_set(wiphy_find_by_wdev(rrm->wdev_id), freqs)) + goto free_freqs; + if (passive) beacon->scan_id = scan_passive_full(rrm->wdev_id, &params, rrm_scan_triggered, @@ -454,12 +457,13 @@ static void rrm_handle_beacon_scan(struct rrm_state *rrm, rrm_scan_results, rrm, NULL); +free_freqs: scan_freq_set_free(freqs); - if (beacon->scan_id == 0) { - rrm_info_destroy(&beacon->info); - rrm->pending = NULL; - } + if (beacon->scan_id) + return; + + rrm_reject_measurement_request(rrm, REPORT_REJECT_INCAPABLE); } static bool rrm_verify_beacon_request(const uint8_t *request, size_t len) diff --git a/src/sae.c b/src/sae.c @@ -37,6 +37,9 @@ #include "src/mpdu.h" #include "src/auth-proto.h" #include "src/sae.h" +#include "src/module.h" + +static bool debug; /* SHA-512 is the highest supported hashing function as of 802.11-2020 */ #define SAE_MAX_HASH_LEN 64 @@ -45,6 +48,12 @@ #define SAE_SYNC_MAX 3 #define SAE_MAX_ASSOC_RETRY 3 +#define sae_debug(fmat, ...) \ +({ \ + if (debug) \ + l_info("[SAE]: "fmat, ##__VA_ARGS__); \ +}) + enum sae_state { SAE_STATE_NOTHING = 0, SAE_STATE_COMMITTED = 1, @@ -154,7 +163,7 @@ static int sae_choose_next_group(struct sae_sm *sm) return -ENOENT; } - l_debug("Forcing default SAE group 19"); + sae_debug("Forcing default SAE group 19"); sm->group_retry++; sm->group = 19; @@ -176,6 +185,8 @@ static int sae_choose_next_group(struct sae_sm *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); return 0; @@ -327,6 +338,9 @@ static int sae_reject(struct sae_sm *sm, uint16_t transaction, uint16_t status) ptr += 2; } + sae_debug("Rejecting exchange transaction=%u status=%u", + transaction, status); + sm->tx_auth(reject, ptr - reject, sm->user_data); return status; @@ -631,6 +645,9 @@ static bool sae_send_confirm(struct sae_sm *sm) memcpy(ptr, confirm, r); ptr += r; + sae_debug("Sending Confirm to "MAC" sc=%u", + MAC_STR(sm->handshake->aa), sm->sc); + sm->tx_auth(body, ptr - body, sm->user_data); return true; } @@ -827,6 +844,8 @@ 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); return 0; @@ -844,6 +863,8 @@ static bool sae_send_commit(struct sae_sm *sm, bool retry) if (r < 0) return false; + sae_debug("Sending Commit to "MAC, MAC_STR(hs->aa)); + sm->tx_auth(commit, r, sm->user_data); return true; @@ -858,6 +879,8 @@ static bool sae_assoc_timeout(struct auth_proto *ap) sm->assoc_retry++; + sae_debug("Retry Associate to "MAC, MAC_STR(sm->handshake->aa)); + sm->tx_assoc(sm->user_data); return true; @@ -921,6 +944,8 @@ static int sae_process_anti_clogging(struct sae_sm *sm, const uint8_t *ptr, return -EBADMSG; } + sae_debug("Processed anti-clogging token"); + l_free(sm->token); sm->token = l_memdup(ptr, len); sm->token_len = len; @@ -1036,6 +1061,9 @@ static int sae_verify_committed(struct sae_sm *sm, uint16_t transaction, goto reject_unsupp_group; } + sae_debug("AP rejected group, trying again with group %u", + sm->group); + sm->sync = 0; sae_send_commit(sm, false); @@ -1297,8 +1325,6 @@ static int sae_verify_packet(struct sae_sm *sm, uint16_t trans, uint16_t status, const uint8_t *frame, size_t len) { - l_debug("rx trans=%u, state=%s", trans, sae_state_to_str(sm->state)); - if (trans != SAE_STATE_COMMITTED && trans != SAE_STATE_CONFIRMED) return -EBADMSG; @@ -1324,16 +1350,23 @@ static int sae_rx_authenticate(struct auth_proto *ap, const struct mmpdu_header *hdr = (const struct mmpdu_header *) frame; const struct mmpdu_authentication *auth = mmpdu_body(hdr); int ret; + uint16_t transaction = L_LE16_TO_CPU(auth->transaction_sequence); + uint16_t status = L_LE16_TO_CPU(auth->status); + + sae_debug("Received frame transaction=%u status=%u state=%s", + transaction, status, sae_state_to_str(sm->state)); len -= mmpdu_header_len(hdr); - ret = sae_verify_packet(sm, L_LE16_TO_CPU(auth->transaction_sequence), - L_LE16_TO_CPU(auth->status), - auth->ies, len - 6); - if (ret != 0) + ret = sae_verify_packet(sm, transaction, status, auth->ies, len - 6); + if (ret != 0) { + if (ret < 0 && ret != -EAGAIN) + sae_debug("Frame did not verify (%s)", strerror(-ret)); + return ret; + } - switch (L_LE16_TO_CPU(auth->transaction_sequence)) { + switch (transaction) { case SAE_STATE_COMMITTED: return sae_process_commit(sm, hdr->address_2, auth->ies, len - 6); @@ -1341,8 +1374,7 @@ static int sae_rx_authenticate(struct auth_proto *ap, return sae_process_confirm(sm, hdr->address_2, auth->ies, len - 6); default: - l_error("invalid transaction sequence %u", - L_LE16_TO_CPU(auth->transaction_sequence)); + l_error("invalid transaction sequence %u", transaction); } /* should never get here */ @@ -1442,12 +1474,26 @@ struct auth_proto *sae_sm_new(struct handshake_state *hs, hs->authenticator_rsnxe; if (ie_rsnxe_capable(rsnxe, IE_RSNX_SAE_H2E) && hs->ecc_sae_pts) { - l_debug("Using SAE H2E"); + sae_debug("Using SAE H2E"); sm->sae_type = CRYPTO_SAE_HASH_TO_ELEMENT; } else { - l_debug("Using SAE Hunting and Pecking"); + sae_debug("Using SAE Hunting and Pecking"); sm->sae_type = CRYPTO_SAE_LOOPING; } return &sm->ap; } + +static int sae_init(void) +{ + if (getenv("IWD_SAE_DEBUG")) + debug = true; + + return 0; +} + +static void sae_exit(void) +{ +} + +IWD_MODULE(sae, sae_init, sae_exit); diff --git a/src/scan.c b/src/scan.c @@ -54,6 +54,7 @@ /* User configurable options */ static double RANK_5G_FACTOR; +static double RANK_6G_FACTOR; static uint32_t SCAN_MAX_INTERVAL; static uint32_t SCAN_INIT_INTERVAL; @@ -1645,10 +1646,14 @@ static void scan_bss_compute_rank(struct scan_bss *bss) rank = (double)bss->data_rate / max_rate * USHRT_MAX; - /* Prefer 5G/6G networks over 2.4G */ - if (bss->frequency > 4000) + /* Prefer 5G networks over 2.4G and 6G */ + if (bss->frequency >= 4900 && bss->frequency < 5900) rank *= RANK_5G_FACTOR; + /* Prefer 6G networks over 2.4G and 5G */ + if (bss->frequency >= 5900 && bss->frequency < 7200) + rank *= RANK_6G_FACTOR; + /* Rank loaded APs lower and lightly loaded APs higher */ if (bss->utilization >= 192) rank *= RANK_HIGH_UTILIZATION_FACTOR; @@ -2039,6 +2044,33 @@ static void scan_parse_result_frequencies(struct l_genl_msg *msg, } } +static void scan_retry_pending(uint32_t wiphy_id) +{ + const struct l_queue_entry *entry; + + l_debug(""); + + for (entry = l_queue_get_entries(scan_contexts); entry; + entry = entry->next) { + struct scan_context *sc = entry->data; + struct scan_request *sr = l_queue_peek_head(sc->requests); + + if (wiphy_get_id(sc->wiphy) != wiphy_id) + continue; + + if (!sr) + continue; + + if (!wiphy_radio_work_is_running(sc->wiphy, sr->work.id)) + continue; + + sc->state = SCAN_STATE_NOT_RUNNING; + start_next_scan_request(&sr->work); + + return; + } +} + static void scan_notify(struct l_genl_msg *msg, void *user_data) { struct l_genl_attr attr; @@ -2060,8 +2092,17 @@ static void scan_notify(struct l_genl_msg *msg, void *user_data) return; sc = l_queue_find(scan_contexts, scan_context_match, &wdev_id); - if (!sc) + if (!sc) { + /* + * If the event is for an unmanaged device, retry pending scan + * requests on the same wiphy. + */ + if (cmd == NL80211_CMD_NEW_SCAN_RESULTS || + cmd == NL80211_CMD_SCAN_ABORTED) + scan_retry_pending(wiphy_id); + return; + } l_debug("Scan notification %s(%u)", nl80211cmd_to_string(cmd), cmd); @@ -2343,6 +2384,10 @@ static int scan_init(void) &RANK_5G_FACTOR)) RANK_5G_FACTOR = 1.0; + if (!l_settings_get_double(config, "Rank", "BandModifier6Ghz", + &RANK_6G_FACTOR)) + RANK_6G_FACTOR = 1.0; + if (!l_settings_get_uint(config, "Scan", "InitialPeriodicScanInterval", &SCAN_INIT_INTERVAL)) SCAN_INIT_INTERVAL = 10; diff --git a/src/station.c b/src/station.c @@ -59,6 +59,10 @@ #include "src/frame-xchg.h" #include "src/sysfs.h" #include "src/band.h" +#include "src/ft.h" +#include "src/eap.h" +#include "src/eap-tls-common.h" +#include "src/storage.h" static struct l_queue *station_list; static uint32_t netdev_watch; @@ -68,6 +72,7 @@ static bool anqp_disabled; static bool supports_arp_evict_nocarrier; static bool supports_ndisc_evict_nocarrier; static struct watchlist event_watches; +static uint32_t known_networks_watch; struct station { enum station_state state; @@ -107,6 +112,7 @@ struct station { /* Set of frequencies to scan first when attempting a roam */ struct scan_freq_set *roam_freqs; + struct l_queue *roam_bss_list; /* Frequencies split into subsets by priority */ struct scan_freq_set *scan_freqs_order[3]; @@ -114,6 +120,8 @@ struct station { uint32_t wiphy_watch; + struct wiphy_radio_work_item ft_work; + bool preparing_roam : 1; bool roam_scan_full : 1; bool signal_low : 1; @@ -129,6 +137,39 @@ struct anqp_entry { uint32_t pending; }; +/* + * Used as entries for the roam list since holding scan_bss pointers directly + * from station->bss_list is not 100% safe due to the possibility of the + * hardware scanning and overwriting station->bss_list. + */ +struct roam_bss { + uint8_t addr[6]; + uint16_t rank; + int32_t signal_strength; +}; + +static struct roam_bss *roam_bss_from_scan_bss(const struct scan_bss *bss) +{ + struct roam_bss *rbss = l_new(struct roam_bss, 1); + + memcpy(rbss->addr, bss->addr, 6); + rbss->rank = bss->rank; + rbss->signal_strength = bss->signal_strength; + + return rbss; +} + +static int roam_bss_rank_compare(const void *a, const void *b, void *user_data) +{ + const struct roam_bss *new_bss = a, *bss = b; + + if (bss->rank == new_bss->rank) + return (bss->signal_strength > + new_bss->signal_strength) ? 1 : -1; + + return (bss->rank > new_bss->rank) ? 1 : -1; +} + struct wiphy *station_get_wiphy(struct station *station) { return station->wiphy; @@ -146,12 +187,9 @@ struct network *station_get_connected_network(struct station *station) bool station_is_busy(struct station *station) { - if (station->state != STATION_STATE_DISCONNECTED && + return station->state != STATION_STATE_DISCONNECTED && station->state != STATION_STATE_AUTOCONNECT_FULL && - station->state != STATION_STATE_AUTOCONNECT_QUICK) - return true; - - return false; + station->state != STATION_STATE_AUTOCONNECT_QUICK; } static bool station_is_autoconnecting(struct station *station) @@ -160,6 +198,13 @@ static bool station_is_autoconnecting(struct station *station) station->state == STATION_STATE_AUTOCONNECT_QUICK; } +static bool station_is_roaming(struct station *station) +{ + return station->state == STATION_STATE_ROAMING || + station->state == STATION_STATE_FT_ROAMING || + station->state == STATION_STATE_FW_ROAMING; +} + static bool station_debug_event(struct station *station, const char *name) { struct l_dbus_message *signal; @@ -1112,9 +1157,15 @@ build_ie: * seen that they do not include the OCI in the 4-way handshake yet * still advertise the capability. Because of this OCV is disabled if * any offload features are detected (since IWD prefers to use offload). + * + * TODO: For now OCV is disabled if the network is FT capable. This is + * being done until support in the kernel is added to + * automatically include the OCI element for the association + * request. */ info.ocvc = !disable_ocv && bss_info.ocvc && info.mfpc && - !wiphy_can_offload(wiphy); + !wiphy_can_offload(wiphy) && + !IE_AKM_IS_FT(info.akm_suites); /* * IEEE 802.11-2020 9.4.2.24.4 states extended key IDs can only be used @@ -1122,7 +1173,7 @@ build_ie: * also indicates support. */ if (wiphy_supports_ext_key_id(wiphy) && bss_info.extended_key_id && - info.pairwise_ciphers == IE_RSN_CIPHER_SUITE_CCMP) + IE_CIPHER_IS_GCMP_CCMP(info.pairwise_ciphers)) info.extended_key_id = true; /* RSN takes priority */ @@ -1420,6 +1471,10 @@ static const char *station_state_to_string(enum station_state state) return "disconnecting"; case STATION_STATE_ROAMING: return "roaming"; + case STATION_STATE_FT_ROAMING: + return "ft-roaming"; + case STATION_STATE_FW_ROAMING: + return "fw-roaming"; } return "invalid"; @@ -1566,6 +1621,8 @@ static void station_enter_state(struct station *station, case STATION_STATE_DISCONNECTING: break; case STATION_STATE_ROAMING: + case STATION_STATE_FT_ROAMING: + case STATION_STATE_FW_ROAMING: station_set_evict_nocarrier(station, false); break; } @@ -1644,6 +1701,10 @@ static void station_roam_state_clear(struct station *station) scan_freq_set_free(station->roam_freqs); station->roam_freqs = NULL; } + + l_queue_clear(station->roam_bss_list, l_free); + + ft_clear_authentications(netdev_get_ifindex(station->netdev)); } static void station_reset_connection_state(struct station *station) @@ -1689,7 +1750,7 @@ static void station_reset_connection_state(struct station *station) if (station->state == STATION_STATE_CONNECTED || station->state == STATION_STATE_CONNECTING || station->state == STATION_STATE_CONNECTING_AUTO || - station->state == STATION_STATE_ROAMING) + station_is_roaming(station)) network_disconnected(network); } @@ -1767,6 +1828,8 @@ static void parse_neighbor_report(struct station *station, struct handshake_state *hs = netdev_get_handshake(station->netdev); const struct scan_freq_set *supported = wiphy_get_supported_freqs(station->wiphy); + const struct scan_freq_set *disabled = + wiphy_get_disabled_freqs(station->wiphy); freq_set_md = scan_freq_set_new(); freq_set_no_md = scan_freq_set_new(); @@ -1803,8 +1866,9 @@ static void parse_neighbor_report(struct station *station, if (!(band & wiphy_get_supported_bands(station->wiphy))) continue; - /* Skip if frequency is not supported */ - if (!scan_freq_set_contains(supported, freq)) + /* Skip if frequency is not supported or disabled */ + if (!scan_freq_set_contains(supported, freq) || + scan_freq_set_contains(disabled, freq)) continue; if (!memcmp(info.addr, @@ -1959,7 +2023,8 @@ static void station_ft_ds_action_start(struct station *station) * Fire and forget. Netdev will maintain a cache of responses * and when the time comes these can be referenced for a roam */ - netdev_fast_transition_over_ds_action(station->netdev, bss); + ft_action(netdev_get_ifindex(station->netdev), + station->connected_bss->frequency, bss); } } @@ -1989,6 +2054,8 @@ static void station_roamed(struct station *station) l_warn("Could not request neighbor report"); } + l_queue_clear(station->roam_bss_list, l_free); + station_ft_ds_action_start(station); station_enter_state(station, STATION_STATE_CONNECTED); @@ -2013,11 +2080,13 @@ static void station_roam_failed(struct station *station) { l_debug("%u", netdev_get_ifindex(station->netdev)); + l_queue_clear(station->roam_bss_list, l_free); + /* * If we attempted a reassociation or a fast transition, and ended up * here then we are now disconnected. */ - if (station->state == STATION_STATE_ROAMING) { + if (station_is_roaming(station)) { station_disassociated(station); return; } @@ -2050,6 +2119,30 @@ delayed_retry: station_roam_retry(station); } +static void station_disconnect_on_error_cb(struct netdev *netdev, bool success, + void *user_data) +{ + struct station *station = user_data; + bool continue_autoconnect; + + station_enter_state(station, STATION_STATE_DISCONNECTED); + + continue_autoconnect = station->state == STATION_STATE_CONNECTING_AUTO; + + if (continue_autoconnect) { + if (station_autoconnect_next(station) < 0) { + l_debug("Nothing left on autoconnect list"); + station_enter_state(station, + STATION_STATE_AUTOCONNECT_FULL); + } + + return; + } + + if (station->autoconnect) + station_enter_state(station, STATION_STATE_AUTOCONNECT_QUICK); +} + static void station_netconfig_event_handler(enum netconfig_event event, void *user_data) { @@ -2058,7 +2151,26 @@ static void station_netconfig_event_handler(enum netconfig_event event, switch (event) { case NETCONFIG_EVENT_CONNECTED: station_enter_state(station, STATION_STATE_CONNECTED); + break; + case NETCONFIG_EVENT_FAILED: + if (station->connect_pending) { + struct l_dbus_message *reply = dbus_error_failed( + station->connect_pending); + + dbus_pending_reply(&station->connect_pending, reply); + } + + if (L_IN_SET(station->state, STATION_STATE_CONNECTING, + STATION_STATE_CONNECTING_AUTO)) + network_connect_failed(station->connected_network, + false); + netdev_disconnect(station->netdev, + station_disconnect_on_error_cb, + station); + station_reset_connection_state(station); + + station_enter_state(station, STATION_STATE_DISCONNECTING); break; default: l_error("station: Unsupported netconfig event: %d.", event); @@ -2084,42 +2196,26 @@ static void station_reassociate_cb(struct netdev *netdev, station_roam_failed(station); } -static void station_fast_transition_cb(struct netdev *netdev, - enum netdev_result result, - void *event_data, - void *user_data) -{ - struct station *station = user_data; - - l_debug("%u, result: %d", netdev_get_ifindex(station->netdev), result); - - if (station->state != STATION_STATE_ROAMING) - return; - - if (result == NETDEV_RESULT_OK) - station_roamed(station); - else - station_roam_failed(station); -} - static void station_netdev_event(struct netdev *netdev, enum netdev_event event, void *event_data, void *user_data); -static void station_transition_reassociate(struct station *station, +static int station_transition_reassociate(struct station *station, struct scan_bss *bss, struct handshake_state *new_hs) { - if (netdev_reassociate(station->netdev, bss, station->connected_bss, + int ret; + + ret = netdev_reassociate(station->netdev, bss, station->connected_bss, new_hs, station_netdev_event, - station_reassociate_cb, station) < 0) { - handshake_state_free(new_hs); - station_roam_failed(station); - return; - } + station_reassociate_cb, station); + if (ret < 0) + return ret; station->connected_bss = bss; station->preparing_roam = false; station_enter_state(station, STATION_STATE_ROAMING); + + return 0; } static bool bss_match_bssid(const void *a, const void *b) @@ -2144,8 +2240,8 @@ static void station_preauthenticate_cb(struct netdev *netdev, if (!station->preparing_roam || result == NETDEV_RESULT_ABORTED) return; - bss = l_queue_find(station->bss_list, bss_match_bssid, - station->preauth_bssid); + bss = network_bss_find_by_addr(station->connected_network, + station->preauth_bssid); if (!bss) { l_error("Roam target BSS not found"); station_roam_failed(station); @@ -2191,18 +2287,109 @@ static void station_preauthenticate_cb(struct netdev *netdev, handshake_state_set_supplicant_ie(new_hs, rsne_buf); } - station_transition_reassociate(station, bss, new_hs); + if (station_transition_reassociate(station, bss, new_hs) < 0) { + handshake_state_free(new_hs); + station_roam_failed(station); + } } -static void station_transition_start(struct station *station, - struct scan_bss *bss) +static void station_transition_start(struct station *station); + +static bool station_ft_work_ready(struct wiphy_radio_work_item *item) +{ + struct station *station = l_container_of(item, struct station, ft_work); + struct roam_bss *rbss = l_queue_pop_head(station->roam_bss_list); + struct scan_bss *bss = network_bss_find_by_addr( + station->connected_network, rbss->addr); + int ret; + + l_free(rbss); + + /* Very unlikely, but the BSS could have gone away */ + if (!bss) + goto try_next; + + ret = ft_associate(netdev_get_ifindex(station->netdev), bss->addr); + if (ret == -ENOENT) { + station_debug_event(station, "ft-over-air-roam-failed"); +try_next: + station_transition_start(station); + return true; + } else if (ret < 0) + goto assoc_failed; + + station->connected_bss = bss; + station->preparing_roam = false; + station_enter_state(station, STATION_STATE_FT_ROAMING); + + return true; + +assoc_failed: + station_roam_failed(station); + return true; +} + +static const struct wiphy_radio_work_item_ops ft_work_ops = { + .do_work = station_ft_work_ready, +}; + +static bool station_fast_transition(struct station *station, + struct scan_bss *bss) +{ + struct handshake_state *hs = netdev_get_handshake(station->netdev); + struct network *connected = station->connected_network; + const struct network_info *info = network_get_info(connected); + const struct iovec *vendor_ies; + size_t iov_elems = 0; + int ret; + + /* Rebuild handshake RSN for target AP */ + if (station_build_handshake_rsn(hs, station->wiphy, + station->connected_network, bss) < 0) + return false; + + /* Reset the vendor_ies in case they're different */ + vendor_ies = network_info_get_extra_ies(info, bss, &iov_elems); + handshake_state_set_vendor_ies(hs, vendor_ies, iov_elems); + + if ((hs->mde[4] & 1)) { + ret = ft_associate(netdev_get_ifindex(station->netdev), + bss->addr); + /* No action responses from this BSS, try over air */ + if (ret == -ENOENT) { + station_debug_event(station, "try-ft-over-air"); + goto try_over_air; + } else if (ret < 0) + return false; + + station->connected_bss = bss; + station->preparing_roam = false; + station_enter_state(station, STATION_STATE_FT_ROAMING); + + return true; + } else { +try_over_air: + /* + * Send FT-Authenticate and insert a work item which will be + * gated until authentication completes + */ + ft_authenticate(netdev_get_ifindex(station->netdev), bss); + + wiphy_radio_work_insert(station->wiphy, &station->ft_work, + WIPHY_WORK_PRIORITY_CONNECT, &ft_work_ops); + + return true; + } +} + +static bool station_try_next_transition(struct station *station, + struct scan_bss *bss) { struct handshake_state *hs = netdev_get_handshake(station->netdev); struct network *connected = station->connected_network; enum security security = network_get_security(connected); struct handshake_state *new_hs; struct ie_rsn_info cur_rsne, target_rsne; - int ret; l_debug("%u, target %s", netdev_get_ifindex(station->netdev), util_address_to_string(bss->addr)); @@ -2211,54 +2398,8 @@ static void station_transition_start(struct station *station, station->ap_directed_roaming = false; /* Can we use Fast Transition? */ - if (station_can_fast_transition(hs, bss)) { - const struct network_info *info = network_get_info(connected); - const struct iovec *vendor_ies; - size_t iov_elems = 0; - - /* Rebuild handshake RSN for target AP */ - if (station_build_handshake_rsn(hs, station->wiphy, - station->connected_network, bss) < 0) { - l_error("rebuilding handshake rsne failed"); - station_roam_failed(station); - return; - } - - /* Reset the vendor_ies in case they're different */ - vendor_ies = network_info_get_extra_ies(info, bss, &iov_elems); - handshake_state_set_vendor_ies(hs, vendor_ies, iov_elems); - - if ((hs->mde[4] & 1)) { - ret = netdev_fast_transition_over_ds(station->netdev, - bss, station->connected_bss, - station_fast_transition_cb); - /* No action responses from this BSS, try over air */ - if (ret == -ENOENT) - goto try_over_air; - else if (ret < 0) { - /* - * If we are here FT-over-air will not work - * either (identical checks) so try again later. - */ - station_roam_retry(station); - return; - } - } else { -try_over_air: - if (netdev_fast_transition(station->netdev, bss, - station->connected_bss, - station_fast_transition_cb) < 0) { - station_roam_failed(station); - return; - } - } - - station->connected_bss = bss; - station->preparing_roam = false; - station_enter_state(station, STATION_STATE_ROAMING); - - return; - } + if (station_can_fast_transition(hs, bss)) + return station_fast_transition(station, bss); /* Non-FT transition */ @@ -2288,17 +2429,46 @@ try_over_air: if (netdev_preauthenticate(station->netdev, bss, station_preauthenticate_cb, station) >= 0) - return; + return true; } new_hs = station_handshake_setup(station, connected, bss); if (!new_hs) { l_error("station_handshake_setup failed in reassociation"); - station_roam_failed(station); - return; + return false; + } + + if (station_transition_reassociate(station, bss, new_hs) < 0) { + handshake_state_free(new_hs); + return false; + } + + return true; +} + +static void station_transition_start(struct station *station) +{ + struct roam_bss *rbss; + bool roaming = false; + + /* + * For each failed attempt pop the BSS leaving the head of the queue + * with the current roam candidate. + */ + while ((rbss = l_queue_peek_head(station->roam_bss_list))) { + struct scan_bss *bss = network_bss_find_by_addr( + station->connected_network, rbss->addr); + + roaming = station_try_next_transition(station, bss); + if (roaming) + break; + + l_queue_pop_head(station->roam_bss_list); + l_free(rbss); } - station_transition_reassociate(station, bss, new_hs); + if (!roaming) + station_roam_failed(station); } static void station_roam_scan_triggered(int err, void *user_data) @@ -2318,6 +2488,20 @@ static void station_roam_scan_triggered(int err, void *user_data) */ } +static void station_update_roam_bss(struct station *station, + struct scan_bss *bss) +{ + struct network *network = station->connected_network; + struct scan_bss *old = + l_queue_remove_if(station->bss_list, bss_match, bss); + + network_bss_update(network, bss); + l_queue_push_tail(station->bss_list, bss); + + if (old) + scan_bss_free(old); +} + static bool station_roam_scan_notify(int err, struct l_queue *bss_list, const struct scan_freq_set *freqs, void *userdata) @@ -2327,12 +2511,10 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list, struct handshake_state *hs = netdev_get_handshake(station->netdev); struct scan_bss *current_bss = station->connected_bss; struct scan_bss *bss; - struct scan_bss *best_bss = NULL; - double best_bss_rank = 0.0; + double cur_bss_rank = 0.0; static const double RANK_FT_FACTOR = 1.3; uint16_t mdid; enum security orig_security, security; - bool seen = false; if (err) { station_roam_failed(station); @@ -2352,6 +2534,19 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list, &mdid, NULL, NULL); /* + * Find the current BSS rank, use the updated result if it exists. If + * this is an AP roam keep the current rank as zero to force the roam + * to occur. + */ + bss = l_queue_find(bss_list, bss_match_bssid, current_bss->addr); + if (bss && !station->ap_directed_roaming) { + cur_bss_rank = bss->rank; + + if (hs->mde && bss->mde_present && l_get_le16(bss->mde) == mdid) + cur_bss_rank *= RANK_FT_FACTOR; + } + + /* * BSSes in the bss_list come already ranked with their initial * association preference rank value. We only need to add preference * for BSSes that are within the FT Mobility Domain so as to favor @@ -2364,6 +2559,7 @@ 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", @@ -2372,9 +2568,8 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list, bss->frequency, bss->rank, bss->signal_strength, kbps100 / 10, kbps100 % 10); - /* Skip the BSS we are connected to if doing an AP roam */ - if (station->ap_directed_roaming && !memcmp(bss->addr, - station->connected_bss->addr, 6)) + /* Skip the BSS we are connected to */ + if (!memcmp(bss->addr, station->connected_bss->addr, 6)) goto next; /* Skip result if it is not part of the ESS */ @@ -2388,8 +2583,6 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list, if (security != orig_security) goto next; - seen = true; - if (network_can_connect_bss(network, bss) < 0) goto next; @@ -2401,15 +2594,21 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list, if (hs->mde && bss->mde_present && l_get_le16(bss->mde) == mdid) rank *= RANK_FT_FACTOR; - if (rank > best_bss_rank) { - if (best_bss) - scan_bss_free(best_bss); + if (rank <= cur_bss_rank) + goto next; - best_bss = bss; - best_bss_rank = rank; + /* + * We need to update/add any potential roam candidate so + * station/network know it exists. + */ + station_update_roam_bss(station, bss); - continue; - } + rbss = roam_bss_from_scan_bss(bss); + + l_queue_insert(station->roam_bss_list, rbss, + roam_bss_rank_compare, NULL); + + continue; next: scan_bss_free(bss); @@ -2417,36 +2616,17 @@ next: l_queue_destroy(bss_list, NULL); - if (!seen) - goto fail_free_bss; - /* See if we have anywhere to roam to */ - if (!best_bss || scan_bss_addr_eq(best_bss, station->connected_bss)) { + if (l_queue_isempty(station->roam_bss_list)) { station_debug_event(station, "no-roam-candidates"); - goto fail_free_bss; + goto fail; } - bss = network_bss_find_by_addr(network, best_bss->addr); - if (bss) { - network_bss_update(network, best_bss); - l_queue_remove(station->bss_list, bss); - scan_bss_free(bss); - - l_queue_insert(station->bss_list, best_bss, - scan_bss_rank_compare, NULL); - } else { - network_bss_add(network, best_bss); - l_queue_push_tail(station->bss_list, best_bss); - } - - station_transition_start(station, best_bss); + station_transition_start(station); return true; -fail_free_bss: - if (best_bss) - scan_bss_free(best_bss); - +fail: station_roam_failed(station); return true; @@ -2494,12 +2674,17 @@ static int station_roam_scan_known_freqs(struct station *station) station->connected_network); struct scan_freq_set *freqs = network_info_get_roam_frequencies(info, station->connected_bss->frequency, 5); - int r; + int r = -ENODATA; if (!freqs) - return -ENODATA; + return r; + + if (!wiphy_constrain_freq_set(station->wiphy, freqs)) + goto free_set; r = station_roam_scan(station, freqs); + +free_set: scan_freq_set_free(freqs); return r; } @@ -2638,10 +2823,12 @@ static bool station_cannot_roam(struct station *station) disabled = false; return disabled || station->preparing_roam || - station->state == STATION_STATE_ROAMING; + station->state == STATION_STATE_ROAMING || + station->state == STATION_STATE_FT_ROAMING; } #define WNM_REQUEST_MODE_PREFERRED_CANDIDATE_LIST (1 << 0) +#define WNM_REQUEST_MODE_DISASSOCIATION_IMMINENT (1 << 2) #define WNM_REQUEST_MODE_TERMINATION_IMMINENT (1 << 3) #define WNM_REQUEST_MODE_ESS_DISASSOCIATION_IMMINENT (1 << 4) @@ -2659,6 +2846,31 @@ static void station_ap_directed_roam(struct station *station, if (station_cannot_roam(station)) return; + if (station->state != STATION_STATE_CONNECTED) { + l_debug("roam: unexpected AP directed roam -- ignore"); + return; + } + + /* + * Sanitize the frame to check that it is from our current AP. + * + * 802.11-2020 Section 9.3.3.1 about Address2: + * "If the STA is an AP with dot11MultiBSSDImplemented set to false, + * then this address is the BSSID." + * + * Address3: + * "If the STA is an AP or PCP, the Address 3 field is the same as the + * Address 2 field." + * + * For now check that Address2 & Address3 is the same as the connected + * BSS address. + */ + if (memcmp(hdr->address_2, station->connected_bss, ETH_ALEN) || + memcmp(hdr->address_2, hdr->address_3, ETH_ALEN)) { + l_debug("roam: AP directed roam not from our AP -- ignore"); + return; + } + if (body_len < 7) goto format_error; @@ -2689,7 +2901,20 @@ static void station_ap_directed_roam(struct station *station, dtimer, valid_interval, MAC_STR(hdr->address_3)); - /* check req_mode for optional values */ + /* + * The ap_directed_roaming flag forces IWD to roam if there are any + * candidates, even if they are worse than the current BSS. This isn't + * always a good idea since we may be associated to the best BSS. Where + * this does matter is if the AP indicates its going down or will be + * disassociating us. If either of these bits are set, set the + * ap_directed_roaming flag. Otherwise still try roaming but don't + * treat it any different than a normal roam. + */ + if (req_mode & (WNM_REQUEST_MODE_DISASSOCIATION_IMMINENT | + WNM_REQUEST_MODE_TERMINATION_IMMINENT | + WNM_REQUEST_MODE_ESS_DISASSOCIATION_IMMINENT)) + station->ap_directed_roaming = true; + if (req_mode & WNM_REQUEST_MODE_TERMINATION_IMMINENT) { if (pos + 12 > body_len) goto format_error; @@ -2712,37 +2937,6 @@ static void station_ap_directed_roam(struct station *station, pos += url_len; } - if (station->state != STATION_STATE_CONNECTED) { - l_debug("roam: unexpected AP directed roam -- ignore"); - return; - } - - /* - * Sanitize the frame to check that it is from our current AP. - * - * 802.11-2020 Section 9.3.3.1 about Address2: - * "If the STA is an AP with dot11MultiBSSDImplemented set to false, - * then this address is the BSSID." - * - * Address3: - * "If the STA is an AP or PCP, the Address 3 field is the same as the - * Address 2 field." - * - * For now check that Address2 & Address3 is the same as the connected - * BSS address. - */ - if (memcmp(hdr->address_2, station->connected_bss, ETH_ALEN) || - memcmp(hdr->address_2, hdr->address_3, ETH_ALEN)) { - l_debug("roam: AP directed roam not from our AP -- ignore"); - return; - } - - if (station->preparing_roam) { - l_debug("roam: roam attempt already in progress -- ignore"); - return; - } - - station->ap_directed_roaming = true; station->preparing_roam = true; l_timeout_remove(station->roam_trigger_timeout); @@ -2794,8 +2988,7 @@ static void station_event_roamed(struct station *station, struct scan_bss *new) network_bss_update(station->connected_network, new); /* Remove new BSS if it exists in past scan results */ - stale = l_queue_remove_if(station->bss_list, bss_match_bssid, - new->addr); + stale = l_queue_remove_if(station->bss_list, bss_match, new); if (stale) scan_bss_free(stale); @@ -3069,6 +3262,8 @@ static void station_disconnect_event(struct station *station, void *event_data) event_data, station); return; case STATION_STATE_CONNECTED: + case STATION_STATE_FT_ROAMING: + case STATION_STATE_FW_ROAMING: station_disassociated(station); return; default: @@ -3122,7 +3317,7 @@ static void station_netdev_event(struct netdev *netdev, enum netdev_event event, station_signal_agent_notify(station); break; case NETDEV_EVENT_ROAMING: - station_enter_state(station, STATION_STATE_ROAMING); + station_enter_state(station, STATION_STATE_FW_ROAMING); break; case NETDEV_EVENT_ROAMED: station_event_roamed(station, (struct scan_bss *) event_data); @@ -3133,6 +3328,12 @@ static void station_netdev_event(struct netdev *netdev, enum netdev_event event, case NETDEV_EVENT_PACKET_LOSS_NOTIFY: station_packets_lost(station, l_get_u32(event_data)); break; + case NETDEV_EVENT_FT_ROAMED: + if (L_WARN_ON(station->state != STATION_STATE_FT_ROAMING)) + return; + + station_roamed(station); + break; } } @@ -3965,6 +4166,8 @@ static bool station_property_get_state(struct l_dbus *dbus, statestr = "disconnecting"; break; case STATION_STATE_ROAMING: + case STATION_STATE_FT_ROAMING: + case STATION_STATE_FW_ROAMING: statestr = "roaming"; break; } @@ -4180,6 +4383,8 @@ static struct station *station_create(struct netdev *netdev) station_set_autoconnect(station, autoconnect); + station->roam_bss_list = l_queue_new(); + return station; } @@ -4269,6 +4474,8 @@ static void station_free(struct station *station) wiphy_state_watch_remove(station->wiphy, station->wiphy_watch); + l_queue_destroy(station->roam_bss_list, l_free); + l_free(station); } @@ -4339,6 +4546,21 @@ static void station_get_diagnostic_cb( diagnostic_akm_suite_to_security(hs->akm_suite, hs->wpa_ie)); + if (hs->pairwise_cipher) { + const char *str; + + if (hs->pairwise_cipher == + IE_RSN_CIPHER_SUITE_USE_GROUP_CIPHER) + str = ie_rsn_cipher_suite_to_string(hs->group_cipher); + else + str = ie_rsn_cipher_suite_to_string( + hs->pairwise_cipher); + + if (str) + dbus_append_dict_basic(builder, "PairwiseCipher", + 's', str); + } + diagnostic_info_to_dict(info, builder); l_dbus_message_builder_leave_array(builder); @@ -4381,6 +4603,72 @@ static struct l_dbus_message *station_get_diagnostics(struct l_dbus *dbus, return NULL; } +struct station_roam_data { + struct station *station; + struct l_dbus_message *pending; + uint8_t bssid[6]; +}; + +static void station_force_roam_scan_triggered(int err, void *user_data) +{ + struct station_roam_data *data = user_data; + struct station *station = data->station; + + if (err) + station_roam_failed(station); +} + +static bool station_force_roam_scan_notify(int err, struct l_queue *bss_list, + const struct scan_freq_set *freqs, + void *user_data) +{ + struct station_roam_data *data = user_data; + struct station *station = data->station; + struct scan_bss *target; + struct l_dbus_message *reply; + + if (err) { + reply = dbus_error_from_errno(err, data->pending); + goto reply; + } + + target = l_queue_remove_if(bss_list, bss_match_bssid, data->bssid); + if (!target) { + reply = dbus_error_not_found(data->pending); + goto reply; + } + + l_debug("Attempting forced roam to BSS "MAC, MAC_STR(target->addr)); + + /* The various roam routines expect this to be set from scanning */ + station->preparing_roam = true; + l_queue_push_tail(station->roam_bss_list, + roam_bss_from_scan_bss(target)); + + station_update_roam_bss(station, target); + + station_transition_start(station); + + reply = l_dbus_message_new_method_return(data->pending); + +reply: + dbus_pending_reply(&data->pending, reply); + + return false; +} + +static void station_force_roam_scan_destroy(void *user_data) +{ + struct station_roam_data *data = user_data; + + data->station->roam_scan_id = 0; + + if (data->pending) + l_dbus_message_unref(data->pending); + + l_free(data); +} + static struct l_dbus_message *station_force_roam(struct l_dbus *dbus, struct l_dbus_message *message, void *user_data) @@ -4390,6 +4678,9 @@ static struct l_dbus_message *station_force_roam(struct l_dbus *dbus, struct l_dbus_message_iter iter; uint8_t *mac; uint32_t mac_len; + struct scan_parameters params = { 0 }; + struct scan_freq_set *freqs = NULL; + struct station_roam_data *data; if (!l_dbus_message_get_arguments(message, "ay", &iter)) goto invalid_args; @@ -4404,8 +4695,11 @@ static struct l_dbus_message *station_force_roam(struct l_dbus *dbus, return dbus_error_not_connected(message); target = network_bss_find_by_addr(station->connected_network, mac); - if (!target || target == station->connected_bss) - return dbus_error_invalid_args(message); + if (!target) + goto full_scan; + + if (target && target == station->connected_bss) + return dbus_error_already_exists(message); if (station->connected_bss->ssid_len != target->ssid_len) goto invalid_args; @@ -4414,14 +4708,45 @@ static struct l_dbus_message *station_force_roam(struct l_dbus *dbus, target->ssid_len)) goto invalid_args; - l_debug("Attempting forced roam to BSS "MAC, MAC_STR(mac)); + /* + * Always scan before a roam to ensure the kernel has the BSS in its + * cache. If we already see the BSS only scan that frequency + */ + freqs = scan_freq_set_new(); + scan_freq_set_add(freqs, target->frequency); - /* The various roam routines expect this to be set from scanning */ - station->preparing_roam = true; + params.freqs = freqs; - station_transition_start(station, target); +full_scan: + params.flush = true; - return l_dbus_message_new_method_return(message); + data = l_new(struct station_roam_data, 1); + data->station = station; + data->pending = l_dbus_message_ref(message); + memcpy(data->bssid, mac, 6); + + station->roam_scan_id = scan_active_full( + netdev_get_wdev_id(station->netdev), + &params, + station_force_roam_scan_triggered, + station_force_roam_scan_notify, data, + station_force_roam_scan_destroy); + + if (freqs) + scan_freq_set_free(freqs); + + if (!station->roam_scan_id) { + l_free(data); + return dbus_error_failed(message); + } + + if (freqs) + l_debug("Scanning on %u for BSS "MAC, target->frequency, + MAC_STR(mac)); + else + l_debug("Full scan for BSS "MAC, MAC_STR(mac)); + + return NULL; invalid_args: return dbus_error_invalid_args(message); @@ -4802,6 +5127,22 @@ static void station_netdev_watch(struct netdev *netdev, } } +static void station_known_networks_changed(enum known_networks_event event, + const struct network_info *info, + void *user_data) +{ + _auto_(l_free) char *network_id = NULL; + + if (event != KNOWN_NETWORKS_EVENT_REMOVED) + return; + + if (info->type != SECURITY_8021X) + return; + + network_id = l_util_hexstring(info->ssid, strlen(info->ssid)); + eap_tls_forget_peer(network_id); +} + static int station_init(void) { station_list = l_queue_new(); @@ -4856,6 +5197,12 @@ static int station_init(void) watchlist_init(&event_watches, NULL); + eap_tls_set_session_cache_ops(storage_eap_tls_cache_load, + storage_eap_tls_cache_sync); + known_networks_watch = known_networks_watch_add( + station_known_networks_changed, + NULL, NULL); + return 0; } @@ -4873,9 +5220,12 @@ static void station_exit(void) l_queue_destroy(station_list, NULL); station_list = NULL; watchlist_destroy(&event_watches); + known_networks_watch_remove(known_networks_watch); + known_networks_watch = 0; } IWD_MODULE(station, station_init, station_exit) +IWD_MODULE_DEPENDS(station, known_networks) IWD_MODULE_DEPENDS(station, netdev); IWD_MODULE_DEPENDS(station, netconfig); IWD_MODULE_DEPENDS(station, frame_xchg); diff --git a/src/station.h b/src/station.h @@ -42,7 +42,9 @@ enum station_state { STATION_STATE_CONNECTING_AUTO, STATION_STATE_CONNECTED, STATION_STATE_DISCONNECTING, - STATION_STATE_ROAMING + STATION_STATE_ROAMING, /* Reassociation */ + STATION_STATE_FT_ROAMING, /* Fast transition */ + STATION_STATE_FW_ROAMING, /* Firmware roamed by itself */ }; enum station_event { diff --git a/src/storage.c b/src/storage.c @@ -53,6 +53,7 @@ #define STORAGE_FILE_MODE (S_IRUSR | S_IWUSR) #define KNOWN_FREQ_FILENAME ".known_network.freq" +#define EAP_TLS_CACHE_FILENAME ".eap-tls-session-cache" static char *storage_path = NULL; static char *storage_hotspot_path = NULL; @@ -701,6 +702,47 @@ void storage_known_frequencies_sync(struct l_settings *known_freqs) l_free(known_freq_file_path); } +struct l_settings *storage_eap_tls_cache_load(void) +{ + _auto_(l_free) char *path = + storage_get_path("%s", EAP_TLS_CACHE_FILENAME); + struct l_settings *cache = l_settings_new(); + + if (!l_settings_load_from_file(cache, path)) + l_debug("No session cache loaded from %s, starting with an " + "empty cache", path); + + return cache; +} + +void storage_eap_tls_cache_sync(const struct l_settings *cache) +{ + _auto_(l_free) char *path = + storage_get_path("%s", EAP_TLS_CACHE_FILENAME); + _auto_(l_free) char *settings_data = NULL; + _auto_(l_free) char *data = NULL; + size_t len; + static const char comment[] = + "# External changes to this file are not tracked by IWD " + "and will be overwritten.\n\n"; + static const size_t comment_len = L_ARRAY_SIZE(comment) - 1; + + settings_data = l_settings_to_data(cache, &len); + data = l_malloc(comment_len + len); + memcpy(data, comment, comment_len); + memcpy(data + comment_len, settings_data, len); + + /* + * Note this data contains cryptographic secrets. write_file() + * happens to set the right permissions on the file. + * + * TODO: consider encrypting with system_key. + */ + write_file(data, comment_len + len, false, "%s", path); + explicit_bzero(settings_data, len); + explicit_bzero(data, len); +} + bool storage_is_file(const char *filename) { char *path; diff --git a/src/storage.h b/src/storage.h @@ -51,6 +51,9 @@ int storage_network_remove(enum security type, const char *ssid); struct l_settings *storage_known_frequencies_load(void); void storage_known_frequencies_sync(struct l_settings *known_freqs); +struct l_settings *storage_eap_tls_cache_load(void); +void storage_eap_tls_cache_sync(const struct l_settings *cache); + int __storage_decrypt(struct l_settings *settings, const char *ssid, bool *changed); char *__storage_encrypt(const struct l_settings *settings, const char *ssid, diff --git a/src/wiphy.c b/src/wiphy.c @@ -138,6 +138,7 @@ struct wiphy { bool blacklisted : 1; bool registered : 1; bool self_managed : 1; + bool ap_probe_resp_offload : 1; }; static struct l_queue *wiphy_list = NULL; @@ -149,19 +150,41 @@ enum ie_rsn_cipher_suite wiphy_select_cipher(struct wiphy *wiphy, uint16_t mask) mask &= wiphy->supported_ciphers; - /* CCMP is our first choice, TKIP second */ + if (mask & IE_RSN_CIPHER_SUITE_GCMP_256) + return IE_RSN_CIPHER_SUITE_GCMP_256; + + if (mask & IE_RSN_CIPHER_SUITE_CCMP_256) + return IE_RSN_CIPHER_SUITE_CCMP_256; + + if (mask & IE_RSN_CIPHER_SUITE_GCMP) + return IE_RSN_CIPHER_SUITE_GCMP; + if (mask & IE_RSN_CIPHER_SUITE_CCMP) return IE_RSN_CIPHER_SUITE_CCMP; if (mask & IE_RSN_CIPHER_SUITE_TKIP) return IE_RSN_CIPHER_SUITE_TKIP; - if (mask & IE_RSN_CIPHER_SUITE_BIP) - return IE_RSN_CIPHER_SUITE_BIP; + if (mask & IE_RSN_CIPHER_SUITE_BIP_GMAC_256) + return IE_RSN_CIPHER_SUITE_BIP_GMAC_256; + + if (mask & IE_RSN_CIPHER_SUITE_BIP_CMAC_256) + return IE_RSN_CIPHER_SUITE_BIP_CMAC_256; + + if (mask & IE_RSN_CIPHER_SUITE_BIP_GMAC) + return IE_RSN_CIPHER_SUITE_BIP_GMAC; + + if (mask & IE_RSN_CIPHER_SUITE_BIP_CMAC) + return IE_RSN_CIPHER_SUITE_BIP_CMAC; return 0; } +uint16_t wiphy_get_supported_ciphers(struct wiphy *wiphy, uint16_t mask) +{ + return wiphy->supported_ciphers & mask; +} + static bool wiphy_can_connect_sae(struct wiphy *wiphy) { /* @@ -177,7 +200,7 @@ static bool wiphy_can_connect_sae(struct wiphy *wiphy) * WPA3 Specification version 3, Section 2.3: * A STA shall negotiate PMF when associating to an AP using SAE */ - if (!(wiphy->supported_ciphers & IE_RSN_CIPHER_SUITE_BIP)) { + if (!(wiphy->supported_ciphers & IE_RSN_CIPHER_SUITE_BIP_CMAC)) { l_debug("HW not MFP capable, can't use SAE"); return false; } @@ -473,6 +496,11 @@ const struct scan_freq_set *wiphy_get_disabled_freqs(const struct wiphy *wiphy) return wiphy->disabled_freqs; } +bool wiphy_supports_probe_resp_offload(struct wiphy *wiphy) +{ + return wiphy->ap_probe_resp_offload; +} + bool wiphy_can_transition_disable(struct wiphy *wiphy) { /* @@ -482,7 +510,7 @@ bool wiphy_can_transition_disable(struct wiphy *wiphy) if (!(wiphy->supported_ciphers & IE_RSN_CIPHER_SUITE_CCMP)) return false; - if (!(wiphy->supported_ciphers & IE_RSN_CIPHER_SUITE_BIP)) + if (!(wiphy->supported_ciphers & IE_RSN_CIPHER_SUITE_BIP_CMAC)) return false; return true; @@ -1114,7 +1142,7 @@ static void wiphy_print_band_info(struct band *band, const char *name) static void wiphy_print_basic_info(struct wiphy *wiphy) { - char buf[1024]; + char buf[2048]; l_info("Wiphy: %d, Name: %s", wiphy->id, wiphy->name); l_info("\tPermanent Address: "MAC, MAC_STR(wiphy->permanent_addr)); @@ -1129,18 +1157,33 @@ static void wiphy_print_basic_info(struct wiphy *wiphy) wiphy_print_band_info(wiphy->band_6g, "6GHz Band"); if (wiphy->supported_ciphers) { - int len = 0; + int n = 0; + size_t len = 0; + int i = sizeof(wiphy->supported_ciphers) * 8 - 1; + + len += snprintf(buf, sizeof(buf), "\tCiphers:"); - len += sprintf(buf + len, "\tCiphers:"); + for (; i >= 0 && len < sizeof(buf); i--) { + typeof(wiphy->supported_ciphers) cipher = 1 << i; + const char *str; - if (wiphy->supported_ciphers & IE_RSN_CIPHER_SUITE_CCMP) - len += sprintf(buf + len, " CCMP"); + if (cipher == IE_RSN_CIPHER_SUITE_WEP40 || + cipher == IE_RSN_CIPHER_SUITE_WEP104) + continue; + + if (!(wiphy->supported_ciphers & cipher)) + continue; - if (wiphy->supported_ciphers & IE_RSN_CIPHER_SUITE_TKIP) - len += sprintf(buf + len, " TKIP"); + str = ie_rsn_cipher_suite_to_string(cipher); + if (!str) + continue; - if (wiphy->supported_ciphers & IE_RSN_CIPHER_SUITE_BIP) - len += sprintf(buf + len, " BIP"); + len += snprintf(buf + len, sizeof(buf) - len, "%s%s", + !n || (n % 4) ? " " : "\n\t\t ", + str); + + n += 1; + } l_info("%s", buf); } @@ -1209,8 +1252,32 @@ static void parse_supported_ciphers(struct wiphy *wiphy, const void *data, case CRYPTO_CIPHER_WEP104: wiphy->supported_ciphers |= IE_RSN_CIPHER_SUITE_WEP104; break; - case CRYPTO_CIPHER_BIP: - wiphy->supported_ciphers |= IE_RSN_CIPHER_SUITE_BIP; + case CRYPTO_CIPHER_BIP_CMAC: + wiphy->supported_ciphers |= + IE_RSN_CIPHER_SUITE_BIP_CMAC; + break; + case CRYPTO_CIPHER_GCMP: + wiphy->supported_ciphers |= IE_RSN_CIPHER_SUITE_GCMP; + break; + case CRYPTO_CIPHER_GCMP_256: + wiphy->supported_ciphers |= + IE_RSN_CIPHER_SUITE_GCMP_256; + break; + case CRYPTO_CIPHER_CCMP_256: + wiphy->supported_ciphers |= + IE_RSN_CIPHER_SUITE_CCMP_256; + break; + case CRYPTO_CIPHER_BIP_GMAC: + wiphy->supported_ciphers |= + IE_RSN_CIPHER_SUITE_BIP_GMAC; + break; + case CRYPTO_CIPHER_BIP_GMAC_256: + wiphy->supported_ciphers |= + IE_RSN_CIPHER_SUITE_BIP_GMAC_256; + break; + case CRYPTO_CIPHER_BIP_CMAC_256: + wiphy->supported_ciphers |= + IE_RSN_CIPHER_SUITE_BIP_CMAC_256; break; default: /* TODO: Support other ciphers */ break; @@ -1644,6 +1711,9 @@ static void wiphy_parse_attributes(struct wiphy *wiphy, case NL80211_ATTR_WIPHY_SELF_MANAGED_REG: wiphy->self_managed = true; break; + case NL80211_ATTR_PROBE_RESP_OFFLOAD: + wiphy->ap_probe_resp_offload = true; + break; } } } diff --git a/src/wiphy.h b/src/wiphy.h @@ -46,11 +46,12 @@ struct wiphy_radio_work_item { }; enum { - WIPHY_WORK_PRIORITY_FRAME = 0, - WIPHY_WORK_PRIORITY_OFFCHANNEL = 0, - WIPHY_WORK_PRIORITY_CONNECT = 1, - WIPHY_WORK_PRIORITY_SCAN = 2, - WIPHY_WORK_PRIORITY_PERIODIC_SCAN = 3, + WIPHY_WORK_PRIORITY_FT = 0, + WIPHY_WORK_PRIORITY_FRAME = 1, + WIPHY_WORK_PRIORITY_OFFCHANNEL = 1, + WIPHY_WORK_PRIORITY_CONNECT = 2, + WIPHY_WORK_PRIORITY_SCAN = 3, + WIPHY_WORK_PRIORITY_PERIODIC_SCAN = 4, }; enum wiphy_state_watch_event { @@ -67,6 +68,8 @@ typedef void (*wiphy_destroy_func_t)(void *user_data); enum ie_rsn_cipher_suite wiphy_select_cipher(struct wiphy *wiphy, uint16_t mask); +uint16_t wiphy_get_supported_ciphers(struct wiphy *wiphy, uint16_t mask); + enum ie_rsn_akm_suite wiphy_select_akm(struct wiphy *wiphy, const struct scan_bss *bss, enum security security, @@ -96,6 +99,7 @@ uint32_t wiphy_get_supported_bands(struct wiphy *wiphy); const struct scan_freq_set *wiphy_get_supported_freqs( const struct wiphy *wiphy); const struct scan_freq_set *wiphy_get_disabled_freqs(const struct wiphy *wiphy); +bool wiphy_supports_probe_resp_offload(struct wiphy *wiphy); bool wiphy_can_transition_disable(struct wiphy *wiphy); bool wiphy_can_offload(struct wiphy *wiphy); bool wiphy_supports_cmds_auth_assoc(struct wiphy *wiphy); diff --git a/src/wsc.c b/src/wsc.c @@ -665,6 +665,8 @@ static void wsc_check_can_connect(struct wsc_station_dbus *wsc, case STATION_STATE_AUTOCONNECT_QUICK: case STATION_STATE_AUTOCONNECT_FULL: case STATION_STATE_ROAMING: + case STATION_STATE_FT_ROAMING: + case STATION_STATE_FW_ROAMING: l_warn("%s: invalid station state", __func__); break; } diff --git a/tools/hwsim.c b/tools/hwsim.c @@ -175,7 +175,13 @@ static const uint32_t hwsim_supported_ciphers[] = { CRYPTO_CIPHER_WEP104, CRYPTO_CIPHER_TKIP, CRYPTO_CIPHER_CCMP, - CRYPTO_CIPHER_BIP, + CRYPTO_CIPHER_BIP_CMAC, + CRYPTO_CIPHER_GCMP, + CRYPTO_CIPHER_GCMP_256, + CRYPTO_CIPHER_CCMP_256, + CRYPTO_CIPHER_BIP_GMAC, + CRYPTO_CIPHER_BIP_GMAC_256, + CRYPTO_CIPHER_BIP_CMAC_256, }; static uint32_t hwsim_ciphers[L_ARRAY_SIZE(hwsim_supported_ciphers)]; static int hwsim_num_ciphers = 0; @@ -196,7 +202,13 @@ static const struct hwsim_support cipher_map[] = { { "wep104", CRYPTO_CIPHER_WEP104 }, { "tkip", CRYPTO_CIPHER_TKIP }, { "ccmp", CRYPTO_CIPHER_CCMP }, - { "bip", CRYPTO_CIPHER_BIP }, + { "bip_cmac", CRYPTO_CIPHER_BIP_CMAC }, + { "gcmp", CRYPTO_CIPHER_GCMP }, + { "gcmp_256", CRYPTO_CIPHER_GCMP_256 }, + { "ccmp_256", CRYPTO_CIPHER_CCMP_256 }, + { "bip_gmac", CRYPTO_CIPHER_BIP_GMAC }, + { "bip_gmac_256", CRYPTO_CIPHER_BIP_GMAC_256 }, + { "bip_cmac_256", CRYPTO_CIPHER_BIP_CMAC_256 }, { } }; @@ -1204,7 +1216,7 @@ static void process_rules(const struct radio_info_rec *src_radio, struct hwsim_rule *rule = rule_entry->data; if (!rule->enabled) - return; + continue; if (!rule->source_any && !radio_match_addr(src_radio, rule->source) && diff --git a/tools/run-tests b/tools/run-tests @@ -37,6 +37,14 @@ def dbg(*s, **kwargs): ''' print(*s, **kwargs, file=sys.__stdout__) +def write_results(file, results): + with open(file, 'w') as f: + for test, results in results.items(): + if results.failures != 0 or results.errors != 0: + f.write('%s:FAIL\n' % test) + else: + f.write('%s:PASS\n' % test) + def exit_vm(): if config: for p in Process.get_all(): @@ -45,13 +53,9 @@ def exit_vm(): if config.ctx and config.ctx.results: success = print_results(config.ctx.results) - else: - success = False - if config.ctx.args.result: - result = 'PASS' if success else 'FAIL' - with open(config.ctx.args.result, 'w') as f: - f.write(result) + if config.ctx.args.result: + write_results(config.ctx.args.result, config.ctx.results) os.sync() diff --git a/tools/utils.py b/tools/utils.py @@ -449,6 +449,9 @@ class Namespace: if Process.is_verbose('iwd-rtnl'): env['IWD_RTNL_DEBUG'] = '1' + if Process.is_verbose('iwd-sae'): + env['IWD_SAE_DEBUG'] = '1' + proc = self.start_process(args, env=env) proc.wait_for_service(self, 'net.connman.iwd', 20) diff --git a/unit/test-arc4.c b/unit/test-arc4.c @@ -92,6 +92,8 @@ static void arc4_skip_test(const void *data) assert(arc4_skip(test->key, 16, test->offset, buf, sizeof(buf), buf)); assert(!memcmp(buf, test->result, sizeof(buf))); + assert(arc4_skip(test->key, 16, test->offset, buf, sizeof(buf), buf)); + assert(l_memeqzero(buf, 16)); } int main(int argc, char *argv[]) diff --git a/unit/test-ie.c b/unit/test-ie.c @@ -423,7 +423,7 @@ static const struct ie_rsne_info_test ie_rsne_info_test_6 = { .pairwise_ciphers = IE_RSN_CIPHER_SUITE_CCMP, .akm_suites = IE_RSN_AKM_SUITE_8021X, .mfpc = true, /* Management frame protection is enabled, not required */ - .group_management_cipher = IE_RSN_CIPHER_SUITE_BIP, + .group_management_cipher = IE_RSN_CIPHER_SUITE_BIP_CMAC, }; static void ie_test_rsne_info(const void *data) diff --git a/wired/ead.service.in b/wired/ead.service.in @@ -1,5 +1,6 @@ [Unit] Description=Ethernet service +Documentation=man:ead(8) After=network-pre.target Before=network.target Wants=network.target