commit 8f02cded430980a6cf77d603554da13c7afffa6a
parent 3b6c2ae3b0955e0c278d03a756125c1fb8f2e7f0
Author: illiliti <illiliti@protonmail.com>
Date: Sat, 12 Jun 2021 20:46:24 +0300
Merge tag '1.15'
Release 1.15
Diffstat:
74 files changed, 3364 insertions(+), 1880 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -54,6 +54,7 @@ unit/test-eap-mschapv2
unit/test-eap-sim
unit/test-client
unit/test-p2p
+unit/test-band
unit/cert-*.pem
unit/cert-*.csr
unit/cert-*.srl
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,8 @@
+ver 1.15:
+ Add support for FT-over-DS procedure with multiple BSS.
+ Add support for estimation of VHT RX data rate.
+ Add support for exporting Daemon information.
+
ver 1.14:
Fix issue with scanning property and quick scan cancellation.
Fix issue with handling authentication timeouts from SAE.
diff --git a/Makefile.am b/Makefile.am
@@ -244,6 +244,8 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h src/missing.h \
src/eap-wsc.c src/eap-wsc.h \
src/wscutil.h src/wscutil.c \
src/diagnostic.h src/diagnostic.c \
+ src/ip-pool.h src/ip-pool.c \
+ src/band.h src/band.c \
$(eap_sources) \
$(builtin_sources)
@@ -386,7 +388,7 @@ unit_tests = unit/test-cmac-aes \
unit/test-crypto unit/test-eapol unit/test-mpdu \
unit/test-ie unit/test-util unit/test-ssid-security \
unit/test-arc4 unit/test-wsc unit/test-eap-mschapv2 \
- unit/test-eap-sim unit/test-sae unit/test-p2p
+ unit/test-eap-sim unit/test-sae unit/test-p2p unit/test-band
if CLIENT
unit_tests += unit/test-client
@@ -443,6 +445,9 @@ 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_LDADD = $(ell_ldadd)
+
unit_test_crypto_SOURCES = unit/test-crypto.c \
src/crypto.h src/crypto.c
unit_test_crypto_LDADD = $(ell_ldadd)
diff --git a/README b/README
@@ -271,7 +271,7 @@ Mailing list:
https://lists.01.org/postorius/lists/iwd.lists.01.org/
IRC:
- irc://irc.freenode.net/#iwd
+ irc://irc.oftc.net/#iwd
Wiki:
https://iwd.wiki.kernel.org/
diff --git a/autotests/testAP/dhcp/main.conf b/autotests/testAP/dhcp/main.conf
@@ -3,4 +3,6 @@ DisableMacAddressRandomization=true
[General]
EnableNetworkConfiguration=true
-APRanges=192.168.80.0/23
+
+[IPv4]
+APAddressPool=192.168.80.0/27
diff --git a/autotests/testAP/dhcp_test.py b/autotests/testAP/dhcp_test.py
@@ -58,8 +58,14 @@ class Test(unittest.TestCase):
testutil.test_iface_operstate(dev2.name)
testutil.test_ifaces_connected(dev1.name, dev2.name, group=False)
- testutil.test_ip_address_match(dev1.name, "192.168.80.1")
- testutil.test_ip_address_match(dev2.name, "192.168.80.2")
+ try:
+ testutil.test_ip_address_match(dev1.name, "192.168.80.1")
+ testutil.test_ip_address_match(dev2.name, "192.168.80.2")
+ ip = "192.168.80.1"
+ except:
+ testutil.test_ip_address_match(dev1.name, "192.168.80.17")
+ testutil.test_ip_address_match(dev2.name, "192.168.80.18")
+ ip = "192.168.80.17"
wd.unregister_psk_agent(psk_agent)
@@ -76,7 +82,7 @@ class Test(unittest.TestCase):
# got initially.
dev4.start_ap('TestAP4', 'Password4')
- testutil.test_ip_address_match(dev4.name, "192.168.80.1")
+ testutil.test_ip_address_match(dev4.name, ip)
finally:
dev1.stop_ap()
diff --git a/autotests/testAPRoam/connection_test.py b/autotests/testAPRoam/connection_test.py
@@ -36,9 +36,9 @@ class Test(unittest.TestCase):
rule2.source = bss_radio[2].addresses[0]
rule2.bidirectional = True
- rule0.signal = -2000
- rule1.signal = -2500
- rule2.signal = -3000
+ rule0.signal = -6000
+ rule1.signal = -6900
+ rule2.signal = -8000
wd = IWD()
diff --git a/autotests/testFT-8021x-roam/connection_test.py b/autotests/testFT-8021x-roam/connection_test.py
@@ -23,13 +23,13 @@ class Test(unittest.TestCase):
rule1.source = self.bss_radio[1].addresses[0]
rule1.bidirectional = True
- wd = IWD()
-
- device = wd.list_devices(1)[0]
-
# Check that iwd selects BSS 0 first
rule0.signal = -2000
- rule1.signal = -2500
+ rule1.signal = -6900
+
+ wd = IWD(True)
+
+ device = wd.list_devices(1)[0]
condition = 'not obj.scanning'
wd.wait_for_object_condition(device, condition)
@@ -97,16 +97,6 @@ class Test(unittest.TestCase):
os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up')
hwsim = Hwsim()
- wd = IWD()
- device = wd.list_devices(1)[0]
- try:
- device.disconnect()
- except:
- pass
-
- condition = 'obj.state == DeviceState.disconnected'
- wd.wait_for_object_condition(device, condition)
-
for rule in list(hwsim.rules.keys()):
del hwsim.rules[rule]
@@ -128,7 +118,9 @@ class Test(unittest.TestCase):
'" down hw ether 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
diff --git a/autotests/testFT-8021x-roam/hw.conf b/autotests/testFT-8021x-roam/hw.conf
@@ -1,5 +1,6 @@
[SETUP]
num_radios=3
+start_iwd=0
[HOSTAPD]
rad0=ft-eap-ccmp-1.conf
diff --git a/autotests/testFT-FILS-SHA256/connection_test.py b/autotests/testFT-FILS-SHA256/connection_test.py
@@ -24,7 +24,11 @@ class Test(unittest.TestCase):
rule1.source = self.bss_radio[1].addresses[0]
rule1.bidirectional = True
- wd = IWD()
+ # Check that iwd selects BSS 0 first
+ rule0.signal = -2000
+ rule1.signal = -6900
+
+ wd = IWD(True)
psk_agent = PSKAgent('user@example.com', ('user@example.com',
'secret123'))
@@ -32,10 +36,6 @@ class Test(unittest.TestCase):
device = wd.list_devices(1)[0]
- # Check that iwd selects BSS 0 first
- rule0.signal = -2000
- rule1.signal = -2500
-
condition = 'not obj.scanning'
wd.wait_for_object_condition(device, condition)
@@ -127,16 +127,6 @@ class Test(unittest.TestCase):
os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up')
hwsim = Hwsim()
- wd = IWD()
- device = wd.list_devices(1)[0]
- try:
- device.disconnect()
- except:
- pass
-
- condition = 'obj.state == DeviceState.disconnected'
- wd.wait_for_object_condition(device, condition)
-
for rule in list(hwsim.rules.keys()):
del hwsim.rules[rule]
@@ -159,7 +149,9 @@ class Test(unittest.TestCase):
'" down hw ether 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
diff --git a/autotests/testFT-FILS-SHA256/hw.conf b/autotests/testFT-FILS-SHA256/hw.conf
@@ -1,5 +1,6 @@
[SETUP]
num_radios=3
+start_iwd=0
[HOSTAPD]
rad0=ft-eap-ccmp-1.conf
diff --git a/autotests/testFT-FILS-SHA384/connection_test.py b/autotests/testFT-FILS-SHA384/connection_test.py
@@ -24,7 +24,11 @@ class Test(unittest.TestCase):
rule1.source = self.bss_radio[1].addresses[0]
rule1.bidirectional = True
- wd = IWD()
+ # Check that iwd selects BSS 0 first
+ rule0.signal = -2000
+ rule1.signal = -6900
+
+ wd = IWD(True)
psk_agent = PSKAgent('user@example.com', ('user@example.com',
'secret123'))
@@ -32,10 +36,6 @@ class Test(unittest.TestCase):
device = wd.list_devices(1)[0]
- # Check that iwd selects BSS 0 first
- rule0.signal = -2000
- rule1.signal = -2500
-
condition = 'not obj.scanning'
wd.wait_for_object_condition(device, condition)
@@ -127,16 +127,6 @@ class Test(unittest.TestCase):
os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up')
hwsim = Hwsim()
- wd = IWD()
- device = wd.list_devices(1)[0]
- try:
- device.disconnect()
- except:
- pass
-
- condition = 'obj.state == DeviceState.disconnected'
- wd.wait_for_object_condition(device, condition)
-
for rule in list(hwsim.rules.keys()):
del hwsim.rules[rule]
@@ -159,7 +149,9 @@ class Test(unittest.TestCase):
'" down hw ether 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
diff --git a/autotests/testFT-FILS-SHA384/hw.conf b/autotests/testFT-FILS-SHA384/hw.conf
@@ -1,5 +1,6 @@
[SETUP]
num_radios=3
+start_iwd=0
[HOSTAPD]
rad0=ft-eap-ccmp-1.conf
diff --git a/autotests/testFT-PSK-over-DS/connection_test.py b/autotests/testFT-PSK-over-DS/connection_test.py
@@ -24,17 +24,17 @@ class Test(unittest.TestCase):
rule1.source = self.bss_radio[1].addresses[0]
rule1.bidirectional = True
- wd = IWD()
+ # Check that iwd selects BSS 0 first
+ rule0.signal = -2000
+ rule1.signal = -6900
+
+ wd = IWD(True)
psk_agent = PSKAgent("EasilyGuessedPassword")
wd.register_psk_agent(psk_agent)
device = wd.list_devices(1)[0]
- # Check that iwd selects BSS 0 first
- rule0.signal = -2000
- rule1.signal = -2500
-
condition = 'not obj.scanning'
wd.wait_for_object_condition(device, condition)
@@ -62,8 +62,13 @@ class Test(unittest.TestCase):
condition = 'obj.state == DeviceState.connected'
wd.wait_for_object_condition(device, condition)
+ self.bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % device.address)
+
+ # list_sta actually reports any authenticated stations. Due to the
+ # nature of FT-over-DS IWD should authenticate to all stations with
+ # the same mobility domain. This means both APs should show our station.
self.assertTrue(self.bss_hostapd[0].list_sta())
- self.assertFalse(self.bss_hostapd[1].list_sta())
+ self.assertTrue(self.bss_hostapd[1].list_sta())
wd.unregister_psk_agent(psk_agent)
@@ -103,16 +108,6 @@ class Test(unittest.TestCase):
os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up')
hwsim = Hwsim()
- wd = IWD()
- device = wd.list_devices(1)[0]
- try:
- device.disconnect()
- except:
- pass
-
- condition = 'obj.state == DeviceState.disconnected'
- wd.wait_for_object_condition(device, condition)
-
for rule in list(hwsim.rules.keys()):
del hwsim.rules[rule]
@@ -132,7 +127,9 @@ class Test(unittest.TestCase):
'" down hw ether 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
diff --git a/autotests/testFT-PSK-over-DS/hw.conf b/autotests/testFT-PSK-over-DS/hw.conf
@@ -1,5 +1,6 @@
[SETUP]
num_radios=3
+start_iwd=0
[HOSTAPD]
rad0=ft-psk-ccmp-1.conf
diff --git a/autotests/testFT-PSK-roam/connection_test.py b/autotests/testFT-PSK-roam/connection_test.py
@@ -34,8 +34,6 @@ class Test(unittest.TestCase):
wd.register_psk_agent(psk_agent)
device = wd.list_devices(1)[0]
- # prevent autoconnect
- device.disconnect()
condition = 'not obj.scanning'
wd.wait_for_object_condition(device, condition)
@@ -124,7 +122,6 @@ class Test(unittest.TestCase):
os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up')
hwsim = Hwsim()
-
for rule in list(hwsim.rules.keys()):
del hwsim.rules[rule]
@@ -144,7 +141,9 @@ class Test(unittest.TestCase):
'" down hw ether 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
diff --git a/autotests/testFT-SAE-roam/connection_test.py b/autotests/testFT-SAE-roam/connection_test.py
@@ -15,8 +15,6 @@ from config import ctx
class Test(unittest.TestCase):
def test_roam_success(self):
- wd = IWD()
-
hwsim = Hwsim()
rule0 = hwsim.rules.create()
@@ -31,16 +29,18 @@ class Test(unittest.TestCase):
rule2.source = self.bss_radio[2].addresses[0]
rule2.bidirectional = True
+ # Check that iwd selects BSS 0 first
+ rule0.signal = -2000
+ rule1.signal = -6900
+ rule2.signal = -7200
+
+ wd = IWD(True)
+
psk_agent = PSKAgent("EasilyGuessedPassword")
wd.register_psk_agent(psk_agent)
device = wd.list_devices(1)[0]
- # Check that iwd selects BSS 0 first
- rule0.signal = -2000
- rule1.signal = -2500
- rule2.signal = -3000
-
condition = 'not obj.scanning'
wd.wait_for_object_condition(device, condition)
@@ -135,16 +135,6 @@ class Test(unittest.TestCase):
os.system('ifconfig "' + self.bss_hostapd[2].ifname + '" up')
hwsim = Hwsim()
- wd = IWD()
- device = wd.list_devices(1)[0]
- try:
- device.disconnect()
- except:
- pass
-
- condition = 'obj.state == DeviceState.disconnected'
- wd.wait_for_object_condition(device, condition)
-
for rule in list(hwsim.rules.keys()):
del hwsim.rules[rule]
diff --git a/autotests/testFT-SAE-roam/hw.conf b/autotests/testFT-SAE-roam/hw.conf
@@ -1,5 +1,6 @@
[SETUP]
num_radios=4
+start_iwd=0
[HOSTAPD]
rad0=ft-sae-1.conf
diff --git a/autotests/testHT-VHT/connection_test.py b/autotests/testHT-VHT/connection_test.py
@@ -61,17 +61,17 @@ class Test(unittest.TestCase):
rule0 = hwsim.rules.create()
rule0.source = vht_radio.addresses[0]
rule0.bidirectional = True
- rule0.signal = -2000
+ rule0.signal = -5100
rule1 = hwsim.rules.create()
rule1.source = ht_radio.addresses[0]
rule1.bidirectional = True
- rule1.signal = -2000
+ rule1.signal = -5200
rule2 = hwsim.rules.create()
rule2.source = non_ht_radio.addresses[0]
rule2.bidirectional = True
- rule2.signal = -2000
+ rule2.signal = -5300
wd = IWD()
@@ -83,12 +83,12 @@ class Test(unittest.TestCase):
self.do_connect(wd, device, vht_hostapd)
# lower VHT BSS signal, HT should now be preferred
- rule0.signal = -6000
+ rule0.signal = -8200
self.do_connect(wd, device, ht_hostapd)
# lower HT BSS signal, basic rate BSS should now be preferred
- rule1.signal = -6000
+ rule1.signal = -7600
self.do_connect(wd, device, non_ht_hostapd)
diff --git a/autotests/testP2P/client_test.py b/autotests/testP2P/client_test.py
@@ -1,106 +0,0 @@
-#!/usr/bin/python3
-
-import unittest
-import sys
-import netifaces
-import os
-
-import iwd
-from iwd import IWD
-import testutil
-from config import ctx
-from wpas import Wpas
-
-class Test(unittest.TestCase):
- def test_1_client_go_neg_responder(self):
- self.p2p_client_test(False)
-
- def test_2_client_go_neg_initiator(self):
- self.p2p_client_test(True)
-
- def p2p_client_test(self, preauthorize):
- wpas = Wpas(p2p=True)
- wd = IWD()
-
- # Not strictly necessary but prevents the station interface from queuing its scans
- # in the wiphy radio work queue and delaying P2P scans.
- wd.list_devices(1)[0].disconnect()
-
- devices = wd.list_p2p_devices(1)
- p2p = devices[0]
- p2p.enabled = True
- p2p.name = 'testdev1'
-
- wpas.p2p_find()
- p2p.discovery_request = True
- wd.wait(5)
- wd.wait_for_object_condition(wpas, 'len(obj.p2p_peers) == 1', max_wait=20)
- p2p.discovery_request = False
- wpas.p2p_listen()
-
- peers = p2p.get_peers()
- self.assertEqual(len(peers), 1)
- peer = next(iter(peers.values()))
- self.assertEqual(peer.name, wpas.config['device_name'])
- self.assertEqual(peer.category, 'display')
- self.assertEqual(peer.subcategory, 'monitor')
-
- wpas_peer = next(iter(wpas.p2p_peers.values()))
- self.assertEqual(wpas_peer['name'], p2p.name)
- self.assertEqual(wpas_peer['pri_dev_type'], '1-0050F204-6') # 1 == Computer, 6 == Desktop
- self.assertEqual(wpas_peer['config_methods'], '0x1080')
-
- if preauthorize:
- wpas.p2p_authorize(wpas_peer)
-
- peer.connect(wait=False)
-
- self.assertEqual(len(wpas.p2p_go_neg_requests), 0)
- self.assertEqual(len(wpas.p2p_clients), 0)
- wd.wait_for_object_condition(wpas, 'len(obj.p2p_go_neg_requests) == 1', max_wait=3)
- request = wpas.p2p_go_neg_requests[wpas_peer['p2p_dev_addr']]
-
- if not preauthorize:
- self.assertEqual(request['dev_passwd_id'], '4')
- self.assertEqual(request['go_intent'], '2') # Hardcoded in src/p2p.c
-
- wpas.p2p_accept_go_neg_request(request)
-
- wd.wait_for_object_condition(request, '\'success\' in obj', max_wait=3)
- self.assertEqual(request['success'], True)
- self.assertEqual(request['role'], 'GO')
- self.assertEqual(request['wps_method'], 'PBC')
- self.assertEqual(request['p2p_dev_addr'], wpas_peer['p2p_dev_addr'])
-
- wd.wait_for_object_condition(wpas, 'obj.p2p_group is not None', max_wait=3)
- go_ifname = wpas.p2p_group['ifname']
- ctx.start_process(['ifconfig', go_ifname, '192.168.1.20', 'netmask', '255.255.255.0'], wait=True)
- os.system('> /tmp/dhcpd.leases')
- dhcpd = ctx.start_process(['dhcpd', '-f', '-cf', '/tmp/dhcpd.conf', '-lf', '/tmp/dhcpd.leases', go_ifname])
-
- wd.wait_for_object_condition(wpas, 'len(obj.p2p_clients) == 1', max_wait=3)
- client = wpas.p2p_clients[request['peer_iface']]
- self.assertEqual(client['p2p_dev_addr'], wpas_peer['p2p_dev_addr'])
-
- wd.wait_for_object_condition(peer, 'obj.connected', max_wait=15)
- our_ip = netifaces.ifaddresses(peer.connected_interface)[netifaces.AF_INET][0]['addr']
- self.assertEqual(peer.connected_ip, '192.168.1.20')
- self.assertEqual(our_ip, '192.168.1.30')
-
- testutil.test_iface_operstate(peer.connected_interface)
- testutil.test_ifaces_connected(peer.connected_interface, go_ifname)
-
- peer.disconnect()
- wd.wait_for_object_condition(wpas, 'len(obj.p2p_clients) == 0', max_wait=3)
- self.assertEqual(peer.connected, False)
-
- p2p.enabled = False
- ctx.stop_process(dhcpd)
- wpas.clean_up()
-
- @classmethod
- def tearDownClass(cls):
- IWD.clear_storage()
-
-if __name__ == '__main__':
- unittest.main(exit=True)
diff --git a/autotests/testP2P/connection_test.py b/autotests/testP2P/connection_test.py
@@ -0,0 +1,139 @@
+#!/usr/bin/python3
+
+import unittest
+import sys
+import netifaces
+import os
+import time
+
+import iwd
+from iwd import IWD
+import testutil
+from config import ctx
+from wpas import Wpas
+
+class Test(unittest.TestCase):
+ def test_1_client_go_neg_responder(self):
+ self.p2p_connect_test(preauthorize=False, go=False)
+
+ def test_2_client_go_neg_initiator(self):
+ self.p2p_connect_test(preauthorize=True, go=False)
+
+ def test_3_go_go_neg_responder(self):
+ self.p2p_connect_test(preauthorize=False, go=True)
+
+ def test_4_go_go_neg_initiator(self):
+ self.p2p_connect_test(preauthorize=True, go=True)
+
+ def p2p_connect_test(self, preauthorize, go):
+ wd = IWD()
+ wpas = Wpas(p2p=True)
+ wpas_go_intent = 10 if not go else 1
+
+ # Not strictly necessary but prevents the station interface from queuing its scans
+ # in the wiphy radio work queue and delaying P2P scans.
+ wd.list_devices(1)[0].disconnect()
+
+ devices = wd.list_p2p_devices(1)
+ p2p = devices[0]
+ p2p.enabled = True
+ p2p.name = 'testdev1'
+
+ wpas.p2p_find()
+ p2p.discovery_request = True
+ wd.wait(5)
+ wd.wait_for_object_condition(wpas, 'len(obj.p2p_peers) == 1', max_wait=20)
+ p2p.discovery_request = False
+ wpas.p2p_listen()
+
+ peers = p2p.get_peers()
+ self.assertEqual(len(peers), 1)
+ peer = next(iter(peers.values()))
+ self.assertEqual(peer.name, wpas.config['device_name'])
+ self.assertEqual(peer.category, 'display')
+ self.assertEqual(peer.subcategory, 'monitor')
+
+ wpas_peer = next(iter(wpas.p2p_peers.values()))
+ self.assertEqual(wpas_peer['name'], p2p.name)
+ self.assertEqual(wpas_peer['pri_dev_type'], '1-0050F204-6') # 1 == Computer, 6 == Desktop
+ self.assertEqual(wpas_peer['config_methods'], '0x1080')
+
+ if preauthorize:
+ wpas.p2p_authorize(wpas_peer, go_intent=wpas_go_intent)
+
+ peer.connect(wait=False)
+
+ self.assertEqual(len(wpas.p2p_go_neg_requests), 0)
+ self.assertEqual(len(wpas.p2p_clients), 0)
+ wd.wait_for_object_condition(wpas, 'len(obj.p2p_go_neg_requests) == 1', max_wait=3)
+ request = wpas.p2p_go_neg_requests[wpas_peer['p2p_dev_addr']]
+
+ if not preauthorize:
+ self.assertEqual(request['dev_passwd_id'], '4')
+ self.assertEqual(request['go_intent'], '2') # Hardcoded in src/p2p.c
+
+ wpas.p2p_accept_go_neg_request(request, go_intent=wpas_go_intent)
+
+ wd.wait_for_object_condition(request, '\'success\' in obj', max_wait=3)
+ self.assertEqual(request['success'], True)
+ self.assertEqual(request['role'], 'GO' if not go else 'client')
+ self.assertEqual(request['wps_method'], 'PBC')
+ self.assertEqual(request['p2p_dev_addr'], wpas_peer['p2p_dev_addr'])
+
+ if go:
+ # For some reason wpa_supplicant's newly created P2P-client interface doesn't inherit
+ # the settings from the main interface which were loaded from the config file
+ # (P2P-device and P2P-GO interfaces do), we need to set config_methods again.
+ peer_ifname = 'p2p-' + wpas.interface.name + '-0'
+ wpas.set('config_methods', wpas.config['config_methods'], ifname=peer_ifname)
+ wpas.set('device_name', wpas.config['device_name'], ifname=peer_ifname)
+ wpas.set('device_type', wpas.config['device_type'], ifname=peer_ifname)
+
+ wd.wait_for_object_condition(wpas, 'obj.p2p_group is not None', max_wait=3)
+ peer_ifname = wpas.p2p_group['ifname']
+
+ if not go:
+ ctx.start_process(['ifconfig', peer_ifname, '192.168.1.20', 'netmask', '255.255.255.0'], wait=True)
+ os.system('> /tmp/dhcpd.leases')
+ dhcp = ctx.start_process(['dhcpd', '-f', '-cf', '/tmp/dhcpd.conf', '-lf', '/tmp/dhcpd.leases', peer_ifname])
+
+ wd.wait_for_object_condition(wpas, 'len(obj.p2p_clients) == 1', max_wait=3)
+ client = wpas.p2p_clients[request['peer_iface']]
+ self.assertEqual(client['p2p_dev_addr'], wpas_peer['p2p_dev_addr'])
+ else:
+ dhcp = ctx.start_process(['dhclient', '-v', '-d', '--no-pid', '-cf', '/dev/null', '-lf', '/tmp/dhcpd.leases',
+ '-sf', '/tmp/dhclient-script', peer_ifname])
+
+ wd.wait_for_object_condition(peer, 'obj.connected', max_wait=15)
+ time.sleep(1) # Give the client time to set the IP
+ our_ip = netifaces.ifaddresses(peer.connected_interface)[netifaces.AF_INET][0]['addr']
+ peer_ip = netifaces.ifaddresses(peer_ifname)[netifaces.AF_INET][0]['addr']
+ self.assertEqual(peer.connected_ip, peer_ip)
+
+ if not go:
+ self.assertEqual(our_ip, '192.168.1.30')
+ self.assertEqual(peer_ip, '192.168.1.20')
+ else:
+ self.assertEqual(our_ip, '192.168.1.1')
+ self.assertEqual(peer_ip, '192.168.1.2')
+
+ testutil.test_iface_operstate(peer.connected_interface)
+ testutil.test_ifaces_connected(peer.connected_interface, peer_ifname)
+
+ peer.disconnect()
+ if not go:
+ wd.wait_for_object_condition(wpas, 'len(obj.p2p_clients) == 0', max_wait=3)
+ else:
+ wd.wait_for_object_condition(wpas, 'obj.p2p_group is None', max_wait=3)
+ self.assertEqual(peer.connected, False)
+
+ p2p.enabled = False
+ ctx.stop_process(dhcp)
+ wpas.clean_up()
+
+ @classmethod
+ def tearDownClass(cls):
+ IWD.clear_storage()
+
+if __name__ == '__main__':
+ unittest.main(exit=True)
diff --git a/autotests/testP2P/dhclient-script b/autotests/testP2P/dhclient-script
@@ -0,0 +1,17 @@
+#! /bin/bash
+case $reason in
+BOUND|RENEW|REBIND|REBOOT)
+ if [ x$new_ip_address != x ] && \
+ [ x$new_ip_address != x$old_ip_address -o \
+ x$reason = xBOUND -o x$reason = xREBOOT ]; then
+ /sbin/ip addr add $new_ip_address/${new_subnet_mask:-32} \
+ ${new_broadcast_arg} \
+ dev $interface
+ fi
+;;
+EXPIRE|FAIL|RELEASE|STOP)
+ if [ x$old_ip_address != x ]; then
+ /sbin/ip -4 addr flush dev $interface
+ fi
+;;
+esac
diff --git a/autotests/testP2P/main.conf b/autotests/testP2P/main.conf
@@ -4,3 +4,6 @@ EnableNetworkConfiguration=true
[P2P]
# Something different from the default of 'pc' for validation
DeviceType=desktop
+
+[IPv4]
+APAddressPool=192.168.1.0/28
diff --git a/autotests/testPreauth-roam/connection_test.py b/autotests/testPreauth-roam/connection_test.py
@@ -46,9 +46,9 @@ class Test(unittest.TestCase):
# Check that iwd selects BSS 0 first
rule0.signal = -2500
- rule1.signal = -3500
+ rule1.signal = -6900
- wd = IWD()
+ wd = IWD(True)
device = wd.list_devices(1)[0]
diff --git a/autotests/testPreauth-roam/hw.conf b/autotests/testPreauth-roam/hw.conf
@@ -1,5 +1,6 @@
[SETUP]
num_radios=3
+start_iwd=0
[HOSTAPD]
rad0=eaptls-preauth-1.conf
diff --git a/autotests/util/iwd.py b/autotests/util/iwd.py
@@ -826,7 +826,7 @@ class P2PDevice(IWDDBusAbstract):
self._peer_dict = {}
for path, rssi in self._iface.GetPeers():
- self._peer_dict[path] = old_dict[path] if path in old_dict else P2PPeer(path)
+ self._peer_dict[path] = old_dict[path] if path in old_dict else P2PPeer(path, namespace=self._namespace)
self._peer_dict[path].rssi = rssi
return self._peer_dict
diff --git a/autotests/util/wpas.py b/autotests/util/wpas.py
@@ -8,13 +8,11 @@ ctrl_count = 0
class Wpas:
def _start_wpas(self, config_name=None, p2p=False):
- global ctrl_count
-
main_interface = None
for interface in ctx.wpas_interfaces:
if config_name is None or interface.config == config_name:
if main_interface is not None:
- raise Exception('More than was wpa_supplicant interface matches given config')
+ raise Exception('More than one wpa_supplicant interface matches given config')
main_interface = interface
if main_interface is None:
@@ -37,15 +35,9 @@ class Wpas:
self.wpa_supplicant = ctx.start_process(cmd)
- self.local_ctrl = '/tmp/wpas_' + str(os.getpid()) + '_' + str(ctrl_count)
- ctrl_count = ctrl_count + 1
- self.ctrl_sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
- self.ctrl_sock.bind(self.local_ctrl)
-
- self.remote_ctrl = self.socket_path + '/' + self.ifname
- self.wpa_supplicant.wait_for_socket(self.remote_ctrl, 2)
- self.ctrl_sock.connect(self.remote_ctrl)
- self.io_watch = GLib.io_add_watch(self.ctrl_sock, GLib.IO_IN, self._handle_data_in)
+ self.sockets = {}
+ self.cleanup_paths = []
+ self.io_watch = GLib.io_add_watch(self._get_socket(), GLib.IO_IN, self._handle_data_in)
self.p2p_peers = {}
self.p2p_go_neg_requests = {}
@@ -173,11 +165,34 @@ class Wpas:
return True
- def _ctrl_request(self, command, timeout=10):
+ def _ctrl_request(self, command, ifname=None):
if type(command) is str:
command = str.encode(command)
- self.ctrl_sock.send(bytes(command))
+ self._get_socket(ifname).send(bytes(command))
+
+ def _get_socket(self, ifname=None):
+ global ctrl_count
+
+ if ifname is None:
+ ifname = self.ifname
+
+ if ifname in self.sockets:
+ return self.sockets[ifname]
+
+ local_path = '/tmp/wpas_' + str(os.getpid()) + '_' + str(ctrl_count)
+ ctrl_count = ctrl_count + 1
+ remote_path = self.socket_path + '/' + ifname
+
+ self.wpa_supplicant.wait_for_socket(remote_path, 2)
+ sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
+ sock.bind(local_path)
+ self.cleanup_paths.append(local_path)
+ sock.connect(remote_path)
+ self.cleanup_paths.append(remote_path)
+
+ self.sockets[ifname] = sock
+ return sock
# Normal find phase with listen and active scan states
def p2p_find(self):
@@ -203,22 +218,28 @@ class Wpas:
def p2p_connect(self, peer, pin=None, go_intent=None):
self._rx_data = []
self._ctrl_request('P2P_CONNECT ' + peer['p2p_dev_addr'] + ' ' + ('pbc' if pin is None else pin) +
- ('' if go_intent is None else 'go_intent=' + str(go_intent)))
+ ('' if go_intent is None else ' go_intent=' + str(go_intent)))
self.wait_for_event('OK')
def p2p_accept_go_neg_request(self, request, pin=None, go_intent=None):
self._rx_data = []
self._ctrl_request('P2P_CONNECT ' + request['p2p_dev_addr'] + ' ' + ('pbc' if pin is None else pin) +
- ('' if go_intent is None else 'go_intent=' + str(go_intent)))
+ ('' if go_intent is None else ' go_intent=' + str(go_intent)))
self.wait_for_event('OK')
# Pre-accept the next GO Negotiation Request from this peer to avoid the extra Respone + Request frames
def p2p_authorize(self, peer, pin=None, go_intent=None):
self._rx_data = []
self._ctrl_request('P2P_CONNECT ' + peer['p2p_dev_addr'] + ' ' + ('pbc' if pin is None else pin) +
- ('' if go_intent is None else 'go_intent=' + str(go_intent)) + ' auth')
+ ('' if go_intent is None else ' go_intent=' + str(go_intent)) + ' auth')
self.wait_for_event('OK')
+ def p2p_set(self, key, value, **kwargs):
+ self._ctrl_request('P2P_SET ' + key + ' ' + value, **kwargs)
+
+ def set(self, key, value, **kwargs):
+ self._ctrl_request('SET ' + key + ' ' + value, **kwargs)
+
# Probably needed: remove references to self so that the GC can call __del__ automatically
def clean_up(self):
if self.io_watch is not None:
@@ -227,16 +248,16 @@ class Wpas:
if self.wpa_supplicant is not None:
ctx.stop_process(self.wpa_supplicant)
self.wpa_supplicant = None
+ for path in self.cleanup_paths:
+ if os.path.exists(path):
+ os.remove(path)
+ self.cleanup_paths = []
def _stop_wpas(self):
self.clean_up()
- if self.ctrl_sock:
- self.ctrl_sock.close()
- self.ctrl_sock = None
- if os.path.exists(self.remote_ctrl):
- os.remove(self.remote_ctrl)
- if os.path.exists(self.local_ctrl):
- os.remove(self.local_ctrl)
+ for ifname in self.sockets:
+ self.sockets[ifname].close()
+ self.sockets = {}
def __del__(self):
self._stop_wpas()
diff --git a/configure.ac b/configure.ac
@@ -1,5 +1,5 @@
AC_PREREQ(2.60)
-AC_INIT(iwd, 1.14)
+AC_INIT(iwd, 1.15)
AC_CONFIG_HEADERS(config.h)
AC_CONFIG_AUX_DIR(build-aux)
@@ -267,7 +267,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.40"
+ ell_min_version="0.41"
else
ell_min_version="0.5"
fi
diff --git a/doc/agent-api.txt b/doc/agent-api.txt
@@ -29,7 +29,7 @@ Service unique name
Interface net.connman.iwd.Agent
Object path freely definable
-Methods void Release()
+Methods void Release() [noreply]
This method gets called when the service daemon
unregisters the agent. An agent can use it to do
@@ -70,7 +70,7 @@ Methods void Release()
Possible Errors: net.connman.iwd.Agent.Error.Canceled
- void Cancel(string reason)
+ void Cancel(string reason) [noreply]
This method gets called to indicate that the agent
request failed before a reply was returned. The
diff --git a/doc/daemon-api.txt b/doc/daemon-api.txt
@@ -0,0 +1,30 @@
+Daemon hierarchy
+================
+
+Service net.connman.iwd
+Interface net.connman.iwd.Daemon [Experimental]
+Object path /net/connman/iwd
+
+Methods dict GetInfo()
+
+ Returns basic IWD daemon's status and configuration
+ properties. Their values are global and may be useful
+ for D-Bus clients interacting with IWD, not so much
+ for the user. The returned dictionary (a{sv}) maps
+ string keys to values of types defined per key.
+ Clients should ignore unknown keys.
+
+ The following key/value pairs are defined currently:
+
+ string Version - IWD release version,
+
+ string StateDirectory - Absolute path to the IWD
+ state directory where network configuration and
+ runtime state files are kept (see $STATE_DIRECTORY in
+ iwd(8) and iwd.network(5)).
+
+ bool NetworkConfigurationEnabled - Whether network
+ configuration is enabled (see iwd(8)). When true,
+ IWD configures the address, netmask, the resolver,
+ a route, the DHCP client or server (in station vs.
+ access point mode.)
diff --git a/doc/station-api.txt b/doc/station-api.txt
@@ -171,7 +171,7 @@ Service unique name
Interface net.connman.iwd.SignalLevelAgent
Object path freely definable
-Methods void Release(object device)
+Methods void Release(object device) [noreply]
This method gets called when the service daemon
unregisters the agent. An agent can use it to do
@@ -179,7 +179,7 @@ Methods void Release(object device)
agent, because when this method gets called it has
already been unregistered.
- string Changed(object device, uint8 level)
+ void Changed(object device, uint8 level) [noreply]
This method gets called when the signal strength
measurement for the device's connected network
diff --git a/doc/test-runner.txt b/doc/test-runner.txt
@@ -28,6 +28,7 @@ OS:
10. <iwd>/src/iwd 0.0
11. ofono (optional)
12. phonesim (optional)
+ 13. wpa_supplicant 2.9
Note: The version for hostapd is listed as 'recent'. Older hostapd versions
will work but we are continually adopting new features from hostapd and using
diff --git a/monitor/nlmon.c b/monitor/nlmon.c
@@ -1104,8 +1104,68 @@ static void print_ie_vendor(unsigned int level, const char *label,
}
}
-static void print_ie_mcs(unsigned int level, const char *label,
- const void *data, uint16_t size)
+static void print_ht_capabilities(unsigned int level, const char *label,
+ const void *data, uint16_t size)
+{
+ static const char *ht_capabilities_info_bitfield[16] = {
+ [0] = "LDPC Coding Capability",
+ [1] = "Supported Channel Width Set",
+ [2] = "SM Power Save",
+ [3] = "SM Power Save",
+ [4] = "HT-Greenfield",
+ [5] = "Short GI for 20Mhz",
+ [6] = "Short GI for 40Mhz",
+ [7] = "Tx STBC",
+ [8] = "Rx STBC",
+ [9] = "Rx STBC",
+ [10] = "HT-Delayed Block Ack",
+ [11] = "Maximum A-MSDU Length",
+ [12] = "DSSS/CCK Mode in 40Mhz",
+ [13] = "Reserved",
+ [14] = "40 Mhz Intolerant",
+ [15] = "L-SIG TXOP Protection Support",
+ };
+ static const char *ht_capabilities_sm_power_save[4] = {
+ "Static", "Dynamic", "Reserved", "Disabled",
+ };
+ static const char *ht_capabilities_rx_stbc[4] = {
+ "Disabled", "One spatial stream", "One and two spatial streams",
+ "One, two and three spatial streams"
+ };
+ uint8_t info_mask[] = { 0x03, 0xfc };
+ const uint8_t *htc = data;
+ uint8_t sm_power_save;
+ uint8_t rx_stbc;
+
+ if (size != 2)
+ return print_ie_error(level, label, size, -EINVAL);
+
+ /* Print bits 0-1 */
+ print_ie_bitfield(level, "HT Capabilities Info", data, info_mask,
+ 1, ht_capabilities_info_bitfield);
+
+ /* Print SM Power Save */
+ sm_power_save = bit_field(htc[0], 2, 2);
+ print_attr(level, "HT Capabilities Info: bits 2-3: %s",
+ ht_capabilities_sm_power_save[sm_power_save]);
+
+ /* Print bits 4-7 */
+ info_mask[0] = 0xf0;
+ print_ie_bitfield(level, "HT Capabilities Info", data, info_mask,
+ 1, ht_capabilities_info_bitfield);
+
+ rx_stbc = bit_field(htc[1], 0, 2);
+ print_attr(level, "HT Capabilities Info: bits 8-9: %s",
+ ht_capabilities_rx_stbc[rx_stbc]);
+
+ /* Print bits 10-15 */
+ info_mask[0] = 0x00;
+ print_ie_bitfield(level, "HT Capabilities Info", data, info_mask,
+ 2, ht_capabilities_info_bitfield);
+}
+
+static void print_ht_mcs_set(unsigned int level, const char *label,
+ const void *data, uint16_t size)
{
const uint8_t *bytes = data;
int i;
@@ -1309,7 +1369,60 @@ static void print_ie_ht_operation(unsigned int level, const char *label,
print_ie_bitfield(level + 1, "Information", &bytes[1],
bytemask, sizeof(bytemask), ht_ops_bitfield);
- print_ie_mcs(level + 1, "Basic MCS set", &bytes[6], 16);
+ print_ht_mcs_set(level + 1, "Basic MCS set", &bytes[6], 16);
+}
+
+static void print_spatial_stream_map(unsigned int level, const char *label,
+ const uint8_t *map)
+{
+ static const char *spatial_streams[] = {
+ "0 - MCS 0-7 supported",
+ "1 - MCS 0-8 supported",
+ "2 - MCS 0-9 supported",
+ "3 - No MCS support",
+ };
+
+ print_attr(level + 1, "%s 1 Streams: %s", label,
+ spatial_streams[bit_field(map[0], 0, 2)]);
+ print_attr(level + 1, "%s 2 Streams: %s", label,
+ spatial_streams[bit_field(map[0], 2, 2)]);
+ print_attr(level + 1, "%s 3 Streams: %s", label,
+ spatial_streams[bit_field(map[0], 4, 2)]);
+ print_attr(level + 1, "%s 4 Streams: %s", label,
+ spatial_streams[bit_field(map[0], 6, 2)]);
+ print_attr(level + 1, "%s 5 Streams: %s", label,
+ spatial_streams[bit_field(map[1], 0, 2)]);
+ print_attr(level + 1, "%s 6 Streams: %s", label,
+ spatial_streams[bit_field(map[1], 2, 2)]);
+ print_attr(level + 1, "%s 7 Streams: %s", label,
+ spatial_streams[bit_field(map[1], 4, 2)]);
+ print_attr(level + 1, "%s 8 Streams: %s", label,
+ spatial_streams[bit_field(map[1], 6, 2)]);
+}
+
+static void print_ie_vht_operation(unsigned int level, const char *label,
+ const void *data, uint16_t size)
+{
+ static const char *channel_width[] = {
+ "0 - 20 or 40 Mhz channel width",
+ "1 - 80 Mhz",
+ "2 - 160 Mhz",
+ "3 - 80+80 Mhz",
+ };
+ uint8_t *bytes = (uint8_t *) data;
+
+ if (size < 5) {
+ print_ie_error(level, label, size, -EINVAL);
+ return;
+ }
+
+ print_attr(level, "%s:", label);
+ print_attr(level + 1, "Channel Width %s", bytes[0] > 3 ? "Reserved" :
+ channel_width[bytes[0]]);
+ print_attr(level + 1, "Channel Center Frequency 1: %d", bytes[1]);
+ print_attr(level + 1, "Channel Center Frequency 2: %d", bytes[2]);
+
+ print_spatial_stream_map(level + 1, "Basic VHT-MCS", bytes + 3);
}
static const char *extended_capabilities_bitfield[80] = {
@@ -1433,31 +1546,6 @@ static void print_ie_ht_capabilities(unsigned int level,
const char *label,
const void *data, uint16_t size)
{
- static const char *ht_capabilities_info_bitfield[16] = {
- [0] = "LDPC Coding Capability",
- [1] = "Supported Channel Width Set",
- [2] = "SM Power Save",
- [3] = "SM Power Save",
- [4] = "HT-Greenfield",
- [5] = "Short GI for 20Mhz",
- [6] = "Short GI for 40Mhz",
- [7] = "Tx STBC",
- [8] = "Rx STBC",
- [9] = "Rx STBC",
- [10] = "HT-Delayed Block Ack",
- [11] = "Maximum A-MSDU Length",
- [12] = "DSSS/CCK Mode in 40Mhz",
- [13] = "Reserved",
- [14] = "40 Mhz Intolerant",
- [15] = "L-SIG TXOP Protection Support",
- };
- static const char *ht_capabilities_sm_power_save[4] = {
- "Static", "Dynamic", "Reserved", "Disabled",
- };
- static const char *ht_capabilities_rx_stbc[4] = {
- "Disabled", "One spatial stream", "One and two spatial streams",
- "One, two and three spatial streams"
- };
static const char *ht_capabilities_min_mpdu_start_spacing[8] = {
"No restriction", "1/4 us", "1/2 us", "1 us", "2 us",
"4 us", "8 us", "16 us",
@@ -1468,10 +1556,7 @@ static void print_ie_ht_capabilities(unsigned int level,
static const char *ht_capabilities_mcs_feedback[4] = {
"No feedback", "Reserved", "Unsolicited", "Both",
};
- uint8_t info_mask[] = { 0x03, 0xfc };
const uint8_t *htc = data;
- uint8_t sm_power_save;
- uint8_t rx_stbc;
uint8_t ampdu_exponent;
bool pco;
bool plus_htc;
@@ -1483,28 +1568,7 @@ static void print_ie_ht_capabilities(unsigned int level,
if (size != 26)
return;
- /* Print bits 0-1 */
- print_ie_bitfield(level + 1, "HT Capabilities Info", data, info_mask,
- 1, ht_capabilities_info_bitfield);
-
- /* Print SM Power Save */
- sm_power_save = bit_field(htc[0], 2, 2);
- print_attr(level + 1, "HT Capabilities Info: bits 2-3: %s",
- ht_capabilities_sm_power_save[sm_power_save]);
-
- /* Print bits 4-7 */
- info_mask[0] = 0xf0;
- print_ie_bitfield(level + 1, "HT Capabilities Info", data, info_mask,
- 1, ht_capabilities_info_bitfield);
-
- rx_stbc = bit_field(htc[1], 0, 2);
- print_attr(level + 1, "HT Capabilities Info: bits 8-9: %s",
- ht_capabilities_rx_stbc[rx_stbc]);
-
- /* Print bits 10-15 */
- info_mask[0] = 0x00;
- print_ie_bitfield(level + 1, "HT Capabilities Info", data, info_mask,
- 2, ht_capabilities_info_bitfield);
+ print_ht_capabilities(level + 1, "HT Capabilities Info", htc, 2);
ampdu_exponent = bit_field(htc[2], 0, 2);
print_attr(level + 1, "A-MPDU Parameters: "
@@ -1515,7 +1579,7 @@ static void print_ie_ht_capabilities(unsigned int level,
"Minimum MPDU Start Spacing: %s",
ht_capabilities_min_mpdu_start_spacing[bits]);
- print_ie_mcs(level + 1, "Supported MCS", htc + 3, 16);
+ print_ht_mcs_set(level + 1, "Supported MCS", htc + 3, 16);
pco = test_bit(htc + 18, 0);
print_attr(level + 1, "HT Extended Capabilities: PCO: %s",
@@ -1545,6 +1609,52 @@ static void print_ie_ht_capabilities(unsigned int level,
/* TODO: ASEL Capability field */
}
+static void print_ie_vht_capabilities(unsigned int level,
+ const char *label,
+ const void *data, uint16_t size)
+{
+ static const char *vht_capabilities_info_bitfield[] = {
+ [0 ... 1] = "Maximum MPDU Length",
+ [2 ... 3] = "Supported Channel Width Set",
+ [4] = "RX LDPC",
+ [5] = "Short GI for 80 Mhz",
+ [6] = "Short GI for 160 and 80+80 Mhz",
+ [7] = "Tx STBC",
+ [8 ... 10] = "Rx STBC",
+ [11] = "SU Beamformer Capable",
+ [12] = "SU Beamformee Capable",
+ [13 ... 15] = "Beamformee STS Capability",
+ [16 ... 18] = "Number of Sounding Dimensions",
+ [19] = "MU Beamformer Capable",
+ [20] = "MU Beamformee Capable",
+ [21] = "TXOP PS",
+ [22] = "+HTC-VHT Capable",
+ [23 ... 25] = "Maximum A-MPDU Length Exponent",
+ [26 ... 27] = "VHT Link Adapation Capable",
+ [28] = "RX Antenna Pattern Consistency",
+ [29] = "TX Antenna Pattern Consistency",
+ [30 ... 31] = "Extended NSS BW Support",
+ };
+ uint8_t info_mask[] = { 0xf0, 0x18, 0x78, 0x30 };
+
+ print_attr(level, "%s: len %u", label, size);
+
+ if (size != 12)
+ return;
+
+ print_ie_bitfield(level + 1, "VHT Capabilities Info", data, info_mask,
+ 4, vht_capabilities_info_bitfield);
+
+ print_spatial_stream_map(level + 1, "RxVHT-MCS", data + 4);
+ print_attr(level + 1, "Rx Highest Supported Long GI Data Rate: %d",
+ l_get_le16(data + 6) & 0x1f);
+ print_spatial_stream_map(level + 1, "TxVHT-MCS", data + 8);
+ print_attr(level + 1, "Tx Highest Supported Long GI Data Rate: %d",
+ l_get_le16(data + 10) & 0x1f);
+ if (test_bit(data + 4, 61))
+ print_attr(level + 1, "VHT Extended NSS BW Capable");
+}
+
static void print_ie_rm_enabled_caps(unsigned int level,
const char *label,
const void *data, uint16_t size)
@@ -2072,12 +2182,16 @@ static struct attr_entry ie_entry[] = {
ATTR_CUSTOM, { .function = print_ie_rate } },
{ IE_TYPE_HT_OPERATION, "HT Operation",
ATTR_CUSTOM, { .function = print_ie_ht_operation } },
+ { IE_TYPE_VHT_OPERATION, "VHT Operation",
+ ATTR_CUSTOM, { .function = print_ie_vht_operation } },
{ IE_TYPE_VENDOR_SPECIFIC, "Vendor specific",
ATTR_CUSTOM, { .function = print_ie_vendor } },
{ IE_TYPE_EXTENDED_CAPABILITIES, "Extended Capabilities",
ATTR_CUSTOM, { .function = print_ie_extended_capabilities } },
{ IE_TYPE_HT_CAPABILITIES, "HT Capabilities",
ATTR_CUSTOM, { .function = print_ie_ht_capabilities } },
+ { IE_TYPE_VHT_CAPABILITIES, "VHT Capabilities",
+ ATTR_CUSTOM, { .function = print_ie_vht_capabilities } },
{ IE_TYPE_RM_ENABLED_CAPABILITIES, "RM Enabled Capabilities",
ATTR_CUSTOM, { .function = print_ie_rm_enabled_caps } },
{ IE_TYPE_INTERWORKING, "Interworking",
@@ -4834,6 +4948,8 @@ static const struct attr_entry sta_info_table[] = {
"Per-chain signal strength" },
{ NL80211_STA_INFO_CHAIN_SIGNAL_AVG,
"Per-chain signal strength average" },
+ { NL80211_STA_INFO_EXPECTED_THROUGHPUT,
+ "Expected Throughput", ATTR_U32 },
{ }
};
@@ -5118,8 +5234,10 @@ static const struct attr_entry wiphy_bands_table[] = {
ATTR_CUSTOM, { .function = print_band_frequencies } },
{ NL80211_BAND_ATTR_RATES, "Rates",
ATTR_CUSTOM, { .function = print_band_rates } },
- { NL80211_BAND_ATTR_HT_MCS_SET, "HT MCS Set" },
- { NL80211_BAND_ATTR_HT_CAPA, "HT Capabilities" },
+ { NL80211_BAND_ATTR_HT_MCS_SET, "HT MCS Set",
+ ATTR_CUSTOM, { .function = print_ht_mcs_set } },
+ { NL80211_BAND_ATTR_HT_CAPA, "HT Capabilities",
+ ATTR_CUSTOM, { .function = print_ht_capabilities } },
{ NL80211_BAND_ATTR_HT_AMPDU_FACTOR, "AMPDU Factor" },
{ NL80211_BAND_ATTR_HT_AMPDU_DENSITY, "AMPDU Density" },
{ NL80211_BAND_ATTR_VHT_MCS_SET, "VHT MCS Set" },
diff --git a/src/agent.c b/src/agent.c
@@ -75,24 +75,6 @@ static unsigned int agent_timeout_input_request(void)
return 120;
}
-static void send_request(struct agent *agent, const char *request)
-{
- struct l_dbus_message *message;
-
- l_debug("send %s request to %s %s", request, agent->owner,
- agent->path);
-
- message = l_dbus_message_new_method_call(dbus_get_bus(),
- agent->owner,
- agent->path,
- IWD_AGENT_INTERFACE,
- request);
-
- l_dbus_message_set_arguments(message, "");
-
- l_dbus_send(dbus_get_bus(), message);
-}
-
static void send_cancel_request(void *user_data, int reason)
{
struct agent *agent = user_data;
@@ -126,6 +108,7 @@ static void send_cancel_request(void *user_data, int reason)
"Cancel");
l_dbus_message_set_arguments(message, "s", reasonstr);
+ l_dbus_message_set_no_reply(message, true);
l_dbus_send(dbus_get_bus(), message);
}
@@ -656,9 +639,20 @@ static void setup_agent_interface(struct l_dbus_interface *interface)
static bool release_agent(void *data, void *user_data)
{
struct agent *agent = data;
-
#ifdef HAVE_DBUS
- send_request(agent, "Release");
+ struct l_dbus_message *message;
+
+ l_debug("send Release to %s %s", agent->owner, agent->path);
+
+ message = l_dbus_message_new_method_call(dbus_get_bus(),
+ agent->owner,
+ agent->path,
+ IWD_AGENT_INTERFACE,
+ "Release");
+
+ l_dbus_message_set_arguments(message, "");
+ l_dbus_message_set_no_reply(message, true);
+ l_dbus_send(dbus_get_bus(), message);
#endif
agent_free(agent);
diff --git a/src/ap.c b/src/ap.c
@@ -52,6 +52,7 @@
#include "src/frame-xchg.h"
#include "src/wscutil.h"
#include "src/eap-wsc.h"
+#include "src/ip-pool.h"
#include "src/ap.h"
#include "src/storage.h"
#include "src/diagnostic.h"
@@ -88,15 +89,13 @@ struct ap_state {
uint16_t last_aid;
struct l_queue *sta_states;
- struct l_dhcp_server *server;
+ struct l_dhcp_server *netconfig_dhcp;
+ struct l_rtnl_address *netconfig_addr4;
uint32_t rtnl_add_cmd;
- char *own_ip;
- unsigned int ip_prefix;
bool started : 1;
bool gtk_set : 1;
- bool cleanup_ip : 1;
- bool use_ip_pool : 1;
+ bool netconfig_set_addr4 : 1;
};
struct sta_state {
@@ -127,115 +126,10 @@ struct ap_wsc_pbc_probe_record {
uint64_t timestamp;
};
-struct ap_ip_pool {
- uint32_t start;
- uint32_t end;
- uint8_t prefix;
-
- /* Fist/last valid subnet */
- uint8_t sub_start;
- uint8_t sub_end;
-
- struct l_uintset *used;
-};
-
-struct ap_ip_pool pool;
+static bool netconfig_enabled;
+static char **global_addr4_strs;
static uint32_t netdev_watch;
-struct l_netlink *rtnl;
-
-/*
- * Creates pool of IPs which AP intefaces can use. Each call to ip_pool_get
- * will advance the subnet +1 so there are no IP conflicts between AP
- * interfaces
- */
-static bool ip_pool_create(const char *ip_prefix)
-{
- if (!util_ip_prefix_tohl(ip_prefix, &pool.prefix, &pool.start,
- &pool.end, NULL))
- return false;
-
- if (pool.prefix > 24) {
- l_error("APRanges prefix must 24 or less (%u used)",
- pool.prefix);
- memset(&pool, 0, sizeof(pool));
- return false;
- }
-
- /*
- * Find the number of subnets we can use, this will dictate the number
- * of AP interfaces that can be created (when using DHCP)
- */
- pool.sub_start = (pool.start & 0x0000ff00) >> 8;
- pool.sub_end = (pool.end & 0x0000ff00) >> 8;
-
- pool.used = l_uintset_new_from_range(pool.sub_start, pool.sub_end);
-
- return true;
-}
-
-static char *ip_pool_get()
-{
- uint32_t ip;
- struct in_addr ia;
- uint8_t next_subnet = (uint8_t)l_uintset_find_unused_min(pool.used);
-
- /* This shouldn't happen */
- if (next_subnet < pool.sub_start || next_subnet > pool.sub_end)
- return NULL;
-
- l_uintset_put(pool.used, next_subnet);
-
- ip = pool.start;
- ip &= 0xffff00ff;
- ip |= (next_subnet << 8);
-
- ia.s_addr = htonl(ip);
- return l_strdup(inet_ntoa(ia));
-}
-
-static bool ip_pool_put(const char *address)
-{
- struct in_addr ia;
- uint32_t ip;
- uint8_t subnet;
-
- if (inet_aton(address, &ia) < 0)
- return false;
-
- ip = ntohl(ia.s_addr);
-
- subnet = (ip & 0x0000ff00) >> 8;
-
- if (subnet < pool.sub_start || subnet > pool.sub_end)
- return false;
-
- return l_uintset_take(pool.used, subnet);
-}
-
-static void ip_pool_destroy()
-{
- if (pool.used)
- l_uintset_free(pool.used);
-
- memset(&pool, 0, sizeof(pool));
-}
-
-static const char *broadcast_from_ip(const char *ip)
-{
- struct in_addr ia;
- uint32_t bcast;
-
- if (inet_aton(ip, &ia) != 1)
- return NULL;
-
- bcast = ntohl(ia.s_addr);
- bcast &= 0xffffff00;
- bcast |= 0x000000ff;
-
- ia.s_addr = htonl(bcast);
-
- return inet_ntoa(ia);
-}
+static struct l_netlink *rtnl;
static void ap_stop_handshake(struct sta_state *sta)
{
@@ -317,26 +211,23 @@ static void ap_reset(struct ap_state *ap)
l_uintset_free(ap->rates);
l_queue_destroy(ap->wsc_pbc_probes, l_free);
+ l_timeout_remove(ap->wsc_pbc_timeout);
ap->started = false;
/* Delete IP if one was set by IWD */
- if (ap->cleanup_ip)
- l_rtnl_ifaddr4_delete(rtnl, netdev_get_ifindex(netdev),
- ap->ip_prefix, ap->own_ip,
- broadcast_from_ip(ap->own_ip),
- NULL, NULL, NULL);
+ if (ap->netconfig_set_addr4) {
+ l_rtnl_ifaddr_delete(rtnl, netdev_get_ifindex(netdev),
+ ap->netconfig_addr4, NULL, NULL, NULL);
+ ap->netconfig_set_addr4 = false;
+ }
- if (ap->own_ip) {
- /* Release IP from pool if used */
- if (ap->use_ip_pool)
- ip_pool_put(ap->own_ip);
+ l_rtnl_address_free(l_steal_ptr(ap->netconfig_addr4));
- l_free(ap->own_ip);
+ if (ap->netconfig_dhcp) {
+ l_dhcp_server_destroy(ap->netconfig_dhcp);
+ ap->netconfig_dhcp = NULL;
}
-
- if (ap->server)
- l_dhcp_server_stop(ap->server);
}
static void ap_del_station(struct sta_state *sta, uint16_t reason,
@@ -2142,15 +2033,39 @@ static void do_debug(const char *str, void *user_data)
l_info("%s%s", prefix, str);
}
-static void ap_start_failed(struct ap_state *ap)
+static void ap_start_failed(struct ap_state *ap, int err)
{
- ap->ops->handle_event(AP_EVENT_START_FAILED, NULL, ap->user_data);
+ struct ap_event_start_failed_data data = { err };
+
+ ap->ops->handle_event(AP_EVENT_START_FAILED, &data, ap->user_data);
ap_reset(ap);
l_genl_family_free(ap->nl80211);
l_free(ap);
}
+static void ap_dhcp_event_cb(struct l_dhcp_server *server,
+ enum l_dhcp_server_event event, void *user_data,
+ const struct l_dhcp_lease *lease)
+{
+ struct ap_state *ap = user_data;
+
+ switch (event) {
+ case L_DHCP_SERVER_EVENT_NEW_LEASE:
+ ap->ops->handle_event(AP_EVENT_DHCP_NEW_LEASE, lease,
+ ap->user_data);
+ break;
+
+ case L_DHCP_SERVER_EVENT_LEASE_EXPIRED:
+ ap->ops->handle_event(AP_EVENT_DHCP_LEASE_EXPIRED, lease,
+ ap->user_data);
+ break;
+
+ default:
+ break;
+ }
+}
+
static void ap_start_cb(struct l_genl_msg *msg, void *user_data)
{
struct ap_state *ap = user_data;
@@ -2159,22 +2074,28 @@ static void ap_start_cb(struct l_genl_msg *msg, void *user_data)
if (l_genl_msg_get_error(msg) < 0) {
l_error("START_AP failed: %i", l_genl_msg_get_error(msg));
-
- goto failed;
+ ap_start_failed(ap, l_genl_msg_get_error(msg));
+ return;
}
- if (ap->server && !l_dhcp_server_start(ap->server)) {
- l_error("DHCP server failed to start");
- goto failed;
+ if (ap->netconfig_dhcp) {
+ if (!l_dhcp_server_start(ap->netconfig_dhcp)) {
+ l_error("DHCP server failed to start");
+ ap_start_failed(ap, -EINVAL);
+ return;
+ }
+
+ if (!l_dhcp_server_set_event_handler(ap->netconfig_dhcp,
+ ap_dhcp_event_cb,
+ ap, NULL)) {
+ l_error("l_dhcp_server_set_event_handler failed");
+ ap_start_failed(ap, -EIO);
+ return;
+ }
}
ap->started = true;
ap->ops->handle_event(AP_EVENT_STARTED, NULL, ap->user_data);
-
- return;
-
-failed:
- ap_start_failed(ap);
}
static struct l_genl_msg *ap_build_cmd_start_ap(struct ap_state *ap)
@@ -2260,34 +2181,41 @@ static struct l_genl_msg *ap_build_cmd_start_ap(struct ap_state *ap)
return cmd;
}
-static void ap_ifaddr4_added_cb(int error, uint16_t type, const void *data,
- uint32_t len, void *user_data)
+static bool ap_start_send(struct ap_state *ap)
{
- struct ap_state *ap = user_data;
- struct l_genl_msg *cmd;
-
- ap->rtnl_add_cmd = 0;
+ struct l_genl_msg *cmd = ap_build_cmd_start_ap(ap);
- if (error) {
- l_error("Failed to set IP address");
- goto error;
+ if (!cmd) {
+ l_error("ap_build_cmd_start_ap failed");
+ return false;
}
- cmd = ap_build_cmd_start_ap(ap);
- if (!cmd)
- goto error;
-
ap->start_stop_cmd_id = l_genl_family_send(ap->nl80211, cmd,
ap_start_cb, ap, NULL);
if (!ap->start_stop_cmd_id) {
+ l_error("AP_START l_genl_family_send failed");
l_genl_msg_unref(cmd);
- goto error;
+ return false;
}
- return;
+ return true;
+}
-error:
- ap_start_failed(ap);
+static void ap_ifaddr4_added_cb(int error, uint16_t type, const void *data,
+ uint32_t len, void *user_data)
+{
+ struct ap_state *ap = user_data;
+
+ ap->rtnl_add_cmd = 0;
+
+ if (error) {
+ l_error("Failed to set IP address");
+ ap_start_failed(ap, error);
+ return;
+ }
+
+ if (!ap_start_send(ap))
+ ap_start_failed(ap, -EIO);
}
static bool ap_parse_new_station_ies(const void *data, uint16_t len,
@@ -2459,10 +2387,12 @@ static void ap_mlme_notify(struct l_genl_msg *msg, void *user_data)
switch (l_genl_msg_get_command(msg)) {
case NL80211_CMD_STOP_AP:
if (ap->start_stop_cmd_id) {
+ struct ap_event_start_failed_data data = { -ECANCELED };
+
l_genl_family_cancel(ap->nl80211,
ap->start_stop_cmd_id);
ap->start_stop_cmd_id = 0;
- ap->ops->handle_event(AP_EVENT_START_FAILED, NULL,
+ ap->ops->handle_event(AP_EVENT_START_FAILED, &data,
ap->user_data);
} else if (ap->started) {
ap->started = false;
@@ -2483,182 +2413,271 @@ static void ap_mlme_notify(struct l_genl_msg *msg, void *user_data)
}
}
-static bool dhcp_load_settings(struct ap_state *ap,
- const struct l_settings *settings)
+#define AP_DEFAULT_IPV4_PREFIX_LEN 28
+
+static int ap_setup_netconfig4(struct ap_state *ap, const char **addr_str_list,
+ uint8_t prefix_len, const char *gateway_str,
+ const char **ip_range,
+ const char **dns_str_list,
+ unsigned int lease_time)
{
- struct l_dhcp_server *server = ap->server;
+ uint32_t ifindex = netdev_get_ifindex(ap->netdev);
+ struct l_rtnl_address *existing_addr = ip_pool_get_addr4(ifindex);
+ struct l_rtnl_address *new_addr = NULL;
+ int ret;
struct in_addr ia;
+ struct l_dhcp_server *dhcp = NULL;
+ bool r;
+ char addr_str_buf[INET_ADDRSTRLEN];
+
+ dhcp = l_dhcp_server_new(ifindex);
+ if (!dhcp) {
+ l_error("Failed to create DHCP server on ifindex %u", ifindex);
+ ret = -EIO;
+ goto cleanup;
+ }
- L_AUTO_FREE_VAR(char *, netmask) = l_settings_get_string(settings,
- "IPv4", "Netmask");
- L_AUTO_FREE_VAR(char *, gateway) = l_settings_get_string(settings,
- "IPv4", "Gateway");
- char **dns = l_settings_get_string_list(settings, "IPv4",
- "DNSList", ',');
- char **ip_range = l_settings_get_string_list(settings, "IPv4",
- "IPRange", ',');
- unsigned int lease_time;
- bool ret = false;
+ if (getenv("IWD_DHCP_DEBUG"))
+ l_dhcp_server_set_debug(dhcp, do_debug,
+ "[DHCPv4 SERV] ", NULL);
- if (!l_settings_get_uint(settings, "IPv4", "LeaseTime", &lease_time))
- lease_time = 0;
+ /*
+ * The address pool specified for this AP (if any) has the priority,
+ * next is the address currently set on the interface (if any) and
+ * last is the global AP address pool (APRanges setting).
+ */
+ if (addr_str_list) {
+ if (!prefix_len)
+ prefix_len = AP_DEFAULT_IPV4_PREFIX_LEN;
+
+ ret = ip_pool_select_addr4(addr_str_list, prefix_len,
+ &new_addr);
+ } else if (existing_addr &&
+ l_rtnl_address_get_prefix_length(existing_addr) <
+ 31) {
+ if (!prefix_len)
+ prefix_len = l_rtnl_address_get_prefix_length(
+ existing_addr);
+
+ if (!l_rtnl_address_get_address(existing_addr, addr_str_buf)) {
+ ret = -EIO;
+ goto cleanup;
+ }
- if (gateway && !l_dhcp_server_set_gateway(server, gateway)) {
- l_error("[IPv4].Gateway value error");
- goto error;
+ new_addr = l_rtnl_address_new(addr_str_buf, prefix_len);
+ ret = 0;
+ } else {
+ if (!prefix_len)
+ prefix_len = AP_DEFAULT_IPV4_PREFIX_LEN;
+
+ ret = ip_pool_select_addr4((const char **) global_addr4_strs,
+ prefix_len, &new_addr);
}
- if (dns && !l_dhcp_server_set_dns(server, dns)) {
- l_error("[IPv4].DNSList value error");
- goto error;
+ if (ret)
+ goto cleanup;
+
+ ret = -EIO;
+
+ /*
+ * l_dhcp_server_start() would retrieve the current IPv4 from
+ * the interface but set it anyway in case there are multiple
+ * addresses, saves one ioctl too.
+ */
+ if (!l_rtnl_address_get_address(new_addr, addr_str_buf)) {
+ l_error("l_rtnl_address_get_address failed");
+ goto cleanup;
}
- if (netmask && !l_dhcp_server_set_netmask(server, netmask)) {
- l_error("[IPv4].Netmask value error");
- goto error;
+ if (!l_dhcp_server_set_ip_address(dhcp, addr_str_buf)) {
+ l_error("l_dhcp_server_set_ip_address failed");
+ goto cleanup;
+ }
+
+ ia.s_addr = htonl(util_netmask_from_prefix(prefix_len));
+
+ if (!l_dhcp_server_set_netmask(dhcp, inet_ntoa(ia))) {
+ l_error("l_dhcp_server_set_netmask failed");
+ goto cleanup;
+ }
+
+ if (gateway_str && !l_dhcp_server_set_gateway(dhcp, gateway_str)) {
+ l_error("l_dhcp_server_set_gateway failed");
+ goto cleanup;
}
if (ip_range) {
- if (l_strv_length(ip_range) != 2) {
- l_error("Two addresses expected in [IPv4].IPRange");
- goto error;
+ r = l_dhcp_server_set_ip_range(dhcp, ip_range[0], ip_range[1]);
+ if (!r) {
+ l_error("l_dhcp_server_set_ip_range failed");
+ goto cleanup;
}
+ }
- if (!l_dhcp_server_set_ip_range(server, ip_range[0],
- ip_range[1])) {
- l_error("Error setting IP range from [IPv4].IPRange");
- goto error;
+ if (dns_str_list) {
+ r = l_dhcp_server_set_dns(dhcp, (char **) dns_str_list);
+ if (!r) {
+ l_error("l_dhcp_server_set_dns failed");
+ goto cleanup;
}
}
- if (lease_time && !l_dhcp_server_set_lease_time(server, lease_time)) {
- l_error("[IPv4].LeaseTime value error");
- goto error;
+ if (lease_time && !l_dhcp_server_set_lease_time(dhcp, lease_time)) {
+ l_error("l_dhcp_server_set_lease_time failed");
+ goto cleanup;
}
- if (netmask && inet_pton(AF_INET, netmask, &ia) > 0)
- ap->ip_prefix = __builtin_popcountl(ia.s_addr);
- else
- ap->ip_prefix = 24;
+ ap->netconfig_set_addr4 = true;
+ ap->netconfig_addr4 = l_steal_ptr(new_addr);
+ ap->netconfig_dhcp = l_steal_ptr(dhcp);
+ ret = 0;
- ret = true;
+ if (existing_addr && l_rtnl_address_get_prefix_length(existing_addr) >
+ prefix_len) {
+ char addr_str_buf2[INET_ADDRSTRLEN];
-error:
- l_strv_free(dns);
- l_strv_free(ip_range);
+ if (l_rtnl_address_get_address(existing_addr, addr_str_buf2) &&
+ !strcmp(addr_str_buf, addr_str_buf2))
+ ap->netconfig_set_addr4 = false;
+ }
+
+cleanup:
+ l_dhcp_server_destroy(dhcp);
+ l_rtnl_address_free(new_addr);
+ l_rtnl_address_free(existing_addr);
return ret;
}
-/*
- * This will determine the IP being used for DHCP. The IP will be automatically
- * set to ap->own_ip.
- *
- * The address to set (or keep) is determined in this order:
- * 1. Address defined in provisioning file
- * 2. Address already set on interface
- * 3. Address in IP pool.
- *
- * Returns: 0 if an IP was successfully selected and needs to be set
- * -EALREADY if an IP was already set on the interface or
- * IP configuration was not enabled,
- * -EEXIST if the IP pool ran out of IP's
- * -EINVAL if there was an error.
- */
-static int ap_setup_dhcp(struct ap_state *ap, const struct l_settings *settings)
+static int ap_load_ipv4(struct ap_state *ap, const struct l_settings *config)
{
- uint32_t ifindex = netdev_get_ifindex(ap->netdev);
- struct in_addr ia;
- uint32_t address = 0;
- L_AUTO_FREE_VAR(char *, addr) = NULL;
int ret = -EINVAL;
+ char **addr_str_list = NULL;
+ uint32_t static_addr = 0;
+ uint8_t prefix_len = 0;
+ char *gateway_str = NULL;
+ char **ip_range = NULL;
+ char **dns_str_list = NULL;
+ unsigned int lease_time = 0;
+ struct in_addr ia;
- /* get the current address if there is one */
- if (l_net_get_address(ifindex, &ia) && ia.s_addr != 0)
- address = ia.s_addr;
+ if (!l_settings_has_group(config, "IPv4") || !netconfig_enabled)
+ return 0;
- addr = l_settings_get_string(settings, "IPv4", "Address");
- if (addr) {
- if (inet_pton(AF_INET, addr, &ia) < 0)
- return -EINVAL;
+ if (l_settings_has_key(config, "IPv4", "Address")) {
+ addr_str_list = l_settings_get_string_list(config, "IPv4",
+ "Address", ',');
+ if (!addr_str_list || !*addr_str_list) {
+ l_error("Can't parse the profile [IPv4].Address "
+ "setting as a string list");
+ goto done;
+ }
- /* Is a matching address already set on interface? */
- if (ia.s_addr == address)
- ret = -EALREADY;
- else
- ret = 0;
- } else if (address) {
- /* No address in config, but interface has one set */
- addr = l_strdup(inet_ntoa(ia));
- ret = -EALREADY;
- } else if (pool.used) {
- /* No config file, no address set. Use IP pool */
- addr = ip_pool_get();
- if (!addr) {
- l_error("No more IP's in pool, cannot start AP on %u",
- ifindex);
- return -EEXIST;
+ /* Check for the static IP syntax: Address=<IP> */
+ if (l_strv_length(addr_str_list) == 1 &&
+ inet_pton(AF_INET, *addr_str_list, &ia) == 1)
+ static_addr = ntohl(ia.s_addr);
+ }
+
+ if (l_settings_has_key(config, "IPv4", "Netmask")) {
+ L_AUTO_FREE_VAR(char *, netmask_str) =
+ l_settings_get_string(config, "IPv4", "Netmask");
+
+ if (inet_pton(AF_INET, netmask_str, &ia) != 1) {
+ l_error("Can't parse the profile [IPv4].Netmask "
+ "setting");
+ goto done;
}
- ap->use_ip_pool = true;
- ap->ip_prefix = pool.prefix;
- ret = 0;
- } else
- return -EALREADY;
+ prefix_len = __builtin_popcount(ia.s_addr);
- ap->server = l_dhcp_server_new(ifindex);
- if (!ap->server) {
- l_error("Failed to create DHCP server on %u", ifindex);
- return -EINVAL;
+ if (ntohl(ia.s_addr) != util_netmask_from_prefix(prefix_len)) {
+ l_error("Invalid profile [IPv4].Netmask value");
+ goto done;
+ }
}
- if (getenv("IWD_DHCP_DEBUG"))
- l_dhcp_server_set_debug(ap->server, do_debug,
- "[DHCPv4 SERV] ", NULL);
+ if (l_settings_has_key(config, "IPv4", "Gateway")) {
+ gateway_str = l_settings_get_string(config, "IPv4", "Gateway");
+ if (!gateway_str) {
+ l_error("Invalid profile [IPv4].Gateway value");
+ goto done;
+ }
+ }
- /* Set the remaining DHCP options in config file */
- if (!dhcp_load_settings(ap, settings))
- return -EINVAL;
+ if (l_settings_get_value(config, "IPv4", "IPRange")) {
+ int i;
+ uint32_t netmask;
+ uint8_t tmp_len = prefix_len ?: AP_DEFAULT_IPV4_PREFIX_LEN;
- if (!l_dhcp_server_set_ip_address(ap->server, addr))
- return -EINVAL;
+ ip_range = l_settings_get_string_list(config, "IPv4",
+ "IPRange", ',');
- ap->own_ip = l_steal_ptr(addr);
- return ret;
-}
+ if (!static_addr) {
+ l_error("[IPv4].IPRange only makes sense in an AP "
+ "profile if a static local address has also "
+ "been specified");
+ goto done;
+ }
-static int ap_load_dhcp(struct ap_state *ap, const struct l_settings *config,
- bool *wait_dhcp)
-{
- uint32_t ifindex = netdev_get_ifindex(ap->netdev);
- int err = -EINVAL;
+ if (!ip_range || l_strv_length(ip_range) != 2) {
+ l_error("Can't parse the profile [IPv4].IPRange "
+ "setting as two address strings");
+ goto done;
+ }
- if (!l_settings_has_group(config, "IPv4"))
- return 0;
+ netmask = util_netmask_from_prefix(tmp_len);
- err = ap_setup_dhcp(ap, config);
- if (err == 0) {
- /* Address change required */
- ap->rtnl_add_cmd = l_rtnl_ifaddr4_add(rtnl, ifindex,
- ap->ip_prefix, ap->own_ip,
- broadcast_from_ip(ap->own_ip),
- ap_ifaddr4_added_cb, ap, NULL);
+ for (i = 0; i < 2; i++) {
+ struct in_addr range_addr;
- if (!ap->rtnl_add_cmd) {
- l_error("Failed to add IPv4 address");
- return -EIO;
+ if (inet_pton(AF_INET, ip_range[i], &range_addr) != 1) {
+ l_error("Can't parse address in "
+ "[IPv4].IPRange[%i]", i + 1);
+ goto done;
+ }
+
+ if ((static_addr ^ ntohl(range_addr.s_addr)) &
+ netmask) {
+ ia.s_addr = htonl(static_addr);
+ l_error("[IPv4].IPRange[%i] is not in the "
+ "%s/%i subnet", i + 1, inet_ntoa(ia),
+ tmp_len);
+ goto done;
+ }
}
+ }
- ap->cleanup_ip = true;
+ if (l_settings_has_key(config, "IPv4", "DNSList")) {
+ dns_str_list = l_settings_get_string_list(config, "IPv4",
+ "DNSList", ',');
+ if (!dns_str_list || !*dns_str_list) {
+ l_error("Can't parse the profile [IPv4].DNSList "
+ "setting as a string list");
+ goto done;
+ }
+ }
- *wait_dhcp = true;
- err = 0;
- /* Selected address already set, continue normally */
- } else if (err == -EALREADY) {
- *wait_dhcp = false;
- err = 0;
+ if (l_settings_has_key(config, "IPv4", "LeaseTime")) {
+ if (!l_settings_get_uint(config, "IPv4", "LeaseTime",
+ &lease_time) ||
+ lease_time < 1) {
+ l_error("Error parsing [IPv4].LeaseTime as a positive "
+ "integer");
+ goto done;
+ }
}
- return err;
+ ret = ap_setup_netconfig4(ap, (const char **) addr_str_list, prefix_len,
+ gateway_str, (const char **) ip_range,
+ (const char **) dns_str_list,
+ lease_time);
+
+done:
+ l_strv_free(addr_str_list);
+ l_free(gateway_str);
+ l_strv_free(ip_range);
+ l_strv_free(dns_str_list);
+ return ret;
}
static bool ap_load_psk(struct ap_state *ap, const struct l_settings *config)
@@ -2713,7 +2732,7 @@ static bool ap_load_psk(struct ap_state *ap, const struct l_settings *config)
}
static int ap_load_config(struct ap_state *ap, const struct l_settings *config,
- bool *out_wait_dhcp, bool *out_cck_rates)
+ bool *out_cck_rates)
{
size_t len;
L_AUTO_FREE_VAR(char *, strval) = NULL;
@@ -2739,11 +2758,12 @@ static int ap_load_config(struct ap_state *ap, const struct l_settings *config,
return -EINVAL;
/*
- * This loads DHCP settings either from the l_settings object or uses
- * the defaults. wait_on_address will be set true if an address change
- * is required.
+ * This looks at the network configuration settings in @config and
+ * relevant global settings and if it determines that netconfig is to
+ * be enabled for the AP, it both creates the DHCP server object and
+ * processes IP settings, applying the defaults where needed.
*/
- err = ap_load_dhcp(ap, config, out_wait_dhcp);
+ err = ap_load_ipv4(ap, config);
if (err)
return err;
@@ -2858,17 +2878,16 @@ struct ap_state *ap_start(struct netdev *netdev, struct l_settings *config,
{
struct ap_state *ap;
struct wiphy *wiphy = netdev_get_wiphy(netdev);
- struct l_genl_msg *cmd;
uint64_t wdev_id = netdev_get_wdev_id(netdev);
- int err = -EINVAL;
- bool wait_on_address = false;
+ int err;
bool cck_rates = true;
- if (err_out)
- *err_out = err;
+ if (L_WARN_ON(!config)) {
+ if (err_out)
+ *err_out = -EINVAL;
- if (L_WARN_ON(!config))
return NULL;
+ }
ap = l_new(struct ap_state, 1);
ap->nl80211 = l_genl_family_new(iwd_get_genl(), NL80211_GENL_NAME);
@@ -2876,7 +2895,7 @@ struct ap_state *ap_start(struct netdev *netdev, struct l_settings *config,
ap->ops = ops;
ap->user_data = user_data;
- err = ap_load_config(ap, config, &wait_on_address, &cck_rates);
+ err = ap_load_config(ap, config, &cck_rates);
if (err)
goto error;
@@ -2942,29 +2961,26 @@ struct ap_state *ap_start(struct netdev *netdev, struct l_settings *config,
if (!ap->mlme_watch)
l_error("Registering for MLME notification failed");
- if (wait_on_address) {
- if (err_out)
- *err_out = 0;
+ if (ap->netconfig_set_addr4) {
+ ap->rtnl_add_cmd = l_rtnl_ifaddr_add(rtnl,
+ netdev_get_ifindex(netdev),
+ ap->netconfig_addr4,
+ ap_ifaddr4_added_cb, ap, NULL);
+ if (!ap->rtnl_add_cmd) {
+ l_error("Failed to add the IPv4 address");
+ goto error;
+ }
return ap;
}
- cmd = ap_build_cmd_start_ap(ap);
- if (!cmd)
- goto error;
+ if (ap_start_send(ap)) {
+ if (err_out)
+ *err_out = 0;
- ap->start_stop_cmd_id = l_genl_family_send(ap->nl80211, cmd,
- ap_start_cb, ap, NULL);
- if (!ap->start_stop_cmd_id) {
- l_genl_msg_unref(cmd);
- goto error;
+ return ap;
}
- if (err_out)
- *err_out = 0;
-
- return ap;
-
error:
if (err_out)
*err_out = err;
@@ -3075,8 +3091,6 @@ void ap_free(struct ap_state *ap)
{
ap_reset(ap);
l_genl_family_free(ap->nl80211);
- if (ap->server)
- l_dhcp_server_destroy(ap->server);
l_free(ap);
}
@@ -3155,13 +3169,17 @@ static void ap_if_event_func(enum ap_event_type type, const void *event_data,
switch (type) {
case AP_EVENT_START_FAILED:
+ {
+ const struct ap_event_start_failed_data *data = event_data;
+
if (L_WARN_ON(!ap_if->pending))
break;
- reply = dbus_error_failed(ap_if->pending);
+ reply = dbus_error_from_errno(data->error, ap_if->pending);
dbus_pending_reply(&ap_if->pending, reply);
ap_if->ap = NULL;
break;
+ }
case AP_EVENT_STARTED:
if (L_WARN_ON(!ap_if->pending))
@@ -3214,6 +3232,8 @@ static void ap_if_event_func(enum ap_event_type type, const void *event_data,
case AP_EVENT_REGISTRATION_START:
case AP_EVENT_REGISTRATION_SUCCESS:
case AP_EVENT_PBC_MODE_EXIT:
+ case AP_EVENT_DHCP_NEW_LEASE:
+ case AP_EVENT_DHCP_LEASE_EXPIRED:
/* Ignored */
break;
}
@@ -3532,7 +3552,6 @@ static void ap_netdev_watch(struct netdev *netdev,
static int ap_init(void)
{
const struct l_settings *settings = iwd_get_config();
- bool dhcp_enable;
netdev_watch = netdev_watch_add(ap_netdev_watch, NULL, NULL);
@@ -3545,31 +3564,47 @@ static int ap_init(void)
#endif
/*
- * Reusing [General].EnableNetworkConfiguration as a switch to enable
- * DHCP server. If no value is found or it is false do not create a
- * DHCP server.
+ * Enable network configuration and DHCP only if
+ * [General].EnableNetworkConfiguration is true.
*/
if (!l_settings_get_bool(settings, "General",
- "EnableNetworkConfiguration", &dhcp_enable))
- dhcp_enable = false;
-
- if (dhcp_enable) {
- L_AUTO_FREE_VAR(char *, ip_prefix);
-
- ip_prefix = l_settings_get_string(settings, "General",
- "APRanges");
- /*
- * In this case its assumed the user only cares about station
- * netconfig so we let ap_init pass but DHCP will not be
- * enabled.
- */
- if (!ip_prefix) {
- l_warn("[General].APRanges must be set for DHCP");
- return 0;
+ "EnableNetworkConfiguration",
+ &netconfig_enabled))
+ netconfig_enabled = false;
+
+ if (netconfig_enabled) {
+ if (l_settings_get_value(settings, "IPv4", "APAddressPool")) {
+ global_addr4_strs = l_settings_get_string_list(settings,
+ "IPv4",
+ "APAddressPool",
+ ',');
+ if (!global_addr4_strs || !*global_addr4_strs) {
+ l_error("Can't parse the [IPv4].APAddressPool "
+ "setting as a string list");
+ l_strv_free(global_addr4_strs);
+ global_addr4_strs = NULL;
+ }
+ } else if (l_settings_get_value(settings,
+ "General", "APRanges")) {
+ l_warn("The [General].APRanges setting is deprecated, "
+ "use [IPv4].APAddressPool instead");
+
+ global_addr4_strs = l_settings_get_string_list(settings,
+ "General",
+ "APRanges",
+ ',');
+ if (!global_addr4_strs || !*global_addr4_strs) {
+ l_error("Can't parse the [General].APRanges "
+ "setting as a string list");
+ l_strv_free(global_addr4_strs);
+ global_addr4_strs = NULL;
+ }
}
- if (!ip_pool_create(ip_prefix))
- return -EINVAL;
+ /* Fall back to 192.168.0.0/16 */
+ if (!global_addr4_strs)
+ global_addr4_strs =
+ l_strv_append(NULL, "192.168.0.0/16");
}
rtnl = iwd_get_rtnl();
@@ -3584,7 +3619,7 @@ static void ap_exit(void)
l_dbus_unregister_interface(dbus_get_bus(), IWD_AP_INTERFACE);
#endif
- ip_pool_destroy();
+ l_strv_free(global_addr4_strs);
}
IWD_MODULE(ap, ap_init, ap_exit)
diff --git a/src/ap.h b/src/ap.h
@@ -33,6 +33,12 @@ enum ap_event_type {
AP_EVENT_REGISTRATION_START,
AP_EVENT_REGISTRATION_SUCCESS,
AP_EVENT_PBC_MODE_EXIT,
+ AP_EVENT_DHCP_NEW_LEASE,
+ AP_EVENT_DHCP_LEASE_EXPIRED,
+};
+
+struct ap_event_start_failed_data {
+ int error;
};
struct ap_event_station_added_data {
diff --git a/src/band.c b/src/band.c
@@ -0,0 +1,467 @@
+/*
+ *
+ * Wireless daemon for Linux
+ *
+ * Copyright (C) 2021 Intel Corporation. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <errno.h>
+
+#include <ell/ell.h>
+
+#include "ell/useful.h"
+
+#include "band.h"
+
+void band_free(struct band *band)
+{
+ l_free(band);
+}
+
+/*
+ * Rates are stored as they are encoded in the Supported Rates IE.
+ * This data was taken from 802.11 Section 17.3.10.2 Table 17-18 and
+ * Table 17-4. Together we have minimum RSSI required for a given data rate.
+ */
+static const struct {
+ int32_t rssi;
+ uint8_t rate;
+} rate_rssi_map[] = {
+ { -90, 2 }, /* Make something up for 11b rates */
+ { -88, 4 },
+ { -86, 11 },
+ { -84, 22 },
+ { -82, 12 },
+ { -81, 18 },
+ { -79, 24 },
+ { -77, 36 },
+ { -74, 48 },
+ { -70, 72 },
+ { -66, 96 },
+ { -65, 108 },
+};
+
+static bool peer_supports_rate(const uint8_t *rates, uint8_t rate)
+{
+ int i;
+
+ if (rates && rates[1]) {
+ for (i = 0; i < rates[1]; i++) {
+ uint8_t r = rates[i + 2] & 0x7f;
+
+ if (r == rate)
+ return true;
+ }
+ }
+
+ return false;
+}
+
+int band_estimate_nonht_rate(const struct band *band,
+ const uint8_t *supported_rates,
+ const uint8_t *ext_supported_rates,
+ int32_t rssi, uint64_t *out_data_rate)
+{
+ int nrates = L_ARRAY_SIZE(rate_rssi_map);
+ uint8_t max_rate = 0;
+ int i;
+
+ if (!supported_rates && !ext_supported_rates)
+ return -EINVAL;
+
+ /*
+ * Start at the back of the array. Rates are generally given in
+ * ascending order, starting at 11b rates, then 11g rates. More often
+ * than not we'll pick the highest rate and avoid unneeded processing
+ */
+ for (i = band->supported_rates_len - 1; i >= 0; i--) {
+ uint8_t rate = band->supported_rates[i];
+ int j;
+
+ if (max_rate >= rate)
+ continue;
+
+ /* Can this rate be used at the peer's RSSI? */
+ for (j = 0; j < nrates; j++)
+ if (rate_rssi_map[j].rate == rate)
+ break;
+
+ if (j == nrates)
+ continue;
+
+ if (rssi < rate_rssi_map[j].rssi)
+ continue;
+
+ if (peer_supports_rate(supported_rates, rate) ||
+ peer_supports_rate(ext_supported_rates, rate))
+ max_rate = rate;
+ }
+
+ if (!max_rate)
+ return -EINVAL;
+
+ *out_data_rate = max_rate * 500000;
+ return 0;
+}
+
+/*
+ * Base RSSI values for 20MHz (both HT and VHT) 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.
+ */
+static const int32_t ht_vht_base_rssi[] = {
+ -82, -79, -77, -74, -70, -66, -65, -64, -59, -57
+};
+
+/*
+ * Data Rate for HT/VHT is obtained according to this formula:
+ * Nsd * Nbpscs * R * Nss / (Tdft + Tgi)
+ *
+ * Where Nsd is [52, 108, 234, 468] for 20/40/80/160 Mhz respectively
+ * Nbpscs is [1, 2, 4, 6, 8] for BPSK/QPSK/16QAM/64QAM/256QAM
+ * R is [1/2, 2/3, 3/4, 5/6] depending on the MCS index
+ * Nss is the number of spatial streams
+ * Tdft = 3.2 us
+ * Tgi = Long/Short GI of 0.8/0.4 us
+ *
+ * Short GI rate can be easily obtained by multiplying by (10 / 9)
+ *
+ * The table was pre-computed using the following python snippet:
+ * rfactors = [ 1/2, 1/2, 3/4, 1/2, 3/4, 2/3, 3/4, 5/6, 3/4, 5/6 ]
+ * nbpscs = [1, 2, 2, 4, 4, 6, 6, 6, 8, 8 ]
+ * nsds = [52, 108, 234, 468]
+ *
+ * for nsd in nsds:
+ * rates = []
+ * for i in xrange(0, 10):
+ * data_rate = (nsd * rfactors[i] * nbpscs[i]) / 0.004
+ * rates.append(int(data_rate) * 1000)
+ * print('rates for nsd: ' + nsd + ': ' + rates)
+ */
+
+static const uint64_t ht_vht_rates[4][10] = {
+ [OFDM_CHANNEL_WIDTH_20MHZ] = {
+ 6500000ULL, 13000000ULL, 19500000ULL, 26000000ULL,
+ 39000000ULL, 52000000ULL, 58500000ULL, 65000000ULL,
+ 78000000ULL, 86666000ULL },
+ [OFDM_CHANNEL_WIDTH_40MHZ] = {
+ 13500000ULL, 27000000ULL, 40500000ULL, 54000000ULL,
+ 81000000ULL, 108000000ULL, 121500000ULL, 135000000ULL,
+ 162000000ULL, 180000000ULL, },
+ [OFDM_CHANNEL_WIDTH_80MHZ] = {
+ 29250000ULL, 58500000ULL, 87750000ULL, 117000000ULL,
+ 175500000ULL, 234000000ULL, 263250000ULL, 292500000ULL,
+ 351000000ULL, 390000000ULL, },
+ [OFDM_CHANNEL_WIDTH_160MHZ] = {
+ 58500000ULL, 117000000ULL, 175500000ULL, 234000000ULL,
+ 351000000ULL, 468000000ULL, 526500000ULL, 585000000ULL,
+ 702000000ULL, 780000000ULL,
+ }
+};
+
+/*
+ * Both HT and VHT rates are calculated in the same fashion. The only difference
+ * is a relative MCS index is used for HT since, for each NSS, the formula
+ * is the same with relative index's. This is why this is called with index % 8
+ * for HT, but not VHT.
+ */
+bool band_ofdm_rate(uint8_t index, enum ofdm_channel_width width,
+ int32_t rssi, uint8_t nss, bool sgi,
+ uint64_t *data_rate)
+{
+ uint64_t rate;
+ int32_t width_adjust = width * 3;
+
+ if (rssi < ht_vht_base_rssi[index] + width_adjust)
+ return false;
+
+ rate = ht_vht_rates[width][index];
+
+ if (sgi)
+ rate = rate / 9 * 10;
+
+ rate *= nss;
+
+ *data_rate = rate;
+ return true;
+}
+
+static bool find_best_mcs_ht(const struct band *band,
+ const uint8_t *tx_mcs_set,
+ uint8_t max_mcs, enum ofdm_channel_width width,
+ int32_t rssi, bool sgi,
+ uint64_t *out_data_rate)
+{
+ int i;
+
+ /*
+ * TODO: Support MCS values 32 - 76
+ *
+ * The MCS values > 31 use an unequal modulation, and the number of
+ * supported MCS indexes per NSS differs. We do not consider them
+ * here for now to keep things simple(r).
+ */
+ for (i = max_mcs; i >= 0; i--) {
+ if (!test_bit(band->ht_mcs_set, i))
+ continue;
+
+ if (!test_bit(tx_mcs_set, i))
+ continue;
+
+ if (band_ofdm_rate(i % 8, width, rssi,
+ (i / 8) + 1, sgi, out_data_rate))
+ return true;
+ }
+
+ return false;
+}
+
+int band_estimate_ht_rx_rate(const struct band *band,
+ const uint8_t *htc, const uint8_t *hto,
+ int32_t rssi, uint64_t *out_data_rate)
+{
+ uint8_t channel_offset;
+ int max_mcs = 31;
+ bool sgi;
+ uint8_t unequal_tx_mcs_set[16];
+ const uint8_t *tx_mcs_set;
+
+ if (!band->ht_supported)
+ return -ENOTSUP;
+
+ if (!htc || !hto)
+ return -ENOTSUP;
+
+ memset(unequal_tx_mcs_set, 0, sizeof(unequal_tx_mcs_set));
+
+ tx_mcs_set = htc + 5;
+
+ /*
+ * Check 'Tx MCS Set Defined' at bit 96 and 'Tx MCS Set Unequal' at
+ * bit 97 of the Supported MCS Set field. Also extract 'Tx Maximum
+ * Number of Spatial Streams Supported' field at bits 98 and 99.
+ *
+ * Note 44 on page 1662 of 802.11-2016 states:
+ * "How a non-AP STA determines an AP’s HT MCS transmission support,
+ * if the Tx MCS Set subfield in the HT Capabilities element
+ * advertised by the AP is equal to 0 or if he Tx Rx MCS Set Not Equal
+ * subfield in that element is equal to 1, is implementation dependent.
+ * The non-AP STA might conservatively use the basic HT-MCS set, or it
+ * might use knowledge of past transmissions by the AP, or it might
+ * use other means.
+ */
+ if (test_bit(tx_mcs_set, 96)) {
+ if (test_bit(tx_mcs_set, 97)) {
+ uint8_t max_nss = bit_field(tx_mcs_set[12], 2, 2);
+
+ max_mcs = max_nss * 4 + 7;
+
+ /*
+ * For purposes of finding the best MCS below, assume
+ * the AP can send any MCS up to max_nss (i.e 0-7 for
+ * 1 nss, 0-15 for 2 nss, 0-23 for 3 nss, 0-31 for 4
+ */
+ memset(unequal_tx_mcs_set, 0xff, max_nss + 1);
+ tx_mcs_set = unequal_tx_mcs_set;
+ }
+ } else
+ max_mcs = 7;
+
+ /* Test for 40 Mhz operation */
+ channel_offset = bit_field(hto[3], 0, 2);
+ if (test_bit(hto + 3, 2) &&
+ (channel_offset == 1 || channel_offset == 3)) {
+ sgi = test_bit(band->ht_capabilities, 6) &&
+ test_bit(htc + 2, 6);
+
+ if (find_best_mcs_ht(band, tx_mcs_set, max_mcs,
+ OFDM_CHANNEL_WIDTH_40MHZ,
+ rssi, sgi, out_data_rate))
+ return 0;
+ }
+
+ sgi = test_bit(band->ht_capabilities, 5) && test_bit(htc + 2, 5);
+
+ if (find_best_mcs_ht(band, tx_mcs_set, max_mcs,
+ OFDM_CHANNEL_WIDTH_20MHZ,
+ rssi, sgi, out_data_rate))
+ return 0;
+
+ return -EINVAL;
+}
+
+static bool find_best_mcs_vht(uint8_t max_index, enum ofdm_channel_width width,
+ int32_t rssi, uint8_t nss, bool sgi,
+ uint64_t *out_data_rate)
+{
+ int i;
+
+ /*
+ * Iterate over all available MCS indexes to find the best one
+ * we can use. Note that band_ofdm_rate() will return false if a
+ * given combination cannot be used due to rssi being too low.
+ *
+ * Also, Certain MCS/Width/NSS combinations are not valid,
+ * refer to IEEE 802.11-2016 Section 21.5 for more details
+ */
+
+ for (i = max_index; i >= 0; i--)
+ if (band_ofdm_rate(i, width, rssi,
+ nss, sgi, out_data_rate))
+ return true;
+
+ return false;
+}
+
+/*
+ * IEEE 802.11 - Table 9-250
+ *
+ * For simplicity, we are ignoring the Extended BSS BW support, per NOTE 11:
+ *
+ * NOTE 11-A receiving STA in which dot11VHTExtendedNSSCapable is false will
+ * ignore the Extended NSS BW Support subfield and effectively evaluate this
+ * table only at the entries where Extended NSS BW Support is 0.
+ *
+ * This also allows us to group the 160/80+80 widths together, since they are
+ * the same when Extended NSS BW is zero.
+ */
+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,
+ int32_t rssi, uint64_t *out_data_rate)
+{
+ uint32_t nss = 0;
+ 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;
+
+ if (!band->vht_supported || !band->ht_supported)
+ return -ENOTSUP;
+
+ if (!vhtc || !vhto || !htc || !hto)
+ return -ENOTSUP;
+
+ if (vhto[2] > 3)
+ return -EBADMSG;
+
+ /*
+ * Find the highest NSS/MCS index combination. Since this is used by
+ * STAs, we try to estimate our 'download' speed from the AP/peer.
+ * Hence we look at the TX MCS map of the peer and our own RX MCS map
+ * to find an overlapping combination that works
+ */
+ 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)
+ return -EBADMSG;
+
+ /*
+ * There is no way to know whether a peer would send us packets using
+ * the short guard interval (SGI.) SGI capability is only used to
+ * indicate whether the peer can accept packets that we send this way.
+ * Here we make the assumption that if the peer has the capability to
+ * accept packets using SGI and we have the capability to do so, then
+ * SGI will be used
+ *
+ * Also, we assume that the highest bandwidth will result in the
+ * highest rate for any given rssi. Even accounting for invalid
+ * MCS/Width/NSS combinations, the higher channel width results
+ * in better data rate at [mcs index - 2] compared to [mcs index] of
+ * a next lower bandwidth.
+ */
+
+ /* See if 160 Mhz operation is available */
+ chan_width = bit_field(band->vht_capabilities[0], 2, 2);
+ if (chan_width != 1 && chan_width != 2)
+ goto try_vht80;
+
+ /*
+ * Channel Width is set to 2 or 3, or 1 and
+ * channel center frequency segment 1 is non-zero
+ */
+ if (vhto[2] == 2 || vhto[2] == 3 || (vhto[2] == 1 && vhto[4])) {
+ sgi = test_bit(band->vht_capabilities, 6) &&
+ test_bit(vhtc + 2, 6);
+
+ if (find_best_mcs_vht(max_mcs, OFDM_CHANNEL_WIDTH_160MHZ,
+ rssi, nss, sgi, out_data_rate))
+ return 0;
+ }
+
+try_vht80:
+ if (vhto[2] == 1) {
+ sgi = test_bit(band->vht_capabilities, 5) &&
+ test_bit(vhtc + 2, 5);
+
+ if (find_best_mcs_vht(max_mcs, OFDM_CHANNEL_WIDTH_80MHZ,
+ rssi, nss, sgi, out_data_rate))
+ return 0;
+ } /* Otherwise, assume 20/40 Operation */
+
+ channel_offset = bit_field(hto[3], 0, 2);
+
+ /* Test for 40 Mhz operation */
+ if (test_bit(hto + 3, 2) &&
+ (channel_offset == 1 || channel_offset == 3)) {
+ sgi = test_bit(band->ht_capabilities, 6) &&
+ test_bit(htc + 2, 6);
+
+ if (find_best_mcs_vht(max_mcs, OFDM_CHANNEL_WIDTH_40MHZ,
+ rssi, nss, sgi, out_data_rate))
+ return 0;
+ }
+
+ sgi = test_bit(band->ht_capabilities, 5) && test_bit(htc + 2, 5);
+
+ if (find_best_mcs_vht(max_mcs, OFDM_CHANNEL_WIDTH_20MHZ,
+ rssi, nss, sgi, out_data_rate))
+ return 0;
+
+ return -EINVAL;
+}
diff --git a/src/band.h b/src/band.h
@@ -0,0 +1,57 @@
+/*
+ *
+ * Wireless daemon for Linux
+ *
+ * Copyright (C) 2021 Intel Corporation. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+enum ofdm_channel_width {
+ OFDM_CHANNEL_WIDTH_20MHZ = 0,
+ OFDM_CHANNEL_WIDTH_40MHZ,
+ OFDM_CHANNEL_WIDTH_80MHZ,
+ OFDM_CHANNEL_WIDTH_160MHZ,
+};
+
+struct band {
+ uint8_t vht_mcs_set[8];
+ uint8_t vht_capabilities[4];
+ bool vht_supported : 1;
+ uint8_t ht_mcs_set[16];
+ uint8_t ht_capabilities[2];
+ bool ht_supported : 1;
+ uint16_t supported_rates_len;
+ uint8_t supported_rates[];
+};
+
+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_vht_rx_rate(const struct band *band,
+ const uint8_t *vhtc, const uint8_t *vhto,
+ const uint8_t *htc, const uint8_t *hto,
+ int32_t rssi, uint64_t *out_data_rate);
+int band_estimate_ht_rx_rate(const struct band *band,
+ const uint8_t *htc, const uint8_t *hto,
+ int32_t rssi, uint64_t *out_data_rate);
+int band_estimate_nonht_rate(const struct band *band,
+ const uint8_t *supported_rates,
+ const uint8_t *ext_supported_rates,
+ int32_t rssi, uint64_t *out_data_rate);
diff --git a/src/dbus.h b/src/dbus.h
@@ -24,6 +24,7 @@
#define IWD_SERVICE "net.connman.iwd"
+#define IWD_DAEMON_INTERFACE "net.connman.iwd.Daemon"
#define IWD_AGENT_MANAGER_INTERFACE "net.connman.iwd.AgentManager"
#define IWD_WIPHY_INTERFACE "net.connman.iwd.Adapter"
#define IWD_DEVICE_INTERFACE "net.connman.iwd.Device"
diff --git a/src/eap-gtc.c b/src/eap-gtc.c
@@ -79,7 +79,6 @@ static int eap_gtc_check_settings(struct l_settings *settings,
const struct eap_secret_info *secret;
char identity_key[72];
char password_key[72];
- char password_key_old[72];
L_AUTO_FREE_VAR(char *, identity);
L_AUTO_FREE_VAR(char *, password) = NULL;
@@ -105,17 +104,6 @@ static int eap_gtc_check_settings(struct l_settings *settings,
password = l_settings_get_string(settings, "Security", password_key);
if (!password) {
- snprintf(password_key_old, sizeof(password_key_old),
- "%sGTC-Secret", prefix);
- password = l_settings_get_string(settings, "Security",
- password_key_old);
- if (password) {
- explicit_bzero(password, strlen(password));
- l_warn("Setting '%s' is deprecated, use '%s' instead",
- password_key_old, password_key);
- return 0;
- }
-
secret = l_queue_find(secrets, eap_secret_info_match,
password_key);
if (secret)
diff --git a/src/eap-md5.c b/src/eap-md5.c
@@ -98,7 +98,6 @@ static int eap_md5_check_settings(struct l_settings *settings,
const struct eap_secret_info *secret;
char identity_key[72];
char password_key[72];
- char password_key_old[72];
L_AUTO_FREE_VAR(char *, identity);
L_AUTO_FREE_VAR(char *, password) = NULL;
@@ -124,17 +123,6 @@ static int eap_md5_check_settings(struct l_settings *settings,
password = l_settings_get_string(settings, "Security", password_key);
if (!password) {
- snprintf(password_key_old, sizeof(password_key_old),
- "%sMD5-Secret", prefix);
- password = l_settings_get_string(settings, "Security",
- password_key_old);
- if (password) {
- explicit_bzero(password, strlen(password));
- l_warn("Setting '%s' is deprecated, use '%s' instead",
- password_key_old, password_key);
- return 0;
- }
-
secret = l_queue_find(secrets, eap_secret_info_match,
password_key);
if (secret)
diff --git a/src/eapolutil.h b/src/eapolutil.h
@@ -57,7 +57,7 @@ struct eapol_header {
struct eapol_frame {
struct eapol_header header;
- uint8_t data[0];
+ uint8_t data[];
} __attribute__ ((packed));
/* gets pointer to MIC */
@@ -111,7 +111,7 @@ struct eapol_key {
uint8_t eapol_key_iv[16];
uint8_t key_rsc[8];
uint8_t reserved[8];
- uint8_t key_data[0];
+ uint8_t key_data[];
} __attribute__ ((packed));
const struct eapol_key *eapol_key_validate(const uint8_t *frame, size_t len,
diff --git a/src/ft.c b/src/ft.c
@@ -452,7 +452,7 @@ static bool mde_equal(const uint8_t *mde1, const uint8_t *mde2)
return memcmp(mde1, mde1, mde1[1] + 2) == 0;
}
-static bool ft_over_ds_process_ies(struct ft_ds_info *info,
+bool ft_over_ds_parse_action_ies(struct ft_ds_info *info,
struct handshake_state *hs,
const uint8_t *ies,
size_t ies_len)
@@ -523,11 +523,15 @@ ft_error:
return -EBADMSG;
}
-int ft_over_ds_parse_action_response(struct ft_ds_info *info,
- struct handshake_state *hs,
- const uint8_t *frame, size_t frame_len)
+int ft_over_ds_parse_action_response(const uint8_t *frame, size_t frame_len,
+ const uint8_t **spa_out,
+ const uint8_t **aa_out,
+ const uint8_t **ies_out,
+ size_t *ies_len)
{
uint16_t status;
+ const uint8_t *aa;
+ const uint8_t *spa;
if (frame_len < 16)
return -EINVAL;
@@ -540,17 +544,23 @@ int ft_over_ds_parse_action_response(struct ft_ds_info *info,
if (frame[1] != 2)
return -EINVAL;
- if (memcmp(frame + 2, info->spa, 6))
- return -ENOENT;
- if (memcmp(frame + 8, info->aa, 6))
- return -ENOENT;
+ spa = frame + 2;
+ aa = frame + 8;
status = l_get_le16(frame + 14);
if (status != 0)
return (int)status;
- if (!ft_over_ds_process_ies(info, hs, frame + 16, frame_len - 16))
- return -EBADMSG;
+ if (spa_out)
+ *spa_out = spa;
+
+ if (aa_out)
+ *aa_out = aa;
+
+ if (ies_out && ies_len) {
+ *ies_out = frame + 16;
+ *ies_len = frame_len - 16;
+ }
return 0;
}
diff --git a/src/ft.h b/src/ft.h
@@ -47,9 +47,15 @@ bool ft_build_authenticate_ies(struct handshake_state *hs,
const uint8_t *new_snonce, uint8_t *buf,
size_t *len);
-int ft_over_ds_parse_action_response(struct ft_ds_info *info,
+int ft_over_ds_parse_action_response(const uint8_t *frame, size_t frame_len,
+ const uint8_t **spa_out,
+ const uint8_t **aa_out,
+ const uint8_t **ies_out,
+ size_t *ies_len);
+bool ft_over_ds_parse_action_ies(struct ft_ds_info *info,
struct handshake_state *hs,
- const uint8_t *frame, size_t frame_len);
+ const uint8_t *ies,
+ size_t ies_len);
struct auth_proto *ft_over_air_sm_new(struct handshake_state *hs,
ft_tx_authenticate_func_t tx_auth,
diff --git a/src/ie.c b/src/ie.c
@@ -1631,559 +1631,6 @@ int ie_parse_bss_load_from_data(const uint8_t *data, uint8_t len,
out_channel_utilization, out_admission_capacity);
}
-/*
- * We have to store this mapping since basic rates don't come with a convenient
- * MCS index. Rates are stored as they are encoded in the Supported Rates IE.
- * This does not include non 802.11g data rates, e.g. 1/2/4Mbps. This data was
- * taken from 802.11 Section 17.3.10.2 and Table 10-7.
- *
- * Section 17.3.10.2 defines minimum RSSI for modulations, and Table
- * 10-7 defines reference rates for the different modulations. Together we
- * have minimum RSSI required for a given data rate.
- */
-struct basic_rate_map {
- int32_t rssi;
- uint8_t rate;
-};
-
-/*
- * Rates are stored in 500Kbps increments. This is how the IE encodes the data
- * so its more convenient to match by this encoding. The actual data rate is
- * converted to Mbps after we find a match
- */
-static const struct basic_rate_map rate_rssi_map[] = {
- { -82, 12 },
- { -81, 18 },
- { -79, 24 },
- { -77, 36 },
- { -74, 48 },
- { -70, 72 },
- { -66, 96 },
- { -65, 108 },
-};
-
-static int ie_parse_supported_rates(struct ie_tlv_iter *supp_rates_iter,
- struct ie_tlv_iter *ext_supp_rates_iter,
- int32_t rssi,
- uint64_t *data_rate)
-{
- uint8_t max_rate = 0;
- uint8_t highest = 0;
- const uint8_t *rates;
- unsigned int len;
- unsigned int i;
-
- len = ie_tlv_iter_get_length(supp_rates_iter);
-
- if (len == 0)
- return -EINVAL;
-
- /* Find highest rates possible with our RSSI */
- for (i = 0; i < L_ARRAY_SIZE(rate_rssi_map); i++) {
- const struct basic_rate_map *map = &rate_rssi_map[i];
-
- if (rssi < map->rssi)
- break;
-
- max_rate = map->rate;
- }
-
- /* Find highest rate in Supported Rates IE */
- rates = ie_tlv_iter_get_data(supp_rates_iter);
-
- for (i = 0; i < len; i++) {
- uint8_t r = rates[i] & 0x7f;
-
- if (r <= max_rate && r > highest)
- highest = r;
- }
-
- /* Find highest rate in Extended Supported Rates IE */
- if (ext_supp_rates_iter) {
- len = ie_tlv_iter_get_length(ext_supp_rates_iter);
- rates = ie_tlv_iter_get_data(ext_supp_rates_iter);
-
- for (i = 0; i < len; i++) {
- uint8_t r = rates[i] & 0x7f;
-
- if (r <= max_rate && r > highest)
- highest = r;
- }
- }
-
- *data_rate = (highest / 2) * 1000000;
-
- return 0;
-}
-
-int ie_parse_supported_rates_from_data(const uint8_t *supp_rates_ie,
- uint8_t supp_rates_len,
- const uint8_t *ext_supp_rates_ie,
- uint8_t ext_supp_rates_len,
- int32_t rssi, uint64_t *data_rate)
-{
- struct ie_tlv_iter supp_rates_iter;
- struct ie_tlv_iter ext_supp_rates_iter;
-
- if (supp_rates_ie) {
- ie_tlv_iter_init(&supp_rates_iter, supp_rates_ie,
- supp_rates_len);
-
- if (!ie_tlv_iter_next(&supp_rates_iter))
- return -EMSGSIZE;
-
- if (ie_tlv_iter_get_tag(&supp_rates_iter) !=
- IE_TYPE_SUPPORTED_RATES)
- return -EPROTOTYPE;
- }
-
- if (ext_supp_rates_ie) {
- ie_tlv_iter_init(&ext_supp_rates_iter, ext_supp_rates_ie,
- ext_supp_rates_len);
-
- if (!ie_tlv_iter_next(&ext_supp_rates_iter))
- return -EMSGSIZE;
-
- if (ie_tlv_iter_get_tag(&ext_supp_rates_iter) !=
- IE_TYPE_EXTENDED_SUPPORTED_RATES)
- return -EPROTOTYPE;
- }
-
- return ie_parse_supported_rates(
- (supp_rates_ie) ? &supp_rates_iter : NULL,
- (ext_supp_rates_ie) ? &ext_supp_rates_iter : NULL,
- rssi, data_rate);
-}
-
-enum ht_vht_channel_width {
- HT_VHT_CHANNEL_WIDTH_20MHZ = 0,
- HT_VHT_CHANNEL_WIDTH_40MHZ,
- HT_VHT_CHANNEL_WIDTH_80MHZ,
- HT_VHT_CHANNEL_WIDTH_160MHZ,
-};
-
-/*
- * Base RSSI values for 20MHz (both HT and VHT) 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.
- */
-static const int32_t ht_vht_base_rssi[] = {
- -82, -79, -77, -74, -70, -66, -65, -64, -59, -57
-};
-
-struct ht_vht_rate {
- uint64_t rate;
- uint64_t sgi_rate;
-};
-
-static const struct ht_vht_rate ht_vht_rates[] = {
- [HT_VHT_CHANNEL_WIDTH_20MHZ] = { .rate = 6500000,
- .sgi_rate = 7200000 },
- [HT_VHT_CHANNEL_WIDTH_40MHZ] = { .rate = 13500000,
- .sgi_rate = 15000000 },
- [HT_VHT_CHANNEL_WIDTH_80MHZ] = { .rate = 29300000,
- .sgi_rate = 32500000 },
- [HT_VHT_CHANNEL_WIDTH_160MHZ] = { .rate = 58500000,
- .sgi_rate = 65000000 },
-};
-
-/*
- * Both HT and VHT rates are calculated in the same fashion. The only difference
- * is a relative MCS index is used for HT since, for each NSS, the formula
- * is the same with relative index's. This is why this is called with index % 8
- * for HT, but not VHT.
- */
-static bool calculate_ht_vht_data_rate(uint8_t index,
- enum ht_vht_channel_width width,
- int32_t rssi, uint8_t nss, bool sgi,
- uint64_t *data_rate)
-{
- const struct ht_vht_rate *rate = &ht_vht_rates[width];
- int32_t width_adjust = width * 3;
-
- if (rssi < ht_vht_base_rssi[index] + width_adjust)
- return false;
-
- if (sgi)
- *data_rate = rate->sgi_rate;
- else
- *data_rate = rate->rate;
-
- /* adjust base for spatial streams */
- *data_rate *= nss;
-
- /*
- * As with HT, the VHT rates multiplier jumps up
- * by 2 after MCS index 4
- */
- if (index < 4)
- *data_rate *= index + 1;
- else
- *data_rate *= index + 3;
-
- return true;
-}
-
-static int ie_parse_ht_capability(struct ie_tlv_iter *iter, int32_t rssi,
- uint64_t *data_rate)
-{
- unsigned int len;
- const uint8_t *data;
- uint8_t ht_cap;
- int i;
- uint64_t highest_rate = 0;
- bool support_40mhz;
- bool short_gi_20mhz;
- bool short_gi_40mhz;
-
- len = ie_tlv_iter_get_length(iter);
-
- if (len < 26)
- return -EINVAL;
-
- if (ie_tlv_iter_get_tag(iter) != IE_TYPE_HT_CAPABILITIES)
- return -EINVAL;
-
- data = ie_tlv_iter_get_data(iter);
-
- /* Parse out channel width set and short GI */
- ht_cap = l_get_u8(data++);
-
- support_40mhz = test_bit(&ht_cap, 1);
- short_gi_20mhz = test_bit(&ht_cap, 5);
- short_gi_40mhz = test_bit(&ht_cap, 6);
-
- data += 2;
-
- /*
- * TODO: Support MCS values 32 - 76
- *
- * The MCS values > 31 do not follow the same pattern since they use
- * unequal modulation per spatial stream. These higher MCS values
- * actually don't follow a pattern at all, since each stream can have a
- * different modulation a higher MCS value does not mean higher
- * throughput. For this reason these MCS indexes are left out.
- */
- for (i = 31; i >= 0; i--) {
- uint64_t drate;
-
- if (!test_bit(data, i))
- continue;
-
- if (!support_40mhz)
- goto check_20;
-
- if (calculate_ht_vht_data_rate(i % 8,
- HT_VHT_CHANNEL_WIDTH_40MHZ,
- rssi, (i / 8) + 1,
- short_gi_40mhz, &drate)) {
- *data_rate = drate;
- return 0;
- }
-
-check_20:
- if (!calculate_ht_vht_data_rate(i % 8,
- HT_VHT_CHANNEL_WIDTH_20MHZ,
- rssi, (i / 8) + 1,
- short_gi_20mhz, &drate))
- continue;
-
- if (!support_40mhz) {
- *data_rate = drate;
- return 0;
- }
-
- if (drate > highest_rate)
- highest_rate = drate;
- }
-
- if (!highest_rate)
- return -ENOTSUP;
-
- *data_rate = highest_rate;
-
- return 0;
-}
-
-static int ie_parse_ht_capability_from_data(const uint8_t *data, uint8_t len,
- int32_t rssi, uint64_t *data_rate)
-{
- struct ie_tlv_iter iter;
- uint8_t tag;
-
- ie_tlv_iter_init(&iter, data, len);
-
- if (!ie_tlv_iter_next(&iter))
- return -EMSGSIZE;
-
- tag = ie_tlv_iter_get_tag(&iter);
-
- if (tag != IE_TYPE_HT_CAPABILITIES)
- return -EPROTOTYPE;
-
- return ie_parse_ht_capability(&iter, rssi, data_rate);
-}
-
-/*
- * IEEE 802.11 - Table 9-250
- *
- * For simplicity, we are ignoring the Extended BSS BW support, per NOTE 11:
- *
- * NOTE 11-A receiving STA in which dot11VHTExtendedNSSCapable is false will
- * ignore the Extended NSS BW Support subfield and effectively evaluate this
- * table only at the entries where Extended NSS BW Support is 0.
- *
- * This also allows us to group the 160/80+80 widths together, since they are
- * the same when Extended NSS BW is zero.
- */
-static const uint8_t vht_width_map[3][4] = {
- [0] = { 1, 1, 1, 0 },
- [1] = { 1, 1, 1, 1 },
- [2] = { 1, 1, 1, 1 },
-};
-
-static int ie_parse_vht_capability(struct ie_tlv_iter *vht_iter,
- struct ie_tlv_iter *ht_iter, int32_t rssi,
- uint64_t *data_rate)
-{
- int width;
- int mcs;
- unsigned int nss;
- unsigned int len;
- const uint8_t *data;
- uint8_t channel_width_set;
- uint8_t rx_mcs_map[2];
- uint8_t tx_mcs_map[2];
- unsigned int max_rx_mcs = 0;
- unsigned int rx_nss = 1;
- unsigned int max_tx_mcs = 0;
- unsigned int tx_nss = 1;
- uint8_t ht_cap;
- bool short_gi_20mhz;
- bool short_gi_40mhz;
- bool short_gi_80mhz;
- bool short_gi_160mhz;
- uint64_t highest_rate = 0;
-
- /* grab the short GI bits from the HT IE */
- len = ie_tlv_iter_get_length(ht_iter);
-
- if (len != 26)
- return -EINVAL;
-
- data = ie_tlv_iter_get_data(ht_iter);
-
- ht_cap = l_get_u8(data);
-
- short_gi_20mhz = test_bit(&ht_cap, 5);
- short_gi_40mhz = test_bit(&ht_cap, 6);
-
- /* now move onto VHT */
- len = ie_tlv_iter_get_length(vht_iter);
-
- if (len != 12)
- return -EINVAL;
-
- data = ie_tlv_iter_get_data(vht_iter);
-
- channel_width_set = bit_field(*data, 2, 2);
- short_gi_80mhz = bit_field(*data, 5, 1);
- short_gi_160mhz = bit_field(*data, 6, 1);
-
- data += 4;
-
- rx_mcs_map[0] = *data++;
- rx_mcs_map[1] = *data++;
-
- data += 2;
-
- tx_mcs_map[0] = *data++;
- tx_mcs_map[1] = *data++;
-
- /* NSS->MCS map values are grouped in 2-bit values */
- for (mcs = 15; mcs >= 0; mcs -= 2) {
- uint8_t rx_val = bit_field(rx_mcs_map[mcs / 8],
- mcs % 8, 2);
- uint8_t tx_val = bit_field(tx_mcs_map[mcs / 8],
- mcs % 8, 2);
-
- /*
- * 0 indicates support for MCS 0-7
- * 1 indicates support for MCS 0-8
- * 2 indicates support for MCS 0-9
- *
- * Therefore 7 + rx/tx_val gives us our max MCS index.
- */
- if (!max_rx_mcs && rx_val < 3) {
- max_rx_mcs = 7 + rx_val;
- rx_nss = (mcs / 2) + 1;
- }
-
- if (!max_tx_mcs && tx_val < 3) {
- max_tx_mcs = 7 + tx_val;
- tx_nss = (mcs / 2) + 1;
- }
-
- if (max_rx_mcs && max_tx_mcs)
- break;
- }
-
- if (!max_rx_mcs && !max_tx_mcs)
- return -EINVAL;
-
- /*
- * Now, using channel width, MCS index, and NSS we can determine the
- * theoretical maximum data rate. We iterate through all possible
- * combinations (width, MCS, NSS), saving the highest data rate we find.
- *
- * We could calculate a maximum data rate separately for TX/RX, but
- * since this is only used for BSS ranking, the minimum between the
- * two should be good enough.
- */
- for (width = sizeof(vht_width_map[0]) - 1; width >= 0; width--) {
- bool sgi = false;
-
- if (!vht_width_map[channel_width_set][width])
- continue;
-
- /*
- * Consolidate short GI support into a single boolean, dependent
- * on the channel width for this iteration.
- */
- switch (width) {
- case HT_VHT_CHANNEL_WIDTH_20MHZ:
- sgi = short_gi_20mhz;
- break;
- case HT_VHT_CHANNEL_WIDTH_40MHZ:
- sgi = short_gi_40mhz;
- break;
- case HT_VHT_CHANNEL_WIDTH_80MHZ:
- sgi = short_gi_80mhz;
- break;
- case HT_VHT_CHANNEL_WIDTH_160MHZ:
- sgi = short_gi_160mhz;
- break;
- }
-
- for (nss = minsize(rx_nss, tx_nss); nss > 0; nss--) {
- /* NSS > 4 does not apply to 20/40MHz */
- if (width <= HT_VHT_CHANNEL_WIDTH_40MHZ && nss > 4)
- continue;
-
- for (mcs = minsize(max_rx_mcs, max_tx_mcs);
- mcs >= 0; mcs--) {
- uint64_t drate;
-
- if (!calculate_ht_vht_data_rate(mcs, width,
- rssi, nss, sgi, &drate))
- continue;
-
- if (drate > highest_rate)
- highest_rate = drate;
-
- /* Lower MCS index will only have lower rates */
- goto next_chanwidth;
- }
- }
-next_chanwidth: ; /* empty statement */
- }
-
- if (highest_rate == 0)
- return -ENOTSUP;
-
- *data_rate = highest_rate;
-
- return 0;
-}
-
-static int ie_parse_vht_capability_from_data(const uint8_t *vht_ie,
- size_t vht_len, const uint8_t *ht_ie,
- size_t ht_len, int32_t rssi,
- uint64_t *data_rate)
-{
- struct ie_tlv_iter vht_iter;
- struct ie_tlv_iter ht_iter;
- uint8_t tag;
-
- ie_tlv_iter_init(&vht_iter, vht_ie, vht_len);
-
- if (!ie_tlv_iter_next(&vht_iter))
- return -EMSGSIZE;
-
- tag = ie_tlv_iter_get_tag(&vht_iter);
-
- if (tag != IE_TYPE_VHT_CAPABILITIES)
- return -EPROTOTYPE;
-
- ie_tlv_iter_init(&ht_iter, ht_ie, ht_len);
-
- if (!ie_tlv_iter_next(&ht_iter))
- return -EMSGSIZE;
-
- tag = ie_tlv_iter_get_tag(&ht_iter);
-
- if (tag != IE_TYPE_HT_CAPABILITIES)
- return -EPROTOTYPE;
-
- return ie_parse_vht_capability(&vht_iter, &ht_iter, rssi, data_rate);
-}
-
-/*
- * Calculates the theoretical maximum data rates out of the provided
- * supported rates IE, HT IE, and VHT IE. All 3 parsing functions are allowed
- * to return -ENOTSUP, which indicates that a data rate was not found given
- * the provided data. This is not fatal, it most likely means our RSSI was too
- * low.
- */
-int ie_parse_data_rates(const uint8_t *supp_rates_ie,
- const uint8_t *ext_supp_rates_ie,
- const uint8_t *ht_ie,
- const uint8_t *vht_ie,
- int32_t rssi,
- uint64_t *data_rate)
-{
- int ret = -ENOTSUP;
- uint64_t rate = 0;
-
- /* An RSSI this low will not yield any rate results */
- if (rssi < -82)
- return -ENOTSUP;
-
- if (ht_ie && vht_ie) {
- ret = ie_parse_vht_capability_from_data(vht_ie, IE_LEN(vht_ie),
- ht_ie, IE_LEN(ht_ie),
- rssi, &rate);
- if (ret == 0)
- goto done;
- }
-
- if (ht_ie) {
- ret = ie_parse_ht_capability_from_data(ht_ie, IE_LEN(ht_ie),
- rssi, &rate);
- if (ret == 0)
- goto done;
- }
-
- if (supp_rates_ie || ext_supp_rates_ie) {
- ret = ie_parse_supported_rates_from_data(supp_rates_ie,
- IE_LEN(supp_rates_ie),
- ext_supp_rates_ie,
- IE_LEN(supp_rates_ie),
- rssi, &rate);
- if (ret == 0)
- goto done;
- }
-
- return ret;
-
-done:
- *data_rate = rate;
-
- return 0;
-}
-
int ie_parse_mobility_domain(struct ie_tlv_iter *iter, uint16_t *mdid,
bool *ft_over_ds, bool *resource_req)
{
diff --git a/src/ie.h b/src/ie.h
@@ -289,12 +289,12 @@ enum ie_rsn_akm_suite {
(akm == IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256))
#define IE_AKM_IS_FT(akm) \
- ((akm == IE_RSN_AKM_SUITE_FT_OVER_8021X) || \
- (akm == IE_RSN_AKM_SUITE_FT_USING_PSK) || \
- (akm == IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256) || \
- (akm == IE_RSN_AKM_SUITE_FT_OVER_8021X_SHA384) || \
- (akm == IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA256) || \
- (akm == IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384))
+ (akm & (IE_RSN_AKM_SUITE_FT_OVER_8021X | \
+ IE_RSN_AKM_SUITE_FT_USING_PSK | \
+ IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256 | \
+ IE_RSN_AKM_SUITE_FT_OVER_8021X_SHA384 | \
+ IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA256 | \
+ IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384))
#define IE_AKM_IS_FILS(akm) \
((akm == IE_RSN_AKM_SUITE_FILS_SHA256) || \
@@ -484,19 +484,6 @@ int ie_parse_bss_load_from_data(const uint8_t *data, uint8_t len,
uint8_t *out_channel_utilization,
uint16_t *out_admission_capacity);
-int ie_parse_supported_rates_from_data(const uint8_t *supp_rates_ie,
- uint8_t supp_rates_len,
- const uint8_t *ext_supp_rates_ie,
- uint8_t ext_supp_rates_len,
- int32_t rssi, uint64_t *data_rate);
-
-int ie_parse_data_rates(const uint8_t *supp_rates_ie,
- const uint8_t *ext_supp_rates_ie,
- const uint8_t *ht_ie,
- const uint8_t *vht_ie,
- int32_t rssi,
- uint64_t *data_rate);
-
int ie_parse_mobility_domain(struct ie_tlv_iter *iter, uint16_t *mdid,
bool *ft_over_ds, bool *resource_req);
int ie_parse_mobility_domain_from_data(const uint8_t *data, uint8_t len,
diff --git a/src/ip-pool.c b/src/ip-pool.c
@@ -0,0 +1,394 @@
+/*
+ *
+ * Wireless daemon for Linux
+ *
+ * Copyright (C) 2021 Intel Corporation. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <ell/ell.h>
+
+#include "src/util.h"
+#include "src/iwd.h"
+#include "src/module.h"
+#include "src/netdev.h"
+#include "src/ip-pool.h"
+
+struct ip_pool_addr4_record {
+ uint32_t ifindex;
+ struct l_rtnl_address *addr;
+};
+
+struct ip_pool_addr4_range {
+ uint32_t start;
+ uint32_t end;
+};
+
+static struct l_queue *used_addr4_list;
+static struct l_netlink *rtnl;
+
+static int ip_pool_addr4_range_compare(const void *a, const void *b,
+ void *user_data)
+{
+ const struct ip_pool_addr4_range *range_a = a;
+ const struct ip_pool_addr4_range *range_b = b;
+
+ return range_a->start > range_b->start ? 1 : -1;
+}
+
+/*
+ * Append any address ranges within an input start/end range which contain
+ * at least one full subnet and don't intersect with any subnets already in
+ * use. This may result in the input range being split into multiple ranges
+ * of different sizes or being skipped altogether.
+ * All inputs must be rounded to the subnet boundary and the @used queue
+ * sorted by the subnet start address.
+ */
+static void ip_pool_append_range(struct l_queue *to,
+ const struct ip_pool_addr4_range *range,
+ struct l_queue *used, const char *str)
+{
+ const struct l_queue_entry *entry = l_queue_get_entries(used);
+ const struct ip_pool_addr4_range *used_range =
+ entry ? entry->data : NULL;
+ uint32_t start = range->start;
+ bool print = true;
+
+ while (range->end > start) {
+ while (used_range && used_range->end <= start) {
+ entry = entry->next;
+ used_range = entry ? entry->data : NULL;
+ }
+
+ /* No more used ranges that intersect with @start/@range->end */
+ if (!used_range || range->end <= used_range->start) {
+ struct ip_pool_addr4_range *sub =
+ l_new(struct ip_pool_addr4_range, 1);
+
+ sub->start = start;
+ sub->end = range->end;
+ l_queue_push_tail(to, sub);
+ l_queue_insert(used, l_memdup(sub, sizeof(*sub)),
+ ip_pool_addr4_range_compare, NULL);
+ return;
+ }
+
+ if (print) {
+ l_debug("Address spec %s intersects with at least one "
+ "subnet already in use on the system or "
+ "specified in the settings", str);
+ print = false;
+ }
+
+ /* Now we know @used_range is non-NULL and intersects */
+ if (start < used_range->start) {
+ struct ip_pool_addr4_range *sub =
+ l_new(struct ip_pool_addr4_range, 1);
+
+ sub->start = start;
+ sub->end = used_range->start;
+ l_queue_push_tail(to, sub);
+ l_queue_insert(used, l_memdup(sub, sizeof(*sub)),
+ ip_pool_addr4_range_compare, NULL);
+ }
+
+ /* Skip to the start of the next subnet */
+ start = used_range->end;
+ }
+}
+
+/*
+ * Select a subnet and a host address from a defined space.
+ *
+ * Returns: 0 when an address was selected and written to *out_addr,
+ * -EEXIST if all available subnet addresses are in use,
+ * -EINVAL if there was a different error.
+ */
+int ip_pool_select_addr4(const char **addr_str_list, uint8_t subnet_prefix_len,
+ struct l_rtnl_address **out_addr)
+{
+ uint32_t total = 0;
+ uint32_t selected;
+ unsigned int i;
+ uint32_t subnet_size = 1 << (32 - subnet_prefix_len);
+ uint32_t host_mask = subnet_size - 1;
+ uint32_t subnet_mask = ~host_mask;
+ uint32_t host_addr = 0;
+ struct l_queue *ranges = l_queue_new();
+ struct l_queue *used = l_queue_new();
+ struct in_addr ia;
+ const struct l_queue_entry *entry;
+ int err = -EINVAL;
+ char ipstr[INET_ADDRSTRLEN];
+
+ if (!addr_str_list || !addr_str_list[0])
+ goto cleanup;
+
+ /* Build a sorted list of used/unavailable subnets */
+ for (entry = l_queue_get_entries(used_addr4_list);
+ entry; entry = entry->next) {
+ const struct ip_pool_addr4_record *rec = entry->data;
+ struct ip_pool_addr4_range *range;
+ char addr_str[INET_ADDRSTRLEN];
+ uint8_t used_prefix_len =
+ l_rtnl_address_get_prefix_length(rec->addr);
+ uint32_t used_subnet_size;
+
+ if (l_rtnl_address_get_family(rec->addr) != AF_INET ||
+ !l_rtnl_address_get_address(rec->addr,
+ addr_str) ||
+ used_prefix_len < 1 ||
+ inet_pton(AF_INET, addr_str, &ia) != 1)
+ continue;
+
+ used_subnet_size = 1 << (32 - used_prefix_len);
+
+ range = l_new(struct ip_pool_addr4_range, 1);
+ range->start = ntohl(ia.s_addr) & subnet_mask;
+ range->end = (range->start + used_subnet_size + subnet_size -
+ 1) & subnet_mask;
+ l_queue_insert(used, range, ip_pool_addr4_range_compare, NULL);
+ }
+
+ /* Build the list of available subnets */
+
+ /* Check for the static IP syntax: Address=<IP> */
+ if (l_strv_length((char **) addr_str_list) == 1 &&
+ inet_pton(AF_INET, *addr_str_list, &ia) == 1) {
+ struct ip_pool_addr4_range range;
+
+ host_addr = ntohl(ia.s_addr);
+ range.start = host_addr & subnet_mask;
+ range.end = range.start + subnet_size;
+ ip_pool_append_range(ranges, &range, used, *addr_str_list);
+ goto check_avail;
+ }
+
+ for (i = 0; addr_str_list[i]; i++) {
+ struct ip_pool_addr4_range range;
+ uint32_t addr;
+ uint8_t addr_prefix;
+
+ if (!util_ip_prefix_tohl(addr_str_list[i], &addr_prefix, &addr,
+ NULL, NULL)) {
+ l_error("Can't parse %s as a subnet address",
+ addr_str_list[i]);
+ goto cleanup;
+ }
+
+ if (addr_prefix > subnet_prefix_len) {
+ l_debug("Address spec %s smaller than requested "
+ "subnet (prefix len %i)", addr_str_list[i],
+ subnet_prefix_len);
+ continue;
+ }
+
+ range.start = addr & subnet_mask;
+ range.end = range.start + (1 << (32 - addr_prefix));
+ ip_pool_append_range(ranges, &range, used, addr_str_list[i]);
+ }
+
+check_avail:
+ if (l_queue_isempty(ranges)) {
+ l_error("No IP subnets available for new Access Point after "
+ "eliminating those already in use on the system");
+ err = -EEXIST;
+ goto cleanup;
+ }
+
+ if (host_addr)
+ goto done;
+
+ /* Count available @subnet_prefix_len-sized subnets */
+ for (entry = l_queue_get_entries(ranges); entry; entry = entry->next) {
+ struct ip_pool_addr4_range *range = entry->data;
+
+ total += (range->end - range->start) >>
+ (32 - subnet_prefix_len);
+ }
+
+ selected = l_getrandom_uint32() % total;
+
+ /* Find the @selected'th @subnet_prefix_len-sized subnet */
+ for (entry = l_queue_get_entries(ranges);; entry = entry->next) {
+ struct ip_pool_addr4_range *range = entry->data;
+ uint32_t count = (range->end - range->start) >>
+ (32 - subnet_prefix_len);
+
+ if (selected < count) {
+ host_addr = range->start +
+ (selected << (32 - subnet_prefix_len));
+ break;
+ }
+
+ selected -= count;
+ }
+
+ if ((host_addr & host_mask) == 0)
+ host_addr += 1;
+
+done:
+ err = 0;
+ ia.s_addr = htonl(host_addr);
+ if (L_WARN_ON(!inet_ntop(AF_INET, &ia, ipstr, INET_ADDRSTRLEN)))
+ err = -errno;
+ else
+ *out_addr = l_rtnl_address_new(ipstr, subnet_prefix_len);
+
+cleanup:
+ l_queue_destroy(ranges, l_free);
+ l_queue_destroy(used, l_free);
+ return err;
+}
+
+static void ip_pool_addr4_record_free(void *data)
+{
+ struct ip_pool_addr4_record *rec = data;
+
+ l_rtnl_address_free(rec->addr);
+ l_free(rec);
+}
+
+static bool ip_pool_addr4_match_ifindex(const void *a, const void *b)
+{
+ const struct ip_pool_addr4_record *addr = a;
+
+ return addr->ifindex == L_PTR_TO_UINT(b);
+}
+
+struct l_rtnl_address *ip_pool_get_addr4(uint32_t ifindex)
+{
+ const struct ip_pool_addr4_record *rec =
+ l_queue_find(used_addr4_list, ip_pool_addr4_match_ifindex,
+ L_UINT_TO_PTR(ifindex));
+
+ return rec ? l_rtnl_address_clone(rec->addr) : 0;
+}
+
+static bool ip_pool_addr4_match_free(void *data, void *user_data)
+{
+ const struct ip_pool_addr4_record *a = data;
+ const struct ip_pool_addr4_record *b = user_data;
+ char a_addr_str[INET_ADDRSTRLEN];
+ char b_addr_str[INET_ADDRSTRLEN];
+
+ if (a->ifindex != b->ifindex ||
+ l_rtnl_address_get_prefix_length(a->addr) !=
+ l_rtnl_address_get_prefix_length(b->addr))
+ return false;
+
+ if (!l_rtnl_address_get_address(a->addr, a_addr_str) ||
+ !l_rtnl_address_get_address(b->addr, b_addr_str) ||
+ strcmp(a_addr_str, b_addr_str))
+ return false;
+
+ ip_pool_addr4_record_free(data);
+ return true;
+}
+
+static void ip_pool_addr_notify(uint16_t type, const void *data, uint32_t len,
+ void *user_data)
+{
+ const struct ifaddrmsg *ifa = data;
+ struct l_rtnl_address *addr;
+
+ if (ifa->ifa_family != AF_INET || ifa->ifa_prefixlen < 1)
+ return;
+
+ len -= NLMSG_ALIGN(sizeof(struct ifaddrmsg));
+
+ addr = l_rtnl_ifaddr_extract(ifa, len);
+ if (!addr)
+ return;
+
+ if (type == RTM_NEWADDR) {
+ struct ip_pool_addr4_record *rec;
+
+ rec = l_new(struct ip_pool_addr4_record, 1);
+ rec->ifindex = ifa->ifa_index;
+ rec->addr = l_steal_ptr(addr);
+ l_queue_push_tail(used_addr4_list, rec);
+ } else if (type == RTM_DELADDR) {
+ struct ip_pool_addr4_record rec;
+
+ rec.ifindex = ifa->ifa_index;
+ rec.addr = addr;
+
+ l_queue_foreach_remove(used_addr4_list,
+ ip_pool_addr4_match_free, &rec);
+ }
+
+ l_rtnl_address_free(addr);
+}
+
+static void ip_pool_addr4_dump_cb(int error,
+ uint16_t type, const void *data,
+ uint32_t len, void *user_data)
+{
+ if (error) {
+ l_error("addr4_dump_cb: %s (%i)", strerror(-error), -error);
+ return;
+ }
+
+ ip_pool_addr_notify(type, data, len, user_data);
+}
+
+static int ip_pool_init(void)
+{
+ const struct l_settings *settings = iwd_get_config();
+ bool netconfig_enabled;
+
+ if (!l_settings_get_bool(settings, "General",
+ "EnableNetworkConfiguration",
+ &netconfig_enabled))
+ netconfig_enabled = false;
+
+ if (!netconfig_enabled)
+ return 0;
+
+ rtnl = iwd_get_rtnl();
+
+ if (!l_netlink_register(rtnl, RTNLGRP_IPV4_IFADDR,
+ ip_pool_addr_notify, NULL, NULL)) {
+ l_error("Failed to register for RTNL link notifications");
+ return -EIO;
+ }
+
+ if (!l_rtnl_ifaddr4_dump(rtnl, ip_pool_addr4_dump_cb, NULL, NULL)) {
+ l_error("Sending the IPv4 addr dump req failed");
+ return -EIO;
+ }
+
+ used_addr4_list = l_queue_new();
+ return 0;
+}
+
+static void ip_pool_exit(void)
+{
+ l_queue_destroy(used_addr4_list, ip_pool_addr4_record_free);
+ used_addr4_list = NULL;
+}
+
+IWD_MODULE(ip_pool, ip_pool_init, ip_pool_exit)
diff --git a/src/ip-pool.h b/src/ip-pool.h
@@ -0,0 +1,25 @@
+/*
+ *
+ * Wireless daemon for Linux
+ *
+ * Copyright (C) 2021 Intel Corporation. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+int ip_pool_select_addr4(const char **addr_str_list, uint8_t subnet_prefix_len,
+ struct l_rtnl_address **out_addr);
+struct l_rtnl_address *ip_pool_get_addr4(uint32_t ifindex);
diff --git a/src/iwd.ap.rst b/src/iwd.ap.rst
@@ -104,14 +104,31 @@ is desired, the group header line must still be present:
:widths: 20 80
* - Address
- - Local IP address
+ - Local IP address or a comma-separated list of prefix-notation addresses
Optional local address pool for the access point and the DHCP server.
- If provided this addresss will be set on the AP interface and any other
- DHCP server options will be derived from it, unless they are overridden
- by other settings below. If *Address* is not provided and no IP
- address is set on the interface prior to calling `StartProfile`, the IP
- pool defined by the global ``[General].APRanges`` setting will be used.
+ If a single address is provided this address will be set on the AP
+ interface and any other DHCP server options will be derived from it
+ if not overridden by other settings below.
+
+ If a list of addresses and prefix lengths is specified (in the
+ `<IP>/<prefix-len>` format), a single subnet address will be selected
+ from the available space each time this profile is started. The subnet
+ size is based on the ``[IPv4].Netmask`` setting.
+
+ If *Address* is not provided and no IP address is set on the
+ interface prior to calling `StartProfile` the value of the main.conf
+ ``[IPv4].APAddressPool`` setting will be inherited, which in turn
+ defaults to 192.168.0.0/16.
+
+ For example, if ``[IPv4].Netmask`` is set to 255.255.255.0 and this
+ setting, or the global *APAddressPool* fallback, is set to
+ ``192.168.0.0/16, 10.0.0.0/22``, IWD will select one of the 256 subnets
+ with addresses in the 192.168.<0-255>.0/24 range or one of the 4 subnets
+ with addresses in the 10.0.<0-3>.0/24 range, allowing 270 possible
+ subnets. Defining an address pool larger than the desired subnet gives
+ IWD a chance to avoid conflicts if other interfaces on the system use
+ dynamically assigned addresses.
* - Gateway
- IP Address of gateway
@@ -122,7 +139,7 @@ is desired, the group header line must still be present:
* - Netmask
- Local netmask of the AP
- This will be generated from ``[IPv4].Address`` if not provided.
+ Defaults to a 28-bit netmask if not provided.
* - DNSList
- List of DNS servers as a comma-separated IP address list
diff --git a/src/iwd.config.rst b/src/iwd.config.rst
@@ -67,8 +67,8 @@ The group ``[General]`` contains general settings.
obtain the dynamic addresses from the network through the built-in
DHCP client.
- This also enables DHCP server when in AP mode when either
- [General].APRanges is set or an AP profile is being used.
+ This also enables network configuration and the DHCP server when in AP
+ mode and the AP profile being activated does not override it.
The network configuration feature is disabled by default. See
``[Network]`` settings for additional settings related to network
@@ -131,7 +131,14 @@ The group ``[General]`` contains general settings.
* - RoamThreshold
- Value: rssi dBm value, from -100 to 1, default: **-70**
- This can be used to control how aggressively **iwd** roams.
+ This value can be used to control how aggressively **iwd** roams when
+ connected to a 2.4Ghz access point.
+
+ * - RoamThreshold5G
+ - Value: rssi dBm value, from -100 to 1, default: **-76**
+
+ This value can be used to control how aggressively **iwd** roams when
+ connected to a 5GHz access point.
* - RoamRetryInterval
- Value: unsigned int value in seconds (default: **60**)
@@ -175,7 +182,7 @@ The group ``[General]`` contains general settings.
then setting ``DisableANQP`` to ``false`` is recommended.
Network
----------
+-------
The group ``[Network]`` contains network configuration related settings.
@@ -312,6 +319,29 @@ No modification from defaults is normally required.
prevent **iwd** from roaming properly, but can be useful for networks
operating under extremely low rssi levels where roaming isn't possible.
+IPv4
+----
+
+The group ``[IPv4]`` contains settings related to IPv4 network configuration.
+
+.. list-table::
+ :header-rows: 0
+ :stub-columns: 0
+ :widths: 20 80
+ :align: left
+
+ * - APAddressPool
+ - Values: comma-separated list of prefix-notation IP strings
+
+ Defines the space of IPs used for the Access Point-mode subnet addresses
+ and the DHCP server. Defaults to 192.168.0.0/16. The prefix length
+ decides the size of the pool from which an address is selected but the
+ actual subnet size (netmask) is based on the AP profile being activated
+ and defaults to 28 bits. The AP profile's ``[IPv4].Address`` setting
+ overrides the global value set here. Setting a too small address space
+ will limit the number of access points that can be running
+ simultaneously on different interfaces.
+
SEE ALSO
========
diff --git a/src/iwd.h b/src/iwd.h
@@ -41,3 +41,4 @@ const char *iwd_get_iface_blacklist(void);
const char *iwd_get_phy_whitelist(void);
const char *iwd_get_phy_blacklist(void);
+bool iwd_is_developer_mode(void);
diff --git a/src/knownnetworks.c b/src/knownnetworks.c
@@ -382,17 +382,10 @@ void known_network_update(struct network_info *network,
network->is_hidden = is_hidden;
+ /* If no entry, default to AutoConnectable=True */
if (!l_settings_get_bool(settings, "Settings", "AutoConnect",
- &is_autoconnectable)) {
- /* If no entry, default to AutoConnectable=True */
- is_autoconnectable = true;
-
- /* Try legacy property name just in case */
- if (l_settings_get_bool(settings, "Settings", "Autoconnect",
&is_autoconnectable))
- l_warn("Autoconnect setting is deprecated, use"
- " AutoConnect instead");
- }
+ is_autoconnectable = true;
known_network_set_autoconnect(network, is_autoconnectable);
}
@@ -705,16 +698,9 @@ static void known_network_new(const char *ssid, enum security security,
is_hidden = false;
if (!l_settings_get_bool(settings, "Settings", "AutoConnect",
- &is_autoconnectable)) {
+ &is_autoconnectable))
is_autoconnectable = true;
- /* Try legacy property name just in case */
- if (l_settings_get_bool(settings, "Settings", "Autoconnect",
- &is_autoconnectable))
- l_warn("Autoconnect setting is deprecated, use"
- " AutoConnect instead");
- }
-
if (is_hidden)
num_known_hidden_networks++;
diff --git a/src/main.c b/src/main.c
@@ -54,6 +54,7 @@ static const char *nointerfaces;
static const char *phys;
static const char *nophys;
static const char *debugopt;
+static bool developeropt;
static bool terminating;
static bool nl80211_complete;
@@ -128,13 +129,18 @@ const char *iwd_get_phy_blacklist(void)
return nophys;
}
+bool iwd_is_developer_mode(void)
+{
+ return developeropt;
+}
+
static void usage(void)
{
printf("iwd - Wireless daemon\n"
"Usage:\n");
printf("\tiwd [options]\n");
printf("Options:\n"
- "\t-B, --dbus-debug Enable D-Bus debugging\n"
+ "\t-E, --developer Enable developer mode\n"
"\t-i, --interfaces Interfaces to manage\n"
"\t-I, --nointerfaces Interfaces to ignore\n"
"\t-p, --phys Phys to manage\n"
@@ -145,7 +151,7 @@ static void usage(void)
}
static const struct option main_options[] = {
- { "dbus-debug", no_argument, NULL, 'B' },
+ { "developer", no_argument, NULL, 'E' },
{ "version", no_argument, NULL, 'v' },
{ "interfaces", required_argument, NULL, 'i' },
{ "nointerfaces", required_argument, NULL, 'I' },
@@ -188,6 +194,16 @@ static void request_name_callback(struct l_dbus *dbus, bool success,
if (!l_dbus_object_manager_enable(dbus, "/"))
l_warn("Unable to register the ObjectManager");
+ if (!l_dbus_object_add_interface(dbus, IWD_BASE_PATH,
+ IWD_DAEMON_INTERFACE,
+ NULL) ||
+ !l_dbus_object_add_interface(dbus, IWD_BASE_PATH,
+ L_DBUS_INTERFACE_PROPERTIES,
+ NULL))
+ l_info("Unable to add %s and/or %s at %s",
+ IWD_DAEMON_INTERFACE, L_DBUS_INTERFACE_PROPERTIES,
+ IWD_BASE_PATH);
+
/* TODO: Always request nl80211 for now, ignoring auto-loading */
l_genl_request_family(genl, NL80211_GENL_NAME, nl80211_appeared,
NULL, NULL);
@@ -197,12 +213,52 @@ fail_exit:
l_main_quit();
}
+static struct l_dbus_message *iwd_dbus_get_info(struct l_dbus *dbus,
+ struct l_dbus_message *message,
+ void *user_data)
+{
+ struct l_dbus_message *reply;
+ struct l_dbus_message_builder *builder;
+ L_AUTO_FREE_VAR(char *, storage_dir) = storage_get_path(NULL);
+ bool netconfig_enabled;
+
+ if (!l_settings_get_bool(iwd_config, "General",
+ "EnableNetworkConfiguration",
+ &netconfig_enabled))
+ netconfig_enabled = false;
+
+ reply = l_dbus_message_new_method_return(message);
+ builder = l_dbus_message_builder_new(reply);
+ l_dbus_message_builder_enter_array(builder, "{sv}");
+
+ dbus_append_dict_basic(builder, "NetworkConfigurationEnabled", 'b',
+ &netconfig_enabled);
+ dbus_append_dict_basic(builder, "StateDirectory", 's', storage_dir);
+ dbus_append_dict_basic(builder, "Version", 's', VERSION);
+
+ l_dbus_message_builder_leave_array(builder);
+ l_dbus_message_builder_finalize(builder);
+ l_dbus_message_builder_destroy(builder);
+
+ return reply;
+}
+
+static void iwd_setup_deamon_interface(struct l_dbus_interface *interface)
+{
+ l_dbus_interface_method(interface, "GetInfo", 0, iwd_dbus_get_info,
+ "a{sv}", "", "info");
+}
+
static void dbus_ready(void *user_data)
{
struct l_dbus *dbus = user_data;
l_dbus_name_acquire(dbus, "net.connman.iwd", false, false, false,
request_name_callback, NULL);
+
+ l_dbus_register_interface(dbus, IWD_DAEMON_INTERFACE,
+ iwd_setup_deamon_interface,
+ NULL, false);
}
static void dbus_disconnected(void *user_data)
@@ -357,7 +413,6 @@ done:
int main(int argc, char *argv[])
{
- bool enable_dbus_debug = false;
int exit_status;
struct l_dbus *dbus;
const char *config_dir;
@@ -367,14 +422,14 @@ int main(int argc, char *argv[])
for (;;) {
int opt;
- opt = getopt_long(argc, argv, "Bi:I:p:P:d::vh",
+ opt = getopt_long(argc, argv, "Ei:I:p:P:d::vh",
main_options, NULL);
if (opt < 0)
break;
switch (opt) {
- case 'B':
- enable_dbus_debug = true;
+ case 'E':
+ developeropt = true;
break;
case 'i':
interfaces = optarg;
@@ -485,9 +540,6 @@ int main(int argc, char *argv[])
goto failed_dbus;
}
- if (enable_dbus_debug)
- l_dbus_set_debug(dbus, do_debug, "[DBUS] ", NULL);
-
l_dbus_set_ready_handler(dbus, dbus_ready, dbus, NULL);
l_dbus_set_disconnect_handler(dbus, dbus_disconnected, NULL, NULL);
dbus_init(dbus);
diff --git a/src/manager.c b/src/manager.c
@@ -847,14 +847,8 @@ static int manager_init(void)
}
if (!l_settings_get_bool(config, "General",
- "UseDefaultInterface", &use_default)) {
- if (!l_settings_get_bool(config, "General",
- "use_default_interface", &use_default))
- use_default = false;
- else
- l_warn("[General].use_default_interface is deprecated"
- ", please use UseDefaultInterface");
- }
+ "UseDefaultInterface", &use_default))
+ use_default = false;
return 0;
diff --git a/src/netconfig.c b/src/netconfig.c
@@ -68,6 +68,8 @@ struct netconfig {
struct l_acd *acd;
+ uint32_t addr4_add_cmd_id;
+ uint32_t addr6_add_cmd_id;
uint32_t route4_add_gateway_cmd_id;
};
@@ -623,8 +625,8 @@ static bool netconfig_ipv4_routes_install(struct netconfig *netconfig)
{
L_AUTO_FREE_VAR(char *, gateway) = NULL;
struct in_addr in_addr;
- char *network;
char ip[INET_ADDRSTRLEN];
+ char network[INET_ADDRSTRLEN];
unsigned int prefix_len =
l_rtnl_address_get_prefix_length(netconfig->v4_address);
@@ -635,8 +637,7 @@ static bool netconfig_ipv4_routes_install(struct netconfig *netconfig)
in_addr.s_addr = in_addr.s_addr &
htonl(0xFFFFFFFFLU << (32 - prefix_len));
- network = inet_ntoa(in_addr);
- if (!network)
+ if (!inet_ntop(AF_INET, &in_addr, network, INET_ADDRSTRLEN))
return false;
if (!l_rtnl_route4_add_connected(rtnl, netconfig->ifindex,
@@ -651,11 +652,17 @@ static bool netconfig_ipv4_routes_install(struct netconfig *netconfig)
gateway = netconfig_ipv4_get_gateway(netconfig);
if (!gateway) {
- l_error("netconfig: Failed to obtain gateway from %s.",
+ l_debug("No gateway obtained from %s.",
netconfig->rtm_protocol == RTPROT_STATIC ?
"setting file" : "DHCPv4 lease");
- return false;
+ if (netconfig->notify) {
+ netconfig->notify(NETCONFIG_EVENT_CONNECTED,
+ netconfig->user_data);
+ netconfig->notify = NULL;
+ }
+
+ return true;
}
netconfig->route4_add_gateway_cmd_id =
@@ -680,6 +687,8 @@ static void netconfig_ipv4_ifaddr_add_cmd_cb(int error, uint16_t type,
{
struct netconfig *netconfig = user_data;
+ netconfig->addr4_add_cmd_id = 0;
+
if (error && error != -EEXIST) {
l_error("netconfig: Failed to add IP address. "
"Error %d: %s", error, strerror(-error));
@@ -702,6 +711,8 @@ static void netconfig_ipv6_ifaddr_add_cmd_cb(int error, uint16_t type,
struct netconfig *netconfig = user_data;
struct l_rtnl_route *gateway;
+ netconfig->addr6_add_cmd_id = 0;
+
if (error && error != -EEXIST) {
l_error("netconfig: Failed to add IPv6 address. "
"Error %d: %s", error, strerror(-error));
@@ -765,10 +776,11 @@ static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client,
return;
}
- L_WARN_ON(!l_rtnl_ifaddr_add(rtnl, netconfig->ifindex,
+ L_WARN_ON(!(netconfig->addr4_add_cmd_id =
+ l_rtnl_ifaddr_add(rtnl, netconfig->ifindex,
netconfig->v4_address,
netconfig_ipv4_ifaddr_add_cmd_cb,
- netconfig, NULL));
+ netconfig, NULL)));
break;
case L_DHCP_CLIENT_EVENT_LEASE_RENEWED:
break;
@@ -824,24 +836,32 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client,
}
}
+static void netconfig_remove_v4_address(struct netconfig *netconfig)
+{
+ if (!netconfig->v4_address)
+ return;
+
+ L_WARN_ON(!l_rtnl_ifaddr_delete(rtnl, netconfig->ifindex,
+ netconfig->v4_address,
+ netconfig_ifaddr_del_cmd_cb,
+ netconfig, NULL));
+ l_rtnl_address_free(netconfig->v4_address);
+ netconfig->v4_address = NULL;
+}
+
static void netconfig_reset_v4(struct netconfig *netconfig)
{
if (netconfig->rtm_protocol) {
- if (netconfig->v4_address) {
- L_WARN_ON(!l_rtnl_ifaddr_delete(rtnl,
- netconfig->ifindex,
- netconfig->v4_address,
- netconfig_ifaddr_del_cmd_cb,
- netconfig, NULL));
- l_rtnl_address_free(netconfig->v4_address);
- netconfig->v4_address = NULL;
- }
+ netconfig_remove_v4_address(netconfig);
l_strfreev(netconfig->dns4_overrides);
netconfig->dns4_overrides = NULL;
l_dhcp_client_stop(netconfig->dhcp_client);
netconfig->rtm_protocol = 0;
+
+ l_acd_destroy(netconfig->acd);
+ netconfig->acd = NULL;
}
}
@@ -851,10 +871,11 @@ static void netconfig_ipv4_acd_event(enum l_acd_event event, void *user_data)
switch (event) {
case L_ACD_EVENT_AVAILABLE:
- L_WARN_ON(!l_rtnl_ifaddr_add(rtnl, netconfig->ifindex,
+ L_WARN_ON(!(netconfig->addr4_add_cmd_id =
+ l_rtnl_ifaddr_add(rtnl, netconfig->ifindex,
netconfig->v4_address,
netconfig_ipv4_ifaddr_add_cmd_cb,
- netconfig, NULL));
+ netconfig, NULL)));
return;
case L_ACD_EVENT_CONFLICT:
/*
@@ -872,17 +893,18 @@ static void netconfig_ipv4_acd_event(enum l_acd_event event, void *user_data)
* case.
*/
l_error("netconfig: statically configured address was lost");
- netconfig_reset_v4(netconfig);
+ netconfig_remove_v4_address(netconfig);
break;
}
}
static void netconfig_ipv4_select_and_install(struct netconfig *netconfig)
{
- netconfig->v4_address = netconfig_get_static4_address(netconfig);
- if (netconfig->v4_address) {
- char ip[INET6_ADDRSTRLEN];
+ char ip[INET6_ADDRSTRLEN];
+ netconfig->v4_address = netconfig_get_static4_address(netconfig);
+ if (netconfig->v4_address &&
+ l_rtnl_address_get_address(netconfig->v4_address, ip)) {
netconfig->rtm_protocol = RTPROT_STATIC;
netconfig->acd = l_acd_new(netconfig->ifindex);
l_acd_set_event_handler(netconfig->acd,
@@ -892,17 +914,16 @@ static void netconfig_ipv4_select_and_install(struct netconfig *netconfig)
l_acd_set_debug(netconfig->acd, do_debug,
"[ACD] ", NULL);
- l_rtnl_address_get_address(netconfig->v4_address, ip);
-
if (!l_acd_start(netconfig->acd, ip)) {
l_error("failed to start ACD, continuing anyways");
l_acd_destroy(netconfig->acd);
netconfig->acd = NULL;
- L_WARN_ON(!l_rtnl_ifaddr_add(rtnl, netconfig->ifindex,
+ L_WARN_ON(!(netconfig->addr4_add_cmd_id =
+ l_rtnl_ifaddr_add(rtnl, netconfig->ifindex,
netconfig->v4_address,
netconfig_ipv4_ifaddr_add_cmd_cb,
- netconfig, NULL));
+ netconfig, NULL)));
}
return;
@@ -937,9 +958,10 @@ static void netconfig_ipv6_select_and_install(struct netconfig *netconfig)
address = netconfig_get_static6_address(netconfig);
if (address) {
netconfig->rtm_v6_protocol = RTPROT_STATIC;
- L_WARN_ON(!l_rtnl_ifaddr_add(rtnl, netconfig->ifindex, address,
+ L_WARN_ON(!(netconfig->addr6_add_cmd_id =
+ l_rtnl_ifaddr_add(rtnl, netconfig->ifindex, address,
netconfig_ipv6_ifaddr_add_cmd_cb,
- netconfig, NULL));
+ netconfig, NULL)));
l_rtnl_address_free(address);
return;
}
@@ -1056,6 +1078,16 @@ bool netconfig_reset(struct netconfig *netconfig)
netconfig->route4_add_gateway_cmd_id = 0;
}
+ if (netconfig->addr4_add_cmd_id) {
+ l_netlink_cancel(rtnl, netconfig->addr4_add_cmd_id);
+ netconfig->addr4_add_cmd_id = 0;
+ }
+
+ if (netconfig->addr6_add_cmd_id) {
+ l_netlink_cancel(rtnl, netconfig->addr6_add_cmd_id);
+ netconfig->addr6_add_cmd_id = 0;
+ }
+
if (netconfig->rtm_protocol || netconfig->rtm_v6_protocol)
resolve_revert(netconfig->resolve);
diff --git a/src/netdev.c b/src/netdev.c
@@ -95,9 +95,6 @@ struct netdev_handshake_state {
struct netdev_ft_over_ds_info {
struct ft_ds_info super;
struct netdev *netdev;
- struct l_timeout *timeout;
- netdev_ft_over_ds_cb_t cb;
- void *user_data;
bool parsed : 1;
};
@@ -169,7 +166,7 @@ struct netdev {
struct l_genl_msg *auth_cmd;
struct wiphy_radio_work_item work;
- struct netdev_ft_over_ds_info *ft_ds_info;
+ struct l_queue *ft_ds_list;
bool connected : 1;
bool associated : 1;
@@ -687,6 +684,13 @@ static void netdev_preauth_destroy(void *data)
l_free(state);
}
+static void netdev_ft_ds_entry_free(void *data)
+{
+ struct netdev_ft_over_ds_info *info = data;
+
+ ft_ds_info_free(&info->super);
+}
+
static void netdev_connect_free(struct netdev *netdev)
{
if (netdev->work.id)
@@ -754,8 +758,10 @@ static void netdev_connect_free(struct netdev *netdev)
netdev->disconnect_cmd_id = 0;
}
- if (netdev->ft_ds_info)
- ft_ds_info_free(&netdev->ft_ds_info->super);
+ if (netdev->ft_ds_list) {
+ l_queue_destroy(netdev->ft_ds_list, netdev_ft_ds_entry_free);
+ netdev->ft_ds_list = NULL;
+ }
}
static void netdev_connect_failed(struct netdev *netdev,
@@ -771,10 +777,15 @@ static void netdev_connect_failed(struct netdev *netdev,
if (connect_cb)
connect_cb(netdev, result, &status_or_reason, connect_data);
- else if (event_filter)
+ else if (event_filter) {
+ /* NETDEV_EVENT_DISCONNECT_BY_SME expects a reason code */
+ if (result != NETDEV_RESULT_HANDSHAKE_FAILED)
+ status_or_reason = MMPDU_REASON_CODE_UNSPECIFIED;
+
event_filter(netdev, NETDEV_EVENT_DISCONNECT_BY_SME,
&status_or_reason,
connect_data);
+ }
}
static void netdev_disconnect_cb(struct l_genl_msg *msg, void *user_data)
@@ -791,6 +802,12 @@ static void netdev_free(void *data)
l_debug("Freeing netdev %s[%d]", netdev->name, netdev->index);
+ netdev->ifi_flags &= ~IFF_UP;
+
+ if (netdev->events_ready)
+ WATCHLIST_NOTIFY(&netdev_watches, netdev_watch_func_t,
+ netdev, NETDEV_WATCH_EVENT_DEL);
+
if (netdev->neighbor_report_cb) {
netdev->neighbor_report_cb(netdev, -ENODEV, NULL, 0,
netdev->user_data);
@@ -798,9 +815,10 @@ static void netdev_free(void *data)
l_timeout_remove(netdev->neighbor_report_timeout);
}
- if (netdev->connected)
+ if (netdev->connected || netdev->connect_cmd_id || netdev->work.id)
netdev_connect_free(netdev);
- else if (netdev->disconnect_cmd_id) {
+
+ if (netdev->disconnect_cmd_id) {
l_genl_family_cancel(nl80211, netdev->disconnect_cmd_id);
netdev->disconnect_cmd_id = 0;
@@ -811,6 +829,11 @@ static void netdev_free(void *data)
netdev->user_data = NULL;
}
+ if (netdev->disconnect_idle) {
+ l_idle_remove(netdev->disconnect_idle);
+ netdev->disconnect_idle = NULL;
+ }
+
if (netdev->join_adhoc_cmd_id) {
l_genl_family_cancel(nl80211, netdev->join_adhoc_cmd_id);
netdev->join_adhoc_cmd_id = 0;
@@ -849,15 +872,11 @@ static void netdev_free(void *data)
if (netdev->fw_roam_bss)
scan_bss_free(netdev->fw_roam_bss);
- if (netdev->disconnect_idle) {
- l_idle_remove(netdev->disconnect_idle);
- netdev->disconnect_idle = NULL;
+ if (netdev->ft_ds_list) {
+ l_queue_destroy(netdev->ft_ds_list, netdev_ft_ds_entry_free);
+ netdev->ft_ds_list = NULL;
}
- if (netdev->events_ready)
- WATCHLIST_NOTIFY(&netdev_watches, netdev_watch_func_t,
- netdev, NETDEV_WATCH_EVENT_DEL);
-
scan_wdev_remove(netdev->wdev_id);
watchlist_destroy(&netdev->station_watches);
@@ -891,6 +910,7 @@ struct netdev *netdev_find(int ifindex)
/* Threshold RSSI for roaming to trigger, configurable in main.conf */
static int LOW_SIGNAL_THRESHOLD;
+static int LOW_SIGNAL_THRESHOLD_5GHZ;
static void netdev_cqm_event_rssi_threshold(struct netdev *netdev,
uint32_t rssi_event)
@@ -925,6 +945,8 @@ static void netdev_cqm_event_rssi_value(struct netdev *netdev, int rssi_val)
{
bool new_rssi_low;
uint8_t prev_rssi_level_idx = netdev->cur_rssi_level_idx;
+ int threshold = netdev->frequency > 4000 ? LOW_SIGNAL_THRESHOLD_5GHZ :
+ LOW_SIGNAL_THRESHOLD;
if (!netdev->connected)
return;
@@ -939,7 +961,7 @@ static void netdev_cqm_event_rssi_value(struct netdev *netdev, int rssi_val)
if (!netdev->event_filter)
return;
- new_rssi_low = rssi_val < LOW_SIGNAL_THRESHOLD;
+ new_rssi_low = rssi_val < threshold;
if (netdev->cur_rssi_low != new_rssi_low) {
int event = new_rssi_low ?
NETDEV_EVENT_RSSI_THRESHOLD_LOW :
@@ -1283,6 +1305,11 @@ static void netdev_connect_ok(struct netdev *netdev)
netdev->fw_roam_bss = NULL;
}
+ if (netdev->ft_ds_list) {
+ l_queue_destroy(netdev->ft_ds_list, netdev_ft_ds_entry_free);
+ netdev->ft_ds_list = NULL;
+ }
+
if (netdev->connect_cb) {
netdev->connect_cb(netdev, NETDEV_RESULT_OK, NULL,
netdev->user_data);
@@ -3268,6 +3295,9 @@ int netdev_connect(struct netdev *netdev, struct scan_bss *bss,
struct eapol_sm *sm = NULL;
bool is_rsn = hs->supplicant_ie != NULL;
+ if (!(netdev->ifi_flags & IFF_UP))
+ return -ENETDOWN;
+
if (netdev->type != NL80211_IFTYPE_STATION &&
netdev->type != NL80211_IFTYPE_P2P_CLIENT)
return -ENOTSUP;
@@ -3342,6 +3372,9 @@ int netdev_disconnect(struct netdev *netdev,
struct l_genl_msg *disconnect;
bool send_disconnect = true;
+ if (!(netdev->ifi_flags & IFF_UP))
+ return -ENETDOWN;
+
if (netdev->type != NL80211_IFTYPE_STATION &&
netdev->type != NL80211_IFTYPE_P2P_CLIENT)
return -ENOTSUP;
@@ -3439,12 +3472,6 @@ int netdev_reassociate(struct netdev *netdev, struct scan_bss *target_bss,
if (err < 0)
return err;
- /* In case of a previous failed over-DS attempt */
- if (netdev->ft_ds_info) {
- ft_ds_info_free(&netdev->ft_ds_info->super);
- netdev->ft_ds_info = NULL;
- }
-
memcpy(netdev->prev_bssid, orig_bss->addr, ETH_ALEN);
netdev->associated = false;
@@ -3673,12 +3700,6 @@ static int netdev_ft_tx_associate(struct iovec *ie_iov, size_t iov_len,
return -EIO;
}
- /* No need to keep this around at this point */
- if (netdev->ft_ds_info) {
- ft_ds_info_free(&netdev->ft_ds_info->super);
- netdev->ft_ds_info = NULL;
- }
-
return 0;
}
@@ -3750,12 +3771,26 @@ static void prepare_ft(struct netdev *netdev, struct scan_bss *target_bss)
static void netdev_ft_over_ds_auth_failed(struct netdev_ft_over_ds_info *info,
uint16_t status)
{
- if (info->cb)
- info->cb(info->netdev, status, info->super.aa, info->user_data);
-
+ l_queue_remove(info->netdev->ft_ds_list, info);
ft_ds_info_free(&info->super);
+}
+
+struct ft_ds_finder {
+ const uint8_t *spa;
+ const uint8_t *aa;
+};
- info->netdev->ft_ds_info = NULL;
+static bool match_ft_ds_info(const void *a, const void *b)
+{
+ const struct netdev_ft_over_ds_info *info = a;
+ const struct ft_ds_finder *finder = b;
+
+ if (memcmp(info->super.spa, finder->spa, 6))
+ return false;
+ if (memcmp(info->super.aa, finder->aa, 6))
+ return false;
+
+ return true;
}
static void netdev_ft_response_frame_event(const struct mmpdu_header *hdr,
@@ -3763,36 +3798,45 @@ static void netdev_ft_response_frame_event(const struct mmpdu_header *hdr,
int rssi, void *user_data)
{
struct netdev *netdev = user_data;
- struct netdev_ft_over_ds_info *info = netdev->ft_ds_info;
+ struct netdev_ft_over_ds_info *info;
int ret;
uint16_t status_code = MMPDU_STATUS_CODE_UNSPECIFIED;
-
- if (!info)
- return;
-
- ret = ft_over_ds_parse_action_response(&info->super, netdev->handshake,
- body, body_len);
+ const uint8_t *aa;
+ const uint8_t *spa;
+ const uint8_t *ies;
+ size_t ies_len;
+ struct ft_ds_finder finder;
+
+ ret = ft_over_ds_parse_action_response(body, body_len, &spa, &aa,
+ &ies, &ies_len);
if (ret < 0)
return;
- l_timeout_remove(info->timeout);
- info->timeout = NULL;
+ finder.spa = spa;
+ finder.aa = aa;
- /* Now make sure the packet contained a success status code */
+ info = l_queue_find(netdev->ft_ds_list, match_ft_ds_info, &finder);
+ if (!info)
+ return;
+
+ /* Lookup successful, now check the status code */
if (ret > 0) {
status_code = (uint16_t)ret;
goto ft_error;
}
- info->parsed = true;
+ ret = ft_over_ds_parse_action_ies(&info->super, netdev->handshake,
+ ies, ies_len);
+ if (ret < 0)
+ goto ft_error;
- if (info->cb)
- info->cb(netdev, 0, info->super.aa, info->user_data);
+ info->parsed = true;
return;
ft_error:
- l_debug("FT-over-DS to "MAC" failed", MAC_STR(info->super.aa));
+ l_debug("FT-over-DS to "MAC" failed (%d)", MAC_STR(info->super.aa),
+ status_code);
netdev_ft_over_ds_auth_failed(info, status_code);
}
@@ -3870,10 +3914,8 @@ int netdev_fast_transition_over_ds(struct netdev *netdev,
struct scan_bss *target_bss,
netdev_connect_cb_t cb)
{
- struct netdev_ft_over_ds_info *info = netdev->ft_ds_info;
-
- if (!info || !info->parsed)
- return -ENOENT;
+ struct netdev_ft_over_ds_info *info;
+ struct ft_ds_finder finder;
if (!netdev->operational)
return -ENOTCONN;
@@ -3883,6 +3925,14 @@ int netdev_fast_transition_over_ds(struct netdev *netdev,
l_get_le16(target_bss->mde))
return -EINVAL;
+ finder.spa = netdev->addr;
+ finder.aa = target_bss->addr;
+
+ info = l_queue_find(netdev->ft_ds_list, match_ft_ds_info, &finder);
+
+ if (!info || !info->parsed)
+ return -ENOENT;
+
prepare_ft(netdev, target_bss);
ft_over_ds_prepare_handshake(&info->super, netdev->handshake);
@@ -3910,34 +3960,16 @@ static void netdev_ft_request_cb(struct l_genl_msg *msg, void *user_data)
}
}
-static void netdev_ft_over_ds_timeout(struct l_timeout *timeout,
- void *user_data)
-{
- struct netdev_ft_over_ds_info *info = user_data;
-
- l_timeout_remove(info->timeout);
- info->timeout = NULL;
-
- l_debug("");
-
- netdev_ft_over_ds_auth_failed(info, MMPDU_STATUS_CODE_UNSPECIFIED);
-}
-
static void netdev_ft_ds_info_free(struct ft_ds_info *ft)
{
struct netdev_ft_over_ds_info *info = l_container_of(ft,
struct netdev_ft_over_ds_info, super);
- if (info->timeout)
- l_timeout_remove(info->timeout);
-
l_free(info);
}
int netdev_fast_transition_over_ds_action(struct netdev *netdev,
- const struct scan_bss *target_bss,
- netdev_ft_over_ds_cb_t cb,
- void *user_data)
+ const struct scan_bss *target_bss)
{
struct netdev_ft_over_ds_info *info;
uint8_t ft_req[14];
@@ -3946,10 +3978,6 @@ int netdev_fast_transition_over_ds_action(struct netdev *netdev,
uint8_t buf[512];
size_t len;
- /* TODO: Just allow single outstanding action frame for now */
- if (netdev->ft_ds_info)
- return -EALREADY;
-
if (!netdev->operational)
return -ENOTCONN;
@@ -3969,9 +3997,6 @@ int netdev_fast_transition_over_ds_action(struct netdev *netdev,
l_getrandom(info->super.snonce, 32);
info->super.free = netdev_ft_ds_info_free;
- info->cb = cb;
- info->user_data = user_data;
-
ft_req[0] = 6; /* FT category */
ft_req[1] = 1; /* FT Request action */
memcpy(ft_req + 2, netdev->addr, 6);
@@ -3988,10 +4013,10 @@ int netdev_fast_transition_over_ds_action(struct netdev *netdev,
iovs[2].iov_base = NULL;
- netdev->ft_ds_info = info;
+ if (!netdev->ft_ds_list)
+ netdev->ft_ds_list = l_queue_new();
- info->timeout = l_timeout_create_ms(300, netdev_ft_over_ds_timeout,
- info, NULL);
+ l_queue_push_head(netdev->ft_ds_list, info);
netdev_send_action_framev(netdev, netdev->handshake->aa, iovs, 2,
netdev->frequency,
@@ -4520,6 +4545,42 @@ failed:
}
+static void netdev_channel_switch_event(struct l_genl_msg *msg,
+ struct netdev *netdev)
+{
+ struct l_genl_attr attr;
+ uint16_t type, len;
+ const void *data;
+ uint32_t *freq = NULL;
+
+ l_debug("");
+
+ if (!l_genl_attr_init(&attr, msg))
+ return;
+
+ while (l_genl_attr_next(&attr, &type, &len, &data)) {
+ switch (type) {
+ case NL80211_ATTR_WIPHY_FREQ:
+ if (len != 4)
+ continue;
+
+ freq = (uint32_t *) data;
+ break;
+ }
+ }
+
+ if (!freq)
+ return;
+
+ l_debug("Channel switch event, frequency: %u", *freq);
+
+ if (!netdev->event_filter)
+ return;
+
+ netdev->event_filter(netdev, NETDEV_EVENT_CHANNEL_SWITCHED, freq,
+ netdev->user_data);
+}
+
static void netdev_mlme_notify(struct l_genl_msg *msg, void *user_data)
{
struct netdev *netdev = NULL;
@@ -4545,6 +4606,9 @@ static void netdev_mlme_notify(struct l_genl_msg *msg, void *user_data)
case NL80211_CMD_ROAM:
netdev_roam_event(msg, netdev);
break;
+ case NL80211_CMD_CH_SWITCH_NOTIFY:
+ netdev_channel_switch_event(msg, netdev);
+ break;
case NL80211_CMD_CONNECT:
netdev_connect_event(msg, netdev);
break;
@@ -4806,9 +4870,11 @@ static struct l_genl_msg *netdev_build_cmd_cqm_rssi_update(
uint32_t hyst = 5;
int thold_count;
int32_t thold_list[levels_num + 2];
+ int threshold = netdev->frequency > 4000 ? LOW_SIGNAL_THRESHOLD_5GHZ :
+ LOW_SIGNAL_THRESHOLD;
if (levels_num == 0) {
- thold_list[0] = LOW_SIGNAL_THRESHOLD;
+ thold_list[0] = threshold;
thold_count = 1;
} else {
/*
@@ -4827,13 +4893,12 @@ static struct l_genl_msg *netdev_build_cmd_cqm_rssi_update(
if (i && thold_list[thold_count - 1] >= val)
return NULL;
- if (val >= LOW_SIGNAL_THRESHOLD && !low_sig_added) {
- thold_list[thold_count++] =
- LOW_SIGNAL_THRESHOLD;
+ if (val >= threshold && !low_sig_added) {
+ thold_list[thold_count++] = threshold;
low_sig_added = true;
/* Duplicate values are not allowed */
- if (val == LOW_SIGNAL_THRESHOLD)
+ if (val == threshold)
continue;
}
@@ -5833,6 +5898,10 @@ static int netdev_init(void)
&LOW_SIGNAL_THRESHOLD))
LOW_SIGNAL_THRESHOLD = -70;
+ if (!l_settings_get_int(settings, "General", "RoamThreshold5G",
+ &LOW_SIGNAL_THRESHOLD_5GHZ))
+ LOW_SIGNAL_THRESHOLD_5GHZ = -76;
+
if (!l_settings_get_bool(settings, "General", "ControlPortOverNL80211",
&pae_over_nl80211))
pae_over_nl80211 = true;
@@ -5890,6 +5959,7 @@ static void netdev_exit(void)
watchlist_destroy(&netdev_watches);
l_queue_destroy(netdev_list, netdev_free);
+ netdev_list = NULL;
l_genl_family_free(nl80211);
nl80211 = NULL;
@@ -5910,9 +5980,6 @@ void netdev_shutdown(void)
netdev_free(netdev);
l_queue_pop_head(netdev_list);
}
-
- l_queue_destroy(netdev_list, NULL);
- netdev_list = NULL;
}
IWD_MODULE(netdev, netdev_init, netdev_exit);
diff --git a/src/netdev.h b/src/netdev.h
@@ -43,6 +43,7 @@ enum netdev_event {
NETDEV_EVENT_ASSOCIATING,
NETDEV_EVENT_ROAMING,
NETDEV_EVENT_ROAMED,
+ NETDEV_EVENT_CHANNEL_SWITCHED,
NETDEV_EVENT_DISCONNECT_BY_AP,
NETDEV_EVENT_DISCONNECT_BY_SME,
NETDEV_EVENT_RSSI_THRESHOLD_LOW,
@@ -163,9 +164,7 @@ int netdev_reassociate(struct netdev *netdev, struct scan_bss *target_bss,
int netdev_fast_transition(struct netdev *netdev, struct scan_bss *target_bss,
netdev_connect_cb_t cb);
int netdev_fast_transition_over_ds_action(struct netdev *netdev,
- const struct scan_bss *target_bss,
- netdev_ft_over_ds_cb_t cb,
- void *user_data);
+ const struct scan_bss *target_bss);
int netdev_fast_transition_over_ds(struct netdev *netdev,
struct scan_bss *target_bss,
netdev_connect_cb_t cb);
diff --git a/src/network.c b/src/network.c
@@ -172,6 +172,8 @@ void network_connected(struct network *network)
void network_disconnected(struct network *network)
{
network_settings_close(network);
+
+ l_queue_clear(network->blacklist, NULL);
}
/* First 64 entries calculated by 1 / pow(n, 0.3) for n >= 1 */
@@ -613,8 +615,6 @@ void network_connect_failed(struct network *network, bool in_handshake)
l_queue_destroy(network->secrets, eap_secret_info_free);
network->secrets = NULL;
-
- l_queue_clear(network->blacklist, NULL);
}
static bool hotspot_info_matches(struct network *network,
@@ -693,6 +693,12 @@ bool network_bss_update(struct network *network, struct scan_bss *bss)
l_queue_insert(network->bss_list, bss, scan_bss_rank_compare, NULL);
+ /* Sync frequency for already known networks */
+ if (network->info) {
+ known_network_add_frequency(network->info, bss->frequency);
+ known_network_frequency_sync(network->info);
+ }
+
return true;
}
@@ -763,6 +769,12 @@ bool network_has_erp_identity(struct network *network)
return ret;
}
+const struct l_queue_entry *network_bss_list_get_entries(
+ struct network *network)
+{
+ return l_queue_get_entries(network->bss_list);
+}
+
struct scan_bss *network_bss_select(struct network *network,
bool fallback_to_blacklist)
{
@@ -1460,6 +1472,10 @@ int network_rank_compare(const void *a, const void *b, void *user)
void network_rank_update(struct network *network, bool connected)
{
+ static const double RANK_RSNE_FACTOR = 1.2;
+ static const double RANK_WPA_FACTOR = 1.0;
+ static const double RANK_OPEN_FACTOR = 0.5;
+ static const double RANK_NO_PRIVACY_FACTOR = 0.5;
/*
* Theoretically there may be difference between the BSS selection
* here and in network_bss_select but those should be rare cases.
@@ -1499,6 +1515,21 @@ void network_rank_update(struct network *network, bool connected)
network->rank = rankmod_table[n] * best_bss->rank + USHRT_MAX;
} else
network->rank = best_bss->rank;
+
+ /*
+ * Prefer RSNE first, WPA second. Open networks are much less
+ * desirable.
+ */
+ if (best_bss->rsne)
+ network->rank *= RANK_RSNE_FACTOR;
+ else if (best_bss->wpa)
+ network->rank *= RANK_WPA_FACTOR;
+ else
+ network->rank *= RANK_OPEN_FACTOR;
+
+ /* We prefer networks with CAP PRIVACY */
+ if (!(best_bss->capability & IE_BSS_CAP_PRIVACY))
+ network->rank *= RANK_NO_PRIVACY_FACTOR;
}
static void network_unset_hotspot(struct network *network, void *user_data)
diff --git a/src/network.h b/src/network.h
@@ -81,3 +81,6 @@ const struct iovec *network_get_extra_ies(struct network *network,
size_t *num_elems);
bool network_has_erp_identity(struct network *network);
+
+const struct l_queue_entry *network_bss_list_get_entries(
+ struct network *network);
diff --git a/src/p2p.c b/src/p2p.c
@@ -34,6 +34,7 @@
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <linux/if.h>
#include <ell/ell.h>
@@ -170,6 +171,7 @@ struct p2p_wfd_properties {
};
static struct l_queue *p2p_device_list;
+static unsigned int p2p_dhcp_timeout_val;
static struct l_settings *p2p_dhcp_settings;
static struct p2p_wfd_properties *p2p_own_wfd;
static unsigned int p2p_wfd_disconnect_watch;
@@ -662,10 +664,11 @@ static void p2p_connection_reset(struct p2p_device *dev)
netconfig_destroy(dev->conn_netconfig);
dev->conn_netconfig = NULL;
l_settings_free(dev->conn_netconfig_settings);
- l_free(dev->conn_peer_ip);
- dev->conn_peer_ip = NULL;
}
+ l_free(dev->conn_peer_ip);
+ dev->conn_peer_ip = NULL;
+
if (dev->conn_new_intf_cmd_id)
/*
* Note this may result in the interface being created
@@ -902,22 +905,11 @@ static void p2p_group_event(enum ap_event_type type, const void *event_data,
case AP_EVENT_STATION_ADDED:
{
const struct ap_event_station_added_data *data = event_data;
- L_AUTO_FREE_VAR(uint8_t *, p2p_data) = NULL;
- ssize_t p2p_data_len;
L_AUTO_FREE_VAR(uint8_t *, wfd_data) = NULL;
ssize_t wfd_data_len;
struct p2p_association_req req_info;
int r;
- p2p_data = ie_tlv_extract_p2p_payload(data->assoc_ies,
- data->assoc_ies_len,
- &p2p_data_len);
- if (!p2p_data) {
- l_error("Missing or invalid P2P IEs: %s (%i)",
- strerror(-p2p_data_len), (int) -p2p_data_len);
- goto invalid_ie;
- }
-
/*
* We don't need to validate most of the Association Request
* P2P IE contents as we already have all the information there
@@ -932,8 +924,8 @@ static void p2p_group_event(enum ap_event_type type, const void *event_data,
* information shall be used by the P2P Group Owner for Group
* Information Advertisement.
*/
- r = p2p_parse_association_req(p2p_data, p2p_data_len,
- &req_info);
+ r = p2p_parse_association_req(data->assoc_ies,
+ data->assoc_ies_len, &req_info);
if (r < 0) {
l_error("Can't parse P2P Association Request: %s (%i)",
strerror(-r), -r);
@@ -962,8 +954,8 @@ static void p2p_group_event(enum ap_event_type type, const void *event_data,
p2p_extract_wfd_properties(wfd_data, wfd_data_len,
dev->conn_peer->wfd);
- dev->conn_peer_added = true;
- p2p_peer_connect_done(dev);
+ /* Setup is progressing so re-arm the timeout */
+ l_timeout_modify(dev->conn_dhcp_timeout, p2p_dhcp_timeout_val);
break;
}
@@ -982,6 +974,33 @@ static void p2p_group_event(enum ap_event_type type, const void *event_data,
break;
case AP_EVENT_PBC_MODE_EXIT:
break;
+
+ case AP_EVENT_DHCP_NEW_LEASE:
+ {
+ const struct l_dhcp_lease *lease = event_data;
+
+ if (dev->conn_peer_added)
+ break;
+
+ l_rtnl_set_linkmode_and_operstate(iwd_get_rtnl(),
+ netdev_get_ifindex(dev->conn_netdev),
+ IF_LINK_MODE_DEFAULT, IF_OPER_UP,
+ NULL, NULL, NULL);
+
+ dev->conn_peer_added = true;
+ dev->conn_peer_ip = l_dhcp_lease_get_address(lease);
+ l_timeout_remove(dev->conn_dhcp_timeout);
+ p2p_peer_connect_done(dev);
+ break;
+ }
+
+ case AP_EVENT_DHCP_LEASE_EXPIRED:
+ /*
+ * Only one DHCP lease allowed for now, as soon as it expires
+ * the connection is considered to be down.
+ */
+ p2p_connect_failed(dev);
+ break;
};
return;
@@ -1036,6 +1055,7 @@ static size_t p2p_group_write_p2p_ie(struct p2p_device *dev,
case MPDU_MANAGEMENT_SUBTYPE_PROBE_RESPONSE:
{
+ L_AUTO_FREE_VAR(uint8_t *, tmp) = NULL;
struct p2p_probe_resp info = {};
const struct mmpdu_probe_request *req =
mmpdu_body(client_frame);
@@ -1049,8 +1069,8 @@ static size_t p2p_group_write_p2p_ie(struct p2p_device *dev,
* Response frame if the received Probe Request frame does
* not contain a P2P IE."
*/
- if (!ie_tlv_extract_p2p_payload(req->ies, req_ies_len,
- &req_p2p_data_size))
+ if (!(tmp = ie_tlv_extract_p2p_payload(req->ies, req_ies_len,
+ &req_p2p_data_size)))
return 0;
info.capability = dev->capability;
@@ -1189,6 +1209,22 @@ static const struct ap_ops p2p_go_ops = {
.write_extra_ies = p2p_group_write_ies,
};
+static void p2p_dhcp_timeout(struct l_timeout *timeout, void *user_data)
+{
+ struct p2p_device *dev = user_data;
+
+ l_debug("");
+
+ p2p_connect_failed(dev);
+}
+
+static void p2p_dhcp_timeout_destroy(void *user_data)
+{
+ struct p2p_device *dev = user_data;
+
+ dev->conn_dhcp_timeout = NULL;
+}
+
static void p2p_group_start(struct p2p_device *dev)
{
struct l_settings *config = l_settings_new();
@@ -1239,7 +1275,8 @@ static void p2p_group_start(struct p2p_device *dev)
l_settings_set_bytes(config, "Security", "PreSharedKey", psk, 32);
- l_settings_add_group(config, "IPv4");
+ /* Enable netconfig, set maximum usable DHCP lease time */
+ l_settings_set_uint(config, "IPv4", "LeaseTime", 0x7fffffff);
dev->capability.group_caps |= P2P_GROUP_CAP_GO;
dev->capability.group_caps |= P2P_GROUP_CAP_GROUP_FORMATION;
@@ -1247,8 +1284,15 @@ static void p2p_group_start(struct p2p_device *dev)
dev->group = ap_start(dev->conn_netdev, config, &p2p_go_ops, NULL, dev);
l_settings_free(config);
- if (!dev->group)
+ if (!dev->group) {
p2p_connect_failed(dev);
+ return;
+ }
+
+ /* Set timeout on client connecting and getting its IP */
+ dev->conn_dhcp_timeout = l_timeout_create(p2p_dhcp_timeout_val,
+ p2p_dhcp_timeout, dev,
+ p2p_dhcp_timeout_destroy);
}
static void p2p_netconfig_event_handler(enum netconfig_event event,
@@ -1273,32 +1317,11 @@ static void p2p_netconfig_event_handler(enum netconfig_event event,
}
}
-static void p2p_dhcp_timeout(struct l_timeout *timeout, void *user_data)
-{
- struct p2p_device *dev = user_data;
-
- l_debug("");
-
- p2p_connect_failed(dev);
-}
-
-static void p2p_dhcp_timeout_destroy(void *user_data)
-{
- struct p2p_device *dev = user_data;
-
- dev->conn_dhcp_timeout = NULL;
-}
-
static void p2p_start_client_netconfig(struct p2p_device *dev)
{
uint32_t ifindex = netdev_get_ifindex(dev->conn_netdev);
- unsigned int dhcp_timeout_val;
struct l_settings *settings;
- if (!l_settings_get_uint(iwd_get_config(), "P2P", "DHCPTimeout",
- &dhcp_timeout_val))
- dhcp_timeout_val = 20; /* 20s default */
-
if (!dev->conn_netconfig) {
dev->conn_netconfig = netconfig_new(ifindex);
if (!dev->conn_netconfig) {
@@ -1310,7 +1333,7 @@ static void p2p_start_client_netconfig(struct p2p_device *dev)
settings = dev->conn_netconfig_settings ?: p2p_dhcp_settings;
netconfig_configure(dev->conn_netconfig, settings, dev->conn_addr,
p2p_netconfig_event_handler, dev);
- dev->conn_dhcp_timeout = l_timeout_create(dhcp_timeout_val,
+ dev->conn_dhcp_timeout = l_timeout_create(p2p_dhcp_timeout_val,
p2p_dhcp_timeout, dev,
p2p_dhcp_timeout_destroy);
}
@@ -4774,7 +4797,7 @@ static bool p2p_peer_get_connected_ip(struct l_dbus *dbus,
{
struct p2p_peer *peer = user_data;
- if (!p2p_peer_operational(peer) || !peer->dev->conn_peer_ip)
+ if (!p2p_peer_operational(peer))
return false;
l_dbus_message_builder_append_basic(builder, 's', peer->dev->conn_peer_ip);
@@ -5134,6 +5157,10 @@ static int p2p_init(void)
l_error("Unable to register the P2P Service Manager object");
#endif
+ if (!l_settings_get_uint(iwd_get_config(), "P2P", "DHCPTimeout",
+ &p2p_dhcp_timeout_val))
+ p2p_dhcp_timeout_val = 20; /* 20s default */
+
return 0;
}
diff --git a/src/p2putil.c b/src/p2putil.c
@@ -2637,7 +2637,7 @@ void p2p_get_random_string(char *buf, size_t len)
l_getrandom(buf, len);
while (len) {
- int index = *buf % set_size;
+ int index = (uint8_t) *buf % set_size;
*buf++ = CHARSET[index];
len--;
diff --git a/src/resolve.c b/src/resolve.c
@@ -598,19 +598,8 @@ static int resolve_init(void)
method_name = l_settings_get_value(iwd_get_config(), "Network",
"NameResolvingService");
- if (!method_name) {
- method_name = l_settings_get_value(iwd_get_config(), "General",
- "dns_resolve_method");
- if (method_name)
- l_warn("[General].dns_resolve_method is deprecated, "
- "use [Network].NameResolvingService");
- else /* Default to systemd-resolved service. */
-#ifdef HAVE_DBUS
- method_name = "systemd";
-#else
- method_name = "resolvconf";
-#endif
- }
+ if (!method_name)
+ method_name = "resolvconf";
for (i = 0; resolve_method_ops_list[i].name; i++) {
if (strcmp(resolve_method_ops_list[i].name, method_name))
diff --git a/src/scan.c b/src/scan.c
@@ -999,18 +999,6 @@ static bool scan_parse_bss_information_elements(struct scan_bss *bss,
bss->ssid_len = iter.len;
have_ssid = true;
break;
- case IE_TYPE_SUPPORTED_RATES:
- if (iter.len > 8)
- return false;
-
- bss->has_sup_rates = true;
- memcpy(bss->supp_rates_ie, iter.data - 2, iter.len + 2);
-
- break;
- case IE_TYPE_EXTENDED_SUPPORTED_RATES:
- bss->ext_supp_rates_ie = l_memdup(iter.data - 2,
- iter.len + 2);
- break;
case IE_TYPE_RSN:
if (!bss->rsne)
bss->rsne = l_memdup(iter.data - 2,
@@ -1056,20 +1044,10 @@ static bool scan_parse_bss_information_elements(struct scan_bss *bss,
break;
case IE_TYPE_HT_CAPABILITIES:
- if (iter.len != 26)
- return false;
-
bss->ht_capable = true;
- memcpy(bss->ht_ie, iter.data - 2, iter.len + 2);
-
break;
case IE_TYPE_VHT_CAPABILITIES:
- if (iter.len != 12)
- return false;
-
bss->vht_capable = true;
- memcpy(bss->vht_ie, iter.data - 2, iter.len + 2);
-
break;
case IE_TYPE_ADVERTISEMENT_PROTOCOL:
if (iter.len < 2)
@@ -1164,6 +1142,7 @@ static bool scan_parse_bss_information_elements(struct scan_bss *bss,
}
static struct scan_bss *scan_parse_attr_bss(struct l_genl_attr *attr,
+ struct wiphy *wiphy,
uint32_t *out_seen_ms_ago)
{
uint16_t type, len;
@@ -1231,7 +1210,7 @@ static struct scan_bss *scan_parse_attr_bss(struct l_genl_attr *attr,
if (L_WARN_ON(len != sizeof(uint64_t)))
break;
- bss->time_stamp = l_get_u64(data);
+ bss->time_stamp = l_get_u64(data) / L_NSEC_PER_USEC;
break;
}
}
@@ -1247,8 +1226,16 @@ static struct scan_bss *scan_parse_attr_bss(struct l_genl_attr *attr,
memcmp(ies, beacon_ies, ies_len)))
bss->source_frame = SCAN_BSS_PROBE_RESP;
- if (ies && !scan_parse_bss_information_elements(bss, ies, ies_len))
- goto fail;
+ /* Set data rate to something low, just in case estimation fails */
+ bss->data_rate = 2000000;
+
+ if (ies) {
+ if (!scan_parse_bss_information_elements(bss, ies, ies_len))
+ goto fail;
+
+ L_WARN_ON(wiphy_estimate_data_rate(wiphy, ies, ies_len, bss,
+ &bss->data_rate) < 0);
+ }
return bss;
@@ -1280,85 +1267,43 @@ static struct scan_freq_set *scan_parse_attr_scan_frequencies(
}
static struct scan_bss *scan_parse_result(struct l_genl_msg *msg,
- uint64_t *out_wdev,
+ struct wiphy *wiphy,
uint32_t *out_seen_ms_ago)
{
struct l_genl_attr attr, nested;
- uint16_t type, len;
- const void *data;
- const uint64_t *wdev = NULL;
+ uint16_t type;
struct scan_bss *bss = NULL;
if (!l_genl_attr_init(&attr, msg))
return NULL;
- while (l_genl_attr_next(&attr, &type, &len, &data)) {
+ while (l_genl_attr_next(&attr, &type, NULL, NULL)) {
switch (type) {
- case NL80211_ATTR_WDEV:
- if (len != sizeof(uint64_t))
- return NULL;
-
- wdev = data;
- break;
-
case NL80211_ATTR_BSS:
if (!l_genl_attr_recurse(&attr, &nested))
return NULL;
- bss = scan_parse_attr_bss(&nested, out_seen_ms_ago);
+ bss = scan_parse_attr_bss(&nested, wiphy,
+ out_seen_ms_ago);
break;
}
}
- if (!bss)
- return NULL;
-
- if (!wdev) {
- scan_bss_free(bss);
- return NULL;
- }
-
- if (out_wdev)
- *out_wdev = *wdev;
-
return bss;
}
static void scan_bss_compute_rank(struct scan_bss *bss)
{
- static const double RANK_RSNE_FACTOR = 1.2;
- static const double RANK_WPA_FACTOR = 1.0;
- static const double RANK_OPEN_FACTOR = 0.5;
- static const double RANK_NO_PRIVACY_FACTOR = 0.5;
static const double RANK_HIGH_UTILIZATION_FACTOR = 0.8;
static const double RANK_LOW_UTILIZATION_FACTOR = 1.2;
- static const double RANK_MIN_SUPPORTED_RATE_FACTOR = 0.6;
- static const double RANK_MAX_SUPPORTED_RATE_FACTOR = 1.3;
double rank;
uint32_t irank;
-
- /*
- * Signal strength is in mBm (100 * dBm) and is negative.
- * WiFi range is -0 to -100 dBm
- */
-
- /* Heavily slanted towards signal strength */
- rank = 10000 + bss->signal_strength;
-
/*
- * Prefer RSNE first, WPA second. Open networks are much less
- * desirable.
+ * Maximum rate is 2340Mbps (VHT)
*/
- if (bss->rsne)
- rank *= RANK_RSNE_FACTOR;
- else if (bss->wpa)
- rank *= RANK_WPA_FACTOR;
- else
- rank *= RANK_OPEN_FACTOR;
+ double max_rate = 2340000000;
- /* We prefer networks with CAP PRIVACY */
- if (!(bss->capability & IE_BSS_CAP_PRIVACY))
- rank *= RANK_NO_PRIVACY_FACTOR;
+ rank = (double)bss->data_rate / max_rate * USHRT_MAX;
/* Prefer 5G networks over 2.4G */
if (bss->frequency > 4000)
@@ -1370,29 +1315,6 @@ static void scan_bss_compute_rank(struct scan_bss *bss)
else if (bss->utilization <= 63)
rank *= RANK_LOW_UTILIZATION_FACTOR;
- if (bss->has_sup_rates || bss->ext_supp_rates_ie) {
- uint64_t data_rate;
-
- if (ie_parse_data_rates(bss->has_sup_rates ?
- bss->supp_rates_ie : NULL,
- bss->ext_supp_rates_ie,
- bss->ht_capable ? bss->ht_ie : NULL,
- bss->vht_capable ? bss->vht_ie : NULL,
- bss->signal_strength / 100,
- &data_rate) == 0) {
- double factor = RANK_MAX_SUPPORTED_RATE_FACTOR -
- RANK_MIN_SUPPORTED_RATE_FACTOR;
-
- /*
- * Maximum rate is 2340Mbps (VHT)
- */
- factor = factor * data_rate / 2340000000U +
- RANK_MIN_SUPPORTED_RATE_FACTOR;
- rank *= factor;
- } else
- rank *= RANK_MIN_SUPPORTED_RATE_FACTOR;
- }
-
irank = rank;
if (irank > USHRT_MAX)
@@ -1419,7 +1341,6 @@ struct scan_bss *scan_bss_new_from_probe_req(const struct mmpdu_header *mpdu,
if (!scan_parse_bss_information_elements(bss, body, body_len))
goto fail;
- scan_bss_compute_rank(bss);
return bss;
fail:
@@ -1429,7 +1350,6 @@ fail:
void scan_bss_free(struct scan_bss *bss)
{
- l_free(bss->ext_supp_rates_ie);
l_free(bss->rsne);
l_free(bss->wpa);
l_free(bss->wsc);
@@ -1517,16 +1437,19 @@ static void get_scan_callback(struct l_genl_msg *msg, void *user_data)
l_debug("get_scan_callback");
- bss = scan_parse_result(msg, &wdev_id, &seen_ms_ago);
- if (!bss)
+ if (nl80211_parse_attrs(msg, NL80211_ATTR_WDEV, &wdev_id,
+ NL80211_ATTR_UNSPEC) < 0)
return;
if (wdev_id != sc->wdev_id) {
l_warn("wdev mismatch in get_scan_callback");
- scan_bss_free(bss);
return;
}
+ bss = scan_parse_result(msg, sc->wiphy, &seen_ms_ago);
+ if (!bss)
+ return;
+
if (!bss->time_stamp)
bss->time_stamp = results->time_stamp -
seen_ms_ago * L_USEC_PER_MSEC;
diff --git a/src/scan.h b/src/scan.h
@@ -64,14 +64,11 @@ struct scan_bss {
uint8_t mde[3];
uint8_t ssid[32];
uint8_t ssid_len;
- uint8_t supp_rates_ie[10];
- uint8_t *ext_supp_rates_ie;
uint8_t utilization;
uint8_t cc[3];
uint16_t rank;
- uint8_t ht_ie[28];
- uint8_t vht_ie[14];
uint64_t time_stamp;
+ uint64_t data_rate;
uint8_t hessid[6];
uint8_t *rc_ie; /* Roaming consortium IE */
uint8_t hs20_version;
@@ -81,7 +78,6 @@ struct scan_bss {
bool mde_present : 1;
bool cc_present : 1;
bool cap_rm_neighbor_report : 1;
- bool has_sup_rates : 1;
bool ht_capable : 1;
bool vht_capable : 1;
bool anqp_capable : 1;
diff --git a/src/station.c b/src/station.c
@@ -34,6 +34,7 @@
#include <ell/ell.h>
+#include "ell/useful.h"
#include "src/util.h"
#include "src/iwd.h"
#include "src/module.h"
@@ -152,12 +153,6 @@ static bool station_is_autoconnecting(struct station *station)
station->state == STATION_STATE_AUTOCONNECT_QUICK;
}
-struct autoconnect_entry {
- uint16_t rank;
- struct network *network;
- struct scan_bss *bss;
-};
-
static void station_property_set_scanning(struct station *station,
bool scanning)
{
@@ -176,29 +171,31 @@ static void station_property_set_scanning(struct station *station,
static void station_enter_state(struct station *station,
enum station_state state);
-static void station_autoconnect_next(struct station *station)
+static int station_autoconnect_next(struct station *station)
{
- struct autoconnect_entry *entry;
+ struct network *network;
int r;
- while ((entry = l_queue_pop_head(station->autoconnect_list))) {
- l_debug("Considering autoconnecting to BSS '%s' with SSID: %s,"
- " freq: %u, rank: %u, strength: %i",
- util_address_to_string(entry->bss->addr),
- network_get_ssid(entry->network),
- entry->bss->frequency, entry->rank,
- entry->bss->signal_strength);
+ while ((network = l_queue_pop_head(station->autoconnect_list))) {
+ const char *ssid = network_get_ssid(network);
+ struct scan_bss *bss = network_bss_select(network, false);
- if (blacklist_contains_bss(entry->bss->addr)) {
- l_free(entry);
+ l_debug("autoconnect: Trying SSID: %s", ssid);
+
+ if (!bss) {
+ l_debug("autoconnect: No suitable BSSes found");
continue;
}
- r = network_autoconnect(entry->network, entry->bss);
- l_free(entry);
+ l_debug("autoconnect: '%s' freq: %u, rank: %u, strength: %i",
+ util_address_to_string(bss->addr),
+ bss->frequency, bss->rank,
+ bss->signal_strength);
+ r = network_autoconnect(network, bss);
if (!r) {
- station_enter_state(station, STATION_STATE_CONNECTING);
+ station_enter_state(station,
+ STATION_STATE_CONNECTING_AUTO);
if (station->quick_scan_id) {
scan_cancel(netdev_get_wdev_id(station->netdev),
@@ -207,36 +204,13 @@ static void station_autoconnect_next(struct station *station)
station_property_set_scanning(station, false);
}
- return;
- }
+ return 0;
+ } else
+ l_debug("autoconnect: network_autoconnect: %s (%d)",
+ strerror(-r), r);
}
-}
-
-static int autoconnect_rank_compare(const void *a, const void *b, void *user)
-{
- const struct autoconnect_entry *new_ae = a;
- const struct autoconnect_entry *ae = b;
- return (ae->rank > new_ae->rank) ? 1 : -1;
-}
-
-static void station_add_autoconnect_bss(struct station *station,
- struct network *network,
- struct scan_bss *bss)
-{
- double rankmod;
- struct autoconnect_entry *entry;
-
- /* See if network is autoconnectable (is a known network) */
- if (!network_rankmod(network, &rankmod))
- return;
-
- entry = l_new(struct autoconnect_entry, 1);
- entry->network = network;
- entry->bss = bss;
- entry->rank = bss->rank * rankmod;
- l_queue_insert(station->autoconnect_list, entry,
- autoconnect_rank_compare, NULL);
+ return -ENOENT;
}
static void bss_free(void *data)
@@ -326,12 +300,14 @@ static struct network *station_add_seen_bss(struct station *station,
enum security security;
const char *path;
char ssid[33];
+ uint32_t kbps100 = DIV_ROUND_CLOSEST(bss->data_rate, 100000);
l_debug("Processing BSS '%s' with SSID: %s, freq: %u, rank: %u, "
- "strength: %i",
+ "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);
+ bss->frequency, bss->rank, bss->signal_strength,
+ kbps100 / 10, kbps100 % 10);
if (util_ssid_is_hidden(bss->ssid_len, bss->ssid)) {
l_debug("BSS has hidden SSID");
@@ -457,12 +433,9 @@ static bool match_nai_realms(const struct network_info *info, void *user_data)
static void network_add_foreach(struct network *network, void *user_data)
{
struct station *station = user_data;
- struct scan_bss *bss = network_bss_select(network, false);
-
- if (!bss)
- return;
- station_add_autoconnect_bss(station, network, bss);
+ l_queue_insert(station->autoconnect_list, network,
+ network_rank_compare, NULL);
}
static bool match_pending(const void *a, const void *b)
@@ -553,7 +526,7 @@ request_done:
/* Notify all watchers now that every ANQP request has finished */
l_queue_foreach_remove(station->anqp_pending, anqp_entry_foreach, NULL);
- l_queue_destroy(station->autoconnect_list, l_free);
+ l_queue_destroy(station->autoconnect_list, NULL);
station->autoconnect_list = l_queue_new();
if (station_is_autoconnecting(station)) {
@@ -662,7 +635,7 @@ void station_set_scan_results(struct station *station,
l_queue_clear(station->hidden_bss_list_sorted, NULL);
- l_queue_destroy(station->autoconnect_list, l_free);
+ l_queue_destroy(station->autoconnect_list, NULL);
station->autoconnect_list = l_queue_new();
station_bss_list_remove_expired_bsses(station, freqs);
@@ -865,11 +838,7 @@ build_ie:
if (!handshake_state_set_supplicant_ie(hs, rsne_buf))
goto not_supported;
- if (info.akm_suites & (IE_RSN_AKM_SUITE_FT_OVER_8021X |
- IE_RSN_AKM_SUITE_FT_USING_PSK |
- IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256 |
- IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA256 |
- IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384))
+ if (IE_AKM_IS_FT(info.akm_suites))
add_mde = true;
open_network:
@@ -1173,6 +1142,8 @@ static const char *station_state_to_string(enum station_state state)
return "autoconnect_full";
case STATION_STATE_CONNECTING:
return "connecting";
+ case STATION_STATE_CONNECTING_AUTO:
+ return "connecting (auto)";
case STATION_STATE_CONNECTED:
return "connected";
case STATION_STATE_DISCONNECTING:
@@ -1220,6 +1191,7 @@ static void station_enter_state(struct station *station,
new_scan_results, station);
break;
case STATION_STATE_CONNECTING:
+ case STATION_STATE_CONNECTING_AUTO:
/* Refresh the ordered network list */
network_rank_update(station->connected_network, true);
l_queue_remove(station->networks_sorted, station->connected_network);
@@ -1338,6 +1310,7 @@ static void station_reset_connection_state(struct station *station)
if (station->state == STATION_STATE_CONNECTED ||
station->state == STATION_STATE_CONNECTING ||
+ station->state == STATION_STATE_CONNECTING_AUTO ||
station->state == STATION_STATE_ROAMING)
network_disconnected(network);
@@ -1375,21 +1348,6 @@ static void station_disassociated(struct station *station)
station_enter_state(station, STATION_STATE_AUTOCONNECT_QUICK);
}
-static void station_connect_cb(struct netdev *netdev, enum netdev_result result,
- void *event_data, void *user_data);
-
-static void station_disconnect_event(struct station *station, void *event_data)
-{
- l_debug("%u", netdev_get_ifindex(station->netdev));
-
- if (station->connect_pending)
- station_connect_cb(station->netdev,
- NETDEV_RESULT_HANDSHAKE_FAILED,
- event_data, station);
- else
- station_disassociated(station);
-}
-
static void station_roam_timeout_rearm(struct station *station, int seconds);
static int station_roam_scan(struct station *station,
struct scan_freq_set *freq_set);
@@ -1732,45 +1690,6 @@ static bool bss_match_bssid(const void *a, const void *b)
return !memcmp(bss->addr, bssid, sizeof(bss->addr));
}
-static void station_fast_transition_ds_cb(struct netdev *netdev,
- uint16_t status, const uint8_t *bssid,
- void *user_data)
-{
- struct station *station = user_data;
- struct scan_bss *bss;
-
- if (status != 0)
- goto failed;
-
- /*
- * TODO: In the future it may be desired to start sending out these
- * FT-over-DS action frames at the time of connecting then be able to
- * roam immediately when required. If this is being done we can simply
- * bail out now as ft already caches the entires. But since this was
- * initiated due to a need to roam, do so now.
- */
-
- /* Make sure we still have our BSS */
- bss = l_queue_find(station->bss_list, bss_match_bssid, bssid);
- if (!bss)
- goto failed;
-
- l_debug("Starting FT-over-DS roam");
-
- if (netdev_fast_transition_over_ds(station->netdev, bss,
- station_fast_transition_cb) < 0)
- goto failed;
-
- station->connected_bss = bss;
- station->preparing_roam = false;
- station_enter_state(station, STATION_STATE_ROAMING);
-
- return;
-
-failed:
- station_roam_retry(station);
-}
-
static void station_preauthenticate_cb(struct netdev *netdev,
enum netdev_result result,
const uint8_t *pmk, void *user_data)
@@ -1835,15 +1754,46 @@ static void station_preauthenticate_cb(struct netdev *netdev,
station_transition_reassociate(station, bss, new_hs);
}
+static bool station_can_fast_transition(struct handshake_state *hs,
+ struct scan_bss *bss)
+{
+ uint16_t mdid;
+
+ if (!hs->mde)
+ return false;
+
+ if (ie_parse_mobility_domain_from_data(hs->mde, hs->mde[1] + 2,
+ &mdid, NULL, NULL) < 0)
+ return false;
+
+ if (!(bss->mde_present && l_get_le16(bss->mde) == mdid))
+ return false;
+
+ if (hs->supplicant_ie != NULL) {
+ struct ie_rsn_info rsn_info;
+
+ if (!IE_AKM_IS_FT(hs->akm_suite))
+ return false;
+
+ if (scan_bss_get_rsn_info(bss, &rsn_info) < 0)
+ return false;
+
+ if (!IE_AKM_IS_FT(rsn_info.akm_suites))
+ return false;
+ }
+
+ return true;
+}
+
static void station_transition_start(struct station *station,
struct scan_bss *bss)
{
struct handshake_state *hs = netdev_get_handshake(station->netdev);
struct network *connected = station->connected_network;
enum security security = network_get_security(connected);
- uint16_t mdid;
struct handshake_state *new_hs;
struct ie_rsn_info cur_rsne, target_rsne;
+ int ret;
l_debug("%u, target %s", netdev_get_ifindex(station->netdev),
util_address_to_string(bss->addr));
@@ -1851,12 +1801,8 @@ static void station_transition_start(struct station *station,
/* Reset AP roam flag, at this point the roaming behaves the same */
station->ap_directed_roaming = false;
- if (hs->mde)
- ie_parse_mobility_domain_from_data(hs->mde, hs->mde[1] + 2,
- &mdid, NULL, NULL);
-
/* Can we use Fast Transition? */
- if (hs->mde && bss->mde_present && l_get_le16(bss->mde) == mdid) {
+ if (station_can_fast_transition(hs, bss)) {
/* Rebuild handshake RSN for target AP */
if (station_build_handshake_rsn(hs, station->wiphy,
station->connected_network, bss) < 0) {
@@ -1866,21 +1812,22 @@ static void station_transition_start(struct station *station,
}
/* FT-over-DS can be better suited for these situations */
- if ((hs->mde[4] & 1) && (station->ap_directed_roaming ||
- station->signal_low)) {
- if (netdev_fast_transition_over_ds_action(
- station->netdev, bss,
- station_fast_transition_ds_cb,
- station) < 0) {
+ if ((hs->mde[4] & 1) && station->signal_low) {
+ ret = netdev_fast_transition_over_ds(station->netdev,
+ bss, station_fast_transition_cb);
+ /* No action responses from this BSS, try over air */
+ if (ret == -ENOENT)
+ goto try_over_air;
+ else if (ret < 0) {
+ /*
+ * If we are here FT-over-air will not work
+ * either (identical checks) so try again later.
+ */
station_roam_retry(station);
+ return;
}
-
- /*
- * Set connected_bss/preparing_roam/state only on a
- * successful FT-over-DS action frame response
- */
- return;
} else {
+try_over_air:
if (netdev_fast_transition(station->netdev, bss,
station_fast_transition_cb) < 0) {
station_roam_failed(station);
@@ -2386,43 +2333,19 @@ static void station_event_roamed(struct station *station, struct scan_bss *new)
station_roamed(station);
}
-static void station_rssi_level_changed(struct station *station,
- uint8_t level_idx);
-
-static void station_netdev_event(struct netdev *netdev, enum netdev_event event,
- void *event_data, void *user_data)
+static void station_event_channel_switched(struct station *station,
+ const uint32_t freq)
{
- struct station *station = user_data;
+ struct network *network = station->connected_network;
- switch (event) {
- case NETDEV_EVENT_AUTHENTICATING:
- l_debug("Authenticating");
- break;
- case NETDEV_EVENT_ASSOCIATING:
- l_debug("Associating");
- break;
- case NETDEV_EVENT_DISCONNECT_BY_AP:
- case NETDEV_EVENT_DISCONNECT_BY_SME:
- station_disconnect_event(station, event_data);
- break;
- case NETDEV_EVENT_RSSI_THRESHOLD_LOW:
- station_low_rssi(station);
- break;
- case NETDEV_EVENT_RSSI_THRESHOLD_HIGH:
- station_ok_rssi(station);
- break;
- case NETDEV_EVENT_RSSI_LEVEL_NOTIFY:
- station_rssi_level_changed(station, l_get_u8(event_data));
- break;
- case NETDEV_EVENT_ROAMING:
- station_enter_state(station, STATION_STATE_ROAMING);
- break;
- case NETDEV_EVENT_ROAMED:
- station_event_roamed(station, (struct scan_bss *) event_data);
- break;
- }
+ station->connected_bss->frequency = freq;
+
+ network_bss_update(network, station->connected_bss);
}
+static void station_rssi_level_changed(struct station *station,
+ uint8_t level_idx);
+
static bool station_try_next_bss(struct station *station)
{
struct scan_bss *next;
@@ -2491,38 +2414,100 @@ static bool station_retry_with_status(struct station *station,
return station_try_next_bss(station);
}
-static void station_connect_dbus_reply(struct station *station,
- enum netdev_result result)
+static void station_ft_ds_action_start(struct station *station, uint16_t mdid)
{
- struct l_dbus_message *reply;
+ const struct l_queue_entry *entry;
+ struct scan_bss *bss;
+ struct ie_rsn_info rsn_info;
- switch (result) {
- case NETDEV_RESULT_ABORTED:
- reply = dbus_error_aborted(station->connect_pending);
- break;
- case NETDEV_RESULT_OK:
- reply = l_dbus_message_new_method_return(
- station->connect_pending);
- break;
- default:
- reply = dbus_error_failed(station->connect_pending);
- break;
+ for (entry = network_bss_list_get_entries(station->connected_network);
+ entry; entry = entry->next) {
+ bss = entry->data;
+
+ if (bss == station->connected_bss)
+ continue;
+
+ if (mdid != l_get_le16(bss->mde))
+ continue;
+
+ if (scan_bss_get_rsn_info(bss, &rsn_info) < 0)
+ continue;
+
+ if (!IE_AKM_IS_FT(rsn_info.akm_suites))
+ continue;
+
+ /*
+ * Fire and forget. Netdev will maintain a cache of responses and
+ * when the time comes these can be referenced for a roam
+ */
+ netdev_fast_transition_over_ds_action(station->netdev, bss);
+ }
+}
+
+static void station_connect_ok(struct station *station)
+{
+ struct handshake_state *hs = netdev_get_handshake(station->netdev);
+
+ l_debug("");
+
+ if (station->connect_pending) {
+ struct l_dbus_message *reply =
+ l_dbus_message_new_method_return(
+ station->connect_pending);
+ dbus_pending_reply(&station->connect_pending, reply);
+ }
+
+ /*
+ * Get a neighbor report now so future roams can avoid waiting for
+ * a report at that time
+ */
+ if (station->connected_bss->cap_rm_neighbor_report) {
+ if (netdev_neighbor_report_req(station->netdev,
+ station_early_neighbor_report_cb) < 0)
+ l_warn("Could not request neighbor report");
}
- dbus_pending_reply(&station->connect_pending, reply);
+ /*
+ * If this network supports FT-over-DS send initial action frames now
+ * to prepare for future roams.
+ */
+ if (station_can_fast_transition(hs, station->connected_bss) &&
+ (hs->mde[4] & 1)) {
+ uint16_t mdid;
+
+ if (ie_parse_mobility_domain_from_data(hs->mde, hs->mde[1] + 2,
+ &mdid, NULL, NULL) < 0)
+ return;
+
+ station_ft_ds_action_start(station, mdid);
+ }
+
+ network_connected(station->connected_network);
+
+ if (station->netconfig)
+ netconfig_configure(station->netconfig,
+ network_get_settings(
+ station->connected_network),
+ netdev_get_address(station->netdev),
+ station_netconfig_event_handler,
+ station);
+ else
+ station_enter_state(station, STATION_STATE_CONNECTED);
}
static void station_connect_cb(struct netdev *netdev, enum netdev_result result,
void *event_data, void *user_data)
{
struct station *station = user_data;
+ bool continue_autoconnect;
l_debug("%u, result: %d", netdev_get_ifindex(station->netdev), result);
switch (result) {
case NETDEV_RESULT_OK:
blacklist_remove_bss(station->connected_bss->addr);
- break;
+ station_connect_ok(station);
+ return;
case NETDEV_RESULT_HANDSHAKE_FAILED:
/* reason code in this case */
if (station_retry_with_reason(station, l_get_u16(event_data)))
@@ -2540,43 +2525,106 @@ static void station_connect_cb(struct netdev *netdev, enum netdev_result result,
break;
}
- if (station->connect_pending)
- station_connect_dbus_reply(station, result);
+ if (station->connect_pending) {
+ struct l_dbus_message *reply;
- if (result != NETDEV_RESULT_OK) {
- if (result != NETDEV_RESULT_ABORTED) {
- bool in_handshake =
- result == NETDEV_RESULT_HANDSHAKE_FAILED;
+ if (result == NETDEV_RESULT_ABORTED)
+ reply = dbus_error_aborted(station->connect_pending);
+ else
+ reply = dbus_error_failed(station->connect_pending);
+
+ dbus_pending_reply(&station->connect_pending, reply);
+ }
+
+ if (result == NETDEV_RESULT_ABORTED)
+ return;
- network_connect_failed(station->connected_network,
- in_handshake);
- station_disassociated(station);
+ continue_autoconnect = station->state == STATION_STATE_CONNECTING_AUTO;
+
+ if (station->state == STATION_STATE_CONNECTING) {
+ bool during_eapol = result == NETDEV_RESULT_HANDSHAKE_FAILED;
+ network_connect_failed(station->connected_network,
+ during_eapol);
+ }
+
+ station_reset_connection_state(station);
+ station_enter_state(station, STATION_STATE_DISCONNECTED);
+
+ if (continue_autoconnect) {
+ if (station_autoconnect_next(station) < 0) {
+ l_debug("Nothing left on autoconnect list");
+ station_enter_state(station,
+ STATION_STATE_AUTOCONNECT_FULL);
}
return;
}
+ if (station->autoconnect)
+ station_enter_state(station, STATION_STATE_AUTOCONNECT_QUICK);
+}
+
+static void station_disconnect_event(struct station *station, void *event_data)
+{
+ l_debug("%u", netdev_get_ifindex(station->netdev));
+
/*
- * Get a neighbor report now so future roams can avoid waiting for
- * a report at that time
+ * If we're connecting, AP deauthenticated us, most likely because
+ * we provided the wrong password or otherwise failed authentication
+ * during the handshaking phase. Treat this as a connection failure
*/
- if (station->connected_bss->cap_rm_neighbor_report) {
- if (netdev_neighbor_report_req(station->netdev,
- station_early_neighbor_report_cb) < 0)
- l_warn("Could not request neighbor report");
+ switch (station->state) {
+ case STATION_STATE_CONNECTING:
+ case STATION_STATE_CONNECTING_AUTO:
+ station_connect_cb(station->netdev,
+ NETDEV_RESULT_HANDSHAKE_FAILED,
+ event_data, station);
+ return;
+ case STATION_STATE_CONNECTED:
+ station_disassociated(station);
+ return;
+ default:
+ break;
}
- network_connected(station->connected_network);
+ l_warn("Unexpected disconnect event");
+}
- if (station->netconfig)
- netconfig_configure(station->netconfig,
- network_get_settings(
- station->connected_network),
- netdev_get_address(station->netdev),
- station_netconfig_event_handler,
- station);
- else
- station_enter_state(station, STATION_STATE_CONNECTED);
+static void station_netdev_event(struct netdev *netdev, enum netdev_event event,
+ void *event_data, void *user_data)
+{
+ struct station *station = user_data;
+
+ switch (event) {
+ case NETDEV_EVENT_AUTHENTICATING:
+ l_debug("Authenticating");
+ break;
+ case NETDEV_EVENT_ASSOCIATING:
+ l_debug("Associating");
+ break;
+ case NETDEV_EVENT_DISCONNECT_BY_AP:
+ case NETDEV_EVENT_DISCONNECT_BY_SME:
+ station_disconnect_event(station, event_data);
+ break;
+ case NETDEV_EVENT_RSSI_THRESHOLD_LOW:
+ station_low_rssi(station);
+ break;
+ case NETDEV_EVENT_RSSI_THRESHOLD_HIGH:
+ station_ok_rssi(station);
+ break;
+ case NETDEV_EVENT_RSSI_LEVEL_NOTIFY:
+ station_rssi_level_changed(station, l_get_u8(event_data));
+ break;
+ case NETDEV_EVENT_ROAMING:
+ station_enter_state(station, STATION_STATE_ROAMING);
+ break;
+ case NETDEV_EVENT_ROAMED:
+ station_event_roamed(station, (struct scan_bss *) event_data);
+ break;
+ case NETDEV_EVENT_CHANNEL_SWITCHED:
+ station_event_channel_switched(station, l_get_u32(event_data));
+ break;
+ }
}
int __station_connect_network(struct station *station, struct network *network,
@@ -3184,7 +3232,8 @@ static struct l_dbus_message *station_dbus_scan(struct l_dbus *dbus,
if (station->dbus_scan_id)
return dbus_error_busy(message);
- if (station->state == STATION_STATE_CONNECTING)
+ if (station->state == STATION_STATE_CONNECTING ||
+ station->state == STATION_STATE_CONNECTING_AUTO)
return dbus_error_busy(message);
station->dbus_scan_subset_idx = 0;
@@ -3391,13 +3440,28 @@ static bool station_property_get_state(struct l_dbus *dbus,
void *user_data)
{
struct station *station = user_data;
- const char *statestr;
+ const char *statestr = "invalid";
- if (!station_is_busy(station))
- /* Special case. For now we treat AUTOCONNECT as disconnected */
+ switch (station->state) {
+ case STATION_STATE_AUTOCONNECT_QUICK:
+ case STATION_STATE_AUTOCONNECT_FULL:
+ case STATION_STATE_DISCONNECTED:
statestr = "disconnected";
- else
- statestr = station_state_to_string(station->state);
+ break;
+ case STATION_STATE_CONNECTING:
+ case STATION_STATE_CONNECTING_AUTO:
+ statestr = "connecting";
+ break;
+ case STATION_STATE_CONNECTED:
+ statestr = "connected";
+ break;
+ case STATION_STATE_DISCONNECTING:
+ statestr = "disconnecting";
+ break;
+ case STATION_STATE_ROAMING:
+ statestr = "roaming";
+ break;
+ }
l_dbus_message_builder_append_basic(builder, 's', statestr);
return true;
@@ -3576,9 +3640,6 @@ static void station_free(struct station *station)
if (!l_queue_remove(station_list, station))
return;
- if (station->connected_bss)
- netdev_disconnect(station->netdev, NULL, NULL);
-
l_dbus_object_remove_interface(dbus_get_bus(),
netdev_get_path(station->netdev),
IWD_STATION_DIAGNOSTIC_INTERFACE);
@@ -3630,7 +3691,7 @@ static void station_free(struct station *station)
l_hashmap_destroy(station->networks, network_free);
l_queue_destroy(station->bss_list, bss_free);
l_queue_destroy(station->hidden_bss_list_sorted, NULL);
- l_queue_destroy(station->autoconnect_list, l_free);
+ l_queue_destroy(station->autoconnect_list, NULL);
watchlist_destroy(&station->state_watches);
@@ -3751,12 +3812,49 @@ static struct l_dbus_message *station_get_diagnostics(struct l_dbus *dbus,
return NULL;
}
+static struct l_dbus_message *station_force_roam(struct l_dbus *dbus,
+ struct l_dbus_message *message,
+ void *user_data)
+{
+ struct station *station = user_data;
+ struct scan_bss *target;
+ struct l_dbus_message_iter iter;
+ uint8_t *mac;
+ uint32_t mac_len;
+
+ if (!l_dbus_message_get_arguments(message, "ay", &iter))
+ goto invalid_args;
+
+ if (!l_dbus_message_iter_get_fixed_array(&iter, &mac, &mac_len))
+ goto invalid_args;
+
+ if (mac_len != 6)
+ return dbus_error_invalid_args(message);
+
+ target = network_bss_find_by_addr(station->connected_network, mac);
+ if (!target || target == station->connected_bss)
+ return dbus_error_invalid_args(message);
+
+ l_debug("Attempting forced roam to BSS "MAC, MAC_STR(mac));
+
+ station_transition_start(station, target);
+
+ return l_dbus_message_new_method_return(message);
+
+invalid_args:
+ return dbus_error_invalid_args(message);
+}
+
static void station_setup_diagnostic_interface(
struct l_dbus_interface *interface)
{
l_dbus_interface_method(interface, "GetDiagnostics", 0,
station_get_diagnostics, "a{sv}", "",
"diagnostics");
+
+ if (iwd_is_developer_mode())
+ l_dbus_interface_method(interface, "Roam", 0,
+ station_force_roam, "", "ay", "mac");
}
static void station_destroy_diagnostic_interface(void *user_data)
@@ -3864,15 +3962,8 @@ static int station_init(void)
if (!l_settings_get_bool(iwd_get_config(), "General",
"EnableNetworkConfiguration",
- &netconfig_enabled)) {
- if (l_settings_get_bool(iwd_get_config(), "General",
- "enable_network_config",
&netconfig_enabled))
- l_warn("[General].enable_network_config is deprecated,"
- " use [General].EnableNetworkConfiguration");
- else
netconfig_enabled = false;
- }
if (!netconfig_enabled)
l_info("station: Network configuration is disabled.");
diff --git a/src/station.h b/src/station.h
@@ -39,6 +39,7 @@ enum station_state {
STATION_STATE_AUTOCONNECT_FULL,
/* Connecting */
STATION_STATE_CONNECTING,
+ STATION_STATE_CONNECTING_AUTO,
STATION_STATE_CONNECTED,
STATION_STATE_DISCONNECTING,
STATION_STATE_ROAMING
diff --git a/src/wiphy.c b/src/wiphy.c
@@ -55,6 +55,7 @@
#include "src/watchlist.h"
#include "src/nl80211util.h"
#include "src/nl80211cmd.h"
+#include "src/band.h"
#define EXT_CAP_LEN 10
@@ -78,13 +79,14 @@ struct wiphy {
uint16_t supported_iftypes;
uint16_t supported_ciphers;
struct scan_freq_set *supported_freqs;
+ struct band *band_2g;
+ struct band *band_5g;
char *model_str;
char *vendor_str;
char *driver_str;
struct watchlist state_watches;
uint8_t extended_capabilities[EXT_CAP_LEN + 2]; /* max bitmap size + IE header */
uint8_t *iftype_extended_capabilities[NUM_NL80211_IFTYPES];
- uint8_t *supported_rates[NUM_NL80211_BANDS];
uint8_t rm_enabled_capabilities[7]; /* 5 size max + header */
struct l_genl_family *nl80211;
char regdom_country[2];
@@ -304,8 +306,15 @@ static void wiphy_free(void *data)
for (i = 0; i < NUM_NL80211_IFTYPES; i++)
l_free(wiphy->iftype_extended_capabilities[i]);
- for (i = 0; i < NUM_NL80211_BANDS; i++)
- l_free(wiphy->supported_rates[i]);
+ if (wiphy->band_2g) {
+ band_free(wiphy->band_2g);
+ wiphy->band_2g = NULL;
+ }
+
+ if (wiphy->band_5g) {
+ band_free(wiphy->band_5g);
+ wiphy->band_5g = NULL;
+ }
scan_freq_set_free(wiphy->supported_freqs);
watchlist_destroy(&wiphy->state_watches);
@@ -385,10 +394,15 @@ uint32_t wiphy_get_id(struct wiphy *wiphy)
uint32_t wiphy_get_supported_bands(struct wiphy *wiphy)
{
- if (!wiphy->supported_freqs)
- return 0;
+ uint32_t bands = 0;
+
+ if (wiphy->band_2g)
+ bands |= SCAN_BAND_2_4_GHZ;
- return scan_freq_set_get_bands(wiphy->supported_freqs);
+ if (wiphy->band_5g)
+ bands |= SCAN_BAND_5_GHZ;
+
+ return bands;
}
const struct scan_freq_set *wiphy_get_supported_freqs(
@@ -624,15 +638,26 @@ bool wiphy_supports_iftype(struct wiphy *wiphy, uint32_t iftype)
const uint8_t *wiphy_get_supported_rates(struct wiphy *wiphy, unsigned int band,
unsigned int *out_num)
{
- if (band >= L_ARRAY_SIZE(wiphy->supported_rates))
+ struct band *bandp;
+
+ switch (band) {
+ case NL80211_BAND_2GHZ:
+ bandp = wiphy->band_2g;
+ break;
+ case NL80211_BAND_5GHZ:
+ bandp = wiphy->band_5g;
+ break;
+ default:
+ return NULL;
+ }
+
+ if (!bandp)
return NULL;
if (out_num)
- *out_num =
- (uint8_t *) rawmemchr(wiphy->supported_rates[band], 0) -
- wiphy->supported_rates[band];
+ *out_num = bandp->supported_rates_len;
- return wiphy->supported_rates[band];
+ return bandp->supported_rates;
}
void wiphy_get_reg_domain_country(struct wiphy *wiphy, char *out)
@@ -647,6 +672,99 @@ void wiphy_get_reg_domain_country(struct wiphy *wiphy, char *out)
out[1] = country[1];
}
+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)
+{
+ struct ie_tlv_iter iter;
+ const void *supported_rates = NULL;
+ const void *ext_supported_rates = NULL;
+ const void *vht_capabilities = NULL;
+ const void *vht_operation = NULL;
+ const void *ht_capabilities = NULL;
+ const void *ht_operation = NULL;
+ const struct band *bandp;
+ enum scan_band band;
+
+ if (scan_freq_to_channel(bss->frequency, &band) == 0)
+ return -ENOTSUP;
+
+ switch (band) {
+ case SCAN_BAND_2_4_GHZ:
+ bandp = wiphy->band_2g;
+ break;
+ case SCAN_BAND_5_GHZ:
+ bandp = wiphy->band_5g;
+ break;
+ default:
+ return -ENOTSUP;
+ }
+
+ ie_tlv_iter_init(&iter, ies, ies_len);
+
+ while (ie_tlv_iter_next(&iter)) {
+ uint8_t tag = ie_tlv_iter_get_tag(&iter);
+
+ switch (tag) {
+ case IE_TYPE_SUPPORTED_RATES:
+ if (iter.len > 8)
+ return -EBADMSG;
+
+ supported_rates = iter.data - 2;
+ break;
+ case IE_TYPE_EXTENDED_SUPPORTED_RATES:
+ ext_supported_rates = iter.data - 2;
+ break;
+ case IE_TYPE_HT_CAPABILITIES:
+ if (iter.len != 26)
+ return -EBADMSG;
+
+ ht_capabilities = iter.data - 2;
+ break;
+ case IE_TYPE_HT_OPERATION:
+ if (iter.len != 22)
+ return -EBADMSG;
+
+ ht_operation = iter.data - 2;
+ break;
+ case IE_TYPE_VHT_CAPABILITIES:
+ if (iter.len != 12)
+ return -EBADMSG;
+
+ vht_capabilities = iter.data - 2;
+ break;
+ case IE_TYPE_VHT_OPERATION:
+ if (iter.len != 5)
+ return -EBADMSG;
+
+ vht_operation = iter.data - 2;
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (!band_estimate_vht_rx_rate(bandp, vht_capabilities, vht_operation,
+ ht_capabilities, ht_operation,
+ bss->signal_strength / 100,
+ out_data_rate))
+ return 0;
+
+ if (!band_estimate_ht_rx_rate(bandp, ht_capabilities, ht_operation,
+ bss->signal_strength / 100,
+ out_data_rate))
+ return 0;
+
+ if (!band_estimate_nonht_rate(bandp, supported_rates,
+ ext_supported_rates,
+ bss->signal_strength / 100,
+ out_data_rate))
+ return 0;
+
+ return -ENOTSUP;
+}
+
uint32_t wiphy_state_watch_add(struct wiphy *wiphy,
wiphy_state_watch_func_t func,
void *user_data, wiphy_destroy_func_t destroy)
@@ -659,30 +777,118 @@ bool wiphy_state_watch_remove(struct wiphy *wiphy, uint32_t id)
return watchlist_remove(&wiphy->state_watches, id);
}
-static void wiphy_print_basic_info(struct wiphy *wiphy)
+static void wiphy_print_mcs_indexes(const uint8_t *mcs)
{
- uint32_t bands;
- char buf[1024];
+ int i;
- l_info("Wiphy: %d, Name: %s", wiphy->id, wiphy->name);
- l_info("\tPermanent Address: "MAC, MAC_STR(wiphy->permanent_addr));
+ for (i = 0; i < 77; i++) {
+ int start;
- bands = scan_freq_set_get_bands(wiphy->supported_freqs);
+ if (!test_bit(mcs, i))
+ continue;
- if (bands) {
- int len = 0;
+ start = i;
- len += sprintf(buf + len, "\tBands:");
+ while (i < 76 && test_bit(mcs, i + 1))
+ i += 1;
- if (bands & SCAN_BAND_2_4_GHZ)
- len += sprintf(buf + len, " 2.4 GHz");
+ if (start != i)
+ l_info("\t\t\t%d-%d", start, i);
+ else
+ l_info("\t\t\t%d", start);
+ }
+}
+
+static void wiphy_print_vht_mcs_info(const uint8_t *mcs_map,
+ const char *prefix)
+{
+ int i;
- if (bands & SCAN_BAND_5_GHZ)
- len += sprintf(buf + len, " 5 GHz");
+ for (i = 14; i >= 0; i -= 2) {
+ int mcs = bit_field(mcs_map[i / 8], i % 8, 2);
- l_info("%s", buf);
+ if (mcs == 0x3)
+ continue;
+
+ l_info("\t\t\tMax %s MCS: 0-%d for NSS: %d", prefix,
+ mcs + 7, i / 2 + 1);
+ return;
+ }
+}
+
+static void wiphy_print_band_info(struct band *band, const char *name)
+{
+ int i;
+
+ l_info("\t%s:", name);
+ l_info("\t\tBitrates (non-HT):");
+
+ for (i = 0; i < band->supported_rates_len; i++)
+ l_info("\t\t\t%2d.%d Mbps", band->supported_rates[i] / 2,
+ band->supported_rates[i] % 2 * 5);
+
+ if (band->ht_supported) {
+ uint8_t max_nss = bit_field(band->ht_mcs_set[12], 2, 2) + 1;
+ l_info("\t\tHT Capabilities:");
+
+ if (test_bit(band->ht_capabilities, 1))
+ l_info("\t\t\tHT40");
+ else
+ l_info("\t\t\tHT20");
+
+ if (test_bit(band->ht_capabilities, 5))
+ l_info("\t\t\tShort GI for 20Mhz");
+
+ if (test_bit(band->ht_capabilities, 6))
+ l_info("\t\t\tShort GI for 40Mhz");
+
+ l_info("\t\tHT RX MCS indexes:");
+ wiphy_print_mcs_indexes(band->ht_mcs_set);
+
+ if (test_bit(band->ht_mcs_set, 96)) {
+ if (test_bit(band->ht_mcs_set, 97))
+ l_info("\t\tHT TX MCS differ, max NSS: %d",
+ max_nss);
+ } else
+ l_info("\t\tHT TX MCS set undefined");
}
+ if (band->vht_supported) {
+ l_info("\t\tVHT Capabilities:");
+
+ switch (bit_field(band->vht_capabilities[0], 2, 2)) {
+ case 1:
+ l_info("\t\t\t160 Mhz operation");
+ break;
+ case 2:
+ l_info("\t\t\t160 Mhz, 80+80 Mhz operation");
+ break;
+ }
+
+ if (test_bit(band->vht_capabilities, 5))
+ l_info("\t\t\tShort GI for 80Mhz");
+
+ 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");
+ }
+}
+
+static void wiphy_print_basic_info(struct wiphy *wiphy)
+{
+ char buf[1024];
+
+ l_info("Wiphy: %d, Name: %s", wiphy->id, wiphy->name);
+ l_info("\tPermanent Address: "MAC, MAC_STR(wiphy->permanent_addr));
+
+ if (wiphy->band_2g)
+ wiphy_print_band_info(wiphy->band_2g, "2.4Ghz Band");
+
+ if (wiphy->band_5g)
+ wiphy_print_band_info(wiphy->band_5g, "5Ghz Band");
+
if (wiphy->supported_ciphers) {
int len = 0;
@@ -800,49 +1006,81 @@ static void parse_supported_frequencies(struct wiphy *wiphy,
}
}
-static uint8_t *parse_supported_rates(struct l_genl_attr *attr)
+static int parse_supported_rates(struct l_genl_attr *attr, struct band *band)
{
uint16_t type;
uint16_t len;
const void *data;
struct l_genl_attr nested;
int count = 0;
- uint8_t *ret;
if (!l_genl_attr_recurse(attr, &nested))
- return NULL;
-
- while (l_genl_attr_next(&nested, NULL, NULL, NULL))
- count++;
-
- if (!l_genl_attr_recurse(attr, &nested))
- return NULL;
-
- ret = l_malloc(count + 1);
- ret[count] = 0;
-
- count = 0;
+ return -EBADMSG;
while (l_genl_attr_next(&nested, NULL, NULL, NULL)) {
struct l_genl_attr nested2;
- if (!l_genl_attr_recurse(&nested, &nested2)) {
- l_free(ret);
- return NULL;
- }
+ if (!l_genl_attr_recurse(&nested, &nested2))
+ return -EBADMSG;
while (l_genl_attr_next(&nested2, &type, &len, &data)) {
+ uint32_t rate;
+
if (type != NL80211_BITRATE_ATTR_RATE || len != 4)
continue;
+ rate = l_get_u32(data);
+
+ if (rate % 5)
+ continue;
+
/*
* Convert from the 100kb/s units reported by the
* kernel to the 500kb/s used in 802.11 IEs.
*/
- ret[count++] = *(const uint32_t *) data / 5;
+ rate /= 5;
+
+ /*
+ * Rates past 120 seem to be used for other purposes,
+ * BSS Membership Selector (HT/VHT), etc
+ */
+ if (rate > 120)
+ continue;
+
+ band->supported_rates[count++] = rate;
}
}
+ band->supported_rates_len = count;
+
+ return 0;
+}
+
+static struct band *band_new_from_message(struct l_genl_attr *band)
+{
+ uint16_t type;
+ struct l_genl_attr nested;
+ uint16_t count = 0;
+ struct band *ret;
+ size_t toalloc;
+
+ /* First find the number of supported rates */
+ while (l_genl_attr_next(band, &type, NULL, NULL)) {
+ switch (type) {
+ case NL80211_BAND_ATTR_RATES:
+ if (!l_genl_attr_recurse(band, &nested))
+ return NULL;
+
+ while (l_genl_attr_next(&nested, NULL, NULL, NULL))
+ count++;
+ }
+ }
+
+ toalloc = sizeof(struct band) + count * sizeof(uint8_t);
+ ret = l_malloc(toalloc);
+ memset(ret, 0, toalloc);
+ memset(ret->vht_mcs_set, 0xff, sizeof(ret->vht_mcs_set));
+
return ret;
}
@@ -850,18 +1088,42 @@ static void parse_supported_bands(struct wiphy *wiphy,
struct l_genl_attr *bands)
{
uint16_t type;
+ uint16_t len;
+ const void *data;
struct l_genl_attr attr;
while (l_genl_attr_next(bands, &type, NULL, NULL)) {
- enum nl80211_band band = type;
+ struct band **bandp;
+ struct band *band;
- if (band != NL80211_BAND_2GHZ && band != NL80211_BAND_5GHZ)
+ switch (type) {
+ case NL80211_BAND_2GHZ:
+ bandp = &wiphy->band_2g;
+ break;
+ case NL80211_BAND_5GHZ:
+ bandp = &wiphy->band_5g;
+ break;
+ default:
continue;
+ }
if (!l_genl_attr_recurse(bands, &attr))
continue;
- while (l_genl_attr_next(&attr, &type, NULL, NULL)) {
+ if (*bandp == NULL) {
+ band = band_new_from_message(&attr);
+ if (!band)
+ continue;
+
+ /* Reset iter to beginning */
+ if (!l_genl_attr_recurse(bands, &attr)) {
+ band_free(band);
+ continue;
+ }
+ } else
+ band = *bandp;
+
+ while (l_genl_attr_next(&attr, &type, &len, &data)) {
struct l_genl_attr freqs;
switch (type) {
@@ -873,14 +1135,47 @@ static void parse_supported_bands(struct wiphy *wiphy,
break;
case NL80211_BAND_ATTR_RATES:
- if (wiphy->supported_rates[band])
+ if (parse_supported_rates(&attr, band) < 0) {
+ band_free(band);
+ continue;
+ }
+
+ break;
+ case NL80211_BAND_ATTR_VHT_MCS_SET:
+ if (L_WARN_ON(len != sizeof(band->vht_mcs_set)))
+ continue;
+
+ memcpy(band->vht_mcs_set, data, len);
+ band->vht_supported = true;
+ break;
+ case NL80211_BAND_ATTR_VHT_CAPA:
+ if (L_WARN_ON(len !=
+ sizeof(band->vht_capabilities)))
+ continue;
+
+ memcpy(band->vht_capabilities, data, len);
+ band->vht_supported = true;
+ break;
+ case NL80211_BAND_ATTR_HT_MCS_SET:
+ if (L_WARN_ON(len != sizeof(band->ht_mcs_set)))
continue;
- wiphy->supported_rates[band] =
- parse_supported_rates(&attr);
+ memcpy(band->ht_mcs_set, data, len);
+ band->ht_supported = true;
+ break;
+ case NL80211_BAND_ATTR_HT_CAPA:
+ if (L_WARN_ON(len !=
+ sizeof(band->ht_capabilities)))
+ continue;
+
+ memcpy(band->ht_capabilities, data, len);
+ band->ht_supported = true;
break;
}
}
+
+ if (*bandp == NULL)
+ *bandp = band;
}
}
diff --git a/src/wiphy.h b/src/wiphy.h
@@ -107,6 +107,11 @@ 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,
uint8_t addr[static 6]);
+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);
+
uint32_t wiphy_state_watch_add(struct wiphy *wiphy,
wiphy_state_watch_func_t func, void *user_data,
wiphy_destroy_func_t destroy);
diff --git a/src/wsc.c b/src/wsc.c
@@ -628,6 +628,7 @@ static void wsc_check_can_connect(struct wsc_station_dbus *wsc,
wsc_connect(wsc);
return;
case STATION_STATE_CONNECTING:
+ case STATION_STATE_CONNECTING_AUTO:
case STATION_STATE_CONNECTED:
if (station_disconnect(wsc->station) < 0)
goto error;
diff --git a/src/wscutil.c b/src/wscutil.c
@@ -3073,7 +3073,7 @@ bool wsc_device_type_from_setting_str(const char *value,
* DeviceType=1-0050f204-1
*/
if (wsc_device_type_from_subcategory_str(out, value))
- true;
+ return true;
u = strtoull(value, &endp, 0);
diff --git a/test/force-roam b/test/force-roam
@@ -0,0 +1,16 @@
+#!/usr/bin/python3
+
+import sys
+import dbus
+
+if (len(sys.argv) != 3):
+ print("Usage: %s <device> <mac>" % (sys.argv[0]))
+ sys.exit(1)
+
+bus = dbus.SystemBus()
+device = dbus.Interface(bus.get_object("net.connman.iwd", sys.argv[1]),
+ "net.connman.iwd.StationDiagnostic")
+
+mac = sys.argv[2].replace(':', '')
+
+device.Roam(dbus.ByteArray.fromhex(mac))
diff --git a/tools/test-runner b/tools/test-runner
@@ -672,7 +672,7 @@ class Namespace:
if self.args.valgrind:
args.extend(['valgrind', '--leak-check=full', '--track-origins=yes',
- '--log-file=/tmp/valgrind.log'])
+ '--log-file=/tmp/valgrind.log.%p'])
args.extend(['iwd', '-p', iwd_radios])
@@ -1183,14 +1183,19 @@ def post_test(ctx, to_copy):
finally:
ctx.stop_test_processes()
+ if ctx.args.valgrind:
+ for f in os.listdir('/tmp'):
+ if f.startswith("valgrind.log."):
+ dbg(f)
+ with open('/tmp/' + f, 'r') as v:
+ dbg(v.read())
+ dbg("\n")
+ os.remove('/tmp/' + f)
+
allowed = ['phonesim.conf', 'certs', 'secrets', 'iwd']
for f in [f for f in os.listdir('/tmp') if f not in allowed]:
dbg("File %s was not cleaned up!" % f)
-
- if ctx.args.valgrind:
- with open('/tmp/valgrind.log', 'r') as f:
- dbg(f.read())
- dbg("\n")
+ os.remove('/tmp/' + f)
def print_results(results):
table = PrettyTable(['Test', colored('Passed', 'green'), colored('Failed', 'red'), \
@@ -1570,7 +1575,15 @@ class Main:
else:
smp = int(nproc / 2)
- print("Using %d cores for VM" % smp)
+ #
+ # Increase RAM if valgrind is being used
+ #
+ if self.args.valgrind:
+ ram = 512
+ else:
+ ram = 256
+
+ print("Using %d cores, %d RAM for VM" % (smp, ram))
#
# This passes through most of the command line options to
@@ -1593,7 +1606,7 @@ class Main:
qemu_binary,
'-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,security_model=none,multidevs=remap',
@@ -1607,7 +1620,7 @@ class Main:
'-append',
'console=ttyS0,115200n8 earlyprintk=serial \
rootfstype=9p root=/dev/root \
- rootflags=trans=virtio,version=9p2000.u \
+ rootflags=trans=virtio,msize=1048576,version=9p2000.u \
acpi=off pci=noacpi %s ro \
mac80211_hwsim.radios=0 %s' % (kern_log, options),
'-cpu', 'host', '-smp', str(smp)
diff --git a/unit/test-band.c b/unit/test-band.c
@@ -0,0 +1,296 @@
+/*
+ *
+ * Wireless daemon for Linux
+ *
+ * Copyright (C) 2021 Intel Corporation. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <ell/ell.h>
+
+#include "src/band.h"
+
+static struct band *new_band()
+{
+ /* Band with VHT/80, short GI, NSS:2 and VHT MCS 0-9 */
+ static const uint8_t vht_mcs_set[] = {
+ 0xfa, 0xff, 0x00, 0x00, 0xfa, 0xff, 0x00, 0x20,
+ };
+ static const uint8_t vht_capabilities[] = {
+ 0xa0, 0x71, 0x80, 0x03,
+ };
+ static const uint8_t ht_mcs_set[] = {
+ 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x2c, 0x01, 0x01, 0x00, 0x00, 0x00,
+ };
+ static const uint8_t ht_capabilities[] = {
+ 0xee, 0x11,
+ };
+ /* band + 8 basic rates */
+ struct band *band = l_malloc(sizeof(struct band) + 8);
+
+ band->supported_rates_len = 8;
+ band->supported_rates[0] = 12;
+ band->supported_rates[1] = 18;
+ band->supported_rates[2] = 24;
+ band->supported_rates[3] = 36;
+ band->supported_rates[4] = 48;
+ band->supported_rates[5] = 72;
+ band->supported_rates[6] = 96;
+ band->supported_rates[7] = 108;
+
+ band->ht_supported = true;
+ band->vht_supported = true;
+
+ memcpy(band->vht_mcs_set, vht_mcs_set, sizeof(band->vht_mcs_set));
+ memcpy(band->vht_capabilities, vht_capabilities,
+ sizeof(band->vht_capabilities));
+ memcpy(band->ht_mcs_set, ht_mcs_set, sizeof(band->ht_mcs_set));
+ memcpy(band->ht_capabilities, ht_capabilities,
+ sizeof(band->ht_capabilities));
+
+ return band;
+}
+
+static void band_test_nonht_1(const void *data)
+{
+ uint8_t supported_rates[] = { 1, 8,
+ 0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c };
+ struct band *band = new_band();
+ uint64_t data_rate;
+ int ret;
+
+ ret = band_estimate_nonht_rate(band, supported_rates, NULL,
+ -50, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 54000000);
+
+ ret = band_estimate_nonht_rate(band, supported_rates, NULL,
+ -66, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 48000000);
+
+ ret = band_estimate_nonht_rate(band, supported_rates, NULL,
+ -70, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 36000000);
+
+ ret = band_estimate_nonht_rate(band, supported_rates, NULL,
+ -74, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 24000000);
+
+ ret = band_estimate_nonht_rate(band, supported_rates, NULL,
+ -77, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 18000000);
+
+ ret = band_estimate_nonht_rate(band, supported_rates, NULL,
+ -79, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 12000000);
+
+ ret = band_estimate_nonht_rate(band, supported_rates, NULL,
+ -81, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 9000000);
+
+ ret = band_estimate_nonht_rate(band, supported_rates, NULL,
+ -82, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 6000000);
+
+ ret = band_estimate_nonht_rate(band, supported_rates, NULL,
+ -83, &data_rate);
+ assert(ret < 0);
+
+ band_free(band);
+}
+
+static void band_test_ht_1(const void *data)
+{
+ /* HT40 */
+ uint8_t hto[] = { 61, 22,
+ 0x95, 0x0d, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ /* HT40, MCS 0-23, 40/20Mhz SGI */
+ uint8_t htc[] = { 45, 26,
+ 0xef, 0x09, 0x17, 0xff, 0xff, 0xff, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00 };
+ struct band *band = new_band();
+ uint64_t data_rate;
+ int ret;
+
+ ret = band_estimate_ht_rx_rate(band, htc, hto, -51, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 300000000);
+
+ ret = band_estimate_ht_rx_rate(band, htc, hto, -62, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 270000000);
+
+ ret = band_estimate_ht_rx_rate(band, htc, hto, -63, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 240000000);
+
+ ret = band_estimate_ht_rx_rate(band, htc, hto, -66, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 180000000);
+
+ ret = band_estimate_ht_rx_rate(band, htc, hto, -71, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 120000000);
+
+ ret = band_estimate_ht_rx_rate(band, htc, hto, -74, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 90000000);
+
+ ret = band_estimate_ht_rx_rate(band, htc, hto, -76, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 60000000);
+
+ ret = band_estimate_ht_rx_rate(band, htc, hto, -79, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 30000000);
+
+ /* We should now fall back to HT20 */
+ ret = band_estimate_ht_rx_rate(band, htc, hto, -82, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 14444440);
+
+ ret = band_estimate_ht_rx_rate(band, htc, hto, -83, &data_rate);
+ assert(ret < 0);
+
+ band_free(band);
+}
+
+static void band_test_vht_1(const void *data)
+{
+ /* VHT operating on 80 Mhz */
+ uint8_t vhto[] = { 192, 5, 0x01, 0x9b, 0x00, 0x00, 0x00 };
+ /* VHT80, NSS:3, MCS 0-9, 80Mhz SGI */
+ uint8_t vhtc[] = { 191, 12,
+ 0xb2, 0x59, 0x82, 0x0f, 0xea, 0xff, 0x00, 0x00,
+ 0xea, 0xff, 0x00, 0x00 };
+ /* HT40 */
+ uint8_t hto[] = { 61, 22,
+ 0x95, 0x0d, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ /* HT40, MCS 0-23, 40/20Mhz SGI */
+ uint8_t htc[] = { 45, 26,
+ 0xef, 0x09, 0x17, 0xff, 0xff, 0xff, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00 };
+ struct band *band = new_band();
+ uint64_t data_rate;
+ int ret;
+
+ ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
+ -51, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 866666660);
+
+ ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
+ -53, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 780000000);
+
+ ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
+ -56, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 650000000);
+
+ ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
+ -59, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 585000000);
+
+ ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
+ -60, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 520000000);
+
+ ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
+ -63, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 390000000);
+
+ ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
+ -67, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 260000000);
+
+ ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
+ -70, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 195000000);
+
+ ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
+ -73, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 130000000);
+
+ ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
+ -76, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 65000000);
+
+ /* We should now fall back to HT40 */
+ ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
+ -79, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 30000000);
+
+ /* And only enough for HT20 */
+ ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
+ -82, &data_rate);
+ assert(ret == 0);
+ assert(data_rate == 14444440);
+
+ ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
+ -83, &data_rate);
+ assert(ret < 0);
+
+ band_free(band);
+}
+
+int main(int argc, char *argv[])
+{
+ l_test_init(&argc, &argv);
+
+ l_test_add("/band/non-HT/test1", band_test_nonht_1, NULL);
+
+ l_test_add("/band/HT/test1", band_test_ht_1, NULL);
+
+ l_test_add("/band/VHT/test1", band_test_vht_1, NULL);
+
+ return l_test_run();
+}
diff --git a/unit/test-util.c b/unit/test-util.c
@@ -162,6 +162,7 @@ static void ip_prefix_test(const void *data)
uint32_t end;
uint32_t mask;
struct in_addr ia;
+ char ip[INET_ADDRSTRLEN];
assert(util_ip_prefix_tohl(valid[i].ip_prefix,
&prefix, &start, &end, &mask));
@@ -169,13 +170,16 @@ static void ip_prefix_test(const void *data)
assert(valid[i].prefix == prefix);
ia.s_addr = htonl(start);
- assert(strcmp(inet_ntoa(ia), valid[i].start) == 0);
+ assert(inet_ntop(AF_INET, &ia, ip, INET_ADDRSTRLEN));
+ assert(strcmp(ip, valid[i].start) == 0);
ia.s_addr = htonl(end);
- assert(strcmp(inet_ntoa(ia), valid[i].end) == 0);
+ assert(inet_ntop(AF_INET, &ia, ip, INET_ADDRSTRLEN));
+ assert(strcmp(ip, valid[i].end) == 0);
ia.s_addr = htonl(mask);
- assert(strcmp(inet_ntoa(ia), valid[i].mask) == 0);
+ assert(inet_ntop(AF_INET, &ia, ip, INET_ADDRSTRLEN));
+ assert(strcmp(ip, valid[i].mask) == 0);
}
}