commit 642ba4aff76570b610c4fdec22cc30c6195f3b31
parent b5ac9484fa3cb986af37fad2c34dddcc2f272d03
Author: illiliti <illiliti@protonmail.com>
Date: Sun, 11 Sep 2022 14:21:04 +0300
Merge tag '1.30'
Release 1.30
Diffstat:
61 files changed, 2754 insertions(+), 511 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -38,6 +38,7 @@ tools/hwsim
tools/hwsim.1
tools/probe-req
tools/iwd-decrypt-profile
+tools/iwd-psk
unit/test-cmac-aes
unit/test-arc4
unit/test-hmac-md5
@@ -68,3 +69,4 @@ unit/*.log
unit/*.trs
test-suite.log
src/builtin.h
+autotests/*/__pycache__
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,11 @@
+ver 1.30:
+ Fix issue with handling OWE if buggy AP is detected.
+ Fix issue with handling quick scan and enabling 6GHz.
+ Fix issue with handling tags for extended IEs.
+ Add support for handling HE capabilities.
+ Add support for handling regulatory domain changes.
+ Add support for handling netdev packet loss events.
+
ver 1.29:
Fix issue with handling EAP-Success message.
Fix issue with handling secure setting and EAPoL.
diff --git a/Makefile.am b/Makefile.am
@@ -302,7 +302,9 @@ client_iwctl_SOURCES = client/main.c \
client/wsc.c client/station.c \
client/diagnostic.c client/diagnostic.h \
client/daemon.c client/daemon.h \
- client/dpp.c
+ client/dpp.c client/station-debug.c \
+ src/util.c src/util.h \
+ src/band.c src/band.h
client_iwctl_LDADD = $(ell_ldadd) $(READLINE_LIBS)
@@ -469,7 +471,8 @@ unit_test_kdf_sha256_LDADD = $(ell_ldadd)
unit_test_ie_SOURCES = unit/test-ie.c src/ie.h src/ie.c
unit_test_ie_LDADD = $(ell_ldadd)
-unit_test_band_SOURCES = unit/test-band.c src/band.h src/band.c
+unit_test_band_SOURCES = unit/test-band.c src/band.h src/band.c src/netdev.h \
+ src/ie.h src/ie.c
unit_test_band_LDADD = $(ell_ldadd)
unit_test_crypto_SOURCES = unit/test-crypto.c \
diff --git a/autotests/testFILS/fils_256_test.py b/autotests/testFILS/fils_256_test.py
@@ -62,8 +62,6 @@ class Test(unittest.TestCase):
@classmethod
def setUpClass(cls):
IWD.copy_to_storage('ssidFILS-256.8021x')
- os.system('ip link set lo up')
- pass
@classmethod
def tearDownClass(cls):
diff --git a/autotests/testFILS/fils_384_test.py b/autotests/testFILS/fils_384_test.py
@@ -62,8 +62,6 @@ class Test(unittest.TestCase):
@classmethod
def setUpClass(cls):
IWD.copy_to_storage('ssidFILS-384.8021x')
- os.system('ip link set lo up')
- pass
@classmethod
def tearDownClass(cls):
diff --git a/autotests/testFT-8021x-roam/connection_test.py b/autotests/testFT-8021x-roam/connection_test.py
@@ -66,28 +66,10 @@ class Test(unittest.TestCase):
cls.bss_hostapd = [ HostapdCLI(config='ft-eap-ccmp-1.conf'),
HostapdCLI(config='ft-eap-ccmp-2.conf') ]
- # Set interface addresses to those expected by hostapd config files
- os.system('ip link set dev "' + cls.bss_hostapd[0].ifname + '" down')
- os.system('ip link set dev "' + cls.bss_hostapd[0].ifname + \
- '" address 12:00:00:00:00:01 up')
- os.system('ip link set dev "' + cls.bss_hostapd[1].ifname + '" down')
- os.system('ip link set dev "' + cls.bss_hostapd[1].ifname + \
- '" address 12:00:00:00:00:02 up')
-
- cls.bss_hostapd[0].reload()
- cls.bss_hostapd[0].wait_for_event("AP-ENABLED")
- cls.bss_hostapd[1].reload()
- cls.bss_hostapd[1].wait_for_event("AP-ENABLED")
-
- # Fill in the neighbor AP tables in both BSSes. By default each
- # instance knows only about current BSS, even inside one hostapd
- # process.
- # FT still works without the neighbor AP table but neighbor reports
- # have to be disabled in the .conf files
- cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT',
- '1200000000028f0000005102060603000000')
- cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT',
- '1200000000018f0000005101060603000000')
+ cls.bss_hostapd[0].set_address('12:00:00:00:00:01')
+ cls.bss_hostapd[1].set_address('12:00:00:00:00:02')
+
+ HostapdCLI.group_neighbors(*cls.bss_hostapd)
@classmethod
def tearDownClass(cls):
diff --git a/autotests/testFT-FILS/connection_test.py b/autotests/testFT-FILS/connection_test.py
@@ -122,32 +122,15 @@ class Test(unittest.TestCase):
@classmethod
def setUpClass(cls):
- os.system('ip link set lo up')
IWD.copy_to_storage('TestFT.8021x')
cls.bss_hostapd = [ HostapdCLI(config='ft-eap-ccmp-1.conf'),
HostapdCLI(config='ft-eap-ccmp-2.conf') ]
- # Set interface addresses to those expected by hostapd config files
- os.system('ip link set dev "' + cls.bss_hostapd[0].ifname + '" down')
- os.system('ip link set dev "' + cls.bss_hostapd[0].ifname + '" addr 12:00:00:00:00:01 up')
- os.system('ip link set dev "' + cls.bss_hostapd[1].ifname + '" down')
- os.system('ip link set dev "' + cls.bss_hostapd[1].ifname + '" addr 12:00:00:00:00:02 up')
-
- cls.bss_hostapd[0].reload()
- cls.bss_hostapd[0].wait_for_event("AP-ENABLED")
- cls.bss_hostapd[1].reload()
- cls.bss_hostapd[1].wait_for_event("AP-ENABLED")
-
- # Fill in the neighbor AP tables in both BSSes. By default each
- # instance knows only about current BSS, even inside one hostapd
- # process.
- # FT still works without the neighbor AP table but neighbor reports
- # have to be disabled in the .conf files
- cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT',
- '1200000000028f0000005102060603000000')
- cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT',
- '1200000000018f0000005101060603000000')
+ cls.bss_hostapd[0].set_address('12:00:00:00:00:01')
+ cls.bss_hostapd[1].set_address('12:00:00:00:00:02')
+
+ HostapdCLI.group_neighbors(*cls.bss_hostapd)
@classmethod
def tearDownClass(cls):
diff --git a/autotests/testNetconfig/static_test.py b/autotests/testNetconfig/static_test.py
@@ -13,36 +13,28 @@ import testutil
from config import ctx
import os
import socket
+import gc
class Test(unittest.TestCase):
def test_connection_success(self):
# Use a non-default storage_dir for one of the instances, the default for the other one
- wd = IWD(True, iwd_storage_dir='/tmp/storage')
-
- ns0 = ctx.get_namespace('ns0')
-
- wd_ns0 = IWD(True, namespace=ns0)
-
- psk_agent = PSKAgent("secret123")
- psk_agent_ns0 = PSKAgent("secret123", namespace=ns0)
- wd.register_psk_agent(psk_agent)
- wd_ns0.register_psk_agent(psk_agent_ns0)
-
- dev1 = wd.list_devices(1)[0]
- dev2 = wd_ns0.list_devices(1)[0]
+ iwd_main = IWD(True, iwd_storage_dir='/tmp/storage-main')
+ psk_agent_main = PSKAgent("secret123")
+ iwd_main.register_psk_agent(psk_agent_main)
+ dev1 = iwd_main.list_devices(1)[0]
ordered_network = dev1.get_ordered_network('ap-main')
self.assertEqual(ordered_network.type, NetworkType.psk)
condition = 'not obj.connected'
- wd.wait_for_object_condition(ordered_network.network_object, condition)
+ iwd_main.wait_for_object_condition(ordered_network.network_object, condition)
ordered_network.network_object.connect()
condition = 'obj.state == DeviceState.connected'
- wd.wait_for_object_condition(dev1, condition)
+ iwd_main.wait_for_object_condition(dev1, condition)
testutil.test_iface_operstate()
testutil.test_ifaces_connected()
@@ -80,22 +72,73 @@ class Test(unittest.TestCase):
# of the log since we care about the end result here.
self.assertEqual(expected_rclog, entries[-3:])
+ # Run our second client in a separate namespace to allow ACD (ARP) to
+ # work, and also be able to set identical IPs on both interfaces for
+ # the next part of this test.
+ ns0 = ctx.get_namespace('ns0')
+
+ iwd_ns0_1 = IWD(True, namespace=ns0, iwd_storage_dir='/tmp/storage-ns0-1')
+ psk_agent_ns0_1 = PSKAgent("secret123", namespace=ns0)
+ iwd_ns0_1.register_psk_agent(psk_agent_ns0_1)
+ dev2 = iwd_ns0_1.list_devices(1)[0]
+
ordered_network = dev2.get_ordered_network('ap-main')
condition = 'not obj.connected'
- wd_ns0.wait_for_object_condition(ordered_network.network_object, condition)
+ iwd_ns0_1.wait_for_object_condition(ordered_network.network_object, condition)
+
+ # Attempt a connection to the same AP that iwd_main is connected to
+ # using the same static config. The new client's ACD client should
+ # detect an IP conflict and not allow the device to reach the
+ # "connected" state although the DBus .Connect call will succeed.
+ ordered_network.network_object.connect()
+ self.assertEqual(dev2.state, iwd.DeviceState.connecting)
+ try:
+ # We should either stay in "connecting" indefinitely or move to
+ # "disconnecting"
+ condition = 'obj.state != DeviceState.connecting'
+ iwd_ns0_1.wait_for_object_condition(dev2, condition, max_wait=21)
+ self.assertEqual(dev2.state, iwd.DeviceState.disconnecting)
+ except TimeoutError:
+ dev2.disconnect()
+
+ iwd_ns0_1.unregister_psk_agent(psk_agent_ns0_1)
+ del dev2
+ # Note: if any references to iwd_ns0_1 are left, the "del iwd_ns0_1"
+ # will not kill the IWD process the iwd_ns0_2 initialization will raise
+ # an exception. The iwd_ns0_1.wait_for_object_condition() above
+ # creates a circular reference (which is not wrong in itself) and
+ # gc.collect() gets rid of it. The actual solution is to eventually
+ # avoid executing anything important in .__del__ (which is wrong.)
+ gc.collect()
+ del iwd_ns0_1
+
+ iwd_ns0_2 = IWD(True, namespace=ns0, iwd_storage_dir='/tmp/storage-ns0-2')
+ psk_agent_ns0_2 = PSKAgent("secret123", namespace=ns0)
+ iwd_ns0_2.register_psk_agent(psk_agent_ns0_2)
+ dev2 = iwd_ns0_2.list_devices(1)[0]
- # Connect to the same network from a dynamically configured client. The
- # DHCP server doesn't know (even though dev1 announced itself) that
- # 192.168.1.10 is already in use and if it assigns dev2 the lowest
- # available address, that's going to be 192.168.1.10. dev1's ACD
- # implementation should then stop using this address.
+ ordered_network = dev2.get_ordered_network('ap-main')
+
+ condition = 'not obj.connected'
+ iwd_ns0_2.wait_for_object_condition(ordered_network.network_object, condition)
+
+ # Connect to the same network from a dynamically configured client. We
+ # block ICMP pings so that the DHCP server can't confirm that
+ # 192.168.1.10 is in use by dev1 and if it assigns dev2 the lowest
+ # available address, that's going to be 192.168.1.10. We also keep the
+ # second client's netdev in a separate namespace so that the kernel
+ # lets us assign the same IP. dev1's ACD implementation should then
+ # stop using this address. Yes, a quite unrealistic scenario but this
+ # lets us test our reaction to a conflict appearing after successful
+ # initial setup.
+ os.system("echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all")
ordered_network.network_object.connect()
condition = 'obj.state == DeviceState.connected'
- wd_ns0.wait_for_object_condition(dev2, condition)
+ iwd_ns0_2.wait_for_object_condition(dev2, condition)
- wd.wait(1)
+ iwd_main.wait(1)
# Check dev1 is now disconnected or without its IPv4 address
if dev1.state == iwd.DeviceState.connected:
testutil.test_ip_address_match(dev1.name, None)
@@ -104,9 +147,9 @@ class Test(unittest.TestCase):
dev2.disconnect()
condition = 'not obj.connected'
- wd.wait_for_object_condition(ordered_network.network_object, condition)
+ iwd_main.wait_for_object_condition(ordered_network.network_object, condition)
- wd.unregister_psk_agent(psk_agent)
+ iwd_main.unregister_psk_agent(psk_agent_main)
@classmethod
def setUpClass(cls):
@@ -127,7 +170,8 @@ class Test(unittest.TestCase):
cls.dhcpd_pid = ctx.start_process(['dhcpd', '-f', '-cf', '/tmp/dhcpd.conf',
'-lf', '/tmp/dhcpd.leases',
hapd.ifname], cleanup=remove_lease)
- IWD.copy_to_storage('static.psk', '/tmp/storage', 'ap-main.psk')
+ IWD.copy_to_storage('static.psk', '/tmp/storage-main', 'ap-main.psk')
+ IWD.copy_to_storage('static.psk', '/tmp/storage-ns0-1', 'ap-main.psk')
cls.orig_path = os.environ['PATH']
os.environ['PATH'] = '/tmp/test-bin:' + os.environ['PATH']
@@ -136,7 +180,7 @@ class Test(unittest.TestCase):
@classmethod
def tearDownClass(cls):
cls.dhcpd_pid.kill()
- os.system('rm -rf /tmp/resolvconf.log /tmp/test-bin /tmp/storage')
+ os.system('rm -rf /tmp/resolvconf.log /tmp/test-bin /tmp/storage-*')
os.environ['PATH'] = cls.orig_path
if __name__ == '__main__':
diff --git a/autotests/testPSK-roam/connection_test.py b/autotests/testPSK-roam/connection_test.py
@@ -13,7 +13,7 @@ from hostapd import HostapdCLI
import testutil
class Test(unittest.TestCase):
- def validate_connection(self, wd, over_ds=False):
+ def validate_connection(self, wd, over_ds=False, pkt_loss=False):
device = wd.list_devices(1)[0]
ordered_network = device.get_ordered_network('TestFT', full_scan=True)
@@ -41,7 +41,16 @@ class Test(unittest.TestCase):
if over_ds:
self.rule0.enabled = True
- device.roam(self.bss_hostapd[1].bssid)
+ if pkt_loss:
+ # Drop all data frames
+ self.rule1.enabled = True
+ # Set the current BSS signal lower so we have roam candidates
+ self.rule2.enabled = True
+ # Send 100 packets (to be dropped), should trigger beacon loss
+ testutil.tx_packets(device.name, self.bss_hostapd[0].ifname, 100)
+ device.wait_for_event('packet-loss-roam', timeout=30)
+ else:
+ device.roam(self.bss_hostapd[1].bssid)
condition = 'obj.state == DeviceState.roaming'
wd.wait_for_object_condition(device, condition)
@@ -52,6 +61,10 @@ class Test(unittest.TestCase):
to_condition = 'obj.state == DeviceState.connected'
wd.wait_for_object_change(device, from_condition, to_condition)
+ if pkt_loss:
+ self.rule1.enabled = False
+ self.rule2.enabled = False
+
self.bss_hostapd[1].wait_for_event('AP-STA-CONNECTED %s' % device.address)
testutil.test_iface_operstate(device.name)
@@ -132,6 +145,23 @@ class Test(unittest.TestCase):
self.validate_connection(wd)
+ def test_roam_packet_loss(self):
+ wd = IWD(True)
+
+ 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].set_value('ocv', '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', '0')
+ self.bss_hostapd[0].set_value('ocv', '1')
+ self.bss_hostapd[1].reload()
+ self.bss_hostapd[1].wait_for_event("AP-ENABLED")
+
+ self.validate_connection(wd, pkt_loss=True)
+
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')
@@ -139,6 +169,8 @@ class Test(unittest.TestCase):
os.system('ip link set "' + self.bss_hostapd[1].ifname + '" up')
self.rule0.enabled = False
+ self.rule1.enabled = False
+ self.rule2.enabled = False
@classmethod
def setUpClass(cls):
@@ -148,6 +180,7 @@ class Test(unittest.TestCase):
cls.bss_hostapd = [ HostapdCLI(config='ft-psk-ccmp-1.conf'),
HostapdCLI(config='ft-psk-ccmp-2.conf') ]
+ rad0 = hwsim.get_radio('rad0')
rad2 = hwsim.get_radio('rad2')
cls.rule0 = hwsim.rules.create()
@@ -157,26 +190,19 @@ class Test(unittest.TestCase):
cls.rule0.prefix = 'b0'
cls.rule0.drop = True
- # Set interface addresses to those expected by hostapd config files
- os.system('ip link set dev "' + cls.bss_hostapd[0].ifname + '" down')
- os.system('ip link set dev "' + cls.bss_hostapd[0].ifname + '" addr 12:00:00:00:00:01 up')
- os.system('ip link set dev "' + cls.bss_hostapd[1].ifname + '" down')
- os.system('ip link set dev "' + cls.bss_hostapd[1].ifname + '" addr 12:00:00:00:00:02 up')
-
- cls.bss_hostapd[0].reload()
- cls.bss_hostapd[0].wait_for_event("AP-ENABLED")
- cls.bss_hostapd[1].reload()
- cls.bss_hostapd[1].wait_for_event("AP-ENABLED")
-
- # Fill in the neighbor AP tables in both BSSes. By default each
- # instance knows only about current BSS, even inside one hostapd
- # process.
- # FT still works without the neighbor AP table but neighbor reports
- # have to be disabled in the .conf files
- cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT',
- '1200000000028f0000005102060603000000')
- cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT',
- '1200000000018f0000005101060603000000')
+ cls.rule1 = hwsim.rules.create()
+ cls.rule1.source = rad2.addresses[0]
+ cls.rule1.prefix = '08'
+ cls.rule1.drop = True
+
+ cls.rule2 = hwsim.rules.create()
+ cls.rule2.source = rad0.addresses[0]
+ cls.rule2.signal = -7000
+
+ cls.bss_hostapd[0].set_address('12:00:00:00:00:01')
+ cls.bss_hostapd[1].set_address('12:00:00:00:00:02')
+
+ HostapdCLI.group_neighbors(*cls.bss_hostapd)
@classmethod
def tearDownClass(cls):
diff --git a/autotests/testPSK-roam/roam_ap_disconnect_test.py b/autotests/testPSK-roam/roam_ap_disconnect_test.py
@@ -46,10 +46,7 @@ class Test(unittest.TestCase):
self.validate()
def test_ap_disconnect_neighbors(self):
- self.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT',
- '1200000000028f0000005102060603000000')
- self.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT',
- '1200000000018f0000005101060603000000')
+ HostapdCLI.group_neighbors(*self.bss_hostapd)
self.validate()
@@ -85,11 +82,8 @@ class Test(unittest.TestCase):
cls.rule0.signal = -8000
cls.rule0.enabled = True
- # Set interface addresses to those expected by hostapd config files
- os.system('ip link set dev "' + cls.bss_hostapd[0].ifname + '" down')
- os.system('ip link set dev "' + cls.bss_hostapd[0].ifname + '" addr 12:00:00:00:00:01 up')
- os.system('ip link set dev "' + cls.bss_hostapd[1].ifname + '" down')
- os.system('ip link set dev "' + cls.bss_hostapd[1].ifname + '" addr 12:00:00:00:00:02 up')
+ cls.bss_hostapd[0].set_address('12:00:00:00:00:01')
+ cls.bss_hostapd[1].set_address('12:00:00:00:00:02')
@classmethod
def tearDownClass(cls):
diff --git a/autotests/testPreauth-roam/connection_test.py b/autotests/testPreauth-roam/connection_test.py
@@ -17,18 +17,7 @@ class Test(unittest.TestCase):
bss0_addr = bss_hostapd[0].bssid
bss1_addr = bss_hostapd[1].bssid
- # Fill in the neighbor AP tables in both BSSes. By default each
- # instance knows only about current BSS, even inside one hostapd
- # process.
- # Roaming still works without the neighbor AP table but neighbor
- # reports have to be disabled in the .conf files
- bss0_nr = ''.join(bss0_addr.split(':')) + \
- '8f0000005101060603000000'
- bss1_nr = ''.join(bss1_addr.split(':')) + \
- '8f0000005102060603000000'
-
- bss_hostapd[0].set_neighbor(bss1_addr, 'TestPreauth', bss1_nr)
- bss_hostapd[1].set_neighbor(bss0_addr, 'TestPreauth', bss0_nr)
+ HostapdCLI.group_neighbors(*bss_hostapd)
wd = IWD(True)
@@ -86,8 +75,6 @@ class Test(unittest.TestCase):
def setUpClass(cls):
IWD.copy_to_storage('TestPreauth.8021x')
- os.system('ip link set lo up')
-
@classmethod
def tearDownClass(cls):
IWD.clear_storage()
diff --git a/autotests/testRoamRetry/fast_retry_test.py b/autotests/testRoamRetry/fast_retry_test.py
@@ -36,20 +36,7 @@ class Test(unittest.TestCase):
rule1.bidirectional = True
rule1.enabled = True
- # Fill in the neighbor AP tables in both BSSes. By default each
- # instance knows only about current BSS, even inside one hostapd
- # process.
- # Roaming still works without the neighbor AP table but neighbor
- # reports have to be disabled in the .conf files
- bss0_nr = ''.join(bss_radio[0].addresses[0].split(':')) + \
- '8f0000005101060603000000'
- bss1_nr = ''.join(bss_radio[1].addresses[0].split(':')) + \
- '8f0000005102060603000000'
-
- bss_hostapd[0].set_neighbor(bss_radio[1].addresses[0], 'TestRoamRetry',
- bss1_nr)
- bss_hostapd[1].set_neighbor(bss_radio[0].addresses[0], 'TestRoamRetry',
- bss0_nr)
+ HostapdCLI.group_neighbors(*bss_hostapd)
# Start in the vicinity of BSS 0, check that iwd connects to BSS 0
rule0.signal = -2000
diff --git a/autotests/testRoamRetry/stop_retry_test.py b/autotests/testRoamRetry/stop_retry_test.py
@@ -35,20 +35,7 @@ class Test(unittest.TestCase):
rule1.bidirectional = True
rule1.enabled = True
- # Fill in the neighbor AP tables in both BSSes. By default each
- # instance knows only about current BSS, even inside one hostapd
- # process.
- # Roaming still works without the neighbor AP table but neighbor
- # reports have to be disabled in the .conf files
- bss0_nr = ''.join(bss_radio[0].addresses[0].split(':')) + \
- '8f0000005101060603000000'
- bss1_nr = ''.join(bss_radio[1].addresses[0].split(':')) + \
- '8f0000005102060603000000'
-
- bss_hostapd[0].set_neighbor(bss_radio[1].addresses[0], 'TestRoamRetry',
- bss1_nr)
- bss_hostapd[1].set_neighbor(bss_radio[0].addresses[0], 'TestRoamRetry',
- bss0_nr)
+ HostapdCLI.group_neighbors(*bss_hostapd)
# Start in the vicinity of BSS 0, check that iwd connects to BSS 0
rule0.signal = -2000
diff --git a/autotests/testSAE-roam/connection_test.py b/autotests/testSAE-roam/connection_test.py
@@ -120,43 +120,11 @@ class Test(unittest.TestCase):
HostapdCLI(config='ft-sae-2.conf'),
HostapdCLI(config='ft-psk-3.conf') ]
- ctx.start_process(['ip', 'link', 'set', 'dev', cls.bss_hostapd[0].ifname, 'down']).wait()
- ctx.start_process(['ip', 'link', 'set', 'dev', cls.bss_hostapd[0].ifname, \
- 'addr', '12:00:00:00:00:01', 'up']).wait()
- ctx.start_process(['ip', 'link', 'set', 'dev', cls.bss_hostapd[1].ifname, 'down']).wait()
- ctx.start_process(['ip', 'link', 'set', 'dev', cls.bss_hostapd[1].ifname, \
- 'addr', '12:00:00:00:00:02', 'up']).wait()
- ctx.start_process(['ip', 'link', 'set', 'dev', cls.bss_hostapd[2].ifname, 'down']).wait()
- ctx.start_process(['ip', 'link', 'set', 'dev', cls.bss_hostapd[2].ifname, \
- 'addr', '12:00:00:00:00:03', 'up']).wait()
-
- # Set interface addresses to those expected by hostapd config files
- cls.bss_hostapd[0].reload()
- cls.bss_hostapd[0].wait_for_event("AP-ENABLED")
- cls.bss_hostapd[1].reload()
- cls.bss_hostapd[1].wait_for_event("AP-ENABLED")
- cls.bss_hostapd[2].reload()
- cls.bss_hostapd[2].wait_for_event("AP-ENABLED")
-
- # Fill in the neighbor AP tables in both BSSes. By default each
- # instance knows only about current BSS, even inside one hostapd
- # process.
- # FT still works without the neighbor AP table but neighbor reports
- # have to be disabled in the .conf files
- cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT',
- '1200000000028f0000005102060603000000')
- cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:03', 'TestFT',
- '1200000000038f0000005102060603000000')
-
- cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT',
- '1200000000018f0000005101060603000000')
- cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:03', 'TestFT',
- '1200000000038f0000005101060603000000')
-
- cls.bss_hostapd[2].set_neighbor('12:00:00:00:00:01', 'TestFT',
- '1200000000018f0000005101060603000000')
- cls.bss_hostapd[2].set_neighbor('12:00:00:00:00:02', 'TestFT',
- '1200000000028f0000005101060603000000')
+ cls.bss_hostapd[0].set_address('12:00:00:00:00:01')
+ cls.bss_hostapd[1].set_address('12:00:00:00:00:02')
+ cls.bss_hostapd[2].set_address('12:00:00:00:00:03')
+
+ HostapdCLI.group_neighbors(*cls.bss_hostapd)
IWD.copy_to_storage('TestFT.psk')
diff --git a/autotests/util/hostapd.py b/autotests/util/hostapd.py
@@ -281,3 +281,34 @@ class HostapdCLI(object):
@property
def enabled(self):
return self._get_status()['state'] == 'ENABLED'
+
+ def set_address(self, mac):
+ os.system('ip link set dev %s down' % self.ifname)
+ os.system('ip link set dev %s addr %s up' % (self.ifname, mac))
+
+ self.reload()
+ self.wait_for_event("AP-ENABLED")
+
+ def _add_neighbors(self, *args, op_class=81):
+ for hapd in args:
+ status = hapd._get_status()
+
+ ssid = status['ssid[0]']
+ bssid = status['bssid[0]']
+ channel = int(status['channel'])
+
+ if (channel > 14 and op_class == 81):
+ raise Exception("default add_neighbors assumes opclass 0x51!")
+
+ channel = '{:02x}'.format(channel)
+ oper_class = '{:02x}'.format(op_class)
+
+ self.set_neighbor(bssid, ssid, '%s8f000000%s%s060603000000' %
+ (bssid.replace(':', ''), oper_class, channel))
+
+ @classmethod
+ def group_neighbors(cls, *args):
+ for hapd in args:
+ others = [h for h in args if h != hapd]
+
+ hapd._add_neighbors(*others)
diff --git a/autotests/util/iwd.py b/autotests/util/iwd.py
@@ -1091,23 +1091,23 @@ class IWD(AsyncOpAbstract):
some tests do require starting IWD using this constructor (by passing
start_iwd_daemon=True)
'''
- _object_manager_if = None
- _iwd_proc = None
- _devices = None
_default_instance = None
- psk_agents = []
def __init__(self, start_iwd_daemon = False, iwd_config_dir = '/tmp',
- iwd_storage_dir = IWD_STORAGE_DIR, namespace=ctx):
+ iwd_storage_dir = IWD_STORAGE_DIR, namespace=ctx,
+ developer_mode = True):
self.namespace = namespace
self._bus = namespace.get_bus()
+ self._object_manager_if = None
+ self._iwd_proc = None
if start_iwd_daemon:
if self.namespace.is_process_running('iwd'):
raise Exception("IWD requested to start but is already running")
self._iwd_proc = self.namespace.start_iwd(iwd_config_dir,
- iwd_storage_dir)
+ iwd_storage_dir,
+ developer_mode)
self._devices = DeviceList(self)
@@ -1118,6 +1118,8 @@ class IWD(AsyncOpAbstract):
if self.namespace.name is None:
IWD._default_instance = weakref.ref(self)
+ self.psk_agents = []
+
def __del__(self):
for agent in self.psk_agents:
self.unregister_psk_agent(agent)
diff --git a/autotests/util/testutil.py b/autotests/util/testutil.py
@@ -53,6 +53,13 @@ def tx(fromsock, tosock, src, dst):
return (frame, fromsock, tosock, src, dst)
+def tx_packets(if0, if1, num):
+ sock0, addr0 = raw_if_socket(if0)
+ sock1, addr1 = raw_if_socket(if1)
+
+ for i in range(num):
+ tx(sock0, sock1, addr0, addr1)
+
def test_connected(if0=None, if1=None, group=True, expect_fail=False):
if expect_fail:
timeout = 0
diff --git a/client/adapter.c b/client/adapter.c
@@ -319,7 +319,8 @@ static enum cmd_status cmd_set_property(const char *adapter_name,
return CMD_STATUS_TRIGGERED;
}
-static char *set_property_cmd_arg_completion(const char *text, int state)
+static char *set_property_cmd_arg_completion(const char *text, int state,
+ const char *phy)
{
return proxy_property_completion(adapter_properties, text, state);
}
diff --git a/client/command.c b/client/command.c
@@ -213,20 +213,57 @@ bool command_line_find_token(const char *token, uint8_t num_to_inspect)
return false;
}
+/*
+ * Work around readline limitations of not being able to pass a context pointer
+ * to match functions. Set the command match function/entity to these globals
+ * and call a generic match function which can call the _real_ match function
+ * and include the entity.
+ */
+static command_completion_func_t cmd_current_completion_func = NULL;
+static const char *cmd_current_entity = NULL;
+
+static char *cmd_completion_generic(const char *text, int state)
+{
+ return cmd_current_completion_func(text, state, cmd_current_entity);
+}
+
static char **cmd_completion_match_entity_cmd(const char *cmd, const char *text,
const struct command *cmd_list)
{
char **matches = NULL;
size_t i;
+ char *family = NULL;
+ char *entity = NULL;
+ char *prompt = NULL;
for (i = 0; cmd_list[i].cmd; i++) {
+ char *tmp;
+
if (strcmp(cmd_list[i].cmd, cmd))
continue;
if (!cmd_list[i].completion)
break;
- matches = rl_completion_matches(text, cmd_list[i].completion);
+ if (cmd_list[i].entity) {
+ prompt = rl_copy_text(0, rl_end);
+
+ family = strtok_r(prompt, " ", &tmp);
+ if (!family)
+ goto done;
+
+ entity = strtok_r(NULL, " ", &tmp);
+ }
+
+done:
+ cmd_current_completion_func = cmd_list[i].completion;
+ cmd_current_entity = entity;
+
+ matches = rl_completion_matches(text, cmd_completion_generic);
+
+ l_free(prompt);
+ cmd_current_completion_func = NULL;
+ cmd_current_entity = NULL;
break;
}
@@ -292,9 +329,6 @@ static char **cmd_completion_match_family_cmd(const char *cmd_family,
break;
}
- if (family->set_default_entity)
- family->set_default_entity(arg1);
-
matches = cmd_completion_match_entity_cmd(arg2, text,
family->command_list);
@@ -626,21 +660,6 @@ int command_get_exit_status(void)
return exit_status;
}
-void command_reset_default_entities(void)
-{
- const struct l_queue_entry *entry;
-
- for (entry = l_queue_get_entries(command_families); entry;
- entry = entry->next) {
- struct command_family *family = entry->data;
-
- if (!family->reset_default_entity)
- continue;
-
- family->reset_default_entity();
- }
-}
-
void command_family_register(const struct command_family *family)
{
l_queue_push_tail(command_families, (void *) family);
diff --git a/client/command.h b/client/command.h
@@ -25,7 +25,10 @@
#define COMMAND_OPTION_PASSPHRASE "passphrase"
#define COMMAND_OPTION_DONTASK "dont-ask"
-typedef char *(*command_completion_func_t) (const char *text, int state);
+typedef char *(*command_completion_func_t)(const char *text, int state,
+ const char *entity);
+typedef char *(*command_rl_completion_func_t)(const char *text, int state);
+
enum cmd_status {
CMD_STATUS_TRIGGERED,
@@ -51,10 +54,8 @@ struct command_family {
const char *caption;
const char *name;
const struct command *command_list;
- command_completion_func_t family_arg_completion;
- command_completion_func_t entity_arg_completion;
- void (*set_default_entity)(const char *entity);
- void (*reset_default_entity)(void);
+ command_rl_completion_func_t family_arg_completion;
+ command_rl_completion_func_t entity_arg_completion;
};
bool command_option_get(const char *name, const char **value_out);
@@ -71,7 +72,6 @@ void command_noninteractive_trigger(void);
bool command_is_interactive_mode(void);
int command_get_exit_status(void);
void command_set_exit_status(int status);
-void command_reset_default_entities(void);
void command_family_register(const struct command_family *family);
void command_family_unregister(const struct command_family *family);
diff --git a/client/dbus-proxy.c b/client/dbus-proxy.c
@@ -806,8 +806,6 @@ static void service_disappeared_callback(struct l_dbus *dbus,
l_queue_clear(proxy_interfaces, proxy_interface_destroy);
- command_reset_default_entities();
-
display_disable_cmd_prompt();
}
diff --git a/client/dbus-proxy.h b/client/dbus-proxy.h
@@ -34,6 +34,7 @@ struct proxy_interface;
#define IWD_WSC_INTERFACE "net.connman.iwd.SimpleConfiguration"
#define IWD_STATION_INTERFACE "net.connman.iwd.Station"
#define IWD_STATION_DIAGNOSTIC_INTERFACE "net.connman.iwd.StationDiagnostic"
+#define IWD_STATION_DEBUG_INTERFACE "net.connman.iwd.StationDebug"
#define IWD_AP_DIAGNOSTIC_INTERFACE "net.connman.iwd.AccessPointDiagnostic"
#define IWD_DAEMON_INTERFACE "net.connman.iwd.Daemon"
#define IWD_DPP_INTERFACE "net.connman.iwd.DeviceProvisioning"
diff --git a/client/device.c b/client/device.c
@@ -42,8 +42,6 @@ struct device {
const struct proxy_interface *adapter;
};
-static struct proxy_interface *default_device;
-
static void display_device(const struct proxy_interface *proxy)
{
const struct device *device = proxy_interface_get_data(proxy);
@@ -260,52 +258,6 @@ static bool match_by_partial_name(const void *a, const void *b)
return !strncmp(device->name, text, strlen(text));
}
-static bool match_all(const void *a, const void *b)
-{
- return true;
-}
-
-static void device_set_default(const char *device_name)
-{
- struct l_queue *match;
-
- if (!device_name)
- return;
-
- match = proxy_interface_find_all(device_interface_type.interface,
- match_by_name, device_name);
-
- if (!match)
- return;
-
- default_device = l_queue_pop_head(match);
- l_queue_destroy(match, NULL);
-}
-
-static void device_reset_default(void)
-{
- default_device = NULL;
-}
-
-const struct proxy_interface *device_get_default(void)
-{
- struct l_queue *match;
-
- if (default_device)
- return default_device;
-
- match = proxy_interface_find_all(device_interface_type.interface,
- match_all, NULL);
-
- if (!match)
- return NULL;
-
- default_device = l_queue_pop_head(match);
- l_queue_destroy(match, NULL);
-
- return default_device;
-}
-
const struct proxy_interface *device_proxy_find_by_name(const char *name)
{
struct l_queue *match;
@@ -398,7 +350,8 @@ static enum cmd_status cmd_set_property(const char *device_name,
return CMD_STATUS_TRIGGERED;
}
-static char *set_property_cmd_arg_completion(const char *text, int state)
+static char *set_property_cmd_arg_completion(const char *text, int state,
+ const char *device_name)
{
return proxy_property_completion(device_properties, text, state);
}
@@ -463,8 +416,6 @@ static struct command_family device_command_family = {
.command_list = device_commands,
.family_arg_completion = family_arg_completion,
.entity_arg_completion = entity_arg_completion,
- .set_default_entity = device_set_default,
- .reset_default_entity = device_reset_default,
};
static int device_command_family_init(void)
diff --git a/client/known-networks.c b/client/known-networks.c
@@ -387,7 +387,8 @@ static enum cmd_status cmd_set_property(const char *network_name,
return CMD_STATUS_TRIGGERED;
}
-static char *set_property_cmd_arg_completion(const char *text, int state)
+static char *set_property_cmd_arg_completion(const char *text, int state,
+ const char *network_name)
{
return proxy_property_completion(known_network_properties, text, state);
}
diff --git a/client/station-debug.c b/client/station-debug.c
@@ -0,0 +1,443 @@
+#include <ell/ell.h>
+#include "ell/useful.h"
+
+#include "client/command.h"
+#include "client/dbus-proxy.h"
+#include "client/device.h"
+#include "client/display.h"
+#include "client/properties.h"
+#include "client/network.h"
+#include "src/util.h"
+
+struct station_debug {
+ struct l_queue *network_list;
+ bool autoconnect;
+};
+
+struct network {
+ char *ssid;
+ struct l_queue *bss_list;
+};
+
+struct bss {
+ char addr[18];
+ uint32_t frequency;
+ int8_t rssi;
+ int32_t rank;
+ uint8_t mde[3];
+};
+
+static void network_free(void *data)
+{
+ struct network *network = data;
+
+ l_queue_destroy(network->bss_list, l_free);
+}
+
+static void *station_debug_create(void)
+{
+ struct station_debug *debug = l_new(struct station_debug, 1);
+
+ debug->network_list = l_queue_new();
+
+ return debug;
+}
+
+static void station_debug_destroy(void *data)
+{
+ struct station_debug *debug = data;
+
+ l_queue_destroy(debug->network_list, network_free);
+
+ l_free(debug);
+}
+
+static void check_errors_method_callback(struct l_dbus_message *message,
+ void *user_data)
+{
+ dbus_message_has_error(message);
+}
+
+static enum cmd_status cmd_debug_connect(const char *device_name,
+ char **argv, int argc)
+{
+
+ const struct proxy_interface *debug_i;
+ uint8_t addr[6];
+
+ if (argc < 1)
+ return CMD_STATUS_INVALID_ARGS;
+
+ debug_i = device_proxy_find(device_name, IWD_STATION_DEBUG_INTERFACE);
+ if (!debug_i) {
+ display_error("IWD not in developer mode");
+ return CMD_STATUS_INVALID_VALUE;
+ }
+
+ if (!util_string_to_address(argv[0], addr))
+ return CMD_STATUS_INVALID_ARGS;
+
+ proxy_interface_method_call(debug_i, "ConnectBssid", "ay",
+ check_errors_method_callback, 6,
+ addr[0], addr[1], addr[2],
+ addr[3], addr[4], addr[5]);
+ return CMD_STATUS_TRIGGERED;
+}
+
+static enum cmd_status cmd_debug_roam(const char *device_name,
+ char **argv, int argc)
+{
+ const struct proxy_interface *debug_i;
+ uint8_t addr[6];
+
+ if (argc < 1)
+ return CMD_STATUS_INVALID_ARGS;
+
+ debug_i = device_proxy_find(device_name, IWD_STATION_DEBUG_INTERFACE);
+ if (!debug_i) {
+ display_error("IWD not in developer mode");
+ return CMD_STATUS_INVALID_VALUE;
+ }
+
+ if (!util_string_to_address(argv[0], addr))
+ return CMD_STATUS_INVALID_ARGS;
+
+ proxy_interface_method_call(debug_i, "Roam", "ay",
+ check_errors_method_callback, 6,
+ addr[0], addr[1], addr[2],
+ addr[3], addr[4], addr[5]);
+ return CMD_STATUS_TRIGGERED;
+}
+
+static void get_byte_array(struct l_dbus_message_iter *variant, uint8_t *out,
+ unsigned int len)
+{
+ struct l_dbus_message_iter array;
+ uint32_t elems = 6;
+ uint8_t *a;
+
+ if (!l_dbus_message_iter_get_variant(variant, "ay", &array))
+ goto error;
+
+ if (!l_dbus_message_iter_get_fixed_array(&array, &a, &elems))
+ goto error;
+
+ if (elems != len)
+ goto error;
+
+ memcpy(out, a, len);
+
+ return;
+
+error:
+ display_error("Invalid Address element");
+}
+
+static void get_address(struct l_dbus_message_iter *variant,
+ char addr_out[static 18])
+{
+ char *s;
+
+ if (!l_dbus_message_iter_get_variant(variant, "s", &s))
+ goto error;
+
+ if (strlen(s) != 17)
+ goto error;
+
+ strcpy(addr_out, s);
+
+ return;
+
+error:
+ display_error("Invalid Address element");
+}
+
+static uint32_t get_u32(struct l_dbus_message_iter *variant)
+{
+ uint32_t u32 = 0;
+
+ if (!l_dbus_message_iter_get_variant(variant, "u", &u32))
+ display_error("Invalid Frequency element");
+
+ return u32;
+}
+
+static uint32_t get_u16(struct l_dbus_message_iter *variant)
+{
+ uint32_t u16 = 0;
+
+ if (!l_dbus_message_iter_get_variant(variant, "q", &u16))
+ display_error("Invalid Frequency element");
+
+ return u16;
+}
+
+static uint32_t get_i32(struct l_dbus_message_iter *variant)
+{
+ int32_t i32 = 0;
+
+ if (!l_dbus_message_iter_get_variant(variant, "i", &i32))
+ display_error("Invalid Frequency element");
+
+ return i32;
+}
+
+static void display_bss(struct bss *bss)
+{
+ char row[128];
+
+ sprintf(row, "%s%-*s %s %-*i %-*u %-*i %02x%02x%02x",
+ MARGIN MARGIN, 4, "", bss->addr, 4, bss->rssi,
+ 6, bss->frequency, 8, bss->rank,
+ bss->mde[0], bss->mde[1], bss->mde[2]);
+
+ display("%s\n", row);
+
+ return;
+}
+
+static void get_networks_method_callback(struct l_dbus_message *message,
+ void *user_data)
+{
+ struct proxy_interface *debug_i = user_data;
+ struct station_debug *debug = proxy_interface_get_data(debug_i);
+ struct l_dbus_message_iter iter;
+ struct l_dbus_message_iter variant;
+ struct l_dbus_message_iter array;
+ struct l_dbus_message_iter dict;
+ const char *key;
+
+ if (dbus_message_has_error(message))
+ return;
+
+ if (!l_dbus_message_get_arguments(message, "a{oaa{sv}}", &iter)) {
+ l_error("Failed to parse GetDiagnostics message");
+ return;
+ }
+
+ display_table_header("Available Networks (debug)",
+ "%s%-*s %-*s %-*s %-*s %-*s %-*s %-*s",
+ "", 2, "", 4, "SSID", 17, "BSSID", 4, "RSSI",
+ 6, "Freq", 8, "Rank", 10, "MDE");
+
+ while (l_dbus_message_iter_next_entry(&iter, &key, &array)) {
+ struct network *network = l_new(struct network, 1);
+ const struct proxy_interface *net_i = network_get_proxy(key);
+
+ network->ssid = l_strdup(network_get_name(net_i));
+ network->bss_list = l_queue_new();
+
+ display_table_row(MARGIN MARGIN, 3, 32, network->ssid,
+ 18, "", 6, "");
+
+ while (l_dbus_message_iter_next_entry(&array, &dict)) {
+ struct bss *bss = l_new(struct bss, 1);
+
+ while (l_dbus_message_iter_next_entry(&dict, &key,
+ &variant)) {
+ if (!strcmp(key, "Address"))
+ get_address(&variant, bss->addr);
+ else if (!strcmp(key, "Frequency"))
+ bss->frequency = get_u32(&variant);
+ else if (!strcmp(key, "RSSI"))
+ bss->rssi = get_i32(&variant);
+ else if (!strcmp(key, "Rank"))
+ bss->rank = get_u16(&variant);
+ else if (!strcmp(key, "MDE"))
+ get_byte_array(&variant, bss->mde, 3);
+ }
+
+ display_bss(bss);
+
+ l_queue_push_tail(network->bss_list, bss);
+ }
+
+ l_queue_push_tail(debug->network_list, network);
+ }
+
+ display_table_footer();
+}
+
+static enum cmd_status cmd_debug_get_networks(const char *device_name,
+ char **argv, int argc)
+{
+ const struct proxy_interface *debug_i;
+
+ debug_i = device_proxy_find(device_name, IWD_STATION_DEBUG_INTERFACE);
+ if (!debug_i) {
+ display_error("IWD not in developer mode");
+ return CMD_STATUS_INVALID_VALUE;
+ }
+
+ proxy_interface_method_call(debug_i, "GetNetworks", "",
+ get_networks_method_callback);
+
+ return CMD_STATUS_TRIGGERED;
+}
+
+static char *connect_debug_cmd_arg_completion(const char *text, int state,
+ const char *device_name)
+{
+ const struct proxy_interface *debug_i;
+ struct station_debug *debug;
+ static const struct l_queue_entry *n_entry;
+ static const struct l_queue_entry *b_entry;
+ size_t len = strlen(text);
+
+ debug_i = device_proxy_find(device_name, IWD_STATION_DEBUG_INTERFACE);
+ if (!debug_i)
+ return NULL;
+
+ debug = proxy_interface_get_data(debug_i);
+
+ if (!state)
+ n_entry = l_queue_get_entries(debug->network_list);
+
+ while (n_entry) {
+ struct network *network = n_entry->data;
+
+ n_entry = n_entry->next;
+
+ if (!b_entry)
+ b_entry = l_queue_get_entries(network->bss_list);
+
+ while (b_entry) {
+ struct bss *bss = b_entry->data;
+
+ b_entry = b_entry->next;
+
+ if (len > strlen(bss->addr))
+ return NULL;
+
+ if (strncmp(text, bss->addr, len))
+ continue;
+
+ return l_strdup_printf(MAC, MAC_STR(bss->addr));
+ }
+ }
+
+ return NULL;
+}
+
+static const char *get_autoconnect_tostr(const void *data)
+{
+ const struct station_debug *debug = data;
+
+ return debug->autoconnect ? "on" : "off";
+}
+
+static void update_autoconnect(void *data, struct l_dbus_message_iter *variant)
+{
+ struct station_debug *debug = data;
+ bool value;
+
+ if (!l_dbus_message_iter_get_variant(variant, "b", &value)) {
+ debug->autoconnect = false;
+
+ return;
+ }
+
+ debug->autoconnect = value;
+}
+
+static const struct proxy_interface_property debug_properties[] = {
+ { "AutoConnect", "b", update_autoconnect, get_autoconnect_tostr, true,
+ properties_builder_append_on_off_variant,
+ properties_on_off_opts },
+ { }
+};
+
+static enum cmd_status cmd_debug_set_autoconnect(const char *device_name,
+ char **argv, int argc)
+{
+ const struct proxy_interface *proxy = device_proxy_find(device_name,
+ IWD_STATION_DEBUG_INTERFACE);
+
+ if (!proxy) {
+ display_error("IWD not in developer mode");
+ return CMD_STATUS_INVALID_VALUE;
+ }
+
+ if (argc != 1)
+ return CMD_STATUS_INVALID_ARGS;
+
+ if (!proxy_property_set(proxy, "AutoConnect", argv[0],
+ check_errors_method_callback))
+ return CMD_STATUS_INVALID_VALUE;
+
+ return CMD_STATUS_TRIGGERED;
+}
+
+static const struct command station_debug_commands[] = {
+ { "<wlan>", "connect", "<bssid>", cmd_debug_connect,
+ "Connect to a specific BSS", false,
+ connect_debug_cmd_arg_completion },
+ { "<wlan>", "roam", "<bssid>", cmd_debug_roam,
+ "Roam to a BSS", false },
+ { "<wlan>", "get-networks", NULL, cmd_debug_get_networks,
+ "Get networks", true },
+ { "<wlan>", "autoconnect", "on|off", cmd_debug_set_autoconnect,
+ "Set AutoConnect property", false },
+ { }
+};
+
+static char *family_debug_arg_completion(const char *text, int state)
+{
+ return device_arg_completion(text, state, station_debug_commands,
+ IWD_STATION_DEBUG_INTERFACE);
+}
+
+static char *entity_debug_arg_completion(const char *text, int state)
+{
+ return command_entity_arg_completion(text, state,
+ station_debug_commands);
+}
+
+static struct command_family station_debug_command_family = {
+ .caption = "Station Debug",
+ .name = "debug",
+ .command_list = station_debug_commands,
+ .family_arg_completion = family_debug_arg_completion,
+ .entity_arg_completion = entity_debug_arg_completion,
+};
+
+static int station_debug_command_family_init(void)
+{
+ command_family_register(&station_debug_command_family);
+
+ return 0;
+}
+
+static void station_debug_command_family_exit(void)
+{
+ command_family_unregister(&station_debug_command_family);
+}
+
+COMMAND_FAMILY(station_debug_command_family, station_debug_command_family_init,
+ station_debug_command_family_exit)
+
+static const struct proxy_interface_type_ops station_debug_ops = {
+ .create = station_debug_create,
+ .destroy = station_debug_destroy,
+};
+
+static struct proxy_interface_type station_debug_interface_type = {
+ .interface = IWD_STATION_DEBUG_INTERFACE,
+ .ops = &station_debug_ops,
+ .properties = debug_properties,
+};
+
+static int station_debug_interface_init(void)
+{
+ proxy_interface_type_register(&station_debug_interface_type);
+
+ return 0;
+}
+
+static void station_debug_interface_exit(void)
+{
+ proxy_interface_type_unregister(&station_debug_interface_type);
+}
+
+INTERFACE_TYPE(station_debug_interface_type, station_debug_interface_init,
+ station_debug_interface_exit)
diff --git a/client/station.c b/client/station.c
@@ -277,9 +277,11 @@ static enum cmd_status cmd_list(const char *device_name, char **argv, int argc)
return CMD_STATUS_DONE;
}
-static char *connect_cmd_arg_completion(const char *text, int state)
+static char *connect_cmd_arg_completion(const char *text, int state,
+ const char *device_name)
{
- const struct proxy_interface *device = device_get_default();
+ const struct proxy_interface *device = device_proxy_find(device_name,
+ IWD_STATION_INTERFACE);
if (!device)
return NULL;
@@ -489,7 +491,8 @@ static void ordered_networks_callback(struct l_dbus_message *message,
l_queue_destroy(networks, ordered_networks_destroy);
}
-static char *get_networks_cmd_arg_completion(const char *text, int state)
+static char *get_networks_cmd_arg_completion(const char *text, int state,
+ const char *device_name)
{
static int index;
static int len;
diff --git a/configure.ac b/configure.ac
@@ -1,5 +1,5 @@
AC_PREREQ([2.69])
-AC_INIT([iwd],[1.29])
+AC_INIT([iwd],[1.30])
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.52"
+ ell_min_version="0.53"
else
ell_min_version="0.5"
fi
diff --git a/doc/network-api.txt b/doc/network-api.txt
@@ -7,9 +7,9 @@ Object path /net/connman/iwd/{phy0,phy1,...}/{1,2,...}/Xxx
Methods void Connect()
- Connect to the network. Request the device
- implied by the object path to connect to specified
- network.
+ Connect to the network. Request the device implied by
+ the object path to connect to specified network.
+ Connecting to WEP networks is not supported.
Possible errors: net.connman.iwd.Aborted
net.connman.iwd.Busy
@@ -42,7 +42,7 @@ Properties string Name [readonly]
string Type [readonly]
Contains the type of the network. Possible
- types are "open", "psk", "8021x" (EAP)
+ types are "open", "wep", "psk", or "8021x" (EAP)
object KnownNetwork [readonly, optional]
diff --git a/doc/station-debug-api.txt b/doc/station-debug-api.txt
@@ -0,0 +1,68 @@
+Station Debug hierarchy [experimental]
+============================
+
+These are all development APIs not meant for production use.
+
+Service net.connman.iwd
+Interface net.connman.iwd.StationDebug
+Object path /net/connman/iwd/{phy0,phy1,...}/{1,2,...}
+
+Methods void ConnectBssid(array(y) address)
+
+ Connect to a specific BSS. The address parameter should
+ be a byte array of length 6, the BSSID of a BSS which
+ IWD already has in its scan list.
+
+ Possible errors: net.connman.iwd.InvalidArguments
+ net.connman.iwd.NotFound
+
+ void Roam(array(y) address)
+
+ Roam to a specific BSS. The address parameter should be
+ a byte array of length 6, the BSSID of a BSS to roam to.
+ This BSS needs to be in IWD's scan results and fit the
+ requirements for a roam candidate (same network).
+ The type of roam is dependent on the network and is
+ chosen automatically by IWD.
+
+ Possible errors: net.connman.iwd.InvalidArguments
+ net.connman.iwd.NotConnected
+
+ void Scan(array(q) frequencies)
+
+ Scan on specific frequencies. The frequencies parameter
+ should be a list of valid frequencies.
+
+ Possible errors: net.connman.iwd.Busy
+ net.connman.iwd.InvalidArguments
+ net.connamn.iwd.Failed
+
+ a{oaa{sv}} GetNetworks()
+
+ Get a list of networks including data for individual
+ BSS's. Returns a dictionary where keys are network
+ object paths and values are arrays of dictionaries
+ containing BSS information:
+
+ {
+ /network/path/1: [
+ {
+ Address: 11:22:33:44:55,
+ Frequency: 1234,
+ RSSI: -20,
+ Rank: 1000
+ MDE: 001122
+ },
+ { ... }
+ ]
+ }
+
+Signals: Event(s name, av data)
+
+ Signal sent for various debug events. The 'name' is the
+ event name, and 'data' is event dependent.
+
+Properties: boolean AutoConnect
+
+ True if IWD is in an autoconnect state. This property
+ can be written to put IWD into an autoconnect state.
diff --git a/monitor/nlmon.c b/monitor/nlmon.c
@@ -139,7 +139,8 @@ struct attr_entry {
uint16_t attr;
const char *str;
enum attr_type type;
- union {
+
+ struct {
const struct attr_entry *nested;
enum attr_type array_type;
attr_func_t function;
@@ -2278,6 +2279,121 @@ static void print_rsnx(unsigned int level, const char *label,
print_attr(level + 1, "SAE Hash-to-Element");
}
+static void print_bss_parameters(unsigned int level, uint8_t parameters)
+{
+ print_attr(level, "BSS Parameters");
+
+ if (test_bit(¶meters, 0))
+ print_attr(level + 1, "OCT Recommended");
+
+ if (test_bit(¶meters, 1))
+ print_attr(level + 1, "Same SSID");
+
+ if (test_bit(¶meters, 2))
+ print_attr(level + 1, "Multiple BSSID");
+
+ if (test_bit(¶meters, 3))
+ print_attr(level + 1, "Transmitted BSSID");
+
+ if (test_bit(¶meters, 4))
+ print_attr(level + 1, "2.4/5GHz Co-Located ESS member");
+
+ if (test_bit(¶meters, 5))
+ print_attr(level + 1, "Unsolicited Probe Responses Active");
+
+ if (test_bit(¶meters, 6))
+ print_attr(level + 1, "Co-Located AP");
+}
+
+static void print_reduced_neighbor_report(unsigned int level, const char *label,
+ const void *data, uint16_t size)
+{
+ const uint8_t *ptr = data;
+ unsigned int field_count = 0;
+
+ print_attr(level, "%s", label);
+
+ if (size < 5) {
+ print_attr(level + 1, "error parsing");
+ return;
+ }
+
+ level++;
+
+ while (ptr < (uint8_t *)data + size) {
+ uint16_t hdr = l_get_le16(ptr);
+ uint8_t oper = l_get_u8(ptr + 2);
+ uint8_t chan = l_get_u8(ptr + 3);
+ uint8_t count = bit_field((uint8_t)(hdr & 0xff), 4, 4);
+ uint8_t type = bit_field((uint8_t)(hdr & 0xff), 0, 2);
+ uint8_t filtered = test_bit(&hdr, 2);
+ uint8_t info_size = (hdr & 0xff00) >> 8;
+ uint8_t i;
+
+ ptr += 4;
+
+ print_attr(level, "Field #%u", field_count);
+
+ /* TBTT Information Header */
+ print_attr(level + 1, "Info Field Type: %u", type);
+ print_attr(level + 1, "Filtered Neighbor AP: %u", filtered);
+ print_attr(level + 1, "Information Count: %u", count);
+ print_attr(level + 1, "Information Length: %u", info_size);
+
+ print_attr(level + 1, "Operating Class: %u", oper);
+ print_attr(level + 1, "Channel: %u", chan);
+
+ level++;
+
+ /* Information Set(s) */
+ for (i = 0; i <= count; i++) {
+ const uint8_t *info = ptr;
+
+ if (info + info_size > (uint8_t *)data + size ||
+ info_size == 0 || info_size == 3 ||
+ info_size == 4 || info_size == 10) {
+ print_attr(level + 1, "error parsing");
+ return;
+ }
+
+ print_attr(level, "Information Set #%u", i);
+
+ if (info_size >= 1)
+ print_attr(level + 1,
+ "Neighbor TBTT Offset: %u TU's",
+ l_get_u8(info++));
+
+ if (info_size >= 7) {
+ print_attr(level + 1, "BSSID: "MAC,
+ MAC_STR(info));
+ info += 6;
+ }
+
+ if (info_size == 5 || info_size == 6 ||
+ info_size >= 11) {
+ print_attr(level + 1, "Short SSID: %08x",
+ l_get_u32(info));
+ info += 4;
+ }
+
+ if (info_size == 2 || info_size == 6 ||
+ info_size == 8 || info_size == 9 ||
+ info_size >= 12)
+ print_bss_parameters(level + 1, *info++);
+
+ if (info_size == 9 || info_size >= 13)
+ print_attr(level + 1, "20 MHz PSD: %d",
+ (int8_t)*info++);
+
+ ptr += info_size;
+ }
+
+ level--;
+
+ field_count++;
+ }
+}
+
static struct attr_entry ie_entry[] = {
{ IE_TYPE_SSID, "SSID",
ATTR_CUSTOM, { .function = print_ie_ssid } },
@@ -2340,6 +2456,8 @@ static struct attr_entry ie_entry[] = {
ATTR_CUSTOM, { .function = print_fast_bss_transition } },
{ IE_TYPE_MOBILITY_DOMAIN, "Mobility Domain",
ATTR_CUSTOM, { .function = print_mobility_domain } },
+ { IE_TYPE_REDUCED_NEIGHBOR_REPORT, "Reduced Neighbor Report",
+ ATTR_CUSTOM, { .function = print_reduced_neighbor_report } },
{ IE_TYPE_RSNX, "RSNX",
ATTR_CUSTOM, { .function = print_rsnx } },
{ },
@@ -5421,6 +5539,24 @@ static void print_band_rates(unsigned int level, const char *label,
}
}
+static const struct attr_entry iftype_data_table[] = {
+ { NL80211_BAND_IFTYPE_ATTR_IFTYPES, "Interface Types", ATTR_NESTED,
+ { iftype_table } },
+ { NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, "HE MAC Capabilities",
+ ATTR_BINARY },
+ { NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, "HE PHY Capabilities",
+ ATTR_BINARY },
+ { NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, "HE NSS/MCS Set",
+ ATTR_BINARY },
+ { NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, "HE PPE Thresholds",
+ ATTR_BINARY },
+ { NL80211_BAND_IFTYPE_ATTR_MAX, "Highest band HE capability attribute",
+ ATTR_BINARY },
+ { NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA, "HE 6GHz band capabilities",
+ ATTR_BINARY },
+ { }
+};
+
static const struct attr_entry wiphy_bands_table[] = {
{ NL80211_BAND_ATTR_FREQS, "Frequencies",
ATTR_CUSTOM, { .function = print_band_frequencies } },
@@ -5434,6 +5570,8 @@ static const struct attr_entry wiphy_bands_table[] = {
{ NL80211_BAND_ATTR_HT_AMPDU_DENSITY, "AMPDU Density" },
{ NL80211_BAND_ATTR_VHT_MCS_SET, "VHT MCS Set" },
{ NL80211_BAND_ATTR_VHT_CAPA, "VHT Capabilities" },
+ { NL80211_BAND_ATTR_IFTYPE_DATA, "Interface Type Data",
+ ATTR_ARRAY, { iftype_data_table, ATTR_NESTED } },
{ }
};
@@ -6574,6 +6712,7 @@ static void print_value(int indent, const char *label, enum attr_type type,
}
static void print_array(int indent, enum attr_type type,
+ const struct attr_entry *entry,
const void *buf, uint32_t len)
{
const struct nlattr *nla;
@@ -6583,8 +6722,20 @@ static void print_array(int indent, enum attr_type type,
char str[8];
snprintf(str, sizeof(str), "%u", nla_type);
- print_value(indent, str, type,
+
+ switch (type) {
+ case ATTR_NESTED:
+ if (entry->nested)
+ print_attributes(indent + 1, entry->nested,
+ NLA_DATA(nla), NLA_PAYLOAD(nla));
+ else
+ printf("missing nested table\n");
+ break;
+ default:
+ print_value(indent, str, type,
NLA_DATA(nla), NLA_PAYLOAD(nla));
+ break;
+ }
}
}
@@ -6610,7 +6761,7 @@ static void print_attributes(int indent, const struct attr_entry *table,
int64_t val_s64;
uint8_t *ptr;
- str = "Reserved";
+ str = "Unknown";
type = ATTR_UNSPEC;
array_type = ATTR_UNSPEC;
nested = NULL;
@@ -6630,7 +6781,7 @@ static void print_attributes(int indent, const struct attr_entry *table,
switch (type) {
case ATTR_UNSPEC:
- print_attr(indent, "%s: len %u", str,
+ print_attr(indent, "%s: %u len %u", str, nla_type,
NLA_PAYLOAD(nla));
print_hexdump(indent + 1,
NLA_DATA(nla), NLA_PAYLOAD(nla));
@@ -6715,7 +6866,7 @@ static void print_attributes(int indent, const struct attr_entry *table,
NLA_PAYLOAD(nla));
if (array_type == ATTR_UNSPEC)
printf("missing type\n");
- print_array(indent + 1, array_type,
+ print_array(indent + 1, array_type, &table[i],
NLA_DATA(nla), NLA_PAYLOAD(nla));
break;
case ATTR_FLAG_OR_U16:
diff --git a/src/band.c b/src/band.c
@@ -28,10 +28,14 @@
#include "ell/useful.h"
-#include "band.h"
+#include "src/band.h"
+#include "src/netdev.h"
void band_free(struct band *band)
{
+ if (band->he_capabilities)
+ l_queue_destroy(band->he_capabilities, l_free);
+
l_free(band);
}
@@ -122,14 +126,21 @@ int band_estimate_nonht_rate(const struct band *band,
}
/*
- * Base RSSI values for 20MHz (both HT and VHT) channel. These values can be
+ * Base RSSI values for 20MHz (HT, VHT and HE) channel. These values can be
* used to calculate the minimum RSSI values for all other channel widths. HT
- * MCS indexes are grouped into ranges of 8 (per spatial stream) where VHT are
- * grouped in chunks of 10. This just means HT will not use the last two
- * index's of this array.
+ * MCS indexes are grouped into ranges of 8 (per spatial stream), VHT in groups
+ * of 10 and HE in groups of 12. This just means HT will not use the last four
+ * index's of this array, and VHT won't use the last two.
+ *
+ * Note: The values here are not based on anything from 802.11 but data
+ * found elsewhere online (presumably from testing, we hope). The two
+ * indexes for HE (MCS 11/12) are not based on any data, but just
+ * increased by 3dB compared to the previous value. We consider this good
+ * enough for its purpose to estimate the date rate for network/BSS
+ * preference.
*/
-static const int32_t ht_vht_base_rssi[] = {
- -82, -79, -77, -74, -70, -66, -65, -64, -59, -57
+static const int32_t ht_vht_he_base_rssi[] = {
+ -82, -79, -77, -74, -70, -66, -65, -64, -59, -57, -54, -51
};
/*
@@ -191,7 +202,7 @@ bool band_ofdm_rate(uint8_t index, enum ofdm_channel_width width,
uint64_t rate;
int32_t width_adjust = width * 3;
- if (rssi < ht_vht_base_rssi[index] + width_adjust)
+ if (rssi < ht_vht_he_base_rssi[index] + width_adjust)
return false;
rate = ht_vht_rates[width][index];
@@ -331,6 +342,56 @@ static bool find_best_mcs_vht(uint8_t max_index, enum ofdm_channel_width width,
return false;
}
+static bool find_best_mcs_nss(const uint8_t *rx_map, const uint8_t *tx_map,
+ uint8_t value0, uint8_t value1, uint8_t value2,
+ uint32_t *mcs_out, uint32_t *nss_out)
+{
+ uint32_t nss = 0;
+ uint32_t max_mcs = 0;
+ int bitoffset;
+
+ for (bitoffset = 14; bitoffset >= 0; bitoffset -= 2) {
+ uint8_t rx_val = bit_field(rx_map[bitoffset / 8],
+ bitoffset % 8, 2);
+ uint8_t tx_val = bit_field(tx_map[bitoffset / 8],
+ bitoffset % 8, 2);
+
+ /*
+ * 0 indicates support for MCS 0 - value0
+ * 1 indicates support for MCS 0 - value1
+ * 2 indicates support for MCS 0 - value2
+ * 3 indicates no support
+ */
+
+ if (rx_val == 3 || tx_val == 3)
+ continue;
+
+ /* rx_val/tx_val tells us which value# to use */
+ max_mcs = minsize(rx_val, tx_val);
+ switch (max_mcs) {
+ case 0:
+ max_mcs = value0;
+ break;
+ case 1:
+ max_mcs = value1;
+ break;
+ case 2:
+ max_mcs = value2;
+ break;
+ }
+
+ nss = bitoffset / 2 + 1;
+ break;
+ }
+
+ if (!nss)
+ return false;
+
+ *nss_out = nss;
+ *mcs_out = max_mcs;
+
+ return true;
+}
/*
* IEEE 802.11 - Table 9-250
*
@@ -352,7 +413,6 @@ int band_estimate_vht_rx_rate(const struct band *band,
uint32_t max_mcs = 7; /* MCS 0-7 for NSS:1 is always supported */
const uint8_t *rx_mcs_map;
const uint8_t *tx_mcs_map;
- int bitoffset;
uint8_t chan_width;
uint8_t channel_offset;
bool sgi;
@@ -375,29 +435,7 @@ int band_estimate_vht_rx_rate(const struct band *band,
rx_mcs_map = band->vht_mcs_set;
tx_mcs_map = vhtc + 2 + 8;
- for (bitoffset = 14; bitoffset >= 0; bitoffset -= 2) {
- uint8_t rx_val = bit_field(rx_mcs_map[bitoffset / 8],
- bitoffset % 8, 2);
- uint8_t tx_val = bit_field(tx_mcs_map[bitoffset / 8],
- bitoffset % 8, 2);
-
- /*
- * 0 indicates support for MCS 0-7
- * 1 indicates support for MCS 0-8
- * 2 indicates support for MCS 0-9
- * 3 indicates no support
- */
-
- if (rx_val == 3 || tx_val == 3)
- continue;
-
- /* 7 + rx_val/tx_val gives us the maximum mcs index */
- max_mcs = minsize(rx_val, tx_val) + 7;
- nss = bitoffset / 2 + 1;
- break;
- }
-
- if (!nss)
+ if (!find_best_mcs_nss(rx_mcs_map, tx_mcs_map, 7, 8, 9, &max_mcs, &nss))
return -EBADMSG;
/*
@@ -465,6 +503,186 @@ try_vht80:
return -ENETUNREACH;
}
+/*
+ * Data Rate for HE is much the same as HT/VHT but some additional MCS indexes
+ * were added. This mean rfactors, and nbpscs will contain two additional
+ * values:
+ *
+ * rfactors.extend([3/4, 5/6])
+ * nbpscs.extend([10, 10])
+ *
+ * The guard interval also differs:
+ *
+ * Tdft = 12.8us
+ * Tgi = 0.8, 1.6 or 2.3us
+ *
+ * The Nsd values for HE are:
+ *
+ * Nsd = [234, 468, 980, 1960]
+ *
+ * The formula is identical to HT/VHT:
+ *
+ * Nsd * Nbpscs * R * Nss / (Tdft + Tgi)
+ *
+ * Note: The table below assumes a 0.8us GI. There isn't any way to know what
+ * GI will be used for an actual connection, so assume the best.
+ */
+static uint64_t he_rates[4][12] = {
+ [OFDM_CHANNEL_WIDTH_20MHZ] = {
+ 8600000ULL, 17200000ULL, 25800000ULL, 34400000ULL,
+ 51600000ULL, 68800000ULL, 77400000ULL, 86000000ULL,
+ 103200000ULL, 114700000ULL, 129000000ULL, 143300000ULL,
+ },
+ [OFDM_CHANNEL_WIDTH_40MHZ] = {
+ 17200000ULL, 34400000ULL, 51600000ULL, 68800000ULL,
+ 103200000ULL, 137600000ULL, 154900000ULL, 172000000ULL,
+ 206500000ULL, 229400000ULL, 258000000ULL, 286800000ULL,
+ },
+ [OFDM_CHANNEL_WIDTH_80MHZ] = {
+ 36000000ULL, 72000000ULL, 108000000ULL, 144100000ULL,
+ 216200000ULL, 288200000ULL, 324300000ULL, 360300000ULL,
+ 432400000ULL, 480400000ULL, 540400000ULL, 600500000ULL,
+ },
+ [OFDM_CHANNEL_WIDTH_160MHZ] = {
+ 72000000ULL, 144100000ULL, 216200000ULL, 288200000ULL,
+ 432400000ULL, 576500000ULL, 648500000ULL, 720600000ULL,
+ 864700000ULL, 960800000ULL, 1080900000ULL, 1201000000ULL,
+ },
+};
+
+static bool band_he_rate(uint8_t index, enum ofdm_channel_width width,
+ int32_t rssi, uint8_t nss, uint64_t *data_rate)
+{
+ uint64_t rate;
+ int32_t width_adjust;
+
+ width_adjust = width * 3;
+
+ if (rssi < ht_vht_he_base_rssi[index] + width_adjust)
+ return false;
+
+ rate = he_rates[width][index];
+
+ rate *= nss;
+
+ *data_rate = rate;
+ return true;
+}
+
+static bool find_rate_he(const uint8_t *rx_map, const uint8_t *tx_map,
+ enum ofdm_channel_width width, int32_t rssi,
+ uint64_t *out_data_rate)
+{
+ uint32_t nss;
+ uint32_t max_mcs;
+ int i;
+
+ if (!find_best_mcs_nss(rx_map, tx_map, 7, 9, 11,
+ &max_mcs, &nss))
+ return false;
+
+ for (i = max_mcs; i >= 0; i--)
+ if (band_he_rate(i, width, rssi, nss, out_data_rate))
+ return true;
+
+ return false;
+}
+
+/*
+ * HE data rate is calculated based on 802.11ax - Section 27.5
+ */
+int band_estimate_he_rx_rate(const struct band *band, const uint8_t *hec,
+ int32_t rssi, uint64_t *out_data_rate)
+{
+ enum ofdm_channel_width width = OFDM_CHANNEL_WIDTH_20MHZ;
+ int i;
+ const struct band_he_capabilities *he_cap = NULL;
+ const struct l_queue_entry *entry;
+ const uint8_t *rx_map;
+ const uint8_t *tx_map;
+ uint64_t rate = 0;
+ uint64_t new_rate = 0;
+ uint8_t width_set;
+
+ if (!hec || !band->he_capabilities)
+ return -EBADMSG;
+
+ for (entry = l_queue_get_entries(band->he_capabilities);
+ entry; entry = entry->next) {
+ const struct band_he_capabilities *cap = entry->data;
+
+ /*
+ * TODO: Station type is assumed here since it is the only
+ * consumer of these data rate estimation APIs. If this
+ * changes the iftype would need to be passed in.
+ */
+ if (cap->iftypes & (1 << NETDEV_IFTYPE_STATION)) {
+ he_cap = cap;
+ break;
+ }
+ }
+
+ if (!he_cap)
+ return -ENOTSUP;
+
+ /* AND the width sets, giving the widths supported by both */
+ width_set = bit_field(he_cap->he_phy_capa[0], 1, 7) &
+ bit_field((hec + 6)[0], 1, 7);
+
+ /*
+ * The HE-MCS maps are 17 bytes into the HE Capabilities IE, and
+ * alternate RX/TX every 2 bytes. Start the TX map 17 + 2 bytes
+ * into the MCS set. For each MCS set find the best data rate.
+ */
+ rx_map = he_cap->he_mcs_set;
+ tx_map = hec + 19;
+
+ /*
+ * 802.11ax Table 9-322b
+ *
+ * B3 indicates support for 80+80MHz MCS set
+ */
+ if (test_bit(&width_set, 3)) {
+ if (find_rate_he(rx_map + 8, tx_map + 8,
+ OFDM_CHANNEL_WIDTH_160MHZ,
+ rssi, &new_rate))
+ rate = new_rate;
+ }
+
+ /* B2 indicates support for 160MHz MCS set */
+ if (test_bit(&width_set, 2)) {
+ if (find_rate_he(rx_map + 4, tx_map + 4,
+ OFDM_CHANNEL_WIDTH_160MHZ,
+ rssi, &new_rate) && new_rate > rate)
+ rate = new_rate;
+ }
+
+ /* B1 indicates support for 80MHz */
+ if (test_bit(&width_set, 1))
+ width = OFDM_CHANNEL_WIDTH_80MHZ;
+
+ /* B0 indicates support for 40MHz */
+ if (test_bit(&width_set, 0))
+ width = OFDM_CHANNEL_WIDTH_40MHZ;
+
+ /* <= 80MHz MCS set */
+ for (i = width; i >= OFDM_CHANNEL_WIDTH_20MHZ; i--) {
+ if (find_rate_he(rx_map, tx_map, i, rssi, &new_rate)) {
+ if (new_rate > rate)
+ rate = new_rate;
+
+ break;
+ }
+ }
+
+ if (!rate)
+ return -EBADMSG;
+
+ *out_data_rate = rate;
+
+ return 0;
+}
+
static int band_channel_info_get_bandwidth(const struct band_chandef *info)
{
switch (info->channel_width) {
diff --git a/src/band.h b/src/band.h
@@ -49,7 +49,16 @@ struct band_chandef {
uint32_t center2_frequency;
};
+struct band_he_capabilities {
+ uint32_t iftypes;
+ uint8_t he_phy_capa[11];
+ uint8_t he_mcs_set[12];
+};
+
struct band {
+ enum band_freq freq;
+ /* Each entry is type struct band_he_capabilities */
+ struct l_queue *he_capabilities;
uint8_t vht_mcs_set[8];
uint8_t vht_capabilities[4];
bool vht_supported : 1;
@@ -65,7 +74,8 @@ void band_free(struct band *band);
bool band_ofdm_rate(uint8_t index, enum ofdm_channel_width width,
int32_t rssi, uint8_t nss, bool sgi,
uint64_t *data_rate);
-
+int band_estimate_he_rx_rate(const struct band *band, const uint8_t *hec,
+ int32_t rssi, uint64_t *out_dat_rate);
int band_estimate_vht_rx_rate(const struct band *band,
const uint8_t *vhtc, const uint8_t *vhto,
const uint8_t *htc, const uint8_t *hto,
diff --git a/src/device.c b/src/device.c
@@ -276,6 +276,8 @@ static void device_wiphy_state_changed_event(struct wiphy *wiphy,
switch (event) {
case WIPHY_STATE_WATCH_EVENT_RFKILLED:
+ case WIPHY_STATE_WATCH_EVENT_REGDOM_STARTED:
+ case WIPHY_STATE_WATCH_EVENT_REGDOM_DONE:
break;
case WIPHY_STATE_WATCH_EVENT_POWERED:
if (device->dbus_powered)
diff --git a/src/handshake.h b/src/handshake.h
@@ -137,6 +137,7 @@ struct handshake_state {
bool authenticator_ocvc : 1;
bool supplicant_ocvc : 1;
bool ext_key_id_capable : 1;
+ bool force_default_owe_group : 1;
uint8_t ssid[32];
size_t ssid_len;
char *passphrase;
diff --git a/src/ie.c b/src/ie.c
@@ -2577,3 +2577,51 @@ int ie_parse_oci(const void *data, size_t len, const uint8_t **oci)
return 0;
}
+
+/*
+ * Checks the supported width set (Table 9-322b) meets the following
+ * requirements:
+ * - B0 and bits B1/B2/B3 are mutually exclusive.
+ * - B2 is only set if B1 is set
+ * - B3 is only set if B2 is set (and in turn, B1 is set)
+ * - The IE length supports B2 and B3 MCS sets
+ */
+bool ie_validate_he_capabilities(const void *data, size_t len)
+{
+ uint8_t width_set;
+ const uint8_t *ptr = data;
+ bool freq_2_4;
+ bool width_40_80;
+ bool width_160;
+ bool width_80p80;
+
+ if (len < 22)
+ return false;
+
+ width_set = bit_field((ptr + 7)[0], 1, 7);
+
+ /* B0 indicates support for 40MHz, but only in 2.4GHz band */
+ freq_2_4 = test_bit(&width_set, 0);
+
+ /* B1 indicates support for 40/80MHz */
+ width_40_80 = test_bit(&width_set, 1);
+
+ if (width_40_80 && freq_2_4)
+ return false;
+
+ /* B2 indicates support for 160MHz MCS table */
+ width_160 = test_bit(&width_set, 2);
+
+ /* Ensure B1 is set, not B0, and the length includes this MCS table */
+ if (width_160 && (!width_40_80 || freq_2_4 || len < 26))
+ return false;
+
+ /* B3 indicates support for 80+80Mhz MCS table */
+ width_80p80 = test_bit(&width_set, 3);
+
+ /* Ensure B2 is set, not B0, and the length includes this MCS table */
+ if (width_80p80 && (!width_160 || freq_2_4 || len < 30))
+ return false;
+
+ return true;
+}
diff --git a/src/ie.h b/src/ie.h
@@ -274,10 +274,29 @@ enum ie_type {
IE_TYPE_OWE_DH_PARAM = 256 + 32,
IE_TYPE_PASSWORD_IDENTIFIER = 256 + 33,
IE_TYPE_GLK_GCR_PARAMETER_SET = 256 + 34,
+ IE_TYPE_HE_CAPABILITIES = 256 + 35,
+ IE_TYPE_HE_OPERATION = 256 + 36,
+ IE_TYPE_UORA_PARAMETER_SET = 256 + 37,
+ IE_TYPE_MU_EDCA_PARAMETER_SET = 256 + 38,
+ IE_TYPE_SPATIAL_REUSE_PARAMETER_SET = 256 + 39,
+ /* Reserved 40 */
+ IE_TYPE_NDP_FEEDBACK_REPORT_PARAMETER = 256 + 41,
+ IE_TYPE_BSS_COLOR_CHANGE_ANNOUNCEMENT = 256 + 42,
+ IE_TYPE_QUIET_TIME_PERIOD = 256 + 43,
IE_TYPE_VENDOR_SPECIFIC_REQUEST = 256 + 44,
+ IE_TYPE_ESS_REPORT = 256 + 45,
+ IE_TYPE_OPS = 256 + 46,
+ IE_TYPE_HE_BSS_LOAD = 256 + 47,
IE_TYPE_MAX_CHANNEL_SWITCH_TIME = 256 + 52,
IE_TYPE_ESTIMATED_SERVICE_PARAMETERS_OUT = 256 + 53,
IE_TYPE_OCI = 256 + 54,
+ IE_TYPE_MULTIPLE_BSSID_CONFIGURATION = 256 + 55,
+ /* Reserved 56 */
+ IE_TYPE_KNOWN_BSSID = 256 + 57,
+ IE_TYPE_SHORT_SSID_LIST = 256 + 58,
+ IE_TYPE_HE_6GHZ_BAND_CAPABILITIES = 256 + 59,
+ IE_TYPE_UL_MU_POWER_CAPABILITIES = 256 + 60,
+ /* Reserved 61 - 87 */
IE_TYPE_MSCS_DESCRIPTOR = 256 + 88,
IE_TYPE_SUPPLEMENTAL_CLASS_2_CAPABILITIES = 256 + 90,
IE_TYPE_REJECTED_GROUPS = 256 + 92,
@@ -663,3 +682,5 @@ int ie_parse_owe_transition(const void *data, size_t len,
struct ie_owe_transition_info *info);
int ie_parse_oci(const void *data, size_t len, const uint8_t **oci);
+
+bool ie_validate_he_capabilities(const void *data, size_t len);
diff --git a/src/iwd.config.rst b/src/iwd.config.rst
@@ -247,15 +247,6 @@ The group ``[Network]`` contains network configuration related settings.
If not specified, ``300`` is used as default.
- * - MulticastDNS
- - Values: true, false, resolve
-
- Configures multicast DNS on each interface. If not specified,
- systemd-resolved's default value will remain untouched.
- See ``man 5 systemd.network`` for details.
-
- Only applies when ``NameResolvingService=systemd``.
-
Blacklist
---------
diff --git a/src/iwd.network.rst b/src/iwd.network.rst
@@ -316,6 +316,25 @@ connect to that network.
Network Configuration Settings
------------------------------
+The group ``[Network]`` contains general network settings and any network
+specific overrides for global defaults defined in the main iwd configuration
+file.
+
+.. list-table::
+ :header-rows: 0
+ :stub-columns: 0
+ :widths: 20 80
+ :align: left
+
+ * - MulticastDNS
+ - Values: true, false, resolve
+
+ Configures multicast DNS for this network. If not specified,
+ systemd-resolved's default value will remain untouched.
+ See ``man 5 systemd.network`` for details.
+
+ Only applies when ``NameResolvingService=systemd``.
+
The group ``[IPv4]`` contains settings for Internet Protocol version 4 (IPv4)
network configuration with the static addresses.
diff --git a/src/manager.c b/src/manager.c
@@ -49,6 +49,7 @@ static char **whitelist_filter;
static char **blacklist_filter;
static bool randomize;
static bool use_default;
+static unsigned int config_watch;
struct wiphy_setup_state {
uint32_t id;
@@ -754,7 +755,7 @@ static void manager_config_notify(struct l_genl_msg *msg, void *user_data)
if (!wiphy_find(wiphy_id)) {
l_warn("Received a NEW_INTERFACE for a wiphy id"
- " that isn't tracked. This is most ikely a"
+ " that isn't tracked. This is most likely a"
" kernel bug where NEW_WIPHY events that are"
" too large are dropped on the floor."
" Attempting a workaround...");
@@ -820,8 +821,10 @@ static int manager_init(void)
pending_wiphys = l_queue_new();
- if (!l_genl_family_register(nl80211, "config", manager_config_notify,
- NULL, NULL)) {
+ config_watch = l_genl_family_register(nl80211, "config",
+ manager_config_notify,
+ NULL, NULL);
+ if (!config_watch) {
l_error("Registering for config notifications failed");
goto error;
}
@@ -880,6 +883,8 @@ static void manager_exit(void)
l_strfreev(whitelist_filter);
l_strfreev(blacklist_filter);
+ l_genl_family_unregister(nl80211, config_watch);
+
l_queue_destroy(pending_wiphys, wiphy_setup_state_free);
pending_wiphys = NULL;
diff --git a/src/netdev.c b/src/netdev.c
@@ -1073,6 +1073,7 @@ static void netdev_cqm_event(struct l_genl_msg *msg, struct netdev *netdev)
const void *data;
uint32_t *rssi_event = NULL;
int32_t *rssi_val = NULL;
+ uint32_t *pkt_event = NULL;
if (!l_genl_attr_init(&attr, msg))
return;
@@ -1092,12 +1093,25 @@ static void netdev_cqm_event(struct l_genl_msg *msg, struct netdev *netdev)
rssi_event = (uint32_t *) data;
break;
+ case NL80211_ATTR_CQM_PKT_LOSS_EVENT:
+ if (len != 4)
+ continue;
+
+ pkt_event = (uint32_t *) data;
+ break;
+
+ case NL80211_ATTR_CQM_BEACON_LOSS_EVENT:
+ l_debug("Beacon lost event");
+ break;
+
case NL80211_ATTR_CQM_RSSI_LEVEL:
if (len != 4)
continue;
rssi_val = (int32_t *) data;
break;
+ default:
+ l_debug("Unknown CQM event: %d", type);
}
}
@@ -1106,11 +1120,17 @@ static void netdev_cqm_event(struct l_genl_msg *msg, struct netdev *netdev)
}
if (rssi_event) {
- if (rssi_val)
+ if (rssi_val) {
+ l_debug("Signal change event (above=%d signal=%d)",
+ *rssi_event, *rssi_val);
netdev_cqm_event_rssi_value(netdev, *rssi_val);
- else
+ } else {
+ l_debug("Signal change event (above=%d)", *rssi_event);
netdev_cqm_event_rssi_threshold(netdev, *rssi_event);
- }
+ }
+ } else if (pkt_event && netdev->event_filter)
+ netdev->event_filter(netdev, NETDEV_EVENT_PACKET_LOSS_NOTIFY,
+ pkt_event, netdev->user_data);
}
static void netdev_rekey_offload_event(struct l_genl_msg *msg,
@@ -3957,8 +3977,8 @@ offload_1x:
}
static void netdev_connect_common(struct netdev *netdev,
- struct scan_bss *bss,
- struct scan_bss *prev_bss,
+ const struct scan_bss *bss,
+ const struct scan_bss *prev_bss,
struct handshake_state *hs,
const struct iovec *vendor_ies,
size_t num_vendor_ies,
@@ -4051,7 +4071,7 @@ build_cmd_connect:
WIPHY_WORK_PRIORITY_CONNECT, &connect_work_ops);
}
-int netdev_connect(struct netdev *netdev, struct scan_bss *bss,
+int netdev_connect(struct netdev *netdev, const struct scan_bss *bss,
struct handshake_state *hs,
const struct iovec *vendor_ies,
size_t num_vendor_ies,
@@ -4158,8 +4178,9 @@ int netdev_disconnect(struct netdev *netdev,
return 0;
}
-int netdev_reassociate(struct netdev *netdev, struct scan_bss *target_bss,
- struct scan_bss *orig_bss, struct handshake_state *hs,
+int netdev_reassociate(struct netdev *netdev, const struct scan_bss *target_bss,
+ const struct scan_bss *orig_bss,
+ struct handshake_state *hs,
netdev_event_func_t event_filter,
netdev_connect_cb_t cb, void *user_data)
{
@@ -4776,7 +4797,8 @@ static void netdev_preauth_cb(const uint8_t *pmk, void *user_data)
pmk, preauth->user_data);
}
-int netdev_preauthenticate(struct netdev *netdev, struct scan_bss *target_bss,
+int netdev_preauthenticate(struct netdev *netdev,
+ const struct scan_bss *target_bss,
netdev_preauthenticate_cb_t cb, void *user_data)
{
struct netdev_preauth_state *preauth;
@@ -6676,3 +6698,5 @@ void netdev_shutdown(void)
IWD_MODULE(netdev, netdev_init, netdev_exit);
IWD_MODULE_DEPENDS(netdev, eapol);
+IWD_MODULE_DEPENDS(netdev, frame_xchg);
+IWD_MODULE_DEPENDS(netdev, wiphy);
diff --git a/src/netdev.h b/src/netdev.h
@@ -49,6 +49,7 @@ enum netdev_event {
NETDEV_EVENT_RSSI_THRESHOLD_LOW,
NETDEV_EVENT_RSSI_THRESHOLD_HIGH,
NETDEV_EVENT_RSSI_LEVEL_NOTIFY,
+ NETDEV_EVENT_PACKET_LOSS_NOTIFY,
};
enum netdev_watch_event {
@@ -150,7 +151,7 @@ uint8_t netdev_get_rssi_level_idx(struct netdev *netdev);
struct handshake_state *netdev_handshake_state_new(struct netdev *netdev);
struct handshake_state *netdev_get_handshake(struct netdev *netdev);
-int netdev_connect(struct netdev *netdev, struct scan_bss *bss,
+int netdev_connect(struct netdev *netdev, const struct scan_bss *bss,
struct handshake_state *hs,
const struct iovec *vendor_ies,
size_t num_vendor_ies,
@@ -158,8 +159,10 @@ int netdev_connect(struct netdev *netdev, struct scan_bss *bss,
netdev_connect_cb_t cb, void *user_data);
int netdev_disconnect(struct netdev *netdev,
netdev_disconnect_cb_t cb, void *user_data);
-int netdev_reassociate(struct netdev *netdev, struct scan_bss *target_bss,
- struct scan_bss *orig_bss, struct handshake_state *hs,
+int netdev_reassociate(struct netdev *netdev,
+ const struct scan_bss *target_bss,
+ const struct scan_bss *orig_bss,
+ 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,
@@ -172,7 +175,8 @@ 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, struct scan_bss *target_bss,
+int netdev_preauthenticate(struct netdev *netdev,
+ const struct scan_bss *target_bss,
netdev_preauthenticate_cb_t cb,
void *user_data);
diff --git a/src/network.c b/src/network.c
@@ -88,6 +88,7 @@ struct network {
bool provisioning_hidden:1;
uint8_t transition_disable; /* Temporary cache until info is set */
bool have_transition_disable:1;
+ bool force_default_owe_group:1;
int rank;
/* Holds DBus Connect() message if it comes in before ANQP finishes */
struct l_dbus_message *connect_after_anqp;
@@ -525,6 +526,9 @@ int network_handshake_setup(struct network *network, struct scan_bss *bss,
handshake_state_set_protocol_version(hs, eapol_proto_version);
}
+ if (hs->akm_suite == IE_RSN_AKM_SUITE_OWE)
+ hs->force_default_owe_group = network->force_default_owe_group;
+
/*
* The randomization options in the provisioning file are dependent on
* main.conf: [General].AddressRandomization=network. Any other value
@@ -766,6 +770,16 @@ void network_set_info(struct network *network, struct network_info *info)
#endif
}
+void network_set_force_default_owe_group(struct network *network)
+{
+ network->force_default_owe_group = true;
+}
+
+bool network_get_force_default_owe_group(struct network *network)
+{
+ return network->force_default_owe_group;
+}
+
static inline bool __bss_is_sae(const struct scan_bss *bss,
const struct ie_rsn_info *rsn)
{
@@ -1156,7 +1170,7 @@ struct erp_cache_entry *network_get_erp_cache(struct network *network)
}
const struct l_queue_entry *network_bss_list_get_entries(
- struct network *network)
+ const struct network *network)
{
return l_queue_get_entries(network->bss_list);
}
diff --git a/src/network.h b/src/network.h
@@ -58,6 +58,8 @@ void network_sync_settings(struct network *network);
const struct network_info *network_get_info(const struct network *network);
void network_set_info(struct network *network, struct network_info *info);
+void network_set_force_default_owe_group(struct network *network);
+bool network_get_force_default_owe_group(struct network *network);
int network_can_connect_bss(struct network *network,
const struct scan_bss *bss);
@@ -89,7 +91,7 @@ void network_blacklist_add(struct network *network, struct scan_bss *bss);
struct erp_cache_entry *network_get_erp_cache(struct network *network);
const struct l_queue_entry *network_bss_list_get_entries(
- struct network *network);
+ const struct network *network);
struct l_dbus_message *__network_connect(struct network *network,
struct scan_bss *bss,
diff --git a/src/nl80211util.c b/src/nl80211util.c
@@ -32,6 +32,7 @@
#include "src/nl80211util.h"
#include "src/band.h"
+#include "src/util.h"
typedef bool (*attr_handler)(const void *data, uint16_t len, void *o);
@@ -128,6 +129,16 @@ static bool extract_iovec(const void *data, uint16_t len, void *o)
return true;
}
+static bool extract_nested(const void *data, uint16_t len, void *o)
+{
+ const struct l_genl_attr *outer = data;
+ struct l_genl_attr *nested = o;
+
+ l_genl_attr_recurse(outer, nested);
+
+ return true;
+}
+
static attr_handler handler_for_type(enum nl80211_attrs type)
{
switch (type) {
@@ -157,6 +168,8 @@ static attr_handler handler_for_type(enum nl80211_attrs type)
return extract_uint32;
case NL80211_ATTR_FRAME:
return extract_iovec;
+ case NL80211_ATTR_WIPHY_BANDS:
+ return extract_nested;
default:
break;
}
@@ -222,6 +235,10 @@ int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...)
goto done;
}
+ /* For nested attributes use the outer attribute as data */
+ if (entry->handler == extract_nested)
+ data = &attr;
+
if (!entry->handler(data, len, entry->data)) {
ret = -EINVAL;
goto done;
@@ -468,3 +485,46 @@ int nl80211_parse_chandef(struct l_genl_msg *msg, struct band_chandef *out)
memcpy(out, &t, sizeof(t));
return 0;
}
+
+int nl80211_parse_supported_frequencies(struct l_genl_attr *band_freqs,
+ struct scan_freq_set *supported_list,
+ struct scan_freq_set *disabled_list)
+{
+ uint16_t type, len;
+ const void *data;
+ struct l_genl_attr attr;
+ struct l_genl_attr nested;
+
+ if (!l_genl_attr_recurse(band_freqs, &nested))
+ return -EBADMSG;
+
+ while (l_genl_attr_next(&nested, NULL, NULL, NULL)) {
+ uint32_t freq = 0;
+ bool disabled = false;
+
+ if (!l_genl_attr_recurse(&nested, &attr))
+ continue;
+
+ while (l_genl_attr_next(&attr, &type, &len, &data)) {
+ switch (type) {
+ case NL80211_FREQUENCY_ATTR_FREQ:
+ freq = *((uint32_t *) data);
+ break;
+ case NL80211_FREQUENCY_ATTR_DISABLED:
+ disabled = true;
+ break;
+ }
+ }
+
+ if (!freq)
+ continue;
+
+ if (supported_list)
+ scan_freq_set_add(supported_list, freq);
+
+ if (disabled && disabled_list)
+ scan_freq_set_add(disabled_list, freq);
+ }
+
+ return 0;
+}
diff --git a/src/nl80211util.h b/src/nl80211util.h
@@ -23,6 +23,7 @@
#include <ell/ell.h>
struct band_chandef;
+struct scan_freq_set;
int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...);
@@ -55,3 +56,6 @@ struct l_genl_msg *nl80211_build_cmd_frame(uint32_t ifindex,
size_t iov_len);
int nl80211_parse_chandef(struct l_genl_msg *msg, struct band_chandef *out);
+int nl80211_parse_supported_frequencies(struct l_genl_attr *band_freqs,
+ struct scan_freq_set *supported,
+ struct scan_freq_set *disabled);
diff --git a/src/offchannel.c b/src/offchannel.c
@@ -322,3 +322,4 @@ static void offchannel_exit(void)
}
IWD_MODULE(offchannel, offchannel_init, offchannel_exit);
+IWD_MODULE_DEPENDS(offchannel, wiphy);
diff --git a/src/owe.c b/src/owe.c
@@ -45,6 +45,20 @@ struct owe_sm {
static bool owe_reset(struct owe_sm *owe)
{
+ if (owe->hs->force_default_owe_group) {
+ if (owe->retry != 0) {
+ l_warn("Forced default OWE group but was rejected!");
+ return false;
+ }
+
+ l_debug("Forcing default OWE group 19");
+
+ owe->retry++;
+ owe->group = 19;
+
+ goto get_curve;
+ }
+
/*
* Reset OWE with a different curve group and generate a new key pair
*/
@@ -52,6 +66,8 @@ static bool owe_reset(struct owe_sm *owe)
return false;
owe->group = owe->ecc_groups[owe->retry];
+
+get_curve:
owe->curve = l_ecc_curve_from_ike_group(owe->group);
if (owe->private)
diff --git a/src/p2p.c b/src/p2p.c
@@ -1981,6 +1981,7 @@ static bool p2p_provision_scan_notify(int err, struct l_queue *bss_list,
static void p2p_provision_scan_start(struct p2p_device *dev)
{
struct scan_parameters params = {};
+ struct scan_freq_set *freqs = NULL;
uint8_t buf[256];
params.flush = true;
@@ -2009,16 +2010,17 @@ static void p2p_provision_scan_start(struct p2p_device *dev)
* contain all of the 2.4 and 5G channels.
*/
if (dev->conn_go_scan_retry < 12) {
- params.freqs = scan_freq_set_new();
- scan_freq_set_add(params.freqs, dev->conn_go_oper_freq);
+ freqs = scan_freq_set_new();
+ scan_freq_set_add(freqs, dev->conn_go_oper_freq);
+ params.freqs = freqs;
}
dev->scan_id = scan_active_full(dev->wdev_id, ¶ms, NULL,
p2p_provision_scan_notify, dev,
p2p_scan_destroy);
- if (params.freqs)
- scan_freq_set_free(params.freqs);
+ if (freqs)
+ scan_freq_set_free(freqs);
}
static void p2p_start_client_provision(struct p2p_device *dev)
@@ -3781,6 +3783,7 @@ schedule:
static bool p2p_device_scan_start(struct p2p_device *dev)
{
struct scan_parameters params = {};
+ struct scan_freq_set *freqs;
uint8_t buf[256];
unsigned int i;
@@ -3816,13 +3819,13 @@ static bool p2p_device_scan_start(struct p2p_device *dev)
* Request frames intended for both P2P Devices and non-P2P Devices."
*/
params.no_cck_rates = true;
- params.freqs = scan_freq_set_new();
+ freqs = scan_freq_set_new();
for (i = 0; i < L_ARRAY_SIZE(channels_social); i++) {
int chan = channels_social[i];
uint32_t freq = band_channel_to_freq(chan, BAND_FREQ_2_4_GHZ);
- scan_freq_set_add(params.freqs, freq);
+ scan_freq_set_add(freqs, freq);
}
/*
@@ -3849,12 +3852,14 @@ static bool p2p_device_scan_start(struct p2p_device *dev)
dev->chans_per_scan = CHANS_PER_SCAN;
}
- scan_freq_set_add(params.freqs, freq);
+ scan_freq_set_add(freqs, freq);
}
+ params.freqs = freqs;
+
dev->scan_id = scan_active_full(dev->wdev_id, ¶ms, NULL,
p2p_scan_notify, dev, p2p_scan_destroy);
- scan_freq_set_free(params.freqs);
+ scan_freq_set_free(freqs);
return dev->scan_id != 0;
}
diff --git a/src/rrm.c b/src/rrm.c
@@ -890,3 +890,4 @@ static void rrm_exit(void)
IWD_MODULE(rrm, rrm_init, rrm_exit);
IWD_MODULE_DEPENDS(rrm, netdev);
+IWD_MODULE_DEPENDS(rrm, frame_xchg);
diff --git a/src/scan.c b/src/scan.c
@@ -94,14 +94,23 @@ struct scan_request {
*/
bool triggered : 1;
bool in_callback : 1; /* Scan request complete, re-entrancy guard */
+ /* The request was split anticipating 6GHz will become available */
+ bool split : 1;
struct l_queue *cmds;
/* The time the current scan was started. Reported in TRIGGER_SCAN */
uint64_t start_time_tsf;
struct wiphy_radio_work_item work;
+ /*
+ * List of frequencies scanned so far. Since the NEW_SCAN_RESULTS event
+ * contains frequencies of only the last CMD_TRIGGER we need to parse
+ * and save these since there may be additional scan commands to run.
+ */
+ struct scan_freq_set *freqs_scanned;
};
struct scan_context {
uint64_t wdev_id;
+ uint32_t wiphy_watch_id;
/*
* Tells us whether a scan, our own or external, is running.
* Set when scan gets triggered, cleared when scan done and
@@ -125,9 +134,9 @@ struct scan_context {
struct scan_results {
struct scan_context *sc;
struct l_queue *bss_list;
- struct scan_freq_set *freqs;
uint64_t time_stamp;
struct scan_request *sr;
+ struct scan_freq_set *freqs;
};
static bool start_next_scan_request(struct wiphy_radio_work_item *item);
@@ -159,6 +168,8 @@ static void scan_request_free(struct wiphy_radio_work_item *item)
l_queue_destroy(sr->cmds, (l_queue_destroy_func_t) l_genl_msg_unref);
+ scan_freq_set_free(sr->freqs_scanned);
+
l_free(sr);
}
@@ -177,24 +188,6 @@ static void scan_request_failed(struct scan_context *sc,
wiphy_radio_work_done(sc->wiphy, sr->work.id);
}
-static struct scan_context *scan_context_new(uint64_t wdev_id)
-{
- struct wiphy *wiphy = wiphy_find_by_wdev(wdev_id);
- struct scan_context *sc;
-
- if (!wiphy)
- return NULL;
-
- sc = l_new(struct scan_context, 1);
-
- sc->wdev_id = wdev_id;
- sc->wiphy = wiphy;
- sc->state = SCAN_STATE_NOT_RUNNING;
- sc->requests = l_queue_new();
-
- return sc;
-}
-
static void scan_request_cancel(void *data)
{
struct scan_request *sr = data;
@@ -220,6 +213,8 @@ static void scan_context_free(struct scan_context *sc)
if (sc->get_fw_scan_cmd_id && nl80211)
l_genl_family_cancel(nl80211, sc->get_fw_scan_cmd_id);
+ wiphy_state_watch_remove(sc->wiphy, sc->wiphy_watch_id);
+
l_free(sc);
}
@@ -279,7 +274,7 @@ static void scan_freq_append(uint32_t freq, void *user_data)
}
static void scan_build_attr_scan_frequencies(struct l_genl_msg *msg,
- struct scan_freq_set *freqs)
+ const struct scan_freq_set *freqs)
{
struct scan_freq_append_data append_data = { msg, 0 };
@@ -345,9 +340,24 @@ static bool scan_mac_address_randomization_is_disabled(void)
return disabled;
}
+static struct scan_freq_set *scan_get_allowed_freqs(struct scan_context *sc)
+{
+ struct scan_freq_set *allowed = scan_freq_set_new();
+
+ scan_freq_set_merge(allowed, wiphy_get_supported_freqs(sc->wiphy));
+
+ if (!wiphy_constrain_freq_set(sc->wiphy, allowed)) {
+ scan_freq_set_free(allowed);
+ allowed = NULL;
+ }
+
+ return allowed;
+}
+
static struct l_genl_msg *scan_build_cmd(struct scan_context *sc,
bool ignore_flush_flag, bool is_passive,
- const struct scan_parameters *params)
+ const struct scan_parameters *params,
+ const struct scan_freq_set *freqs)
{
struct l_genl_msg *msg;
uint32_t flags = 0;
@@ -359,8 +369,8 @@ static struct l_genl_msg *scan_build_cmd(struct scan_context *sc,
if (wiphy_get_max_scan_ie_len(sc->wiphy))
scan_build_attr_ie(msg, sc, params);
- if (params->freqs)
- scan_build_attr_scan_frequencies(msg, params->freqs);
+ if (freqs)
+ scan_build_attr_scan_frequencies(msg, freqs);
if (params->flush && !ignore_flush_flag && wiphy_has_feature(sc->wiphy,
NL80211_FEATURE_SCAN_FLUSH))
@@ -394,6 +404,8 @@ static struct l_genl_msg *scan_build_cmd(struct scan_context *sc,
if (params->ap_scan)
flags |= NL80211_SCAN_FLAG_AP;
+ flags |= NL80211_SCAN_FLAG_COLOCATED_6GHZ;
+
if (flags)
l_genl_msg_append_attr(msg, NL80211_ATTR_SCAN_FLAGS, 4, &flags);
@@ -515,16 +527,18 @@ static bool scan_cmds_add_hidden(const struct network_info *network,
* of all scans in the batch after the last scan is finished.
*/
*data->cmd = scan_build_cmd(data->sc, true, false,
- data->params);
+ data->params,
+ data->params->freqs);
l_genl_msg_enter_nested(*data->cmd, NL80211_ATTR_SCAN_SSIDS);
}
return true;
}
-static void scan_cmds_add(struct l_queue *cmds, struct scan_context *sc,
+static void scan_build_next_cmd(struct l_queue *cmds, struct scan_context *sc,
bool passive,
- const struct scan_parameters *params)
+ const struct scan_parameters *params,
+ const struct scan_freq_set *freqs)
{
struct l_genl_msg *cmd;
struct scan_cmds_add_data data = {
@@ -535,7 +549,7 @@ static void scan_cmds_add(struct l_queue *cmds, struct scan_context *sc,
wiphy_get_max_num_ssids_per_scan(sc->wiphy),
};
- cmd = scan_build_cmd(sc, false, passive, params);
+ cmd = scan_build_cmd(sc, false, passive, params, freqs);
if (passive) {
/* passive scan */
@@ -563,6 +577,57 @@ static void scan_cmds_add(struct l_queue *cmds, struct scan_context *sc,
l_queue_push_tail(cmds, cmd);
}
+static void scan_cmds_add(struct scan_request *sr, struct scan_context *sc,
+ bool passive,
+ const struct scan_parameters *params)
+{
+ unsigned int i;
+ struct scan_freq_set *subsets[2] = { 0 };
+ struct scan_freq_set *allowed = scan_get_allowed_freqs(sc);
+ const struct scan_freq_set *supported =
+ wiphy_get_supported_freqs(sc->wiphy);
+
+ /*
+ * If 6GHz is not possible, or already allowed, or the frequencies are
+ * explicit don't break up the request.
+ */
+ if (!(scan_freq_set_get_bands(supported) & BAND_FREQ_6_GHZ) ||
+ (scan_freq_set_get_bands(allowed) & BAND_FREQ_6_GHZ) ||
+ params->freqs) {
+ scan_freq_set_free(allowed);
+ scan_build_next_cmd(sr->cmds, sc, passive,
+ params, params->freqs);
+ return;
+ }
+
+ /*
+ * Otherwise a full spectrum scan will likely open up the 6GHz
+ * band. The problem is the regdom update occurs after an
+ * individual scan request so a single request isn't going to
+ * include potential 6GHz results.
+ *
+ * Instead we can break this full scan up into individual bands
+ * and increase our chances of the regdom updating after one of
+ * the earlier requests. If it does update to allow 6GHz an
+ * extra 6GHz-only passive scan can be appended to this request
+ * at that time.
+ */
+ subsets[0] = scan_freq_set_clone(allowed, BAND_FREQ_2_4_GHZ);
+ subsets[1] = scan_freq_set_clone(allowed, BAND_FREQ_5_GHZ);
+
+ scan_freq_set_free(allowed);
+
+ for(i = 0; i < L_ARRAY_SIZE(subsets); i++) {
+ if (!scan_freq_set_isempty(subsets[i]))
+ scan_build_next_cmd(sr->cmds, sc, passive, params,
+ subsets[i]);
+
+ scan_freq_set_free(subsets[i]);
+ }
+
+ sr->split = true;
+}
+
static int scan_request_send_trigger(struct scan_context *sc,
struct scan_request *sr)
{
@@ -607,6 +672,7 @@ static struct scan_request *scan_request_new(struct scan_context *sc,
sr->destroy = destroy;
sr->passive = passive;
sr->cmds = l_queue_new();
+ sr->freqs_scanned = scan_freq_set_new();
return sr;
}
@@ -639,7 +705,7 @@ static uint32_t scan_common(uint64_t wdev_id, bool passive,
sr = scan_request_new(sc, passive, trigger, notify, userdata, destroy);
- scan_cmds_add(sr->cmds, sc, passive, params);
+ scan_cmds_add(sr, sc, passive, params);
/*
* sr->work isn't initialized yet, it will be done by
@@ -652,7 +718,7 @@ static uint32_t scan_common(uint64_t wdev_id, bool passive,
priority, &work_ops);
}
-uint32_t scan_passive(uint64_t wdev_id, struct scan_freq_set *freqs,
+uint32_t scan_passive(uint64_t wdev_id, const struct scan_freq_set *freqs,
scan_trigger_func_t trigger, scan_notify_func_t notify,
void *userdata, scan_destroy_func_t destroy)
{
@@ -733,7 +799,7 @@ static void add_owe_scan_cmd(struct scan_context *sc, struct scan_request *sr,
params.ssid_len = bss->owe_trans->ssid_len;
params.flush = true;
- cmd = scan_build_cmd(sc, ignore_flush, false, ¶ms);
+ cmd = scan_build_cmd(sc, ignore_flush, false, ¶ms, params.freqs);
l_genl_msg_enter_nested(cmd, NL80211_ATTR_SCAN_SSIDS);
l_genl_msg_append_attr(cmd, 0, params.ssid_len, params.ssid);
@@ -1523,14 +1589,11 @@ fail:
return NULL;
}
-static struct scan_freq_set *scan_parse_attr_scan_frequencies(
- struct l_genl_attr *attr)
+static void scan_parse_attr_scan_frequencies(struct l_genl_attr *attr,
+ struct scan_freq_set *set)
{
uint16_t type, len;
const void *data;
- struct scan_freq_set *set;
-
- set = scan_freq_set_new();
while (l_genl_attr_next(attr, &type, &len, &data)) {
uint32_t freq;
@@ -1541,8 +1604,6 @@ static struct scan_freq_set *scan_parse_attr_scan_frequencies(
freq = *((uint32_t *) data);
scan_freq_set_add(set, freq);
}
-
- return set;
}
static struct scan_bss *scan_parse_result(struct l_genl_msg *msg,
@@ -1578,17 +1639,17 @@ static void scan_bss_compute_rank(struct scan_bss *bss)
double rank;
uint32_t irank;
/*
- * Maximum rate is 2340Mbps (VHT)
+ * Maximum rate is 9607.8Mbps (HE)
*/
- double max_rate = 2340000000;
+ double max_rate = 9607800000;
rank = (double)bss->data_rate / max_rate * USHRT_MAX;
- /* Prefer 5G networks over 2.4G */
+ /* Prefer 5G/6G networks over 2.4G */
if (bss->frequency > 4000)
rank *= RANK_5G_FACTOR;
- /* Rank loaded APs lower and lighly loaded APs higher */
+ /* Rank loaded APs lower and lightly loaded APs higher */
if (bss->utilization >= 192)
rank *= RANK_HIGH_UTILIZATION_FACTOR;
else if (bss->utilization <= 63)
@@ -1828,12 +1889,116 @@ static void get_scan_done(void *user)
l_queue_destroy(results->bss_list,
(l_queue_destroy_func_t) scan_bss_free);
- if (results->freqs)
+ if (!results->sr)
scan_freq_set_free(results->freqs);
l_free(results);
}
+static void scan_get_results(struct scan_context *sc, struct scan_request *sr,
+ struct scan_freq_set *freqs)
+{
+ struct scan_results *results;
+ struct l_genl_msg *scan_msg;
+
+ results = l_new(struct scan_results, 1);
+ results->sc = sc;
+ results->time_stamp = l_time_now();
+ results->sr = sr;
+ results->bss_list = l_queue_new();
+ results->freqs = freqs;
+
+ scan_msg = l_genl_msg_new_sized(NL80211_CMD_GET_SCAN, 8);
+
+ l_genl_msg_append_attr(scan_msg, NL80211_ATTR_WDEV, 8,
+ &sc->wdev_id);
+ sc->get_scan_cmd_id = l_genl_family_dump(nl80211, scan_msg,
+ get_scan_callback,
+ results, get_scan_done);
+}
+
+static void scan_wiphy_watch(struct wiphy *wiphy,
+ enum wiphy_state_watch_event event,
+ void *user_data)
+{
+ struct scan_context *sc = user_data;
+ struct scan_request *sr = NULL;
+ struct l_genl_msg *msg = NULL;
+ struct scan_parameters params = { 0 };
+ struct scan_freq_set *freqs_6ghz;
+ struct scan_freq_set *allowed;
+ bool allow_6g;
+ const struct scan_freq_set *supported =
+ wiphy_get_supported_freqs(wiphy);
+
+ /* Only care about regulatory events, and if 6GHz capable */
+ if (event != WIPHY_STATE_WATCH_EVENT_REGDOM_DONE ||
+ !(scan_freq_set_get_bands(supported) & BAND_FREQ_6_GHZ))
+ return;
+
+ if (!sc->sp.id)
+ return;
+
+ sr = l_queue_find(sc->requests, scan_request_match,
+ L_UINT_TO_PTR(sc->sp.id));
+ if (!sr)
+ return;
+
+ allowed = scan_get_allowed_freqs(sc);
+ allow_6g = scan_freq_set_get_bands(allowed) & BAND_FREQ_6_GHZ;
+
+ /*
+ * This update did not allow 6GHz, or the original request was
+ * not expecting 6GHz. The periodic scan should now be ended.
+ */
+ if (!allow_6g || !sr->split) {
+ scan_get_results(sc, sr, sr->freqs_scanned);
+ goto free_allowed;
+ }
+
+ /*
+ * At this point we know there is an ongoing periodic scan.
+ * Create a new 6GHz passive scan request and append to the
+ * command list
+ */
+ freqs_6ghz = scan_freq_set_clone(allowed, BAND_FREQ_6_GHZ);
+
+ msg = scan_build_cmd(sc, false, true, ¶ms, freqs_6ghz);
+ l_queue_push_tail(sr->cmds, msg);
+
+ scan_freq_set_free(freqs_6ghz);
+
+ /*
+ * If this periodic scan is at the top of the queue, continue
+ * running it.
+ */
+ if (l_queue_peek_head(sc->requests) == sr)
+ start_next_scan_request(&sr->work);
+
+free_allowed:
+ scan_freq_set_free(allowed);
+}
+
+static struct scan_context *scan_context_new(uint64_t wdev_id)
+{
+ struct wiphy *wiphy = wiphy_find_by_wdev(wdev_id);
+ struct scan_context *sc;
+
+ if (!wiphy)
+ return NULL;
+
+ sc = l_new(struct scan_context, 1);
+
+ sc->wdev_id = wdev_id;
+ sc->wiphy = wiphy;
+ sc->state = SCAN_STATE_NOT_RUNNING;
+ sc->requests = l_queue_new();
+ sc->wiphy_watch_id = wiphy_state_watch_add(wiphy, scan_wiphy_watch,
+ sc, NULL);
+
+ return sc;
+}
+
static bool scan_parse_flush_flag_from_msg(struct l_genl_msg *msg)
{
struct l_genl_attr attr;
@@ -1850,8 +2015,8 @@ static bool scan_parse_flush_flag_from_msg(struct l_genl_msg *msg)
return false;
}
-static void scan_parse_new_scan_results(struct l_genl_msg *msg,
- struct scan_results *results)
+static void scan_parse_result_frequencies(struct l_genl_msg *msg,
+ struct scan_freq_set *freqs)
{
struct l_genl_attr attr, nested;
uint16_t type, len;
@@ -1868,8 +2033,7 @@ static void scan_parse_new_scan_results(struct l_genl_msg *msg,
break;
}
- results->freqs =
- scan_parse_attr_scan_frequencies(&nested);
+ scan_parse_attr_scan_frequencies(&nested, freqs);
break;
}
}
@@ -1923,8 +2087,7 @@ static void scan_notify(struct l_genl_msg *msg, void *user_data)
switch (cmd) {
case NL80211_CMD_NEW_SCAN_RESULTS:
{
- struct l_genl_msg *scan_msg;
- struct scan_results *results;
+ struct scan_freq_set *freqs;
bool send_next = false;
bool retry = false;
bool get_results = false;
@@ -1940,6 +2103,14 @@ static void scan_notify(struct l_genl_msg *msg, void *user_data)
break;
}
+ /* Regdom changed during a periodic scan */
+ if (sc->sp.id == sr->work.id &&
+ wiphy_regdom_is_updating(sc->wiphy)) {
+ scan_parse_result_frequencies(msg,
+ sr->freqs_scanned);
+ return;
+ }
+
/*
* If this was the last command for the current request
* avoid starting the next request until the GET_SCAN
@@ -1948,8 +2119,11 @@ static void scan_notify(struct l_genl_msg *msg, void *user_data)
*/
if (l_queue_isempty(sr->cmds))
get_results = true;
- else
+ else {
+ scan_parse_result_frequencies(msg,
+ sr->freqs_scanned);
send_next = true;
+ }
} else {
if (sc->get_scan_cmd_id)
break;
@@ -1988,20 +2162,18 @@ static void scan_notify(struct l_genl_msg *msg, void *user_data)
if (!get_results)
break;
- results = l_new(struct scan_results, 1);
- results->sc = sc;
- results->time_stamp = l_time_now();
- results->sr = sr;
- results->bss_list = l_queue_new();
+ /*
+ * In case this was an external scan, setup a new, temporary
+ * frequency set to report the results to the periodic callback
+ */
+ if (!sr)
+ freqs = scan_freq_set_new();
+ else
+ freqs = sr->freqs_scanned;
- scan_parse_new_scan_results(msg, results);
+ scan_parse_result_frequencies(msg, freqs);
- scan_msg = l_genl_msg_new_sized(NL80211_CMD_GET_SCAN, 8);
- l_genl_msg_append_attr(scan_msg, NL80211_ATTR_WDEV, 8,
- &sc->wdev_id);
- sc->get_scan_cmd_id = l_genl_family_dump(nl80211, scan_msg,
- get_scan_callback,
- results, get_scan_done);
+ scan_get_results(sc, sr, freqs);
break;
}
@@ -2198,3 +2370,4 @@ static void scan_exit(void)
}
IWD_MODULE(scan, scan_init, scan_exit)
+IWD_MODULE_DEPENDS(scan, wiphy)
diff --git a/src/scan.h b/src/scan.h
@@ -92,7 +92,7 @@ struct scan_bss {
struct scan_parameters {
const uint8_t *extra_ie;
size_t extra_ie_size;
- struct scan_freq_set *freqs;
+ const struct scan_freq_set *freqs;
uint16_t duration;
bool flush : 1;
bool randomize_mac_addr_hint : 1;
@@ -129,7 +129,7 @@ struct l_genl_msg *scan_build_trigger_scan_bss(uint32_t ifindex,
const uint8_t *ssid,
uint32_t ssid_len);
-uint32_t scan_passive(uint64_t wdev_id, struct scan_freq_set *freqs,
+uint32_t scan_passive(uint64_t wdev_id, const struct scan_freq_set *freqs,
scan_trigger_func_t trigger, scan_notify_func_t notify,
void *userdata, scan_destroy_func_t destroy);
uint32_t scan_passive_full(uint64_t wdev_id,
diff --git a/src/station.c b/src/station.c
@@ -112,6 +112,8 @@ struct station {
struct scan_freq_set *scan_freqs_order[3];
unsigned int dbus_scan_subset_idx;
+ uint32_t wiphy_watch;
+
bool preparing_roam : 1;
bool roam_scan_full : 1;
bool signal_low : 1;
@@ -1354,14 +1356,37 @@ static void station_quick_scan_destroy(void *userdata)
static int station_quick_scan_trigger(struct station *station)
{
- struct scan_freq_set *known_freq_set;
+ _auto_(scan_freq_set_free) struct scan_freq_set *known_freq_set = NULL;
+ bool known_6ghz;
+ const struct scan_freq_set *disabled = wiphy_get_disabled_freqs(
+ station->wiphy);
+
+ if (wiphy_regdom_is_updating(station->wiphy)) {
+ l_debug("regdom is updating, delaying quick scan");
+ return -EAGAIN;
+ }
known_freq_set = known_networks_get_recent_frequencies(5);
if (!known_freq_set)
return -ENODATA;
+ known_6ghz = scan_freq_set_get_bands(known_freq_set) & BAND_FREQ_6_GHZ;
+
+ /*
+ * This means IWD has previously connected to a 6GHz AP before, but now
+ * the regulatory domain disallows 6GHz likely caused by a reboot, the
+ * firmware going down, or a regulatory update. The only way to
+ * re-enable 6GHz is to get enough beacons via scanning for the firmware
+ * to set the regulatory domain. A quick scan is very unlikely to do
+ * this since its so limited, so return an error which will fall back to
+ * full autoconnect.
+ */
+ if ((scan_freq_set_get_bands(disabled) & BAND_FREQ_6_GHZ) &&
+ wiphy_country_is_unknown(station->wiphy) &&
+ known_6ghz)
+ return -ENOTSUP;
+
if (!wiphy_constrain_freq_set(station->wiphy, known_freq_set)) {
- scan_freq_set_free(known_freq_set);
return -ENOTSUP;
}
@@ -1370,8 +1395,6 @@ static int station_quick_scan_trigger(struct station *station)
station_quick_scan_triggered,
station_quick_scan_results,
station_quick_scan_destroy);
- scan_freq_set_free(known_freq_set);
-
if (!station->quick_scan_id)
return -EIO;
@@ -1450,6 +1473,7 @@ static void station_enter_state(struct station *station,
struct l_dbus *dbus = dbus_get_bus();
#endif
bool disconnected;
+ int ret;
l_debug("Old State: %s, new state: %s",
station_state_to_string(station->state),
@@ -1468,7 +1492,8 @@ static void station_enter_state(struct station *station,
switch (state) {
case STATION_STATE_AUTOCONNECT_QUICK:
- if (!station_quick_scan_trigger(station))
+ ret = station_quick_scan_trigger(station);
+ if (ret == 0 || ret == -EAGAIN)
break;
station->state = STATION_STATE_AUTOCONNECT_FULL;
@@ -2300,6 +2325,7 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list,
struct station *station = userdata;
struct network *network = station->connected_network;
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;
@@ -2331,9 +2357,20 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list,
* for BSSes that are within the FT Mobility Domain so as to favor
* Fast Roaming, if it is supported.
*/
+ l_debug("Current BSS '%s' with SSID: %s",
+ util_address_to_string(current_bss->addr),
+ util_ssid_to_utf8(current_bss->ssid_len, current_bss->ssid));
while ((bss = l_queue_pop_head(bss_list))) {
double rank;
+ uint32_t kbps100 = DIV_ROUND_CLOSEST(bss->data_rate, 100000);
+
+ l_debug("Processing BSS '%s' with SSID: %s, freq: %u, rank: %u,"
+ " strength: %i, data_rate: %u.%u",
+ util_address_to_string(bss->addr),
+ util_ssid_to_utf8(bss->ssid_len, bss->ssid),
+ bss->frequency, bss->rank, bss->signal_strength,
+ kbps100 / 10, kbps100 % 10);
/* Skip the BSS we are connected to if doing an AP roam */
if (station->ap_directed_roaming && !memcmp(bss->addr,
@@ -2341,7 +2378,6 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list,
goto next;
/* Skip result if it is not part of the ESS */
-
if (bss->ssid_len != hs->ssid_len ||
memcmp(bss->ssid, hs->ssid, hs->ssid_len))
goto next;
@@ -2513,15 +2549,10 @@ static void station_neighbor_report_cb(struct netdev *netdev, int err,
station_roam_failed(station);
}
-static void station_roam_trigger_cb(struct l_timeout *timeout, void *user_data)
+static void station_start_roam(struct station *station)
{
- struct station *station = user_data;
int r;
- l_debug("%u", netdev_get_ifindex(station->netdev));
-
- l_timeout_remove(station->roam_trigger_timeout);
- station->roam_trigger_timeout = NULL;
station->preparing_roam = true;
/*
@@ -2555,6 +2586,18 @@ static void station_roam_trigger_cb(struct l_timeout *timeout, void *user_data)
station_roam_failed(station);
}
+static void station_roam_trigger_cb(struct l_timeout *timeout, void *user_data)
+{
+ struct station *station = user_data;
+
+ l_debug("%u", netdev_get_ifindex(station->netdev));
+
+ l_timeout_remove(station->roam_trigger_timeout);
+ station->roam_trigger_timeout = NULL;
+
+ station_start_roam(station);
+}
+
static void station_roam_timeout_rearm(struct station *station, int seconds)
{
struct timespec now, min_timeout;
@@ -2793,6 +2836,29 @@ static bool station_try_next_bss(struct station *station)
return true;
}
+static bool station_retry_owe_default_group(struct station *station)
+{
+ /*
+ * Shouldn't ever get here with classic open networks so its safe to
+ * assume if the security is none this is an OWE network.
+ */
+ if (network_get_security(station->connected_network) != SECURITY_NONE)
+ return false;
+
+ /* If we already forced group 19, allow the BSS to be blacklisted */
+ if (network_get_force_default_owe_group(station->connected_network))
+ return false;
+
+ l_warn("Failed to connect to OWE BSS "MAC" possibly because the AP is "
+ "incorrectly deriving the PTK, this AP should be fixed. "
+ "Retrying with group 19 as a workaround",
+ MAC_STR(station->connected_bss->addr));
+
+ network_set_force_default_owe_group(station->connected_network);
+
+ return true;
+}
+
static bool station_retry_with_reason(struct station *station,
uint16_t reason_code)
{
@@ -2803,12 +2869,20 @@ static bool station_retry_with_reason(struct station *station,
* Other reason codes can be added here if its decided we want to
* fail in those cases.
*/
- if (reason_code == MMPDU_REASON_CODE_PREV_AUTH_NOT_VALID ||
- reason_code == MMPDU_REASON_CODE_IEEE8021X_FAILED)
+ switch (reason_code) {
+ case MMPDU_REASON_CODE_PREV_AUTH_NOT_VALID:
+ if (station_retry_owe_default_group(station))
+ goto try_next;
+ /* fall through */
+ case MMPDU_REASON_CODE_IEEE8021X_FAILED:
return false;
+ default:
+ break;
+ }
blacklist_add_bss(station->connected_bss->addr);
+try_next:
return station_try_next_bss(station);
}
@@ -3004,6 +3078,23 @@ static void station_disconnect_event(struct station *station, void *event_data)
l_warn("Unexpected disconnect event");
}
+#define STATION_PKT_LOSS_THRESHOLD 10
+
+static void station_packets_lost(struct station *station, uint32_t num_pkts)
+{
+ l_debug("Packets lost event: %u", num_pkts);
+
+ if (num_pkts < STATION_PKT_LOSS_THRESHOLD)
+ return;
+
+ if (station_cannot_roam(station))
+ return;
+
+ station_debug_event(station, "packet-loss-roam");
+
+ station_start_roam(station);
+}
+
static void station_netdev_event(struct netdev *netdev, enum netdev_event event,
void *event_data, void *user_data)
{
@@ -3039,6 +3130,9 @@ static void station_netdev_event(struct netdev *netdev, enum netdev_event event,
case NETDEV_EVENT_CHANNEL_SWITCHED:
station_event_channel_switched(station, l_get_u32(event_data));
break;
+ case NETDEV_EVENT_PACKET_LOSS_NOTIFY:
+ station_packets_lost(station, l_get_u32(event_data));
+ break;
}
}
@@ -4005,6 +4099,35 @@ static void station_fill_scan_freq_subsets(struct station *station)
}
}
+static void station_wiphy_watch(struct wiphy *wiphy,
+ enum wiphy_state_watch_event event,
+ void *user_data)
+{
+ struct station *station = user_data;
+ int ret;
+
+ if (event != WIPHY_STATE_WATCH_EVENT_REGDOM_DONE)
+ return;
+
+ /*
+ * The only state that requires special handling is for
+ * quick scans since the previous quick scan was delayed until
+ * the regulatory domain updated. Try again in case 6Ghz is now
+ * unlocked (unlikely), or advance to full autoconnect. Just in
+ * case this update came during a quick scan, ignore it.
+ */
+ if (station->state != STATION_STATE_AUTOCONNECT_QUICK ||
+ station->quick_scan_id)
+ return;
+
+ ret = station_quick_scan_trigger(station);
+ if (!ret)
+ return;
+
+ L_WARN_ON(ret == -EAGAIN);
+ station_enter_state(station, STATION_STATE_AUTOCONNECT_FULL);
+}
+
static struct station *station_create(struct netdev *netdev)
{
struct station *station;
@@ -4027,6 +4150,10 @@ static struct station *station_create(struct netdev *netdev)
station->wiphy = netdev_get_wiphy(netdev);
station->netdev = netdev;
+ station->wiphy_watch = wiphy_state_watch_add(station->wiphy,
+ station_wiphy_watch,
+ station, NULL);
+
l_queue_push_head(station_list, station);
#ifdef HAVE_DBUS
@@ -4140,6 +4267,8 @@ static void station_free(struct station *station)
if (station->scan_freqs_order[2])
scan_freq_set_free(station->scan_freqs_order[2]);
+ wiphy_state_watch_remove(station->wiphy, station->wiphy_watch);
+
l_free(station);
}
@@ -4278,6 +4407,13 @@ static struct l_dbus_message *station_force_roam(struct l_dbus *dbus,
if (!target || target == station->connected_bss)
return dbus_error_invalid_args(message);
+ if (station->connected_bss->ssid_len != target->ssid_len)
+ goto invalid_args;
+
+ if (memcmp(station->connected_bss->ssid, target->ssid,
+ target->ssid_len))
+ goto invalid_args;
+
l_debug("Attempting forced roam to BSS "MAC, MAC_STR(mac));
/* The various roam routines expect this to be set from scanning */
@@ -4498,6 +4634,90 @@ static struct l_dbus_message *station_property_set_autoconnect(
return l_dbus_message_new_method_return(message);
}
+static void station_append_byte_array(struct l_dbus_message_builder *builder,
+ const char *name,
+ const uint8_t *bytes, size_t len)
+{
+ size_t i;
+
+ l_dbus_message_builder_enter_dict(builder, "sv");
+ l_dbus_message_builder_append_basic(builder, 's', name);
+ l_dbus_message_builder_enter_variant(builder, "ay");
+ l_dbus_message_builder_enter_array(builder, "y");
+
+ for (i = 0; i < len; i++)
+ l_dbus_message_builder_append_basic(builder, 'y', &bytes[i]);
+
+ l_dbus_message_builder_leave_array(builder);
+ l_dbus_message_builder_leave_variant(builder);
+ l_dbus_message_builder_leave_dict(builder);
+}
+
+static void station_append_bss_list(struct l_dbus_message_builder *builder,
+ const struct l_queue_entry *entry)
+{
+ for (; entry; entry = entry->next) {
+ struct scan_bss *bss = entry->data;
+ int32_t rssi = bss->signal_strength / 100;
+
+ l_dbus_message_builder_enter_array(builder, "{sv}");
+
+ dbus_append_dict_basic(builder, "Frequency", 'u',
+ &bss->frequency);
+ dbus_append_dict_basic(builder, "RSSI", 'i',
+ &rssi);
+ dbus_append_dict_basic(builder, "Rank", 'q', &bss->rank);
+
+ dbus_append_dict_basic(builder, "Address", 's',
+ util_address_to_string(bss->addr));
+
+ station_append_byte_array(builder, "MDE", bss->mde, 3);
+
+ l_dbus_message_builder_leave_array(builder);
+ }
+}
+
+static struct l_dbus_message *station_debug_get_networks(struct l_dbus *dbus,
+ struct l_dbus_message *message,
+ void *user_data)
+{
+ struct station *station = user_data;
+ struct l_dbus_message *reply =
+ l_dbus_message_new_method_return(message);
+ struct l_dbus_message_builder *builder =
+ l_dbus_message_builder_new(reply);
+ const struct l_queue_entry *entry;
+
+ l_dbus_message_builder_enter_array(builder, "{oaa{sv}}");
+
+ if (l_queue_isempty(station->networks_sorted))
+ goto done;
+
+ for (entry = l_queue_get_entries(station->networks_sorted); entry;
+ entry = entry->next) {
+ const struct network *network = entry->data;
+
+ l_dbus_message_builder_enter_dict(builder, "oaa{sv}");
+ l_dbus_message_builder_append_basic(builder, 'o',
+ network_get_path(network));
+ l_dbus_message_builder_enter_array(builder, "a{sv}");
+
+ station_append_bss_list(builder,
+ network_bss_list_get_entries(network));
+
+ l_dbus_message_builder_leave_array(builder);
+ l_dbus_message_builder_leave_dict(builder);
+ }
+
+done:
+ l_dbus_message_builder_leave_array(builder);
+
+ l_dbus_message_builder_finalize(builder);
+ l_dbus_message_builder_destroy(builder);
+
+ return reply;
+}
+
static void station_setup_debug_interface(
struct l_dbus_interface *interface)
{
@@ -4510,6 +4730,9 @@ static void station_setup_debug_interface(
l_dbus_interface_method(interface, "Scan", 0,
station_debug_scan, "", "aq",
"frequencies");
+ l_dbus_interface_method(interface, "GetNetworks", 0,
+ station_debug_get_networks, "a{oaa{sv}}", "",
+ "networks");
l_dbus_interface_signal(interface, "Event", 0, "sav", "name", "data");
@@ -4654,4 +4877,6 @@ static void station_exit(void)
IWD_MODULE(station, station_init, station_exit)
IWD_MODULE_DEPENDS(station, netdev);
-IWD_MODULE_DEPENDS(station, netconfig)
+IWD_MODULE_DEPENDS(station, netconfig);
+IWD_MODULE_DEPENDS(station, frame_xchg);
+IWD_MODULE_DEPENDS(station, wiphy);
diff --git a/src/util.c b/src/util.c
@@ -330,6 +330,9 @@ struct scan_freq_set *scan_freq_set_new(void)
void scan_freq_set_free(struct scan_freq_set *freqs)
{
+ if (!freqs)
+ return;
+
l_uintset_free(freqs->channels_5ghz);
l_uintset_free(freqs->channels_6ghz);
l_free(freqs);
@@ -378,7 +381,7 @@ bool scan_freq_set_contains(const struct scan_freq_set *freqs, uint32_t freq)
return false;
}
-uint32_t scan_freq_set_get_bands(struct scan_freq_set *freqs)
+uint32_t scan_freq_set_get_bands(const struct scan_freq_set *freqs)
{
uint32_t bands = 0;
uint32_t max;
@@ -499,6 +502,28 @@ void scan_freq_set_constrain(struct scan_freq_set *set,
set->channels_2ghz &= constraint->channels_2ghz;
}
+void scan_freq_set_subtract(struct scan_freq_set *set,
+ const struct scan_freq_set *subtract)
+{
+ struct l_uintset *sub;
+
+ sub = l_uintset_subtract(set->channels_6ghz, subtract->channels_6ghz);
+ if (L_WARN_ON(!sub))
+ return;
+
+ l_uintset_free(set->channels_6ghz);
+ set->channels_6ghz = sub;
+
+ sub = l_uintset_subtract(set->channels_5ghz, subtract->channels_5ghz);
+ if (L_WARN_ON(!sub))
+ return;
+
+ l_uintset_free(set->channels_5ghz);
+ set->channels_5ghz = sub;
+
+ set->channels_2ghz &= ~subtract->channels_2ghz;
+}
+
static void add_foreach(uint32_t freq, void *user_data)
{
uint32_t **list = user_data;
@@ -532,3 +557,24 @@ uint32_t *scan_freq_set_to_fixed_array(const struct scan_freq_set *set,
return freqs;
}
+
+struct scan_freq_set *scan_freq_set_clone(const struct scan_freq_set *set,
+ uint32_t band_mask)
+{
+ struct scan_freq_set *new = l_new(struct scan_freq_set, 1);
+
+ if (band_mask & BAND_FREQ_2_4_GHZ)
+ new->channels_2ghz = set->channels_2ghz;
+
+ if (band_mask & BAND_FREQ_5_GHZ)
+ new->channels_5ghz = l_uintset_clone(set->channels_5ghz);
+ else
+ new->channels_5ghz = l_uintset_new_from_range(1, 200);
+
+ if (band_mask & BAND_FREQ_6_GHZ)
+ new->channels_6ghz = l_uintset_clone(set->channels_6ghz);
+ else
+ new->channels_6ghz = l_uintset_new_from_range(1, 233);
+
+ return new;
+}
diff --git a/src/util.h b/src/util.h
@@ -25,6 +25,7 @@
#include <stdint.h>
#include <unistd.h>
+#include <ell/cleanup.h>
#define ___PASTE(a, b) a ## b
#define __PASTE(a, b) ___PASTE(a, b)
@@ -111,15 +112,21 @@ struct scan_freq_set *scan_freq_set_new(void);
void scan_freq_set_free(struct scan_freq_set *freqs);
bool scan_freq_set_add(struct scan_freq_set *freqs, uint32_t freq);
bool scan_freq_set_contains(const struct scan_freq_set *freqs, uint32_t freq);
-uint32_t scan_freq_set_get_bands(struct scan_freq_set *freqs);
+uint32_t scan_freq_set_get_bands(const struct scan_freq_set *freqs);
void scan_freq_set_foreach(const struct scan_freq_set *freqs,
scan_freq_set_func_t func, void *user_data);
void scan_freq_set_merge(struct scan_freq_set *to,
const struct scan_freq_set *from);
void scan_freq_set_constrain(struct scan_freq_set *set,
const struct scan_freq_set *constraint);
+void scan_freq_set_subtract(struct scan_freq_set *set,
+ const struct scan_freq_set *subtract);
bool scan_freq_set_isempty(const struct scan_freq_set *set);
uint32_t *scan_freq_set_to_fixed_array(const struct scan_freq_set *set,
size_t *len_out);
+struct scan_freq_set *scan_freq_set_clone(const struct scan_freq_set *set,
+ uint32_t band_mask);
+
+DEFINE_CLEANUP_FUNC(scan_freq_set_free);
#endif /* __UTIL_H */
diff --git a/src/wiphy.c b/src/wiphy.c
@@ -66,6 +66,7 @@ static char **blacklist_filter;
static int mac_randomize_bytes = 6;
static char regdom_country[2];
static uint32_t work_ids;
+static unsigned int wiphy_dump_id;
enum driver_flag {
DEFAULT_IF = 0x1,
@@ -104,6 +105,8 @@ struct wiphy {
uint16_t supported_iftypes;
uint16_t supported_ciphers;
struct scan_freq_set *supported_freqs;
+ struct scan_freq_set *disabled_freqs;
+ struct scan_freq_set *pending_freqs;
struct band *band_2g;
struct band *band_5g;
struct band *band_6g;
@@ -120,6 +123,8 @@ struct wiphy {
/* Work queue for this radio */
struct l_queue *work;
bool work_in_callback;
+ unsigned int get_reg_id;
+ unsigned int dump_id;
bool support_scheduled_scan:1;
bool support_rekey_offload:1;
@@ -132,6 +137,7 @@ struct wiphy {
bool offchannel_tx_ok : 1;
bool blacklisted : 1;
bool registered : 1;
+ bool self_managed : 1;
};
static struct l_queue *wiphy_list = NULL;
@@ -316,6 +322,7 @@ static struct wiphy *wiphy_new(uint32_t id)
wiphy->id = id;
wiphy->supported_freqs = scan_freq_set_new();
+ wiphy->disabled_freqs = scan_freq_set_new();
watchlist_init(&wiphy->state_watches, NULL);
wiphy->extended_capabilities[0] = IE_TYPE_EXTENDED_CAPABILITIES;
wiphy->extended_capabilities[1] = EXT_CAP_LEN;
@@ -338,6 +345,12 @@ static void wiphy_free(void *data)
l_debug("Freeing wiphy %s[%u]", wiphy->name, wiphy->id);
+ if (wiphy->dump_id)
+ l_genl_family_cancel(nl80211, wiphy->dump_id);
+
+ if (wiphy->get_reg_id)
+ l_genl_family_cancel(nl80211, wiphy->get_reg_id);
+
for (i = 0; i < NUM_NL80211_IFTYPES; i++)
l_free(wiphy->iftype_extended_capabilities[i]);
@@ -357,6 +370,7 @@ static void wiphy_free(void *data)
}
scan_freq_set_free(wiphy->supported_freqs);
+ scan_freq_set_free(wiphy->disabled_freqs);
watchlist_destroy(&wiphy->state_watches);
l_free(wiphy->model_str);
l_free(wiphy->vendor_str);
@@ -454,6 +468,11 @@ const struct scan_freq_set *wiphy_get_supported_freqs(
return wiphy->supported_freqs;
}
+const struct scan_freq_set *wiphy_get_disabled_freqs(const struct wiphy *wiphy)
+{
+ return wiphy->disabled_freqs;
+}
+
bool wiphy_can_transition_disable(struct wiphy *wiphy)
{
/*
@@ -699,6 +718,7 @@ bool wiphy_constrain_freq_set(const struct wiphy *wiphy,
struct scan_freq_set *set)
{
scan_freq_set_constrain(set, wiphy->supported_freqs);
+ scan_freq_set_subtract(set, wiphy->disabled_freqs);
if (!scan_freq_set_get_bands(set))
/* The set is empty. */
@@ -707,17 +727,16 @@ bool wiphy_constrain_freq_set(const struct wiphy *wiphy,
return true;
}
-static char **wiphy_get_supported_iftypes(struct wiphy *wiphy, uint16_t mask)
+static char **wiphy_iftype_mask_to_str(uint16_t mask)
{
- uint16_t supported_mask = wiphy->supported_iftypes & mask;
- char **ret = l_new(char *, __builtin_popcount(supported_mask) + 1);
+ char **ret = l_new(char *, __builtin_popcount(mask) + 1);
unsigned int i;
unsigned int j;
- for (j = 0, i = 0; i < sizeof(supported_mask) * 8; i++) {
+ for (j = 0, i = 0; i < sizeof(mask) * 8; i++) {
const char *str;
- if (!(supported_mask & (1 << i)))
+ if (!(mask & (1 << i)))
continue;
str = netdev_iftype_to_string(i + 1);
@@ -728,6 +747,11 @@ static char **wiphy_get_supported_iftypes(struct wiphy *wiphy, uint16_t mask)
return ret;
}
+static char **wiphy_get_supported_iftypes(struct wiphy *wiphy, uint16_t mask)
+{
+ return wiphy_iftype_mask_to_str(wiphy->supported_iftypes & mask);
+}
+
bool wiphy_supports_iftype(struct wiphy *wiphy, uint32_t iftype)
{
if (iftype > sizeof(wiphy->supported_iftypes) * 8)
@@ -776,6 +800,22 @@ void wiphy_get_reg_domain_country(struct wiphy *wiphy, char *out)
out[1] = country[1];
}
+bool wiphy_country_is_unknown(struct wiphy *wiphy)
+{
+ char cc[2];
+
+ wiphy_get_reg_domain_country(wiphy, cc);
+
+ /*
+ * Treat OO and XX as an unknown country. Additional codes could be
+ * added here if needed. The purpose of this is to know if we can
+ * expect the disabled frequency list to be updated once a country is
+ * known.
+ */
+ return ((cc[0] == 'O' && cc[1] == 'O') ||
+ (cc[0] == 'X' && cc[1] == 'X'));
+}
+
int wiphy_estimate_data_rate(struct wiphy *wiphy,
const void *ies, uint16_t ies_len,
const struct scan_bss *bss,
@@ -788,6 +828,7 @@ int wiphy_estimate_data_rate(struct wiphy *wiphy,
const void *vht_operation = NULL;
const void *ht_capabilities = NULL;
const void *ht_operation = NULL;
+ const void *he_capabilities = NULL;
const struct band *bandp;
enum band_freq band;
@@ -811,7 +852,7 @@ int wiphy_estimate_data_rate(struct wiphy *wiphy,
ie_tlv_iter_init(&iter, ies, ies_len);
while (ie_tlv_iter_next(&iter)) {
- uint8_t tag = ie_tlv_iter_get_tag(&iter);
+ uint16_t tag = ie_tlv_iter_get_tag(&iter);
switch (tag) {
case IE_TYPE_SUPPORTED_RATES:
@@ -847,11 +888,22 @@ int wiphy_estimate_data_rate(struct wiphy *wiphy,
vht_operation = iter.data - 2;
break;
+ case IE_TYPE_HE_CAPABILITIES:
+ if (!ie_validate_he_capabilities(iter.data, iter.len))
+ return -EBADMSG;
+
+ he_capabilities = iter.data;
+ break;
default:
break;
}
}
+ if (!band_estimate_he_rx_rate(bandp, he_capabilities,
+ bss->signal_strength / 100,
+ out_data_rate))
+ return 0;
+
if (!band_estimate_vht_rx_rate(bandp, vht_capabilities, vht_operation,
ht_capabilities, ht_operation,
bss->signal_strength / 100,
@@ -869,6 +921,11 @@ int wiphy_estimate_data_rate(struct wiphy *wiphy,
out_data_rate);
}
+bool wiphy_regdom_is_updating(struct wiphy *wiphy)
+{
+ return wiphy->pending_freqs != NULL;
+}
+
uint32_t wiphy_state_watch_add(struct wiphy *wiphy,
wiphy_state_watch_func_t func,
void *user_data, wiphy_destroy_func_t destroy)
@@ -903,23 +960,83 @@ static void wiphy_print_mcs_indexes(const uint8_t *mcs)
}
}
-static void wiphy_print_vht_mcs_info(const uint8_t *mcs_map,
- const char *prefix)
+static void wiphy_print_mcs_info(const uint8_t *mcs_map,
+ const char *prefix,
+ uint8_t value0,
+ uint8_t value1,
+ uint8_t value2)
{
int i;
for (i = 14; i >= 0; i -= 2) {
+ uint8_t value;
int mcs = bit_field(mcs_map[i / 8], i % 8, 2);
if (mcs == 0x3)
continue;
+ switch (mcs) {
+ case 0:
+ value = value0;
+ break;
+ case 1:
+ value = value1;
+ break;
+ case 2:
+ value = value2;
+ break;
+ }
+
l_info("\t\t\tMax %s MCS: 0-%d for NSS: %d", prefix,
- mcs + 7, i / 2 + 1);
+ value, i / 2 + 1);
return;
}
}
+static void wiphy_print_he_capabilities(struct band *band,
+ const struct band_he_capabilities *he_cap)
+{
+ _auto_(l_strv_free) char **iftypes = NULL;
+ _auto_(l_free) char *joined = NULL;
+ uint8_t width_set = bit_field(he_cap->he_phy_capa[0], 1, 7);
+
+ iftypes = wiphy_iftype_mask_to_str(he_cap->iftypes);
+ joined = l_strjoinv(iftypes, ' ');
+
+ l_info("\t\t\tInterface Types: %s", joined);
+
+ switch (band->freq) {
+ case BAND_FREQ_2_4_GHZ:
+ wiphy_print_mcs_info(he_cap->he_mcs_set,
+ "HE RX <= 80MHz", 7, 9, 11);
+ wiphy_print_mcs_info(he_cap->he_mcs_set + 2,
+ "HE TX <= 80MHz", 7, 9, 11);
+ break;
+ case BAND_FREQ_5_GHZ:
+ case BAND_FREQ_6_GHZ:
+ wiphy_print_mcs_info(he_cap->he_mcs_set,
+ "HE RX <= 80MHz", 7, 9, 11);
+ wiphy_print_mcs_info(he_cap->he_mcs_set + 2,
+ "HE TX <= 80MHz", 7, 9, 11);
+
+ if (test_bit(&width_set, 2)) {
+ wiphy_print_mcs_info(he_cap->he_mcs_set + 4,
+ "HE RX <= 160MHz", 7, 9, 11);
+ wiphy_print_mcs_info(he_cap->he_mcs_set + 6,
+ "HE TX <= 160MHz", 7, 9, 11);
+ }
+
+ if (test_bit(&width_set, 3)) {
+ wiphy_print_mcs_info(he_cap->he_mcs_set + 8,
+ "HE RX <= 80+80MHz", 7, 9, 11);
+ wiphy_print_mcs_info(he_cap->he_mcs_set + 10,
+ "HE TX <= 80+80MHz", 7, 9, 11);
+ }
+
+ break;
+ }
+}
+
static void wiphy_print_band_info(struct band *band, const char *name)
{
int i;
@@ -976,8 +1093,22 @@ static void wiphy_print_band_info(struct band *band, const char *name)
if (test_bit(band->vht_capabilities, 6))
l_info("\t\t\tShort GI for 160 and 80 + 80 Mhz");
- wiphy_print_vht_mcs_info(band->vht_mcs_set, "RX");
- wiphy_print_vht_mcs_info(band->vht_mcs_set + 4, "TX");
+ wiphy_print_mcs_info(band->vht_mcs_set, "RX", 7, 8, 9);
+ wiphy_print_mcs_info(band->vht_mcs_set + 4, "TX", 7, 8, 9);
+ }
+
+ if (band->he_capabilities) {
+ const struct l_queue_entry *entry;
+
+ l_info("\t\tHE Capabilities");
+
+ for (entry = l_queue_get_entries(band->he_capabilities);
+ entry; entry = entry->next) {
+ const struct band_he_capabilities *he_cap = entry->data;
+
+ wiphy_print_he_capabilities(band, he_cap);
+ }
+
}
}
@@ -1090,30 +1221,6 @@ static void parse_supported_ciphers(struct wiphy *wiphy, const void *data,
}
}
-static void parse_supported_frequencies(struct wiphy *wiphy,
- struct l_genl_attr *freqs)
-{
- uint16_t type, len;
- const void *data;
- struct l_genl_attr attr;
-
- while (l_genl_attr_next(freqs, NULL, NULL, NULL)) {
- if (!l_genl_attr_recurse(freqs, &attr))
- continue;
-
- while (l_genl_attr_next(&attr, &type, &len, &data)) {
- uint32_t u32;
-
- switch (type) {
- case NL80211_FREQUENCY_ATTR_FREQ:
- u32 = *((uint32_t *) data);
- scan_freq_set_add(wiphy->supported_freqs, u32);
- break;
- }
- }
- }
-}
-
static int parse_supported_rates(struct l_genl_attr *attr, struct band *band)
{
uint16_t type;
@@ -1187,11 +1294,103 @@ static struct band *band_new_from_message(struct l_genl_attr *band)
toalloc = sizeof(struct band) + count * sizeof(uint8_t);
ret = l_malloc(toalloc);
memset(ret, 0, toalloc);
+
+#if __GNUC__ == 11 && __GNUC_MINOR__ == 2
+_Pragma("GCC diagnostic push")
+_Pragma("GCC diagnostic ignored \"-Warray-bounds\"")
+#endif
memset(ret->vht_mcs_set, 0xff, sizeof(ret->vht_mcs_set));
+#if __GNUC__ == 11 && __GNUC_MINOR__ == 2
+_Pragma("GCC diagnostic pop")
+#endif
return ret;
}
+static uint32_t get_iftypes(struct l_genl_attr *iftypes)
+{
+ uint16_t type;
+ uint16_t len;
+ uint32_t types = 0;
+
+ while (l_genl_attr_next(iftypes, &type, &len, NULL)) {
+ if (len != 0)
+ continue;
+
+ types |= (1 << (type - 1));
+ }
+
+ return types;
+}
+
+static void parse_iftype_attrs(struct band *band, struct l_genl_attr *types)
+{
+ uint16_t type;
+ uint16_t len;
+ const void *data;
+ unsigned int count = 0;
+ struct band_he_capabilities *he_cap =
+ l_new(struct band_he_capabilities, 1);
+
+ while (l_genl_attr_next(types, &type, &len, &data)) {
+ struct l_genl_attr iftypes;
+
+ switch (type) {
+ case NL80211_BAND_IFTYPE_ATTR_IFTYPES:
+ if (!l_genl_attr_recurse(types, &iftypes))
+ goto parse_error;
+
+ he_cap->iftypes = get_iftypes(&iftypes);
+ break;
+ case NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY:
+ if (len > sizeof(he_cap->he_phy_capa))
+ continue;
+
+ memcpy(he_cap->he_phy_capa, data, len);
+ count++;
+ break;
+ case NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET:
+ if (len > sizeof(he_cap->he_mcs_set))
+ continue;
+
+ memcpy(he_cap->he_mcs_set, data, len);
+ count++;
+ break;
+ default:
+ break;
+ }
+ }
+
+ /*
+ * Since the capabilities element indicates what values are present in
+ * the MCS set ensure both values are parsed
+ */
+ if (count != 2 || !he_cap->iftypes)
+ goto parse_error;
+
+ if (!band->he_capabilities)
+ band->he_capabilities = l_queue_new();
+
+ l_queue_push_head(band->he_capabilities, he_cap);
+
+ return;
+
+parse_error:
+ l_free(he_cap);
+}
+
+static void parse_band_iftype_data(struct band *band, struct l_genl_attr *ifdata)
+{
+ while (l_genl_attr_next(ifdata, NULL, NULL, NULL)) {
+ struct l_genl_attr types;
+
+ if (!l_genl_attr_recurse(ifdata, &types))
+ continue;
+
+ parse_iftype_attrs(band, &types);
+ }
+}
+
static void parse_supported_bands(struct wiphy *wiphy,
struct l_genl_attr *bands)
{
@@ -1203,16 +1402,20 @@ static void parse_supported_bands(struct wiphy *wiphy,
while (l_genl_attr_next(bands, &type, NULL, NULL)) {
struct band **bandp;
struct band *band;
+ enum band_freq freq;
switch (type) {
case NL80211_BAND_2GHZ:
bandp = &wiphy->band_2g;
+ freq = BAND_FREQ_2_4_GHZ;
break;
case NL80211_BAND_5GHZ:
bandp = &wiphy->band_5g;
+ freq = BAND_FREQ_5_GHZ;
break;
case NL80211_BAND_6GHZ:
bandp = &wiphy->band_6g;
+ freq = BAND_FREQ_6_GHZ;
break;
default:
continue;
@@ -1226,6 +1429,8 @@ static void parse_supported_bands(struct wiphy *wiphy,
if (!band)
continue;
+ band->freq = freq;
+
/* Reset iter to beginning */
if (!l_genl_attr_recurse(bands, &attr)) {
band_free(band);
@@ -1234,15 +1439,15 @@ static void parse_supported_bands(struct wiphy *wiphy,
} else
band = *bandp;
+
while (l_genl_attr_next(&attr, &type, &len, &data)) {
- struct l_genl_attr freqs;
+ struct l_genl_attr nested;
switch (type) {
case NL80211_BAND_ATTR_FREQS:
- if (!l_genl_attr_recurse(&attr, &freqs))
- continue;
-
- parse_supported_frequencies(wiphy, &freqs);
+ nl80211_parse_supported_frequencies(&attr,
+ wiphy->supported_freqs,
+ wiphy->disabled_freqs);
break;
case NL80211_BAND_ATTR_RATES:
@@ -1282,6 +1487,12 @@ static void parse_supported_bands(struct wiphy *wiphy,
memcpy(band->ht_capabilities, data, len);
band->ht_supported = true;
break;
+ case NL80211_BAND_ATTR_IFTYPE_DATA:
+ if (!l_genl_attr_recurse(&attr, &nested))
+ continue;
+
+ parse_band_iftype_data(band, &nested);
+ break;
}
}
@@ -1430,6 +1641,9 @@ static void wiphy_parse_attributes(struct wiphy *wiphy,
case NL80211_ATTR_ROAM_SUPPORT:
wiphy->support_fw_roam = true;
break;
+ case NL80211_ATTR_WIPHY_SELF_MANAGED_REG:
+ wiphy->self_managed = true;
+ break;
}
}
}
@@ -1642,10 +1856,195 @@ static void wiphy_setup_rm_enabled_capabilities(struct wiphy *wiphy)
*/
}
-static void wiphy_update_reg_domain(struct wiphy *wiphy, bool global,
+static void wiphy_dump_done(void *user_data)
+{
+ struct wiphy *wiphy = user_data;
+ const struct l_queue_entry *e;
+
+ /* This dump was canceled due to another dump */
+ if ((wiphy && !wiphy->dump_id) || (!wiphy && !wiphy_dump_id))
+ return;
+
+ if (wiphy) {
+ wiphy->dump_id = 0;
+ scan_freq_set_free(wiphy->disabled_freqs);
+ wiphy->disabled_freqs = wiphy->pending_freqs;
+ wiphy->pending_freqs = NULL;
+
+ WATCHLIST_NOTIFY(&wiphy->state_watches,
+ wiphy_state_watch_func_t, wiphy,
+ WIPHY_STATE_WATCH_EVENT_REGDOM_DONE);
+
+ return;
+ }
+
+ wiphy_dump_id = 0;
+
+ for (e = l_queue_get_entries(wiphy_list); e; e = e->next) {
+ wiphy = e->data;
+
+ if (!wiphy->pending_freqs || wiphy->self_managed)
+ continue;
+
+ scan_freq_set_free(wiphy->disabled_freqs);
+ wiphy->disabled_freqs = wiphy->pending_freqs;
+ wiphy->pending_freqs = NULL;
+
+ WATCHLIST_NOTIFY(&wiphy->state_watches,
+ wiphy_state_watch_func_t, wiphy,
+ WIPHY_STATE_WATCH_EVENT_REGDOM_DONE);
+ }
+}
+
+/* We are dumping wiphy(s) due to a regulatory change */
+static void wiphy_dump_callback(struct l_genl_msg *msg,
+ void *user_data)
+{
+ struct wiphy *wiphy;
+ uint32_t id;
+ struct l_genl_attr bands;
+ struct l_genl_attr attr;
+ uint16_t type;
+
+ if (nl80211_parse_attrs(msg, NL80211_ATTR_WIPHY, &id,
+ NL80211_ATTR_WIPHY_BANDS, &bands,
+ NL80211_ATTR_UNSPEC) < 0)
+ return;
+
+ wiphy = wiphy_find(id);
+ if (L_WARN_ON(!wiphy))
+ return;
+
+ while (l_genl_attr_next(&bands, NULL, NULL, NULL)) {
+ if (!l_genl_attr_recurse(&bands, &attr))
+ return;
+
+ while (l_genl_attr_next(&attr, &type, NULL, NULL)) {
+ if (type != NL80211_BAND_ATTR_FREQS)
+ continue;
+
+ nl80211_parse_supported_frequencies(&attr, NULL,
+ wiphy->pending_freqs);
+ }
+ }
+}
+
+static bool wiphy_cancel_last_dump(struct wiphy *wiphy)
+{
+ const struct l_queue_entry *e;
+ unsigned int id = 0;
+
+ /*
+ * Zero command ID to signal that wiphy_dump_done doesn't need to do
+ * anything. For a self-managed wiphy just free/NULL pending_freqs. For
+ * a global dump each wiphy needs to be checked and dealt with.
+ */
+ if (wiphy && wiphy->dump_id) {
+ id = wiphy->dump_id;
+ wiphy->dump_id = 0;
+
+ scan_freq_set_free(wiphy->pending_freqs);
+ wiphy->pending_freqs = NULL;
+ } else if (!wiphy && wiphy_dump_id) {
+ id = wiphy_dump_id;
+ wiphy_dump_id = 0;
+
+ for (e = l_queue_get_entries(wiphy_list); e; e = e->next) {
+ struct wiphy *w = e->data;
+
+ if (!w->pending_freqs || w->self_managed)
+ continue;
+
+ scan_freq_set_free(w->pending_freqs);
+ w->pending_freqs = NULL;
+ }
+ }
+
+ if (id) {
+ l_debug("Canceling pending regdom wiphy dump (%s)",
+ wiphy ? wiphy->name : "global");
+
+ l_genl_family_cancel(nl80211, id);
+ }
+
+ return id != 0;
+}
+
+static void wiphy_dump_after_regdom(struct wiphy *wiphy)
+{
+ const struct l_queue_entry *e;
+ struct l_genl_msg *msg;
+ unsigned int id;
+ bool no_start_event;
+
+ msg = l_genl_msg_new_sized(NL80211_CMD_GET_WIPHY, 128);
+
+ if (wiphy)
+ l_genl_msg_append_attr(msg, NL80211_ATTR_WIPHY, 4, &wiphy->id);
+
+ l_genl_msg_append_attr(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP, 0, NULL);
+ id = l_genl_family_dump(nl80211, msg, wiphy_dump_callback,
+ wiphy, wiphy_dump_done);
+ if (!id) {
+ l_error("Wiphy information dump failed");
+ l_genl_msg_unref(msg);
+ return;
+ }
+
+ /*
+ * Another update while dumping wiphy. This next dump should supercede
+ * the first and not result in a DONE event until this new dump is
+ * finished. This is because the disabled frequencies are in an unknown
+ * state and could cause incorrect behavior by any watchers.
+ */
+ no_start_event = wiphy_cancel_last_dump(wiphy);
+
+ /* Limited dump so just emit the event for this wiphy */
+ if (wiphy) {
+ wiphy->dump_id = id;
+ wiphy->pending_freqs = scan_freq_set_new();
+
+ if (no_start_event)
+ return;
+
+ WATCHLIST_NOTIFY(&wiphy->state_watches,
+ wiphy_state_watch_func_t, wiphy,
+ WIPHY_STATE_WATCH_EVENT_REGDOM_STARTED);
+ return;
+ }
+
+ wiphy_dump_id = id;
+
+ /* Otherwise for a global regdom change notify for all wiphy's */
+ for (e = l_queue_get_entries(wiphy_list); e; e = e->next) {
+ struct wiphy *w = e->data;
+
+ if (w->self_managed)
+ continue;
+
+ w->pending_freqs = scan_freq_set_new();
+
+ if (no_start_event)
+ continue;
+
+ WATCHLIST_NOTIFY(&w->state_watches, wiphy_state_watch_func_t,
+ w, WIPHY_STATE_WATCH_EVENT_REGDOM_STARTED);
+ }
+}
+
+static bool wiphy_update_reg_domain(struct wiphy *wiphy, bool global,
struct l_genl_msg *msg)
{
- char *out_country;
+ char out_country[2];
+ char *orig;
+
+ /*
+ * Write the new country code or XX if the reg domain is not a
+ * country domain.
+ */
+ if (nl80211_parse_attrs(msg, NL80211_ATTR_REG_ALPHA2, out_country,
+ NL80211_ATTR_UNSPEC) < 0)
+ out_country[0] = out_country[1] = 'X';
if (global)
/*
@@ -1659,21 +2058,26 @@ static void wiphy_update_reg_domain(struct wiphy *wiphy, bool global,
* wiphy created (that is not self-managed anyway) and we
* haven't received any REG_CHANGE events yet.
*/
- out_country = regdom_country;
+ orig = regdom_country;
+
else
- out_country = wiphy->regdom_country;
+ orig = wiphy->regdom_country;
/*
- * Write the new country code or XX if the reg domain is not a
- * country domain.
+ * The kernel seems to send regdom updates even if the country didn't
+ * change. Skip these as there is no reason to re-dump.
*/
- if (nl80211_parse_attrs(msg, NL80211_ATTR_REG_ALPHA2, out_country,
- NL80211_ATTR_UNSPEC) < 0)
- out_country[0] = out_country[1] = 'X';
+ if (orig[0] == out_country[0] && orig[1] == out_country[1])
+ return false;
l_debug("New reg domain country code for %s is %c%c",
global ? "(global)" : wiphy->name,
out_country[0], out_country[1]);
+
+ orig[0] = out_country[0];
+ orig[1] = out_country[1];
+
+ return true;
}
static void wiphy_get_reg_cb(struct l_genl_msg *msg, void *user_data)
@@ -1682,6 +2086,8 @@ static void wiphy_get_reg_cb(struct l_genl_msg *msg, void *user_data)
uint32_t tmp;
bool global;
+ wiphy->get_reg_id = 0;
+
/*
* NL80211_CMD_GET_REG contains an NL80211_ATTR_WIPHY iff the wiphy
* uses a self-managed regulatory domain.
@@ -1699,8 +2105,9 @@ static void wiphy_get_reg_domain(struct wiphy *wiphy)
msg = l_genl_msg_new(NL80211_CMD_GET_REG);
l_genl_msg_append_attr(msg, NL80211_ATTR_WIPHY, 4, &wiphy->id);
- if (!l_genl_family_send(wiphy->nl80211, msg, wiphy_get_reg_cb, wiphy,
- NULL)) {
+ wiphy->get_reg_id = l_genl_family_send(wiphy->nl80211, msg,
+ wiphy_get_reg_cb, wiphy, NULL);
+ if (!wiphy->get_reg_id) {
l_error("Error sending NL80211_CMD_GET_REG for %s", wiphy->name);
l_genl_msg_unref(msg);
}
@@ -1916,31 +2323,35 @@ static void setup_wiphy_interface(struct l_dbus_interface *interface)
static void wiphy_reg_notify(struct l_genl_msg *msg, void *user_data)
{
uint8_t cmd = l_genl_msg_get_command(msg);
+ struct wiphy *wiphy = NULL;
+ uint32_t wiphy_id;
l_debug("Notification of command %s(%u)",
nl80211cmd_to_string(cmd), cmd);
switch (cmd) {
case NL80211_CMD_REG_CHANGE:
- wiphy_update_reg_domain(NULL, true, msg);
+ if (!wiphy_update_reg_domain(NULL, true, msg))
+ return;
break;
case NL80211_CMD_WIPHY_REG_CHANGE:
- {
- uint32_t wiphy_id;
- struct wiphy *wiphy;
-
if (nl80211_parse_attrs(msg, NL80211_ATTR_WIPHY, &wiphy_id,
NL80211_ATTR_UNSPEC) < 0)
- break;
+ return;
wiphy = wiphy_find(wiphy_id);
if (!wiphy)
- break;
+ return;
+
+ if (!wiphy_update_reg_domain(wiphy, false, msg))
+ return;
- wiphy_update_reg_domain(wiphy, false, msg);
break;
+ default:
+ return;
}
- }
+
+ wiphy_dump_after_regdom(wiphy);
}
static void wiphy_radio_work_next(struct wiphy *wiphy)
@@ -2121,6 +2532,11 @@ static void wiphy_exit(void)
l_strfreev(whitelist_filter);
l_strfreev(blacklist_filter);
+ if (wiphy_dump_id) {
+ l_genl_family_cancel(nl80211, wiphy_dump_id);
+ wiphy_dump_id = 0;
+ }
+
l_queue_destroy(wiphy_list, wiphy_free);
wiphy_list = NULL;
diff --git a/src/wiphy.h b/src/wiphy.h
@@ -56,6 +56,8 @@ enum {
enum wiphy_state_watch_event {
WIPHY_STATE_WATCH_EVENT_POWERED,
WIPHY_STATE_WATCH_EVENT_RFKILLED,
+ WIPHY_STATE_WATCH_EVENT_REGDOM_STARTED,
+ WIPHY_STATE_WATCH_EVENT_REGDOM_DONE,
};
typedef void (*wiphy_state_watch_func_t)(struct wiphy *wiphy,
@@ -93,6 +95,7 @@ const char *wiphy_get_path(struct wiphy *wiphy);
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_can_transition_disable(struct wiphy *wiphy);
bool wiphy_can_offload(struct wiphy *wiphy);
bool wiphy_supports_cmds_auth_assoc(struct wiphy *wiphy);
@@ -121,6 +124,7 @@ const uint8_t *wiphy_get_extended_capabilities(struct wiphy *wiphy,
const uint8_t *wiphy_get_rm_enabled_capabilities(struct wiphy *wiphy);
bool wiphy_get_rsnxe(const struct wiphy *wiphy, uint8_t *buf, size_t len);
void wiphy_get_reg_domain_country(struct wiphy *wiphy, char *out);
+bool wiphy_country_is_unknown(struct wiphy *wiphy);
void wiphy_generate_random_address(struct wiphy *wiphy, uint8_t addr[static 6]);
void wiphy_generate_address_from_ssid(struct wiphy *wiphy, const char *ssid,
@@ -130,6 +134,7 @@ int wiphy_estimate_data_rate(struct wiphy *wiphy,
const void *ies, uint16_t ies_len,
const struct scan_bss *bss,
uint64_t *out_data_rate);
+bool wiphy_regdom_is_updating(struct wiphy *wiphy);
uint32_t wiphy_state_watch_add(struct wiphy *wiphy,
wiphy_state_watch_func_t func, void *user_data,
diff --git a/tools/run-tests b/tools/run-tests
@@ -487,8 +487,6 @@ class TestContext(Namespace):
print("Ofono or Phonesim not found, skipping test")
return
- Process(['ip', 'link', 'set', 'lo', 'up']).wait()
-
os.environ['OFONO_PHONESIM_CONFIG'] = '/tmp/phonesim.conf'
phonesim_args = ['phonesim', '-p', '12345', '/usr/share/phonesim/default.xml']
@@ -889,7 +887,6 @@ def post_test(ctx, to_copy):
elif os.path.exists('/tmp/' + f):
os.remove('/tmp/' + f)
- Process(['ip', 'link', 'set', 'lo', 'down']).wait()
except Exception as e:
print("Exception thrown in post_test")
finally:
@@ -1037,7 +1034,12 @@ atexit.register(exit_vm)
runner.prepare_environment()
if runner.args.start:
- os.system(runner.args.start)
+ ctx = TestContext(runner.args)
+ ctx.start_dbus()
+ os.chdir(runner.args.testhome)
+ os.environ['DBUS_SYSTEM_BUS_ADDRESS'] = ctx.dbus_address
+
+ subprocess.run([runner.args.start])
else:
run_tests(runner.args)
diff --git a/tools/runner.py b/tools/runner.py
@@ -116,6 +116,9 @@ class RunnerCoreArgParse(ArgumentParser):
help='Writes PASS/FAIL to results file')
self.add_argument('--hw', '-w',
type=str,
+ nargs='?',
+ const=True,
+ action='store',
help='Use physical adapters for tests (passthrough)')
self.add_argument('--testhome', help=SUPPRESS)
self.add_argument('--monitor-parent', help=SUPPRESS)
@@ -367,6 +370,7 @@ class QemuRunner(RunnerAbstract):
usb_adapters = None
pci_adapters = None
+ ram = 256
super().__init__(args)
@@ -382,26 +386,29 @@ class QemuRunner(RunnerAbstract):
self._prepare_outfiles()
if args.hw:
- hw_conf = ConfigParser()
- hw_conf.read(args.hw)
+ if os.path.isfile(args.hw):
+ hw_conf = ConfigParser()
+ hw_conf.read(args.hw)
- if hw_conf.has_section('USBAdapters'):
- # The actual key name of the adapter
- # doesn't matter since all we need is the
- # bus/address. This gets named by the kernel
- # anyways once in the VM.
- usb_adapters = [v for v in hw_conf['USBAdapters'].values()]
+ if hw_conf.has_section('USBAdapters'):
+ # The actual key name of the adapter
+ # doesn't matter since all we need is the
+ # bus/address. This gets named by the kernel
+ # anyways once in the VM.
+ usb_adapters = [v for v in hw_conf['USBAdapters'].values()]
- if hw_conf.has_section('PCIAdapters'):
- pci_adapters = [v for v in hw_conf['PCIAdapters'].values()]
+ pci_adapters = self._find_pci_adapters()
kern_log = "ignore_loglevel" if "kernel" in args.verbose else "quiet"
+ if args.valgrind:
+ ram *= 2
+
qemu_cmdline = [
'qemu-system-x86_64',
'-machine', 'type=q35,accel=kvm:tcg',
'-nodefaults', '-no-user-config', '-monitor', 'none',
- '-display', 'none', '-m', '256M', '-nographic', '-vga',
+ '-display', 'none', '-m', '%dM' % ram, '-nographic', '-vga',
'none', '-no-acpi', '-no-hpet',
'-no-reboot', '-fsdev',
'local,id=fsdev-root,path=/,readonly=on,security_model=none,multidevs=remap',
@@ -473,6 +480,25 @@ class QemuRunner(RunnerAbstract):
self.cmdline = qemu_cmdline
+ def _find_pci_adapters(self):
+ adapters = []
+
+ try:
+ files = os.listdir('/sys/module/vfio_pci/drivers/pci:vfio-pci')
+ except:
+ return None
+
+ for bus_addr in files:
+ if not bus_addr.startswith('0000:'):
+ continue
+
+ adapters.append(bus_addr.replace('0000:', ''))
+
+ if len(adapters) == 0:
+ return None
+
+ return adapters
+
def prepare_environment(self):
mounts = [ MountInfo('debugfs', 'debugfs', '/sys/kernel/debug', '', 0) ]
diff --git a/tools/test_runner_kernel_config b/tools/test_runner_kernel_config
@@ -41,6 +41,7 @@ scripts/config --enable CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE
scripts/config --enable CONFIG_X509_CERTIFICATE_PARSER
scripts/config --enable CONFIG_PKCS7_MESSAGE_PARSER
scripts/config --enable CONFIG_PKCS8_PRIVATE_KEY_PARSER
+scripts/config --enable CONFIG_CRYPTO_ECDSA
scripts/config --enable CONFIG_HW_RANDOM_VIRTIO
scripts/config --enable CONFIG_HW_RANDOM_INTEL
diff --git a/tools/utils.py b/tools/utils.py
@@ -246,6 +246,10 @@ class Process(subprocess.Popen):
# Override wait() so it can do so non-blocking
def wait(self, timeout=10):
+ if timeout == None:
+ super().wait()
+ return
+
Namespace.non_block_wait(self.__wait, timeout, 1)
self._cleanup()
@@ -407,7 +411,8 @@ class Namespace:
self._bus = dbus.bus.BusConnection(address_or_type=self.dbus_address)
- def start_iwd(self, config_dir = '/tmp', storage_dir = '/tmp/iwd'):
+ def start_iwd(self, config_dir = '/tmp', storage_dir = '/tmp/iwd',
+ developer_mode = True):
args = []
iwd_radios = ','.join([r.name for r in self.radios if r.use == 'iwd'])
@@ -416,7 +421,10 @@ class Namespace:
'--show-leak-kinds=all',
'--log-file=/tmp/valgrind.log.%p'])
- args.extend(['iwd', '-E'])
+ args.append('iwd')
+
+ if developer_mode:
+ args.append('-E')
if iwd_radios != '':
args.extend(['-p', iwd_radios])
diff --git a/unit/test-band.c b/unit/test-band.c
@@ -32,6 +32,8 @@
#include <ell/ell.h>
#include "src/band.h"
+#include "src/netdev.h"
+#include "src/ie.h"
static struct band *new_band()
{
@@ -52,6 +54,8 @@ static struct band *new_band()
/* band + 8 basic rates */
struct band *band = l_malloc(sizeof(struct band) + 8);
+ memset(band, 0, sizeof(struct band) + 8);
+
band->supported_rates_len = 8;
band->supported_rates[0] = 12;
band->supported_rates[1] = 18;
@@ -282,6 +286,228 @@ static void band_test_vht_1(const void *data)
band_free(band);
}
+struct he_test_data {
+ enum band_freq freq;
+ int32_t rssi;
+ uint64_t expected_rate;
+ int expected_return;
+ /* Own capabilities */
+ struct band_he_capabilities capabilities;
+ /* Peer HE Capabilities IE */
+ uint8_t he_capabilities[31];
+
+};
+
+/* IWD doesn't look at this */
+#define HE_MAC_CAPA 0, 0, 0, 0, 0, 0
+/* IWD only cares about the width set byte */
+#define HE_PHY_CAPA(wset) wset, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+
+#define MCS7 0
+#define MCS9 1
+#define MCS11 2
+#define MCS_UNSUP 0xff, 0xff
+/* A readable macro for defining MCS sets */
+#define HE_MCS_SET(mcs, nss) \
+ (nss >= 1 ? mcs << 0 : 3 << 0) | \
+ (nss >= 2 ? mcs << 2 : 3 << 2) | \
+ (nss >= 3 ? mcs << 4 : 3 << 4) | \
+ (nss >= 4 ? mcs << 6 : 3 << 6), \
+ (nss >= 5 ? mcs << 0 : 3 << 0) | \
+ (nss >= 6 ? mcs << 2 : 3 << 2) | \
+ (nss >= 7 ? mcs << 4 : 3 << 4) | \
+ (nss >= 8 ? mcs << 6 : 3 << 6)
+
+/* 2.4GHz, 20MHz, MCS 7, NSS 1 */
+const struct he_test_data he_test_2_4_20mhz_mcs_7_nss_1 = {
+ .freq = BAND_FREQ_2_4_GHZ,
+ .rssi = -20,
+ .expected_rate = 86000000ULL,
+ .capabilities = {
+ .he_mcs_set = { HE_MCS_SET(MCS7, 1), MCS_UNSUP },
+ .he_phy_capa = { HE_PHY_CAPA(0x00) },
+ .iftypes = 1 << NETDEV_IFTYPE_STATION,
+ },
+ .he_capabilities = {
+ 22, IE_TYPE_HE_CAPABILITIES - 256, HE_MAC_CAPA,
+ HE_PHY_CAPA(0x00), MCS_UNSUP, HE_MCS_SET(MCS7, 1),
+ },
+};
+
+/* 2.4GHz, 40MHz, MCS 7, NSS 1 */
+const struct he_test_data he_test_2_4_40mhz_mcs_7_nss_1 = {
+ .freq = BAND_FREQ_2_4_GHZ,
+ .rssi = -20,
+ .expected_rate = 172000000ULL,
+ .capabilities = {
+ .he_mcs_set = { HE_MCS_SET(MCS7, 1), MCS_UNSUP },
+ .he_phy_capa = { HE_PHY_CAPA(0x02) },
+ .iftypes = 1 << NETDEV_IFTYPE_STATION,
+ },
+ .he_capabilities = {
+ 22, IE_TYPE_HE_CAPABILITIES - 256, HE_MAC_CAPA,
+ HE_PHY_CAPA(0x02), MCS_UNSUP, HE_MCS_SET(MCS7, 1),
+ },
+};
+
+/* 5GHz, 20MHz, MCS 7, NSS 1 */
+const struct he_test_data he_test_5_20mhz_mcs_7_nss_1 = {
+ .freq = BAND_FREQ_5_GHZ,
+ .rssi = -20,
+ .expected_rate = 86000000ULL,
+ .capabilities = {
+ .he_mcs_set = { HE_MCS_SET(MCS7, 1), MCS_UNSUP },
+ .he_phy_capa = { HE_PHY_CAPA(0x00) },
+ .iftypes = 1 << NETDEV_IFTYPE_STATION,
+ },
+ .he_capabilities = {
+ 22, IE_TYPE_HE_CAPABILITIES - 256, HE_MAC_CAPA,
+ HE_PHY_CAPA(0x00), MCS_UNSUP, HE_MCS_SET(MCS7, 1)
+ },
+};
+
+/* 5GHz, 80MHz, MCS 7, NSS 1 */
+const struct he_test_data he_test_5_80mhz_mcs_7_nss_1 = {
+ .freq = BAND_FREQ_5_GHZ,
+ .rssi = -20,
+ .expected_rate = 360300000ULL,
+ .capabilities = {
+ .he_mcs_set = { HE_MCS_SET(MCS7, 1), MCS_UNSUP },
+ .he_phy_capa = { HE_PHY_CAPA(0x04) },
+ .iftypes = 1 << NETDEV_IFTYPE_STATION,
+ },
+ .he_capabilities = {
+ 22, IE_TYPE_HE_CAPABILITIES - 256, HE_MAC_CAPA,
+ HE_PHY_CAPA(0x04), MCS_UNSUP, HE_MCS_SET(MCS7, 1)
+ },
+};
+
+/* 5GHz, 160MHz, MCS 7, NSS 1 */
+const struct he_test_data he_test_5_160mhz_mcs_7_nss_1 = {
+ .freq = BAND_FREQ_5_GHZ,
+ .rssi = -20,
+ .expected_rate = 720600000ULL,
+ .capabilities = {
+ .he_mcs_set = { HE_MCS_SET(MCS7, 1), MCS_UNSUP,
+ HE_MCS_SET(MCS7, 1), MCS_UNSUP },
+ .he_phy_capa = { HE_PHY_CAPA(0x0c) },
+ .iftypes = 1 << NETDEV_IFTYPE_STATION,
+ },
+ .he_capabilities = {
+ 26, IE_TYPE_HE_CAPABILITIES - 256, HE_MAC_CAPA,
+ HE_PHY_CAPA(0x0c), MCS_UNSUP, HE_MCS_SET(MCS7, 1),
+ MCS_UNSUP, HE_MCS_SET(MCS7, 1)
+ },
+};
+
+/* 5GHz, 160/80+80MHz, MCS 7, NSS 1 */
+const struct he_test_data he_test_5_160_80_P_80_mhz_mcs_7_nss_1 = {
+ .freq = BAND_FREQ_5_GHZ,
+ .rssi = -20,
+ .expected_rate = 720600000ULL,
+ .capabilities = {
+ .he_mcs_set = { HE_MCS_SET(MCS7, 1), MCS_UNSUP,
+ HE_MCS_SET(MCS7, 1), MCS_UNSUP,
+ HE_MCS_SET(MCS7, 1), MCS_UNSUP },
+ .he_phy_capa = { HE_PHY_CAPA(0x1c) },
+ .iftypes = 1 << NETDEV_IFTYPE_STATION,
+ },
+ .he_capabilities = {
+ 30, IE_TYPE_HE_CAPABILITIES - 256, HE_MAC_CAPA,
+ HE_PHY_CAPA(0x1c), MCS_UNSUP, HE_MCS_SET(MCS7, 1),
+ MCS_UNSUP, HE_MCS_SET(MCS7, 1),
+ MCS_UNSUP, HE_MCS_SET(MCS7, 1)
+ },
+};
+
+/* 5GHz, max data rate */
+const struct he_test_data he_test_5_max_data_rate = {
+ .freq = BAND_FREQ_5_GHZ,
+ .rssi = -20,
+ .expected_rate = 1201000000ULL * 8ULL,
+ .capabilities = {
+ .he_mcs_set = { HE_MCS_SET(MCS11, 8), MCS_UNSUP,
+ HE_MCS_SET(MCS11, 8), MCS_UNSUP,
+ HE_MCS_SET(MCS11, 8), MCS_UNSUP },
+ .he_phy_capa = { HE_PHY_CAPA(0x1c) },
+ .iftypes = 1 << NETDEV_IFTYPE_STATION,
+ },
+ .he_capabilities = {
+ 30, IE_TYPE_HE_CAPABILITIES - 256, HE_MAC_CAPA,
+ HE_PHY_CAPA(0x1c), MCS_UNSUP, HE_MCS_SET(MCS11, 8),
+ MCS_UNSUP, HE_MCS_SET(MCS11, 8),
+ MCS_UNSUP, HE_MCS_SET(MCS11, 8)
+ },
+};
+
+const struct he_test_data he_all_mcs_unsupported = {
+ .freq = BAND_FREQ_5_GHZ,
+ .rssi = -20,
+ .expected_rate = 1201000000ULL * 8ULL,
+ .expected_return = -EBADMSG,
+ .capabilities = {
+ .he_mcs_set = { MCS_UNSUP, MCS_UNSUP,
+ MCS_UNSUP, MCS_UNSUP,
+ MCS_UNSUP, MCS_UNSUP },
+ .he_phy_capa = { HE_PHY_CAPA(0x1c) },
+ .iftypes = 1 << NETDEV_IFTYPE_STATION,
+ },
+ .he_capabilities = {
+ 30, IE_TYPE_HE_CAPABILITIES - 256, HE_MAC_CAPA,
+ HE_PHY_CAPA(0x1c), MCS_UNSUP, MCS_UNSUP,
+ MCS_UNSUP, MCS_UNSUP,
+ MCS_UNSUP, MCS_UNSUP
+ },
+};
+
+/* 5GHz, max data rate, low-rssi */
+const struct he_test_data he_test_5_low_rssi = {
+ .freq = BAND_FREQ_5_GHZ,
+ .rssi = -80, /* Should force 20MHz/MCS0 width to be used */
+ .expected_rate = 8600000ULL * 8ULL,
+ .capabilities = {
+ .he_mcs_set = { HE_MCS_SET(MCS11, 8), MCS_UNSUP,
+ HE_MCS_SET(MCS11, 8), MCS_UNSUP,
+ HE_MCS_SET(MCS11, 8), MCS_UNSUP },
+ .he_phy_capa = { HE_PHY_CAPA(0x1c) },
+ .iftypes = 1 << NETDEV_IFTYPE_STATION,
+ },
+ .he_capabilities = {
+ 30, IE_TYPE_HE_CAPABILITIES - 256, HE_MAC_CAPA,
+ HE_PHY_CAPA(0x1c), MCS_UNSUP, HE_MCS_SET(MCS11, 8),
+ MCS_UNSUP, HE_MCS_SET(MCS11, 8),
+ MCS_UNSUP, HE_MCS_SET(MCS11, 8)
+ },
+};
+
+static void band_test_he(const void *data)
+{
+ const struct he_test_data *he_data = data;
+ struct band *band;
+ uint64_t rate = 0;
+ int ret;
+
+ band = new_band();
+ band->freq = he_data->freq;
+ band->he_capabilities = l_queue_new();
+
+ l_queue_push_tail(band->he_capabilities,
+ (void*)&(he_data->capabilities));
+
+ assert(ie_validate_he_capabilities(he_data->he_capabilities + 2,
+ he_data->he_capabilities[0]));
+
+ ret = band_estimate_he_rx_rate(band, he_data->he_capabilities + 2,
+ he_data->rssi, &rate);
+ assert(ret == he_data->expected_return);
+
+ if (ret == 0)
+ assert(rate == he_data->expected_rate);
+
+ l_queue_destroy(band->he_capabilities, NULL);
+ l_free(band);
+}
+
struct oci2freq_data {
unsigned int op;
unsigned int chan;
@@ -434,6 +660,25 @@ int main(int argc, char *argv[])
l_test_add("/band/VHT/test1", band_test_vht_1, NULL);
+ l_test_add("/band/HE/test/2.4GHz/20MHz/MCS7/NSS1", band_test_he,
+ &he_test_2_4_20mhz_mcs_7_nss_1);
+ l_test_add("/band/HE/test/2.4GHz/40MHz/MCS7/NSS1", band_test_he,
+ &he_test_2_4_40mhz_mcs_7_nss_1);
+ l_test_add("/band/HE/test/5GHz/20MHz/MCS7/NSS1", band_test_he,
+ &he_test_5_20mhz_mcs_7_nss_1);
+ l_test_add("/band/HE/test/5GHz/80MHz/MCS7/NSS1", band_test_he,
+ &he_test_5_80mhz_mcs_7_nss_1);
+ l_test_add("/band/HE/test/5GHz/160MHz/MCS7/NSS1", band_test_he,
+ &he_test_5_160mhz_mcs_7_nss_1);
+ l_test_add("/band/HE/test/5GHz/160/80+80MHz/MCS7/NSS1", band_test_he,
+ &he_test_5_160_80_P_80_mhz_mcs_7_nss_1);
+ l_test_add("/band/HE/test/5GHz/max data rate", band_test_he,
+ &he_test_5_max_data_rate);
+ l_test_add("/band/HE/test/all MCS unsupported", band_test_he,
+ &he_all_mcs_unsupported);
+ l_test_add("/band/HE/test/low RSSI", band_test_he,
+ &he_test_5_low_rssi);
+
l_test_add("/band/oci2freq 1", test_oci2freq, &oci2freq_data_1);
l_test_add("/band/oci2freq 2", test_oci2freq, &oci2freq_data_2);
l_test_add("/band/oci2freq 3", test_oci2freq, &oci2freq_data_3);