[PATCH 07/12] MLD STA: Add support to configure keys with MLO link ID param

Veerendranath Jakkam quic_vjakkam at quicinc.com
Wed Aug 24 22:53:06 PDT 2022


Add APIs to specify link ID for set key operations for MLO connection.

Signed-off-by: Veerendranath Jakkam <quic_vjakkam at quicinc.com>
---
 src/ap/ap_drv_ops.c          |  1 +
 src/drivers/driver.h         |  6 ++++++
 src/drivers/driver_nl80211.c | 15 +++++++++++++++
 src/rsn_supp/wpa.h           |  4 ++++
 src/rsn_supp/wpa_i.h         | 12 ++++++++++++
 wpa_supplicant/driver_i.h    | 24 ++++++++++++++++++------
 wpa_supplicant/wpas_glue.c   | 16 ++++++++++++++++
 7 files changed, 72 insertions(+), 6 deletions(-)

diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c
index 87c3b9006..2102a2898 100644
--- a/src/ap/ap_drv_ops.c
+++ b/src/ap/ap_drv_ops.c
@@ -716,6 +716,7 @@ int hostapd_drv_set_key(const char *ifname, struct hostapd_data *hapd,
 	params.key_len = key_len;
 	params.vlan_id = vlan_id;
 	params.key_flag = key_flag;
+	params.link_id = -1;
 
 	return hapd->driver->set_key(hapd->drv_priv, &params);
 }
diff --git a/src/drivers/driver.h b/src/drivers/driver.h
index 3602224b6..9a2d9bbc2 100644
--- a/src/drivers/driver.h
+++ b/src/drivers/driver.h
@@ -1772,6 +1772,12 @@ struct wpa_driver_set_key_params {
 	 * %KEY_FLAG_RX_TX
 	 *  RX/TX key. */
 	enum key_flag key_flag;
+
+	/**
+	 * link_id - MLO link ID
+	 *
+	 * set to valid link ID (0-14) when applicable, otherwise -1 */
+	int link_id;
 };
 
 enum wpa_driver_if_type {
diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index a4675eb1d..af9d53b45 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -3343,6 +3343,7 @@ static int wpa_driver_nl80211_set_key(struct i802_bss *bss,
 	size_t key_len = params->key_len;
 	int vlan_id = params->vlan_id;
 	enum key_flag key_flag = params->key_flag;
+	int link_id = params->link_id;
 
 	/* Ignore for P2P Device */
 	if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
@@ -3479,6 +3480,13 @@ static int wpa_driver_nl80211_set_key(struct i802_bss *bss,
 			goto fail;
 	}
 
+	if (link_id != -1) {
+		wpa_printf(MSG_DEBUG, "nl80211: Link ID %d",
+			   link_id);
+		if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))
+			goto fail;
+	}
+
 	ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL);
 	if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE)
 		ret = 0;
@@ -3541,6 +3549,13 @@ static int wpa_driver_nl80211_set_key(struct i802_bss *bss,
 			goto fail;
 	}
 
+	if (link_id != -1) {
+		wpa_printf(MSG_DEBUG, "nl80211: set_key default - Link ID %d",
+			   link_id);
+		if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))
+			goto fail;
+	}
+
 	ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL);
 	if (ret)
 		wpa_printf(MSG_DEBUG,
diff --git a/src/rsn_supp/wpa.h b/src/rsn_supp/wpa.h
index a56802b0a..ecfcf277f 100644
--- a/src/rsn_supp/wpa.h
+++ b/src/rsn_supp/wpa.h
@@ -33,6 +33,10 @@ struct wpa_sm_ctx {
 		       const u8 *addr, int key_idx, int set_tx,
 		       const u8 *seq, size_t seq_len,
 		       const u8 *key, size_t key_len, enum key_flag key_flag);
+	int (*mlo_set_key)(void *ctx, u8 link_id, enum wpa_alg alg,
+			   const u8 *addr, int key_idx, int set_tx,
+			   const u8 *seq, size_t seq_len, const u8 *key,
+			   size_t key_len, enum key_flag key_flag);
 	void * (*get_network_ctx)(void *ctx);
 	int (*get_bssid)(void *ctx, u8 *bssid);
 	int (*ether_send)(void *ctx, const u8 *dest, u16 proto, const u8 *buf,
diff --git a/src/rsn_supp/wpa_i.h b/src/rsn_supp/wpa_i.h
index 8bf0f28d8..f60616352 100644
--- a/src/rsn_supp/wpa_i.h
+++ b/src/rsn_supp/wpa_i.h
@@ -259,6 +259,18 @@ static inline int wpa_sm_set_key(struct wpa_sm *sm, enum wpa_alg alg,
 				seq, seq_len, key, key_len, key_flag);
 }
 
+static inline int wpa_sm_mlo_set_key(struct wpa_sm *sm, u8 link_id,
+				     enum wpa_alg alg, const u8 *addr,
+				     int key_idx, int set_tx, const u8 *seq,
+				     size_t seq_len, const u8 *key,
+				     size_t key_len, enum key_flag key_flag)
+{
+	WPA_ASSERT(sm->ctx->mlo_set_key);
+	return sm->ctx->mlo_set_key(sm->ctx->ctx, link_id, alg, addr, key_idx,
+				    set_tx, seq, seq_len, key, key_len,
+				    key_flag);
+}
+
 static inline void wpa_sm_reconnect(struct wpa_sm *sm)
 {
 	WPA_ASSERT(sm->ctx->reconnect);
diff --git a/wpa_supplicant/driver_i.h b/wpa_supplicant/driver_i.h
index 0c838d341..841e147e2 100644
--- a/wpa_supplicant/driver_i.h
+++ b/wpa_supplicant/driver_i.h
@@ -143,12 +143,12 @@ static inline int wpa_drv_get_ssid(struct wpa_supplicant *wpa_s, u8 *ssid)
 	return -1;
 }
 
-static inline int wpa_drv_set_key(struct wpa_supplicant *wpa_s,
-				  enum wpa_alg alg, const u8 *addr,
-				  int key_idx, int set_tx,
-				  const u8 *seq, size_t seq_len,
-				  const u8 *key, size_t key_len,
-				  enum key_flag key_flag)
+static inline int wpa_drv_mlo_set_key(struct wpa_supplicant *wpa_s, int link_id,
+				      enum wpa_alg alg, const u8 *addr,
+				      int key_idx, int set_tx,
+				      const u8 *seq, size_t seq_len,
+				      const u8 *key, size_t key_len,
+				      enum key_flag key_flag)
 {
 	struct wpa_driver_set_key_params params;
 
@@ -163,6 +163,7 @@ static inline int wpa_drv_set_key(struct wpa_supplicant *wpa_s,
 	params.key = key;
 	params.key_len = key_len;
 	params.key_flag = key_flag;
+	params.link_id = link_id;
 
 	if (alg != WPA_ALG_NONE) {
 		/* keyidx = 1 can be either a broadcast or--with
@@ -183,6 +184,17 @@ static inline int wpa_drv_set_key(struct wpa_supplicant *wpa_s,
 	return -1;
 }
 
+static inline int wpa_drv_set_key(struct wpa_supplicant *wpa_s,
+				  enum wpa_alg alg, const u8 *addr,
+				  int key_idx, int set_tx,
+				  const u8 *seq, size_t seq_len,
+				  const u8 *key, size_t key_len,
+				  enum key_flag key_flag)
+{
+	return wpa_drv_mlo_set_key(wpa_s, -1, alg, addr, key_idx, set_tx,
+				   seq, seq_len, key, key_len, key_flag);
+}
+
 static inline int wpa_drv_get_seqnum(struct wpa_supplicant *wpa_s,
 				     const u8 *addr, int idx, u8 *seq)
 {
diff --git a/wpa_supplicant/wpas_glue.c b/wpa_supplicant/wpas_glue.c
index 2784fb096..62e7e3c5a 100644
--- a/wpa_supplicant/wpas_glue.c
+++ b/wpa_supplicant/wpas_glue.c
@@ -625,6 +625,21 @@ static int wpa_supplicant_set_key(void *_wpa_s, enum wpa_alg alg,
 }
 
 
+static int wpa_supplicant_mlo_set_key(void *_wpa_s, u8 link_id,
+				      enum wpa_alg alg, const u8 *addr,
+				      int key_idx, int set_tx, const u8 *seq,
+				      size_t seq_len, const u8 *key,
+				      size_t key_len, enum key_flag key_flag)
+{
+	struct wpa_supplicant *wpa_s = _wpa_s;
+	if (alg == WPA_ALG_TKIP && key_idx == 0 && key_len == 32) {
+		/* Clear the MIC error counter when setting a new PTK. */
+		wpa_s->mic_errors_seen = 0;
+	}
+	return wpa_drv_mlo_set_key(wpa_s, link_id, alg, addr, key_idx, set_tx, seq,
+			       seq_len, key, key_len, key_flag);
+}
+
 static int wpa_supplicant_mlme_setprotection(void *wpa_s, const u8 *addr,
 					     int protection_type,
 					     int key_type)
@@ -1476,6 +1491,7 @@ int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
 	ctx->deauthenticate = _wpa_supplicant_deauthenticate;
 	ctx->reconnect = _wpa_supplicant_reconnect;
 	ctx->set_key = wpa_supplicant_set_key;
+	ctx->mlo_set_key = wpa_supplicant_mlo_set_key;
 	ctx->get_network_ctx = wpa_supplicant_get_network_ctx;
 	ctx->get_bssid = wpa_supplicant_get_bssid;
 	ctx->ether_send = _wpa_ether_send;
-- 
2.25.1




More information about the Hostap mailing list