Skip to contentSkip to conversation

wiphy: add offload out parameter to wiphy_can_connect_sae

PATCH Superseded James Prestwood 1 participant 7 messages Mar 30, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 wiphy: add offload out parameter to wiphy_can_connect_sae

This will be set if the SAE connection requires offloading to work.

---
 src/wiphy.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
src/wiphy.c +12 -5
index 676f236c..35872577 100644
@@ -126,7 +126,7 @@ enum ie_rsn_cipher_suite wiphy_select_cipher(struct wiphy *wiphy, uint16_t mask)
 	return 0;
 }
 
-static bool wiphy_can_connect_sae(struct wiphy *wiphy)
+static bool wiphy_can_connect_sae(struct wiphy *wiphy, bool *offload)
 {
 	/*
 	 * SAE support in the kernel is a complete mess in that there are 3
@@ -153,8 +153,11 @@ static bool wiphy_can_connect_sae(struct wiphy *wiphy)
 
 	if (wiphy_has_feature(wiphy, NL80211_FEATURE_SAE)) {
 		/* Case (1) */
-		if (wiphy->support_cmds_auth_assoc)
+		if (wiphy->support_cmds_auth_assoc) {
+			if (offload)
+				*offload = false;
 			return true;
+		}
 
 		/*
 		 * Case (3)
@@ -165,8 +168,12 @@ static bool wiphy_can_connect_sae(struct wiphy *wiphy)
 	} else {
 		/* Case (2) */
 		if (wiphy_has_ext_feature(wiphy,
-					NL80211_EXT_FEATURE_SAE_OFFLOAD))
+					NL80211_EXT_FEATURE_SAE_OFFLOAD)) {
+			if (offload)
+				*offload = true;
+
 			return true;
+		}
 
 		return false;
 	}
@@ -234,7 +241,7 @@ enum ie_rsn_akm_suite wiphy_select_akm(struct wiphy *wiphy,
 				goto wpa2_personal;
 			}
 
-			if (!wiphy_can_connect_sae(wiphy))
+			if (!wiphy_can_connect_sae(wiphy, NULL))
 				goto wpa2_personal;
 
 			if (info.akm_suites &
@@ -411,7 +418,7 @@ bool wiphy_can_connect(struct wiphy *wiphy, struct scan_bss *bss)
 		switch (rsn_info.akm_suites) {
 		case IE_RSN_AKM_SUITE_SAE_SHA256:
 		case IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256:
-			if (!wiphy_can_connect_sae(wiphy))
+			if (!wiphy_can_connect_sae(wiphy, NULL))
 				return false;
 
 			break;
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/7 wiphy: add wiphy_needs_offload

This takes an AKM and returns true if that AKM requires offloading. Today only SAE offload and PSK offload are checked. It is assumed that wiphy_can_connect will be called before wiphy_needs_offload as no AKM support is verified in this API.

---
 src/wiphy.c | 30 ++++++++++++++++++++++++++++++
 src/wiphy.h |  1 +
 2 files changed, 31 insertions(+)
src/wiphy.c +30 -0
index 35872577..d40c90ba 100644
@@ -438,6 +438,36 @@ bool wiphy_can_connect(struct wiphy *wiphy, struct scan_bss *bss)
 	return true;
 }
 
+/*
+ * This should only be called *after* wiphy_can_connect has verified the BSS
+ * is connectable.
+ */
+bool wiphy_needs_offload(struct wiphy *wiphy, enum ie_rsn_akm_suite akm)
+{
+	if (IE_AKM_IS_SAE(akm)) {
+		bool offload = false;
+		/*
+		 * This should not fail, the compatibility should have been
+		 * checked already
+		 */
+		L_WARN_ON(wiphy_can_connect_sae(wiphy, &offload));
+
+		return offload;
+	} else if (akm == IE_RSN_AKM_SUITE_FT_USING_PSK) {
+		if (wiphy->support_cmds_auth_assoc)
+			return false;
+
+		/*
+		 * Offload is the only way to do FT on this type of card.
+		 */
+		if (wiphy_has_ext_feature(wiphy,
+				NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
+			return true;
+	}
+
+	return false;
+}
+
 bool wiphy_supports_cmds_auth_assoc(struct wiphy *wiphy)
 {
 	return wiphy->support_cmds_auth_assoc;
src/wiphy.h +1 -0
index 6c91220c..b0f68dd0 100644
@@ -79,6 +79,7 @@ uint32_t wiphy_get_supported_bands(struct wiphy *wiphy);
 const struct scan_freq_set *wiphy_get_supported_freqs(
 						const struct wiphy *wiphy);
 bool wiphy_can_connect(struct wiphy *wiphy, struct scan_bss *bss);
+bool wiphy_needs_offload(struct wiphy *wiphy, enum ie_rsn_akm_suite akm);
 bool wiphy_supports_cmds_auth_assoc(struct wiphy *wiphy);
 bool wiphy_can_randomize_mac_addr(struct wiphy *wiphy);
 bool wiphy_rrm_capable(struct wiphy *wiphy);
Signature · 1 line
2.26.2
#2 lore raw

PATCH 3/7 wiphy: allow FT AKM to be used if Auth/Assoc is not supported

In reply to James Prestwood

Until now FT was only supported via Auth/Assoc commands which barred any fullmac cards from using FT AKMs. With PSK offload support these cards can do FT but only when offloading is used. This situation is checked now which allows the FT AKM to be selected.

A new option [General].4WayOffload was added which is required to enable this functionality. This was done mainly because it is unknown how stable firmware offloading is from card to card.

Note: Enabling offload has one strange side effect which could cause users problems when experimenting with this option. Once offload is enabled the firmware no longer forwards eapol frames for subsequent connections, even if offload is no longer being used. Once enabled a user must restart the firmware (e.g. via rebooting the machine) if they want to turn off the option.

---
 src/wiphy.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)
src/wiphy.c +25 -4
index d40c90ba..395bf74d 100644
@@ -185,12 +185,19 @@ enum ie_rsn_akm_suite wiphy_select_akm(struct wiphy *wiphy,
 {
 	struct ie_rsn_info info;
 	enum security security;
+	bool offload_on;
+	bool offload_needed;
+	const struct l_settings *settings = iwd_get_config();
 
 	memset(&info, 0, sizeof(info));
 	scan_bss_get_rsn_info(bss, &info);
 
 	security = security_determine(bss->capability, &info);
 
+	if (!l_settings_get_bool(settings, "General", "4WayOffload",
+					&offload_on))
+		offload_on = false;
+
 	/*
 	 * If FT is available, use FT authentication to keep the door open
 	 * for fast transitions.  Otherwise use SHA256 version if present.
@@ -241,7 +248,10 @@ enum ie_rsn_akm_suite wiphy_select_akm(struct wiphy *wiphy,
 				goto wpa2_personal;
 			}
 
-			if (!wiphy_can_connect_sae(wiphy, NULL))
+			if (!wiphy_can_connect_sae(wiphy, &offload_needed))
+				goto wpa2_personal;
+
+			if (offload_needed && !offload_on)
 				goto wpa2_personal;
 
 			if (info.akm_suites &
@@ -253,10 +263,21 @@ enum ie_rsn_akm_suite wiphy_select_akm(struct wiphy *wiphy,
 		}
 
 wpa2_personal:
+		/*
+		 * Allow FT if either Auth/Assoc is supported OR if the card
+		 * supports PSK offload. Without Auth/Assoc, PSK offload is the
+		 * only mechanism to allow FT on these cards.
+		 */
 		if ((info.akm_suites & IE_RSN_AKM_SUITE_FT_USING_PSK) &&
-				bss->rsne && bss->mde_present &&
-				wiphy->support_cmds_auth_assoc)
-			return IE_RSN_AKM_SUITE_FT_USING_PSK;
+					bss->rsne && bss->mde_present) {
+			if (wiphy->support_cmds_auth_assoc)
+				return IE_RSN_AKM_SUITE_FT_USING_PSK;
+
+			if (wiphy_has_ext_feature(wiphy,
+				NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) &&
+					offload_on)
+				return IE_RSN_AKM_SUITE_FT_USING_PSK;
+		}
 
 		if (info.akm_suites & IE_RSN_AKM_SUITE_PSK_SHA256)
 			return IE_RSN_AKM_SUITE_PSK_SHA256;
Signature · 1 line
2.26.2
#3 lore raw

PATCH 4/7 wiphy: check offload in wiphy_can_connect

In reply to James Prestwood

This will check if offload is supported and enabled by the user. A new case was added for FT just in case the AP sets only an FT AKM.

---
 src/wiphy.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
src/wiphy.c +22 -1
index 395bf74d..b64d2b74 100644
@@ -420,6 +420,9 @@ bool wiphy_can_connect(struct wiphy *wiphy, struct scan_bss *bss)
 {
 	struct ie_rsn_info rsn_info;
 	int r;
+	bool offload_needed;
+	bool offload_on;
+	const struct l_settings *settings = iwd_get_config();
 
 	memset(&rsn_info, 0, sizeof(rsn_info));
 	r = scan_bss_get_rsn_info(bss, &rsn_info);
@@ -435,11 +438,29 @@ bool wiphy_can_connect(struct wiphy *wiphy, struct scan_bss *bss)
 					rsn_info.group_management_cipher))
 			return false;
 
+		if (!l_settings_get_bool(settings, "General", "4WayOffload",
+						&offload_on))
+			offload_on = false;
 
 		switch (rsn_info.akm_suites) {
 		case IE_RSN_AKM_SUITE_SAE_SHA256:
 		case IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256:
-			if (!wiphy_can_connect_sae(wiphy, NULL))
+			if (!wiphy_can_connect_sae(wiphy, &offload_needed))
+				return false;
+
+			if (offload_needed && !offload_on)
+				return false;
+
+			break;
+		case IE_RSN_AKM_SUITE_FT_USING_PSK:
+			if (wiphy->support_cmds_auth_assoc)
+				return true;
+
+			if (!wiphy_has_ext_feature(wiphy,
+				NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
+				return false;
+
+			if (!offload_on)
 				return false;
 
 			break;
Signature · 1 line
2.26.2
#4 lore raw

PATCH 5/7 netdev: allow PSK offload for FT AKMs

In reply to James Prestwood

If the handshake has offloading set, use ATTR_PMK (for WPA2) which enables PSK offloading.

The CMD_ROAM event path was also modified to take into account handshake offloading. If the handshake is offloaded we still must issue GET_SCAN, but not start eapol since the firmware takes care of this.

---
 src/netdev.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
src/netdev.c +15 -2
index 914f6479..67a92e79 100644
@@ -2641,6 +2641,8 @@ static struct l_genl_msg *netdev_build_cmd_connect(struct netdev *netdev,
 		if (IE_AKM_IS_SAE(hs->akm_suite))
 			l_genl_msg_append_attr(msg, NL80211_ATTR_SAE_PASSWORD,
 					strlen(hs->passphrase), hs->passphrase);
+		else
+			l_genl_msg_append_attr(msg, NL80211_ATTR_PMK, 32, hs->pmk);
 	}
 
 	if (prev_bssid)
@@ -4000,7 +4002,7 @@ static bool netdev_get_fw_scan_cb(int err, struct l_queue *bss_list,
 	 * In this case we should just ignore this and allow the disconnect
 	 * logic to continue.
 	 */
-	if (!netdev->sm)
+	if (!netdev->handshake->offload && !netdev->sm)
 		return false;
 
 	if (err < 0) {
@@ -4028,6 +4030,11 @@ static bool netdev_get_fw_scan_cb(int err, struct l_queue *bss_list,
 
 	handshake_state_set_authenticator_ie(netdev->handshake, bss->rsne);
 
+	if (netdev->handshake->offload) {
+		netdev_connect_ok(netdev);
+		return false;
+	}
+
 	eapol_start(netdev->sm);
 
 	return false;
@@ -4063,14 +4070,20 @@ static bool netdev_roam_event(struct l_genl_msg *msg, struct netdev *netdev)
 		goto failed;
 	}
 
+	/* Handshake completed in firmware, just get the roamed BSS */
+	if (netdev->handshake->offload)
+		goto get_fw_scan;
+
 	/* Reset handshake state */
 	nhs->complete = false;
 	nhs->ptk_installed = false;
 	nhs->gtk_installed = true;
 	nhs->igtk_installed = true;
-	handshake_state_set_authenticator_address(netdev->handshake, mac);
 	netdev->handshake->ptk_complete = false;
 
+get_fw_scan:
+	handshake_state_set_authenticator_address(netdev->handshake, mac);
+
 	if (!scan_get_firmware_scan(netdev->wdev_id, netdev_get_fw_scan_cb,
 					netdev, NULL))
 		goto failed;
Signature · 1 line
2.26.2
#5 lore raw

PATCH 6/7 station: set handshake->offload with wiphy_needs_offload

In reply to James Prestwood

This will handle both SAE offloading and PSK offloading in one API call.

---
 src/station.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
src/station.c +11 -10
index cf4dd2e7..ef186c8b 100644
@@ -981,16 +981,6 @@ static struct handshake_state *station_handshake_setup(struct station *station,
 				goto no_psk;
 
 			handshake_state_set_passphrase(hs, passphrase);
-
-			/*
-			 * TODO: This check isn't strictly correct since
-			 * some drivers may support EXTERNAL_AUTH but since
-			 * wiphy_can_connect takes this into account IWD should
-			 * have already rejected the connection if this was the
-			 * case.
-			 */
-			if (!wiphy_supports_cmds_auth_assoc(wiphy))
-				hs->offload = true;
 		} else {
 			const uint8_t *psk = network_get_psk(network);
 
@@ -999,6 +989,17 @@ static struct handshake_state *station_handshake_setup(struct station *station,
 
 			handshake_state_set_pmk(hs, psk, 32);
 		}
+
+		/*
+		 * wiphy_can_connect/select_akm should have already sorted out
+		 * if both the card supports offload AND the user has enabled
+		 * it.
+		 */
+		hs->offload = wiphy_needs_offload(wiphy, hs->akm_suite);
+
+		if (hs->offload)
+			l_debug("Offloading connection to firmware");
+
 	} else if (security == SECURITY_8021X)
 		handshake_state_set_8021x_config(hs,
 					network_get_settings(network));
Signature · 1 line
2.26.2
#6 lore raw

PATCH 7/7 doc: document new [General].4WayOffload

In reply to James Prestwood

This option will allow the 4-way handshake to be offloaded to firmware if it supports it.

---
 src/iwd.config.rst | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
src/iwd.config.rst +14 -0
index 478bd616..e2060312 100644
@@ -174,6 +174,20 @@ The group ``[General]`` contains general settings.
        off by default.  If you want to easily utilize Hotspot 2.0 networks,
        then setting ``DisableANQP`` to ``false`` is recommended.
 
+   * - 4WayOffload
+     - Values: **false**, true
+
+       Enables the use of 4-way handshake offloading. Some drivers can offload
+       the 4-way handshake to firmware which is needed for protocols which
+       act on Authenticate/Associate frames such as Fast Transition. This
+       option is turned off by default as it is not widely tested.
+
+       Note: There seems to be a bug in the brcmfmac driver/firmware where once
+       offloading is enabled (by turning on this option) it cannot be turned
+       off in the firmware without a hard reboot (or some means of restarting
+       the firmware).
+
+
 Network
 ---------
 
Signature · 1 line
2.26.2