commit 7ea90dc3befeb57e094acc63a6f06e1312d96355
parent c7dcd14e672f3e40921f51cb3e4ee3d7efb25c43
Author: illiliti <illiliti@protonmail.com>
Date: Thu, 6 May 2021 02:34:11 +0300
Merge tag '1.14'
Release 1.14
Diffstat:
59 files changed, 2643 insertions(+), 1418 deletions(-)
diff --git a/AUTHORS b/AUTHORS
@@ -27,3 +27,4 @@ Ard Biesheuvel <ardb@kernel.org>
Mathy Vanhoef <Mathy.Vanhoef@kuleuven.be>
Jonathan Liu <net147@gmail.com>
Daniel Lin <ephemient@gmail.com>
+Sean Anderson <sean.anderson@seco.com>
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,11 @@
+ver 1.14:
+ Fix issue with scanning property and quick scan cancellation.
+ Fix issue with handling authentication timeouts from SAE.
+ Fix issue with handling association timeouts and retries.
+ Fix issue with handling roaming frequencies after roaming.
+ Fix issue with requesting neighbor report after roaming.
+ Add support for handling PSK offload connections.
+
ver 1.13:
Fix issue with EAPoL protocol version 2010 handling.
Fix issue with authenticator method logic handling.
diff --git a/Makefile.am b/Makefile.am
@@ -632,6 +632,7 @@ unit/tls-settings.8021x: unit/cert-ca.pem unit/cert-client.pem unit/cert-client-
BUILT_SOURCES = $(ell_built_sources) src/builtin.h
ell/shared: Makefile
+ $(AM_V_at)$(MKDIR_P) ell
$(AM_V_GEN)for f in $(ell_shared) ; do \
if [ ! -f $$f ] ; then \
$(LN_S) -t ell -f $(abs_srcdir)/../ell/$$f ; \
diff --git a/autotests/testEAP-AKA-ofono/connection_test.py b/autotests/testEAP-AKA-ofono/connection_test.py
@@ -12,10 +12,7 @@ from ofono import Ofono
from config import ctx
class Test(unittest.TestCase):
-
def test_connection_success(self):
- auth = AuthCenter('/tmp/hlrauc.sock', '/tmp/sim.db')
-
ofono = Ofono()
ofono.enable_modem('/phonesim')
ofono.wait_for_sim_auth()
@@ -40,11 +37,7 @@ class Test(unittest.TestCase):
condition = 'not obj.connected'
wd.wait_for_object_condition(ordered_network.network_object, condition)
- try:
- ordered_network.network_object.connect()
- except:
- auth.stop()
- raise
+ ordered_network.network_object.connect()
condition = 'obj.state == DeviceState.connected'
wd.wait_for_object_condition(device, condition)
@@ -54,7 +47,6 @@ class Test(unittest.TestCase):
condition = 'not obj.connected'
wd.wait_for_object_condition(ordered_network.network_object, condition)
- auth.stop()
@classmethod
def setUpClass(cls):
if not ctx.is_process_running('ofonod'):
@@ -62,9 +54,14 @@ class Test(unittest.TestCase):
IWD.copy_to_storage('ssidEAP-AKA.8021x')
+ cls.auth = AuthCenter('/tmp/hlrauc.sock', '/tmp/sim.db')
+
@classmethod
def tearDownClass(cls):
IWD.clear_storage()
+ cls.auth.stop()
+ cls.auth = None
+
if __name__ == '__main__':
unittest.main(exit=True)
diff --git a/autotests/testEAP-AKA-prime-ofono/connection_test.py b/autotests/testEAP-AKA-prime-ofono/connection_test.py
@@ -12,10 +12,7 @@ from ofono import Ofono
from config import ctx
class Test(unittest.TestCase):
-
def test_connection_success(self):
- auth = AuthCenter('/tmp/hlrauc.sock', '/tmp/sim.db')
-
ofono = Ofono()
ofono.enable_modem('/phonesim')
ofono.wait_for_sim_auth()
@@ -40,11 +37,7 @@ class Test(unittest.TestCase):
condition = 'not obj.connected'
wd.wait_for_object_condition(ordered_network.network_object, condition)
- try:
- ordered_network.network_object.connect()
- except:
- auth.stop()
- raise
+ ordered_network.network_object.connect()
condition = 'obj.state == DeviceState.connected'
wd.wait_for_object_condition(device, condition)
@@ -54,8 +47,6 @@ class Test(unittest.TestCase):
condition = 'not obj.connected'
wd.wait_for_object_condition(ordered_network.network_object, condition)
- auth.stop()
-
@classmethod
def setUpClass(cls):
if not ctx.is_process_running('ofonod'):
@@ -63,9 +54,13 @@ class Test(unittest.TestCase):
IWD.copy_to_storage('ssidEAP-AKA.8021x')
+ cls.auth = AuthCenter('/tmp/hlrauc.sock', '/tmp/sim.db')
+
@classmethod
def tearDownClass(cls):
IWD.clear_storage()
+ cls.auth.stop()
+ cls.auth = None
if __name__ == '__main__':
unittest.main(exit=True)
diff --git a/autotests/testEAP-PEAP-SIM/connection_test.py b/autotests/testEAP-PEAP-SIM/connection_test.py
@@ -44,26 +44,26 @@ class Test(unittest.TestCase):
def test_connection_success(self):
- auth = AuthCenter('/tmp/hlrauc.sock', '/tmp/sim.db')
-
ofono = Ofono()
ofono.enable_modem('/phonesim')
ofono.wait_for_sim_auth()
wd = IWD(True)
- try:
- self.validate_connection(wd)
- finally:
- auth.stop()
+ self.validate_connection(wd)
@classmethod
def setUpClass(cls):
+ cls.auth = AuthCenter('/tmp/hlrauc.sock', '/tmp/sim.db')
+
IWD.copy_to_storage('ssidEAP-PEAP-SIM.8021x')
@classmethod
def tearDownClass(cls):
IWD.clear_storage()
+ cls.auth.stop()
+ cls.auth = None
+
if __name__ == '__main__':
unittest.main(exit=True)
diff --git a/autotests/testEAP-SIM-ofono/connection_test.py b/autotests/testEAP-SIM-ofono/connection_test.py
@@ -14,8 +14,6 @@ from config import ctx
class Test(unittest.TestCase):
def test_connection_success(self):
- auth = AuthCenter('/tmp/hlrauc.sock', '/tmp/sim.db')
-
ofono = Ofono()
ofono.enable_modem('/phonesim')
ofono.wait_for_sim_auth()
@@ -40,11 +38,7 @@ class Test(unittest.TestCase):
condition = 'not obj.connected'
wd.wait_for_object_condition(ordered_network.network_object, condition)
- try:
- ordered_network.network_object.connect()
- except:
- auth.stop()
- raise
+ ordered_network.network_object.connect()
condition = 'obj.state == DeviceState.connected'
wd.wait_for_object_condition(device, condition)
@@ -54,8 +48,6 @@ class Test(unittest.TestCase):
condition = 'not obj.connected'
wd.wait_for_object_condition(ordered_network.network_object, condition)
- auth.stop()
-
@classmethod
def setUpClass(cls):
if not ctx.is_process_running('ofonod'):
@@ -63,9 +55,14 @@ class Test(unittest.TestCase):
IWD.copy_to_storage('ssidEAP-SIM.8021x')
+ cls.auth = AuthCenter('/tmp/hlrauc.sock', '/tmp/sim.db')
+
@classmethod
def tearDownClass(cls):
IWD.clear_storage()
+ cls.auth.stop()
+ cls.auth = None
+
if __name__ == '__main__':
unittest.main(exit=True)
diff --git a/autotests/testFT-PSK-roam/connection_test.py b/autotests/testFT-PSK-roam/connection_test.py
@@ -98,6 +98,25 @@ class Test(unittest.TestCase):
self.assertRaises(Exception, testutil.test_ifaces_connected,
(self.bss_hostapd[0].ifname, device.name))
+ rule0.signal = -2000
+ rule1.signal = -8000
+
+ condition = 'obj.state == DeviceState.roaming'
+ wd.wait_for_object_condition(device, condition)
+
+ # Check that iwd is on BSS 0 once out of roaming state and doesn't
+ # go through 'disconnected', 'autoconnect', 'connecting' in between
+ from_condition = 'obj.state == DeviceState.roaming'
+ to_condition = 'obj.state == DeviceState.connected'
+ wd.wait_for_object_change(device, from_condition, to_condition)
+
+ self.assertTrue(self.bss_hostapd[0].list_sta())
+
+ testutil.test_iface_operstate(device.name)
+ testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name)
+ self.assertRaises(Exception, testutil.test_ifaces_connected,
+ (self.bss_hostapd[1].ifname, device.name))
+
def tearDown(self):
os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" down')
os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" down')
diff --git a/autotests/testNetconfig/ssidTKIP.psk b/autotests/testNetconfig/ssidTKIP.psk
@@ -0,0 +1,6 @@
+[IPv4]
+Address=192.168.1.10
+Gateway=192.168.1.1
+
+[Settings]
+AutoConnect=false
diff --git a/autotests/testOWE/timeout_test.py b/autotests/testOWE/timeout_test.py
@@ -45,6 +45,14 @@ class Test(unittest.TestCase):
rule0.source = bss_radio.addresses[0]
rule0.bidirectional = True
rule0.drop = True
+ rule0.prefix = 'b0'
+
+ # Test Authenticate (b0) and Association (00) timeouts
+
+ with self.assertRaises(iwd.FailedEx):
+ ordered_network.network_object.connect()
+
+ rule0.prefix = '00'
with self.assertRaises(iwd.FailedEx):
ordered_network.network_object.connect()
diff --git a/autotests/testSAE/hw.conf b/autotests/testSAE/hw.conf
@@ -1,7 +1,6 @@
[SETUP]
num_radios=7
start_iwd=0
-hwsim_medium=no
[HOSTAPD]
rad0=ssidSAE.conf
diff --git a/autotests/testSAE/timeout_test.py b/autotests/testSAE/timeout_test.py
@@ -0,0 +1,83 @@
+#!/usr/bin/python3
+
+import unittest
+import sys
+
+sys.path.append('../util')
+import iwd
+from iwd import IWD
+from iwd import PSKAgent
+from iwd import NetworkType
+from hwsim import Hwsim
+
+class Test(unittest.TestCase):
+
+ def validate_connection(self, wd):
+ hwsim = Hwsim()
+ bss_radio = hwsim.get_radio('rad0')
+
+ psk_agent = PSKAgent(["secret123", "secret123"])
+ wd.register_psk_agent(psk_agent)
+
+ devices = wd.list_devices(4)
+
+ # These devices aren't used in this test, this makes logs a bit nicer
+ # since these devices would presumably start autoconnecting.
+ devices[1].disconnect()
+ devices[2].disconnect()
+ devices[3].disconnect()
+
+ self.assertIsNotNone(devices)
+ device = devices[0]
+
+ condition = 'not obj.scanning'
+ wd.wait_for_object_condition(device, condition)
+
+ device.scan()
+
+ condition = 'not obj.scanning'
+ wd.wait_for_object_condition(device, condition)
+
+ network = device.get_ordered_network('ssidSAE')
+
+ self.assertEqual(network.type, NetworkType.psk)
+
+ condition = 'not obj.connected'
+ wd.wait_for_object_condition(network.network_object, condition)
+
+ rule0 = hwsim.rules.create()
+ rule0.source = bss_radio.addresses[0]
+ rule0.bidirectional = True
+ rule0.drop = True
+ rule0.prefix = 'b0'
+
+ wd.wait(1)
+ print(rule0)
+
+ with self.assertRaises(iwd.FailedEx):
+ network.network_object.connect()
+
+ condition = 'not obj.connected'
+ wd.wait_for_object_condition(network.network_object, condition)
+
+ rule0.prefix = '00'
+ with self.assertRaises(iwd.FailedEx):
+ network.network_object.connect()
+
+ wd.unregister_psk_agent(psk_agent)
+
+ def test_connection_success(self):
+ wd = IWD(True)
+
+ self.validate_connection(wd)
+
+ @classmethod
+ def setUpClass(cls):
+ pass
+
+ @classmethod
+ def tearDownClass(cls):
+ IWD.clear_storage()
+
+if __name__ == '__main__':
+ unittest.main(exit=True)
diff --git a/autotests/util/hwsim.py b/autotests/util/hwsim.py
@@ -132,6 +132,16 @@ class Rule(HwsimDBusAbstract):
reply_handler=self._success, error_handler=self._failure)
self._wait_for_async_op()
+ @property
+ def prefix(self):
+ return self._properties['Prefix']
+
+ @prefix.setter
+ def prefix(self, value):
+ self._prop_proxy.Set(self._iface_name, 'Prefix', dbus.ByteArray.fromhex(value),
+ reply_handler=self._success, error_handler=self._failure)
+ self._wait_for_async_op()
+
def remove(self):
self._iface.Remove(reply_handler=self._success,
error_handler=self._failure)
@@ -150,7 +160,8 @@ class Rule(HwsimDBusAbstract):
prefix + '\tPriority:\t' + str(self.priority) + '\n' +\
prefix + '\tFrequency:\t' + str(self.frequency) + '\n' + \
prefix + '\tApply rssi:\t' + str(self.signal) + '\n' + \
- prefix + '\tApply drop:\t' + str(self.drop) + '\n'
+ prefix + '\tApply drop:\t' + str(self.drop) + '\n' + \
+ prefix + '\tPrefix:\t' + str([hex(b) for b in self.prefix]) + '\n'
class RuleSet(collections.Mapping):
def __init__(self, hwsim, objects):
diff --git a/autotests/util/iwd.py b/autotests/util/iwd.py
@@ -1064,7 +1064,8 @@ class IWD(AsyncOpAbstract):
# If neither the initial or expected condition evaluate the
# object must be in another unexpected state.
if not eval(from_str) and not eval(to_str):
- raise Exception('unexpected condition between [%s] and [%s]' % from_str, to_str)
+ raise Exception('unexpected condition between [%s] and [%s]' %
+ (from_str, to_str))
# Initial condition does not evaluate but expected does, pass
if not eval(from_str) and eval(to_str):
diff --git a/client/diagnostic.c b/client/diagnostic.c
@@ -92,6 +92,7 @@ static const struct diagnostic_dict_mapping diagnostic_mapping[] = {
{ "RxMCS", 'y' },
{ "TxMCS", 'y' },
{ "Frequency", 'u' },
+ { "Security", 's' },
{ NULL }
};
diff --git a/client/station.c b/client/station.c
@@ -352,7 +352,7 @@ static void ordered_networks_display(struct l_queue *ordered_networks)
display_table_header("Available networks", "%s%-*s%-*s%-*s%*s",
MARGIN, 2, "", 32, "Network name",
- 10, "Security", 6, "Signal");
+ 18, "Security", 6, "Signal");
if (!l_queue_length(ordered_networks)) {
display("No networks available\n");
@@ -369,13 +369,16 @@ static void ordered_networks_display(struct l_queue *ordered_networks)
const char *network_name = network_get_name(network_i);
const char *network_type = network_get_type(network_i);
+ if (!strcmp(network_type, "wep"))
+ network_type = "wep (unsupported)";
+
if (display_signal_as_dbms)
dbms = l_strdup_printf("%d", network->signal_strength);
display("%s%-*s%-*s%-*s%-*s\n", MARGIN, 2,
network_is_connected(network_i) ?
COLOR_BOLDGRAY "> " COLOR_OFF : "",
- 32, network_name, 10, network_type,
+ 32, network_name, 18, network_type,
6, display_signal_as_dbms ? dbms :
dbms_tostars(network->signal_strength));
@@ -612,7 +615,6 @@ static void get_diagnostics_callback(struct l_dbus_message *message,
done:
/* Finish the table started by cmd_show */
display_table_footer();
- display_refresh_reset();
}
static enum cmd_status cmd_show(const char *device_name,
@@ -637,7 +639,6 @@ static enum cmd_status cmd_show(const char *device_name,
*/
if (!diagnostic) {
display_table_footer();
- display_refresh_reset();
return CMD_STATUS_DONE;
}
diff --git a/configure.ac b/configure.ac
@@ -1,5 +1,5 @@
AC_PREREQ(2.60)
-AC_INIT(iwd, 1.13)
+AC_INIT(iwd, 1.14)
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.39"
+ ell_min_version="0.40"
else
ell_min_version="0.5"
fi
diff --git a/doc/station-diagnostic-api.txt b/doc/station-diagnostic-api.txt
@@ -23,6 +23,8 @@ Methods dict GetDiagnostics()
Frequency - Frequency of currently connected BSS.
+ Security - The chosen security for the connection.
+
RSSI [optional] - The RSSI of the currently connected BSS.
AverageRSSI [optional] - Average RSSI of currently connected BSS.
diff --git a/linux/nl80211.h b/linux/nl80211.h
@@ -655,6 +655,9 @@
* When a security association was established on an 802.1X network using
* fast transition, this event should be followed by an
* %NL80211_CMD_PORT_AUTHORIZED event.
+ * Following a %NL80211_CMD_ROAM event userspace can issue
+ * %NL80211_CMD_GET_SCAN in order to obtain the scan information for the
+ * new BSS the card/driver roamed to.
* @NL80211_CMD_DISCONNECT: drop a given connection; also used to notify
* userspace that a connection was dropped by the AP or due to other
* reasons, for this the %NL80211_ATTR_DISCONNECTED_BY_AP and
@@ -1963,8 +1966,15 @@ enum nl80211_commands {
* @NL80211_ATTR_PROBE_RESP: Probe Response template data. Contains the entire
* probe-response frame. The DA field in the 802.11 header is zero-ed out,
* to be filled by the FW.
- * @NL80211_ATTR_DISABLE_HT: Force HT capable interfaces to disable
- * this feature. Currently, only supported in mac80211 drivers.
+ * @NL80211_ATTR_DISABLE_HT: Force HT capable interfaces to disable
+ * this feature during association. This is a flag attribute.
+ * Currently only supported in mac80211 drivers.
+ * @NL80211_ATTR_DISABLE_VHT: Force VHT capable interfaces to disable
+ * this feature during association. This is a flag attribute.
+ * Currently only supported in mac80211 drivers.
+ * @NL80211_ATTR_DISABLE_HE: Force HE capable interfaces to disable
+ * this feature during association. This is a flag attribute.
+ * Currently only supported in mac80211 drivers.
* @NL80211_ATTR_HT_CAPABILITY_MASK: Specify which bits of the
* ATTR_HT_CAPABILITY to which attention should be paid.
* Currently, only mac80211 NICs support this feature.
@@ -3045,6 +3055,8 @@ enum nl80211_attrs {
NL80211_ATTR_SAR_SPEC,
+ NL80211_ATTR_DISABLE_HE,
+
/* add attributes here, update the policy in nl80211.c */
__NL80211_ATTR_AFTER_LAST,
@@ -5928,6 +5940,16 @@ enum nl80211_feature_flags {
* @NL80211_EXT_FEATURE_BEACON_RATE_HE: Driver supports beacon rate
* configuration (AP/mesh) with HE rates.
*
+ * @NL80211_EXT_FEATURE_SECURE_LTF: Device supports secure LTF measurement
+ * exchange protocol.
+ *
+ * @NL80211_EXT_FEATURE_SECURE_RTT: Device supports secure RTT measurement
+ * exchange protocol.
+ *
+ * @NL80211_EXT_FEATURE_PROT_RANGE_NEGO_AND_MEASURE: Device supports management
+ * frame protection for all management frames exchanged during the
+ * negotiation and range measurement procedure.
+ *
* @NUM_NL80211_EXT_FEATURES: number of extended features.
* @MAX_NL80211_EXT_FEATURES: highest extended feature index.
*/
@@ -5989,6 +6011,9 @@ enum nl80211_ext_feature_index {
NL80211_EXT_FEATURE_FILS_DISCOVERY,
NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP,
NL80211_EXT_FEATURE_BEACON_RATE_HE,
+ NL80211_EXT_FEATURE_SECURE_LTF,
+ NL80211_EXT_FEATURE_SECURE_RTT,
+ NL80211_EXT_FEATURE_PROT_RANGE_NEGO_AND_MEASURE,
/* add new features before the definition below */
NUM_NL80211_EXT_FEATURES,
@@ -6286,11 +6311,13 @@ struct nl80211_vendor_cmd_info {
* @NL80211_TDLS_PEER_HT: TDLS peer is HT capable.
* @NL80211_TDLS_PEER_VHT: TDLS peer is VHT capable.
* @NL80211_TDLS_PEER_WMM: TDLS peer is WMM capable.
+ * @NL80211_TDLS_PEER_HE: TDLS peer is HE capable.
*/
enum nl80211_tdls_peer_capability {
NL80211_TDLS_PEER_HT = 1<<0,
NL80211_TDLS_PEER_VHT = 1<<1,
NL80211_TDLS_PEER_WMM = 1<<2,
+ NL80211_TDLS_PEER_HE = 1<<3,
};
/**
@@ -6882,6 +6909,9 @@ enum nl80211_peer_measurement_ftm_capa {
* if neither %NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED nor
* %NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED is set, EDCA based
* ranging will be used.
+ * @NL80211_PMSR_FTM_REQ_ATTR_LMR_FEEDBACK: negotiate for LMR feedback. Only
+ * valid if either %NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED or
+ * %NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED is set.
*
* @NUM_NL80211_PMSR_FTM_REQ_ATTR: internal
* @NL80211_PMSR_FTM_REQ_ATTR_MAX: highest attribute number
@@ -6900,6 +6930,7 @@ enum nl80211_peer_measurement_ftm_req {
NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC,
NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED,
NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED,
+ NL80211_PMSR_FTM_REQ_ATTR_LMR_FEEDBACK,
/* keep last */
NUM_NL80211_PMSR_FTM_REQ_ATTR,
diff --git a/src/adhoc.c b/src/adhoc.c
@@ -494,6 +494,11 @@ static void adhoc_join_cb(struct netdev *netdev, int result, void *user_data)
return;
}
+ l_rtnl_set_linkmode_and_operstate(iwd_get_rtnl(),
+ netdev_get_ifindex(adhoc->netdev),
+ IF_LINK_MODE_DEFAULT, IF_OPER_UP,
+ NULL, NULL, NULL);
+
adhoc->sta_watch_id = netdev_station_watch_add(netdev,
adhoc_station_changed_cb, adhoc);
@@ -649,6 +654,11 @@ static struct l_dbus_message *adhoc_dbus_stop(struct l_dbus *dbus,
if (netdev_leave_adhoc(adhoc->netdev, adhoc_leave_cb, adhoc))
return dbus_error_failed(message);
+ l_rtnl_set_linkmode_and_operstate(iwd_get_rtnl(),
+ netdev_get_ifindex(adhoc->netdev),
+ IF_LINK_MODE_DORMANT, IF_OPER_DOWN,
+ NULL, NULL, NULL);
+
adhoc->pending = l_dbus_message_ref(message);
return NULL;
diff --git a/src/agent.c b/src/agent.c
@@ -564,6 +564,9 @@ static void agent_disconnect(struct l_dbus *dbus, void *user_data)
l_debug("agent %s disconnected", agent->owner);
+ if (agent->pending_id)
+ agent_finalize_pending(agent, NULL);
+
l_queue_remove(agents, agent);
l_idle_oneshot(agent_free, agent, NULL);
diff --git a/src/ap.c b/src/ap.c
@@ -28,6 +28,7 @@
#include <linux/if_ether.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <linux/if.h>
#include <ell/ell.h>
@@ -61,7 +62,15 @@ struct ap_state {
const struct ap_ops *ops;
ap_stopped_func_t stopped_func;
void *user_data;
- struct ap_config *config;
+
+ char ssid[33];
+ char passphrase[64];
+ uint8_t psk[32];
+ uint8_t channel;
+ uint8_t *authorized_macs;
+ unsigned int authorized_macs_num;
+ char wsc_name[33];
+ struct wsc_primary_device_type wsc_primary_device_type;
unsigned int ciphers;
enum ie_rsn_cipher_suite group_cipher;
@@ -228,24 +237,6 @@ static const char *broadcast_from_ip(const char *ip)
return inet_ntoa(ia);
}
-void ap_config_free(struct ap_config *config)
-{
- if (unlikely(!config))
- return;
-
- l_free(config->ssid);
-
- explicit_bzero(config->passphrase, sizeof(config->passphrase));
- explicit_bzero(config->psk, sizeof(config->psk));
- l_free(config->authorized_macs);
- l_free(config->wsc_name);
-
- if (config->profile)
- l_free(config->profile);
-
- l_free(config);
-}
-
static void ap_stop_handshake(struct sta_state *sta)
{
if (sta->sm) {
@@ -281,7 +272,9 @@ static void ap_sta_free(void *data)
struct sta_state *sta = data;
struct ap_state *ap = sta->ap;
- l_uintset_free(sta->rates);
+ if (sta->rates)
+ l_uintset_free(sta->rates);
+
l_free(sta->assoc_ies);
if (sta->assoc_resp_cmd_id)
@@ -299,6 +292,14 @@ static void ap_reset(struct ap_state *ap)
{
struct netdev *netdev = ap->netdev;
+ explicit_bzero(ap->passphrase, sizeof(ap->passphrase));
+ explicit_bzero(ap->psk, sizeof(ap->psk));
+
+ if (ap->authorized_macs_num) {
+ l_free(ap->authorized_macs);
+ ap->authorized_macs_num = 0;
+ }
+
if (ap->mlme_watch)
l_genl_family_unregister(ap->nl80211, ap->mlme_watch);
@@ -315,9 +316,6 @@ static void ap_reset(struct ap_state *ap)
if (ap->rates)
l_uintset_free(ap->rates);
- ap_config_free(ap->config);
- ap->config = NULL;
-
l_queue_destroy(ap->wsc_pbc_probes, l_free);
ap->started = false;
@@ -609,6 +607,20 @@ static void ap_process_wsc_probe_req(struct ap_state *ap, const uint8_t *from,
}
}
+static void ap_write_authorized_macs(struct ap_state *ap,
+ size_t out_len, uint8_t *out)
+{
+ size_t len = ap->authorized_macs_num * 6;
+
+ if (!len)
+ return;
+
+ if (len > out_len)
+ len = out_len;
+
+ memcpy(out, ap->authorized_macs, len);
+}
+
static size_t ap_get_wsc_ie_len(struct ap_state *ap,
enum mpdu_management_subtype type,
const struct mmpdu_header *client_frame,
@@ -664,27 +676,17 @@ static size_t ap_write_wsc_ie(struct ap_state *ap,
wsc_pr.response_type = WSC_RESPONSE_TYPE_AP;
memcpy(wsc_pr.uuid_e, ap->wsc_uuid_r, sizeof(wsc_pr.uuid_e));
- wsc_pr.primary_device_type =
- ap->config->wsc_primary_device_type;
+ wsc_pr.primary_device_type = ap->wsc_primary_device_type;
- if (ap->config->wsc_name)
- l_strlcpy(wsc_pr.device_name, ap->config->wsc_name,
+ if (ap->wsc_name[0] != '\0')
+ l_strlcpy(wsc_pr.device_name, ap->wsc_name,
sizeof(wsc_pr.device_name));
wsc_pr.config_methods =
WSC_CONFIGURATION_METHOD_PUSH_BUTTON;
- if (ap->config->authorized_macs_num) {
- size_t len;
-
- len = ap->config->authorized_macs_num * 6;
- if (len > sizeof(wsc_pr.authorized_macs))
- len = sizeof(wsc_pr.authorized_macs);
-
- memcpy(wsc_pr.authorized_macs,
- ap->config->authorized_macs, len);
- }
-
+ ap_write_authorized_macs(ap, sizeof(wsc_pr.authorized_macs),
+ wsc_pr.authorized_macs);
wsc_data = wsc_build_probe_response(&wsc_pr, &wsc_data_size);
} else if (type == MPDU_MANAGEMENT_SUBTYPE_BEACON) {
struct wsc_beacon wsc_beacon = {};
@@ -699,17 +701,8 @@ static size_t ap_write_wsc_ie(struct ap_state *ap,
WSC_CONFIGURATION_METHOD_PUSH_BUTTON;
}
- if (ap->config->authorized_macs_num) {
- size_t len;
-
- len = ap->config->authorized_macs_num * 6;
- if (len > sizeof(wsc_beacon.authorized_macs))
- len = sizeof(wsc_beacon.authorized_macs);
-
- memcpy(wsc_beacon.authorized_macs,
- ap->config->authorized_macs, len);
- }
-
+ ap_write_authorized_macs(ap, sizeof(wsc_beacon.authorized_macs),
+ wsc_beacon.authorized_macs);
wsc_data = wsc_build_beacon(&wsc_beacon, &wsc_data_size);
} else if (L_IN_SET(type, MPDU_MANAGEMENT_SUBTYPE_ASSOCIATION_RESPONSE,
MPDU_MANAGEMENT_SUBTYPE_REASSOCIATION_RESPONSE)) {
@@ -829,8 +822,7 @@ static size_t ap_build_beacon_pr_head(struct ap_state *ap,
/* SSID IE */
ie_tlv_builder_next(&builder, IE_TYPE_SSID);
- ie_tlv_builder_set_data(&builder, ap->config->ssid,
- strlen(ap->config->ssid));
+ ie_tlv_builder_set_data(&builder, ap->ssid, strlen(ap->ssid));
/* Supported Rates IE */
ie_tlv_builder_next(&builder, IE_TYPE_SUPPORTED_RATES);
@@ -855,7 +847,7 @@ static size_t ap_build_beacon_pr_head(struct ap_state *ap,
/* DSSS Parameter Set IE for DSSS, HR, ERP and HT PHY rates */
ie_tlv_builder_next(&builder, IE_TYPE_DSSS_PARAMETER_SET);
- ie_tlv_builder_set_data(&builder, &ap->config->channel, 1);
+ ie_tlv_builder_set_data(&builder, &ap->channel, 1);
ie_tlv_builder_finalize(&builder, &len);
return 36 + len;
@@ -936,8 +928,7 @@ static uint32_t ap_send_mgmt_frame(struct ap_state *ap,
frame_xchg_cb_t callback,
void *user_data)
{
- uint32_t ch_freq = scan_channel_to_freq(ap->config->channel,
- SCAN_BAND_2_4_GHZ);
+ uint32_t ch_freq = scan_channel_to_freq(ap->channel, SCAN_BAND_2_4_GHZ);
uint64_t wdev_id = netdev_get_wdev_id(ap->netdev);
struct iovec iov[2];
@@ -956,8 +947,7 @@ static void ap_start_handshake(struct sta_state *sta, bool use_eapol_start,
struct ie_rsn_info rsn;
uint8_t bss_rsne[64];
- handshake_state_set_ssid(sta->hs, (void *) ap->config->ssid,
- strlen(ap->config->ssid));
+ handshake_state_set_ssid(sta->hs, (void *) ap->ssid, strlen(ap->ssid));
handshake_state_set_authenticator_address(sta->hs, own_addr);
handshake_state_set_supplicant_address(sta->hs, sta->addr);
@@ -1024,7 +1014,7 @@ static void ap_start_rsna(struct sta_state *sta, const uint8_t *gtk_rsc)
handshake_state_set_authenticator(sta->hs, true);
handshake_state_set_event_func(sta->hs, ap_handshake_event, sta);
handshake_state_set_supplicant_ie(sta->hs, sta->assoc_rsne);
- handshake_state_set_pmk(sta->hs, sta->ap->config->psk, 32);
+ handshake_state_set_pmk(sta->hs, sta->ap->psk, 32);
ap_start_handshake(sta, false, gtk_rsc);
}
@@ -1142,16 +1132,15 @@ static void ap_start_eap_wsc(struct sta_state *sta)
WSC_RF_BAND_2_4_GHZ);
l_settings_set_uint(sta->wsc_settings, "WSC", "ConfigurationMethods",
WSC_CONFIGURATION_METHOD_PUSH_BUTTON);
- l_settings_set_string(sta->wsc_settings, "WSC", "WPA2-SSID",
- ap->config->ssid);
+ l_settings_set_string(sta->wsc_settings, "WSC", "WPA2-SSID", ap->ssid);
- if (ap->config->passphrase[0])
+ if (ap->passphrase[0])
l_settings_set_string(sta->wsc_settings,
"WSC", "WPA2-Passphrase",
- ap->config->passphrase);
+ ap->passphrase);
else
l_settings_set_bytes(sta->wsc_settings,
- "WSC", "WPA2-PSK", ap->config->psk, 32);
+ "WSC", "WPA2-PSK", ap->psk, 32);
sta->hs = netdev_handshake_state_new(ap->netdev);
handshake_state_set_authenticator(sta->hs, true);
@@ -1609,8 +1598,8 @@ static void ap_assoc_reassoc(struct sta_state *sta, bool reassoc,
}
if (!rates || !ssid || (!wsc_data && !rsn) ||
- ssid_len != strlen(ap->config->ssid) ||
- memcmp(ssid, ap->config->ssid, ssid_len)) {
+ ssid_len != strlen(ap->ssid) ||
+ memcmp(ssid, ap->ssid, ssid_len)) {
err = MMPDU_REASON_CODE_INVALID_IE;
goto bad_frame;
}
@@ -1875,10 +1864,8 @@ static void ap_probe_req_cb(const struct mmpdu_header *hdr, const void *body,
struct ie_tlv_iter iter;
const uint8_t *bssid = netdev_get_address(ap->netdev);
bool match = false;
- L_AUTO_FREE_VAR(uint8_t *, resp) =
- l_malloc(512 + ap_get_extra_ies_len(ap,
- MPDU_MANAGEMENT_SUBTYPE_PROBE_RESPONSE, hdr,
- body + body_len - (void *) hdr));
+ uint32_t resp_len;
+ uint8_t *resp;
l_info("AP Probe Request from %s",
util_address_to_string(hdr->address_2));
@@ -1920,11 +1907,11 @@ static void ap_probe_req_cb(const struct mmpdu_header *hdr, const void *body,
if (!ssid || ssid_len == 0) /* Wildcard SSID */
match = true;
- else if (ssid && ssid_len == strlen(ap->config->ssid) && /* One SSID */
- !memcmp(ssid, ap->config->ssid, ssid_len))
+ else if (ssid && ssid_len == strlen(ap->ssid) && /* One SSID */
+ !memcmp(ssid, ap->ssid, ssid_len))
match = true;
else if (ssid && ssid_len == 7 && !memcmp(ssid, "DIRECT-", 7) &&
- !memcmp(ssid, ap->config->ssid, 7)) /* P2P wildcard */
+ !memcmp(ssid, ap->ssid, 7)) /* P2P wildcard */
match = true;
else if (ssid_list) { /* SSID List */
ie_tlv_iter_init(&iter, ssid_list, ssid_list_len);
@@ -1936,24 +1923,27 @@ static void ap_probe_req_cb(const struct mmpdu_header *hdr, const void *body,
ssid = (const char *) ie_tlv_iter_get_data(&iter);
ssid_len = ie_tlv_iter_get_length(&iter);
- if (ssid_len == strlen(ap->config->ssid) &&
- !memcmp(ssid, ap->config->ssid,
- ssid_len)) {
+ if (ssid_len == strlen(ap->ssid) &&
+ !memcmp(ssid, ap->ssid, ssid_len)) {
match = true;
break;
}
}
}
- if (dsss_channel != 0 && dsss_channel != ap->config->channel)
+ if (dsss_channel != 0 && dsss_channel != ap->channel)
match = false;
if (!match)
return;
+ resp_len = 512 + ap_get_extra_ies_len(ap,
+ MPDU_MANAGEMENT_SUBTYPE_PROBE_RESPONSE,
+ hdr, body + body_len - (void *) hdr);
+ resp = l_new(uint8_t, resp_len);
len = ap_build_beacon_pr_head(ap,
MPDU_MANAGEMENT_SUBTYPE_PROBE_RESPONSE,
- hdr->address_2, resp, sizeof(resp));
+ hdr->address_2, resp, resp_len);
len += ap_build_beacon_pr_tail(ap,
MPDU_MANAGEMENT_SUBTYPE_PROBE_RESPONSE,
hdr, body + body_len - (void *) hdr,
@@ -1961,6 +1951,7 @@ static void ap_probe_req_cb(const struct mmpdu_header *hdr, const void *body,
ap_send_mgmt_frame(ap, (struct mmpdu_header *) resp, len,
ap_probe_resp_cb, NULL);
+ l_free(resp);
}
/* 802.11-2016 9.3.3.5 (frame format), 802.11-2016 11.3.5.9 (MLME/SME) */
@@ -2051,15 +2042,15 @@ static void ap_auth_cb(const struct mmpdu_header *hdr, const void *body,
memcmp(hdr->address_3, bssid, 6))
return;
- if (ap->config->authorized_macs_num) {
+ if (ap->authorized_macs_num) {
unsigned int i;
- for (i = 0; i < ap->config->authorized_macs_num; i++)
- if (!memcmp(from, ap->config->authorized_macs + i * 6,
+ for (i = 0; i < ap->authorized_macs_num; i++)
+ if (!memcmp(from, ap->authorized_macs + i * 6,
6))
break;
- if (i == ap->config->authorized_macs_num) {
+ if (i == ap->authorized_macs_num) {
ap_auth_reply(ap, from, MMPDU_REASON_CODE_UNSPECIFIED);
return;
}
@@ -2208,8 +2199,7 @@ static struct l_genl_msg *ap_build_cmd_start_ap(struct ap_state *ap)
uint32_t nl_akm = CRYPTO_AKM_PSK;
uint32_t wpa_version = NL80211_WPA_VERSION_2;
uint32_t auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
- uint32_t ch_freq = scan_channel_to_freq(ap->config->channel,
- SCAN_BAND_2_4_GHZ);
+ uint32_t ch_freq = scan_channel_to_freq(ap->channel, SCAN_BAND_2_4_GHZ);
uint32_t ch_width = NL80211_CHAN_WIDTH_20;
unsigned int i;
@@ -2231,7 +2221,7 @@ static struct l_genl_msg *ap_build_cmd_start_ap(struct ap_state *ap)
return NULL;
cmd = l_genl_msg_new_sized(NL80211_CMD_START_AP, 256 + head_len +
- tail_len + strlen(ap->config->ssid));
+ tail_len + strlen(ap->ssid));
/* SET_BEACON attrs */
l_genl_msg_append_attr(cmd, NL80211_ATTR_BEACON_HEAD, head_len, head);
@@ -2245,8 +2235,8 @@ static struct l_genl_msg *ap_build_cmd_start_ap(struct ap_state *ap)
&ap->beacon_interval);
l_genl_msg_append_attr(cmd, NL80211_ATTR_DTIM_PERIOD, 4, &dtim_period);
l_genl_msg_append_attr(cmd, NL80211_ATTR_IFINDEX, 4, &ifindex);
- l_genl_msg_append_attr(cmd, NL80211_ATTR_SSID, strlen(ap->config->ssid),
- ap->config->ssid);
+ l_genl_msg_append_attr(cmd, NL80211_ATTR_SSID, strlen(ap->ssid),
+ ap->ssid);
l_genl_msg_append_attr(cmd, NL80211_ATTR_HIDDEN_SSID, 4,
&hidden_ssid);
l_genl_msg_append_attr(cmd, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
@@ -2329,7 +2319,11 @@ static bool ap_parse_new_station_ies(const void *data, uint16_t len,
}
*rsn_out = rsn;
- *rates_out = rates;
+
+ if (rates_out)
+ *rates_out = rates;
+ else
+ l_uintset_free(rates);
return true;
@@ -2352,7 +2346,6 @@ static void ap_handle_new_station(struct ap_state *ap, struct l_genl_msg *msg)
const void *data;
uint8_t mac[6];
uint8_t *assoc_rsne = NULL;
- struct l_uintset *rates = NULL;
if (!l_genl_attr_init(&attr, msg))
return;
@@ -2360,11 +2353,11 @@ static void ap_handle_new_station(struct ap_state *ap, struct l_genl_msg *msg)
while (l_genl_attr_next(&attr, &type, &len, &data)) {
switch (type) {
case NL80211_ATTR_IE:
- if (assoc_rsne || rates)
+ if (assoc_rsne)
goto cleanup;
if (!ap_parse_new_station_ies(data, len, &assoc_rsne,
- &rates))
+ NULL))
return;
break;
case NL80211_ATTR_MAC:
@@ -2376,7 +2369,7 @@ static void ap_handle_new_station(struct ap_state *ap, struct l_genl_msg *msg)
}
}
- if (!assoc_rsne || !rates)
+ if (!assoc_rsne)
goto cleanup;
/*
@@ -2391,7 +2384,6 @@ static void ap_handle_new_station(struct ap_state *ap, struct l_genl_msg *msg)
memcpy(sta->addr, mac, 6);
sta->ap = ap;
sta->assoc_rsne = assoc_rsne;
- sta->rates = rates;
sta->aid = ++ap->last_aid;
sta->associated = true;
@@ -2415,7 +2407,6 @@ static void ap_handle_new_station(struct ap_state *ap, struct l_genl_msg *msg)
cleanup:
l_free(assoc_rsne);
- l_uintset_free(rates);
}
static void ap_handle_del_station(struct ap_state *ap, struct l_genl_msg *msg)
@@ -2492,7 +2483,8 @@ static void ap_mlme_notify(struct l_genl_msg *msg, void *user_data)
}
}
-static bool dhcp_load_settings(struct ap_state *ap, struct l_settings *settings)
+static bool dhcp_load_settings(struct ap_state *ap,
+ const struct l_settings *settings)
{
struct l_dhcp_server *server = ap->server;
struct in_addr ia;
@@ -2567,77 +2559,41 @@ error:
* 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
+ * -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, struct l_settings *settings)
+static int ap_setup_dhcp(struct ap_state *ap, const struct l_settings *settings)
{
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;
- ap->server = l_dhcp_server_new(ifindex);
- if (!ap->server) {
- l_error("Failed to create DHCP server on %u", ifindex);
- return -EINVAL;;
- }
-
- if (getenv("IWD_DHCP_DEBUG"))
- l_dhcp_server_set_debug(ap->server, do_debug,
- "[DHCPv4 SERV] ", NULL);
-
/* get the current address if there is one */
if (l_net_get_address(ifindex, &ia) && ia.s_addr != 0)
address = ia.s_addr;
- if (ap->config->profile) {
- char *addr;
-
- addr = l_settings_get_string(settings, "IPv4", "Address");
- if (addr) {
- if (inet_pton(AF_INET, addr, &ia) < 0)
- goto free_addr;
-
- /* 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
- goto free_addr;
-
- /* Set the remaining DHCP options in config file */
- if (!dhcp_load_settings(ap, settings)) {
- ret = -EINVAL;
- goto free_addr;
- }
-
- if (!l_dhcp_server_set_ip_address(ap->server, addr)) {
- ret = -EINVAL;
- goto free_addr;
- }
-
- ap->own_ip = l_strdup(addr);
-
-free_addr:
- l_free(addr);
+ addr = l_settings_get_string(settings, "IPv4", "Address");
+ if (addr) {
+ if (inet_pton(AF_INET, addr, &ia) < 0)
+ return -EINVAL;
- return ret;
+ /* Is a matching address already set on interface? */
+ if (ia.s_addr == address)
+ ret = -EALREADY;
+ else
+ ret = 0;
} else if (address) {
- /* No config file and address is already set */
- ap->own_ip = l_strdup(inet_ntoa(ia));
-
- return -EALREADY;
+ /* 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 */
- ap->own_ip = ip_pool_get();
- if (!ap->own_ip) {
+ addr = ip_pool_get();
+ if (!addr) {
l_error("No more IP's in pool, cannot start AP on %u",
ifindex);
return -EEXIST;
@@ -2645,52 +2601,41 @@ free_addr:
ap->use_ip_pool = true;
ap->ip_prefix = pool.prefix;
+ ret = 0;
+ } else
+ return -EALREADY;
- return 0;
+ ap->server = l_dhcp_server_new(ifindex);
+ if (!ap->server) {
+ l_error("Failed to create DHCP server on %u", ifindex);
+ return -EINVAL;
}
- return -EINVAL;
+ if (getenv("IWD_DHCP_DEBUG"))
+ l_dhcp_server_set_debug(ap->server, do_debug,
+ "[DHCPv4 SERV] ", NULL);
+
+ /* Set the remaining DHCP options in config file */
+ if (!dhcp_load_settings(ap, settings))
+ return -EINVAL;
+
+ if (!l_dhcp_server_set_ip_address(ap->server, addr))
+ return -EINVAL;
+
+ ap->own_ip = l_steal_ptr(addr);
+ return ret;
}
-static int ap_load_profile_and_dhcp(struct ap_state *ap, bool *wait_dhcp)
+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);
- char *passphrase;
- struct l_settings *settings = NULL;
int err = -EINVAL;
- /* No profile or DHCP settings */
- if (!ap->config->profile && !pool.used)
+ if (!l_settings_has_group(config, "IPv4"))
return 0;
- if (ap->config->profile) {
- settings = l_settings_new();
-
- if (!l_settings_load_from_file(settings, ap->config->profile))
- goto cleanup;
-
- passphrase = l_settings_get_string(settings, "Security",
- "Passphrase");
- if (passphrase) {
- if (strlen(passphrase) > 63) {
- l_error("[Security].Passphrase must not exceed "
- "63 characters");
- l_free(passphrase);
- goto cleanup;
- }
-
- strcpy(ap->config->passphrase, passphrase);
- l_free(passphrase);
- }
-
- if (!l_settings_has_group(settings, "IPv4")) {
- *wait_dhcp = false;
- err = 0;
- goto cleanup;
- }
- }
-
- err = ap_setup_dhcp(ap, settings);
+ err = ap_setup_dhcp(ap, config);
if (err == 0) {
/* Address change required */
ap->rtnl_add_cmd = l_rtnl_ifaddr4_add(rtnl, ifindex,
@@ -2700,8 +2645,7 @@ static int ap_load_profile_and_dhcp(struct ap_state *ap, bool *wait_dhcp)
if (!ap->rtnl_add_cmd) {
l_error("Failed to add IPv4 address");
- err = -EIO;
- goto cleanup;
+ return -EIO;
}
ap->cleanup_ip = true;
@@ -2714,24 +2658,201 @@ static int ap_load_profile_and_dhcp(struct ap_state *ap, bool *wait_dhcp)
err = 0;
}
-cleanup:
- l_settings_free(settings);
return err;
}
+static bool ap_load_psk(struct ap_state *ap, const struct l_settings *config)
+{
+ L_AUTO_FREE_VAR(char *, passphrase) =
+ l_settings_get_string(config, "Security", "Passphrase");
+ int err;
+
+ if (passphrase) {
+ if (strlen(passphrase) > 63) {
+ l_error("AP [Security].Passphrase must not exceed "
+ "63 characters");
+ return false;
+ }
+
+ strcpy(ap->passphrase, passphrase);
+ }
+
+ if (l_settings_has_key(config, "Security", "PreSharedKey")) {
+ size_t psk_len;
+ L_AUTO_FREE_VAR(uint8_t *, psk) = l_settings_get_bytes(config,
+ "Security",
+ "PreSharedKey",
+ &psk_len);
+
+ if (!psk || psk_len != 32) {
+ l_error("AP [Security].PreSharedKey must be a 32-byte "
+ "hexstring");
+ return false;
+ }
+
+ memcpy(ap->psk, psk, 32);
+ return true;
+ }
+
+ if (!passphrase) {
+ l_error("AP requires at least one of [Security].PreSharedKey, "
+ "[Security].Passphrase to be present");
+ return false;
+ }
+
+ err = crypto_psk_from_passphrase(passphrase, (uint8_t *) ap->ssid,
+ strlen(ap->ssid), ap->psk);
+ if (err < 0) {
+ l_error("AP couldn't generate the PSK from given "
+ "[Security].Passphrase value: %s (%i)",
+ strerror(-err), -err);
+ return false;
+ }
+
+ return true;
+}
+
+static int ap_load_config(struct ap_state *ap, const struct l_settings *config,
+ bool *out_wait_dhcp, bool *out_cck_rates)
+{
+ size_t len;
+ L_AUTO_FREE_VAR(char *, strval) = NULL;
+ int err;
+
+ strval = l_settings_get_string(config, "General", "SSID");
+ if (L_WARN_ON(!strval))
+ return -ENOMSG;
+
+ len = strlen(strval);
+ if (len < 1 || len > 32) {
+ l_error("AP SSID length outside the [1, 32] range");
+ return -EINVAL;
+ }
+
+ if (L_WARN_ON(!l_utf8_validate(strval, len, NULL)))
+ return -EINVAL;
+
+ strcpy(ap->ssid, strval);
+ l_free(l_steal_ptr(strval));
+
+ if (!ap_load_psk(ap, 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.
+ */
+ err = ap_load_dhcp(ap, config, out_wait_dhcp);
+ if (err)
+ return err;
+
+ if (l_settings_has_key(config, "General", "Channel")) {
+ unsigned int uintval;
+
+ if (!l_settings_get_uint(config, "General", "Channel",
+ &uintval) ||
+ !scan_channel_to_freq(uintval,
+ SCAN_BAND_2_4_GHZ)) {
+ l_error("AP Channel value unsupported");
+ return -EINVAL;
+ }
+
+ ap->channel = uintval;
+ } else
+ /* TODO: Start a Get Survey to decide the channel */
+ ap->channel = 6;
+
+ strval = l_settings_get_string(config, "WSC", "DeviceName");
+ if (strval) {
+ len = strlen(strval);
+
+ if (len > 32) {
+ l_error("AP WSC name length outside the [1, 32] range");
+ return -EINVAL;
+ }
+
+ if (!l_utf8_validate(strval, len, NULL)) {
+ l_error("AP WSC name doesn't validate as UTF-8");
+ return -EINVAL;
+ }
+
+ strcpy(ap->wsc_name, strval);
+ l_free(l_steal_ptr(strval));
+ } else
+ memcpy(ap->wsc_name, ap->ssid, 33);
+
+ strval = l_settings_get_string(config, "WSC", "PrimaryDeviceType");
+ if (strval) {
+ bool ok = wsc_device_type_from_setting_str(strval,
+ &ap->wsc_primary_device_type);
+
+ if (!ok) {
+ l_error("AP [WSC].PrimaryDeviceType format unknown");
+ return -EINVAL;
+ }
+ } else {
+ /* Make ourselves a WFA standard PC by default */
+ ap->wsc_primary_device_type.category = 1;
+ memcpy(ap->wsc_primary_device_type.oui, wsc_wfa_oui, 3);
+ ap->wsc_primary_device_type.oui_type = 0x04;
+ ap->wsc_primary_device_type.subcategory = 1;
+ }
+
+ if (l_settings_get_value(config, "WSC", "AuthorizedMACs")) {
+ char **strvval;
+ unsigned int i;
+
+ strvval = l_settings_get_string_list(config, "WSC",
+ "AuthorizedMACs", ',');
+ if (!strvval) {
+ l_error("AP Authorized MACs list format wrong");
+ return -EINVAL;
+ }
+
+ ap->authorized_macs_num = l_strv_length(strvval);
+ ap->authorized_macs = l_malloc(ap->authorized_macs_num * 6);
+
+ for (i = 0; strvval[i]; i++)
+ if (!util_string_to_address(strvval[i],
+ ap->authorized_macs + i * 6)) {
+ l_error("Bad authorized MAC format: %s",
+ strvval[i]);
+ l_strfreev(strvval);
+ return -EINVAL;
+ }
+
+ l_strfreev(strvval);
+ }
+
+ if (l_settings_get_value(config, "General", "NoCCKRates")) {
+ bool boolval;
+
+ if (!l_settings_get_bool(config, "General", "NoCCKRates",
+ &boolval)) {
+ l_error("AP [General].NoCCKRates not a valid "
+ "boolean");
+ return -EINVAL;
+ }
+
+ *out_cck_rates = !boolval;
+ } else
+ *out_cck_rates = true;
+
+ return 0;
+}
+
/*
* Start a simple independent WPA2 AP on given netdev.
*
* @ops.handle_event is required and must react to AP_EVENT_START_FAILED
* and AP_EVENT_STOPPING by forgetting the ap_state struct, which is
* going to be freed automatically.
- * In the @config struct the .ssid field is required and one of
- * .passphrase and .psk must be filled in. All other fields are optional.
- * If @ap_start succeeds, the returned ap_state takes ownership of
- * @config and the caller shouldn't free it or any of the memory pointed
- * to by its members (which also can't be static).
+ * In the @config struct the [General].SSID key is required and one of
+ * [Security].Passphrase and [Security].PreSharedKey must be filled in.
+ * All other fields are optional.
*/
-struct ap_state *ap_start(struct netdev *netdev, struct ap_config *config,
+struct ap_state *ap_start(struct netdev *netdev, struct l_settings *config,
const struct ap_ops *ops, int *err_out,
void *user_data)
{
@@ -2741,57 +2862,37 @@ struct ap_state *ap_start(struct netdev *netdev, struct ap_config *config,
uint64_t wdev_id = netdev_get_wdev_id(netdev);
int err = -EINVAL;
bool wait_on_address = false;
+ bool cck_rates = true;
if (err_out)
*err_out = err;
- if (L_WARN_ON(!config->ssid))
- return NULL;
-
- if (L_WARN_ON(!config->profile && !config->passphrase[0] &&
- l_memeqzero(config->psk, sizeof(config->psk))))
+ 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);
- ap->config = config;
ap->netdev = netdev;
ap->ops = ops;
ap->user_data = user_data;
- /*
- * This both loads a profile if required and loads DHCP settings either
- * by the profile itself or the IP pool (or does nothing in the case
- * of a profile-less configuration). wait_on_address will be set true
- * if an address change is required.
- */
- err = ap_load_profile_and_dhcp(ap, &wait_on_address);
- if (err < 0)
+ err = ap_load_config(ap, config, &wait_on_address, &cck_rates);
+ if (err)
goto error;
- if (!config->channel)
- /* TODO: Start a Get Survey to decide the channel */
- config->channel = 6;
-
- if (!config->wsc_name)
- config->wsc_name = l_strdup(config->ssid);
-
- if (!config->wsc_primary_device_type.category) {
- /* Make ourselves a WFA standard PC by default */
- config->wsc_primary_device_type.category = 1;
- memcpy(config->wsc_primary_device_type.oui, wsc_wfa_oui, 3);
- config->wsc_primary_device_type.oui_type = 0x04;
- config->wsc_primary_device_type.subcategory = 1;
- }
+ err = -EINVAL;
/* TODO: Add all ciphers supported by wiphy */
ap->ciphers = wiphy_select_cipher(wiphy, 0xffff);
ap->group_cipher = wiphy_select_cipher(wiphy, 0xffff);
ap->beacon_interval = 100;
+
+ wsc_uuid_from_addr(netdev_get_address(netdev), ap->wsc_uuid_r);
+
ap->rates = l_uintset_new(200);
/* TODO: Pick from actual supported rates */
- if (config->no_cck_rates) {
+ if (!cck_rates) {
l_uintset_put(ap->rates, 12); /* 6 Mbps*/
l_uintset_put(ap->rates, 18); /* 9 Mbps*/
l_uintset_put(ap->rates, 24); /* 12 Mbps*/
@@ -2806,15 +2907,6 @@ struct ap_state *ap_start(struct netdev *netdev, struct ap_config *config,
l_uintset_put(ap->rates, 22); /* 11 Mbps*/
}
- wsc_uuid_from_addr(netdev_get_address(netdev), ap->wsc_uuid_r);
-
- if (config->passphrase[0] &&
- crypto_psk_from_passphrase(config->passphrase,
- (uint8_t *) config->ssid,
- strlen(config->ssid),
- config->psk) < 0)
- goto error;
-
if (!frame_watch_add(wdev_id, 0, 0x0000 |
(MPDU_MANAGEMENT_SUBTYPE_ASSOCIATION_REQUEST << 4),
NULL, 0, ap_assoc_req_cb, ap, NULL))
@@ -2877,7 +2969,6 @@ error:
if (err_out)
*err_out = err;
- ap->config = NULL;
ap_reset(ap);
l_genl_family_free(ap->nl80211);
l_free(ap);
@@ -3089,6 +3180,11 @@ static void ap_if_event_func(enum ap_event_type type, const void *event_data,
l_dbus_property_changed(dbus_get_bus(),
netdev_get_path(ap_if->netdev),
IWD_AP_INTERFACE, "Name");
+
+ l_rtnl_set_linkmode_and_operstate(rtnl,
+ netdev_get_ifindex(ap_if->netdev),
+ IF_LINK_MODE_DEFAULT, IF_OPER_UP,
+ NULL, NULL, NULL);
break;
case AP_EVENT_STOPPING:
@@ -3103,6 +3199,11 @@ static void ap_if_event_func(enum ap_event_type type, const void *event_data,
netdev_get_path(ap_if->netdev),
IWD_AP_INTERFACE, "Name");
+ l_rtnl_set_linkmode_and_operstate(rtnl,
+ netdev_get_ifindex(ap_if->netdev),
+ IF_LINK_MODE_DORMANT, IF_OPER_DOWN,
+ NULL, NULL, NULL);
+
if (!ap_if->pending)
ap_if->ap = NULL;
@@ -3127,7 +3228,7 @@ static struct l_dbus_message *ap_dbus_start(struct l_dbus *dbus,
{
struct ap_if_data *ap_if = user_data;
const char *ssid, *wpa2_passphrase;
- struct ap_config *config;
+ struct l_settings *config;
int err;
if (ap_if->ap && ap_if->ap->started)
@@ -3140,16 +3241,17 @@ static struct l_dbus_message *ap_dbus_start(struct l_dbus *dbus,
&ssid, &wpa2_passphrase))
return dbus_error_invalid_args(message);
- config = l_new(struct ap_config, 1);
- config->ssid = l_strdup(ssid);
- l_strlcpy(config->passphrase, wpa2_passphrase,
- sizeof(config->passphrase));
+ config = l_settings_new();
+ l_settings_set_string(config, "General", "SSID", ssid);
+ l_settings_set_string(config, "Security", "Passphrase",
+ wpa2_passphrase);
+ l_settings_add_group(config, "IPv4");
ap_if->ap = ap_start(ap_if->netdev, config, &ap_dbus_ops, &err, ap_if);
- if (!ap_if->ap) {
- ap_config_free(config);
+ l_settings_free(config);
+
+ if (!ap_if->ap)
return dbus_error_from_errno(err, message);
- }
ap_if->pending = l_dbus_message_ref(message);
return NULL;
@@ -3199,7 +3301,8 @@ static struct l_dbus_message *ap_dbus_start_profile(struct l_dbus *dbus,
{
struct ap_if_data *ap_if = user_data;
const char *ssid;
- struct ap_config *config;
+ _auto_(l_settings_free) struct l_settings *config = NULL;
+ char *config_path;
int err;
if (ap_if->ap && ap_if->ap->started)
@@ -3211,19 +3314,30 @@ static struct l_dbus_message *ap_dbus_start_profile(struct l_dbus *dbus,
if (!l_dbus_message_get_arguments(message, "s", &ssid))
return dbus_error_invalid_args(message);
- config = l_new(struct ap_config, 1);
- config->ssid = l_strdup(ssid);
- /* This tells ap_start to pull settings from a profile on disk */
- config->profile = storage_get_path("ap/%s.ap", ssid);
+ config = l_settings_new();
+ config_path = storage_get_path("ap/%s.ap", ssid);
+ err = l_settings_load_from_file(config, config_path) ? 0 : -EIO;
+ l_free(config_path);
+
+ if (err)
+ goto error;
+
+ /*
+ * Since [General].SSID is not an allowed setting for a profile on
+ * disk, we're free to potentially overwrite it with the SSID that
+ * the DBus user asked for.
+ */
+ l_settings_set_string(config, "General", "SSID", ssid);
ap_if->ap = ap_start(ap_if->netdev, config, &ap_dbus_ops, &err, ap_if);
- if (!ap_if->ap) {
- ap_config_free(config);
- return dbus_error_from_errno(err, message);
- }
+ if (!ap_if->ap)
+ goto error;
ap_if->pending = l_dbus_message_ref(message);
return NULL;
+
+error:
+ return dbus_error_from_errno(err, message);
}
static bool ap_dbus_property_get_started(struct l_dbus *dbus,
@@ -3246,11 +3360,11 @@ static bool ap_dbus_property_get_name(struct l_dbus *dbus,
{
struct ap_if_data *ap_if = user_data;
- if (!ap_if->ap || !ap_if->ap->config || !ap_if->ap->started)
+ if (!ap_if->ap || !ap_if->ap->started)
return false;
l_dbus_message_builder_append_basic(builder, 's',
- ap_if->ap->config->ssid);
+ ap_if->ap->ssid);
return true;
}
diff --git a/src/ap.h b/src/ap.h
@@ -58,21 +58,6 @@ struct ap_event_registration_success_data {
typedef void (*ap_stopped_func_t)(void *user_data);
-struct ap_config {
- char *ssid;
- char passphrase[64];
- uint8_t psk[32];
- uint8_t channel;
- uint8_t *authorized_macs;
- unsigned int authorized_macs_num;
- char *wsc_name;
- struct wsc_primary_device_type wsc_primary_device_type;
-
- char *profile;
-
- bool no_cck_rates : 1;
-};
-
struct ap_ops {
void (*handle_event)(enum ap_event_type type, const void *event_data,
void *user_data);
@@ -100,9 +85,7 @@ struct ap_ops {
uint8_t *out_buf, void *user_data);
};
-void ap_config_free(struct ap_config *config);
-
-struct ap_state *ap_start(struct netdev *netdev, struct ap_config *config,
+struct ap_state *ap_start(struct netdev *netdev, struct l_settings *config,
const struct ap_ops *ops, int *err,
void *user_data);
void ap_shutdown(struct ap_state *ap, ap_stopped_func_t stopped_func,
diff --git a/src/dbus.c b/src/dbus.c
@@ -30,36 +30,12 @@
#include <ell/ell.h>
-#include "linux/nl80211.h"
-
#include "src/agent.h"
#include "src/iwd.h"
#include "src/dbus.h"
static struct l_dbus *g_dbus = NULL;
-const char *dbus_iftype_to_string(uint32_t iftype)
-{
- switch (iftype) {
- case NL80211_IFTYPE_ADHOC:
- return "ad-hoc";
- case NL80211_IFTYPE_STATION:
- return "station";
- case NL80211_IFTYPE_AP:
- return "ap";
- case NL80211_IFTYPE_P2P_CLIENT:
- return "p2p-client";
- case NL80211_IFTYPE_P2P_GO:
- return "p2p-go";
- case NL80211_IFTYPE_P2P_DEVICE:
- return "p2p-device";
- default:
- break;
- }
-
- return NULL;
-}
-
struct l_dbus_message *dbus_error_busy(struct l_dbus_message *msg)
{
return l_dbus_message_new_error(msg, IWD_SERVICE ".InProgress",
diff --git a/src/dbus.h b/src/dbus.h
@@ -56,8 +56,6 @@ bool dbus_append_dict_basic(struct l_dbus_message_builder *builder,
const char *name, char type,
const void *data);
-const char *dbus_iftype_to_string(unsigned int iftype);
-
struct l_dbus_message *dbus_error_busy(struct l_dbus_message *msg);
struct l_dbus_message *dbus_error_failed(struct l_dbus_message *msg);
struct l_dbus_message *dbus_error_aborted(struct l_dbus_message *msg);
diff --git a/src/device.c b/src/device.c
@@ -37,8 +37,6 @@
#include "src/scan.h"
#include "src/netdev.h"
#include "src/dbus.h"
-#include "src/frame-xchg.h"
-#include "src/station.h"
struct device {
uint32_t index;
@@ -54,18 +52,6 @@ struct device {
static uint32_t netdev_watch;
-static void device_ap_roam_frame_event(const struct mmpdu_header *hdr,
- const void *body, size_t body_len, int rssi, void *user_data)
-{
- struct device *device = user_data;
- struct station *station = station_find(device->index);
-
- if (!station)
- return;
-
- station_ap_directed_roam(station, hdr, body, body_len);
-}
-
static bool device_property_get_name(struct l_dbus *dbus,
struct l_dbus_message *message,
struct l_dbus_message_builder *builder,
@@ -194,7 +180,7 @@ static bool device_property_get_mode(struct l_dbus *dbus,
{
struct device *device = user_data;
uint32_t iftype = netdev_get_iftype(device->netdev);
- const char *modestr = dbus_iftype_to_string(iftype);
+ const char *modestr = netdev_iftype_to_string(iftype);
if (modestr == NULL)
modestr = "unknown";
@@ -306,7 +292,6 @@ static struct device *device_create(struct wiphy *wiphy, struct netdev *netdev)
struct l_dbus *dbus = dbus_get_bus();
#endif
uint32_t ifindex = netdev_get_ifindex(netdev);
- const uint8_t action_ap_roam_prefix[2] = { 0x0a, 0x07 };
device = l_new(struct device, 1);
device->index = ifindex;
@@ -324,13 +309,6 @@ static struct device *device_create(struct wiphy *wiphy, struct netdev *netdev)
L_DBUS_INTERFACE_PROPERTIES);
#endif
- /*
- * register for AP roam transition watch
- */
- frame_watch_add(netdev_get_wdev_id(netdev), 0, 0x00d0,
- action_ap_roam_prefix, sizeof(action_ap_roam_prefix),
- device_ap_roam_frame_event, device, NULL);
-
device->powered = netdev_get_is_up(netdev);
device->dbus_powered = true;
diff --git a/src/diagnostic.c b/src/diagnostic.c
@@ -28,6 +28,7 @@
#include "src/diagnostic.h"
#include "src/dbus.h"
+#include "src/ie.h"
/*
* Appends values from diagnostic_station_info into a DBus dictionary. This
@@ -111,3 +112,44 @@ bool diagnostic_info_to_dict(const struct diagnostic_station_info *info,
return true;
}
+
+const char *diagnostic_akm_suite_to_security(enum ie_rsn_akm_suite akm,
+ bool wpa)
+{
+ if (akm == 0)
+ return "Open";
+
+ switch (akm) {
+ case IE_RSN_AKM_SUITE_8021X:
+ case IE_RSN_AKM_SUITE_8021X_SHA256:
+ return "WPA2-Enterprise";
+ case IE_RSN_AKM_SUITE_PSK:
+ if (wpa)
+ return "WPA1-Personal";
+
+ /* Fall through */
+ case IE_RSN_AKM_SUITE_PSK_SHA256:
+ return "WPA2-Personal";
+ case IE_RSN_AKM_SUITE_FT_OVER_8021X:
+ case IE_RSN_AKM_SUITE_FT_OVER_8021X_SHA384:
+ return "WPA2-Enterprise + FT";
+ case IE_RSN_AKM_SUITE_FT_USING_PSK:
+ return "WPA2-Personal + FT";
+ case IE_RSN_AKM_SUITE_SAE_SHA256:
+ return "WPA3-Personal";
+ case IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256:
+ return "WPA3-Personal + FT";
+ case IE_RSN_AKM_SUITE_OWE:
+ return "OWE";
+ case IE_RSN_AKM_SUITE_FILS_SHA256:
+ case IE_RSN_AKM_SUITE_FILS_SHA384:
+ return "FILS";
+ case IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA256:
+ case IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384:
+ return "FILS + FT";
+ case IE_RSN_AKM_SUITE_OSEN:
+ return "OSEN";
+ default:
+ return "Unknown";
+ }
+}
diff --git a/src/diagnostic.h b/src/diagnostic.h
@@ -20,6 +20,8 @@
*
*/
+enum ie_rsn_akm_suite;
+
enum diagnostic_mcs_type {
DIAGNOSTIC_MCS_TYPE_NONE,
DIAGNOSTIC_MCS_TYPE_HT,
@@ -52,3 +54,6 @@ struct diagnostic_station_info {
bool diagnostic_info_to_dict(const struct diagnostic_station_info *info,
struct l_dbus_message_builder *builder);
+
+const char *diagnostic_akm_suite_to_security(enum ie_rsn_akm_suite suite,
+ bool wpa);
diff --git a/src/eap-wsc.c b/src/eap-wsc.c
@@ -1742,19 +1742,12 @@ static bool load_primary_device_type(struct l_settings *settings,
struct wsc_primary_device_type *pdt)
{
const char *v;
- int r;
v = l_settings_get_value(settings, "WSC", "PrimaryDeviceType");
if (!v)
return false;
- r = sscanf(v, "%hx-%2hhx%2hhx%2hhx%2hhx-%2hx", &pdt->category,
- &pdt->oui[0], &pdt->oui[1], &pdt->oui[2],
- &pdt->oui_type, &pdt->subcategory);
- if (r != 6)
- return false;
-
- return true;
+ return wsc_device_type_from_setting_str(v, pdt);
}
static bool load_constrained_string(struct l_settings *settings,
diff --git a/src/eap.c b/src/eap.c
@@ -57,12 +57,15 @@ struct eap_state {
struct eap_method *method;
char *identity;
+ char *identity_setting;
bool authenticator;
int last_id;
void *method_state;
bool method_success;
struct l_timeout *complete_timeout;
+ unsigned int identity_req_count;
+ unsigned int method_req_count;
bool discard_success_and_failure:1;
};
@@ -124,11 +127,31 @@ static void eap_free_common(struct eap_state *eap)
if (eap->identity) {
l_free(eap->identity);
eap->identity = NULL;
+ l_free(eap->identity_setting);
+ eap->identity_setting = NULL;
}
}
void eap_free(struct eap_state *eap)
{
+ /*
+ * In supplicant mode we get here whether the authenticator has
+ * sent an EAP-Failure or interrupted the connection at a higher
+ * layer, or even when the negotiation stalled and we interrupted
+ * it, so use this code path to check if it is the Identity value
+ * that the authenticator may have a problem with. We don't know
+ * whether we're the phase 1 or phase 2 EAP state machine
+ * (eap->set_key_material is a hint but doesn't work with EAP-PEAP
+ * phase2) so print the setting name.
+ */
+ if (!eap->authenticator && !eap->method_success) {
+ if (eap->identity_req_count && !eap->method_req_count)
+ l_info("EAP negotiation stopped after the Identity "
+ "exchange, this can happen when the %s value "
+ "is not what the authenticator expects",
+ eap->identity_setting ?: "identity");
+ }
+
eap_free_common(eap);
l_timeout_remove(eap->complete_timeout);
@@ -286,6 +309,8 @@ void __eap_handle_request(struct eap_state *eap, uint16_t id,
void (*op)(struct eap_state *eap,
const uint8_t *pkt, size_t len);
+ eap->method_req_count++;
+
if (type != eap->method->request_type) {
l_warn("EAP server tried method %i while client was "
"configured for method %i",
@@ -316,6 +341,8 @@ void __eap_handle_request(struct eap_state *eap, uint16_t id,
switch (type) {
case EAP_TYPE_IDENTITY:
+ eap->identity_req_count++;
+
if (len >= 2)
l_debug("Optional EAP server identity prompt: \"%.*s\"",
(int) len - 1, pkt + 1);
@@ -776,6 +803,7 @@ bool eap_load_settings(struct eap_state *eap, struct l_settings *settings,
snprintf(setting, sizeof(setting), "%sIdentity", prefix);
eap->identity = l_settings_get_string(settings,
"Security", setting);
+ eap->identity_setting = l_strdup(setting);
} else {
eap->identity = l_strdup(eap->method->get_identity(eap));
}
diff --git a/src/eapol.c b/src/eapol.c
@@ -52,6 +52,7 @@ static uint32_t eapol_4way_handshake_time = 2;
static eapol_rekey_offload_func_t rekey_offload = NULL;
static eapol_tx_packet_func_t tx_packet = NULL;
+static eapol_install_pmk_func_t install_pmk = NULL;
static void *tx_user_data;
#define VERIFY_IS_ZERO(field) \
@@ -1025,6 +1026,17 @@ static void eapol_set_key_timeout(struct eapol_sm *sm,
}
}
+/*
+ * GCC version 8.3 seems to have trouble correctly calculating
+ * ek->header.packet_len when optimization is enabled. This results in iwd
+ * sending invalid 1_of_4 packets (with the KDE payload missing). Work
+ * around this by dropping to O0 for this function when old GCC versions
+ * are used
+ */
+#if __GNUC__ < 9
+#pragma GCC optimize ("O0")
+#endif
+
/* 802.11-2016 Section 12.7.6.2 */
static void eapol_send_ptk_1_of_4(struct eapol_sm *sm)
{
@@ -1068,6 +1080,10 @@ static void eapol_send_ptk_1_of_4(struct eapol_sm *sm)
eapol_sm_write(sm, (struct eapol_frame *) ek, false);
}
+#if __GNUC__ < 9
+#pragma GCC reset_options
+#endif
+
static void eapol_ptk_1_of_4_retry(struct l_timeout *timeout, void *user_data)
{
struct eapol_sm *sm = user_data;
@@ -2162,6 +2178,10 @@ static void eapol_eap_complete_cb(enum eap_result result, void *user_data)
sm->eap = NULL;
handshake_failed(sm, MMPDU_REASON_CODE_IEEE8021X_FAILED);
return;
+ } else {
+ if (install_pmk)
+ install_pmk(sm->handshake, sm->handshake->pmk,
+ sm->handshake->pmk_len);
}
eap_reset(sm->eap);
@@ -2470,6 +2490,11 @@ void __eapol_set_rekey_offload_func(eapol_rekey_offload_func_t func)
rekey_offload = func;
}
+void __eapol_set_install_pmk_func(eapol_install_pmk_func_t func)
+{
+ install_pmk = func;
+}
+
void eapol_register(struct eapol_sm *sm)
{
eapol_frame_watch_func_t rx_handler = sm->handshake->authenticator ?
diff --git a/src/eapol.h b/src/eapol.h
@@ -51,6 +51,9 @@ typedef void (*eapol_frame_watch_func_t)(uint16_t proto, const uint8_t *from,
const struct eapol_frame *frame,
bool noencrypt,
void *user_data);
+typedef void (*eapol_install_pmk_func_t)(struct handshake_state *hs,
+ const uint8_t *pmk,
+ size_t pmk_len);
bool eapol_calculate_mic(enum ie_rsn_akm_suite akm, const uint8_t *kck,
const struct eapol_key *frame, uint8_t *mic,
@@ -102,6 +105,8 @@ void __eapol_tx_packet(uint32_t ifindex, const uint8_t *dst, uint16_t proto,
void __eapol_set_tx_packet_func(eapol_tx_packet_func_t func);
void __eapol_set_tx_user_data(void *user_data);
+void __eapol_set_install_pmk_func(eapol_install_pmk_func_t func);
+
void __eapol_set_rekey_offload_func(eapol_rekey_offload_func_t func);
void __eapol_update_replay_counter(uint32_t ifindex, const uint8_t *spa,
const uint8_t *aa, uint64_t replay_counter);
diff --git a/src/eapolutil.h b/src/eapolutil.h
@@ -32,7 +32,7 @@ enum eapol_protocol_version {
};
/*
- * 802.1X-2010: Table 11-5—Descriptor Type value assignments
+ * 802.1X-2010: Table 11-5-Descriptor Type value assignments
* The WPA key type of 254 comes from somewhere else. Seems it is a legacy
* value that might still be used by older implementations
*/
diff --git a/src/frame-xchg.c b/src/frame-xchg.c
@@ -906,8 +906,6 @@ static void frame_xchg_tx_cb(struct l_genl_msg *msg, void *user_data)
fx->tx_cmd_id = 0;
- l_debug("err %i", -error);
-
if (error < 0) {
if (error == -EBUSY) {
fx->timeout = l_timeout_create_ms(fx->retry_interval,
@@ -926,6 +924,8 @@ static void frame_xchg_tx_cb(struct l_genl_msg *msg, void *user_data)
goto error;
}
+ l_debug("Frame sent, cookie: %"PRIu64" obtained", cookie);
+
early_status = fx->early_status && cookie == fx->cookie;
fx->tx_acked = early_status && fx->tx_acked;
fx->have_cookie = true;
@@ -1269,13 +1269,14 @@ static void frame_xchg_mlme_notify(struct l_genl_msg *msg, void *user_data)
NL80211_ATTR_UNSPEC) < 0)
return;
- l_debug("Received %s", ack ? "an ACK" : "no ACK");
-
fx = l_queue_find(frame_xchgs, frame_xchg_match_running,
&wdev_id);
if (!fx)
return;
+ l_debug("Received %s for cookie: %"PRIu64,
+ ack ? "an ACK" : "no ACK", cookie);
+
if (fx->have_cookie && cookie == fx->cookie && !fx->tx_acked)
frame_xchg_tx_status(fx, ack);
else if (!fx->have_cookie && !fx->tx_acked) {
@@ -1312,7 +1313,6 @@ static void frame_xchg_config_notify(struct l_genl_msg *msg, void *user_data)
if (!wdev) {
wdev = l_new(struct wdev_info, 1);
wdev->id = wdev_id;
- wdev->iftype = iftype;
if (!wdevs)
wdevs = l_queue_new();
@@ -1321,11 +1321,7 @@ static void frame_xchg_config_notify(struct l_genl_msg *msg, void *user_data)
break;
}
- if (wdev->iftype != iftype) {
- wdev->iftype = iftype;
- frame_watch_wdev_remove(wdev_id);
- }
-
+ wdev->iftype = iftype;
break;
case NL80211_CMD_DEL_INTERFACE:
diff --git a/src/ft.c b/src/ft.c
@@ -156,40 +156,6 @@ static bool ft_parse_authentication_resp_frame(const uint8_t *data, size_t len,
return true;
}
-static bool ft_parse_action_resp_frame(const uint8_t *frame, size_t frame_len,
- const uint8_t *spa, const uint8_t *aa,
- uint16_t *out_status,
- const uint8_t **out_ies,
- size_t *out_ies_len)
-{
- uint16_t status = 0;
-
- /* Category FT */
- if (frame[0] != 6)
- return false;
-
- /* FT Action */
- if (frame[1] != 2)
- return false;
-
- if (memcmp(frame + 2, spa, 6))
- return false;
- if (memcmp(frame + 8, aa, 6))
- return false;
-
- status = l_get_le16(frame + 14);
-
- if (out_status)
- *out_status = status;
-
- if (status == 0 && out_ies) {
- *out_ies = frame + 16;
- *out_ies_len = frame_len - 16;
- }
-
- return true;
-}
-
static bool ft_parse_associate_resp_frame(const uint8_t *frame, size_t frame_len,
uint16_t *out_status, const uint8_t **rsne,
const uint8_t **mde, const uint8_t **fte)
@@ -254,10 +220,10 @@ static int ft_tx_reassociate(struct ft_sm *ft)
* MDE + FTE.
*
* 12.8.4: "If present, the RSNE shall be set as follows:
- * — Version field shall be set to 1.
- * — PMKID Count field shall be set to 1.
- * — PMKID field shall contain the PMKR1Name.
- * — All other fields shall be as specified in 8.4.2.27
+ * - Version field shall be set to 1.
+ * - PMKID Count field shall be set to 1.
+ * - PMKID field shall contain the PMKR1Name.
+ * - All other fields shall be as specified in 8.4.2.27
* and 11.5.3."
*/
if (ie_parse_rsne_from_data(hs->supplicant_ie,
@@ -287,14 +253,14 @@ static int ft_tx_reassociate(struct ft_sm *ft)
/*
* 12.8.4: "If present, the FTE shall be set as follows:
- * — ANonce, SNonce, R0KH-ID, and R1KH-ID shall be set to
+ * - ANonce, SNonce, R0KH-ID, and R1KH-ID shall be set to
* the values contained in the second message of this
* sequence.
- * — The Element Count field of the MIC Control field shall
+ * - The Element Count field of the MIC Control field shall
* be set to the number of elements protected in this
* frame (variable).
* [...]
- * — All other fields shall be set to 0."
+ * - All other fields shall be set to 0."
*/
memset(&ft_info, 0, sizeof(ft_info));
@@ -321,28 +287,59 @@ static int ft_tx_reassociate(struct ft_sm *ft)
iov_elems += 1;
}
- ft->tx_assoc(iov, iov_elems, ft->user_data);
-
- return 0;
+ return ft->tx_assoc(iov, iov_elems, ft->user_data);
error:
return -EINVAL;
}
-static int ft_process_ies(struct ft_sm *ft, const uint8_t *ies, size_t ies_len)
+static bool ft_verify_rsne(const uint8_t *rsne, const uint8_t *pmk_r0_name,
+ const uint8_t *authenticator_ie)
+{
+ /*
+ * In an RSN, check for an RSNE containing the PMK-R0-Name and
+ * the remaining fields same as in the advertised RSNE.
+ *
+ * 12.8.3: "The RSNE shall be present only if dot11RSNAActivated
+ * is true. If present, the RSNE shall be set as follows:
+ * - Version field shall be set to 1.
+ * - PMKID Count field shall be set to 1.
+ * - PMKID List field shall be set to the value contained in the
+ * first message of this sequence.
+ * - All other fields shall be identical to the contents of the
+ * RSNE advertised by the AP in Beacon and Probe Response frames."
+ */
+
+ struct ie_rsn_info msg2_rsne;
+
+ if (!rsne)
+ return false;
+
+ if (ie_parse_rsne_from_data(rsne, rsne[1] + 2,
+ &msg2_rsne) < 0)
+ return false;
+
+ if (msg2_rsne.num_pmkids != 1 ||
+ memcmp(msg2_rsne.pmkids, pmk_r0_name, 16))
+ return false;
+
+ if (!handshake_util_ap_ie_matches(rsne, authenticator_ie, false))
+ return false;
+
+ return true;
+}
+
+static int ft_parse_ies(struct handshake_state *hs,
+ const uint8_t *ies, size_t ies_len,
+ const uint8_t **mde_out,
+ const uint8_t **fte_out)
{
struct ie_tlv_iter iter;
const uint8_t *rsne = NULL;
const uint8_t *mde = NULL;
const uint8_t *fte = NULL;
- struct handshake_state *hs = ft->hs;
- uint32_t kck_len = handshake_state_get_kck_len(hs);
bool is_rsn;
- /* Check 802.11r IEs */
- if (!ies)
- goto ft_error;
-
ie_tlv_iter_init(&iter, ies, ies_len);
while (ie_tlv_iter_next(&iter)) {
@@ -372,49 +369,30 @@ static int ft_process_ies(struct ft_sm *ft, const uint8_t *ies, size_t ies_len)
is_rsn = hs->supplicant_ie != NULL;
- /*
- * In an RSN, check for an RSNE containing the PMK-R0-Name and
- * the remaining fields same as in the advertised RSNE.
- *
- * 12.8.3: "The RSNE shall be present only if dot11RSNAActivated
- * is true. If present, the RSNE shall be set as follows:
- * — Version field shall be set to 1.
- * — PMKID Count field shall be set to 1.
- * — PMKID List field shall be set to the value contained in the
- * first message of this sequence.
- * — All other fields shall be identical to the contents of the
- * RSNE advertised by the AP in Beacon and Probe Response frames."
- */
if (is_rsn) {
- struct ie_rsn_info msg2_rsne;
-
- if (!rsne)
+ if (!ft_verify_rsne(rsne, hs->pmk_r0_name,
+ hs->authenticator_ie))
goto ft_error;
+ } else if (rsne)
+ goto ft_error;
- if (ie_parse_rsne_from_data(rsne, rsne[1] + 2,
- &msg2_rsne) < 0)
- goto ft_error;
+ if (mde_out)
+ *mde_out = mde;
- if (msg2_rsne.num_pmkids != 1 ||
- memcmp(msg2_rsne.pmkids, hs->pmk_r0_name, 16))
- goto ft_error;
+ if (fte_out)
+ *fte_out = fte;
- if (!handshake_util_ap_ie_matches(rsne, hs->authenticator_ie,
- false))
- goto ft_error;
- } else if (rsne)
- goto ft_error;
+ return 0;
- /*
- * Check for an MD IE identical to the one we sent in message 1
- *
- * 12.8.3: "The MDE shall contain the MDID and FT Capability and
- * Policy fields. This element shall be the same as the MDE
- * advertised by the target AP in Beacon and Probe Response frames."
- */
- if (!mde || memcmp(hs->mde, mde, hs->mde[1] + 2))
- goto ft_error;
+ft_error:
+ return -EINVAL;
+}
+static bool ft_parse_fte(struct handshake_state *hs,
+ const uint8_t *snonce,
+ const uint8_t *fte,
+ struct ie_ft_info *ft_info)
+{
/*
* In an RSN, check for an FT IE with the same R0KH-ID and the same
* SNonce that we sent, and check that the R1KH-ID and the ANonce
@@ -423,38 +401,108 @@ static int ft_process_ies(struct ft_sm *ft, const uint8_t *ies, size_t ies_len)
*
* 12.8.3: "The FTE shall be present only if dot11RSNAActivated is
* true. If present, the FTE shall be set as follows:
- * — R0KH-ID shall be identical to the R0KH-ID provided by the FTO
+ * - R0KH-ID shall be identical to the R0KH-ID provided by the FTO
* in the first message.
- * — R1KH-ID shall be set to the R1KH-ID of the target AP, from
+ * - R1KH-ID shall be set to the R1KH-ID of the target AP, from
* dot11FTR1KeyHolderID.
- * — ANonce shall be set to a value chosen randomly by the target AP,
+ * - ANonce shall be set to a value chosen randomly by the target AP,
* following the recommendations of 11.6.5.
- * — SNonce shall be set to the value contained in the first message
+ * - SNonce shall be set to the value contained in the first message
* of this sequence.
- * — All other fields shall be set to 0."
+ * - All other fields shall be set to 0."
*/
- if (is_rsn) {
- struct ie_ft_info ft_info;
- uint8_t zeros[24] = {};
+ uint8_t zeros[24] = {};
+ uint32_t kck_len = handshake_state_get_kck_len(hs);
- if (!fte)
- goto ft_error;
+ if (!fte)
+ return false;
- if (ie_parse_fast_bss_transition_from_data(fte, fte[1] + 2,
- kck_len, &ft_info) < 0)
- goto ft_error;
+ if (ie_parse_fast_bss_transition_from_data(fte, fte[1] + 2,
+ kck_len, ft_info) < 0)
+ return false;
- if (ft_info.mic_element_count != 0 ||
- memcmp(ft_info.mic, zeros, kck_len))
- goto ft_error;
+ if (ft_info->mic_element_count != 0 ||
+ memcmp(ft_info->mic, zeros, kck_len))
+ return false;
- if (hs->r0khid_len != ft_info.r0khid_len ||
- memcmp(hs->r0khid, ft_info.r0khid,
- hs->r0khid_len) ||
- !ft_info.r1khid_present)
+ if (hs->r0khid_len != ft_info->r0khid_len ||
+ memcmp(hs->r0khid, ft_info->r0khid,
+ hs->r0khid_len) ||
+ !ft_info->r1khid_present)
+ return false;
+
+ if (memcmp(ft_info->snonce, snonce, 32))
+ return false;
+
+ return true;
+}
+
+static bool mde_equal(const uint8_t *mde1, const uint8_t *mde2)
+{
+ if (!mde1 || !mde2)
+ return false;
+
+ /*
+ * Check for an MD IE identical to the one we sent in message 1
+ *
+ * 12.8.3: "The MDE shall contain the MDID and FT Capability and
+ * Policy fields. This element shall be the same as the MDE
+ * advertised by the target AP in Beacon and Probe Response frames."
+ */
+ return memcmp(mde1, mde1, mde1[1] + 2) == 0;
+}
+
+static bool ft_over_ds_process_ies(struct ft_ds_info *info,
+ struct handshake_state *hs,
+ const uint8_t *ies,
+ size_t ies_len)
+{
+ const uint8_t *mde = NULL;
+ const uint8_t *fte = NULL;
+ bool is_rsn = hs->supplicant_ie != NULL;
+
+ if (ft_parse_ies(hs, ies, ies_len, &mde, &fte) < 0)
+ return false;
+
+ if (!mde_equal(info->mde, mde))
+ goto ft_error;
+
+ if (is_rsn) {
+ if (!ft_parse_fte(hs, info->snonce, fte, &info->ft_info))
goto ft_error;
- if (memcmp(ft_info.snonce, hs->snonce, 32))
+ info->fte = l_memdup(fte, fte[1] + 2);
+ } else if (fte)
+ goto ft_error;
+
+ return true;
+
+ft_error:
+ return false;
+}
+
+static int ft_process_ies(struct handshake_state *hs, const uint8_t *ies,
+ size_t ies_len)
+{
+ const uint8_t *mde = NULL;
+ const uint8_t *fte = NULL;
+ bool is_rsn = hs->supplicant_ie != NULL;
+
+ /* Check 802.11r IEs */
+ if (!ies)
+ goto ft_error;
+
+ if (ft_parse_ies(hs, ies, ies_len, &mde, &fte) < 0)
+ goto ft_error;
+
+
+ if (!mde_equal(hs->mde, mde))
+ goto ft_error;
+
+ if (is_rsn) {
+ struct ie_ft_info ft_info;
+
+ if (!ft_parse_fte(hs, hs->snonce, fte, &ft_info))
goto ft_error;
handshake_state_set_fte(hs, fte);
@@ -469,33 +517,74 @@ static int ft_process_ies(struct ft_sm *ft, const uint8_t *ies, size_t ies_len)
} else if (fte)
goto ft_error;
- return ft_tx_reassociate(ft);
+ return 0;
ft_error:
return -EBADMSG;
}
-static int ft_rx_action(struct auth_proto *ap, const uint8_t *frame,
- size_t frame_len)
+int ft_over_ds_parse_action_response(struct ft_ds_info *info,
+ struct handshake_state *hs,
+ const uint8_t *frame, size_t frame_len)
{
- struct ft_sm *ft = l_container_of(ap, struct ft_sm, ap);
- uint16_t status_code = MMPDU_STATUS_CODE_UNSPECIFIED;
- const uint8_t *ies = NULL;
- size_t ies_len;
+ uint16_t status;
+
+ if (frame_len < 16)
+ return -EINVAL;
+
+ /* Category FT */
+ if (frame[0] != 6)
+ return -EINVAL;
+
+ /* FT Action */
+ if (frame[1] != 2)
+ return -EINVAL;
- if (!ft_parse_action_resp_frame(frame, frame_len, ft->hs->spa,
- ft->hs->aa, &status_code,
- &ies, &ies_len))
+ if (memcmp(frame + 2, info->spa, 6))
+ return -ENOENT;
+ if (memcmp(frame + 8, info->aa, 6))
+ return -ENOENT;
+
+ 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;
- /* AP Rejected the authenticate / associate */
- if (status_code != 0)
- goto auth_error;
+ return 0;
+}
- return ft_process_ies(ft, ies, ies_len);
+bool ft_over_ds_prepare_handshake(struct ft_ds_info *info,
+ struct handshake_state *hs)
+{
+ if (!hs->supplicant_ie)
+ return true;
-auth_error:
- return (int)status_code;
+ memcpy(hs->snonce, info->snonce, sizeof(hs->snonce));
+
+ handshake_state_set_fte(hs, info->fte);
+
+ handshake_state_set_anonce(hs, info->ft_info.anonce);
+
+ handshake_state_set_kh_ids(hs, info->ft_info.r0khid,
+ info->ft_info.r0khid_len,
+ info->ft_info.r1khid);
+
+ handshake_state_derive_ptk(hs);
+
+ return true;
+}
+
+void ft_ds_info_free(struct ft_ds_info *info)
+{
+ __typeof__(info->free) destroy = info->free;
+
+ if (info->fte)
+ l_free(info->fte);
+
+ if (destroy)
+ destroy(info);
}
static int ft_rx_authenticate(struct auth_proto *ap, const uint8_t *frame,
@@ -505,6 +594,7 @@ static int ft_rx_authenticate(struct auth_proto *ap, const uint8_t *frame,
uint16_t status_code = MMPDU_STATUS_CODE_UNSPECIFIED;
const uint8_t *ies = NULL;
size_t ies_len;
+ int ret;
/*
* Parse the Authentication Response and validate the contents
@@ -520,7 +610,11 @@ static int ft_rx_authenticate(struct auth_proto *ap, const uint8_t *frame,
if (status_code != 0)
goto auth_error;
- return ft_process_ies(ft, ies, ies_len);
+ ret = ft_process_ies(ft->hs, ies, ies_len);
+ if (ret < 0)
+ goto auth_error;
+
+ return ft_tx_reassociate(ft);
auth_error:
return (int)status_code;
@@ -550,10 +644,10 @@ static int ft_rx_associate(struct auth_proto *ap, const uint8_t *frame,
*
* 12.8.5: "The RSNE shall be present only if dot11RSNAActivated is
* true. If present, the RSNE shall be set as follows:
- * — Version field shall be set to 1.
- * — PMKID Count field shall be set to 1.
- * — PMKID field shall contain the PMKR1Name
- * — All other fields shall be identical to the contents of the RSNE
+ * - Version field shall be set to 1.
+ * - PMKID Count field shall be set to 1.
+ * - PMKID field shall contain the PMKR1Name
+ * - All other fields shall be identical to the contents of the RSNE
* advertised by the target AP in Beacon and Probe Response frames."
*/
if (is_rsn) {
@@ -669,29 +763,33 @@ static void ft_sm_free(struct auth_proto *ap)
l_free(ft);
}
-static bool ft_start(struct auth_proto *ap)
+static bool ft_over_ds_start(struct auth_proto *ap)
{
struct ft_sm *ft = l_container_of(ap, struct ft_sm, ap);
- struct handshake_state *hs = ft->hs;
+
+ return ft_tx_reassociate(ft) == 0;
+}
+
+bool ft_build_authenticate_ies(struct handshake_state *hs,
+ const uint8_t *new_snonce, uint8_t *buf,
+ size_t *len)
+{
uint32_t kck_len = handshake_state_get_kck_len(hs);
bool is_rsn = hs->supplicant_ie != NULL;
- uint8_t mde[5];
- struct iovec iov[3];
- size_t iov_elems = 0;
+ uint8_t *ptr = buf;
if (is_rsn) {
struct ie_rsn_info rsn_info;
- uint8_t *rsne;
/*
* Rebuild the RSNE to include the PMKR0Name and append
* MDE + FTE.
*
* 12.8.2: "If present, the RSNE shall be set as follows:
- * — Version field shall be set to 1.
- * — PMKID Count field shall be set to 1.
- * — PMKID List field shall contain the PMKR0Name.
- * — All other fields shall be as specified in 8.4.2.27
+ * - Version field shall be set to 1.
+ * - PMKID Count field shall be set to 1.
+ * - PMKID List field shall contain the PMKR0Name.
+ * - All other fields shall be as specified in 8.4.2.27
* and 11.5.3."
*/
if (ie_parse_rsne_from_data(hs->supplicant_ie,
@@ -702,35 +800,27 @@ static bool ft_start(struct auth_proto *ap)
rsn_info.num_pmkids = 1;
rsn_info.pmkids = hs->pmk_r0_name;
- rsne = alloca(256);
- ie_build_rsne(&rsn_info, rsne);
-
- iov[iov_elems].iov_base = rsne;
- iov[iov_elems].iov_len = rsne[1] + 2;
- iov_elems += 1;
+ ie_build_rsne(&rsn_info, ptr);
+ ptr += ptr[1] + 2;
}
/* The MDE advertised by the BSS must be passed verbatim */
- mde[0] = IE_TYPE_MOBILITY_DOMAIN;
- mde[1] = 3;
- memcpy(mde + 2, hs->mde + 2, 3);
-
- iov[iov_elems].iov_base = mde;
- iov[iov_elems].iov_len = 5;
- iov_elems += 1;
+ ptr[0] = IE_TYPE_MOBILITY_DOMAIN;
+ ptr[1] = 3;
+ memcpy(ptr + 2, hs->mde + 2, 3);
+ ptr += 5;
if (is_rsn) {
struct ie_ft_info ft_info;
- uint8_t *fte;
/*
* 12.8.2: "If present, the FTE shall be set as follows:
- * — R0KH-ID shall be the value of R0KH-ID obtained by the
+ * - R0KH-ID shall be the value of R0KH-ID obtained by the
* FTO during its FT initial mobility domain association
* exchange.
- * — SNonce shall be set to a value chosen randomly by the
+ * - SNonce shall be set to a value chosen randomly by the
* FTO, following the recommendations of 11.6.5.
- * — All other fields shall be set to 0."
+ * - All other fields shall be set to 0."
*/
memset(&ft_info, 0, sizeof(ft_info));
@@ -738,25 +828,41 @@ static bool ft_start(struct auth_proto *ap)
memcpy(ft_info.r0khid, hs->r0khid, hs->r0khid_len);
ft_info.r0khid_len = hs->r0khid_len;
- memcpy(ft_info.snonce, hs->snonce, 32);
+ memcpy(ft_info.snonce, new_snonce, 32);
- fte = alloca(256);
- ie_build_fast_bss_transition(&ft_info, kck_len, fte);
+ ie_build_fast_bss_transition(&ft_info, kck_len, ptr);
- iov[iov_elems].iov_base = fte;
- iov[iov_elems].iov_len = fte[1] + 2;
- iov_elems += 1;
+ ptr += ptr[1] + 2;
}
- ft->tx_auth(iov, iov_elems, ft->user_data);
+ if (len)
+ *len = ptr - buf;
return true;
}
-static struct auth_proto *ft_sm_new(struct handshake_state *hs,
+static bool ft_start(struct auth_proto *ap)
+{
+ struct ft_sm *ft = l_container_of(ap, struct ft_sm, ap);
+ struct handshake_state *hs = ft->hs;
+ struct iovec iov;
+ uint8_t buf[512];
+ size_t len;
+
+ if (!ft_build_authenticate_ies(hs, hs->snonce, buf, &len))
+ return false;
+
+ iov.iov_base = buf;
+ iov.iov_len = len;
+
+ ft->tx_auth(&iov, 1, ft->user_data);
+
+ return true;
+}
+
+struct auth_proto *ft_over_air_sm_new(struct handshake_state *hs,
ft_tx_authenticate_func_t tx_auth,
ft_tx_associate_func_t tx_assoc,
- bool over_air,
void *user_data)
{
struct ft_sm *ft = l_new(struct ft_sm, 1);
@@ -766,7 +872,7 @@ static struct auth_proto *ft_sm_new(struct handshake_state *hs,
ft->hs = hs;
ft->user_data = user_data;
- ft->ap.rx_authenticate = (over_air) ? ft_rx_authenticate : ft_rx_action;
+ ft->ap.rx_authenticate = ft_rx_authenticate;
ft->ap.rx_associate = ft_rx_associate;
ft->ap.start = ft_start;
ft->ap.free = ft_sm_free;
@@ -774,18 +880,19 @@ static struct auth_proto *ft_sm_new(struct handshake_state *hs,
return &ft->ap;
}
-struct auth_proto *ft_over_air_sm_new(struct handshake_state *hs,
- ft_tx_authenticate_func_t tx_auth,
- ft_tx_associate_func_t tx_assoc,
- void *user_data)
-{
- return ft_sm_new(hs, tx_auth, tx_assoc, true, user_data);
-}
-
struct auth_proto *ft_over_ds_sm_new(struct handshake_state *hs,
- ft_tx_authenticate_func_t tx_auth,
ft_tx_associate_func_t tx_assoc,
void *user_data)
{
- return ft_sm_new(hs, tx_auth, tx_assoc, false, user_data);
+ struct ft_sm *ft = l_new(struct ft_sm, 1);
+
+ ft->tx_assoc = tx_assoc;
+ ft->hs = hs;
+ ft->user_data = user_data;
+
+ ft->ap.rx_associate = ft_rx_associate;
+ ft->ap.start = ft_over_ds_start;
+ ft->ap.free = ft_sm_free;
+
+ return &ft->ap;
}
diff --git a/src/ft.h b/src/ft.h
@@ -20,17 +20,45 @@
*
*/
+struct handshake_state;
+
typedef void (*ft_tx_authenticate_func_t)(struct iovec *iov, size_t iov_len,
void *user_data);
-typedef void (*ft_tx_associate_func_t)(struct iovec *ie_iov, size_t iov_len,
+typedef int (*ft_tx_associate_func_t)(struct iovec *ie_iov, size_t iov_len,
void *user_data);
+typedef void (*ft_ds_free_func_t)(void *user_data);
+
+struct ft_ds_info {
+ uint8_t spa[6];
+ uint8_t aa[6];
+ uint8_t snonce[32];
+ uint8_t mde[3];
+ uint8_t *fte;
+
+ struct ie_ft_info ft_info;
+
+ void (*free)(struct ft_ds_info *s);
+};
+
+void ft_ds_info_free(struct ft_ds_info *info);
+
+bool ft_build_authenticate_ies(struct handshake_state *hs,
+ const uint8_t *new_snonce, uint8_t *buf,
+ size_t *len);
+
+int ft_over_ds_parse_action_response(struct ft_ds_info *info,
+ struct handshake_state *hs,
+ const uint8_t *frame, size_t frame_len);
+
struct auth_proto *ft_over_air_sm_new(struct handshake_state *hs,
ft_tx_authenticate_func_t tx_auth,
ft_tx_associate_func_t tx_assoc,
void *user_data);
struct auth_proto *ft_over_ds_sm_new(struct handshake_state *hs,
- ft_tx_authenticate_func_t tx_auth,
ft_tx_associate_func_t tx_assoc,
void *user_data);
+
+bool ft_over_ds_prepare_handshake(struct ft_ds_info *info,
+ struct handshake_state *hs);
diff --git a/src/handshake.h b/src/handshake.h
@@ -116,7 +116,6 @@ struct handshake_state {
bool wait_for_gtk : 1;
bool no_rekey : 1;
bool support_fils : 1;
- bool offload : 1;
uint8_t ssid[32];
size_t ssid_len;
char *passphrase;
diff --git a/src/ie.c b/src/ie.c
@@ -740,7 +740,7 @@ static int parse_ciphers(const uint8_t *data, size_t len,
out_info->extended_key_id = test_bit(data + 1, 5);
/*
- * BIP—default group management cipher suite in an RSNA with
+ * BIP-default group management cipher suite in an RSNA with
* management frame protection enabled
*/
if (out_info->mfpc)
@@ -1931,7 +1931,7 @@ static int ie_parse_ht_capability_from_data(const uint8_t *data, uint8_t len,
*
* For simplicity, we are ignoring the Extended BSS BW support, per NOTE 11:
*
- * NOTE 11—A receiving STA in which dot11VHTExtendedNSSCapable is false will
+ * 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.
*
diff --git a/src/ie.h b/src/ie.h
@@ -288,6 +288,20 @@ enum ie_rsn_akm_suite {
((akm == IE_RSN_AKM_SUITE_SAE_SHA256) || \
(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))
+
+#define IE_AKM_IS_FILS(akm) \
+ ((akm == IE_RSN_AKM_SUITE_FILS_SHA256) || \
+ (akm == IE_RSN_AKM_SUITE_FILS_SHA384) || \
+ (akm == IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA256) || \
+ (akm == IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384))
+
#define IE_LEN(ie) \
(ie) ? (ie)[1] + 2 : 0
diff --git a/src/iwd.ap.rst b/src/iwd.ap.rst
@@ -3,7 +3,7 @@
============
--------------------------------------
-Configuration of IWD access point
+Configuration of IWD access points
--------------------------------------
:Author: James Prestwood <prestwoj@gmail.com>
@@ -25,19 +25,38 @@ Description of access point provisioning files.
DESCRIPTION
===========
-An access point provisioning files define the configuration of an IWD access
+An access point provisioning file defines the configuration of an IWD access
point. These files live in *$STATE_DIRECTORY*/ap (/var/lib/iwd/ap by default).
+They are read when the `net.connman.iwd.AccessPoint.StartProfile(ssid)` DBus
+method is used.
FILE FORMAT
===========
-See *iwd.network* for details on the file format.
+See *iwd.network* for details on the settings file syntax.
SETTINGS
========
The settings are split into several categories. Each category has a group
-associated with it and described in separate tables below.
+associated with it and is described in the corresponding table below.
+
+General Settings
+----------------
+
+The group ``[General]`` contains general AP configuration.
+
+.. list-table::
+ :header-rows: 0
+ :stub-columns: 0
+ :widths: 20 80
+ :align: left
+
+ * - Channel
+ - Channel number
+
+ Optional channel number for the access point to operate on. Only the
+ 2.4GHz-band channels are currently allowed.
Network Authentication Settings
-------------------------------
@@ -54,13 +73,30 @@ configuration.
* - Passphrase
- 8..63 character string
- Passphrase to be used with this access point.
+ WPA-PSK Passphrase to be used with this access point. At least one of
+ *Passphrase*, *PreSharedKey* must be present.
+
+ * - PreSharedKey
+ - 64-character hex-string
+
+ Processed passphrase for this network in the form of a hex-encoded
+ 32-byte pre-shared key. Either this or *Passphrase* must be present.
+
+IPv4 Network Configuration
+--------------------------
+
+The group ``[IPv4]`` contains settings for IWD's built-in DHCP server. All
+settings are optional. They're used if network configuration was enabled as
+described in ``iwd.config(5)``. Omitting the ``[IPv4]`` group disables
+network configuration for this access point so if an all-defaults DHCP setup
+is desired, the group header line must still be present:
+
+.. code-block::
-DHCP Server Settings
---------------------
+ # Enable network configuration
+ [IPv4]
-The group ``[IPv4]`` contains settings for IWD's built in DHCP server. All
-settings are optional.
+ [other groups follow]
.. list-table::
:header-rows: 0
@@ -68,41 +104,76 @@ settings are optional.
:widths: 20 80
* - Address
- - IP Address of AP
+ - Local IP address
- Optional address for the DHCP server/access point. If provided this
- address will be set on the AP interface and any other DHCP server options
- will be derived from this address, unless they are overriden inside the
- AP profile. If [IPv4].Address is not provided and no IP address is set
- on the interface prior to calling StartProfile the IP pool will be used.
+ 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.
* - Gateway
- IP Address of gateway
- IP address of gateway. This will inherit from [IPv4].Address if not
- provided.
+ IP address of the gateway to be advertised by DHCP. This will fall back
+ to the local IP address if not provided.
* - Netmask
- - Netmask of DHCP server
+ - Local netmask of the AP
- This will be generated from [IPv4].Address if not provided.
+ This will be generated from ``[IPv4].Address`` if not provided.
* - DNSList
- - List of DNS servers
+ - List of DNS servers as a comma-separated IP address list
A list of DNS servers which will be advertised by the DHCP server. If
not provided no DNS servers will be sent by the DHCP server.
* - LeaseTime
- - Time limit for DHCP leases
+ - Time limit for DHCP leases in seconds
Override the default lease time.
* - IPRange
- - Range of IPs to use for the DHCP server
+ - Range of IPs given as two addresses separated by a comma
+
+ From and to addresses of the range assigned to clients through DHCP.
+ If not provided the range from local address + 1 to .254 will be used.
+
+Wi-Fi Simple Configuration
+--------------------------
+
+The group ``[WSC]`` fine-tunes some Wi-Fi Simple Configuration local parameters
+(formerly known as WPS, Wi-Fi Protected Setup.)
+
+.. list-table::
+ :header-rows: 0
+ :stub-columns: 0
+ :widths: 20 80
+ :align: left
+
+ * - DeviceName
+ - 1..32-character string
+
+ Optional Device Name string for the AP to advertise as. Defaults to
+ the SSID.
+
+ * - PrimaryDeviceType
+ - Subcategory string or a 64-bit integer
+
+ Optional Primary Device Type for the AP to advertise as. Defaults to
+ PC computer. Can be specified as a lower-case WSC v2.0.5 subcategory
+ string or a 64-bit integer encoding, from MSB to LSB: the 16-bit
+ category ID, the 24-bit OUI, the 8-bit OUI type and the 16-bit
+ subcategory ID.
+
+ * - AuthorizedMACs
+ - Comma-separated MAC address list
- If not provided a default range will be chosen which is the DHCP server
- address + 1 to 254.
+ Optional list of Authorized MAC addresses for the WSC registrar to
+ check on association. Each address is specified in the
+ colon-hexadecimal notation. Defaults to no MAC-based checks.
SEE ALSO
========
diff --git a/src/netconfig.c b/src/netconfig.c
@@ -67,6 +67,8 @@ struct netconfig {
struct resolve *resolve;
struct l_acd *acd;
+
+ uint32_t route4_add_gateway_cmd_id;
};
static struct l_netlink *rtnl;
@@ -585,12 +587,25 @@ static void netconfig_ifaddr_ipv6_cmd_cb(int error, uint16_t type,
netconfig_ifaddr_ipv6_notify(type, data, len, user_data);
}
+static void netconfig_route_generic_cb(int error, uint16_t type,
+ const void *data, uint32_t len,
+ void *user_data)
+{
+ if (error) {
+ l_error("netconfig: Failed to add route. Error %d: %s",
+ error, strerror(-error));
+ return;
+ }
+}
+
static void netconfig_route_add_cmd_cb(int error, uint16_t type,
const void *data, uint32_t len,
void *user_data)
{
struct netconfig *netconfig = user_data;
+ netconfig->route4_add_gateway_cmd_id = 0;
+
if (error) {
l_error("netconfig: Failed to add route. Error %d: %s",
error, strerror(-error));
@@ -627,7 +642,7 @@ static bool netconfig_ipv4_routes_install(struct netconfig *netconfig)
if (!l_rtnl_route4_add_connected(rtnl, netconfig->ifindex,
prefix_len, network, ip,
netconfig->rtm_protocol,
- netconfig_route_add_cmd_cb,
+ netconfig_route_generic_cb,
netconfig, NULL)) {
l_error("netconfig: Failed to add subnet route.");
@@ -643,11 +658,13 @@ static bool netconfig_ipv4_routes_install(struct netconfig *netconfig)
return false;
}
- if (!l_rtnl_route4_add_gateway(rtnl, netconfig->ifindex, gateway, ip,
+ netconfig->route4_add_gateway_cmd_id =
+ l_rtnl_route4_add_gateway(rtnl, netconfig->ifindex, gateway, ip,
ROUTE_PRIORITY_OFFSET,
netconfig->rtm_protocol,
netconfig_route_add_cmd_cb,
- netconfig, NULL)) {
+ netconfig, NULL);
+ if (!netconfig->route4_add_gateway_cmd_id) {
l_error("netconfig: Failed to add route for: %s gateway.",
gateway);
@@ -695,7 +712,7 @@ static void netconfig_ipv6_ifaddr_add_cmd_cb(int error, uint16_t type,
if (gateway) {
L_WARN_ON(!l_rtnl_route_add(rtnl, netconfig->ifindex,
gateway,
- netconfig_route_add_cmd_cb,
+ netconfig_route_generic_cb,
netconfig, NULL));
l_rtnl_route_free(gateway);
}
@@ -1034,6 +1051,11 @@ bool netconfig_reset(struct netconfig *netconfig)
{
struct netdev *netdev = netdev_find(netconfig->ifindex);
+ if (netconfig->route4_add_gateway_cmd_id) {
+ l_netlink_cancel(rtnl, netconfig->route4_add_gateway_cmd_id);
+ netconfig->route4_add_gateway_cmd_id = 0;
+ }
+
if (netconfig->rtm_protocol || netconfig->rtm_v6_protocol)
resolve_revert(netconfig->resolve);
diff --git a/src/netdev.c b/src/netdev.c
@@ -67,6 +67,14 @@
#define ENOTSUPP 524
#endif
+enum connection_type {
+ CONNECTION_TYPE_SOFTMAC,
+ CONNECTION_TYPE_FULLMAC,
+ CONNECTION_TYPE_SAE_OFFLOAD,
+ CONNECTION_TYPE_PSK_OFFLOAD,
+ CONNECTION_TYPE_8021X_OFFLOAD,
+};
+
static uint32_t unicast_watch;
struct netdev_handshake_state {
@@ -75,11 +83,23 @@ struct netdev_handshake_state {
uint32_t group_new_key_cmd_id;
uint32_t group_management_new_key_cmd_id;
uint32_t set_station_cmd_id;
+ uint32_t set_pmk_cmd_id;
bool ptk_installed;
bool gtk_installed;
bool igtk_installed;
bool complete;
struct netdev *netdev;
+ enum connection_type type;
+};
+
+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;
};
struct netdev {
@@ -116,7 +136,6 @@ struct netdev {
struct l_timeout *neighbor_report_timeout;
struct l_timeout *sa_query_timeout;
struct l_timeout *group_handshake_timeout;
- struct l_timeout *gas_timeout;
uint16_t sa_query_id;
uint8_t prev_bssid[ETH_ALEN];
uint8_t prev_snonce[32];
@@ -140,6 +159,8 @@ struct netdev {
void *get_station_data;
netdev_destroy_func_t get_station_destroy;
+ struct l_idle *disconnect_idle;
+
struct watchlist station_watches;
struct l_io *pae_io; /* for drivers without EAPoL over NL80211 */
@@ -148,6 +169,8 @@ struct netdev {
struct l_genl_msg *auth_cmd;
struct wiphy_radio_work_item work;
+ struct netdev_ft_over_ds_info *ft_ds_info;
+
bool connected : 1;
bool associated : 1;
bool operational : 1;
@@ -182,6 +205,57 @@ static struct watchlist netdev_watches;
static bool pae_over_nl80211;
static bool mac_per_ssid;
+const char *netdev_iftype_to_string(uint32_t iftype)
+{
+ switch (iftype) {
+ case NL80211_IFTYPE_ADHOC:
+ return "ad-hoc";
+ case NL80211_IFTYPE_STATION:
+ return "station";
+ case NL80211_IFTYPE_AP:
+ return "ap";
+ case NL80211_IFTYPE_P2P_CLIENT:
+ return "p2p-client";
+ case NL80211_IFTYPE_P2P_GO:
+ return "p2p-go";
+ case NL80211_IFTYPE_P2P_DEVICE:
+ return "p2p-device";
+ default:
+ break;
+ }
+
+ return NULL;
+}
+
+static inline bool is_offload(struct handshake_state *hs)
+{
+ struct netdev_handshake_state *nhs =
+ l_container_of(hs, struct netdev_handshake_state, super);
+
+ if (!nhs)
+ return false;
+
+ switch (nhs->type) {
+ case CONNECTION_TYPE_SOFTMAC:
+ case CONNECTION_TYPE_FULLMAC:
+ /*
+ * 8021x offload does not quite fit into the same category of PSK
+ * offload. First the netdev_connect_event comes prior to EAP meaning
+ * the handshake is not done at this point. In addition it still
+ * requires EAP take place in userspace meaning IWD needs an eapol_sm.
+ * Because of this, and our prior use of 'is_offload', it does not fit
+ * into the same category and will need to be handled specially.
+ */
+ case CONNECTION_TYPE_8021X_OFFLOAD:
+ return false;
+ case CONNECTION_TYPE_SAE_OFFLOAD:
+ case CONNECTION_TYPE_PSK_OFFLOAD:
+ return true;
+ }
+
+ return false;
+}
+
/* Cancels ongoing GTK/IGTK related commands (if any) */
static void netdev_handshake_state_cancel_rekey(
struct netdev_handshake_state *nhs)
@@ -212,6 +286,11 @@ static void netdev_handshake_state_cancel_all(
l_genl_family_cancel(nl80211, nhs->set_station_cmd_id);
nhs->set_station_cmd_id = 0;
}
+
+ if (nhs->set_pmk_cmd_id) {
+ l_genl_family_cancel(nl80211, nhs->set_pmk_cmd_id);
+ nhs->set_pmk_cmd_id = 0;
+ }
}
static void netdev_handshake_state_free(struct handshake_state *hs)
@@ -269,22 +348,7 @@ uint64_t netdev_get_wdev_id(struct netdev *netdev)
enum netdev_iftype netdev_get_iftype(struct netdev *netdev)
{
- switch (netdev->type) {
- case NL80211_IFTYPE_STATION:
- return NETDEV_IFTYPE_STATION;
- case NL80211_IFTYPE_AP:
- return NETDEV_IFTYPE_AP;
- case NL80211_IFTYPE_ADHOC:
- return NETDEV_IFTYPE_ADHOC;
- case NL80211_IFTYPE_P2P_CLIENT:
- return NETDEV_IFTYPE_P2P_CLIENT;
- case NL80211_IFTYPE_P2P_GO:
- return NETDEV_IFTYPE_P2P_GO;
- default:
- /* can't really do much here */
- l_error("unknown iftype %u", netdev->type);
- return NETDEV_IFTYPE_STATION;
- }
+ return netdev->type;
}
const char *netdev_get_name(struct netdev *netdev)
@@ -689,6 +753,9 @@ static void netdev_connect_free(struct netdev *netdev)
l_genl_family_cancel(nl80211, netdev->disconnect_cmd_id);
netdev->disconnect_cmd_id = 0;
}
+
+ if (netdev->ft_ds_info)
+ ft_ds_info_free(&netdev->ft_ds_info->super);
}
static void netdev_connect_failed(struct netdev *netdev,
@@ -699,8 +766,6 @@ static void netdev_connect_failed(struct netdev *netdev,
netdev_event_func_t event_filter = netdev->event_filter;
void *connect_data = netdev->user_data;
- netdev->disconnect_cmd_id = 0;
-
/* Done this way to allow re-entrant netdev_connect calls */
netdev_connect_free(netdev);
@@ -716,6 +781,7 @@ static void netdev_disconnect_cb(struct l_genl_msg *msg, void *user_data)
{
struct netdev *netdev = user_data;
+ netdev->disconnect_cmd_id = 0;
netdev_connect_failed(netdev, netdev->result, netdev->last_code);
}
@@ -783,6 +849,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->events_ready)
WATCHLIST_NOTIFY(&netdev_watches, netdev_watch_func_t,
netdev, NETDEV_WATCH_EVENT_DEL);
@@ -1212,11 +1283,6 @@ static void netdev_connect_ok(struct netdev *netdev)
netdev->fw_roam_bss = NULL;
}
- /* Allow station to sync the PSK to disk */
- if (netdev->handshake && netdev->handshake->offload)
- handshake_event(netdev->handshake,
- HANDSHAKE_EVENT_SETTING_KEYS);
-
if (netdev->connect_cb) {
netdev->connect_cb(netdev, NETDEV_RESULT_OK, NULL,
netdev->user_data);
@@ -1257,12 +1323,20 @@ static void netdev_setting_keys_failed(struct netdev_handshake_state *nhs,
netdev->group_handshake_timeout = NULL;
}
- netdev->result = NETDEV_RESULT_KEY_SETTING_FAILED;
- handshake_event(&nhs->super, HANDSHAKE_EVENT_SETTING_KEYS_FAILED, &err);
-
switch (netdev->type) {
case NL80211_IFTYPE_STATION:
case NL80211_IFTYPE_P2P_CLIENT:
+ /*
+ * If we failed due to the netdev being brought down,
+ * just abort the connection and do not try to send a
+ * CMD_DISCONNECT
+ */
+ if (err == -ENETDOWN) {
+ netdev_connect_failed(netdev, NETDEV_RESULT_ABORTED,
+ MMPDU_STATUS_CODE_UNSPECIFIED);
+ return;
+ }
+
msg = netdev_build_cmd_disconnect(netdev,
MMPDU_REASON_CODE_UNSPECIFIED);
netdev->disconnect_cmd_id = l_genl_family_send(nl80211, msg,
@@ -1270,11 +1344,19 @@ static void netdev_setting_keys_failed(struct netdev_handshake_state *nhs,
netdev, NULL);
break;
case NL80211_IFTYPE_AP:
+ if (err == -ENETDOWN)
+ return;
+
msg = netdev_build_cmd_del_station(netdev, nhs->super.spa,
MMPDU_REASON_CODE_UNSPECIFIED, false);
if (!l_genl_family_send(nl80211, msg, NULL, NULL, NULL))
l_error("error sending DEL_STATION");
+
+ break;
}
+
+ netdev->result = NETDEV_RESULT_KEY_SETTING_FAILED;
+ handshake_event(&nhs->super, HANDSHAKE_EVENT_SETTING_KEYS_FAILED, &err);
}
static void try_handshake_complete(struct netdev_handshake_state *nhs)
@@ -1284,7 +1366,9 @@ static void try_handshake_complete(struct netdev_handshake_state *nhs)
nhs->complete = true;
handshake_event(&nhs->super, HANDSHAKE_EVENT_COMPLETE);
- netdev_connect_ok(nhs->netdev);
+ if (nhs->netdev->type == NL80211_IFTYPE_STATION ||
+ nhs->netdev->type == NL80211_IFTYPE_P2P_CLIENT)
+ netdev_connect_ok(nhs->netdev);
}
}
@@ -1665,6 +1749,54 @@ invalid_key:
netdev_setting_keys_failed(nhs, err);
}
+static void netdev_set_pmk_cb(struct l_genl_msg *msg, void *user_data)
+{
+ struct netdev_handshake_state *nhs = user_data;
+ struct netdev *netdev = nhs->netdev;
+ int err = l_genl_msg_get_error(msg);
+
+ nhs->set_pmk_cmd_id = 0;
+
+ if (err < 0) {
+ l_error("Error with SET_PMK/SET_STATION");
+ netdev_setting_keys_failed(nhs, err);
+ return;
+ }
+
+ handshake_event(netdev->handshake, HANDSHAKE_EVENT_SETTING_KEYS);
+ netdev_connect_ok(netdev);
+}
+
+static void netdev_set_pmk(struct handshake_state *hs, const uint8_t *pmk,
+ size_t pmk_len)
+{
+ struct l_genl_msg *msg;
+ struct netdev_handshake_state *nhs = l_container_of(hs,
+ struct netdev_handshake_state, super);
+ struct netdev *netdev = nhs->netdev;
+
+ /* Only relevent for 8021x offload */
+ if (nhs->type != CONNECTION_TYPE_8021X_OFFLOAD)
+ return;
+
+ msg = l_genl_msg_new(NL80211_CMD_SET_PMK);
+
+ l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
+ l_genl_msg_append_attr(msg, NL80211_ATTR_MAC, 6, netdev->handshake->aa);
+ l_genl_msg_append_attr(msg, NL80211_ATTR_PMK,
+ netdev->handshake->pmk_len,
+ netdev->handshake->pmk);
+
+ nhs->set_pmk_cmd_id = l_genl_family_send(nl80211, msg,
+ netdev_set_pmk_cb,
+ nhs, NULL);
+ if (!nhs->set_pmk_cmd_id) {
+ l_error("Failed to set SET_PMK");
+ netdev_setting_keys_failed(nhs, -EIO);
+ return;
+ }
+}
+
void netdev_handshake_failed(struct handshake_state *hs, uint16_t reason_code)
{
struct netdev_handshake_state *nhs =
@@ -1825,6 +1957,60 @@ static void netdev_send_qos_map_set(struct netdev *netdev,
netdev, NULL);
}
+static void parse_request_ies(struct netdev *netdev, const uint8_t *ies,
+ size_t ies_len)
+{
+ struct ie_tlv_iter iter;
+ const void *data;
+
+ /*
+ * The driver may have modified the IEs we passed to CMD_CONNECT
+ * before sending them out, the actual IE sent is reflected in the
+ * ATTR_REQ_IE sequence. These are the values EAPoL will need to use.
+ */
+ ie_tlv_iter_init(&iter, ies, ies_len);
+
+ while (ie_tlv_iter_next(&iter)) {
+ data = ie_tlv_iter_get_data(&iter);
+
+ switch (ie_tlv_iter_get_tag(&iter)) {
+ case IE_TYPE_RSN:
+ handshake_state_set_supplicant_ie(netdev->handshake,
+ data - 2);
+ break;
+ case IE_TYPE_VENDOR_SPECIFIC:
+ if (!is_ie_wpa_ie(data, ie_tlv_iter_get_length(&iter)))
+ break;
+
+ handshake_state_set_supplicant_ie(netdev->handshake,
+ data - 2);
+ break;
+ case IE_TYPE_MOBILITY_DOMAIN:
+ handshake_state_set_mde(netdev->handshake, data - 2);
+ break;
+ }
+ }
+}
+
+static void netdev_driver_connected(struct netdev *netdev)
+{
+ netdev->connected = true;
+
+ if (netdev->event_filter)
+ netdev->event_filter(netdev, NETDEV_EVENT_ASSOCIATING, NULL,
+ netdev->user_data);
+
+ /*
+ * We register the eapol state machine here, in case the PAE
+ * socket receives EAPoL packets before the nl80211 socket
+ * receives the connected event. The logical sequence of
+ * events can be reversed (e.g. connect_event, then PAE data)
+ * due to scheduling
+ */
+ if (netdev->sm)
+ eapol_register(netdev->sm);
+}
+
static void netdev_connect_event(struct l_genl_msg *msg, struct netdev *netdev)
{
struct l_genl_attr attr;
@@ -1836,7 +2022,6 @@ static void netdev_connect_event(struct l_genl_msg *msg, struct netdev *netdev)
struct ie_tlv_iter iter;
const uint8_t *resp_ies = NULL;
size_t resp_ies_len;
- uint8_t cmd = l_genl_msg_get_command(msg);
l_debug("");
@@ -1846,6 +2031,10 @@ static void netdev_connect_event(struct l_genl_msg *msg, struct netdev *netdev)
if (netdev->ignore_connect_event)
return;
+ /* Work around mwifiex which sends a Connect Event prior to the Ack */
+ if (netdev->connect_cmd_id)
+ netdev_driver_connected(netdev);
+
if (!netdev->connected) {
l_warn("Unexpected connection related event -- "
"is another supplicant running?");
@@ -1890,46 +2079,14 @@ static void netdev_connect_event(struct l_genl_msg *msg, struct netdev *netdev)
goto error;
}
- /*
- * A CMD_ROAM event will not have a status code, since it indicates
- * the hardware has already roamed. A failed roam on fullmac should
- * result in an explicit disconnect event.
- */
- if (cmd == NL80211_CMD_CONNECT) {
- /* AP Rejected the authenticate / associate */
- if (!status_code || *status_code != 0)
- goto error;
- }
+ /* AP Rejected the authenticate / associate */
+ if (!status_code || *status_code != 0)
+ goto error;
if (!ies)
goto process_resp_ies;
- /*
- * The driver may have modified the IEs we passed to CMD_CONNECT
- * before sending them out, the actual IE sent is reflected in the
- * ATTR_REQ_IE sequence. These are the values EAPoL will need to use.
- */
- ie_tlv_iter_init(&iter, ies, ies_len);
-
- while (ie_tlv_iter_next(&iter)) {
- data = ie_tlv_iter_get_data(&iter);
-
- switch (ie_tlv_iter_get_tag(&iter)) {
- case IE_TYPE_RSN:
- handshake_state_set_supplicant_ie(netdev->handshake,
- data - 2);
- break;
- case IE_TYPE_VENDOR_SPECIFIC:
- if (!is_ie_wpa_ie(data, ie_tlv_iter_get_length(&iter)))
- break;
- handshake_state_set_supplicant_ie(netdev->handshake,
- data - 2);
- break;
- case IE_TYPE_MOBILITY_DOMAIN:
- handshake_state_set_mde(netdev->handshake, data - 2);
- break;
- }
- }
+ parse_request_ies(netdev, ies, ies_len);
process_resp_ies:
if (resp_ies) {
@@ -1984,28 +2141,8 @@ process_resp_ies:
netdev_send_qos_map_set(netdev, qos_set, qos_len);
}
- /*
- * TODO: Only SAE/WPA3-personal offload is supported. In this case IWD
- * is 'done'. In the case of 8021x offload EAP still needs to take
- * place, so this must be updated accordingly when that is implemented.
- */
- if (netdev->handshake->offload)
- goto done;
-
if (netdev->sm) {
/*
- * Let station know about the roam so a state change can occur.
- */
- if (cmd == NL80211_CMD_ROAM) {
- if (netdev->event_filter)
- netdev->event_filter(netdev,
- NETDEV_EVENT_ROAMING,
- NULL, netdev->user_data);
- /* EAPoL started after GET_SCAN */
- return;
- }
-
- /*
* Start processing EAPoL frames now that the state machine
* has all the input data even in FT mode.
*/
@@ -2015,7 +2152,11 @@ process_resp_ies:
return;
}
-done:
+ /* Allow station to sync the PSK to disk */
+ if (is_offload(netdev->handshake))
+ handshake_event(netdev->handshake,
+ HANDSHAKE_EVENT_SETTING_KEYS);
+
netdev_connect_ok(netdev);
return;
@@ -2234,12 +2375,7 @@ static void netdev_authenticate_event(struct l_genl_msg *msg,
return;
else if (ret > 0)
status_code = (uint16_t)ret;
-
- goto auth_error;
- } else
- goto auth_error;
-
- return;
+ }
auth_error:
netdev_connect_failed(netdev, NETDEV_RESULT_AUTHENTICATION_FAILED,
@@ -2280,7 +2416,15 @@ static void netdev_associate_event(struct l_genl_msg *msg,
if (auth_proto_assoc_timeout(netdev->ap))
return;
- goto assoc_failed;
+ /*
+ * There will be no connect event when Associate times
+ * out. The failed connection must be explicitly
+ * initiated here.
+ */
+ netdev_connect_failed(netdev,
+ NETDEV_RESULT_ASSOCIATION_FAILED,
+ status_code);
+ return;
case NL80211_ATTR_FRAME:
frame = data;
@@ -2326,7 +2470,7 @@ static void netdev_associate_event(struct l_genl_msg *msg,
} else if (ret == -EAGAIN) {
/*
* Here to support OWE retries. OWE will retry
- * internally, but a connect even will still be emitted.
+ * internally, but a connect event will still be emitted
*/
netdev->ignore_connect_event = true;
return;
@@ -2350,25 +2494,14 @@ static void netdev_cmd_connect_cb(struct l_genl_msg *msg, void *user_data)
netdev->connect_cmd_id = 0;
- /* Wait for connect event */
if (l_genl_msg_get_error(msg) >= 0) {
- netdev->connected = true;
-
- if (netdev->event_filter)
- netdev->event_filter(netdev,
- NETDEV_EVENT_ASSOCIATING,
- NULL,
- netdev->user_data);
-
/*
- * We register the eapol state machine here, in case the PAE
- * socket receives EAPoL packets before the nl80211 socket
- * receives the connected event. The logical sequence of
- * events can be reversed (e.g. connect_event, then PAE data)
- * due to scheduling
+ * connected should be false if the connect event hasn't come
+ * in yet. i.e. the CMD_CONNECT ack arrived first (typical).
+ * Mark the connection as 'connected'
*/
- if (netdev->sm)
- eapol_register(netdev->sm);
+ if (!netdev->connected)
+ netdev_driver_connected(netdev);
return;
}
@@ -2615,6 +2748,8 @@ static struct l_genl_msg *netdev_build_cmd_connect(struct netdev *netdev,
const struct iovec *vendor_ies,
size_t num_vendor_ies)
{
+ struct netdev_handshake_state *nhs =
+ l_container_of(hs, struct netdev_handshake_state, super);
uint32_t auth_type = IE_AKM_IS_SAE(hs->akm_suite) ?
NL80211_AUTHTYPE_SAE :
NL80211_AUTHTYPE_OPEN_SYSTEM;
@@ -2634,10 +2769,20 @@ static struct l_genl_msg *netdev_build_cmd_connect(struct netdev *netdev,
bss->ssid_len, bss->ssid);
l_genl_msg_append_attr(msg, NL80211_ATTR_AUTH_TYPE, 4, &auth_type);
- if (hs->offload) {
- if (IE_AKM_IS_SAE(hs->akm_suite))
- l_genl_msg_append_attr(msg, NL80211_ATTR_SAE_PASSWORD,
+ switch (nhs->type) {
+ case CONNECTION_TYPE_SOFTMAC:
+ case CONNECTION_TYPE_FULLMAC:
+ break;
+ case CONNECTION_TYPE_SAE_OFFLOAD:
+ l_genl_msg_append_attr(msg, NL80211_ATTR_SAE_PASSWORD,
strlen(hs->passphrase), hs->passphrase);
+ break;
+ case CONNECTION_TYPE_PSK_OFFLOAD:
+ l_genl_msg_append_attr(msg, NL80211_ATTR_PMK, 32, hs->pmk);
+ break;
+ case CONNECTION_TYPE_8021X_OFFLOAD:
+ l_genl_msg_append_attr(msg, NL80211_ATTR_WANT_1X_4WAY_HS,
+ 0, NULL);
}
if (prev_bssid)
@@ -2994,6 +3139,93 @@ static const struct wiphy_radio_work_item_ops connect_work_ops = {
.destroy = netdev_connection_work_destroy,
};
+static int netdev_handshake_state_setup_connection_type(
+ struct handshake_state *hs)
+{
+ struct netdev_handshake_state *nhs = l_container_of(hs,
+ struct netdev_handshake_state, super);
+ struct wiphy *wiphy = nhs->netdev->wiphy;
+ bool softmac = wiphy_supports_cmds_auth_assoc(wiphy);
+ bool canroam = wiphy_supports_firmware_roam(wiphy);
+
+ /*
+ * Sanity check that any FT AKMs are set only on softmac or on
+ * devices that support firmware roam
+ */
+ if (L_WARN_ON(IE_AKM_IS_FT(hs->akm_suite) && !softmac && !canroam))
+ return -ENOTSUP;
+
+ switch (hs->akm_suite) {
+ case IE_RSN_AKM_SUITE_PSK:
+ case IE_RSN_AKM_SUITE_FT_USING_PSK:
+ case IE_RSN_AKM_SUITE_PSK_SHA256:
+ if (wiphy_has_ext_feature(wiphy,
+ NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
+ goto psk_offload;
+
+ if (softmac)
+ goto softmac;
+
+ goto fullmac;
+ case IE_RSN_AKM_SUITE_8021X:
+ case IE_RSN_AKM_SUITE_FT_OVER_8021X:
+ case IE_RSN_AKM_SUITE_8021X_SHA256:
+ case IE_RSN_AKM_SUITE_8021X_SUITE_B_SHA256:
+ case IE_RSN_AKM_SUITE_8021X_SUITE_B_SHA384:
+ case IE_RSN_AKM_SUITE_FT_OVER_8021X_SHA384:
+ if (wiphy_has_ext_feature(wiphy,
+ NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
+ goto offload_1x;
+
+ if (softmac)
+ goto softmac;
+
+ goto fullmac;
+ case IE_RSN_AKM_SUITE_SAE_SHA256:
+ case IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256:
+ if (wiphy_has_ext_feature(wiphy,
+ NL80211_EXT_FEATURE_SAE_OFFLOAD))
+ goto sae_offload;
+
+ if (softmac && wiphy_has_feature(wiphy, NL80211_FEATURE_SAE))
+ goto softmac;
+
+ return -EINVAL;
+ case IE_RSN_AKM_SUITE_OWE:
+ case IE_RSN_AKM_SUITE_FILS_SHA256:
+ case IE_RSN_AKM_SUITE_FILS_SHA384:
+ case IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA256:
+ case IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384:
+ /* FILS and OWE have no offload in any upstream driver */
+ if (softmac)
+ goto softmac;
+
+ return -ENOTSUP;
+ case IE_RSN_AKM_SUITE_TDLS:
+ case IE_RSN_AKM_SUITE_AP_PEER_KEY_SHA256:
+ case IE_RSN_AKM_SUITE_OSEN:
+ return -ENOTSUP;
+ }
+
+ return -ENOTSUP;
+
+softmac:
+ nhs->type = CONNECTION_TYPE_SOFTMAC;
+ return 0;
+fullmac:
+ nhs->type = CONNECTION_TYPE_FULLMAC;
+ return 0;
+sae_offload:
+ nhs->type = CONNECTION_TYPE_SAE_OFFLOAD;
+ return 0;
+psk_offload:
+ nhs->type = CONNECTION_TYPE_PSK_OFFLOAD;
+ return 0;
+offload_1x:
+ nhs->type = CONNECTION_TYPE_8021X_OFFLOAD;
+ return 0;
+}
+
static int netdev_connect_common(struct netdev *netdev,
struct l_genl_msg *cmd_connect,
struct scan_bss *bss,
@@ -3030,6 +3262,8 @@ int netdev_connect(struct netdev *netdev, struct scan_bss *bss,
netdev_event_func_t event_filter,
netdev_connect_cb_t cb, void *user_data)
{
+ struct netdev_handshake_state *nhs = l_container_of(hs,
+ struct netdev_handshake_state, super);
struct l_genl_msg *cmd_connect = NULL;
struct eapol_sm *sm = NULL;
bool is_rsn = hs->supplicant_ie != NULL;
@@ -3041,12 +3275,20 @@ int netdev_connect(struct netdev *netdev, struct scan_bss *bss,
if (netdev->connected || netdev->connect_cmd_id || netdev->work.id)
return -EISCONN;
+ if (!is_rsn) {
+ nhs->type = CONNECTION_TYPE_SOFTMAC;
+ goto build_cmd_connect;
+ }
+
+ if (netdev_handshake_state_setup_connection_type(hs) < 0)
+ return -ENOTSUP;
+
+ if (nhs->type != CONNECTION_TYPE_SOFTMAC)
+ goto build_cmd_connect;
+
switch (hs->akm_suite) {
case IE_RSN_AKM_SUITE_SAE_SHA256:
case IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256:
- if (hs->offload)
- goto build_cmd_connect;
-
netdev->ap = sae_sm_new(hs, netdev_sae_tx_authenticate,
netdev_sae_tx_associate,
netdev);
@@ -3072,14 +3314,28 @@ build_cmd_connect:
if (!cmd_connect)
return -EINVAL;
- if (!hs->offload && (is_rsn || hs->settings_8021x))
+ if (!is_offload(hs) && (is_rsn || hs->settings_8021x)) {
sm = eapol_sm_new(hs);
+
+ if (nhs->type == CONNECTION_TYPE_8021X_OFFLOAD)
+ eapol_sm_set_require_handshake(sm, false);
+ }
}
return netdev_connect_common(netdev, cmd_connect, bss, hs, sm,
event_filter, cb, user_data);
}
+static void disconnect_idle(struct l_idle *idle, void *user_data)
+{
+ struct netdev *netdev = user_data;
+
+ l_idle_remove(idle);
+ netdev->disconnect_idle = NULL;
+
+ netdev->disconnect_cb(netdev, true, netdev->user_data);
+}
+
int netdev_disconnect(struct netdev *netdev,
netdev_disconnect_cb_t cb, void *user_data)
{
@@ -3112,7 +3368,8 @@ int netdev_disconnect(struct netdev *netdev,
if (netdev->connect_cmd_id) {
l_genl_family_cancel(nl80211, netdev->connect_cmd_id);
netdev->connect_cmd_id = 0;
- } else
+ } else if (!wiphy_radio_work_is_running(netdev->wiphy,
+ netdev->work.id))
send_disconnect = false;
netdev_connect_failed(netdev, NETDEV_RESULT_ABORTED,
@@ -3136,8 +3393,12 @@ int netdev_disconnect(struct netdev *netdev,
netdev->disconnect_cb = cb;
netdev->user_data = user_data;
netdev->aborting = true;
- } else if (cb)
- cb(netdev, true, user_data);
+ } else if (cb) {
+ netdev->disconnect_cb = cb;
+ netdev->user_data = user_data;
+ netdev->disconnect_idle = l_idle_create(disconnect_idle,
+ netdev, NULL);
+ }
return 0;
}
@@ -3154,6 +3415,14 @@ int netdev_reassociate(struct netdev *netdev, struct scan_bss *target_bss,
bool is_rsn = hs->supplicant_ie != NULL;
int err;
+ if (netdev_handshake_state_setup_connection_type(hs) < 0)
+ return -ENOTSUP;
+
+ /* TODO: SoftMac SAE/FILS Re-Associations are not suppored yet */
+ if (L_WARN_ON(IE_AKM_IS_SAE(hs->akm_suite) ||
+ IE_AKM_IS_FILS(hs->akm_suite)))
+ return -ENOTSUP;
+
cmd_connect = netdev_build_cmd_connect(netdev, target_bss, hs,
orig_bss->addr, NULL, 0);
if (!cmd_connect)
@@ -3170,10 +3439,17 @@ 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;
netdev->operational = false;
+ netdev->connected = false;
netdev_rssi_polling_update(netdev);
@@ -3298,7 +3574,8 @@ static uint32_t netdev_send_action_framev(struct netdev *netdev,
const uint8_t *to,
struct iovec *iov, size_t iov_len,
uint32_t freq,
- l_genl_msg_func_t callback)
+ l_genl_msg_func_t callback,
+ void *user_data)
{
uint32_t id;
struct l_genl_msg *msg = nl80211_build_cmd_frame(netdev->index,
@@ -3306,7 +3583,7 @@ static uint32_t netdev_send_action_framev(struct netdev *netdev,
to, freq,
iov, iov_len);
- id = l_genl_family_send(nl80211, msg, callback, netdev, NULL);
+ id = l_genl_family_send(nl80211, msg, callback, user_data, NULL);
if (!id)
l_genl_msg_unref(msg);
@@ -3318,14 +3595,16 @@ static uint32_t netdev_send_action_frame(struct netdev *netdev,
const uint8_t *to,
const uint8_t *body, size_t body_len,
uint32_t freq,
- l_genl_msg_func_t callback)
+ l_genl_msg_func_t callback,
+ void *user_data)
{
struct iovec iov[1];
iov[0].iov_base = (void *)body;
iov[0].iov_len = body_len;
- return netdev_send_action_framev(netdev, to, iov, 1, freq, callback);
+ return netdev_send_action_framev(netdev, to, iov, 1, freq, callback,
+ user_data);
}
static void netdev_cmd_authenticate_ft_cb(struct l_genl_msg *msg,
@@ -3373,7 +3652,7 @@ restore_snonce:
MMPDU_STATUS_CODE_UNSPECIFIED);
}
-static void netdev_ft_tx_associate(struct iovec *ie_iov, size_t iov_len,
+static int netdev_ft_tx_associate(struct iovec *ie_iov, size_t iov_len,
void *user_data)
{
struct netdev *netdev = user_data;
@@ -3391,49 +3670,131 @@ static void netdev_ft_tx_associate(struct iovec *ie_iov, size_t iov_len,
if (!netdev->connect_cmd_id) {
l_genl_msg_unref(msg);
- netdev_connect_failed(netdev, NETDEV_RESULT_ASSOCIATION_FAILED,
- MMPDU_STATUS_CODE_UNSPECIFIED);
- return;
+ 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;
}
-static void netdev_ft_request_cb(struct l_genl_msg *msg, void *user_data)
+static void prepare_ft(struct netdev *netdev, struct scan_bss *target_bss)
{
- struct netdev *netdev = user_data;
+ struct netdev_handshake_state *nhs;
- if (l_genl_msg_get_error(msg) < 0) {
- l_error("Could not send CMD_FRAME");
- netdev_connect_failed(netdev,
- NETDEV_RESULT_AUTHENTICATION_FAILED,
- MMPDU_STATUS_CODE_UNSPECIFIED);
+ /*
+ * We reuse the handshake_state object and reset what's needed.
+ * Could also create a new object and copy most of the state but
+ * we would end up doing more work.
+ */
+ memcpy(netdev->prev_snonce, netdev->handshake->snonce, 32);
+
+ memcpy(netdev->prev_bssid, netdev->handshake->aa, 6);
+ netdev->prev_frequency = netdev->frequency;
+ netdev->frequency = target_bss->frequency;
+
+ handshake_state_set_authenticator_address(netdev->handshake,
+ target_bss->addr);
+
+ if (target_bss->rsne)
+ handshake_state_set_authenticator_ie(netdev->handshake,
+ target_bss->rsne);
+ memcpy(netdev->handshake->mde + 2, target_bss->mde, 3);
+
+ netdev->associated = false;
+ netdev->operational = false;
+ netdev->in_ft = true;
+
+ /*
+ * Cancel commands that could be running because of EAPoL activity
+ * like re-keying, this way the callbacks for those commands don't
+ * have to check if failures resulted from the transition.
+ */
+ nhs = l_container_of(netdev->handshake,
+ struct netdev_handshake_state, super);
+
+ /* reset key states just as we do in initialization */
+ nhs->complete = false;
+ nhs->ptk_installed = false;
+ nhs->gtk_installed = true;
+ nhs->igtk_installed = true;
+
+ if (nhs->group_new_key_cmd_id) {
+ l_genl_family_cancel(nl80211, nhs->group_new_key_cmd_id);
+ nhs->group_new_key_cmd_id = 0;
+ }
+
+ if (nhs->group_management_new_key_cmd_id) {
+ l_genl_family_cancel(nl80211,
+ nhs->group_management_new_key_cmd_id);
+ nhs->group_management_new_key_cmd_id = 0;
+ }
+
+ if (netdev->rekey_offload_cmd_id) {
+ l_genl_family_cancel(nl80211, netdev->rekey_offload_cmd_id);
+ netdev->rekey_offload_cmd_id = 0;
+ }
+
+ netdev_rssi_polling_update(netdev);
+
+ if (netdev->sm) {
+ eapol_sm_free(netdev->sm);
+ netdev->sm = NULL;
}
}
+static void netdev_ft_over_ds_auth_failed(struct netdev_ft_over_ds_info *info,
+ uint16_t status)
+{
+ if (info->cb)
+ info->cb(info->netdev, status, info->super.aa, info->user_data);
+
+ ft_ds_info_free(&info->super);
+
+ info->netdev->ft_ds_info = NULL;
+}
+
static void netdev_ft_response_frame_event(const struct mmpdu_header *hdr,
const void *body, size_t body_len,
int rssi, void *user_data)
{
+ struct netdev *netdev = user_data;
+ struct netdev_ft_over_ds_info *info = netdev->ft_ds_info;
int ret;
uint16_t status_code = MMPDU_STATUS_CODE_UNSPECIFIED;
- struct netdev *netdev = user_data;
- if (!netdev->ap || !netdev->in_ft)
+ if (!info)
return;
- ret = auth_proto_rx_authenticate(netdev->ap, body, body_len);
+ ret = ft_over_ds_parse_action_response(&info->super, netdev->handshake,
+ body, body_len);
if (ret < 0)
- goto ft_error;
- else if (ret > 0) {
+ return;
+
+ l_timeout_remove(info->timeout);
+ info->timeout = NULL;
+
+ /* Now make sure the packet contained a success status code */
+ if (ret > 0) {
status_code = (uint16_t)ret;
goto ft_error;
}
+ info->parsed = true;
+
+ if (info->cb)
+ info->cb(netdev, 0, info->super.aa, info->user_data);
+
return;
ft_error:
- netdev_connect_failed(netdev, NETDEV_RESULT_AUTHENTICATION_FAILED,
- status_code);
- return;
+ l_debug("FT-over-DS to "MAC" failed", MAC_STR(info->super.aa));
+
+ netdev_ft_over_ds_auth_failed(info, status_code);
}
static void netdev_qos_map_frame_event(const struct mmpdu_header *hdr,
@@ -3458,28 +3819,6 @@ static void netdev_qos_map_frame_event(const struct mmpdu_header *hdr,
netdev_send_qos_map_set(netdev, body + 4, body_len - 4);
}
-static void netdev_ft_over_ds_tx_authenticate(struct iovec *iov,
- size_t iov_len, void *user_data)
-{
- struct netdev *netdev = user_data;
- uint8_t ft_req[14];
- struct handshake_state *hs = netdev->handshake;
- struct iovec iovs[iov_len + 1];
-
- ft_req[0] = 6; /* FT category */
- ft_req[1] = 1; /* FT Request action */
- memcpy(ft_req + 2, netdev->addr, 6);
- memcpy(ft_req + 8, hs->aa, 6);
-
- iovs[0].iov_base = ft_req;
- iovs[0].iov_len = sizeof(ft_req);
- memcpy(iovs + 1, iov, sizeof(*iov) * iov_len);
-
- netdev_send_action_framev(netdev, netdev->prev_bssid, iovs, iov_len + 1,
- netdev->prev_frequency,
- netdev_ft_request_cb);
-}
-
static bool netdev_ft_work_ready(struct wiphy_radio_work_item *item)
{
struct netdev *netdev = l_container_of(item, struct netdev, work);
@@ -3500,12 +3839,9 @@ static const struct wiphy_radio_work_item_ops ft_work_ops = {
.do_work = netdev_ft_work_ready,
};
-static int fast_transition(struct netdev *netdev, struct scan_bss *target_bss,
- bool over_air,
+int netdev_fast_transition(struct netdev *netdev, struct scan_bss *target_bss,
netdev_connect_cb_t cb)
{
- struct netdev_handshake_state *nhs;
-
if (!netdev->operational)
return -ENOTCONN;
@@ -3514,77 +3850,48 @@ static int fast_transition(struct netdev *netdev, struct scan_bss *target_bss,
l_get_le16(target_bss->mde))
return -EINVAL;
- /*
- * We reuse the handshake_state object and reset what's needed.
- * Could also create a new object and copy most of the state but
- * we would end up doing more work.
- */
- memcpy(netdev->prev_bssid, netdev->handshake->aa, ETH_ALEN);
- memcpy(netdev->prev_snonce, netdev->handshake->snonce, 32);
+ prepare_ft(netdev, target_bss);
handshake_state_new_snonce(netdev->handshake);
- netdev->prev_frequency = netdev->frequency;
- netdev->frequency = target_bss->frequency;
+ netdev->connect_cb = cb;
- handshake_state_set_authenticator_address(netdev->handshake,
- target_bss->addr);
+ netdev->ap = ft_over_air_sm_new(netdev->handshake,
+ netdev_ft_tx_authenticate,
+ netdev_ft_tx_associate, netdev);
- if (target_bss->rsne)
- handshake_state_set_authenticator_ie(netdev->handshake,
- target_bss->rsne);
- memcpy(netdev->handshake->mde + 2, target_bss->mde, 3);
+ wiphy_radio_work_insert(netdev->wiphy, &netdev->work, 1,
+ &ft_work_ops);
- netdev->associated = false;
- netdev->operational = false;
- netdev->in_ft = true;
- netdev->connect_cb = cb;
+ return 0;
+}
- /*
- * Cancel commands that could be running because of EAPoL activity
- * like re-keying, this way the callbacks for those commands don't
- * have to check if failures resulted from the transition.
- */
- nhs = l_container_of(netdev->handshake,
- struct netdev_handshake_state, super);
+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;
- /* reset key states just as we do in initialization */
- nhs->complete = false;
- nhs->ptk_installed = false;
- nhs->gtk_installed = true;
- nhs->igtk_installed = true;
+ if (!info || !info->parsed)
+ return -ENOENT;
- if (nhs->group_new_key_cmd_id) {
- l_genl_family_cancel(nl80211, nhs->group_new_key_cmd_id);
- nhs->group_new_key_cmd_id = 0;
- }
+ if (!netdev->operational)
+ return -ENOTCONN;
- if (nhs->group_management_new_key_cmd_id) {
- l_genl_family_cancel(nl80211,
- nhs->group_management_new_key_cmd_id);
- nhs->group_management_new_key_cmd_id = 0;
- }
+ if (!netdev->handshake->mde || !target_bss->mde_present ||
+ l_get_le16(netdev->handshake->mde + 2) !=
+ l_get_le16(target_bss->mde))
+ return -EINVAL;
- if (netdev->rekey_offload_cmd_id) {
- l_genl_family_cancel(nl80211, netdev->rekey_offload_cmd_id);
- netdev->rekey_offload_cmd_id = 0;
- }
+ prepare_ft(netdev, target_bss);
- netdev_rssi_polling_update(netdev);
+ ft_over_ds_prepare_handshake(&info->super, netdev->handshake);
- if (netdev->sm) {
- eapol_sm_free(netdev->sm);
- netdev->sm = NULL;
- }
+ netdev->connect_cb = cb;
- if (over_air)
- netdev->ap = ft_over_air_sm_new(netdev->handshake,
- netdev_ft_tx_authenticate,
- netdev_ft_tx_associate, netdev);
- else
- netdev->ap = ft_over_ds_sm_new(netdev->handshake,
- netdev_ft_over_ds_tx_authenticate,
- netdev_ft_tx_associate, netdev);
+ netdev->ap = ft_over_ds_sm_new(netdev->handshake,
+ netdev_ft_tx_associate,
+ netdev);
wiphy_radio_work_insert(netdev->wiphy, &netdev->work, 1,
&ft_work_ops);
@@ -3592,17 +3899,110 @@ static int fast_transition(struct netdev *netdev, struct scan_bss *target_bss,
return 0;
}
-int netdev_fast_transition(struct netdev *netdev, struct scan_bss *target_bss,
- netdev_connect_cb_t cb)
+static void netdev_ft_request_cb(struct l_genl_msg *msg, void *user_data)
{
- return fast_transition(netdev, target_bss, true, cb);
+ struct netdev_ft_over_ds_info *info = user_data;
+
+ if (l_genl_msg_get_error(msg) < 0) {
+ l_error("Could not send CMD_FRAME for FT-over-DS");
+ netdev_ft_over_ds_auth_failed(info,
+ MMPDU_STATUS_CODE_UNSPECIFIED);
+ }
}
-int netdev_fast_transition_over_ds(struct netdev *netdev,
- struct scan_bss *target_bss,
- netdev_connect_cb_t cb)
+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)
{
- return fast_transition(netdev, target_bss, false, cb);
+ 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)
+{
+ struct netdev_ft_over_ds_info *info;
+ uint8_t ft_req[14];
+ struct handshake_state *hs = netdev->handshake;
+ struct iovec iovs[5];
+ uint8_t buf[512];
+ size_t len;
+
+ /* TODO: Just allow single outstanding action frame for now */
+ if (netdev->ft_ds_info)
+ return -EALREADY;
+
+ if (!netdev->operational)
+ return -ENOTCONN;
+
+ if (!netdev->handshake->mde || !target_bss->mde_present ||
+ l_get_le16(netdev->handshake->mde + 2) !=
+ l_get_le16(target_bss->mde))
+ return -EINVAL;
+
+ l_debug("");
+
+ info = l_new(struct netdev_ft_over_ds_info, 1);
+ info->netdev = netdev;
+
+ memcpy(info->super.spa, hs->spa, ETH_ALEN);
+ memcpy(info->super.aa, target_bss->addr, ETH_ALEN);
+ memcpy(info->super.mde, target_bss->mde, sizeof(info->super.mde));
+ 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);
+ memcpy(ft_req + 8, info->super.aa, 6);
+
+ iovs[0].iov_base = ft_req;
+ iovs[0].iov_len = sizeof(ft_req);
+
+ if (!ft_build_authenticate_ies(hs, info->super.snonce, buf, &len))
+ goto failed;
+
+ iovs[1].iov_base = buf;
+ iovs[1].iov_len = len;
+
+ iovs[2].iov_base = NULL;
+
+ netdev->ft_ds_info = info;
+
+ info->timeout = l_timeout_create_ms(300, netdev_ft_over_ds_timeout,
+ info, NULL);
+
+ netdev_send_action_framev(netdev, netdev->handshake->aa, iovs, 2,
+ netdev->frequency,
+ netdev_ft_request_cb,
+ info);
+
+ return 0;
+
+failed:
+ l_free(info);
+ return -EIO;
}
static void netdev_preauth_cb(const uint8_t *pmk, void *user_data)
@@ -3688,7 +4088,8 @@ int netdev_neighbor_report_req(struct netdev *netdev,
if (!netdev_send_action_frame(netdev, netdev->handshake->aa,
action_frame, sizeof(action_frame),
netdev->frequency,
- netdev_neighbor_report_req_cb))
+ netdev_neighbor_report_req_cb,
+ netdev))
return -EIO;
netdev->neighbor_report_cb = cb;
@@ -3775,7 +4176,7 @@ static void netdev_sa_query_req_frame_event(const struct mmpdu_header *hdr,
if (!netdev_send_action_frame(netdev, netdev->handshake->aa,
sa_resp, sizeof(sa_resp),
netdev->frequency,
- netdev_sa_query_resp_cb)) {
+ netdev_sa_query_resp_cb, netdev)) {
l_error("error sending SA Query response");
return;
}
@@ -3914,7 +4315,7 @@ static void netdev_unprot_disconnect_event(struct l_genl_msg *msg,
if (!netdev_send_action_frame(netdev, netdev->handshake->aa,
action_frame, sizeof(action_frame),
netdev->frequency,
- netdev_sa_query_req_cb)) {
+ netdev_sa_query_req_cb, netdev)) {
l_error("error sending SA Query action frame");
return;
}
@@ -3957,16 +4358,22 @@ static void netdev_station_event(struct l_genl_msg *msg,
netdev_station_watch_func_t, netdev, mac, added);
}
-static void netdev_scan_notify(struct l_genl_msg *msg, void *user_data)
+static struct netdev *netdev_from_message(struct l_genl_msg *msg)
{
- struct netdev *netdev = NULL;
uint32_t ifindex;
if (nl80211_parse_attrs(msg, NL80211_ATTR_IFINDEX, &ifindex,
NL80211_ATTR_UNSPEC) < 0)
- return;
+ return NULL;
- netdev = netdev_find(ifindex);
+ return netdev_find(ifindex);
+}
+
+static void netdev_scan_notify(struct l_genl_msg *msg, void *user_data)
+{
+ struct netdev *netdev;
+
+ netdev = netdev_from_message(msg);
if (!netdev)
return;
@@ -3992,19 +4399,15 @@ static bool netdev_get_fw_scan_cb(int err, struct l_queue *bss_list,
struct scan_bss *bss = NULL;
/*
- * If there was a failure in netdev_connect_event this would reset
- * the connect state (netdev_connect_free) causing the sm to be freed.
- * In this case we should just ignore this and allow the disconnect
- * logic to continue.
+ * If we happened to be disconnected prior to GET_SCAN coming back
+ * just bail out now. This disconnect should already have been handled.
*/
- if (!netdev->sm)
+ if (!netdev->connected)
return false;
if (err < 0) {
l_error("Failed to get scan after roam (%d)", err);
- netdev_connect_failed(netdev, NETDEV_RESULT_ABORTED,
- MMPDU_REASON_CODE_UNSPECIFIED);
- return false;
+ goto failed;
}
/*
@@ -4016,17 +4419,28 @@ static bool netdev_get_fw_scan_cb(int err, struct l_queue *bss_list,
if (!bss) {
l_error("Roam target BSS not found in scan results");
- netdev_connect_failed(netdev, NETDEV_RESULT_ABORTED,
- MMPDU_REASON_CODE_UNSPECIFIED);
- return false;
+ goto failed;
}
netdev->fw_roam_bss = bss;
handshake_state_set_authenticator_ie(netdev->handshake, bss->rsne);
- eapol_start(netdev->sm);
+ if (is_offload(netdev->handshake)) {
+ netdev_connect_ok(netdev);
+ return false;
+ }
+
+ if (netdev->sm) {
+ if (!eapol_start(netdev->sm))
+ goto failed;
+ }
+
+ return false;
+failed:
+ netdev_connect_failed(netdev, NETDEV_RESULT_ABORTED,
+ MMPDU_REASON_CODE_UNSPECIFIED);
return false;
}
@@ -4042,74 +4456,79 @@ static bool netdev_get_fw_scan_cb(int err, struct l_queue *bss_list,
* The current handshake/netdev_handshake objects are reused after being
* reset to allow eapol to happen again without it thinking this is a re-key.
*/
-static bool netdev_roam_event(struct l_genl_msg *msg, struct netdev *netdev)
+static void netdev_roam_event(struct l_genl_msg *msg, struct netdev *netdev)
{
struct netdev_handshake_state *nhs =
l_container_of(netdev->handshake,
struct netdev_handshake_state,
super);
- const uint8_t *mac;
+ struct l_genl_attr attr;
+ uint16_t type, len;
+ const void *data;
+ const uint8_t *mac = NULL;
l_debug("");
netdev->operational = false;
- if (nl80211_parse_attrs(msg, NL80211_ATTR_MAC, &mac,
- NL80211_ATTR_UNSPEC) < 0) {
+ if (!l_genl_attr_init(&attr, msg))
+ goto failed;
+
+ while (l_genl_attr_next(&attr, &type, &len, &data)) {
+ switch (type) {
+ case NL80211_ATTR_MAC:
+ mac = data;
+ break;
+ case NL80211_ATTR_REQ_IE:
+ parse_request_ies(netdev, data, len);
+ break;
+ }
+ }
+
+ if (!mac) {
l_error("Failed to parse ATTR_MAC from CMD_ROAM");
goto failed;
}
+ /* Handshake completed in firmware, just get the roamed BSS */
+ if (is_offload(netdev->handshake))
+ goto get_fw_scan;
+
/* Reset handshake state */
nhs->complete = false;
nhs->ptk_installed = false;
nhs->gtk_installed = true;
nhs->igtk_installed = true;
- handshake_state_set_authenticator_address(netdev->handshake, mac);
netdev->handshake->ptk_complete = false;
+get_fw_scan:
+ handshake_state_set_authenticator_address(netdev->handshake, mac);
+
if (!scan_get_firmware_scan(netdev->wdev_id, netdev_get_fw_scan_cb,
netdev, NULL))
goto failed;
- return true;
+ if (netdev->event_filter)
+ netdev->event_filter(netdev, NETDEV_EVENT_ROAMING,
+ NULL, netdev->user_data);
+ return;
failed:
- l_error("Failed to roam to new BSS");
+ l_error("Failed to properly handle the ROAM event -- submit logs!");
netdev_connect_failed(netdev, NETDEV_RESULT_ABORTED,
MMPDU_REASON_CODE_UNSPECIFIED);
- return false;
}
static void netdev_mlme_notify(struct l_genl_msg *msg, void *user_data)
{
struct netdev *netdev = NULL;
- struct l_genl_attr attr;
- uint16_t type, len;
- const void *data;
uint8_t cmd;
cmd = l_genl_msg_get_command(msg);
-
l_debug("MLME notification %s(%u)", nl80211cmd_to_string(cmd), cmd);
- if (!l_genl_attr_init(&attr, msg))
- return;
-
- while (l_genl_attr_next(&attr, &type, &len, &data)) {
- switch (type) {
- case NL80211_ATTR_IFINDEX:
- if (len != sizeof(uint32_t)) {
- l_warn("Invalid interface index attribute");
- return;
- }
-
- netdev = netdev_find(*((uint32_t *) data));
- break;
- }
- }
-
+ netdev = netdev_from_message(msg);
if (!netdev)
return;
@@ -4124,9 +4543,8 @@ static void netdev_mlme_notify(struct l_genl_msg *msg, void *user_data)
netdev_associate_event(msg, netdev);
break;
case NL80211_CMD_ROAM:
- if (!netdev_roam_event(msg, netdev))
- return;
- /* fall through */
+ netdev_roam_event(msg, netdev);
+ break;
case NL80211_CMD_CONNECT:
netdev_connect_event(msg, netdev);
break;
@@ -4497,6 +4915,8 @@ static void netdev_get_station_cb(struct l_genl_msg *msg, void *user_data)
if (!l_genl_attr_init(&attr, msg))
goto parse_error;
+ memset(&info, 0, sizeof(info));
+
while (l_genl_attr_next(&attr, &type, &len, &data)) {
switch (type) {
case NL80211_ATTR_STA_INFO:
@@ -4570,6 +4990,9 @@ int netdev_get_current_station(struct netdev *netdev,
netdev_get_station_cb_t cb, void *user_data,
netdev_destroy_func_t destroy)
{
+ if (!netdev->handshake)
+ return -ENOTCONN;
+
return netdev_get_station(netdev, netdev->handshake->aa, cb,
user_data, destroy);
}
@@ -4625,6 +5048,92 @@ static int netdev_cqm_rssi_update(struct netdev *netdev)
return 0;
}
+static void netdev_add_station_frame_watches(struct netdev *netdev)
+{
+ static const uint8_t action_neighbor_report_prefix[2] = { 0x05, 0x05 };
+ static const uint8_t action_sa_query_resp_prefix[2] = { 0x08, 0x01 };
+ static const uint8_t action_sa_query_req_prefix[2] = { 0x08, 0x00 };
+ static const uint8_t action_ft_response_prefix[] = { 0x06, 0x02 };
+ static const uint8_t action_qos_map_prefix[] = { 0x01, 0x04 };
+ uint64_t wdev = netdev->wdev_id;
+
+ /* Subscribe to Management -> Action -> RM -> Neighbor Report frames */
+ frame_watch_add(wdev, 0, 0x00d0, action_neighbor_report_prefix,
+ sizeof(action_neighbor_report_prefix),
+ netdev_neighbor_report_frame_event, netdev, NULL);
+
+ frame_watch_add(wdev, 0, 0x00d0, action_sa_query_resp_prefix,
+ sizeof(action_sa_query_resp_prefix),
+ netdev_sa_query_resp_frame_event, netdev, NULL);
+
+ frame_watch_add(wdev, 0, 0x00d0, action_sa_query_req_prefix,
+ sizeof(action_sa_query_req_prefix),
+ netdev_sa_query_req_frame_event, netdev, NULL);
+
+ frame_watch_add(wdev, 0, 0x00d0, action_ft_response_prefix,
+ sizeof(action_ft_response_prefix),
+ netdev_ft_response_frame_event, netdev, NULL);
+
+ if (wiphy_supports_qos_set_map(netdev->wiphy))
+ frame_watch_add(wdev, 0, 0x00d0, action_qos_map_prefix,
+ sizeof(action_qos_map_prefix),
+ netdev_qos_map_frame_event, netdev, NULL);
+}
+
+static void netdev_setup_interface(struct netdev *netdev)
+{
+ switch (netdev->type) {
+ case NL80211_IFTYPE_STATION:
+ /* Set RSSI threshold for CQM notifications */
+ netdev_cqm_rssi_update(netdev);
+ netdev_add_station_frame_watches(netdev);
+ break;
+ default:
+ break;
+ }
+}
+
+static void netdev_set_interface_event(struct l_genl_msg *msg,
+ struct netdev *netdev)
+{
+ uint32_t iftype;
+ uint64_t wdev_id;
+
+ if (nl80211_parse_attrs(msg, NL80211_ATTR_IFTYPE, &iftype,
+ NL80211_ATTR_WDEV, &wdev_id,
+ NL80211_ATTR_UNSPEC) < 0)
+ return;
+
+ if (iftype == netdev->type)
+ return;
+
+ l_debug("Interface type changed from %s to %s",
+ netdev_iftype_to_string(netdev->type),
+ netdev_iftype_to_string(iftype));
+ netdev->type = iftype;
+ frame_watch_wdev_remove(wdev_id);
+
+ netdev_setup_interface(netdev);
+
+ WATCHLIST_NOTIFY(&netdev_watches, netdev_watch_func_t,
+ netdev, NETDEV_WATCH_EVENT_IFTYPE_CHANGE);
+}
+
+static void netdev_config_notify(struct l_genl_msg *msg, void *user_data)
+{
+ struct netdev *netdev;
+
+ netdev = netdev_from_message(msg);
+ if (!netdev)
+ return;
+
+ switch (l_genl_msg_get_command(msg)) {
+ case NL80211_CMD_SET_INTERFACE:
+ netdev_set_interface_event(msg, netdev);
+ break;
+ }
+}
+
static struct l_genl_msg *netdev_build_cmd_set_interface(struct netdev *netdev,
uint32_t iftype)
{
@@ -4685,12 +5194,6 @@ static void netdev_set_iftype_cb(struct l_genl_msg *msg, void *user_data)
if (error != 0)
goto done;
- netdev->type = req->pending_type;
-
- /* Set RSSI threshold for CQM notifications */
- if (netdev->type == NL80211_IFTYPE_STATION)
- netdev_cqm_rssi_update(netdev);
-
/* If the netdev was down originally, we're done */
if (!req->bring_up)
goto done;
@@ -5171,11 +5674,6 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,
struct wiphy *wiphy = NULL;
struct ifinfomsg *rtmmsg;
size_t bufsize;
- const uint8_t action_neighbor_report_prefix[2] = { 0x05, 0x05 };
- const uint8_t action_sa_query_resp_prefix[2] = { 0x08, 0x01 };
- const uint8_t action_sa_query_req_prefix[2] = { 0x08, 0x00 };
- const uint8_t action_ft_response_prefix[] = { 0x06, 0x02 };
- const uint8_t action_qos_map_prefix[] = { 0x01, 0x04 };
struct l_io *pae_io = NULL;
if (nl80211_parse_attrs(msg, NL80211_ATTR_IFINDEX, &ifindex,
@@ -5249,31 +5747,7 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,
l_free(rtmmsg);
- /* Subscribe to Management -> Action -> RM -> Neighbor Report frames */
- frame_watch_add(wdev, 0, 0x00d0, action_neighbor_report_prefix,
- sizeof(action_neighbor_report_prefix),
- netdev_neighbor_report_frame_event, netdev, NULL);
-
- frame_watch_add(wdev, 0, 0x00d0, action_sa_query_resp_prefix,
- sizeof(action_sa_query_resp_prefix),
- netdev_sa_query_resp_frame_event, netdev, NULL);
-
- frame_watch_add(wdev, 0, 0x00d0, action_sa_query_req_prefix,
- sizeof(action_sa_query_req_prefix),
- netdev_sa_query_req_frame_event, netdev, NULL);
-
- frame_watch_add(wdev, 0, 0x00d0, action_ft_response_prefix,
- sizeof(action_ft_response_prefix),
- netdev_ft_response_frame_event, netdev, NULL);
-
- if (wiphy_supports_qos_set_map(netdev->wiphy))
- frame_watch_add(wdev, 0, 0x00d0, action_qos_map_prefix,
- sizeof(action_qos_map_prefix),
- netdev_qos_map_frame_event, netdev, NULL);
-
- /* Set RSSI threshold for CQM notifications */
- if (netdev->type == NL80211_IFTYPE_STATION)
- netdev_cqm_rssi_update(netdev);
+ netdev_setup_interface(netdev);
return netdev;
}
@@ -5377,6 +5851,7 @@ static int netdev_init(void)
__eapol_set_rekey_offload_func(netdev_set_rekey_offload);
__eapol_set_tx_packet_func(netdev_control_port_frame);
+ __eapol_set_install_pmk_func(netdev_set_pmk);
unicast_watch = l_genl_add_unicast_watch(genl, NL80211_GENL_NAME,
netdev_unicast_notify,
@@ -5392,6 +5867,10 @@ static int netdev_init(void)
NULL, NULL))
l_error("Registering for scan notifications failed");
+ if (!l_genl_family_register(nl80211, "config", netdev_config_notify,
+ NULL, NULL))
+ l_error("Registering for config notifications failed");
+
return 0;
fail_netlink:
diff --git a/src/netdev.h b/src/netdev.h
@@ -57,14 +57,16 @@ enum netdev_watch_event {
NETDEV_WATCH_EVENT_DOWN,
NETDEV_WATCH_EVENT_NAME_CHANGE,
NETDEV_WATCH_EVENT_ADDRESS_CHANGE,
+ NETDEV_WATCH_EVENT_IFTYPE_CHANGE,
};
+/* Mirror definitions from nl80211.h to make conversions simpler */
enum netdev_iftype {
NETDEV_IFTYPE_ADHOC = 1,
NETDEV_IFTYPE_STATION = 2,
NETDEV_IFTYPE_AP = 3,
- NETDEV_IFTYPE_P2P_CLIENT,
- NETDEV_IFTYPE_P2P_GO,
+ NETDEV_IFTYPE_P2P_CLIENT = 8,
+ NETDEV_IFTYPE_P2P_GO = 9,
};
typedef void (*netdev_command_cb_t)(struct netdev *netdev, int result,
@@ -78,7 +80,7 @@ typedef void (*netdev_command_cb_t)(struct netdev *netdev, int result,
* NETDEV_RESULT_AUTHENTICATION_FAILED - MMPDU_STATUS_CODE
* NETDEV_RESULT_ASSOCIATION_FAILED - MMPDU_STATUS_CODE
* NETDEV_RESULT_HANDSHAKE_FAILED - MMPDU_REASON_CODE
- * NETDEV_RESULT_KEY_SETTINGS_FAILED - unused
+ * NETDEV_RESULT_KEY_SETTING_FAILED - unused
* NETDEV_RESULT_ABORTED - unused.
*/
typedef void (*netdev_connect_cb_t)(struct netdev *netdev,
@@ -121,6 +123,12 @@ typedef void (*netdev_get_station_cb_t)(
const struct diagnostic_station_info *info,
void *user_data);
+const char *netdev_iftype_to_string(uint32_t iftype);
+
+typedef void (*netdev_ft_over_ds_cb_t)(struct netdev *netdev,
+ uint16_t status, const uint8_t *bssid,
+ void *user_data);
+
struct wiphy *netdev_get_wiphy(struct netdev *netdev);
const uint8_t *netdev_get_address(struct netdev *netdev);
uint32_t netdev_get_ifindex(struct netdev *netdev);
@@ -154,6 +162,10 @@ int netdev_reassociate(struct netdev *netdev, struct scan_bss *target_bss,
netdev_connect_cb_t cb, void *user_data);
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);
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
@@ -32,6 +32,8 @@
#include <ell/ell.h>
+#include "ell/useful.h"
+
#include "src/missing.h"
#include "src/module.h"
#include "src/ie.h"
@@ -50,6 +52,7 @@
#include "src/network.h"
#include "src/blacklist.h"
#include "src/util.h"
+#include "src/erp.h"
static uint32_t known_networks_watch;
static uint32_t anqp_watch;
@@ -377,56 +380,54 @@ static int network_load_psk(struct network *network, bool need_passphrase)
size_t psk_len;
uint8_t *psk = l_settings_get_bytes(network->settings, "Security",
"PreSharedKey", &psk_len);
- char *passphrase = l_settings_get_string(network->settings,
+ _auto_(l_free) char *passphrase =
+ l_settings_get_string(network->settings,
"Security", "Passphrase");
+ _auto_(l_free) char *path =
+ storage_get_network_file_path(security, ssid);
int r;
- /* PSK can be generated from the passphrase but not the other way */
- if ((!psk || need_passphrase) && !passphrase) {
+ if (psk && psk_len != 32) {
+ l_error("%s: invalid PreSharedKey format", path);
l_free(psk);
- return -ENOKEY;
+ psk = NULL;
+ psk_len = 0;
}
- network_reset_passphrase(network);
- network_reset_psk(network);
- network->passphrase = passphrase;
-
- if (psk) {
- char *path;
+ /* PSK can be generated from the passphrase but not the other way */
+ if (!psk || need_passphrase) {
+ if (!passphrase)
+ return -ENOKEY;
- if (psk_len == 32) {
- network->psk = psk;
- return 0;
+ if (!crypto_passphrase_is_valid(passphrase)) {
+ l_error("%s: invalid Passphrase format", path);
+ return -ENOKEY;
}
+ }
- l_free(psk);
-
- path = storage_get_network_file_path(security, ssid);
- l_error("%s: invalid PreSharedKey format", path);
- l_free(path);
+ network_reset_passphrase(network);
+ network_reset_psk(network);
+ network->passphrase = l_steal_ptr(passphrase);
- if (!passphrase)
- return -EINVAL;
+ if (psk) {
+ network->psk = psk;
+ return 0;
}
network->psk = l_malloc(32);
- r = crypto_psk_from_passphrase(passphrase, (uint8_t *) ssid,
+ r = crypto_psk_from_passphrase(network->passphrase, (uint8_t *) ssid,
strlen(ssid), network->psk);
if (!r) {
network->update_psk = true;
return 0;
}
- if (r == -ERANGE || r == -EINVAL)
- l_error("PSK generation failed: invalid passphrase format");
- else
- l_error("PSK generation failed: %s. "
- "Ensure Crypto Engine is properly configured",
- strerror(-r));
+ l_error("PSK generation failed: %s", strerror(-r));
network_reset_passphrase(network);
network_reset_psk(network);
- return -EINVAL;
+
+ return r;
}
void network_sync_psk(struct network *network)
@@ -722,6 +723,46 @@ static bool match_bss(const void *a, const void *b)
return a == b;
}
+bool network_has_erp_identity(struct network *network)
+{
+ struct erp_cache_entry *cache;
+ struct l_settings *settings;
+ char *check_id;
+ const char *identity;
+ bool ret;
+
+ settings = network_get_settings(network);
+ if (!settings)
+ return false;
+
+ check_id = l_settings_get_string(settings, "Security", "EAP-Identity");
+ if (!check_id)
+ return false;
+
+ cache = erp_cache_get(network_get_ssid(network));
+ if (!cache) {
+ l_free(check_id);
+ return false;
+ }
+
+ identity = erp_cache_entry_get_identity(cache);
+
+ ret = strcmp(check_id, identity) == 0;
+
+ l_free(check_id);
+ erp_cache_put(cache);
+
+ /*
+ * The settings file must have change out from under us. In this
+ * case we want to remove the ERP entry because it is no longer
+ * valid.
+ */
+ if (!ret)
+ erp_cache_remove(identity);
+
+ return ret;
+}
+
struct scan_bss *network_bss_select(struct network *network,
bool fallback_to_blacklist)
{
@@ -729,6 +770,7 @@ struct scan_bss *network_bss_select(struct network *network,
struct wiphy *wiphy = station_get_wiphy(network->station);
const struct l_queue_entry *bss_entry;
struct scan_bss *candidate = NULL;
+ bool fils_hint = network_has_erp_identity(network);
for (bss_entry = l_queue_get_entries(bss_list); bss_entry;
bss_entry = bss_entry->next) {
@@ -737,7 +779,7 @@ struct scan_bss *network_bss_select(struct network *network,
switch (network_get_security(network)) {
case SECURITY_PSK:
case SECURITY_8021X:
- if (!wiphy_can_connect(wiphy, bss))
+ if (!wiphy_can_connect(wiphy, bss, fils_hint))
continue;
/* fall through */
case SECURITY_NONE:
diff --git a/src/network.h b/src/network.h
@@ -79,3 +79,5 @@ void network_blacklist_add(struct network *network, struct scan_bss *bss);
const struct iovec *network_get_extra_ies(struct network *network,
size_t *num_elems);
+
+bool network_has_erp_identity(struct network *network);
diff --git a/src/nl80211cmd.c b/src/nl80211cmd.c
@@ -164,6 +164,18 @@ static const struct {
{ NL80211_CMD_STA_OPMODE_CHANGED, "STA Opmode Changed" },
{ NL80211_CMD_CONTROL_PORT_FRAME, "Control Port Frame" },
{ NL80211_CMD_GET_FTM_RESPONDER_STATS, "Get FTM Responder Stats" },
+ { NL80211_CMD_PEER_MEASUREMENT_START, "Peer Measurement Start" },
+ { NL80211_CMD_PEER_MEASUREMENT_RESULT, "Peer Measurement Result" },
+ { NL80211_CMD_PEER_MEASUREMENT_COMPLETE,
+ "Peer Measurement Complete" },
+
+ { NL80211_CMD_NOTIFY_RADAR, "Notify Radar" },
+ { NL80211_CMD_UPDATE_OWE_INFO, "Update OWE Info" },
+ { NL80211_CMD_PROBE_MESH_LINK, "Probe Mesh Link" },
+ { NL80211_CMD_SET_TID_CONFIG, "Set TID Config" },
+ { NL80211_CMD_UNPROT_BEACON, "Unprotected Beacon" },
+ { NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS,
+ "Control Port TX Status" },
{ }
};
diff --git a/src/p2p.c b/src/p2p.c
@@ -1191,13 +1191,32 @@ static const struct ap_ops p2p_go_ops = {
static void p2p_group_start(struct p2p_device *dev)
{
- struct ap_config *config = l_new(struct ap_config, 1);
-
- config->ssid = l_strdup(dev->go_group_id.ssid);
- config->channel = dev->listen_channel;
- config->wsc_name = l_strdup(dev->device_info.device_name);
- config->wsc_primary_device_type = dev->device_info.primary_device_type;
- config->no_cck_rates = true;
+ struct l_settings *config = l_settings_new();
+ uint8_t psk[32];
+ char *macs[2] = {};
+ const struct wsc_primary_device_type *pdt =
+ &dev->device_info.primary_device_type;
+ uint64_t pdt_uint =
+ ((uint64_t) pdt->category << 48) |
+ ((uint64_t) pdt->oui[0] << 40) |
+ ((uint64_t) pdt->oui[1] << 32) |
+ ((uint64_t) pdt->oui[2] << 24) |
+ ((uint64_t) pdt->oui_type << 16) |
+ pdt->subcategory;
+
+ l_settings_set_string(config, "General", "SSID", dev->go_group_id.ssid);
+ l_settings_set_uint(config, "General", "Channel", dev->listen_channel);
+ l_settings_set_bool(config, "General", "NoCCKRates", true);
+ l_settings_set_string(config, "WSC", "DeviceName",
+ dev->device_info.device_name);
+ l_settings_set_uint64(config, "WSC", "PrimaryDeviceType", pdt_uint);
+ /*
+ * Section 3.1.4.4: "It shall only allow association by the
+ * P2P Device that it is currently in Group Formation with."
+ */
+ macs[0] = (char *) util_address_to_string(
+ dev->conn_peer_interface_addr);
+ l_settings_set_string_list(config, "WSC", "AuthorizedMACs", macs, ',');
/*
* Section 3.2.1: "The Credentials for a P2P Group issued to a
@@ -1211,29 +1230,25 @@ static void p2p_group_start(struct p2p_device *dev)
* it's a little costlier to generate for the same cryptographic
* strength as the PSK.
*/
- if (!l_getrandom(config->psk, 32)) {
+ if (!l_getrandom(psk, 32)) {
l_error("l_getrandom() failed");
- ap_config_free(config);
+ l_settings_free(config);
p2p_connect_failed(dev);
return;
}
- /*
- * Section 3.1.4.4: "It shall only allow association by the
- * P2P Device that it is currently in Group Formation with."
- */
- config->authorized_macs = l_memdup(dev->conn_peer_interface_addr, 6);
- config->authorized_macs_num = 1;
+ l_settings_set_bytes(config, "Security", "PreSharedKey", psk, 32);
+
+ l_settings_add_group(config, "IPv4");
dev->capability.group_caps |= P2P_GROUP_CAP_GO;
dev->capability.group_caps |= P2P_GROUP_CAP_GROUP_FORMATION;
dev->group = ap_start(dev->conn_netdev, config, &p2p_go_ops, NULL, dev);
- if (!dev->group) {
- ap_config_free(config);
+ l_settings_free(config);
+
+ if (!dev->group)
p2p_connect_failed(dev);
- return;
- }
}
static void p2p_netconfig_event_handler(enum netconfig_event event,
@@ -1325,7 +1340,7 @@ static void p2p_netdev_connect_cb(struct netdev *netdev,
/*
* In the AUTHENTICATION_FAILED and ASSOCIATION_FAILED
* cases there's nothing to disconnect. In the
- * HANDSHAKE_FAILED and KEY_SETTINGS failed cases
+ * HANDSHAKE_FAILED and KEY_SETTING failed cases
* netdev disconnects from the GO automatically and we are
* called already from within the disconnect callback,
* so we can directly free the netdev.
@@ -4359,43 +4374,12 @@ struct p2p_device *p2p_device_update_from_genl(struct l_genl_msg *msg,
str = l_settings_get_string(iwd_get_config(), "P2P", "DeviceType");
- /*
- * Standard WSC subcategories are unique and more specific than
- * categories so there's no point for the user to specify the
- * category if they choose to use the string format.
- *
- * As an example our default value (Computer - PC) can be
- * encoded as either of:
- *
- * DeviceType=pc
- * DeviceType=0x00010050f2040001
- */
- if (str && !wsc_device_type_from_subcategory_str(
- &dev->device_info.primary_device_type,
- str)) {
- unsigned long long u;
- char *endp;
-
- u = strtoull(str, &endp, 0);
-
- /*
- * Accept any custom category, OUI and subcategory values but
- * require non-zero category as a sanity check.
- */
- if (*endp != '\0' || (u & 0xffff000000000000ll) == 0)
- l_error("[P2P].DeviceType must be a subcategory string "
- "or a 64-bit integer encoding the full Primary"
- " Device Type attribute: "
- "<Category>|<OUI>|<OUI Type>|<Subcategory>");
- else {
- dev->device_info.primary_device_type.category = u >> 48;
- dev->device_info.primary_device_type.oui[0] = u >> 40;
- dev->device_info.primary_device_type.oui[1] = u >> 32;
- dev->device_info.primary_device_type.oui[2] = u >> 24;
- dev->device_info.primary_device_type.oui_type = u >> 16;
- dev->device_info.primary_device_type.subcategory = u;
- }
- }
+ if (str && !wsc_device_type_from_setting_str(str,
+ &dev->device_info.primary_device_type))
+ l_error("[P2P].DeviceType must be a subcategory string "
+ "or a 64-bit integer encoding the full Primary"
+ " Device Type attribute: "
+ "<Category>|<OUI>|<OUI Type>|<Subcategory>");
l_free(str);
diff --git a/src/resolve.c b/src/resolve.c
@@ -131,11 +131,9 @@ static void systemd_link_generic_reply(struct l_dbus_message *message,
const char *name;
const char *text;
- if (!l_dbus_message_is_error(message))
+ if (!l_dbus_message_get_error(message, &name, &text))
return;
- l_dbus_message_get_error(message, &name, &text);
-
l_error("resolve-systemd: Failed to modify the %s entries. %s: %s",
type, name, text);
}
diff --git a/src/rrm.c b/src/rrm.c
@@ -117,6 +117,7 @@ struct rrm_beacon_req_info {
/* Per-netdev state */
struct rrm_state {
struct station *station;
+ uint32_t watch_id;
uint32_t ifindex;
uint64_t wdev_id;
struct rrm_request_info *pending;
@@ -662,6 +663,17 @@ static void rrm_station_watch_cb(enum station_state state, void *userdata)
}
}
+static void rrm_station_watch_destroy(void *user_data)
+{
+ struct rrm_state *rrm = user_data;
+
+ l_debug("");
+
+ rrm_cancel_pending(rrm);
+ rrm->watch_id = 0;
+ rrm->station = NULL;
+}
+
static void rrm_frame_watch_cb(const struct mmpdu_header *mpdu,
const void *body, size_t body_len,
int rssi, void *user_data)
@@ -684,8 +696,9 @@ static void rrm_frame_watch_cb(const struct mmpdu_header *mpdu,
return;
}
- station_add_state_watch(rrm->station, rrm_station_watch_cb,
- rrm, NULL);
+ rrm->watch_id = station_add_state_watch(rrm->station,
+ rrm_station_watch_cb, rrm,
+ rrm_station_watch_destroy);
}
/*
@@ -757,14 +770,20 @@ static void rrm_state_destroy(void *data)
l_free(rrm);
}
-static void rrm_new_state(struct netdev *netdev)
+static void rrm_add_frame_watches(struct rrm_state *rrm)
{
- struct rrm_state *rrm;
- uint16_t frame_type = 0x00d0;
- uint8_t prefix[] = { 0x05, 0x00 };
+ static const uint16_t frame_type = 0x00d0;
+ static const uint8_t prefix[] = { 0x05, 0x00 };
- if (netdev_get_iftype(netdev) != NETDEV_IFTYPE_STATION)
- return;
+ l_debug("");
+
+ frame_watch_add(rrm->wdev_id, 0, frame_type, prefix, sizeof(prefix),
+ rrm_frame_watch_cb, rrm, NULL);
+}
+
+static struct rrm_state *rrm_new_state(struct netdev *netdev)
+{
+ struct rrm_state *rrm;
rrm = l_new(struct rrm_state, 1);
@@ -772,10 +791,9 @@ static void rrm_new_state(struct netdev *netdev)
rrm->ifindex = netdev_get_ifindex(netdev);
rrm->wdev_id = netdev_get_wdev_id(netdev);
- frame_watch_add(rrm->wdev_id, 0, frame_type, prefix, sizeof(prefix),
- rrm_frame_watch_cb, rrm, NULL);
-
l_queue_push_head(states, rrm);
+
+ return rrm;
}
static bool match_ifindex(const void *a, const void *b)
@@ -794,8 +812,12 @@ static void rrm_netdev_watch(struct netdev *netdev,
switch (event) {
case NETDEV_WATCH_EVENT_NEW:
- rrm_new_state(netdev);
- return;
+ rrm = rrm_new_state(netdev);
+
+ if (netdev_get_iftype(netdev) == NETDEV_IFTYPE_STATION)
+ rrm_add_frame_watches(rrm);
+
+ break;
case NETDEV_WATCH_EVENT_DEL:
/*
* This event is triggered by the netdev being removed, which
@@ -806,11 +828,22 @@ static void rrm_netdev_watch(struct netdev *netdev,
rrm = l_queue_remove_if(states, match_ifindex,
L_UINT_TO_PTR(ifindex));
if (rrm) {
- rrm_cancel_pending(rrm);
+ if (rrm->station && rrm->watch_id)
+ station_remove_state_watch(rrm->station,
+ rrm->watch_id);
+
l_free(rrm);
}
- return;
+ break;
+ case NETDEV_WATCH_EVENT_IFTYPE_CHANGE:
+ rrm = l_queue_find(states, match_ifindex,
+ L_UINT_TO_PTR(ifindex));
+
+ if (rrm && netdev_get_iftype(netdev) == NETDEV_IFTYPE_STATION)
+ rrm_add_frame_watches(rrm);
+
+ break;
default:
break;
}
diff --git a/src/sae.c b/src/sae.c
@@ -37,6 +37,7 @@
#define SAE_RETRANSMIT_TIMEOUT 2
#define SAE_SYNC_MAX 3
+#define SAE_MAX_ASSOC_RETRY 3
enum sae_state {
SAE_STATE_NOTHING = 0,
@@ -73,6 +74,7 @@ struct sae_sm {
uint16_t rc;
/* remote peer */
uint8_t peer[6];
+ uint8_t assoc_retry;
sae_tx_authenticate_func_t tx_auth;
sae_tx_associate_func_t tx_assoc;
@@ -550,7 +552,7 @@ static int sae_process_commit(struct sae_sm *sm, const uint8_t *from,
/*
* IEEE 802.11-2016 - Section 12.4.4.2.1 ECC group definition
* ECC groups make use of a mapping function, F, that maps a
- * point (x, y) that satisfies the curve equation to its x-coordinate—
+ * point (x, y) that satisfies the curve equation to its x-coordinate-
* i.e., if P = (x, y) then F(P) = x.
*/
klen = l_ecc_point_get_x(k_point, k, sizeof(k));
@@ -670,31 +672,16 @@ static bool sae_send_commit(struct sae_sm *sm, bool retry)
return true;
}
-static bool sae_timeout(struct auth_proto *ap)
+static bool sae_assoc_timeout(struct auth_proto *ap)
{
struct sae_sm *sm = l_container_of(ap, struct sae_sm, ap);
- /* regardless of state, reject if sync exceeds max */
- if (sm->sync > SAE_SYNC_MAX) {
- sae_reject_authentication(sm, MMPDU_REASON_CODE_UNSPECIFIED);
+ if (sm->assoc_retry >= SAE_MAX_ASSOC_RETRY)
return false;
- }
- sm->sync++;
+ sm->assoc_retry++;
- switch (sm->state) {
- case SAE_STATE_COMMITTED:
- sae_send_commit(sm, true);
- break;
- case SAE_STATE_CONFIRMED:
- sm->sc++;
- sae_send_confirm(sm);
- break;
- default:
- /* should never happen */
- l_error("SAE timeout in bad state %u", sm->state);
- return false;
- }
+ sm->tx_assoc(sm->user_data);
return true;
}
@@ -1178,7 +1165,7 @@ struct auth_proto *sae_sm_new(struct handshake_state *hs,
sm->ap.free = sae_free;
sm->ap.rx_authenticate = sae_rx_authenticate;
sm->ap.rx_associate = sae_rx_associate;
- sm->ap.auth_timeout = sae_timeout;
+ sm->ap.assoc_timeout = sae_assoc_timeout;
return &sm->ap;
}
diff --git a/src/station.c b/src/station.c
@@ -55,6 +55,7 @@
#include "src/anqp.h"
#include "src/anqputil.h"
#include "src/diagnostic.h"
+#include "src/frame-xchg.h"
static struct l_queue *station_list;
static uint32_t netdev_watch;
@@ -203,6 +204,7 @@ static void station_autoconnect_next(struct station *station)
scan_cancel(netdev_get_wdev_id(station->netdev),
station->quick_scan_id);
station->quick_scan_id = 0;
+ station_property_set_scanning(station, false);
}
return;
@@ -755,46 +757,6 @@ static void station_handshake_event(struct handshake_state *hs,
va_end(args);
}
-static bool station_has_erp_identity(struct network *network)
-{
- struct erp_cache_entry *cache;
- struct l_settings *settings;
- char *check_id;
- const char *identity;
- bool ret;
-
- settings = network_get_settings(network);
- if (!settings)
- return false;
-
- check_id = l_settings_get_string(settings, "Security", "EAP-Identity");
- if (!check_id)
- return false;
-
- cache = erp_cache_get(network_get_ssid(network));
- if (!cache) {
- l_free(check_id);
- return false;
- }
-
- identity = erp_cache_entry_get_identity(cache);
-
- ret = strcmp(check_id, identity) == 0;
-
- l_free(check_id);
- erp_cache_put(cache);
-
- /*
- * The settings file must have change out from under us. In this
- * case we want to remove the ERP entry because it is no longer
- * valid.
- */
- if (!ret)
- erp_cache_remove(identity);
-
- return ret;
-}
-
static int station_build_handshake_rsn(struct handshake_state *hs,
struct wiphy *wiphy,
struct network *network,
@@ -823,7 +785,7 @@ static int station_build_handshake_rsn(struct handshake_state *hs,
* wiphy may select FILS if supported by the AP.
*/
if (security == SECURITY_8021X && hs->support_fils)
- fils_hint = station_has_erp_identity(network);
+ fils_hint = network_has_erp_identity(network);
info.akm_suites = wiphy_select_akm(wiphy, bss, fils_hint);
@@ -982,16 +944,6 @@ static struct handshake_state *station_handshake_setup(struct station *station,
goto no_psk;
handshake_state_set_passphrase(hs, passphrase);
-
- /*
- * TODO: This check isn't strictly correct since
- * some drivers may support EXTERNAL_AUTH but since
- * wiphy_can_connect takes this into account IWD should
- * have already rejected the connection if this was the
- * case.
- */
- if (!wiphy_supports_cmds_auth_assoc(wiphy))
- hs->offload = true;
} else {
const uint8_t *psk = network_get_psk(network);
@@ -1285,11 +1237,6 @@ static void station_enter_state(struct station *station,
periodic_scan_stop(station);
break;
case STATION_STATE_DISCONNECTED:
-#ifdef HAVE_DBUS
- l_dbus_object_remove_interface(dbus_get_bus(),
- netdev_get_path(station->netdev),
- IWD_STATION_DIAGNOSTIC_INTERFACE);
-#endif
periodic_scan_stop(station);
break;
case STATION_STATE_CONNECTED:
@@ -1302,6 +1249,10 @@ static void station_enter_state(struct station *station,
periodic_scan_stop(station);
break;
case STATION_STATE_DISCONNECTING:
+ l_dbus_object_remove_interface(dbus_get_bus(),
+ netdev_get_path(station->netdev),
+ IWD_STATION_DIAGNOSTIC_INTERFACE);
+ break;
case STATION_STATE_ROAMING:
break;
}
@@ -1443,6 +1394,180 @@ static void station_roam_timeout_rearm(struct station *station, int seconds);
static int station_roam_scan(struct station *station,
struct scan_freq_set *freq_set);
+static uint32_t station_freq_from_neighbor_report(const uint8_t *country,
+ struct ie_neighbor_report_info *info, enum scan_band *out_band)
+{
+ enum scan_band band;
+ uint32_t freq;
+
+ if (info->oper_class == 0) {
+ /*
+ * Some Cisco APs report all operating class values as 0
+ * in the Neighbor Report Responses. Work around this by
+ * using the most likely operating class for the channel
+ * number as the 2.4GHz and 5GHz bands happen to mostly
+ * use channels in two disjoint ranges.
+ */
+ if (info->channel_num >= 1 && info->channel_num <= 14)
+ band = SCAN_BAND_2_4_GHZ;
+ else if (info->channel_num >= 36 && info->channel_num <= 169)
+ band = SCAN_BAND_5_GHZ;
+ else {
+ l_debug("Ignored: 0 oper class with an unusual "
+ "channel number");
+
+ return 0;
+ }
+ } else {
+ band = scan_oper_class_to_band(country, info->oper_class);
+ if (!band) {
+ l_debug("Ignored: unsupported oper class");
+
+ return 0;
+ }
+ }
+
+ freq = scan_channel_to_freq(info->channel_num, band);
+ if (!freq) {
+ l_debug("Ignored: unsupported channel");
+
+ return 0;
+ }
+
+ if (out_band)
+ *out_band = band;
+
+ return freq;
+}
+
+static void parse_neighbor_report(struct station *station,
+ const uint8_t *reports,
+ size_t reports_len,
+ struct scan_freq_set **set)
+{
+ struct ie_tlv_iter iter;
+ int count_md = 0, count_no_md = 0;
+ struct scan_freq_set *freq_set_md, *freq_set_no_md;
+ uint32_t current_freq = 0;
+ struct handshake_state *hs = netdev_get_handshake(station->netdev);
+
+ freq_set_md = scan_freq_set_new();
+ freq_set_no_md = scan_freq_set_new();
+
+ ie_tlv_iter_init(&iter, reports, reports_len);
+
+ /* First see if any of the reports contain the MD bit set */
+ while (ie_tlv_iter_next(&iter)) {
+ struct ie_neighbor_report_info info;
+ uint32_t freq;
+ enum scan_band band;
+ const uint8_t *cc = NULL;
+
+ if (ie_tlv_iter_get_tag(&iter) != IE_TYPE_NEIGHBOR_REPORT)
+ continue;
+
+ if (ie_parse_neighbor_report(&iter, &info) < 0)
+ continue;
+
+ l_debug("Neighbor report received for %s: ch %i "
+ "(oper class %i), %s",
+ util_address_to_string(info.addr),
+ (int) info.channel_num, (int) info.oper_class,
+ info.md ? "MD set" : "MD not set");
+
+ if (station->connected_bss->cc_present)
+ cc = station->connected_bss->cc;
+
+ freq = station_freq_from_neighbor_report(cc, &info, &band);
+ if (!freq)
+ continue;
+
+ /* Skip if the band is not supported */
+ if (!(band & wiphy_get_supported_bands(station->wiphy)))
+ continue;
+
+ if (!memcmp(info.addr,
+ station->connected_bss->addr, ETH_ALEN)) {
+ /*
+ * If this report is for the current AP, don't add
+ * it to any of the lists yet. We will need to scan
+ * its channel because it may still be the best ranked
+ * or the only visible AP.
+ */
+ current_freq = freq;
+
+ continue;
+ }
+
+ /* Add the frequency to one of the lists */
+ if (info.md && hs->mde) {
+ scan_freq_set_add(freq_set_md, freq);
+
+ count_md += 1;
+ } else {
+ scan_freq_set_add(freq_set_no_md, freq);
+
+ count_no_md += 1;
+ }
+ }
+
+ if (!current_freq)
+ current_freq = station->connected_bss->frequency;
+
+ /*
+ * If there are neighbor reports with the MD bit set then the bit
+ * is probably valid so scan only the frequencies of the neighbors
+ * with that bit set, which will allow us to use Fast Transition.
+ * Some APs, such as those based on hostapd do not set the MD bit
+ * even if the neighbor is within the MD.
+ *
+ * In any case we only select the frequencies here and will check
+ * the IEs in the scan results as the authoritative information
+ * on whether we can use Fast Transition, and rank BSSes based on
+ * that.
+ *
+ * TODO: possibly save the neighbors from outside the MD and if
+ * none of the ones in the MD end up working, try a non-FT
+ * transition to those neighbors. We should be using a
+ * blacklisting mechanism (for both initial connection and
+ * transitions) so that cound_md would not count the
+ * BSSes already used and when it goes down to 0 we'd
+ * automatically fall back to the non-FT candidates and then to
+ * full scan.
+ */
+ if (count_md) {
+ scan_freq_set_add(freq_set_md, current_freq);
+ *set = freq_set_md;
+ scan_freq_set_free(freq_set_no_md);
+ } else if (count_no_md) {
+ scan_freq_set_add(freq_set_no_md, current_freq);
+ *set = freq_set_no_md;
+ scan_freq_set_free(freq_set_md);
+ } else {
+ scan_freq_set_free(freq_set_no_md);
+ scan_freq_set_free(freq_set_md);
+ *set = NULL;
+ }
+}
+
+static void station_early_neighbor_report_cb(struct netdev *netdev, int err,
+ const uint8_t *reports,
+ size_t reports_len,
+ void *user_data)
+{
+ struct station *station = user_data;
+
+ l_debug("ifindex: %u, error: %d(%s)",
+ netdev_get_ifindex(station->netdev),
+ err, err < 0 ? strerror(-err) : "");
+
+ if (!reports || err)
+ return;
+
+ parse_neighbor_report(station, reports, reports_len,
+ &station->roam_freqs);
+}
+
static void station_roamed(struct station *station)
{
station->roam_scan_full = false;
@@ -1457,9 +1582,35 @@ static void station_roamed(struct station *station)
if (station->netconfig)
netconfig_reconfigure(station->netconfig);
+ if (station->roam_freqs) {
+ scan_freq_set_free(station->roam_freqs);
+ station->roam_freqs = NULL;
+ }
+
+ 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");
+ }
+
station_enter_state(station, STATION_STATE_CONNECTED);
}
+static void station_roam_retry(struct station *station)
+{
+ /*
+ * If we're still connected to the old BSS, only clear preparing_roam
+ * and reattempt in 60 seconds if signal level is still low at that
+ * time.
+ */
+ station->preparing_roam = false;
+ station->roam_scan_full = false;
+ station->ap_directed_roaming = false;
+
+ if (station->signal_low)
+ station_roam_timeout_rearm(station, roam_retry_interval);
+}
+
static void station_roam_failed(struct station *station)
{
l_debug("%u", netdev_get_ifindex(station->netdev));
@@ -1484,22 +1635,21 @@ static void station_roam_failed(struct station *station)
* If we tried a limited scan, failed and the signal is still low,
* repeat with a full scan right away
*/
- if (station->signal_low && !station->roam_scan_full &&
- !station_roam_scan(station, NULL))
- return;
+ if (station->signal_low && !station->roam_scan_full) {
+ /*
+ * Since we're re-using roam_scan_id, explicitly cancel
+ * the scan here, so that the destroy callback is not called
+ * after the return of this function
+ */
+ scan_cancel(netdev_get_wdev_id(station->netdev),
+ station->roam_scan_id);
-delayed_retry:
- /*
- * If we're still connected to the old BSS, only clear preparing_roam
- * and reattempt in 60 seconds if signal level is still low at that
- * time.
- */
- station->preparing_roam = false;
- station->roam_scan_full = false;
- station->ap_directed_roaming = false;
+ if (!station_roam_scan(station, NULL))
+ return;
+ }
- if (station->signal_low)
- station_roam_timeout_rearm(station, roam_retry_interval);
+delayed_retry:
+ station_roam_retry(station);
}
static void station_netconfig_event_handler(enum netconfig_event event,
@@ -1582,6 +1732,45 @@ 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)
@@ -1679,11 +1868,18 @@ 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(station->netdev, bss,
- station_fast_transition_cb) < 0) {
- station_roam_failed(station);
- return;
+ if (netdev_fast_transition_over_ds_action(
+ station->netdev, bss,
+ station_fast_transition_ds_cb,
+ station) < 0) {
+ station_roam_retry(station);
}
+
+ /*
+ * Set connected_bss/preparing_roam/state only on a
+ * successful FT-over-DS action frame response
+ */
+ return;
} else {
if (netdev_fast_transition(station->netdev, bss,
station_fast_transition_cb) < 0) {
@@ -1769,6 +1965,7 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list,
uint16_t mdid;
enum security orig_security, security;
bool seen = false;
+ bool fils_hint = network_has_erp_identity(network);
if (err) {
station_roam_failed(station);
@@ -1825,7 +2022,7 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list,
seen = true;
- if (!wiphy_can_connect(station->wiphy, bss))
+ if (!wiphy_can_connect(station->wiphy, bss, fils_hint))
goto next;
if (blacklist_contains_bss(bss->addr))
@@ -1930,162 +2127,6 @@ static int station_roam_scan_known_freqs(struct station *station)
return r;
}
-static uint32_t station_freq_from_neighbor_report(const uint8_t *country,
- struct ie_neighbor_report_info *info, enum scan_band *out_band)
-{
- enum scan_band band;
- uint32_t freq;
-
- if (info->oper_class == 0) {
- /*
- * Some Cisco APs report all operating class values as 0
- * in the Neighbor Report Responses. Work around this by
- * using the most likely operating class for the channel
- * number as the 2.4GHz and 5GHz bands happen to mostly
- * use channels in two disjoint ranges.
- */
- if (info->channel_num >= 1 && info->channel_num <= 14)
- band = SCAN_BAND_2_4_GHZ;
- else if (info->channel_num >= 36 && info->channel_num <= 169)
- band = SCAN_BAND_5_GHZ;
- else {
- l_debug("Ignored: 0 oper class with an unusual "
- "channel number");
-
- return 0;
- }
- } else {
- band = scan_oper_class_to_band(country, info->oper_class);
- if (!band) {
- l_debug("Ignored: unsupported oper class");
-
- return 0;
- }
- }
-
- freq = scan_channel_to_freq(info->channel_num, band);
- if (!freq) {
- l_debug("Ignored: unsupported channel");
-
- return 0;
- }
-
- if (out_band)
- *out_band = band;
-
- return freq;
-}
-
-static void parse_neighbor_report(struct station *station,
- const uint8_t *reports,
- size_t reports_len,
- struct scan_freq_set **set)
-{
- struct ie_tlv_iter iter;
- int count_md = 0, count_no_md = 0;
- struct scan_freq_set *freq_set_md, *freq_set_no_md;
- uint32_t current_freq = 0;
- struct handshake_state *hs = netdev_get_handshake(station->netdev);
-
- freq_set_md = scan_freq_set_new();
- freq_set_no_md = scan_freq_set_new();
-
- ie_tlv_iter_init(&iter, reports, reports_len);
-
- /* First see if any of the reports contain the MD bit set */
- while (ie_tlv_iter_next(&iter)) {
- struct ie_neighbor_report_info info;
- uint32_t freq;
- enum scan_band band;
- const uint8_t *cc = NULL;
-
- if (ie_tlv_iter_get_tag(&iter) != IE_TYPE_NEIGHBOR_REPORT)
- continue;
-
- if (ie_parse_neighbor_report(&iter, &info) < 0)
- continue;
-
- l_debug("Neighbor report received for %s: ch %i "
- "(oper class %i), %s",
- util_address_to_string(info.addr),
- (int) info.channel_num, (int) info.oper_class,
- info.md ? "MD set" : "MD not set");
-
- if (station->connected_bss->cc_present)
- cc = station->connected_bss->cc;
-
- freq = station_freq_from_neighbor_report(cc, &info, &band);
- if (!freq)
- continue;
-
- /* Skip if the band is not supported */
- if (!(band & wiphy_get_supported_bands(station->wiphy)))
- continue;
-
- if (!memcmp(info.addr,
- station->connected_bss->addr, ETH_ALEN)) {
- /*
- * If this report is for the current AP, don't add
- * it to any of the lists yet. We will need to scan
- * its channel because it may still be the best ranked
- * or the only visible AP.
- */
- current_freq = freq;
-
- continue;
- }
-
- /* Add the frequency to one of the lists */
- if (info.md && hs->mde) {
- scan_freq_set_add(freq_set_md, freq);
-
- count_md += 1;
- } else {
- scan_freq_set_add(freq_set_no_md, freq);
-
- count_no_md += 1;
- }
- }
-
- if (!current_freq)
- current_freq = station->connected_bss->frequency;
-
- /*
- * If there are neighbor reports with the MD bit set then the bit
- * is probably valid so scan only the frequencies of the neighbors
- * with that bit set, which will allow us to use Fast Transition.
- * Some APs, such as those based on hostapd do not set the MD bit
- * even if the neighbor is within the MD.
- *
- * In any case we only select the frequencies here and will check
- * the IEs in the scan results as the authoritative information
- * on whether we can use Fast Transition, and rank BSSes based on
- * that.
- *
- * TODO: possibly save the neighbors from outside the MD and if
- * none of the ones in the MD end up working, try a non-FT
- * transition to those neighbors. We should be using a
- * blacklisting mechanism (for both initial connection and
- * transitions) so that cound_md would not count the
- * BSSes already used and when it goes down to 0 we'd
- * automatically fall back to the non-FT candidates and then to
- * full scan.
- */
- if (count_md) {
- scan_freq_set_add(freq_set_md, current_freq);
- *set = freq_set_md;
- scan_freq_set_free(freq_set_no_md);
- } else if (count_no_md) {
- scan_freq_set_add(freq_set_no_md, current_freq);
- *set = freq_set_no_md;
- scan_freq_set_free(freq_set_md);
- } else {
- scan_freq_set_free(freq_set_no_md);
- scan_freq_set_free(freq_set_md);
- *set = NULL;
- }
-}
-
static void station_neighbor_report_cb(struct netdev *netdev, int err,
const uint8_t *reports,
size_t reports_len, void *user_data)
@@ -2217,9 +2258,9 @@ static bool station_cannot_roam(struct station *station)
#define WNM_REQUEST_MODE_TERMINATION_IMMINENT (1 << 3)
#define WNM_REQUEST_MODE_ESS_DISASSOCIATION_IMMINENT (1 << 4)
-void station_ap_directed_roam(struct station *station,
- const struct mmpdu_header *hdr,
- const void *body, size_t body_len)
+static void station_ap_directed_roam(struct station *station,
+ const struct mmpdu_header *hdr,
+ const void *body, size_t body_len)
{
uint32_t pos = 0;
uint8_t req_mode;
@@ -2342,7 +2383,7 @@ static void station_event_roamed(struct station *station, struct scan_bss *new)
l_queue_insert(station->bss_list, new, scan_bss_rank_compare, NULL);
- station_enter_state(station, STATION_STATE_CONNECTED);
+ station_roamed(station);
}
static void station_rssi_level_changed(struct station *station,
@@ -2471,24 +2512,6 @@ static void station_connect_dbus_reply(struct station *station,
dbus_pending_reply(&station->connect_pending, reply);
}
-static void station_early_neighbor_report_cb(struct netdev *netdev, int err,
- const uint8_t *reports,
- size_t reports_len,
- void *user_data)
-{
- struct station *station = user_data;
-
- l_debug("ifindex: %u, error: %d(%s)",
- netdev_get_ifindex(station->netdev),
- err, err < 0 ? strerror(-err) : "");
-
- if (!reports || err)
- return;
-
- parse_neighbor_report(station, reports, reports_len,
- &station->roam_freqs);
-}
-
static void station_connect_cb(struct netdev *netdev, enum netdev_result result,
void *event_data, void *user_data)
{
@@ -2668,6 +2691,7 @@ void station_connect_network(struct station *station, struct network *network,
scan_cancel(netdev_get_wdev_id(station->netdev),
station->quick_scan_id);
station->quick_scan_id = 0;
+ station_property_set_scanning(station, false);
}
if (station_is_busy(station)) {
@@ -3555,6 +3579,10 @@ static void station_free(struct station *station)
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);
+
if (station->netconfig) {
netconfig_destroy(station->netconfig);
station->netconfig = NULL;
@@ -3663,6 +3691,7 @@ static void station_get_diagnostic_cb(
struct station *station = user_data;
struct l_dbus_message *reply;
struct l_dbus_message_builder *builder;
+ struct handshake_state *hs = netdev_get_handshake(station->netdev);
if (!info) {
reply = dbus_error_aborted(station->get_station_pending);
@@ -3679,6 +3708,9 @@ static void station_get_diagnostic_cb(
util_address_to_string(info->addr));
dbus_append_dict_basic(builder, "Frequency", 'u',
&station->connected_bss->frequency);
+ dbus_append_dict_basic(builder, "Security", 's',
+ diagnostic_akm_suite_to_security(hs->akm_suite,
+ hs->wpa_ie));
diagnostic_info_to_dict(info, builder);
@@ -3731,15 +3763,48 @@ static void station_destroy_diagnostic_interface(void *user_data)
{
}
+static void ap_roam_frame_event(const struct mmpdu_header *hdr,
+ const void *body, size_t body_len,
+ int rssi, void *user_data)
+{
+ uint32_t ifindex = L_PTR_TO_UINT(user_data);
+ struct station *station = station_find(ifindex);
+
+ if (!station)
+ return;
+
+ station_ap_directed_roam(station, hdr, body, body_len);
+}
+
+static void add_frame_watches(struct netdev *netdev)
+{
+ static const uint8_t action_ap_roam_prefix[2] = { 0x0a, 0x07 };
+
+ /*
+ * register for AP roam transition watch
+ */
+ frame_watch_add(netdev_get_wdev_id(netdev), 0, 0x00d0,
+ action_ap_roam_prefix, sizeof(action_ap_roam_prefix),
+ ap_roam_frame_event,
+ L_UINT_TO_PTR(netdev_get_ifindex(netdev)), NULL);
+}
+
static void station_netdev_watch(struct netdev *netdev,
enum netdev_watch_event event, void *userdata)
{
switch (event) {
- case NETDEV_WATCH_EVENT_UP:
case NETDEV_WATCH_EVENT_NEW:
- if (netdev_get_iftype(netdev) == NETDEV_IFTYPE_STATION &&
- netdev_get_is_up(netdev))
+ if (netdev_get_iftype(netdev) == NETDEV_IFTYPE_STATION) {
+ add_frame_watches(netdev);
+
+ if (netdev_get_is_up(netdev))
+ station_create(netdev);
+ }
+ break;
+ case NETDEV_WATCH_EVENT_UP:
+ if (netdev_get_iftype(netdev) == NETDEV_IFTYPE_STATION)
station_create(netdev);
+
break;
#ifdef HAVE_DBUS
case NETDEV_WATCH_EVENT_DOWN:
@@ -3749,6 +3814,11 @@ static void station_netdev_watch(struct netdev *netdev,
IWD_STATION_INTERFACE);
break;
#endif
+ case NETDEV_WATCH_EVENT_IFTYPE_CHANGE:
+ if (netdev_get_iftype(netdev) == NETDEV_IFTYPE_STATION)
+ add_frame_watches(netdev);
+
+ break;
default:
break;
}
diff --git a/src/station.h b/src/station.h
@@ -83,10 +83,6 @@ void station_remove_anqp_watch(uint32_t id);
bool station_set_autoconnect(struct station *station, bool autoconnect);
-void station_ap_directed_roam(struct station *station,
- const struct mmpdu_header *hdr,
- const void *body, size_t body_len);
-
int __station_connect_network(struct station *station, struct network *network,
struct scan_bss *bss);
void station_connect_network(struct station *station, struct network *network,
diff --git a/src/wiphy.c b/src/wiphy.c
@@ -178,6 +178,8 @@ enum ie_rsn_akm_suite wiphy_select_akm(struct wiphy *wiphy,
{
struct ie_rsn_info info;
enum security security;
+ bool psk_offload = wiphy_has_ext_feature(wiphy,
+ NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK);
memset(&info, 0, sizeof(info));
scan_bss_get_rsn_info(bss, &info);
@@ -246,10 +248,17 @@ enum ie_rsn_akm_suite wiphy_select_akm(struct wiphy *wiphy,
}
wpa2_personal:
+ /*
+ * Allow FT if either Auth/Assoc is supported OR if the card
+ * supports PSK offload. Without Auth/Assoc, PSK offload is the
+ * only mechanism to allow FT on these cards.
+ */
if ((info.akm_suites & IE_RSN_AKM_SUITE_FT_USING_PSK) &&
- bss->rsne && bss->mde_present &&
- wiphy->support_cmds_auth_assoc)
- return IE_RSN_AKM_SUITE_FT_USING_PSK;
+ bss->rsne && bss->mde_present) {
+ if (wiphy->support_cmds_auth_assoc ||
+ (psk_offload && wiphy->support_fw_roam))
+ return IE_RSN_AKM_SUITE_FT_USING_PSK;
+ }
if (info.akm_suites & IE_RSN_AKM_SUITE_PSK_SHA256)
return IE_RSN_AKM_SUITE_PSK_SHA256;
@@ -388,7 +397,8 @@ const struct scan_freq_set *wiphy_get_supported_freqs(
return wiphy->supported_freqs;
}
-bool wiphy_can_connect(struct wiphy *wiphy, struct scan_bss *bss)
+bool wiphy_can_connect(struct wiphy *wiphy, struct scan_bss *bss,
+ bool fils_hint)
{
struct ie_rsn_info rsn_info;
int r;
@@ -407,24 +417,7 @@ bool wiphy_can_connect(struct wiphy *wiphy, struct scan_bss *bss)
rsn_info.group_management_cipher))
return false;
-
- switch (rsn_info.akm_suites) {
- case IE_RSN_AKM_SUITE_SAE_SHA256:
- case IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256:
- if (!wiphy_can_connect_sae(wiphy))
- return false;
-
- break;
- case IE_RSN_AKM_SUITE_OWE:
- case IE_RSN_AKM_SUITE_FILS_SHA256:
- case IE_RSN_AKM_SUITE_FILS_SHA384:
- case IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA256:
- case IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384:
- if (!wiphy->support_cmds_auth_assoc)
- return false;
-
- break;
- }
+ return wiphy_select_akm(wiphy, bss, fils_hint);
} else if (r != -ENOENT)
return false;
@@ -612,7 +605,7 @@ static char **wiphy_get_supported_iftypes(struct wiphy *wiphy, uint16_t mask)
if (!(supported_mask & (1 << i)))
continue;
- str = dbus_iftype_to_string(i + 1);
+ str = netdev_iftype_to_string(i + 1);
if (str)
ret[j++] = l_strdup(str);
}
@@ -1635,6 +1628,16 @@ void wiphy_radio_work_done(struct wiphy *wiphy, uint32_t id)
wiphy_radio_work_next(wiphy);
}
+bool wiphy_radio_work_is_running(struct wiphy *wiphy, uint32_t id)
+{
+ struct wiphy_radio_work_item *item = l_queue_peek_head(wiphy->work);
+
+ if (!item)
+ return false;
+
+ return item->id == id;
+}
+
static int wiphy_init(void)
{
struct l_genl *genl = iwd_get_genl();
diff --git a/src/wiphy.h b/src/wiphy.h
@@ -78,7 +78,8 @@ const char *wiphy_get_path(struct wiphy *wiphy);
uint32_t wiphy_get_supported_bands(struct wiphy *wiphy);
const struct scan_freq_set *wiphy_get_supported_freqs(
const struct wiphy *wiphy);
-bool wiphy_can_connect(struct wiphy *wiphy, struct scan_bss *bss);
+bool wiphy_can_connect(struct wiphy *wiphy, struct scan_bss *bss,
+ bool fils_hint);
bool wiphy_supports_cmds_auth_assoc(struct wiphy *wiphy);
bool wiphy_can_randomize_mac_addr(struct wiphy *wiphy);
bool wiphy_rrm_capable(struct wiphy *wiphy);
@@ -116,3 +117,4 @@ uint32_t wiphy_radio_work_insert(struct wiphy *wiphy,
int priority,
const struct wiphy_radio_work_item_ops *ops);
void wiphy_radio_work_done(struct wiphy *wiphy, uint32_t id);
+bool wiphy_radio_work_is_running(struct wiphy *wiphy, uint32_t id);
diff --git a/src/wscutil.c b/src/wscutil.c
@@ -3050,3 +3050,48 @@ bool wsc_device_type_from_subcategory_str(struct wsc_primary_device_type *out,
return false;
}
+
+bool wsc_device_type_from_setting_str(const char *value,
+ struct wsc_primary_device_type *out)
+{
+ unsigned long long u;
+ char *endp;
+
+ if (!value)
+ return false;
+
+ /*
+ * Standard WSC subcategories are unique and more specific than
+ * categories so there's no point for the user to specify the
+ * category if they choose to use the string format.
+ *
+ * As an example our default value (Computer - PC) can be
+ * encoded as either of:
+ *
+ * DeviceType=pc
+ * DeviceType=0x00010050f2040001
+ * DeviceType=1-0050f204-1
+ */
+ if (wsc_device_type_from_subcategory_str(out, value))
+ true;
+
+ u = strtoull(value, &endp, 0);
+
+ /*
+ * Accept any custom category, OUI and subcategory values but require
+ * non-zero category as a sanity check.
+ */
+ if (*endp == '\0' && (u & 0xffff000000000000ll) != 0) {
+ out->category = u >> 48;
+ out->oui[0] = u >> 40;
+ out->oui[1] = u >> 32;
+ out->oui[2] = u >> 24;
+ out->oui_type = u >> 16;
+ out->subcategory = u;
+ return true;
+ }
+
+ return sscanf(value, "%hx-%2hhx%2hhx%2hhx%2hhx-%2hx", &out->category,
+ &out->oui[0], &out->oui[1], &out->oui[2],
+ &out->oui_type, &out->subcategory) == 6;
+}
diff --git a/src/wscutil.h b/src/wscutil.h
@@ -681,3 +681,5 @@ bool wsc_device_type_to_dbus_str(const struct wsc_primary_device_type *val,
const char **subcategory_str);
bool wsc_device_type_from_subcategory_str(struct wsc_primary_device_type *out,
const char *subcategory_str);
+bool wsc_device_type_from_setting_str(const char *value,
+ struct wsc_primary_device_type *out);
diff --git a/tools/hwsim.c b/tools/hwsim.c
@@ -114,6 +114,7 @@ enum hwsim_tx_control_flags {
#define IEEE80211_TX_RATE_TABLE_SIZE 4
#define HWSIM_DELAY_MIN_MS 1
+#define HWSIM_MAX_PREFIX_LEN 128
struct hwsim_rule {
unsigned int id;
@@ -127,6 +128,8 @@ struct hwsim_rule {
int priority;
int signal;
int delay;
+ uint8_t *prefix;
+ size_t prefix_len;
};
struct hwsim_support {
@@ -1203,6 +1206,12 @@ static void process_rules(const struct radio_info_rec *src_radio,
if (rule->frequency && rule->frequency != frame->frequency)
continue;
+ if (rule->prefix && frame->payload_len >= rule->prefix_len) {
+ if (memcmp(rule->prefix, frame->payload,
+ rule->prefix_len) != 0)
+ continue;
+ }
+
/* Rule deemed to match frame, apply any changes */
if (rule->signal)
@@ -2025,6 +2034,10 @@ static struct l_dbus_message *rule_remove(struct l_dbus *dbus,
path = rule_get_path(rule);
l_queue_remove(rules, rule);
+
+ if (rule->prefix)
+ l_free(rule->prefix);
+
l_free(rule);
l_dbus_unregister_object(dbus, path);
@@ -2303,6 +2316,59 @@ static struct l_dbus_message *rule_property_set_delay(
return l_dbus_message_new_method_return(message);
}
+static bool rule_property_get_prefix(struct l_dbus *dbus,
+ struct l_dbus_message *message,
+ struct l_dbus_message_builder *builder,
+ void *user_data)
+{
+ struct hwsim_rule *rule = user_data;
+ size_t i;
+
+ l_dbus_message_builder_enter_array(builder, "y");
+
+ for (i = 0; i < rule->prefix_len; i++)
+ l_dbus_message_builder_append_basic(builder, 'y',
+ rule->prefix + i);
+
+ l_dbus_message_builder_leave_array(builder);
+
+ return true;
+}
+
+static struct l_dbus_message *rule_property_set_prefix(
+ struct l_dbus *dbus,
+ struct l_dbus_message *message,
+ struct l_dbus_message_iter *new_value,
+ l_dbus_property_complete_cb_t complete,
+ void *user_data)
+{
+ struct hwsim_rule *rule = user_data;
+ struct l_dbus_message_iter iter;
+ const uint8_t *prefix;
+ uint32_t len;
+
+ if (!l_dbus_message_iter_get_variant(new_value, "ay", &iter))
+ goto invalid_args;
+
+ if (!l_dbus_message_iter_get_fixed_array(&iter,
+ (const void **)&prefix, &len))
+ goto invalid_args;
+
+ if (len > HWSIM_MAX_PREFIX_LEN)
+ goto invalid_args;
+
+ if (rule->prefix)
+ l_free(rule->prefix);
+
+ rule->prefix = l_memdup(prefix, len);
+ rule->prefix_len = len;
+
+ return l_dbus_message_new_method_return(message);
+
+invalid_args:
+ return dbus_error_invalid_args(message);
+}
+
static void setup_rule_interface(struct l_dbus_interface *interface)
{
l_dbus_interface_method(interface, "Remove", 0, rule_remove, "", "");
@@ -2339,6 +2405,10 @@ static void setup_rule_interface(struct l_dbus_interface *interface)
L_DBUS_PROPERTY_FLAG_AUTO_EMIT, "u",
rule_property_get_delay,
rule_property_set_delay);
+ l_dbus_interface_property(interface, "Prefix",
+ L_DBUS_PROPERTY_FLAG_AUTO_EMIT, "ay",
+ rule_property_get_prefix,
+ rule_property_set_prefix);
}
static void request_name_callback(struct l_dbus *dbus, bool success,
diff --git a/tools/test-runner b/tools/test-runner
@@ -194,8 +194,11 @@ class Process:
self.io_position = self.stdout.tell()
if ctx:
- # Verbose requested, add stdout/stderr to write FD list
- if self.name in ctx.args.verbose:
+ # Verbose requested, add stdout/stderr to write FD list.
+ # This will end up always returning true if logging is
+ # on which isn't desired so pass log=False as to only
+ # allow stdout to processes listed in --verbose.
+ if ctx.is_verbose(self.name, log=False):
self.verbose = True
# Add output file to FD list
@@ -242,33 +245,24 @@ class Process:
if not wait and not check:
return
- self.pid.wait()
+ self.pid.wait(timeout=5)
self.killed = True
+ self.ret = self.pid.returncode
self.stdout.seek(self.io_position)
self.out = self.stdout.read()
self.stdout.seek(0, 2)
- self.ret = self.pid.returncode
- #
- # No IO callback for wait/check=True processes so write out
- # the data to any FD's now.
- #
if len(self.write_fds) > 0:
- for fd in self.write_fds:
- fd.write(self.out)
- fd.close()
+ self.process_io(self.stdout)
- self.write_fds = []
-
- if self.verbose:
- sys.__stdout__.write(self.out)
+ self.write_fds = []
print("%s returned %d" % (args[0], self.ret))
if check and self.ret != 0:
raise subprocess.CalledProcessError(returncode=self.ret, cmd=self.args)
- def io_callback(self, source, cb_condition):
+ def process_io(self, source):
#
# The file will have already been written to, meaning the seek
# position points to EOF. This is why the position is saved so
@@ -286,20 +280,27 @@ class Process:
for f in self.write_fds:
f.write(data)
+ f.flush()
if self.verbose:
sys.__stdout__.write(data)
+ sys.__stdout__.flush()
return True
+ def io_callback(self, source, cb_condition):
+ return self.process_io(source)
+
def __del__(self):
print("Del process %s" % self.args)
+ os.remove(self.output_name)
+
+ self.stdout.close()
+
if not self.killed:
self.kill()
- os.remove(self.output_name)
-
def kill(self, force=False):
print("Killing process %s" % self.args)
@@ -319,8 +320,10 @@ class Process:
self.ctx = None
- for f in self.write_fds:
- f.close()
+ self.process_io(self.stdout)
+
+ if self.cleanup:
+ self.cleanup()
self.write_fds = []
@@ -328,13 +331,7 @@ class Process:
GLib.source_remove(self.io_watch)
self.io_watch = None
- if self.cleanup:
- self.cleanup()
-
self.cleanup = None
-
- self.stdout.close()
-
self.killed = True
def wait_for_socket(self, socket, wait):
@@ -599,7 +596,7 @@ class Namespace:
if self.name == "root":
self._bus = dbus.bus.BusConnection(address_or_type=self.dbus_address)
- for p in self.processes:
+ for p in list(self.processes):
print("Killing process %s" % p.name)
p.kill()
@@ -693,23 +690,20 @@ class Namespace:
if self.is_verbose('iwd-tls'):
env['IWD_TLS_DEBUG'] = '1'
- if self.is_verbose('iwd-genl'):
- env['IWD_GENL_DEBUG'] = '1'
-
if self.is_verbose('iwd-acd'):
env['IWD_ACD_DEBUG'] = '1'
pid = self.start_process(args, env=env)
return pid
- def is_verbose(self, process):
+ def is_verbose(self, process, log=True):
process = os.path.basename(process)
if self.args is None:
return False
# every process is verbose when logging is enabled
- if self.args.log:
+ if log and self.args.log:
return True
if process in self.args.verbose:
diff --git a/unit/test-sae.c b/unit/test-sae.c
@@ -236,59 +236,6 @@ static size_t setup_assoc_frame(struct associate_frame *frame, uint16_t status)
return sizeof(frame->hdr) + sizeof(frame->assoc);
}
-static void test_confirm_timeout(const void *arg)
-{
- struct test_data *td = l_new(struct test_data, 1);
- struct auth_proto *ap = test_initialize(td);
- struct authenticate_frame *frame = alloca(
- sizeof(struct authenticate_frame) +
- sizeof(aa_commit));
- size_t len;
- int i;
-
- len = setup_auth_frame(frame, aa, 1, 0, aa_commit, sizeof(aa_commit));
-
- assert(auth_proto_rx_authenticate(ap, (uint8_t *)frame, len) == 0);
-
- assert(td->confirm_success);
-
- assert(l_get_le16(td->tx_packet + 4) == 1);
-
- for (i = 1; i < 5; i++) {
- assert(auth_proto_auth_timeout(ap));
- assert(l_get_le16(td->tx_packet + 4) == i + 1);
- }
-
- assert(!auth_proto_auth_timeout(ap));
-
- test_destruct(td);
-
- auth_proto_free(ap);
-}
-
-static void test_commit_timeout(const void *arg)
-{
- struct test_data *td = l_new(struct test_data, 1);
- struct auth_proto *ap = test_initialize(td);
- uint8_t last_packet[512];
- int i;
-
- memcpy(last_packet, td->tx_packet, td->tx_packet_len);
-
- for (i = 0; i < 4; i++) {
- assert(auth_proto_auth_timeout(ap));
-
- assert(!memcmp(last_packet, td->tx_packet, td->tx_packet_len));
-
- memcpy(last_packet, td->tx_packet, td->tx_packet_len);
- }
-
- assert(!auth_proto_auth_timeout(ap));
-
- test_destruct(td);
- auth_proto_free(ap);
-}
-
static void test_clogging(const void *arg)
{
struct test_data *td = l_new(struct test_data, 1);
@@ -575,16 +522,7 @@ static void test_confirm_after_accept(const void *arg)
assert(td1->tx_assoc_called);
- /* simulate sm2 not receiving confirm and resending its confirm */
- ap2->auth_timeout(ap2);
- frame_len = setup_auth_frame(frame, aa, 2, 0, td2->tx_packet + 4,
- td2->tx_packet_len - 4);
- assert(auth_proto_rx_authenticate(ap1, (uint8_t *)frame,
- frame_len) == 0);
-
- /* sc should be set to 0xffff */
- assert(l_get_u16(td1->tx_packet + 4) == 0xffff);
- /* sm1 should respond with a new confirm, and accept */
+ /* sm1 should respond with a confirm, and accept */
frame_len = setup_auth_frame(frame, spa, 2, 0, td1->tx_packet + 4,
td1->tx_packet_len - 4);
assert(auth_proto_rx_authenticate(ap2, (uint8_t *)frame,
@@ -703,8 +641,6 @@ int main(int argc, char *argv[])
goto done;
}
- l_test_add("SAE commit timeout", test_commit_timeout, NULL);
- l_test_add("SAE confirm timeout", test_confirm_timeout, NULL);
l_test_add("SAE anti-clogging", test_clogging, NULL);
l_test_add("SAE early confirm", test_early_confirm, NULL);
l_test_add("SAE reflection", test_reflection, NULL);