From patchwork Thu Dec 14 18:01:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13493497 Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) (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 68FD567B73 for ; Thu, 14 Dec 2023 18:01:26 +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="ISmZ6rSr" Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-425ff068d17so6506471cf.1 for ; Thu, 14 Dec 2023 10:01:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702576885; x=1703181685; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=oHQHosg5Zj41fusGceU7mz94vvneJxJ0CXEcwdHRAhc=; b=ISmZ6rSrjawN0GwXaRqfV18IB3lkpAjsGpjEwLMzcIpjM/QKC+xyxvlQcrZz47uf9E WEqlWUPfILyz1/Z9EB2knzSxSZl9G1uTcYQqsZ8JrfgSIolNr9vP3Nbv343MPtPk/heg Bu3NtJiHnPGwbOGbuyee7wN9MwO1GVbEm89vvJyeRbZ7PEshv59h0TdeE8/zwacESwzn sq8s2uxPRMFK2rHkXtmgEYxUr0ijCculJ1Iw/PcJM9oF9qh+EKiV9yGlWLK7iblfRegp PnI/AYNbDICe00/Cp1xzvEqPmVqDAuzfRmQ+CgbB9EMoW9yrh3jyqC2dhUmoD8+g+2oI HIVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702576885; x=1703181685; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=oHQHosg5Zj41fusGceU7mz94vvneJxJ0CXEcwdHRAhc=; b=vLlzGy+YJRoOH/l3lYbErwjdKQbkeYjqPhoc34Ce7cm0J3cU5Re9pMFTy0Oxa9qfI1 i4id9+gXP932B1LJMTyKw075fWuAwZ124ynUiGPfsTfnmIPnY0ZLnf+s8aer6tWsm6a+ l4XTB6mHP3jv8SqSBl2qar1I14fPeaHs9j3dDFYS/+/swooFkZKaQmFSSAaxuD6B7crk UGm5PfuP2pzSBE3IcRea0L9FcVOwjnXlX9JlD+/MSvo62dH/0gCdn0YYo692oKYZx4d0 BCdfzHB5D+u3PqFWtmOkZLgsvdGBceNFR7KNnPbQTJ3m8qaae46Lf6CzLT6WN6KH5EvE Jh7w== X-Gm-Message-State: AOJu0YyYnqqecK8KAcClo+Qjgp8cMQHxbdRyK29On+DgaJCBznAkHH6L badFp19DFzv/x0d6ngIGOvNZ0Y8brOw= X-Google-Smtp-Source: AGHT+IH6ycqSGRHzn3M9oiJrYwPpg3JTer9+xJhQ+gCXo/6HovzzRfN0XLMi6RnZu/bhTR5Cr6sbHw== X-Received: by 2002:ac8:5707:0:b0:425:4043:1d7e with SMTP id 7-20020ac85707000000b0042540431d7emr13073789qtw.81.1702576884997; Thu, 14 Dec 2023 10:01:24 -0800 (PST) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id o8-20020ac85548000000b004257bf9a394sm5949511qtr.14.2023.12.14.10.01.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 10:01:24 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 1/5] network: remove 'path' from settings_load_pt_ecc Date: Thu, 14 Dec 2023 10:01:06 -0800 Message-Id: <20231214180110.130991-1-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The path argument was used purely for debugging. It can be just as informational printing just the SSID of the profile that failed to parse the setting without requiring callers allocate a string to call the function. --- src/network.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/network.c b/src/network.c index 79f964b2..41c5460b 100644 --- a/src/network.c +++ b/src/network.c @@ -556,7 +556,6 @@ int network_handshake_setup(struct network *network, struct scan_bss *bss, } static int network_settings_load_pt_ecc(struct network *network, - const char *path, unsigned int group, struct l_ecc_point **out_pt) { @@ -581,7 +580,7 @@ static int network_settings_load_pt_ecc(struct network *network, return 0; bad_format: - l_error("%s: invalid %s format", path, key); + l_error("%s profile: invalid %s format", network->ssid, key); generate: if (!network->passphrase) @@ -656,12 +655,10 @@ static int network_load_psk(struct network *network, struct scan_bss *bss) network_reset_psk(network); network->passphrase = l_steal_ptr(passphrase); - if (network_settings_load_pt_ecc(network, path, - 19, &network->sae_pt_19) > 0) + if (network_settings_load_pt_ecc(network, 19, &network->sae_pt_19) > 0) network->sync_settings = true; - if (network_settings_load_pt_ecc(network, path, - 20, &network->sae_pt_20) > 0) + if (network_settings_load_pt_ecc(network, 20, &network->sae_pt_20) > 0) network->sync_settings = true; network->psk = l_steal_ptr(psk); From patchwork Thu Dec 14 18:01:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13493498 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.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 B375167E6A for ; Thu, 14 Dec 2023 18:01:27 +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="mtR0cISO" Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-425a116f1cdso53378391cf.0 for ; Thu, 14 Dec 2023 10:01:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702576886; x=1703181686; 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=5LL5XMoKKfyj4lF/ccY1D6SLjeOwyNN/EZbhZdDGiOM=; b=mtR0cISOIHPaToaJnLu/9xm7QEHkrW41kabG++6ujR5RW5pQ7UXUAkpgV3vJU3ICRH wCHBqKYesIsHH/Wu794W2HL0wwha0OXJpN1s0R6UJmpyBRXruZu1pTS7yiZPsAjEbVMl qryOIsq28AhbNY6tqijaZ2Rl3qe4NoBP/0cZPxKwTFflNHafYQcxp5E4XmVVFOaFm+Lc G7bXpouAoCvPMvGBj2MgN2NZ0R0N/mOxi257Ho28rtLDYPhCLEKeIyEEGWePHsIPQFDI yqkUPajWNr1oYxq+OG7OltjoAK0sR6eFTjLPst6ilYwEFwaFzYt2O3JnO0ztZQPG7P7e 7Egg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702576886; x=1703181686; 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=5LL5XMoKKfyj4lF/ccY1D6SLjeOwyNN/EZbhZdDGiOM=; b=Xx4ctBwMiNRUiJ+7QDPZHZU9FUOL3oD7IXp4tRK+BNXIv1VhVeDyrGz6h3NeTkbRk+ hrE4bdtSZP+X9cm5XqEzwqNSKRbaF+sJSQ5NlsSwIX3+tRgGni3QDjenZ38Ho87U3e1/ SHvKZMMBoE18P7Dc8z21lAV/fj0E/OmRt4DwM36Ms+g1JQhnpPszdxK+wfzQO+cPPHVq RqQzeuNlVFEljgp4NjZYeza+lmynAIIQhU0VuD1D41vWlItkedrZWqzfOX5ERyug0eD4 0GPks2JFi8EoNoKzoy2BL0BrDENYLXwjdBsRd62LbP7IUm6XHW0cspbRS+nh1K6hh22d 6s7A== X-Gm-Message-State: AOJu0YwEKlXEbYRICr3dcxBp/GwNPB8hbWUYt5zi+VquTFu0ANY/ShrD hcHXKySQpcF7qbWpzYShaHvVNpaekog= X-Google-Smtp-Source: AGHT+IHt0LwcbXUGg/+ryL9m1mskrbj4I4Q4XC/fHREk8xrn4CaJ0Sd+qWsrlZHyBFNLDmXPOgIPWg== X-Received: by 2002:a05:622a:1001:b0:425:4043:189b with SMTP id d1-20020a05622a100100b004254043189bmr14896442qte.78.1702576886227; Thu, 14 Dec 2023 10:01:26 -0800 (PST) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id o8-20020ac85548000000b004257bf9a394sm5949511qtr.14.2023.12.14.10.01.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 10:01:25 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 2/5] knownnetworks: network: support updating known network settings Date: Thu, 14 Dec 2023 10:01:07 -0800 Message-Id: <20231214180110.130991-2-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231214180110.130991-1-prestwoj@gmail.com> References: <20231214180110.130991-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently if a known network is modified on disk the settings are not reloaded by network. Only disconnecting/reconnecting to the network would update the settings. This poses an issue to DPP since its creating or updating a known network after configuration then trying to connect. The connection itself works fine since the PSK/passphrase is set to the network object directly, but any additional settings are not updated. To fix this add a new UPDATED known network event. This is then handled from within network and all settings read from disk are applied to the network object. --- src/knownnetworks.c | 4 ++ src/knownnetworks.h | 1 + src/network.c | 104 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 106 insertions(+), 3 deletions(-) diff --git a/src/knownnetworks.c b/src/knownnetworks.c index d4d50a6f..04ce74ec 100644 --- a/src/knownnetworks.c +++ b/src/knownnetworks.c @@ -468,6 +468,10 @@ void known_network_update(struct network_info *network, known_network_set_autoconnect(network, new->is_autoconnectable); memcpy(&network->config, new, sizeof(struct network_config)); + + WATCHLIST_NOTIFY(&known_network_watches, + known_networks_watch_func_t, + KNOWN_NETWORKS_EVENT_UPDATED, network); } bool known_networks_foreach(known_networks_foreach_func_t function, diff --git a/src/knownnetworks.h b/src/knownnetworks.h index 0a5c9e25..e8ffac0b 100644 --- a/src/knownnetworks.h +++ b/src/knownnetworks.h @@ -35,6 +35,7 @@ struct network_info; enum known_networks_event { KNOWN_NETWORKS_EVENT_ADDED, KNOWN_NETWORKS_EVENT_REMOVED, + KNOWN_NETWORKS_EVENT_UPDATED, }; struct network_info_ops { diff --git a/src/network.c b/src/network.c index 41c5460b..bd3671ca 100644 --- a/src/network.c +++ b/src/network.c @@ -730,6 +730,73 @@ static void network_settings_save(struct network *network, network_settings_save_sae_pt_ecc(settings, network->sae_pt_20); } +static bool network_settings_update(struct network *network, + struct l_settings *new) +{ + bool have_transition_disable; + uint8_t transition_disable = 0; + unsigned int i; + size_t psk_len; + _auto_(l_strv_free) char **list = NULL; + _auto_(l_free) uint8_t *psk = NULL; + _auto_(l_free) char *passphrase = NULL; + + if (l_settings_get_bool(new, NET_TRANSITION_DISABLE, + &have_transition_disable) && + have_transition_disable) { + list = l_settings_get_string_list(new, + NET_TRANSITION_DISABLE_MODES, ' '); + + for (i = 0; list[i]; i++) { + if (!strcmp(list[i], "personal")) + set_bit(&transition_disable, 0); + else if (!strcmp(list[i], "enterprise")) + set_bit(&transition_disable, 1); + else if (!strcmp(list[i], "open")) + set_bit(&transition_disable, 2); + } + + have_transition_disable = true; + } else + have_transition_disable = false; + + if (network->security != SECURITY_PSK) + goto apply; + + psk = l_settings_get_bytes(network->settings, "Security", + "PreSharedKey", &psk_len); + if (psk && psk_len != 32) { + l_warn("updated [Security].PreSharedKey value is invalid!"); + return false; + } + + passphrase = l_settings_get_string(network->settings, + "Security", "Passphrase"); + if (passphrase && !crypto_passphrase_is_valid(passphrase)) { + l_warn("updated [Security].Passphrase value is invalid!"); + return false; + } + +apply: + network_settings_close(network); + network->settings = new; + + network->have_transition_disable = have_transition_disable; + network->transition_disable = transition_disable; + + if (psk) + network->psk = l_steal_ptr(psk); + + if (passphrase) { + network->passphrase = l_strdup(passphrase); + + network_settings_load_pt_ecc(network, 19, &network->sae_pt_19); + network_settings_load_pt_ecc(network, 20, &network->sae_pt_20); + } + + return true; +} + void network_sync_settings(struct network *network) { struct network_info *info = network->info; @@ -1966,17 +2033,32 @@ static void network_update_hotspot(struct network *network, void *user_data) match_hotspot_network(info, network); } -static void match_known_network(struct station *station, void *user_data) +static void match_known_network(struct station *station, void *user_data, + bool new) { struct network_info *info = user_data; struct network *network; if (!info->is_hotspot) { + struct l_settings *settings; network = station_network_find(station, info->ssid, info->type); if (!network) return; - network_set_info(network, info); + /* New networks should load settings upon connecting */ + if (new) { + network_set_info(network, info); + return; + } + + settings = network_info_open_settings(info); + + if (!settings || !network_settings_update(network, settings)) { + l_warn("Failed to apply new/updated settings (%s)", + info->ssid); + l_settings_free(settings); + } + return; } @@ -1984,17 +2066,33 @@ static void match_known_network(struct station *station, void *user_data) station_network_foreach(station, network_update_hotspot, info); } +static void add_known_network(struct station *station, void *user_data) +{ + match_known_network(station, (struct network_info *)user_data, true); +} + +static void update_known_network(struct station *station, void *user_data) +{ + match_known_network(station, (struct network_info *)user_data, false); +} + static void known_networks_changed(enum known_networks_event event, const struct network_info *info, void *user_data) { switch (event) { case KNOWN_NETWORKS_EVENT_ADDED: - station_foreach(match_known_network, (void *) info); + station_foreach(add_known_network, (void *) info); /* Syncs frequencies of newly known network */ known_network_frequency_sync((struct network_info *)info); break; + case KNOWN_NETWORKS_EVENT_UPDATED: + station_foreach(update_known_network, (void *) info); + + /* Syncs frequencies of updated known network */ + known_network_frequency_sync((struct network_info *)info); + break; case KNOWN_NETWORKS_EVENT_REMOVED: station_foreach(emit_known_network_removed, (void *) info); break; From patchwork Thu Dec 14 18:01:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13493499 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 E7BA567B73 for ; Thu, 14 Dec 2023 18:01:28 +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="NJSgR/ib" Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-425b9acaf80so43676141cf.1 for ; Thu, 14 Dec 2023 10:01:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702576887; x=1703181687; 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=4WpzSlrY5qeXOCQjJdkbcB9WN7UzeI/7Hp5DBbcaUCk=; b=NJSgR/ibUfoJ7x3T5wT6NZo9TD/0uDSI5rs+lCjQmVexyxD5i0A+fTHxXPVFLxZzj9 XI+CeJefL8rvNYJ2H7lMB+CORjXaniOnXohO1AsALaEfYROuMqPfTIKCL6qajAMs+RmP srXOQFzG/8gJHq4ZgYTmySd6xqZLcWsIM/HuZdZ8kA/yLDIngXiNP1ONq0erUZLRY3KY P1C147SQaEn6ErxVuFSKz9pI3L8T2zPkspmCA8UU8I4i0jevB2u0qpz6SUJLw6dBHImc ZLnad8qq6vPh+Cr8Fyuw7A38EvuLxp8HDI1LNbI5EHVcgI8BT1onO5rWQjTRAHBJSd6m Q/GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702576887; x=1703181687; 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=4WpzSlrY5qeXOCQjJdkbcB9WN7UzeI/7Hp5DBbcaUCk=; b=mbWGruXevYU3MmEY1UwELO5ucKrmUF5Ws/k11Z4ZmPmSCssbAKlsZzPSofyAjrSq/l 493+RMH6hxrhAGSWPJC8J0la8c2y3kLT7L4nYXuYp2eFMtG1+5abJKlKnzHRJx1HAVzI IKZfiLzfWmIkFKhv2omuFY6PQkc8+rHMClT0YyIbQ0coA2T0lTGknwbC0ewwiUpVni7B Iind0aAsdiZHZOvYLxU89Qr1tgDKKZxGwQJLuz4OigTLqO7Kav/4KA9I9ehwLMcsinh0 5jeKBJoqW4CgPZUXK8qyAwCyH7G2edDvyz/EbiKiTX/YuDHyeyCTeC5tbqrW3tDl4ulS PkYA== X-Gm-Message-State: AOJu0Yy0haquH0MN1IWc8VrljMMbRC3RmTr9oksBMIZ6JRP0vxQJpMDz ocVEPXT5O1AkbiTKLhiqmvM02vCvJuo= X-Google-Smtp-Source: AGHT+IFzC47Trm4tu/YHftVrMOPgq/gcNEcHfHzeRNG8DPEfwLbNSO619eHCJKdgfhNSaCJ7hwNoUA== X-Received: by 2002:a05:622a:16:b0:425:8663:a06d with SMTP id x22-20020a05622a001600b004258663a06dmr14931087qtw.64.1702576887426; Thu, 14 Dec 2023 10:01:27 -0800 (PST) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id o8-20020ac85548000000b004257bf9a394sm5949511qtr.14.2023.12.14.10.01.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 10:01:26 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 3/5] dpp: fix extra settings not being used when connecting Date: Thu, 14 Dec 2023 10:01:08 -0800 Message-Id: <20231214180110.130991-3-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231214180110.130991-1-prestwoj@gmail.com> References: <20231214180110.130991-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 After DPP completes all settings are written and synced to disk as well as credentials set into the network object itself. The way network/knownnetworks worked at the time did not actually re-load these settings before the connection attempt was made which means that extra settings not set into the network object were not used, i.e. Hidden/Sendhostname. The connection itself always succeeded because the network object was given the credentials directly via setters. Now network and knownnetworks support updating on the directory watch callback and ADDED/UPDATED known network events. Take advantage of this and if the network object already exists after DPP (from a prior scan) wait unil known networks adds/updates the network and issue the connection after that. --- src/dpp.c | 124 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 93 insertions(+), 31 deletions(-) diff --git a/src/dpp.c b/src/dpp.c index 1ff4b99e..dca40660 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 @@ -101,6 +102,7 @@ struct dpp_sm { uint8_t role; int refcount; uint32_t station_watch; + uint32_t known_network_watch; uint64_t wdev_id; @@ -168,6 +170,8 @@ struct dpp_sm { struct l_dbus_message *pending; + struct l_idle *connect_idle; + /* PKEX-specific values */ char *pkex_id; char *pkex_key; @@ -515,6 +519,11 @@ static void dpp_reset(struct dpp_sm *dpp) dpp->pkex_scan_id = 0; } + if (dpp->connect_idle) { + l_idle_remove(dpp->connect_idle); + dpp->connect_idle = NULL; + } + dpp->state = DPP_STATE_NOTHING; dpp->new_freq = 0; dpp->frame_retry = 0; @@ -570,6 +579,8 @@ static void dpp_free(struct dpp_sm *dpp) if (station) station_remove_state_watch(station, dpp->station_watch); + known_networks_watch_remove(dpp->known_network_watch); + l_free(dpp); } @@ -812,8 +823,6 @@ static void dpp_write_config(struct dpp_configuration *config, { _auto_(l_settings_free) struct l_settings *settings = l_settings_new(); _auto_(l_free) char *path; - _auto_(l_free) uint8_t *psk = NULL; - size_t psk_len; path = storage_get_network_file_path(SECURITY_PSK, config->ssid); @@ -822,22 +831,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); @@ -856,14 +856,39 @@ static void dpp_scan_triggered(int err, void *user_data) l_error("Failed to trigger DPP scan"); } +static void dpp_start_connect(struct l_idle *idle, void *user_data) +{ + struct dpp_sm *dpp = user_data; + struct station *station = station_find(netdev_get_ifindex(dpp->netdev)); + struct scan_bss *bss; + struct network *network; + int ret; + + network = station_network_find(station, dpp->config->ssid, + SECURITY_PSK); + + dpp_reset(dpp); + + if (!network) { + l_debug("Network was not found!"); + return; + } + + l_debug("connecting to %s from DPP", network_get_ssid(network)); + + bss = network_bss_select(network, true); + ret = network_autoconnect(network, bss); + if (ret < 0) + l_warn("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 +905,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_start_connect(NULL, dpp); return true; @@ -907,6 +921,51 @@ static void dpp_scan_destroy(void *userdata) dpp_reset(dpp); } +static void dpp_known_network_watch(enum known_networks_event event, + const struct network_info *info, + void *user_data) +{ + struct dpp_sm *dpp = user_data; + + /* + * Check the following + * - DPP is enrolling + * - DPP finished (dpp->config is set) + * - This is for the network DPP just configured + * - DPP isn't already trying to connect (e.g. if the profile was + * immediately modified after DPP synced it). + * - DPP didn't start a scan for the network. + */ + if (dpp->role != DPP_CAPABILITY_ENROLLEE) + return; + if (!dpp->config) + return; + if (strcmp(info->ssid, dpp->config->ssid)) + return; + if (dpp->connect_idle) + return; + if (dpp->connect_scan_id) + return; + + switch (event) { + case KNOWN_NETWORKS_EVENT_ADDED: + case KNOWN_NETWORKS_EVENT_UPDATED: + /* + * network.c takes care of updating the settings for the + * network. This callback just tells us to begin the connection. + * We do have use an idle here because there is no strict + * guarantee of ordering between known network events, e.g. DPP + * could have been called into prior to network and the network + * object isn't updated yet. + */ + dpp->connect_idle = l_idle_create(dpp_start_connect, dpp, NULL); + break; + case KNOWN_NETWORKS_EVENT_REMOVED: + l_warn("profile was removed before DPP could connect"); + break; + } +} + static void dpp_handle_config_response_frame(const struct mmpdu_header *frame, const void *body, size_t body_len, int rssi, void *user_data) @@ -1074,10 +1133,11 @@ 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); - else if (station) { + if (network && bss) { + l_debug("delaying connect until settings are synced"); + dpp->config = config; + return; + } else if (station) { struct scan_parameters params = {0}; params.ssid = (void *) config->ssid; @@ -3780,6 +3840,8 @@ static void dpp_create(struct netdev *netdev) dpp->station_watch = station_add_state_watch(station, dpp_station_state_watch, dpp, NULL); + dpp->known_network_watch = known_networks_watch_add( + dpp_known_network_watch, dpp, NULL); l_queue_push_tail(dpp_list, dpp); } From patchwork Thu Dec 14 18:01:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13493500 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) (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 08A8067E74 for ; Thu, 14 Dec 2023 18:01:29 +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="DkOQlq/c" Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-425ff068d02so5344981cf.1 for ; Thu, 14 Dec 2023 10:01:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702576889; x=1703181689; 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=Ik0TpLbzBGGyA9CN4Lx6Q7/i/gSeXuVLaDc4xi3xR0A=; b=DkOQlq/cb/efEz77357Z03NDDiZQqz+/J4PisS8UGrwm8OIzxE/VL/rG53X0XWnXrA 5b/PR2RulQkri39YCvr5xC/DwvbzeXoM75dqx9kJ/76flg22FP454qtxhzMhyk5elSt7 R2yk/e5Pq6FesvyrvHqI91KZnysYnlDELaCxbH7MEK98TSDq2pjEgZ96ytew17g0Ozk2 5QDcKgeMHVO+6K1dZDKgF1eksyK3mitRG8gy5PP4yEqLPcmfdojiI0SDKGcyHkcPz8my xf8jMHW0HDuzM3aXrx0RHDTWEnb3hHI6nhlGtF7NeEvyssRJn2P3z15UvR2hdfKwpO60 8TWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702576889; x=1703181689; 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=Ik0TpLbzBGGyA9CN4Lx6Q7/i/gSeXuVLaDc4xi3xR0A=; b=t/KpXABm2t+wDR/9wSyzt9HbI6sbwBbwpRsFBguekEU3nqiH0Hh/yknel8yZPYDsPo jkXu92rZWz/hrPEFJxs41tOZGbghwKNAcNPEIcARvuRZ3bCzx8vN0Cs3nGTglNX586j5 T61A5FGQDpNPQLkEELO8+zpRzfzBOfdhDF9YbQzvGj4VTN3P9x7K5xG0r4XAWq9wzGtX jTlPL3Mo6Mzp0bCxsK5p4Q3MezhDZY9C5v/FhHNaHjJ43xXrLLhNQ9Noy3DhLPJWzyfZ rfpViRYosrk59zJlBHQQmYZhGCvzeKgcY8wuXVIfm08YNL4vNQ9hpnFXqwgdv/g5c6Sq IWeA== X-Gm-Message-State: AOJu0YxycdG+pfj2hgCvAaHpgRr/oue4l1Kc+IK2NC0DUoguU4E40Wp4 wjFprbyEQFldJZ9ZE8suzT9KTMP3oiQ= X-Google-Smtp-Source: AGHT+IHhMMBL/GD4ZiyRMWMNy6ep/h5s41252p0aHC0sOT8H4Pr1HDRh60Lo5ULIpyxGXxO7IEL8Tw== X-Received: by 2002:a05:622a:148f:b0:425:4043:8d5a with SMTP id t15-20020a05622a148f00b0042540438d5amr9281404qtx.117.1702576888583; Thu, 14 Dec 2023 10:01:28 -0800 (PST) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id o8-20020ac85548000000b004257bf9a394sm5949511qtr.14.2023.12.14.10.01.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 10:01:28 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 4/5] auto-t: add DPP tests to check extra settings are applied Date: Thu, 14 Dec 2023 10:01:09 -0800 Message-Id: <20231214180110.130991-4-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231214180110.130991-1-prestwoj@gmail.com> References: <20231214180110.130991-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In order to test that extra settings are applied prior to connecting two tests were added for hidden networks as well as one testing if there is already an existing profile after DPP. The reason hidden networks were used was due to the requirement of the "Hidden" settings in the profile. If this setting doesn't get sync'ed to disk the connection will fail. --- autotests/testDPP/hw.conf | 5 ++- autotests/testDPP/pkex_test.py | 72 ++++++++++++++++++++++++++++++- autotests/testDPP/ssidHidden.conf | 9 ++++ autotests/testDPP/ssidHidden.psk | 5 +++ 4 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 autotests/testDPP/ssidHidden.conf create mode 100644 autotests/testDPP/ssidHidden.psk diff --git a/autotests/testDPP/hw.conf b/autotests/testDPP/hw.conf index a2b1470e..85f33777 100644 --- a/autotests/testDPP/hw.conf +++ b/autotests/testDPP/hw.conf @@ -1,5 +1,5 @@ [SETUP] -num_radios=4 +num_radios=5 start_iwd=0 hwsim_medium=yes @@ -8,6 +8,7 @@ rad0=wpas.conf [HOSTAPD] rad1=hostapd.conf +rad2=ssidHidden.conf [NameSpaces] -ns0=rad2 +ns0=rad3 diff --git a/autotests/testDPP/pkex_test.py b/autotests/testDPP/pkex_test.py index 9e0b5dd8..5df6c47d 100644 --- a/autotests/testDPP/pkex_test.py +++ b/autotests/testDPP/pkex_test.py @@ -26,11 +26,11 @@ class Test(unittest.TestCase): self.wpas.dpp_stop_listen() self.wpas.dpp_configurator_remove() - def start_iwd_pkex_configurator(self, device, agent=False): + def start_iwd_pkex_configurator(self, device, agent=False, profile='ssidCCMP.psk'): self.hapd.reload() self.hapd.wait_for_event('AP-ENABLED') - IWD.copy_to_storage('ssidCCMP.psk') + IWD.copy_to_storage(profile) device.autoconnect = True condition = 'obj.state == DeviceState.connected' @@ -186,6 +186,71 @@ class Test(unittest.TestCase): self.agent = None + def test_existing_network(self): + self.hapd.reload() + self.hapd.wait_for_event('AP-ENABLED') + IWD.copy_to_storage("existingProfile.psk", "/tmp/ns0/", "ssidCCMP.psk") + + # 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.start_iwd_pkex_configurator(self.device[0]) + + self.device[1].dpp_pkex_enroll('secret123', identifier="test") + self.device[1].autoconnect = True + + 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_hidden_network(self): + self.hapd_hidden.reload() + self.hapd_hidden.wait_for_event('AP-ENABLED') + IWD.copy_to_storage("existingProfile.psk", "/tmp/ns0/", "ssidHidden.psk") + + # 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.start_iwd_pkex_configurator(self.device[0], profile='ssidHidden.psk') + + self.device[1].dpp_pkex_enroll('secret123', identifier="test") + self.device[1].autoconnect = True + + 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/ssidHidden.psk', 'r') as f: + settings = f.read() + + self.assertIn("Hidden=true", settings) + + def test_hidden_network(self): + self.hapd_hidden.reload() + self.hapd_hidden.wait_for_event('AP-ENABLED') + self.start_iwd_pkex_configurator(self.device[0], profile='ssidHidden.psk') + + self.device[1].dpp_pkex_enroll('secret123', identifier="test") + self.device[1].autoconnect = True + + 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/ssidHidden.psk', 'r') as f: + settings = f.read() + + self.assertIn("Hidden=true", settings) + def setUp(self): ns0 = ctx.get_namespace('ns0') self.wpas = Wpas('wpas.conf') @@ -197,6 +262,8 @@ class Test(unittest.TestCase): self.device.append(self.wd_ns0.list_devices(1)[0]) self.hapd = HostapdCLI('hostapd.conf') self.hapd.disable() + self.hapd_hidden = HostapdCLI('ssidHidden.conf') + self.hapd_hidden.disable() self.hwsim = Hwsim() self.rule_xchg_resp = self.hwsim.rules.create() @@ -240,6 +307,7 @@ class Test(unittest.TestCase): self.hapd = None self.rule_xchg_resp = None IWD.clear_storage() + IWD.clear_storage('/tmp/ns0') @classmethod def setUpClass(cls): diff --git a/autotests/testDPP/ssidHidden.conf b/autotests/testDPP/ssidHidden.conf new file mode 100644 index 00000000..1055fb9c --- /dev/null +++ b/autotests/testDPP/ssidHidden.conf @@ -0,0 +1,9 @@ +hw_mode=g +channel=6 +ssid=ssidHidden + +wpa=1 +wpa_pairwise=TKIP +wpa_passphrase=secret123 + +ignore_broadcast_ssid=1 diff --git a/autotests/testDPP/ssidHidden.psk b/autotests/testDPP/ssidHidden.psk new file mode 100644 index 00000000..9917294e --- /dev/null +++ b/autotests/testDPP/ssidHidden.psk @@ -0,0 +1,5 @@ +[Security] +Passphrase=secret123 + +[Settings] +Hidden=true From patchwork Thu Dec 14 18:01:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13493501 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) (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 5C62567E79 for ; Thu, 14 Dec 2023 18:01:31 +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="WAtf5m+r" Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-425c6157762so35686741cf.2 for ; Thu, 14 Dec 2023 10:01:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702576890; x=1703181690; 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=17kjngjl4clw+g5Gdna9lJMGodPIyyvLG/4MzZRUlT8=; b=WAtf5m+rPWGi6LbikqpymVCYAGq5vITGvrqngGyp7FIfZEHqzMagh2zGjlEB89y5uX Tj6s8b9NLT7s4OcRVGkZVCYQmOrQ+1oQdxAl+T2am1VOCeuUB8XRvhMfUS+a6viXh8zX SxpEIPIg3iUxJNrF5qLTRRtyePljZqDtt35CmvkrFVP2NMWq90skZdM7XiiKtBC8cHDG d7K9mD0cVr283tJhK5ywQoxYoXwfOXSUr3qeHK0ycfqvPEJNa4q6X3YUutBP/4O2gA4F 7yPCmzyi0DMUrbBGWKHBX0H6jjJgmQ6a4ATw5cMO+FC5R44L2jhG6kwRAZdE2TPpZ8vn 1oPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702576890; x=1703181690; 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=17kjngjl4clw+g5Gdna9lJMGodPIyyvLG/4MzZRUlT8=; b=OW4jMoyDV8GaMceUZeZyWOHWQu42KWFBVyqK2R/mG1VxSPZj4xndqAOrNojGXIpKht PJ5S/FMAdNwHFCPRJ4CTq2b5OoofJDHlKKsw89a73rJsWbX6YIaq9rgRFd9RLYRqoEnC +79iFPsLWDhQaHfHq2p3b2plANhVcR8+GS1/I8dOb2eliklknwuvzP5n+81ulALi7mCD MHwGLK/1pULDwEyde7yigjT4cWiaYQkGrBPsdQsId0rmR5O6TrPC+c3M39OYZP3DFWJK 8S6dznXJrNgU3/hIVoJmOxlhvsybKRZXkq+2b3WSIWfYtNiyc4m14/lElRvnIuOJ3gq5 evFA== X-Gm-Message-State: AOJu0YwvT0mVb73nfs4B4wzAT/NqSJb8m8yKRuiDhUuEa+rF34p0h9aX izOSnNO6NEstzs4ul6m6u9uZSaTNrKU= X-Google-Smtp-Source: AGHT+IEEWNig1Oya+zwTU+UVTzrZPk3vh+oQQXt7hzgayHOwPXIr16K+Zljt407+sls0C66bCzChaw== X-Received: by 2002:a05:622a:1a16:b0:425:8f15:bccd with SMTP id f22-20020a05622a1a1600b004258f15bccdmr15844519qtb.89.1702576889817; Thu, 14 Dec 2023 10:01:29 -0800 (PST) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id o8-20020ac85548000000b004257bf9a394sm5949511qtr.14.2023.12.14.10.01.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 10:01:29 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 5/5] auto-t: increase RAM when running with valgrind (UML) Date: Thu, 14 Dec 2023 10:01:10 -0800 Message-Id: <20231214180110.130991-5-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231214180110.130991-1-prestwoj@gmail.com> References: <20231214180110.130991-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This was done for QEMU but not for UML. Running more than a few tests with --valgrind will generally thrown an OOM error pretty quick. --- tools/runner.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/runner.py b/tools/runner.py index 03f44611..e50ba9c0 100644 --- a/tools/runner.py +++ b/tools/runner.py @@ -552,7 +552,12 @@ class UmlRunner(RunnerAbstract): kern_log = "ignore_loglevel" if "kernel" in args.verbose else "quiet" - cmd = [args.kernel, 'rootfstype=hostfs', 'ro', 'mem=256M', 'mac80211_hwsim.radios=0', + if self.args.valgrind: + ram = 512 + else: + ram = 256 + + cmd = [args.kernel, 'rootfstype=hostfs', 'ro', f'mem={ram}M', 'mac80211_hwsim.radios=0', 'time-travel=inf-cpu', 'eth0=mcast', 'eth1=mcast', '%s' % kern_log, 'init=%s' % self.init] cmd.extend(args.to_cmd().split(' '))