From patchwork Fri Nov 10 14:16:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13452451 Received: from mail-oo1-f53.google.com (mail-oo1-f53.google.com [209.85.161.53]) (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 77B661B28E for ; Fri, 10 Nov 2023 14:16:25 +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="V9U3BBYH" Received: by mail-oo1-f53.google.com with SMTP id 006d021491bc7-5849fc56c62so1157759eaf.3 for ; Fri, 10 Nov 2023 06:16:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699625784; x=1700230584; 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=bW/vF11DaiBu7ZzBcky0tyeC7/56glDgVwk0J+pJFnM=; b=V9U3BBYHIehjZUGVx2DDjE/K31kXZIWrXA/06S6WGEzLgbo0KGXR+dd5rFPjKRLCk4 L+FiX+JbKur+j3v3oG84nVRtpK/Xceg9l7PRdf7sjIDK9P7PyX6c+HMGtSKRBhABYZsd tDt6iSzk+SsklVw4vqa0hnhcsx4FfUHm3vOn9eOuwwICMHAoi+4BIMP9D1uecW+PLWgx Z6wihGilHAAtP5HzS1vAxM2eaRgFKAUMQkhteJClkuHrjIoY6TBNLZGWR0Q+hhhjMDhP x/7jxalGJ+m7PQkeJUwVp10FSjDwMNVl86WfxSITdG4JVa1k4rNZtnlbARXl6d23Mns1 tCYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699625784; x=1700230584; 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=bW/vF11DaiBu7ZzBcky0tyeC7/56glDgVwk0J+pJFnM=; b=ryYb33gT1qMmEdSJ8mHZB82HKuXwS3YANjW1j9YstrnaOA0PePQRw2LxRPI6BVP8ah iJErH8lHJk1qHfQi/R6tCs15Sypj7ksyX5QPPXDRIQ+RQgeUTO2mPfxBM08fD5ZxuZi7 AJh+uZkTeiHF6+2uWykuZEsNXBf4dtmpBo+tSS4VNgng25vuADNVh06DXMplvyuc5JkL Q0mScbQL7S1CjKWFz5kgu0ps2iUQFrr65HQl1jO60CAybBaNTwla6puxjRa/LUTFRoik 4bwADureWPmUPdbEiaeHXWBRLmZM+OX3QOUhXoobZD/HKwgw1T+o0iwCiT4CIU6K3Qtu r+tg== X-Gm-Message-State: AOJu0Yx4LyI8fuK9yff7vu1w+D0kwPDFEU6vuFbm6KnT6Z/ZMi7x1vVZ +5o267O6a4olncB4aNXb9BbO9aU5YPQ= X-Google-Smtp-Source: AGHT+IErdVY3ft9sG83jYHnOTXDDmtSb/aFQ1mmT9mvd9pi0UDCzD7mhACLegGjRhnPoHI6cB1PHMA== X-Received: by 2002:a05:6358:3411:b0:169:8620:a228 with SMTP id h17-20020a056358341100b001698620a228mr8282511rwd.3.1699625784228; Fri, 10 Nov 2023 06:16:24 -0800 (PST) Received: from LOCLAP699.rst-02.locus (50-78-19-50-static.hfc.comcastbusiness.net. [50.78.19.50]) by smtp.gmail.com with ESMTPSA id c10-20020a05621401ea00b0065b11053445sm2958163qvu.54.2023.11.10.06.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Nov 2023 06:16:23 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 1/3] dpp: scan to pick up extra frequencies when enrolling Date: Fri, 10 Nov 2023 06:16:18 -0800 Message-Id: <20231110141620.80195-1-prestwoj@gmail.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The DPP-PKEX spec provides a very limited list of frequencies used to discover configurators, only 3 on 2.4 and 5GHz bands. Since configurators (at least in IWD's implementation) are only allowed on the current operating frequency its very unlikely an enrollee will find a configurator on these frequencies out of the entire spectrum. The spec does mention that the 3 default frequencies should be used "In lieu of specific channel information obtained in a manner outside the scope of this specification, ...". This allows the implementation some flexibility in using a broader range of frequencies. To increase the chances of finding a configurator shared code enrollees will first issue a scan to determine what access points are around, then iterate these frequencies. This is especially helpful when the configurators are IWD-based since we know that they'll be on the same channels as the APs in the area. --- src/dpp.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 88 insertions(+), 10 deletions(-) v2: * Removed user-option, scan by default * Fixed potential NULL return from dpp_default_freqs diff --git a/src/dpp.c b/src/dpp.c index c54bd484..daa49410 100644 --- a/src/dpp.c +++ b/src/dpp.c @@ -182,6 +182,7 @@ struct dpp_sm { size_t z_len; uint8_t u[L_ECC_SCALAR_MAX_BYTES]; size_t u_len; + uint32_t pkex_scan_id; bool mcast_support : 1; bool roc_started : 1; @@ -507,6 +508,11 @@ static void dpp_reset(struct dpp_sm *dpp) dpp->retry_timeout = NULL; } + if (dpp->pkex_scan_id) { + scan_cancel(dpp->wdev_id, dpp->pkex_scan_id); + dpp->pkex_scan_id = 0; + } + dpp->state = DPP_STATE_NOTHING; dpp->new_freq = 0; dpp->frame_retry = 0; @@ -3956,6 +3962,14 @@ static struct l_dbus_message *dpp_dbus_stop(struct l_dbus *dbus, return l_dbus_message_new_method_return(message); } +static void dpp_pkex_scan_trigger(int err, void *user_data) +{ + struct dpp_sm *dpp = user_data; + + if (err < 0) + dpp_reset(dpp); +} + /* * Section 5.6.1 * In lieu of specific channel information obtained in a manner outside @@ -3994,6 +4008,62 @@ static uint32_t *dpp_default_freqs(struct dpp_sm *dpp, size_t *out_len) return freqs_out; } +static bool dpp_pkex_scan_notify(int err, struct l_queue *bss_list, + const struct scan_freq_set *freqs, + void *user_data) +{ + struct dpp_sm *dpp = user_data; + const struct l_queue_entry *e; + _auto_(scan_freq_set_free) struct scan_freq_set *freq_set = NULL; + + if (err < 0) + goto failed; + + freq_set = scan_freq_set_new(); + + if (!bss_list || l_queue_isempty(bss_list)) { + dpp->freqs = dpp_default_freqs(dpp, &dpp->freqs_len); + if (!dpp->freqs) + goto failed; + + l_debug("No BSS's seen, using default frequency list"); + goto start; + } + + for (e = l_queue_get_entries(bss_list); e; e = e->next) { + const struct scan_bss *bss = e->data; + + scan_freq_set_add(freq_set, bss->frequency); + } + + l_debug("Found %u frequencies to search for configurator", + l_queue_length(bss_list)); + + dpp->freqs = scan_freq_set_to_fixed_array(freq_set, &dpp->freqs_len); + +start: + dpp->current_freq = dpp->freqs[0]; + + dpp_reset_protocol_timer(dpp, DPP_PKEX_PROTO_TIMEOUT); + + l_debug("PKEX start enrollee (id=%s)", dpp->pkex_id ?: "unset"); + + dpp_start_offchannel(dpp, dpp->current_freq); + + return false; + +failed: + dpp_reset(dpp); + return false; +} + +static void dpp_pkex_scan_destroy(void *user_data) +{ + struct dpp_sm *dpp = user_data; + + dpp->pkex_scan_id = 0; +} + static bool dpp_start_pkex_enrollee(struct dpp_sm *dpp, const char *key, const char *identifier) { @@ -4045,17 +4115,25 @@ static bool dpp_start_pkex_enrollee(struct dpp_sm *dpp, const char *key, dpp_property_changed_notify(dpp); - dpp->freqs = dpp_default_freqs(dpp, &dpp->freqs_len); - if (!dpp->freqs) - goto failed; - - dpp->current_freq = dpp->freqs[dpp->freqs_idx]; - - dpp_reset_protocol_timer(dpp, DPP_PKEX_PROTO_TIMEOUT); - - l_debug("PKEX start enrollee (id=%s)", dpp->pkex_id ?: "unset"); + /* + * The 'dpp_default_freqs' function returns the default frequencies + * outlined in section 5.6.1. For 2.4/5GHz this is only 3 frequencies + * which is unlikely to result in discovery of a configurator. The spec + * does allow frequencies to be "obtained in a manner outside the scope + * of this specification" which is what is being done here. + * + * This is mainly geared towards IWD-based configurators; banking on the + * fact that they are currently connected to nearby APs. Scanning lets + * us see nearby BSS's which should be the same frequencies as our + * target configurator. + */ + l_debug("Performing scan for frequencies to start PKEX"); - dpp_start_offchannel(dpp, dpp->current_freq); + dpp->pkex_scan_id = scan_active(dpp->wdev_id, NULL, 0, + dpp_pkex_scan_trigger, dpp_pkex_scan_notify, + dpp, dpp_pkex_scan_destroy); + if (!dpp->pkex_scan_id) + goto failed; return true; From patchwork Fri Nov 10 14:16:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13452452 Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) (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 9C17B1B294 for ; Fri, 10 Nov 2023 14:16: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="W3w62pOE" Received: by mail-ot1-f41.google.com with SMTP id 46e09a7af769-6d261cb07dcso1224569a34.3 for ; Fri, 10 Nov 2023 06:16:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699625785; x=1700230585; 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=ZIf4pwUkqQB6aGyGNSu0M2ER8NCbxYZBJPAIrpW44TQ=; b=W3w62pOEiO9QsOcY/RmmhfMhlM+PsRkI9riv9W0GBgm9NbqkSQRLgq4HQpKBFJL6MU 8C1xVczgneGKo75geVnBWxw74wtOMi8OsM70SbTkyNVmBwpZl4OwEF8i22/WLtTwdtAf 7lhscLFwkshd/saxEobMzVnIR8SvHtQf0BLoNuB+hRB9cSRCIc656WFNf1tdAbkK4kzk 70bTbZxDCnbamqm5vBneGLvxheK0DgfdbiHa7fvt8muhnli0rtCnrXrRp/LV0+0b4P87 hjsxeF/aMkqlN7l6ilkB8us01Ug6iN5yWNI3itrNVLUTlUwfmSvF91RPuHgowxasdMbx lMLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699625785; x=1700230585; 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=ZIf4pwUkqQB6aGyGNSu0M2ER8NCbxYZBJPAIrpW44TQ=; b=vS7/4C0PiVjmpaZp/nwfKZFGIopfSP/iEK47fpWzvLDL8ttXLr9dk8eAzP/jTA4xKw 0hAmEGpayaf9E7j8cWREL2NSaflTXJVtrhJbUGYBQkH6i78Ru8j30g6B/pZeA/uCVxZZ 8AQ1XPO52ZUjE2ZHZgloZ828xb9/b7rdZJlfHm1w3sOFjXV0mjtAlY/03sQtV8Xk8MyM J/2Ee3GUQyXNMz3L1PVV/aqeMFAsK9BoL38Zby2N8HBDvIhxeKNp/9oqIKQV9z2L652S tRDuuwDhoPB+csiR3qpsxYIuXrMF4+rE5NuFtXoF+l4T/QLnLwRH72DikQWfww+/Xyhp 7Kpw== X-Gm-Message-State: AOJu0Yx8geSFroBVSdpy7Gs82Ug1f3vlvtkYTJFanOuS3Yk4JhvWp+AO TBXTS5TQlfzKmxzEATwG3WQqr4f960Q= X-Google-Smtp-Source: AGHT+IG03RYcZ4ssmKO8OrWrq+iNVoRIxjXdqGoPNkjnezc1PeKmFTBJR/5EhbIHAZLfLfKr58OMkw== X-Received: by 2002:a05:6830:145a:b0:6d6:4e2b:7e47 with SMTP id w26-20020a056830145a00b006d64e2b7e47mr411643otp.17.1699625785407; Fri, 10 Nov 2023 06:16:25 -0800 (PST) Received: from LOCLAP699.rst-02.locus (50-78-19-50-static.hfc.comcastbusiness.net. [50.78.19.50]) by smtp.gmail.com with ESMTPSA id c10-20020a05621401ea00b0065b11053445sm2958163qvu.54.2023.11.10.06.16.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Nov 2023 06:16:25 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 2/3] dpp: make station connected check better, remove duplicate Date: Fri, 10 Nov 2023 06:16:19 -0800 Message-Id: <20231110141620.80195-2-prestwoj@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231110141620.80195-1-prestwoj@gmail.com> References: <20231110141620.80195-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Checking if station has a connected network set was fine, but checking the state is more clear/explicit. This also removes a duplicate check. --- src/dpp.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/dpp.c b/src/dpp.c index daa49410..f1ea01ff 100644 --- a/src/dpp.c +++ b/src/dpp.c @@ -4067,14 +4067,8 @@ static void dpp_pkex_scan_destroy(void *user_data) static bool dpp_start_pkex_enrollee(struct dpp_sm *dpp, const char *key, const char *identifier) { - struct station *station = station_find(netdev_get_ifindex(dpp->netdev)); _auto_(l_ecc_point_free) struct l_ecc_point *qi = NULL; - if (station && station_get_connected_network(station)) { - l_debug("Already connected, disconnect before enrolling"); - return false; - } - if (identifier) dpp->pkex_id = l_strdup(identifier); @@ -4194,7 +4188,7 @@ static struct l_dbus_message *dpp_dbus_pkex_start_enrollee(struct l_dbus *dbus, dpp->interface != DPP_INTERFACE_UNBOUND) return dbus_error_busy(message); - if (station_get_connected_network(station)) + if (station && station_get_state(station) != STATION_STATE_DISCONNECTED) return dbus_error_busy(message); if (!dpp_parse_pkex_args(message, &key, &id)) From patchwork Fri Nov 10 14:16:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13452453 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (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 BB4BE1B28E for ; Fri, 10 Nov 2023 14:16: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="X75zt5+u" Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-6ce2de8da87so1164548a34.1 for ; Fri, 10 Nov 2023 06:16:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699625786; x=1700230586; 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=ekbDauHIj4jrXFThCUA2Z01UjDfb9nb9MmkrcEPbhJ4=; b=X75zt5+uUdMYI23d6xohA15/fKUdyf7BUXGGo+hbQ9/slTUzgr1WamlujMnF3BVcUN UB0g7FOsp6AievB0e2RB2n2brY3ZdQWxrbKkW8IYDz0/C4MYzz5tHEnlk5RUwLAF9HTQ aLzMlGoAtLGB2TcmJ6cNDL7irIofwasqMWOC6l7cjzaLanEuFztl5An2EIJTndMvC9Sn pR4etS46JjduMFEA8kvY7+ytQlskMMfX9orqSPZEyIudg3j+RZbtUOKqJefasulvKh+a nmSI4HlqPymfWvaEKKMe0OojTQ1O5U8FMbx7Mjh7JMtTzUreoTYloB6D930golAgJdMQ Bm+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699625786; x=1700230586; 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=ekbDauHIj4jrXFThCUA2Z01UjDfb9nb9MmkrcEPbhJ4=; b=QTcJ0fp3rJPPc3Oqot/HhjUdkoceoa5OrK2gJklBc0IU5y83OxpFNdmxZBGBVzTzYN HOp6UVb/AXRE3TdnF3S4m6KrSvwjH4EJ9uqtuC8rEXb2Q+9zSbkfOcJIjp5k3ISj3WUn iIAHt4xDTa90K9w4qP22v6X+9m/QZ4iWbwAn0UnIMdDcTmOtId3JR4obgDq110aJMzqv RlKAbhHx0+4aJeWWgxMKa4NrLbapsPMd9Bdis6rHJIfJH16+BaGwgcjq/EUR/kr0z9w5 7S7mNMnXAVz6uqEKA1+P0RdZOUGyUG4SeLikoiQUGM6UDGgxh3kBy0d4n5aNafAa5dXW HHEg== X-Gm-Message-State: AOJu0YxYIqA7wEHtL3v2zie0nubcMNs7vVp74Cx5jZWsUzyGyalRaWp+ b/0esaAJ0OAwkLY4/5HcQOJWg0L6bZQ= X-Google-Smtp-Source: AGHT+IFS/L5faz3uCI9xKyIG1NYL6HcX5C8OC1AjoHlW4Z6UGQStZUWEZ8kGP4lAF2WDHUeRs7B9CQ== X-Received: by 2002:a9d:6d08:0:b0:6d6:471e:1eda with SMTP id o8-20020a9d6d08000000b006d6471e1edamr1759672otp.4.1699625786519; Fri, 10 Nov 2023 06:16:26 -0800 (PST) Received: from LOCLAP699.rst-02.locus (50-78-19-50-static.hfc.comcastbusiness.net. [50.78.19.50]) by smtp.gmail.com with ESMTPSA id c10-20020a05621401ea00b0065b11053445sm2958163qvu.54.2023.11.10.06.16.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Nov 2023 06:16:26 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 3/3] dpp: add station watch to DPP Date: Fri, 10 Nov 2023 06:16:20 -0800 Message-Id: <20231110141620.80195-3-prestwoj@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231110141620.80195-1-prestwoj@gmail.com> References: <20231110141620.80195-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DPP (both DPP and PKEX) run the risk of odd behavior if station decides to change state. DPP is completely unaware of this and best case would just result in a protocol failure, worst case duplicate calls to __station_connect_network. Add a station watch and stop DPP if station changes state during the protocol. --- src/dpp.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/dpp.c b/src/dpp.c index f1ea01ff..46330c08 100644 --- a/src/dpp.c +++ b/src/dpp.c @@ -100,6 +100,7 @@ struct dpp_sm { char *uri; uint8_t role; int refcount; + uint32_t station_watch; uint64_t wdev_id; @@ -542,6 +543,8 @@ static void dpp_reset(struct dpp_sm *dpp) static void dpp_free(struct dpp_sm *dpp) { + struct station *station = station_find(netdev_get_ifindex(dpp->netdev)); + dpp_reset(dpp); if (dpp->own_asn1) { @@ -559,6 +562,13 @@ static void dpp_free(struct dpp_sm *dpp) dpp->boot_private = NULL; } + /* + * Since this is called when the netdev goes down, station may already + * be gone in which case the state watch will automatically go away. + */ + if (station) + station_remove_state_watch(station, dpp->station_watch); + l_free(dpp); } @@ -3614,6 +3624,55 @@ static void dpp_frame_watch(struct dpp_sm *dpp, uint16_t frame_type, L_UINT_TO_PTR(frame_type), NULL); } +/* + * Station is unaware of DPP's state so we need to handle a few cases here so + * weird stuff doesn't happen: + * + * - While configuring we should stay connected, a disconnection/roam should + * stop DPP since it would fail regardless due to the hardware going idle + * or changing channels since configurators assume all comms will be + * on-channel. + * - While enrolling we should stay disconnected. If station connects during + * enrolling it would cause 2x calls to __station_connect_network after + * DPP finishes. + * + * Other conditions shouldn't ever happen i.e. configuring and going into a + * connecting state or enrolling and going to a disconnected/roaming state. + */ +static void dpp_station_state_watch(enum station_state state, void *user_data) +{ + struct dpp_sm *dpp = user_data; + + switch (state) { + case STATION_STATE_DISCONNECTED: + case STATION_STATE_DISCONNECTING: + case STATION_STATE_ROAMING: + case STATION_STATE_FT_ROAMING: + case STATION_STATE_FW_ROAMING: + L_WARN_ON(dpp->role == DPP_CAPABILITY_ENROLLEE); + + if (dpp->role == DPP_CAPABILITY_CONFIGURATOR) { + l_debug("Disconnected while configuring, stopping DPP"); + dpp_reset(dpp); + } + + break; + case STATION_STATE_CONNECTING: + case STATION_STATE_CONNECTED: + case STATION_STATE_CONNECTING_AUTO: + case STATION_STATE_AUTOCONNECT_FULL: + case STATION_STATE_AUTOCONNECT_QUICK: + L_WARN_ON(dpp->role == DPP_CAPABILITY_CONFIGURATOR); + + if (dpp->role == DPP_CAPABILITY_ENROLLEE) { + l_debug("Connecting while enrolling, stopping DPP"); + dpp_reset(dpp); + } + + break; + } +} + static void dpp_create(struct netdev *netdev) { struct l_dbus *dbus = dbus_get_bus(); @@ -3621,6 +3680,7 @@ static void dpp_create(struct netdev *netdev) uint8_t dpp_conf_response_prefix[] = { 0x04, 0x0b }; uint8_t dpp_conf_request_prefix[] = { 0x04, 0x0a }; uint64_t wdev_id = netdev_get_wdev_id(netdev); + struct station *station = station_find(netdev_get_ifindex(netdev)); dpp->netdev = netdev; dpp->state = DPP_STATE_NOTHING; @@ -3666,6 +3726,9 @@ static void dpp_create(struct netdev *netdev) sizeof(dpp_conf_request_prefix), dpp_handle_config_request_frame, dpp, NULL); + dpp->station_watch = station_add_state_watch(station, + dpp_station_state_watch, dpp, NULL); + l_queue_push_tail(dpp_list, dpp); }