public inbox for iwd@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH v2 1/3] dpp-util: store SSID as string, not raw buffer
@ 2023-11-16 18:44 James Prestwood
  2023-11-16 18:44 ` [PATCH v2 2/3] dpp: use the new config->ssid member James Prestwood
  2023-11-16 18:44 ` [PATCH v2 3/3] dpp: use the config's SSID to process scan results James Prestwood
  0 siblings, 2 replies; 3+ messages in thread
From: James Prestwood @ 2023-11-16 18:44 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

Nearly every use of the ssid member first has to memcpy it to a
buffer and NULL terminate. Instead just store the ssid as a
string when creating/parsing from JSON.
---
 src/dpp-util.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/dpp-util.h b/src/dpp-util.h
index b5fc029c..222ba053 100644
--- a/src/dpp-util.h
+++ b/src/dpp-util.h
@@ -112,7 +112,7 @@ enum dpp_attribute_type {
 };
 
 struct dpp_configuration {
-	uint8_t ssid[32];
+	char ssid[33];
 	size_t ssid_len;
 	uint32_t akm_suites;
 	char *passphrase;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2 2/3] dpp: use the new config->ssid member
  2023-11-16 18:44 [PATCH v2 1/3] dpp-util: store SSID as string, not raw buffer James Prestwood
@ 2023-11-16 18:44 ` James Prestwood
  2023-11-16 18:44 ` [PATCH v2 3/3] dpp: use the config's SSID to process scan results James Prestwood
  1 sibling, 0 replies; 3+ messages in thread
From: James Prestwood @ 2023-11-16 18:44 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

This is now a NULL terminated string so it can be used directly.
---
 src/dpp.c | 31 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 19 deletions(-)

diff --git a/src/dpp.c b/src/dpp.c
index 18b2a7c6..b1f9c5ac 100644
--- a/src/dpp.c
+++ b/src/dpp.c
@@ -809,7 +809,6 @@ static void send_config_result(struct dpp_sm *dpp, const uint8_t *to)
 static void dpp_write_config(struct dpp_configuration *config,
 				struct network *network)
 {
-	char ssid[33];
 	_auto_(l_settings_free) struct l_settings *settings = NULL;
 	_auto_(l_free) char *path;
 	_auto_(l_free) uint8_t *psk = NULL;
@@ -820,10 +819,7 @@ static void dpp_write_config(struct dpp_configuration *config,
 	else
 		settings = l_settings_new();
 
-	memcpy(ssid, config->ssid, config->ssid_len);
-	ssid[config->ssid_len] = '\0';
-
-	path = storage_get_network_file_path(SECURITY_PSK, ssid);
+	path = storage_get_network_file_path(SECURITY_PSK, config->ssid);
 
 	if (l_settings_load_from_file(settings, path)) {
 		/* Remove any existing Security keys */
@@ -846,9 +842,9 @@ static void dpp_write_config(struct dpp_configuration *config,
 			network_set_psk(network, psk);
 	}
 
-	l_debug("Storing credential for '%s(%s)'", ssid,
+	l_debug("Storing credential for '%s(%s)'", config->ssid,
 						security_to_str(SECURITY_PSK));
-	storage_network_sync(SECURITY_PSK, ssid, settings);
+	storage_network_sync(SECURITY_PSK, config->ssid, settings);
 }
 
 static void dpp_scan_triggered(int err, void *user_data)
@@ -937,8 +933,6 @@ static void dpp_handle_config_response_frame(const struct mmpdu_header *frame,
 	struct station *station = station_find(netdev_get_ifindex(dpp->netdev));
 	struct network *network = NULL;
 	struct scan_bss *bss = NULL;
-	char ssid[33];
-	size_t ssid_len;
 
 	if (dpp->state != DPP_STATE_CONFIGURING)
 		return;
@@ -1067,17 +1061,13 @@ static void dpp_handle_config_response_frame(const struct mmpdu_header *frame,
 	 * credentials out and be done
 	 */
 	if (station) {
-		memcpy(ssid, config->ssid, config->ssid_len);
-		ssid_len = config->ssid_len;
-		ssid[config->ssid_len] = '\0';
-
-		network = station_network_find(station, ssid, SECURITY_PSK);
+		network = station_network_find(station, config->ssid,
+						SECURITY_PSK);
 		if (network)
 			bss = network_bss_select(network, true);
 	}
 
 	dpp_write_config(config, network);
-	dpp_configuration_free(config);
 
 	send_config_result(dpp, dpp->peer_addr);
 
@@ -1089,19 +1079,22 @@ static void dpp_handle_config_response_frame(const struct mmpdu_header *frame,
 	else if (station) {
 		struct scan_parameters params = {0};
 
-		params.ssid = (void *) ssid;
-		params.ssid_len = ssid_len;
+		params.ssid = (void *) config->ssid;
+		params.ssid_len = config->ssid_len;
 
-		l_debug("Scanning for %s", ssid);
+		l_debug("Scanning for %s", config->ssid);
 
 		dpp->connect_scan_id = scan_active_full(dpp->wdev_id, &params,
 						dpp_scan_triggered,
 						dpp_scan_results, dpp,
 						dpp_scan_destroy);
-		if (dpp->connect_scan_id)
+		if (dpp->connect_scan_id) {
+			dpp_configuration_free(config);
 			return;
+		}
 	}
 
+	dpp_configuration_free(config);
 	dpp_reset(dpp);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2 3/3] dpp: use the config's SSID to process scan results
  2023-11-16 18:44 [PATCH v2 1/3] dpp-util: store SSID as string, not raw buffer James Prestwood
  2023-11-16 18:44 ` [PATCH v2 2/3] dpp: use the new config->ssid member James Prestwood
@ 2023-11-16 18:44 ` James Prestwood
  1 sibling, 0 replies; 3+ messages in thread
From: James Prestwood @ 2023-11-16 18:44 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

The scan result handling was fragile because it assumed the kernel
would only give results matching the requested SSID. This isn't
something we should assume so instead keep the configuration object
around until after the scan and use the target SSID to lookup the
network.
---
 src/dpp.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/dpp.c b/src/dpp.c
index b1f9c5ac..fab114ad 100644
--- a/src/dpp.c
+++ b/src/dpp.c
@@ -861,7 +861,6 @@ static bool dpp_scan_results(int err, struct l_queue *bss_list,
 	struct dpp_sm *dpp = userdata;
 	struct station *station = station_find(netdev_get_ifindex(dpp->netdev));
 	struct scan_bss *bss;
-	char ssid[33];
 	struct network *network;
 
 	if (err < 0)
@@ -877,18 +876,18 @@ static bool dpp_scan_results(int err, struct l_queue *bss_list,
 	if (L_WARN_ON(station_get_connected_network(station)))
 		goto reset;
 
-	/* Purely for grabbing the SSID */
-	bss = l_queue_peek_head(bss_list);
-
-	memcpy(ssid, bss->ssid, bss->ssid_len);
-	ssid[bss->ssid_len] = '\0';
-
 	station_set_scan_results(station, bss_list, freqs, false);
 
-	network = station_network_find(station, ssid, SECURITY_PSK);
+	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);
 
@@ -1089,7 +1088,7 @@ static void dpp_handle_config_response_frame(const struct mmpdu_header *frame,
 						dpp_scan_results, dpp,
 						dpp_scan_destroy);
 		if (dpp->connect_scan_id) {
-			dpp_configuration_free(config);
+			dpp->config = config;
 			return;
 		}
 	}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-11-16 18:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-16 18:44 [PATCH v2 1/3] dpp-util: store SSID as string, not raw buffer James Prestwood
2023-11-16 18:44 ` [PATCH v2 2/3] dpp: use the new config->ssid member James Prestwood
2023-11-16 18:44 ` [PATCH v2 3/3] dpp: use the config's SSID to process scan results James Prestwood

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox