From patchwork Wed Dec 13 17:25:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13491685 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55ABF54BDF for ; Wed, 13 Dec 2023 17:26:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="e0ZMU+SF" Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-67ab5e015aaso46050936d6.0 for ; Wed, 13 Dec 2023 09:26:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702488363; x=1703093163; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IfSjzJXTaxeEhvm1B7MBmwyuYo5Vc1z83FjL0XeTyFM=; b=e0ZMU+SF6DMtnFjv2W4RPSwhnJ1TxZ2QuucV9qVwOpA9RbsG+4u3ZFtAXtBIjIM6VO 0HYg9a6ofgn4bv2F6kOmOdRt6sOO5lCoLwKVA2aJKDlP/ivPWA5XivOk6iwrtBIg31vq hfnxVELr7UMpHTREGnxtbe+SPjlffGrNP8dJcrtXIxMinyxwRGOqSXhg0KdmcbHpOsVF sA0lvoZlvbPLv21mboJJv8lJbVvsywWQIJdU+tZlHJSpHjcz8BbIckpy1IxfRQSCmjva 6GtiXufXWfTaVBHfkEJCuMQaI/UG/mrok/LA8m5U2kXTgCBfvpPoBAore2g+0KagnBbs Q04w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702488363; x=1703093163; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IfSjzJXTaxeEhvm1B7MBmwyuYo5Vc1z83FjL0XeTyFM=; b=nFPa1fZQi9rLXL8E6CJHL8DMT0h7g8HGGecaP2AUsokDBTS1p+jr7q2KUTJpsVWyt/ Myv5bChYvXK8DXBXKS9/RZxebq2JRLhg2QQmtImf6FtXjbAdtJ4gm7dE0Uyh9223PLMi iS5RpU4VO0GpJ84uAYTRNO4us4c/ZR4HeFhdkvY5cOZmpaxy5crR1BzMdco0yccbNDpc LPT5um0MwzjwhPnwUdJDi7ePuVRvBog9SBUdUq7JXD/0ydyKhWq/Lnd2+NJjq91w4i0X v9xBbWH7jXCPOMDtavaqlQ6LGLFUKcR647YMbnJLi1zxr5SHcW+77hXTtGa5KYWrM6fr ObFg== X-Gm-Message-State: AOJu0YwLf/9b46eC9Rp7Wq79RmaejO7gt/cIsxkYh7IO8gOQPVzn0yS0 zXkCW7WtF2FNvKEn5KFVg7eg4xv0NN8= X-Google-Smtp-Source: AGHT+IGo+MTDaDuhpiKl809WOHCxpyPg2Ypou7+cjgVHD2r6eJ5+YKkfmOe4ivSijhEi/Qw6Ux7FIQ== X-Received: by 2002:a05:6214:5c3:b0:67a:a721:7848 with SMTP id t3-20020a05621405c300b0067aa7217848mr9225980qvz.109.1702488362884; Wed, 13 Dec 2023 09:26:02 -0800 (PST) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id hh12-20020a05622a618c00b00425f0ab0393sm556914qtb.17.2023.12.13.09.26.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 09:26:02 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [RFC 1/4] knownnetworks: set ops on info in __network_info_init Date: Wed, 13 Dec 2023 09:25:43 -0800 Message-Id: <20231213172546.145998-2-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231213172546.145998-1-prestwoj@gmail.com> References: <20231213172546.145998-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This function was only used by hotspot as a backdoor to initializing a network info object. For the hotspot case it has its own ops structure which is set after calling. DPP now will need a way to create/update a known network from a receieved configuration but it only needs the default ops structure from known networks. Set this automatically within this function. This won't pose an issue to hotspot as it will just overwrite the ops pointer to its own implementation. --- src/knownnetworks.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/knownnetworks.c b/src/knownnetworks.c index e2d0d515..b8f13cbc 100644 --- a/src/knownnetworks.c +++ b/src/knownnetworks.c @@ -125,21 +125,6 @@ void __network_config_parse(const struct l_settings *settings, } } -void __network_info_init(struct network_info *info, - const char *ssid, enum security security, - struct network_config *config) -{ - if (ssid) - strcpy(info->ssid, ssid); - - info->type = security; - - memcpy(&info->config, config, sizeof(struct network_config)); - - if (info->config.is_hidden) - num_known_hidden_networks++; -} - static void network_info_free(void *data) { struct network_info *network = data; @@ -815,6 +800,23 @@ void known_networks_add(struct network_info *network) KNOWN_NETWORKS_EVENT_ADDED, network); } +void __network_info_init(struct network_info *info, + const char *ssid, enum security security, + struct network_config *config) +{ + if (ssid) + strcpy(info->ssid, ssid); + + info->type = security; + + memcpy(&info->config, config, sizeof(struct network_config)); + + if (info->config.is_hidden) + num_known_hidden_networks++; + + info->ops = &known_network_ops; +} + static void known_network_new(const char *ssid, enum security security, struct network_config *config) { From patchwork Wed Dec 13 17:25:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13491686 Received: from mail-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 256B554FAE for ; Wed, 13 Dec 2023 17:26:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bWjNK0hT" Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-3ba2e4ff6e1so56894b6e.3 for ; Wed, 13 Dec 2023 09:26:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702488364; x=1703093164; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cEPdNfRnU1tcY+wCOLFMTwot+Xe9HH010Ltb3HBhZD0=; b=bWjNK0hTdPOn/E0Q/y/O1cTAMhrMYMSegXxTCEhisffBgERCeB+K7AHWSC8Z5HMGse zJai8mX2tvAChWzCMFc+Kr/mWUVTxBoY/qBwSODddZeZyZC0Efbto0QNnvbz87aZQ94i 2j6BSa/OmnBaPHXV99vLp3VcTQqlTdWVY8aohGqoGHQ6TnMLhawOg79SyqGqsuQUlcAc ZE7soQFtWB1s19OqWbRNdEF6w5eaYYD1Potk5Xq4vDL7pB9+7q4dpVUnGOVePps6T490 ISv8yobU/4EArUA41NpMQSvKv00pJ4kKwvmFjm1xG5Eq+NJf+Q9pVphGD6mnA28+8e3I L2jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702488364; x=1703093164; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cEPdNfRnU1tcY+wCOLFMTwot+Xe9HH010Ltb3HBhZD0=; b=CU0SWjsL1swEYhHPVg5urcUa+7ULCA2gMbxTXc+pkIiGzMWasKmqzJfQM0n+yRe+M9 DwhxAaPAzO936yGeYJ7rQ50CWi2GczpwWcSJrjkY5p82bIZvzepsiLuZiqjONutdxxR4 4VBOOY9s1ZzOrCeeT5GzZjZ/xJ1JGqYuVkKCoXqyAPJ0ZDdtSFIZFDtuYLLDBBLMiYdk S09ZS5YmQlWW9jhBsrvQdZ9HLcefyhg20cbJ53EytSj60+9z3Nx8BRViHh0BuIcfGZgd UjQ6uA8Js/cJAky3MAJVtY5YmIWwL8nIMEnEzOnkwTZ1q8hPYWO1PNQvnwO6kw/koQcp AlZg== X-Gm-Message-State: AOJu0YwVjx7QGfhu642ug57pCbczWT3hNegJ+oe6+LDGiexrFcpj8kIq iFBwswrNwtb6vhLR3EWwHKIi66iJUOk= X-Google-Smtp-Source: AGHT+IGBYs33TWO1rkpgrBZDw2IjQ950DmIhmyVFfa/qc+0QUxG5Yih1sEzaSqRAH9k2hmBVz0jvOg== X-Received: by 2002:a05:6808:1290:b0:3b8:9b7f:40e8 with SMTP id a16-20020a056808129000b003b89b7f40e8mr11148565oiw.17.1702488363851; Wed, 13 Dec 2023 09:26:03 -0800 (PST) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id hh12-20020a05622a618c00b00425f0ab0393sm556914qtb.17.2023.12.13.09.26.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 09:26:03 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [RFC 2/4] station: unify scan cancelation Date: Wed, 13 Dec 2023 09:25:44 -0800 Message-Id: <20231213172546.145998-3-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231213172546.145998-1-prestwoj@gmail.com> References: <20231213172546.145998-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The scan cancelation was all being done manually so group all the automatic-type scans into a single cancel function. This includes hidden, quick, owe, and periodic scans. This is being done in order to avoid scan failures after DPP initiates a connection. This is ultimately done through __station_connect_network which has no cancelation logic. This patch will move the scan cancelation into station_enter_state when the state changes to CONNECTING. All the mentioned scans will be canceled at that point. DBus scans were left out intentionally as they are an explicit type of scan rather than one that IWD starts on its own. --- src/station.c | 96 +++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 53 deletions(-) diff --git a/src/station.c b/src/station.c index 10860808..95ffee05 100644 --- a/src/station.c +++ b/src/station.c @@ -279,16 +279,8 @@ static int station_autoconnect_next(struct station *station) bss->signal_strength); r = network_autoconnect(network, bss); - if (!r) { - if (station->quick_scan_id) { - scan_cancel(netdev_get_wdev_id(station->netdev), - station->quick_scan_id); - station->quick_scan_id = 0; - station_property_set_scanning(station, false); - } - + if (!r) return 0; - } l_debug("autoconnect: network_autoconnect: %s (%d)", strerror(-r), r); @@ -1542,6 +1534,36 @@ static void station_set_drop_unicast_l2_multicast(struct station *station, static void station_signal_agent_notify(struct station *station); +static void station_cancel_scans(struct station *station) +{ + if (station->hidden_network_scan_id) { + scan_cancel(netdev_get_wdev_id(station->netdev), + station->hidden_network_scan_id); + + dbus_pending_reply(&station->hidden_pending, + dbus_error_failed(station->hidden_pending)); + } + + if (station->quick_scan_id) { + 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->owe_hidden_scan_ids) { + void *ptr; + + while ((ptr = l_queue_pop_head(station->owe_hidden_scan_ids))) + scan_cancel(netdev_get_wdev_id(station->netdev), + L_PTR_TO_UINT(ptr)); + + l_queue_destroy(station->owe_hidden_scan_ids, NULL); + } + + periodic_scan_stop(station); +} + static void station_enter_state(struct station *station, enum station_state state) { @@ -1594,7 +1616,9 @@ static void station_enter_state(struct station *station, if (station->signal_agent) station_signal_agent_notify(station); - periodic_scan_stop(station); + /* Scans issued during a connection will fail */ + station_cancel_scans(station); + break; case STATION_STATE_CONNECTED: l_dbus_object_add_interface(dbus, @@ -3539,27 +3563,15 @@ void station_connect_network(struct station *station, struct network *network, struct l_dbus *dbus = dbus_get_bus(); int err; - /* - * If a hidden scan is not completed, station_is_busy would not - * indicate anything is going on so we need to cancel the scan and - * fail the connection now. - */ - if (station->hidden_network_scan_id) { - scan_cancel(netdev_get_wdev_id(station->netdev), - station->hidden_network_scan_id); - - dbus_pending_reply(&station->hidden_pending, - dbus_error_failed(station->hidden_pending)); - } - - if (station->quick_scan_id) { - 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)) { + /* + * All scans will be canceled when entering into a connecting + * state but since we have an async disconnect callback cancel + * them early so we don't potentially trigger a scan in the + * middle of connecting. This also takes care of failing any + * hidden network connection + */ + station_cancel_scans(station); station_disconnect_onconnect(station, network, bss, message); return; @@ -4539,8 +4551,6 @@ static void station_free(struct station *station) station->netconfig = NULL; } - periodic_scan_stop(station); - if (station->signal_agent) { station_signal_agent_release(station->signal_agent, netdev_get_path(station->netdev)); @@ -4551,10 +4561,6 @@ static void station_free(struct station *station) dbus_pending_reply(&station->connect_pending, dbus_error_aborted(station->connect_pending)); - if (station->hidden_pending) - dbus_pending_reply(&station->hidden_pending, - dbus_error_aborted(station->hidden_pending)); - if (station->disconnect_pending) dbus_pending_reply(&station->disconnect_pending, dbus_error_aborted(station->disconnect_pending)); @@ -4567,23 +4573,7 @@ static void station_free(struct station *station) scan_cancel(netdev_get_wdev_id(station->netdev), station->dbus_scan_id); - if (station->quick_scan_id) - scan_cancel(netdev_get_wdev_id(station->netdev), - station->quick_scan_id); - - if (station->hidden_network_scan_id) - scan_cancel(netdev_get_wdev_id(station->netdev), - station->hidden_network_scan_id); - - if (station->owe_hidden_scan_ids) { - void *ptr; - - while ((ptr = l_queue_pop_head(station->owe_hidden_scan_ids))) - scan_cancel(netdev_get_wdev_id(station->netdev), - L_PTR_TO_UINT(ptr)); - - l_queue_destroy(station->owe_hidden_scan_ids, NULL); - } + station_cancel_scans(station); station_roam_state_clear(station); From patchwork Wed Dec 13 17:25:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13491687 Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B05B5677B for ; Wed, 13 Dec 2023 17:26:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mullOZ8K" Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-3ba2dc0f6b7so124284b6e.2 for ; Wed, 13 Dec 2023 09:26:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702488365; x=1703093165; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=m+AzxstyjdTgwauON8U7WBzAIZNTEwIxtXNQec3PDBc=; b=mullOZ8KuG5pfFo0JEqr/R9Wjt1GySasCHWPqqTFkiHZdUv19qYT1ZEZeKfewXk5e3 A2GJT+gc4OcNJOxqINz8Mg0C+oOcE24QkvNiihat/tI1pWUgierDz0hnka004VFrhOhd jugsRloCHm95757jTOO/lBPMGmC90HyuFu1bOldYQ11YWpWwWBdzSv9n6yqlySeHCfZs Vx1JqCy3glYmAzaskq69aOi4TzDwHBzd4xbSBVh9sXJm2XaZ+5a0SX76QnDsQqw5xpw5 As/NL68+CYK2g/nipXKcDe1GPE+kcMj9hDmz3G8lEi7nPTUQob5yE2WcqObBoTSOaEVP MUfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702488365; x=1703093165; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m+AzxstyjdTgwauON8U7WBzAIZNTEwIxtXNQec3PDBc=; b=nZoE30Rq8O1HmXcQUfBfUmFbtu4L/oynpMlQq+cbNPja2RRo3P3aQcaI3n07LNhlou qn0BWhFtAmqJzLuCu6cjMgd1yCMMbCcCok56rKVj6SpLV9wWeRjPdGmiJxXapPmv45ul sVjESvjL/T4GDrpwU0AWqkesQo0jW302F/8wVYxAYaBW9S8zf5fo4nYK5hQd8Re6M9kF tDwtCdZyGlCSY5uGBC3n6siuVgZfTHImPoNDrobqJRenvsWa3lZ5OpOAPopWjqVBaal0 zR88zPr4E7IO93L696JF/bJhOfvQ5LNWcULPOtZj8b0Y6tfri6/WiCvwaZXclARtZYpB pXvg== X-Gm-Message-State: AOJu0Yytc31smEX9ojplPET2yVLBGK1hdqyP8jDMGcJiwjSM/wky07dt Z8B9IDKN7bZdstTcCAEvCvnjiLQrV4k= X-Google-Smtp-Source: AGHT+IHvONMKNigkULiILrPwwgBLtabYdjI4diLHIhM+frGX/z9cRe4H/EYc0xKxwkP201QXkRDaSg== X-Received: by 2002:a05:6808:21a6:b0:3b9:e87b:d963 with SMTP id be38-20020a05680821a600b003b9e87bd963mr11091154oib.85.1702488364812; Wed, 13 Dec 2023 09:26:04 -0800 (PST) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id hh12-20020a05622a618c00b00425f0ab0393sm556914qtb.17.2023.12.13.09.26.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 09:26:04 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [RFC 3/4] dpp: fix non-scan connect path in DPP Date: Wed, 13 Dec 2023 09:25:45 -0800 Message-Id: <20231213172546.145998-4-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231213172546.145998-1-prestwoj@gmail.com> References: <20231213172546.145998-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When DPP completes it writes the network configuration to disk but these changes aren't picked up by the network object until the known networks dir watch. Currently the connection itself works fine because the network object holds a copy of the passphrase/psk but additional settings like Hidden/SendHostname are not updated and not used for the connection through DPP. In theory DPP could also watch for known networks events and wait until the expected network is added but that is also fragile since its not guaranteed that the DPP watch callback will happen _after_ the one in network (when the network_info) is set into the object. Instead, DPP itself can handle the known network creation/update itself. If a known network already exists update its config. Otherwise create a new network_info object and set it into the network object. --- src/dpp.c | 89 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 27 deletions(-) diff --git a/src/dpp.c b/src/dpp.c index 1ff4b99e..3b42541d 100644 --- a/src/dpp.c +++ b/src/dpp.c @@ -53,6 +53,7 @@ #include "src/network.h" #include "src/handshake.h" #include "src/nl80211util.h" +#include "src/knownnetworks.h" #define DPP_FRAME_MAX_RETRIES 5 #define DPP_FRAME_RETRY_TIMEOUT 1 @@ -814,6 +815,8 @@ static void dpp_write_config(struct dpp_configuration *config, _auto_(l_free) char *path; _auto_(l_free) uint8_t *psk = NULL; size_t psk_len; + struct network_config network_config; + struct network_info *info; path = storage_get_network_file_path(SECURITY_PSK, config->ssid); @@ -822,22 +825,13 @@ static void dpp_write_config(struct dpp_configuration *config, l_settings_remove_group(settings, "Security"); } - if (config->passphrase) { + if (config->passphrase) l_settings_set_string(settings, "Security", "Passphrase", config->passphrase); - if (network) - network_set_passphrase(network, config->passphrase); - - } else if (config->psk) { + else if (config->psk) l_settings_set_string(settings, "Security", "PreSharedKey", config->psk); - psk = l_util_from_hexstring(config->psk, &psk_len); - - if (network) - network_set_psk(network, psk); - } - if (config->send_hostname) l_settings_set_bool(settings, "IPv4", "SendHostname", true); @@ -847,6 +841,39 @@ static void dpp_write_config(struct dpp_configuration *config, l_debug("Storing credential for '%s(%s)'", config->ssid, security_to_str(SECURITY_PSK)); storage_network_sync(SECURITY_PSK, config->ssid, settings); + + /* + * The network has yet to be seen. Once a scan is issued station will + * handle network creation and in turn the settings will be loaded from + * disk. + */ + if (!network) + return; + + /* + * Otherwise we need to jump through some hoops in order to update an + * existing network object with the new settings + */ + info = known_networks_find(config->ssid, SECURITY_PSK); + + __network_config_parse(settings, path, &network_config); + + if (info) + known_network_update(info, &network_config); + else { + info = l_new(struct network_info, 1); + __network_info_init(info, config->ssid, SECURITY_PSK, &network_config); + network_set_info(network, info); + } + + if (config->passphrase) + network_set_passphrase(network, config->passphrase); + else if (config->psk) { + psk = l_util_from_hexstring(config->psk, &psk_len); + + if (network) + network_set_psk(network, psk); + } } static void dpp_scan_triggered(int err, void *user_data) @@ -856,14 +883,34 @@ static void dpp_scan_triggered(int err, void *user_data) l_error("Failed to trigger DPP scan"); } +static void dpp_connect(struct dpp_sm *dpp, const char *ssid) +{ + struct station *station = station_find(netdev_get_ifindex(dpp->netdev)); + struct scan_bss *bss; + struct network *network; + int ret; + + network = station_network_find(station, ssid, SECURITY_PSK); + + dpp_reset(dpp); + + if (!network) { + l_debug("Network was not found after scanning"); + return; + } + + bss = network_bss_select(network, true); + ret = network_autoconnect(network, bss); + if (ret < 0) + l_debug("Failed to connect after DPP (%d) %s", ret, strerror(ret)); +} + static bool dpp_scan_results(int err, struct l_queue *bss_list, const struct scan_freq_set *freqs, void *userdata) { struct dpp_sm *dpp = userdata; struct station *station = station_find(netdev_get_ifindex(dpp->netdev)); - struct scan_bss *bss; - struct network *network; if (err < 0) goto reset; @@ -880,18 +927,7 @@ static bool dpp_scan_results(int err, struct l_queue *bss_list, station_set_scan_results(station, bss_list, freqs, false); - network = station_network_find(station, dpp->config->ssid, - SECURITY_PSK); - - dpp_reset(dpp); - - if (!network) { - l_debug("Network was not found after scanning"); - return true; - } - - bss = network_bss_select(network, true); - network_autoconnect(network, bss); + dpp_connect(dpp, dpp->config->ssid); return true; @@ -1075,8 +1111,7 @@ static void dpp_handle_config_response_frame(const struct mmpdu_header *frame, offchannel_cancel(dpp->wdev_id, dpp->offchannel_id); if (network && bss) - __station_connect_network(station, network, bss, - STATION_STATE_CONNECTING); + dpp_connect(dpp, config->ssid); else if (station) { struct scan_parameters params = {0}; From patchwork Wed Dec 13 17:25:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13491688 Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16D7556B86 for ; Wed, 13 Dec 2023 17:26:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PGArqCo1" Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-423d9d508d1so51864971cf.1 for ; Wed, 13 Dec 2023 09:26:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702488366; x=1703093166; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZZdR2Y3WTjhHoUByK3zKp5ikwBZKIUwPV1+jmwCs6+g=; b=PGArqCo1M4EbxKpf0b6mpUtwcvwkqfgPHKCKNayiUKIJPVJbDuYtoUhRaykUGkG0n6 0PapSPthnI2Lz1k2yJuBD3v9RFlxF5E8dkl0BvJd+aqk7KXxb73lzwvHfRnjFxjQOZ9J 2TVnRh7GnBG+36h9HaAbDwlwkfVJm22H0cd+6w0uWTTFKGJzSz9AmtX/YbyXm6JQjFLP Sm56yNUalYEQh3OgM/eGS0L4SM4I8zogCrfg5NXLl1530XWCtFCeKYzkgtiUMXvMd2gy 4E08Jw3tfnBsw/NI7W2JW5oldh4Bh1T0QSZmGj+Q7YQqAC5kNUibq2DdUGIk53+K1Bgt NXoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702488366; x=1703093166; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZZdR2Y3WTjhHoUByK3zKp5ikwBZKIUwPV1+jmwCs6+g=; b=SuS+9rLEHym+flJHaJJi+h/95Sexo4VMjx/X+7XbJjRldAnSQgr2auJpg7xhrJIBNB dRGiL39uPVhcxH1fjlKr2CheVxbXMYRc93dpxqnXDKoL4YXhOFmZbRAflzHiwXrw21ck sswDdlR9OUkwEptFUqxuZrE9PfVZTja5668xakGda+rxDvq846ehQbULY7eBzXYIpdDO oxh45E/FioBYkqHgNiWwuiJjYPQAFaSVQd4kqLbhNzbO67xyg/oRzBWZEzNeSDsLTLea 2iBU3CdV4+KTPajrJvgwBVChQ5FA6ljZHaH76gSlEUtAkFi5zcuM5Rd2JaBw322A/+FA 6ssg== X-Gm-Message-State: AOJu0YymqS8P5vxVEPTP/eIKe5to6jXWgCriAIVmwxtDObzg/Xh4pktr QhknnKg152nEbf4TX78jNQwqGtpTl70= X-Google-Smtp-Source: AGHT+IGP+jdvqnEE1lZFmpf4QTml6DTGZh3FpBJFOVnU41xSI3YQrD32lAaLuCY9Xkffcn9KWeDThw== X-Received: by 2002:a05:622a:10a:b0:423:708a:778c with SMTP id u10-20020a05622a010a00b00423708a778cmr12225874qtw.64.1702488365730; Wed, 13 Dec 2023 09:26:05 -0800 (PST) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id hh12-20020a05622a618c00b00425f0ab0393sm556914qtb.17.2023.12.13.09.26.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 09:26:05 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [RFC 4/4] auto-t: add a few more DPP tests for seen/known networks Date: Wed, 13 Dec 2023 09:25:46 -0800 Message-Id: <20231213172546.145998-5-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231213172546.145998-1-prestwoj@gmail.com> References: <20231213172546.145998-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 These ensure DPP works correctly when a network has already been seen in the scan results as well as if its a known network. --- autotests/testDPP/pkex_test.py | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/autotests/testDPP/pkex_test.py b/autotests/testDPP/pkex_test.py index 9e0b5dd8..07def453 100644 --- a/autotests/testDPP/pkex_test.py +++ b/autotests/testDPP/pkex_test.py @@ -186,6 +186,46 @@ class Test(unittest.TestCase): self.agent = None + def test_network_seen_before_dpp(self): + self.start_iwd_pkex_configurator(self.device[0]) + + # Scan first so a network object already exists + self.device[1].scan() + self.wd.wait_for_object_condition(self.device[1], 'obj.scanning == True') + self.wd.wait_for_object_condition(self.device[1], 'obj.scanning == False') + + self.device[1].dpp_pkex_enroll('secret123', identifier="test") + + condition = 'obj.state == DeviceState.connected' + self.wd.wait_for_object_condition(self.device[1], condition) + + # Check additional settings were carried over + with open('/tmp/ns0/ssidCCMP.psk', 'r') as f: + settings = f.read() + + self.assertIn("SendHostname=true", settings) + + def test_existing_known_network(self): + # Copy an invalid profile, make sure DPP overwrites it and connects + IWD.copy_to_storage("existingProfile.psk", "/tmp/ns0/", "ssidCCMP.psk") + self.start_iwd_pkex_configurator(self.device[0]) + + # Scan first so a network object exists, and its a known network + self.device[1].scan() + self.wd.wait_for_object_condition(self.device[1], 'obj.scanning == True') + self.wd.wait_for_object_condition(self.device[1], 'obj.scanning == False') + + self.device[1].dpp_pkex_enroll('secret123', identifier="test") + + condition = 'obj.state == DeviceState.connected' + self.wd.wait_for_object_condition(self.device[1], condition) + + # Check additional settings were carried over + with open('/tmp/ns0/ssidCCMP.psk', 'r') as f: + settings = f.read() + + self.assertIn("SendHostname=true", settings) + def setUp(self): ns0 = ctx.get_namespace('ns0') self.wpas = Wpas('wpas.conf')