Skip to contentSkip to conversation

ft: rework ft_parse_ies

PATCH In review James Prestwood 2 participants 15 messages Apr 29, 2021 – Apr 30, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/7 ft: rework ft_parse_ies

This adds the RSNE verification to ft_parse_ies which will be common between over-Air and over-DS. The MDE check was also factored out into its own minimal function as to retain the spec comment but allow reuse elsewhere.

---
 src/ft.c | 125 +++++++++++++++++++++++++++++--------------------------
 1 file changed, 66 insertions(+), 59 deletions(-)

v4:
* Moved MDE check into its own function to avoid duplicate comments

src/ft.c +66 -59
index 85d2d369..032eefd1 100644
@@ -329,14 +329,52 @@ error:
 	return -EINVAL;
 }
 
-static int ft_parse_ies(const uint8_t *ies, size_t ies_len,
-			const uint8_t **rsne_out, const uint8_t **mde_out,
+static bool ft_verify_rsne(const uint8_t *rsne, const uint8_t *pmk_r0_name,
+				const uint8_t *authenticator_ie)
+{
+	/*
+	 * In an RSN, check for an RSNE containing the PMK-R0-Name and
+	 * the remaining fields same as in the advertised RSNE.
+	 *
+	 * 12.8.3: "The RSNE shall be present only if dot11RSNAActivated
+	 * is true. If present, the RSNE shall be set as follows:
+	 * - Version field shall be set to 1.
+	 * - PMKID Count field shall be set to 1.
+	 * - PMKID List field shall be set to the value contained in the
+	 *   first message of this sequence.
+	 * - All other fields shall be identical to the contents of the
+	 *   RSNE advertised by the AP in Beacon and Probe Response frames."
+	 */
+
+	struct ie_rsn_info msg2_rsne;
+
+	if (!rsne)
+		return false;
+
+	if (ie_parse_rsne_from_data(rsne, rsne[1] + 2,
+						&msg2_rsne) < 0)
+		return false;
+
+	if (msg2_rsne.num_pmkids != 1 ||
+				memcmp(msg2_rsne.pmkids, pmk_r0_name, 16))
+		return false;
+
+	if (!handshake_util_ap_ie_matches(rsne, authenticator_ie, false))
+		return false;
+
+	return true;
+}
+
+static int ft_parse_ies(struct handshake_state *hs,
+			const uint8_t *ies, size_t ies_len,
+			const uint8_t **mde_out,
 			const uint8_t **fte_out)
 {
 	struct ie_tlv_iter iter;
 	const uint8_t *rsne = NULL;
 	const uint8_t *mde = NULL;
 	const uint8_t *fte = NULL;
+	bool is_rsn;
 
 	ie_tlv_iter_init(&iter, ies, ies_len);
 
@@ -365,8 +403,14 @@ static int ft_parse_ies(const uint8_t *ies, size_t ies_len,
 		}
 	}
 
-	if (rsne_out)
-		*rsne_out = rsne;
+	is_rsn = hs->supplicant_ie != NULL;
+
+	if (is_rsn) {
+		if (!ft_verify_rsne(rsne, hs->pmk_r0_name,
+					hs->authenticator_ie))
+			goto ft_error;
+	} else if (rsne)
+		goto ft_error;
 
 	if (mde_out)
 		*mde_out = mde;
@@ -380,42 +424,6 @@ ft_error:
 	return -EINVAL;
 }
 
-static bool ft_verify_rsne(const uint8_t *rsne, const uint8_t *pmk_r0_name,
-				const uint8_t *authenticator_ie)
-{
-	/*
-	 * In an RSN, check for an RSNE containing the PMK-R0-Name and
-	 * the remaining fields same as in the advertised RSNE.
-	 *
-	 * 12.8.3: "The RSNE shall be present only if dot11RSNAActivated
-	 * is true. If present, the RSNE shall be set as follows:
-	 * - Version field shall be set to 1.
-	 * - PMKID Count field shall be set to 1.
-	 * - PMKID List field shall be set to the value contained in the
-	 *   first message of this sequence.
-	 * - All other fields shall be identical to the contents of the
-	 *   RSNE advertised by the AP in Beacon and Probe Response frames."
-	 */
-
-	struct ie_rsn_info msg2_rsne;
-
-	if (!rsne)
-		return false;
-
-	if (ie_parse_rsne_from_data(rsne, rsne[1] + 2,
-						&msg2_rsne) < 0)
-		return false;
-
-	if (msg2_rsne.num_pmkids != 1 ||
-				memcmp(msg2_rsne.pmkids, pmk_r0_name, 16))
-		return false;
-
-	if (!handshake_util_ap_ie_matches(rsne, authenticator_ie, false))
-		return false;
-
-	return true;
-}
-
 static bool ft_parse_fte(struct handshake_state *hs,
 				const uint8_t *snonce,
 				const uint8_t *fte,
@@ -465,38 +473,37 @@ static bool ft_parse_fte(struct handshake_state *hs,
 	return true;
 }
 
+static bool mde_equal(const uint8_t *mde1, const uint8_t *mde2)
+{
+	if (!mde1 || !mde2)
+		return false;
+
+	/*
+	 * Check for an MD IE identical to the one we sent in message 1
+	 *
+	 * 12.8.3: "The MDE shall contain the MDID and FT Capability and
+	 * Policy fields. This element shall be the same as the MDE
+	 * advertised by the target AP in Beacon and Probe Response frames."
+	 */
+	return memcmp(mde1, mde1, mde1[1] + 2) == 0;
+}
+
 static int ft_process_ies(struct handshake_state *hs, const uint8_t *ies,
 			size_t ies_len)
 {
-	const uint8_t *rsne = NULL;
 	const uint8_t *mde = NULL;
 	const uint8_t *fte = NULL;
-	bool is_rsn;
+	bool is_rsn = hs->supplicant_ie != NULL;
 
 	/* Check 802.11r IEs */
 	if (!ies)
 		goto ft_error;
 
-	if (ft_parse_ies(ies, ies_len, &rsne, &mde, &fte) < 0)
+	if (ft_parse_ies(hs, ies, ies_len, &mde, &fte) < 0)
 		goto ft_error;
 
-	is_rsn = hs->supplicant_ie != NULL;
 
-	if (is_rsn) {
-		if (!ft_verify_rsne(rsne, hs->pmk_r0_name,
-					hs->authenticator_ie))
-			goto ft_error;
-	} else if (rsne)
-		goto ft_error;
-
-	/*
-	 * Check for an MD IE identical to the one we sent in message 1
-	 *
-	 * 12.8.3: "The MDE shall contain the MDID and FT Capability and
-	 * Policy fields. This element shall be the same as the MDE
-	 * advertised by the target AP in Beacon and Probe Response frames."
-	 */
-	if (!mde || memcmp(hs->mde, mde, hs->mde[1] + 2))
+	if (!mde_equal(hs->mde, mde))
 		goto ft_error;
 
 	if (is_rsn) {
Signature · 1 line
2.26.2
#1 lore raw

PATCH v4 2/7 ft: create class for FT-over-DS targets

FT-over-DS is being separated into two independent stages. The first of which is the processing of the action frame response. This new class will hold all the parsed information from the action frame and allowing it to be retrieved at a later time when IWD needs to roam.

Initial info class should be created when the action frame is being sent out. Once a response is received it can be parsed with ft_over_ds_parse_action_response. This verifies the frame and updates the ft_ds_info class with the parsed data.

ft_over_ds_prepare_handshake is the final step prior to Reassociation. This sets all the stored IEs, anonce, and KH IDs into the handshake and derives the new PTK.

---
 src/ft.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/ft.h | 25 +++++++++++++++
 2 files changed, 118 insertions(+)
src/ft.c +93 -0
index 032eefd1..d482e539 100644
@@ -488,6 +488,35 @@ static bool mde_equal(const uint8_t *mde1, const uint8_t *mde2)
 	return memcmp(mde1, mde1, mde1[1] + 2) == 0;
 }
 
+static bool ft_over_ds_process_ies(struct ft_ds_info *info,
+					struct handshake_state *hs,
+					const uint8_t *ies,
+					size_t ies_len)
+{
+	const uint8_t *mde = NULL;
+	const uint8_t *fte = NULL;
+	bool is_rsn = hs->supplicant_ie != NULL;
+
+	if (ft_parse_ies(hs, ies, ies_len, &mde, &fte) < 0)
+		return false;
+
+	if (!mde_equal(info->mde, mde))
+		goto ft_error;
+
+	if (is_rsn) {
+		if (!ft_parse_fte(hs, info->snonce, fte, &info->ft_info))
+			goto ft_error;
+
+		info->fte = l_memdup(fte, fte[1] + 2);
+	} else if (fte)
+		goto ft_error;
+
+	return true;
+
+ft_error:
+	return false;
+}
+
 static int ft_process_ies(struct handshake_state *hs, const uint8_t *ies,
 			size_t ies_len)
 {
@@ -530,6 +559,59 @@ ft_error:
 	return -EBADMSG;
 }
 
+int ft_over_ds_parse_action_response(struct ft_ds_info *info,
+					struct handshake_state *hs,
+					const uint8_t *frame, size_t frame_len)
+{
+	uint16_t status;
+
+	if (frame_len < 16)
+		return -EINVAL;
+
+	/* Category FT */
+	if (frame[0] != 6)
+		return -EINVAL;
+
+	/* FT Action */
+	if (frame[1] != 2)
+		return -EINVAL;
+
+	if (memcmp(frame + 2, info->spa, 6))
+		return -ENOENT;
+	if (memcmp(frame + 8, info->aa, 6))
+		return -ENOENT;
+
+	status = l_get_le16(frame + 14);
+	if (status != 0)
+		return (int)status;
+
+	if (!ft_over_ds_process_ies(info, hs, frame + 16, frame_len - 16))
+		return -EBADMSG;
+
+	return 0;
+}
+
+bool ft_over_ds_prepare_handshake(struct ft_ds_info *info,
+					struct handshake_state *hs)
+{
+	if (!hs->supplicant_ie)
+		return true;
+
+	memcpy(hs->snonce, info->snonce, sizeof(hs->snonce));
+
+	handshake_state_set_fte(hs, info->fte);
+
+	handshake_state_set_anonce(hs, info->ft_info.anonce);
+
+	handshake_state_set_kh_ids(hs, info->ft_info.r0khid,
+						info->ft_info.r0khid_len,
+						info->ft_info.r1khid);
+
+	handshake_state_derive_ptk(hs);
+
+	return true;
+}
+
 static int ft_rx_action(struct auth_proto *ap, const uint8_t *frame,
 				size_t frame_len)
 {
@@ -558,6 +640,17 @@ auth_error:
 	return (int)status_code;
 }
 
+void ft_ds_info_free(struct ft_ds_info *info)
+{
+	__typeof__(info->free) destroy = info->free;
+
+	if (info->fte)
+		l_free(info->fte);
+
+	if (destroy)
+		destroy(info);
+}
+
 static int ft_rx_authenticate(struct auth_proto *ap, const uint8_t *frame,
 				size_t frame_len)
 {
src/ft.h +25 -0
index f24b3b5e..907c3d5d 100644
@@ -20,15 +20,37 @@
  *
  */
 
+struct handshake_state;
+
 typedef void (*ft_tx_authenticate_func_t)(struct iovec *iov, size_t iov_len,
 					void *user_data);
 typedef void (*ft_tx_associate_func_t)(struct iovec *ie_iov, size_t iov_len,
 					void *user_data);
 
+typedef void (*ft_ds_free_func_t)(void *user_data);
+
+struct ft_ds_info {
+	uint8_t spa[6];
+	uint8_t aa[6];
+	uint8_t snonce[32];
+	uint8_t mde[3];
+	uint8_t *fte;
+
+	struct ie_ft_info ft_info;
+
+	void (*free)(struct ft_ds_info *s);
+};
+
+void ft_ds_info_free(struct ft_ds_info *info);
+
 bool ft_build_authenticate_ies(struct handshake_state *hs,
 				const uint8_t *new_snonce, uint8_t *buf,
 				size_t *len);
 
+int ft_over_ds_parse_action_response(struct ft_ds_info *info,
+					struct handshake_state *hs,
+					const uint8_t *frame, size_t frame_len);
+
 struct auth_proto *ft_over_air_sm_new(struct handshake_state *hs,
 				ft_tx_authenticate_func_t tx_auth,
 				ft_tx_associate_func_t tx_assoc,
@@ -38,3 +60,6 @@ struct auth_proto *ft_over_ds_sm_new(struct handshake_state *hs,
 				ft_tx_authenticate_func_t tx_auth,
 				ft_tx_associate_func_t tx_assoc,
 				void *user_data);
+
+bool ft_over_ds_prepare_handshake(struct ft_ds_info *info,
+					struct handshake_state *hs);
Signature · 1 line
2.26.2
#2 lore raw

PATCH v4 3/7 ft: separate over-air from over-ds initializers

In reply to James Prestwood
---
 src/ft.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)
src/ft.c +15 -12
index d482e539..d5f1db5b 100644
@@ -917,10 +917,9 @@ static bool ft_start(struct auth_proto *ap)
 	return true;
 }
 
-static struct auth_proto *ft_sm_new(struct handshake_state *hs,
+struct auth_proto *ft_over_air_sm_new(struct handshake_state *hs,
 				ft_tx_authenticate_func_t tx_auth,
 				ft_tx_associate_func_t tx_assoc,
-				bool over_air,
 				void *user_data)
 {
 	struct ft_sm *ft = l_new(struct ft_sm, 1);
@@ -930,7 +929,7 @@ static struct auth_proto *ft_sm_new(struct handshake_state *hs,
 	ft->hs = hs;
 	ft->user_data = user_data;
 
-	ft->ap.rx_authenticate = (over_air) ? ft_rx_authenticate : ft_rx_action;
+	ft->ap.rx_authenticate = ft_rx_authenticate;
 	ft->ap.rx_associate = ft_rx_associate;
 	ft->ap.start = ft_start;
 	ft->ap.free = ft_sm_free;
@@ -938,18 +937,22 @@ static struct auth_proto *ft_sm_new(struct handshake_state *hs,
 	return &ft->ap;
 }
 
-struct auth_proto *ft_over_air_sm_new(struct handshake_state *hs,
-				ft_tx_authenticate_func_t tx_auth,
-				ft_tx_associate_func_t tx_assoc,
-				void *user_data)
-{
-	return ft_sm_new(hs, tx_auth, tx_assoc, true, user_data);
-}
-
 struct auth_proto *ft_over_ds_sm_new(struct handshake_state *hs,
 				ft_tx_authenticate_func_t tx_auth,
 				ft_tx_associate_func_t tx_assoc,
 				void *user_data)
 {
-	return ft_sm_new(hs, tx_auth, tx_assoc, false, user_data);
+	struct ft_sm *ft = l_new(struct ft_sm, 1);
+
+	ft->tx_assoc = tx_assoc;
+	ft->tx_auth = tx_auth;
+	ft->hs = hs;
+	ft->user_data = user_data;
+
+	ft->ap.rx_authenticate = ft_rx_action;
+	ft->ap.rx_associate = ft_rx_associate;
+	ft->ap.start = ft_start;
+	ft->ap.free = ft_sm_free;
+
+	return &ft->ap;
 }
Signature · 1 line
2.26.2
#3 lore raw

PATCH v4 4/7 netdev: separate over-air and over-ds netdev APIs

In reply to James Prestwood
---
 src/netdev.c | 68 ++++++++++++++++++++++++++++++----------------------
 1 file changed, 39 insertions(+), 29 deletions(-)
src/netdev.c +39 -29
index 25891092..232d098d 100644
@@ -3658,10 +3658,25 @@ static void prepare_ft(struct netdev *netdev, struct scan_bss *target_bss)
 {
 	struct netdev_handshake_state *nhs;
 
+	/*
+	 * We reuse the handshake_state object and reset what's needed.
+	 * Could also create a new object and copy most of the state but
+	 * we would end up doing more work.
+	 */
+	memcpy(netdev->prev_snonce, netdev->handshake->snonce, 32);
+
 	memcpy(netdev->prev_bssid, netdev->handshake->aa, 6);
 	netdev->prev_frequency = netdev->frequency;
 	netdev->frequency = target_bss->frequency;
 
+	handshake_state_set_authenticator_address(netdev->handshake,
+							target_bss->addr);
+
+	if (target_bss->rsne)
+		handshake_state_set_authenticator_ie(netdev->handshake,
+							target_bss->rsne);
+	memcpy(netdev->handshake->mde + 2, target_bss->mde, 3);
+
 	netdev->associated = false;
 	netdev->operational = false;
 	netdev->in_ft = true;
@@ -3809,8 +3824,7 @@ static const struct wiphy_radio_work_item_ops ft_work_ops = {
 	.do_work = netdev_ft_work_ready,
 };
 
-static int fast_transition(struct netdev *netdev, struct scan_bss *target_bss,
-				bool over_air,
+int netdev_fast_transition(struct netdev *netdev, struct scan_bss *target_bss,
 				netdev_connect_cb_t cb)
 {
 	if (!netdev->operational)
@@ -3823,32 +3837,13 @@ static int fast_transition(struct netdev *netdev, struct scan_bss *target_bss,
 
 	prepare_ft(netdev, target_bss);
 
-	/*
-	 * We reuse the handshake_state object and reset what's needed.
-	 * Could also create a new object and copy most of the state but
-	 * we would end up doing more work.
-	 */
-	memcpy(netdev->prev_snonce, netdev->handshake->snonce, 32);
 	handshake_state_new_snonce(netdev->handshake);
 
-	handshake_state_set_authenticator_address(netdev->handshake,
-							target_bss->addr);
-
-	if (target_bss->rsne)
-		handshake_state_set_authenticator_ie(netdev->handshake,
-							target_bss->rsne);
-	memcpy(netdev->handshake->mde + 2, target_bss->mde, 3);
-
 	netdev->connect_cb = cb;
 
-	if (over_air)
-		netdev->ap = ft_over_air_sm_new(netdev->handshake,
+	netdev->ap = ft_over_air_sm_new(netdev->handshake,
 					netdev_ft_tx_authenticate,
 					netdev_ft_tx_associate, netdev);
-	else
-		netdev->ap = ft_over_ds_sm_new(netdev->handshake,
-					netdev_ft_over_ds_tx_authenticate,
-					netdev_ft_tx_associate, netdev);
 
 	wiphy_radio_work_insert(netdev->wiphy, &netdev->work, 1,
 				&ft_work_ops);
@@ -3856,17 +3851,32 @@ static int fast_transition(struct netdev *netdev, struct scan_bss *target_bss,
 	return 0;
 }
 
-int netdev_fast_transition(struct netdev *netdev, struct scan_bss *target_bss,
-				netdev_connect_cb_t cb)
-{
-	return fast_transition(netdev, target_bss, true, cb);
-}
-
 int netdev_fast_transition_over_ds(struct netdev *netdev,
 					struct scan_bss *target_bss,
 					netdev_connect_cb_t cb)
 {
-	return fast_transition(netdev, target_bss, false, cb);
+	if (!netdev->operational)
+		return -ENOTCONN;
+
+	if (!netdev->handshake->mde || !target_bss->mde_present ||
+			l_get_le16(netdev->handshake->mde + 2) !=
+			l_get_le16(target_bss->mde))
+		return -EINVAL;
+
+	prepare_ft(netdev, target_bss);
+
+	handshake_state_new_snonce(netdev->handshake);
+
+	netdev->connect_cb = cb;
+
+	netdev->ap = ft_over_ds_sm_new(netdev->handshake,
+					netdev_ft_over_ds_tx_authenticate,
+					netdev_ft_tx_associate, netdev);
+
+	wiphy_radio_work_insert(netdev->wiphy, &netdev->work, 1,
+				&ft_work_ops);
+
+	return 0;
 }
 
 static void netdev_preauth_cb(const uint8_t *pmk, void *user_data)
Signature · 1 line
2.26.2
#4 lore raw

PATCH v4 5/7 ft: netdev: refactor FT-over-DS into two stages

In reply to James Prestwood

FT-over-DS followed the same pattern as FT-over-Air which worked, but really limited how the protocol could be used. FT-over-DS is unique in that we can authenticate to many APs by sending out FT action frames and parsing the results. Once parsed IWD can immediately Reassociate, or do so at a later time.

To take advantage of this IWD need to separate FT-over-DS into two stages: action frame and reassociation.

The initial action frame stage is started by netdev. The target BSS is sent an FT action frame and a new cache entry is created in ft.c. Once the response is received the entry is updated with all the needed data to Reassociate. To limit the record keeping on netdev each FT-over-DS entry holds a userdata pointer so netdev doesn't need to maintain its own list of data for callbacks.

Once the action response is parsed netdev will call back signalling the action frame sequence was completed (either successfully or not). At this point the 'normal' FT procedure can start using the FT-over-DS auth-proto.

---
 src/ft.c     |  74 +++----------------
 src/ft.h     |   1 -
 src/netdev.c | 196 ++++++++++++++++++++++++++++++++++++++++-----------
 src/netdev.h |   8 +++
 4 files changed, 169 insertions(+), 110 deletions(-)
src/ft.c +8 -66
index d5f1db5b..76285d13 100644
@@ -156,40 +156,6 @@ static bool ft_parse_authentication_resp_frame(const uint8_t *data, size_t len,
 	return true;
 }
 
-static bool ft_parse_action_resp_frame(const uint8_t *frame, size_t frame_len,
-					const uint8_t *spa, const uint8_t *aa,
-					uint16_t *out_status,
-					const uint8_t **out_ies,
-					size_t *out_ies_len)
-{
-	uint16_t status = 0;
-
-	/* Category FT */
-	if (frame[0] != 6)
-		return false;
-
-	/* FT Action */
-	if (frame[1] != 2)
-		return false;
-
-	if (memcmp(frame + 2, spa, 6))
-		return false;
-	if (memcmp(frame + 8, aa, 6))
-		return false;
-
-	status = l_get_le16(frame + 14);
-
-	if (out_status)
-		*out_status = status;
-
-	if (status == 0 && out_ies) {
-		*out_ies = frame + 16;
-		*out_ies_len = frame_len - 16;
-	}
-
-	return true;
-}
-
 static bool ft_parse_associate_resp_frame(const uint8_t *frame, size_t frame_len,
 				uint16_t *out_status, const uint8_t **rsne,
 				const uint8_t **mde, const uint8_t **fte)
@@ -612,34 +578,6 @@ bool ft_over_ds_prepare_handshake(struct ft_ds_info *info,
 	return true;
 }
 
-static int ft_rx_action(struct auth_proto *ap, const uint8_t *frame,
-				size_t frame_len)
-{
-	struct ft_sm *ft = l_container_of(ap, struct ft_sm, ap);
-	uint16_t status_code = MMPDU_STATUS_CODE_UNSPECIFIED;
-	const uint8_t *ies = NULL;
-	size_t ies_len;
-	int ret;
-
-	if (!ft_parse_action_resp_frame(frame, frame_len, ft->hs->spa,
-						ft->hs->aa, &status_code,
-						&ies, &ies_len))
-		return -EBADMSG;
-
-	/* AP Rejected the authenticate / associate */
-	if (status_code != 0)
-		goto auth_error;
-
-	ret = ft_process_ies(ft->hs, ies, ies_len);
-	if (ret < 0)
-		goto auth_error;
-
-	return ft_tx_reassociate(ft);
-
-auth_error:
-	return (int)status_code;
-}
-
 void ft_ds_info_free(struct ft_ds_info *info)
 {
 	__typeof__(info->free) destroy = info->free;
@@ -827,6 +765,13 @@ static void ft_sm_free(struct auth_proto *ap)
 	l_free(ft);
 }
 
+static bool ft_over_ds_start(struct auth_proto *ap)
+{
+	struct ft_sm *ft = l_container_of(ap, struct ft_sm, ap);
+
+	return ft_tx_reassociate(ft) == 0;
+}
+
 bool ft_build_authenticate_ies(struct handshake_state *hs,
 				const uint8_t *new_snonce, uint8_t *buf,
 				size_t *len)
@@ -938,20 +883,17 @@ struct auth_proto *ft_over_air_sm_new(struct handshake_state *hs,
 }
 
 struct auth_proto *ft_over_ds_sm_new(struct handshake_state *hs,
-				ft_tx_authenticate_func_t tx_auth,
 				ft_tx_associate_func_t tx_assoc,
 				void *user_data)
 {
 	struct ft_sm *ft = l_new(struct ft_sm, 1);
 
 	ft->tx_assoc = tx_assoc;
-	ft->tx_auth = tx_auth;
 	ft->hs = hs;
 	ft->user_data = user_data;
 
-	ft->ap.rx_authenticate = ft_rx_action;
 	ft->ap.rx_associate = ft_rx_associate;
-	ft->ap.start = ft_start;
+	ft->ap.start = ft_over_ds_start;
 	ft->ap.free = ft_sm_free;
 
 	return &ft->ap;
src/ft.h +0 -1
index 907c3d5d..7c009f16 100644
@@ -57,7 +57,6 @@ struct auth_proto *ft_over_air_sm_new(struct handshake_state *hs,
 				void *user_data);
 
 struct auth_proto *ft_over_ds_sm_new(struct handshake_state *hs,
-				ft_tx_authenticate_func_t tx_auth,
 				ft_tx_associate_func_t tx_assoc,
 				void *user_data);
 
src/netdev.c +153 -43

269 lines not on this page · raw message

src/netdev.h +8 -0
index 43ea3893..2f7f3647 100644
@@ -125,6 +125,10 @@ typedef void (*netdev_get_station_cb_t)(
 
 const char *netdev_iftype_to_string(uint32_t iftype);
 
+typedef void (*netdev_ft_over_ds_cb_t)(struct netdev *netdev,
+					uint16_t status, const uint8_t *bssid,
+					void *user_data);
+
 struct wiphy *netdev_get_wiphy(struct netdev *netdev);
 const uint8_t *netdev_get_address(struct netdev *netdev);
 uint32_t netdev_get_ifindex(struct netdev *netdev);
@@ -158,6 +162,10 @@ int netdev_reassociate(struct netdev *netdev, struct scan_bss *target_bss,
 			netdev_connect_cb_t cb, void *user_data);
 int netdev_fast_transition(struct netdev *netdev, struct scan_bss *target_bss,
 				netdev_connect_cb_t cb);
+int netdev_fast_transition_over_ds_action(struct netdev *netdev,
+					struct scan_bss *target_bss,
+					netdev_ft_over_ds_cb_t cb,
+					void *user_data);
 int netdev_fast_transition_over_ds(struct netdev *netdev,
 					struct scan_bss *target_bss,
 					netdev_connect_cb_t cb);
Signature · 1 line
2.26.2
#5 lore raw

Re: [PATCH v4 5/7] ft: netdev: refactor FT-over-DS into two stages

Hi James,

Quoted 28 lines · James Prestwood

FT-over-DS followed the same pattern as FT-over-Air which worked, but really limited how the protocol could be used. FT-over-DS is unique in that we can authenticate to many APs by sending out FT action frames and parsing the results. Once parsed IWD can immediately Reassociate, or do so at a later time.

To take advantage of this IWD need to separate FT-over-DS into two stages: action frame and reassociation.

The initial action frame stage is started by netdev. The target BSS is sent an FT action frame and a new cache entry is created in ft.c. Once the response is received the entry is updated with all the needed data to Reassociate. To limit the record keeping on netdev each FT-over-DS entry holds a userdata pointer so netdev doesn't need to maintain its own list of data for callbacks.

Once the action response is parsed netdev will call back signalling the action frame sequence was completed (either successfully or not). At this point the 'normal' FT procedure can start using the FT-over-DS auth-proto.

---
  src/ft.c     |  74 +++----------------
  src/ft.h     |   1 -
  src/netdev.c | 196 ++++++++++++++++++++++++++++++++++++++++-----------
  src/netdev.h |   8 +++
  4 files changed, 169 insertions(+), 110 deletions(-)

<snip>

Quoted 32 lines
src/netdev.c +9 -9
@@ -3719,44 +3732,52 @@ static void prepare_ft(struct netdev *netdev, struct scan_bss *target_bss)
  	}
  }
 
-static void netdev_ft_request_cb(struct l_genl_msg *msg, void *user_data)
+static void netdev_ft_over_ds_auth_failed(struct netdev_ft_over_ds_info *info,
+						uint16_t status)
  {
-	struct netdev *netdev = user_data;
-	int err = l_genl_msg_get_error(msg);
+	if (info->cb)
+		info->cb(info->netdev, status, info->super.aa, info->user_data);
 
-	if (err < 0) {
-		l_error("Could not send CMD_FRAME (%d)", err);
-		netdev_connect_failed(netdev,
-					NETDEV_RESULT_AUTHENTICATION_FAILED,
-					MMPDU_STATUS_CODE_UNSPECIFIED);
-	}
+	ft_ds_info_free(&info->super);
+
+	info->netdev->ft_ds_info = NULL;
  }
 
  static void netdev_ft_response_frame_event(const struct mmpdu_header *hdr,
  					const void *body, size_t body_len,
  					int rssi, void *user_data)
  {
+	struct netdev *netdev = user_data;
+	struct netdev_ft_over_ds_info *info = netdev->ft_ds_info;
  	int ret;
  	uint16_t status_code = MMPDU_STATUS_CODE_UNSPECIFIED;

src/netdev.c static void prepare_ft(struct netdev *netdev, struct scan_bss *target_bss) · line 3760

Quoted 10 lines
src/netdev.c +4 -3
-	struct netdev *netdev = user_data;
 
-	if (!netdev->ap || !netdev->in_ft)
+	if (!info)
  		return;
 
-	ret = auth_proto_rx_authenticate(netdev->ap, body, body_len);
+	l_timeout_remove(info->timeout);
+	info->timeout = NULL;
+

So why do you kill the timeout before checking whether the frame was valid or not?

Quoted 6 lines
src/netdev.c +3 -2
+	ret = ft_over_ds_parse_action_response(&info->super, netdev->handshake,
+						body, body_len);
  	if (ret < 0)
-		goto ft_error;
-	else if (ret > 0) {
+		return;

src/netdev.c static void prepare_ft(struct netdev *netdev, struct scan_bss *target_bss) · line 3774

Quoted 10 lines
src/netdev.c +6 -0
+
+	/* Now make sure the packet contained a success status code */
+	if (ret > 0) {
  		status_code = (uint16_t)ret;
  		goto ft_error;
  	}
 
+	if (info->cb)
+		info->cb(netdev, 0, info->super.aa, info->user_data);
+

Do you need to set a flag of some sort to indicate that the info has been filled successfully?

Quoted 12 lines
src/netdev.c +3 -3
  	return;
 
  ft_error:
-	netdev_connect_failed(netdev, NETDEV_RESULT_AUTHENTICATION_FAILED,
-				status_code);
-	return;
+	l_debug("FT-over-DS to "MAC" failed", MAC_STR(info->super.aa));
+
+	netdev_ft_over_ds_auth_failed(info, status_code);
  }
 
  static void netdev_qos_map_frame_event(const struct mmpdu_header *hdr,

<snip>

Quoted 13 lines
src/netdev.c +5 -0
@@ -3855,6 +3853,11 @@ int netdev_fast_transition_over_ds(struct netdev *netdev,
  					struct scan_bss *target_bss,
  					netdev_connect_cb_t cb)
  {
+	struct netdev_ft_over_ds_info *info = netdev->ft_ds_info;
+
+	if (!info)
+		return -ENOENT;
+
  	if (!netdev->operational)
  		return -ENOTCONN;
 

src/netdev.c int netdev_fast_transition_over_ds(struct netdev *netdev, · line 3872

Quoted 6 lines
src/netdev.c +2 -1
@@ -3865,13 +3868,14 @@ int netdev_fast_transition_over_ds(struct netdev *netdev,
 
  	prepare_ft(netdev, target_bss);
 
-	handshake_state_new_snonce(netdev->handshake);
+	if (!ft_over_ds_prepare_handshake(&info->super, netdev->handshake))
+		return -ENOENT;

This function doesn't seem to fail?

Quoted 16 lines
src/netdev.h +4 -0
index 43ea3893..2f7f3647 100644
@@ -125,6 +125,10 @@ typedef void (*netdev_get_station_cb_t)(
 
  const char *netdev_iftype_to_string(uint32_t iftype);
 
+typedef void (*netdev_ft_over_ds_cb_t)(struct netdev *netdev,
+					uint16_t status, const uint8_t *bssid,
+					void *user_data);
+
  struct wiphy *netdev_get_wiphy(struct netdev *netdev);
  const uint8_t *netdev_get_address(struct netdev *netdev);
  uint32_t netdev_get_ifindex(struct netdev *netdev);

src/netdev.h int netdev_reassociate(struct netdev *netdev, struct scan_bss *target_bss, · line 166

Quoted 5 lines
src/netdev.h +2 -0
@@ -158,6 +162,10 @@ int netdev_reassociate(struct netdev *netdev, struct scan_bss *target_bss,
  			netdev_connect_cb_t cb, void *user_data);
  int netdev_fast_transition(struct netdev *netdev, struct scan_bss *target_bss,
  				netdev_connect_cb_t cb);
+int netdev_fast_transition_over_ds_action(struct netdev *netdev,
+					struct scan_bss *target_bss,

Ideally you should use const struct scan_bss * whenever possible.

src/netdev.h int netdev_reassociate(struct netdev *netdev, struct scan_bss *target_bss, · line 171

Quoted 6 lines
src/netdev.h +2 -0
+					netdev_ft_over_ds_cb_t cb,
+					void *user_data);
  int netdev_fast_transition_over_ds(struct netdev *netdev,
  					struct scan_bss *target_bss,
  					netdev_connect_cb_t cb);

Regards,
-Denis

#6 lore raw

Re: [PATCH v4 5/7] ft: netdev: refactor FT-over-DS into two stages

Hi Denis,

<snip>

Quoted 7 lines

src/netdev.c static void prepare_ft(struct netdev *netdev, struct scan_bss *target_bss) · line 3774

Quoted 3 lines
src/netdev.c +3 -0
+	if (info->cb)
+		info->cb(netdev, 0, info->super.aa, info->user_data);
+

Do you need to set a flag of some sort to indicate that the info has been filled
successfully?

As long as station behaves and doesn't try and roam prior to a successful the action frame callback I think we can guarantee it has been parsed. But in the future when we do multiple concurrent action frames we would need something to distinguish them in the queue, so I'll add a flag.

Thanks,
James

Quoted 3 lines

Regards,
-Denis

#7 lore raw

Re: [PATCH v4 5/7] ft: netdev: refactor FT-over-DS into two stages

Hi James,

Quoted 11 lines · James Prestwood

Hi Denis,

<snip>

Quoted 7 lines

src/netdev.c static void prepare_ft(struct netdev *netdev, struct scan_bss *target_bss) · line 3774

Quoted 3 lines
src/netdev.c +3 -0
+	if (info->cb)
+		info->cb(netdev, 0, info->super.aa, info->user_data);
+

Do you need to set a flag of some sort to indicate that the info has been filled
successfully?

Quoted 2 lines

As long as station behaves and doesn't try and roam prior to a successful the action frame callback I think we can guarantee it has

Always err on the side of paranoia :)

Quoted 4 lines

been parsed. But in the future when we do multiple concurrent action frames we would need something to distinguish them in the queue, so I'll add a flag.

Also, are you resetting netdev->ft_ds_info once CMD_Associate has been sent?

Regads,
-Denis

#8 lore raw

Re: [PATCH v4 5/7] ft: netdev: refactor FT-over-DS into two stages

Quoted 22 lines · Denis Kenzior

Hi James,

Quoted 8 lines · James Prestwood

Hi Denis,

<snip>

Quoted 5 lines
Quoted 4 lines
(quoted diff) +2 -0
+	if (info->cb)
+		info->cb(netdev, 0, info->super.aa, info-
Quoted 1 line

user_data);

+

Quoted 8 lines
Quoted 4 lines

Do you need to set a flag of some sort to indicate that the info has
been filled
successfully?

As long as station behaves and doesn't try and roam prior to a successful the action frame callback I think we can guarantee it has

Always err on the side of paranoia :)

Quoted 8 lines
Quoted 5 lines

been parsed. But in the future when we do multiple concurrent action
frames we would need something to distinguish them in the queue, so I'll add a flag.

Also, are you resetting netdev->ft_ds_info once CMD_Associate has been sent?

No, and actually I think it can be reset right
inside netdev_fast_transition_over_ds. Once the handshake has been set- up it isn't needed.

Quoted 3 lines

Regads,
-Denis

#9 lore raw

Re: [PATCH v4 5/7] ft: netdev: refactor FT-over-DS into two stages

Hi James,

Quoted 7 lines
Quoted 2 lines

Also, are you resetting netdev->ft_ds_info once CMD_Associate has been sent?

No, and actually I think it can be reset right
inside netdev_fast_transition_over_ds. Once the handshake has been set- up it isn't needed.

OK, but it should be reset in all cases, including if we do a FT-over-Air.

Regards,
-Denis

#10 lore raw

Re: [PATCH v4 5/7] ft: netdev: refactor FT-over-DS into two stages

Quoted 5 lines · Denis Kenzior

Hi James,

Quoted 3 lines
Quoted 2 lines

Also, are you resetting netdev->ft_ds_info once CMD_Associate has been sent?

Quoted 8 lines
Quoted 5 lines

No, and actually I think it can be reset right
inside netdev_fast_transition_over_ds. Once the handshake has been set-
up it isn't needed.

OK, but it should be reset in all cases, including if we do a FT- over-Air.

Ah ok makes sense. Any other connection *should* reset it via netdev_connect_free, but yes we could do over Air after a failed over DS action frame.

Quoted 3 lines

Regards,
-Denis

#11 lore raw

PATCH v4 6/7 station: separate FT-over-DS stages

In reply to James Prestwood

FT-over-DS was refactored to separate the FT action frame and reassociation. From stations standpoint IWD needs to call netdev_fast_transition_over_ds_action prior to actually roaming. For now these two stages are being combined and the action roam happens immediately after the action response callback.

---
 src/station.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 52 insertions(+), 4 deletions(-)
src/station.c +52 -4
index c89b1901..6a308cfd 100644
@@ -113,6 +113,7 @@ struct station {
 	bool ap_directed_roaming : 1;
 	bool scanning : 1;
 	bool autoconnect : 1;
+	bool ft_over_ds : 1;
 };
 
 struct anqp_entry {
@@ -1587,10 +1588,17 @@ static void station_roam_failed(struct station *station)
 	l_debug("%u", netdev_get_ifindex(station->netdev));
 
 	/*
-	 * If we attempted a reassociation or a fast transition, and ended up
-	 * here then we are now disconnected.
+	 * If we attempted a reassociation or a fast transition (except DS),
+	 * and ended up here then we are now disconnected. In the case of
+	 * FT over DS we can remain connected to the AP even if the transition
+	 * fails.
 	 */
 	if (station->state == STATION_STATE_ROAMING) {
+		if (station->ft_over_ds) {
+			station_enter_state(station, STATION_STATE_CONNECTED);
+			goto delayed_retry;
+		}
+
 		station_disassociated(station);
 		return;
 	}
@@ -1628,6 +1636,7 @@ delayed_retry:
 	station->preparing_roam = false;
 	station->roam_scan_full = false;
 	station->ap_directed_roaming = false;
+	station->ft_over_ds = false;
 
 	if (station->signal_low)
 		station_roam_timeout_rearm(station, roam_retry_interval);
@@ -1713,6 +1722,41 @@ static bool bss_match_bssid(const void *a, const void *b)
 	return !memcmp(bss->addr, bssid, sizeof(bss->addr));
 }
 
+static void station_fast_transition_ds_cb(struct netdev *netdev,
+					uint16_t status, const uint8_t *bssid,
+					void *user_data)
+{
+	struct station *station = user_data;
+	struct scan_bss *bss;
+
+	if (status != 0)
+		goto failed;
+
+	/*
+	 * TODO: In the future it may be desired to start sending out these
+	 * FT-over-DS action frames at the time of connecting then be able to
+	 * roam immediately when required. If this is being done we can simply
+	 * bail out now as ft already caches the entires. But since this was
+	 * initiated due to a need to roam, do so now.
+	 */
+
+	/* Make sure we still have our BSS */
+	bss = l_queue_find(station->bss_list, bss_match_bssid, bssid);
+	if (!bss)
+		goto failed;
+
+	l_debug("Starting FT-over-DS roam");
+
+	if (netdev_fast_transition_over_ds(station->netdev, bss,
+					station_fast_transition_cb) < 0)
+		goto failed;
+
+	return;
+
+failed:
+	station_roam_failed(station);
+}
+
 static void station_preauthenticate_cb(struct netdev *netdev,
 					enum netdev_result result,
 					const uint8_t *pmk, void *user_data)
@@ -1810,8 +1854,12 @@ static void station_transition_start(struct station *station,
 		/* FT-over-DS can be better suited for these situations */
 		if ((hs->mde[4] & 1) && (station->ap_directed_roaming ||
 				station->signal_low)) {
-			if (netdev_fast_transition_over_ds(station->netdev, bss,
-					station_fast_transition_cb) < 0) {
+			station->ft_over_ds = true;
+
+			if (netdev_fast_transition_over_ds_action(
+					station->netdev, bss,
+					station_fast_transition_ds_cb,
+					station) < 0) {
 				station_roam_failed(station);
 				return;
 			}
Signature · 1 line
2.26.2
#12 lore raw

Re: [PATCH v4 6/7] station: separate FT-over-DS stages

Hi James,

Quoted 22 lines · James Prestwood

FT-over-DS was refactored to separate the FT action frame and reassociation. From stations standpoint IWD needs to call netdev_fast_transition_over_ds_action prior to actually roaming. For now these two stages are being combined and the action roam happens immediately after the action response callback.

---
  src/station.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++----
  1 file changed, 52 insertions(+), 4 deletions(-)
src/station.c +1 -0
index c89b1901..6a308cfd 100644
@@ -113,6 +113,7 @@ struct station {
  	bool ap_directed_roaming : 1;
  	bool scanning : 1;
  	bool autoconnect : 1;
+	bool ft_over_ds : 1;
  };
 
  struct anqp_entry {

src/station.c static void station_roam_failed(struct station *station) · line 1591

Quoted 6 lines
src/station.c +1 -2
@@ -1587,10 +1588,17 @@ static void station_roam_failed(struct station *station)
  	l_debug("%u", netdev_get_ifindex(station->netdev));
 
  	/*
-	 * If we attempted a reassociation or a fast transition, and ended up
-	 * here then we are now disconnected.
+	 * If we attempted a reassociation or a fast transition (except DS),

The comment is factually correct, but is easy to misinterpret. There's really no difference between Re-Association and FT (over DS or Air). They all go through Authenticate/(Re)Associate dance. If the Association fails -> we're disconnected.

src/station.c static void station_roam_failed(struct station *station) · line 1594

Quoted 3 lines
src/station.c +3 -0
+	 * and ended up here then we are now disconnected. In the case of
+	 * FT over DS we can remain connected to the AP even if the transition
+	 * fails.

This isn't correct. See above. What can fail is the Action frame stage. Once we are committed to the Authenticate/Associate stage, failure should be treated the same.

Before, we used to fail in the Action phase and erroneously station thought we were disconnected...

Quoted 66 lines
src/station.c +41 -1
  	 */
  	if (station->state == STATION_STATE_ROAMING) {
+		if (station->ft_over_ds) {
+			station_enter_state(station, STATION_STATE_CONNECTED);
+			goto delayed_retry;
+		}
+
  		station_disassociated(station);
  		return;
  	}
@@ -1628,6 +1636,7 @@ delayed_retry:
  	station->preparing_roam = false;
  	station->roam_scan_full = false;
  	station->ap_directed_roaming = false;
+	station->ft_over_ds = false;
 
  	if (station->signal_low)
  		station_roam_timeout_rearm(station, roam_retry_interval);
@@ -1713,6 +1722,41 @@ static bool bss_match_bssid(const void *a, const void *b)
  	return !memcmp(bss->addr, bssid, sizeof(bss->addr));
  }
 
+static void station_fast_transition_ds_cb(struct netdev *netdev,
+					uint16_t status, const uint8_t *bssid,
+					void *user_data)
+{
+	struct station *station = user_data;
+	struct scan_bss *bss;
+
+	if (status != 0)
+		goto failed;
+
+	/*
+	 * TODO: In the future it may be desired to start sending out these
+	 * FT-over-DS action frames at the time of connecting then be able to
+	 * roam immediately when required. If this is being done we can simply
+	 * bail out now as ft already caches the entires. But since this was
+	 * initiated due to a need to roam, do so now.
+	 */
+
+	/* Make sure we still have our BSS */
+	bss = l_queue_find(station->bss_list, bss_match_bssid, bssid);
+	if (!bss)
+		goto failed;
+
+	l_debug("Starting FT-over-DS roam");
+
+	if (netdev_fast_transition_over_ds(station->netdev, bss,
+					station_fast_transition_cb) < 0)
+		goto failed;
+
+	return;
+
+failed:
+	station_roam_failed(station);
+}
+
  static void station_preauthenticate_cb(struct netdev *netdev,
  					enum netdev_result result,
  					const uint8_t *pmk, void *user_data)
@@ -1810,8 +1854,12 @@ static void station_transition_start(struct station *station,
  		/* FT-over-DS can be better suited for these situations */
  		if ((hs->mde[4] & 1) && (station->ap_directed_roaming ||
  				station->signal_low)) {
-			if (netdev_fast_transition_over_ds(station->netdev, bss,

src/station.c static void station_transition_start(struct station *station, · line 1865

Quoted 10 lines
src/station.c +6 -1
-					station_fast_transition_cb) < 0) {
+			station->ft_over_ds = true;
+
+			if (netdev_fast_transition_over_ds_action(
+					station->netdev, bss,
+					station_fast_transition_ds_cb,
+					station) < 0) {
  				station_roam_failed(station);
  				return;
  			}

Regards,
-Denis

#13 lore raw

PATCH v4 7/7 ft: netdev: add return value to tx_associate

In reply to James Prestwood

Prior to this, an error sending the FT Reassociation was treated as fatal, which is correct for FT-over-Air but not for FT-over-DS. If the actual l_genl_family_send call fails for FT-over-DS the existing connection can be maintained and there is no need to call netdev_connect_failed.

Adding a return to the tx_associate function works for both FT types. In the FT-over-Air case this return will ultimately get sent back up to auth_proto_rx_authenticate in which case will call netdev_connect_failed. For FT-over-DS tx_associate is actually called from the 'start' operation which can fail and still maintain the existing connection.

---
 src/ft.c     | 4 +---
 src/ft.h     | 2 +-
 src/netdev.c | 8 ++++----
 3 files changed, 6 insertions(+), 8 deletions(-)
src/ft.c +1 -3
index 76285d13..de754fd8 100644
@@ -287,9 +287,7 @@ static int ft_tx_reassociate(struct ft_sm *ft)
 		iov_elems += 1;
 	}
 
-	ft->tx_assoc(iov, iov_elems, ft->user_data);
-
-	return 0;
+	return ft->tx_assoc(iov, iov_elems, ft->user_data);
 
 error:
 	return -EINVAL;
src/ft.h +1 -1
index 7c009f16..3d1cfe30 100644
@@ -24,7 +24,7 @@ struct handshake_state;
 
 typedef void (*ft_tx_authenticate_func_t)(struct iovec *iov, size_t iov_len,
 					void *user_data);
-typedef void (*ft_tx_associate_func_t)(struct iovec *ie_iov, size_t iov_len,
+typedef int (*ft_tx_associate_func_t)(struct iovec *ie_iov, size_t iov_len,
 					void *user_data);
 
 typedef void (*ft_ds_free_func_t)(void *user_data);
src/netdev.c +4 -4
index 97e6665b..048c6bf6 100644
@@ -3643,7 +3643,7 @@ restore_snonce:
 					MMPDU_STATUS_CODE_UNSPECIFIED);
 }
 
-static void netdev_ft_tx_associate(struct iovec *ie_iov, size_t iov_len,
+static int netdev_ft_tx_associate(struct iovec *ie_iov, size_t iov_len,
 					void *user_data)
 {
 	struct netdev *netdev = user_data;
@@ -3661,10 +3661,10 @@ static void netdev_ft_tx_associate(struct iovec *ie_iov, size_t iov_len,
 	if (!netdev->connect_cmd_id) {
 		l_genl_msg_unref(msg);
 
-		netdev_connect_failed(netdev, NETDEV_RESULT_ASSOCIATION_FAILED,
-					MMPDU_STATUS_CODE_UNSPECIFIED);
-		return;
+		return -EIO;
 	}
+
+	return 0;
 }
 
 static void prepare_ft(struct netdev *netdev, struct scan_bss *target_bss)
Signature · 1 line
2.26.2
#14 lore raw
In reply to James Prestwood

Hi James,

Quoted 4 lines · James Prestwood

This adds the RSNE verification to ft_parse_ies which will be common between over-Air and over-DS. The MDE check was also factored out into its own minimal function as to retain the spec comment but allow reuse elsewhere.

Quoted 8 lines
---
  src/ft.c | 125 +++++++++++++++++++++++++++++--------------------------
  1 file changed, 66 insertions(+), 59 deletions(-)

v4:
* Moved MDE check into its own function to avoid duplicate comments

I took the first 4 patches from this series.

Regards,
-Denis