diff mbox series

[03/11] network: retain default ECC group for OWE after setting

Message ID 20240227183405.257206-3-prestwoj@gmail.com (mailing list archive)
State New
Headers show
Series [01/11] doc: Document UseDefaultEccGroup | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-ci-gitlint success GitLint

Commit Message

James Prestwood Feb. 27, 2024, 6:33 p.m. UTC
There is special handling for buggy OWE APs which set a network flag
to use the default OWE group. Utilize the more persistent setting
within known-networks as well as the network object (in case there
is no profile).

This also renames the get/set APIs to be generic to ECC groups rather
than only OWE.
---
 src/network.c | 38 +++++++++++++++++++++++++++++++-------
 src/network.h |  4 ++--
 src/station.c |  4 ++--
 3 files changed, 35 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/src/network.c b/src/network.c
index 287e2be0..a0a89e63 100644
--- a/src/network.c
+++ b/src/network.c
@@ -89,7 +89,7 @@  struct network {
 	bool provisioning_hidden:1;
 	uint8_t transition_disable; /* Temporary cache until info is set */
 	bool have_transition_disable:1;
-	bool force_default_owe_group:1;
+	bool force_default_ecc_group:1;
 	int rank;
 	/* Holds DBus Connect() message if it comes in before ANQP finishes */
 	struct l_dbus_message *connect_after_anqp;
@@ -271,8 +271,12 @@  struct network *network_create(struct station *station, const char *ssid,
 	network->security = security;
 
 	network->info = known_networks_find(ssid, security);
-	if (network->info)
+	if (network->info) {
 		network->info->seen_count++;
+		if (network->info->config.ecc_group ==
+						KNOWN_NETWORK_ECC_GROUP_DEFAULT)
+			network->force_default_ecc_group = true;
+	}
 
 	network->bss_list = l_queue_new();
 	network->blacklist = l_queue_new();
@@ -553,7 +557,7 @@  int network_handshake_setup(struct network *network, struct scan_bss *bss,
 	}
 
 	if (hs->akm_suite == IE_RSN_AKM_SUITE_OWE)
-		hs->force_default_owe_group = network->force_default_owe_group;
+		hs->force_default_owe_group = network->force_default_ecc_group;
 
 	/*
 	 * The randomization options in the provisioning file are dependent on
@@ -818,14 +822,34 @@  void network_set_info(struct network *network, struct network_info *info)
 					IWD_NETWORK_INTERFACE, "KnownNetwork");
 }
 
-void network_set_force_default_owe_group(struct network *network)
+void network_set_force_default_ecc_group(struct network *network)
 {
-	network->force_default_owe_group = true;
+	/* No network info, likely a failed OWE connection */
+	if (!network->info) {
+		network->force_default_ecc_group = true;
+		return;
+	}
+
+	/* Profile explicitly wants to try the most secure group */
+	if (network->info->config.ecc_group ==
+					KNOWN_NETWORK_ECC_GROUP_MOST_SECURE)
+		return;
+
+	l_debug("Forcing default group for %s", network->ssid);
+
+	network->force_default_ecc_group = true;
+	network->info->config.ecc_group = KNOWN_NETWORK_ECC_GROUP_DEFAULT;
 }
 
-bool network_get_force_default_owe_group(struct network *network)
+bool network_get_force_default_ecc_group(struct network *network)
 {
-	return network->force_default_owe_group;
+	if (!network->info)
+		return network->force_default_ecc_group;
+
+	if (network->info->config.ecc_group == KNOWN_NETWORK_ECC_GROUP_DEFAULT)
+		return true;
+
+	return false;
 }
 
 int network_can_connect_bss(struct network *network, const struct scan_bss *bss)
diff --git a/src/network.h b/src/network.h
index ea619f3f..17dfcca8 100644
--- a/src/network.h
+++ b/src/network.h
@@ -58,8 +58,8 @@  void network_sync_settings(struct network *network);
 
 const struct network_info *network_get_info(const struct network *network);
 void network_set_info(struct network *network, struct network_info *info);
-void network_set_force_default_owe_group(struct network *network);
-bool network_get_force_default_owe_group(struct network *network);
+void network_set_force_default_ecc_group(struct network *network);
+bool network_get_force_default_ecc_group(struct network *network);
 
 bool network_update_known_frequencies(struct network *network);
 
diff --git a/src/station.c b/src/station.c
index 8817637b..3712d5bb 100644
--- a/src/station.c
+++ b/src/station.c
@@ -3152,7 +3152,7 @@  static bool station_retry_owe_default_group(struct station *station)
 		return false;
 
 	/* If we already forced group 19, allow the BSS to be blacklisted */
-	if (network_get_force_default_owe_group(station->connected_network))
+	if (network_get_force_default_ecc_group(station->connected_network))
 		return false;
 
 	l_warn("Failed to connect to OWE BSS "MAC" possibly because the AP is "
@@ -3160,7 +3160,7 @@  static bool station_retry_owe_default_group(struct station *station)
 		"Retrying with group 19 as a workaround",
 		MAC_STR(station->connected_bss->addr));
 
-	network_set_force_default_owe_group(station->connected_network);
+	network_set_force_default_ecc_group(station->connected_network);
 
 	return true;
 }