Wireless Daemon for Linux
 help / color / mirror / Atom feed
* [PATCH v2 5/9] ft: get OCI prior to reassociation
@ 2021-09-28 15:46 James Prestwood
  0 siblings, 0 replies; 2+ messages in thread
From: James Prestwood @ 2021-09-28 15:46 UTC (permalink / raw)
  To: iwd 

[-- Attachment #1: Type: text/plain, Size: 5110 bytes --]

This modifies the FT logic to fist call get_oci() before
reassociation. This allows the OCI to be included in reassociation
and in the 4-way handshake later on.

The code path for getting the OCI had to be slightly changed to
handle an OCI that is already set. First the handshake chandef is
NULL'ed out for any new connection. This prevents a stale OCI from
being used. Then some checks were added for this case in
netdev_connect_event and if chandef is already set, start the 4-way
handshake.
---
 src/ft.c     | 13 ++++++++++++-
 src/ft.h     |  2 ++
 src/netdev.c | 29 ++++++++++++++++++++++++++---
 3 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/src/ft.c b/src/ft.c
index 6897f6d7..40e29341 100644
--- a/src/ft.c
+++ b/src/ft.c
@@ -40,6 +40,7 @@ struct ft_sm {
 
 	ft_tx_authenticate_func_t tx_auth;
 	ft_tx_associate_func_t tx_assoc;
+	ft_get_oci get_oci;
 
 	void *user_data;
 };
@@ -640,7 +641,7 @@ static int ft_rx_authenticate(struct auth_proto *ap, const uint8_t *frame,
 	if (ret < 0)
 		goto auth_error;
 
-	return ft_tx_reassociate(ft);
+	return ft->get_oci(ft->user_data);
 
 auth_error:
 	return (int)status_code;
@@ -783,6 +784,13 @@ static int ft_rx_associate(struct auth_proto *ap, const uint8_t *frame,
 	return 0;
 }
 
+static int ft_rx_oci(struct auth_proto *ap)
+{
+	struct ft_sm *ft = l_container_of(ap, struct ft_sm, ap);
+
+	return ft_tx_reassociate(ft);
+}
+
 static void ft_sm_free(struct auth_proto *ap)
 {
 	struct ft_sm *ft = l_container_of(ap, struct ft_sm, ap);
@@ -890,12 +898,14 @@ static bool ft_start(struct auth_proto *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,
+				ft_get_oci get_oci,
 				void *user_data)
 {
 	struct ft_sm *ft = l_new(struct ft_sm, 1);
 
 	ft->tx_auth = tx_auth;
 	ft->tx_assoc = tx_assoc;
+	ft->get_oci = get_oci;
 	ft->hs = hs;
 	ft->user_data = user_data;
 
@@ -903,6 +913,7 @@ struct auth_proto *ft_over_air_sm_new(struct handshake_state *hs,
 	ft->ap.rx_associate = ft_rx_associate;
 	ft->ap.start = ft_start;
 	ft->ap.free = ft_sm_free;
+	ft->ap.rx_oci = ft_rx_oci;
 
 	return &ft->ap;
 }
diff --git a/src/ft.h b/src/ft.h
index 6167e0d7..cc25463f 100644
--- a/src/ft.h
+++ b/src/ft.h
@@ -26,6 +26,7 @@ typedef void (*ft_tx_authenticate_func_t)(struct iovec *iov, size_t iov_len,
 					void *user_data);
 typedef int (*ft_tx_associate_func_t)(struct iovec *ie_iov, size_t iov_len,
 					void *user_data);
+typedef int (*ft_get_oci)(void *user_data);
 
 typedef void (*ft_ds_free_func_t)(void *user_data);
 
@@ -60,6 +61,7 @@ bool ft_over_ds_parse_action_ies(struct ft_ds_info *info,
 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,
+				ft_get_oci get_oci,
 				void *user_data);
 
 struct auth_proto *ft_over_ds_sm_new(struct handshake_state *hs,
diff --git a/src/netdev.c b/src/netdev.c
index 9a4eff0f..a0669173 100644
--- a/src/netdev.c
+++ b/src/netdev.c
@@ -2074,6 +2074,21 @@ static void netdev_get_oci_cb(struct l_genl_msg *msg, void *user_data)
 	handshake_state_set_chandef(netdev->handshake, l_steal_ptr(chandef));
 
 done:
+	if (netdev->ap) {
+		/*
+		 * Cant do much here. IWD assumes every kernel/driver supports
+		 * this. There is no way of detecting support either.
+		 */
+		if (L_WARN_ON(err < 0))
+			netdev_connect_failed(netdev,
+					NETDEV_RESULT_AUTHENTICATION_FAILED,
+					MMPDU_STATUS_CODE_UNSPECIFIED);
+		else
+			auth_proto_rx_oci(netdev->ap);
+
+		return;
+	}
+
 	L_WARN_ON(!eapol_start(netdev->sm));
 }
 
@@ -2581,8 +2596,11 @@ process_resp_ies:
 	}
 
 	if (netdev->sm) {
-		if (netdev_get_oci(netdev) < 0)
-			goto deauth;
+		if (!netdev->handshake->chandef) {
+			if (netdev_get_oci(netdev) < 0)
+				goto deauth;
+		} else if (!eapol_start(netdev->sm))
+				goto deauth;
 
 		return;
 	}
@@ -3633,6 +3651,8 @@ static void netdev_connect_common(struct netdev *netdev,
 	netdev->privacy = bss->capability & IE_BSS_CAP_PRIVACY;
 	handshake_state_set_authenticator_address(hs, bss->addr);
 
+	handshake_state_set_chandef(hs, NULL);
+
 	if (!is_rsn)
 		goto build_cmd_connect;
 
@@ -4099,6 +4119,8 @@ static void prepare_ft(struct netdev *netdev, const struct scan_bss *target_bss)
 	netdev->operational = false;
 	netdev->in_ft = true;
 
+	handshake_state_set_chandef(netdev->handshake, NULL);
+
 	/*
 	 * Cancel commands that could be running because of EAPoL activity
 	 * like re-keying, this way the callbacks for those commands don't
@@ -4273,7 +4295,8 @@ int netdev_fast_transition(struct netdev *netdev,
 
 	netdev->ap = ft_over_air_sm_new(netdev->handshake,
 					netdev_ft_tx_authenticate,
-					netdev_ft_tx_associate, netdev);
+					netdev_ft_tx_associate,
+					netdev_get_oci, netdev);
 	memcpy(netdev->ap->prev_bssid, orig_bss->addr, ETH_ALEN);
 
 	wiphy_radio_work_insert(netdev->wiphy, &netdev->work, 1,
-- 
2.31.1

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

* Re: [PATCH v2 5/9] ft: get OCI prior to reassociation
@ 2021-09-28 16:03 Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2021-09-28 16:03 UTC (permalink / raw)
  To: iwd 

[-- Attachment #1: Type: text/plain, Size: 1273 bytes --]

Hi James,

On 9/28/21 10:46 AM, James Prestwood wrote:
> This modifies the FT logic to fist call get_oci() before
> reassociation. This allows the OCI to be included in reassociation
> and in the 4-way handshake later on.
> 
> The code path for getting the OCI had to be slightly changed to
> handle an OCI that is already set. First the handshake chandef is
> NULL'ed out for any new connection. This prevents a stale OCI from
> being used. Then some checks were added for this case in
> netdev_connect_event and if chandef is already set, start the 4-way
> handshake.
> ---
>   src/ft.c     | 13 ++++++++++++-
>   src/ft.h     |  2 ++
>   src/netdev.c | 29 ++++++++++++++++++++++++++---
>   3 files changed, 40 insertions(+), 4 deletions(-)
> 

<snip>

> @@ -3633,6 +3651,8 @@ static void netdev_connect_common(struct netdev *netdev,
>   	netdev->privacy = bss->capability & IE_BSS_CAP_PRIVACY;
>   	handshake_state_set_authenticator_address(hs, bss->addr);
>   
> +	handshake_state_set_chandef(hs, NULL);
> +
>   	if (!is_rsn)
>   		goto build_cmd_connect;
>   

netdev_connect_common always operates on a brand new handshake, so this should 
not be needed.  I took this out for now.

Patches 1-8 applied, thanks.

Regards,
-Denis

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

end of thread, other threads:[~2021-09-28 16:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-28 16:03 [PATCH v2 5/9] ft: get OCI prior to reassociation Denis Kenzior
  -- strict thread matches above, loose matches on Subject: below --
2021-09-28 15:46 James Prestwood

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