Linux wireless drivers development
 help / color / mirror / Atom feed
From: Felix Fietkau <nbd@nbd.name>
To: linux-wireless@vger.kernel.org
Subject: [PATCH mt76-next 12/16] wifi: mt76: mt792x: reset the group RX PN counters at WoWLAN resume
Date: Thu, 26 Nov 2026 19:23:21 +0100	[thread overview]
Message-ID: <20261126182325.2516607-12-nbd@nbd.name> (raw)
In-Reply-To: <20261126182325.2516607-1-nbd@nbd.name>

With GTK rekey offload, the firmware can renew the GTK during WoWLAN
suspend without reporting it. If the new key reuses a key id whose
counters hold the PN of an earlier key, its frames read as replays after
resume.

At resume, zero the group counters of each link of an interface that
gave rekey data to the firmware. Where a link held a group key with a PN
check, also check key ids 1 to 3, since the new key can use any of them.
Forget the key ids at the end of an association, so that a reassociation
without such a key arms no check. After resume, a replay with a nonzero
PN passes until the first genuine frame of its key id and TID.

Pass no key at a key removal in mt7921_set_key(), as
mt7925_set_link_key() does, since the keys of an association go after
its end and would mark their key ids again.

Fixes: ffa1bf97425b ("mt76: mt7921: introduce PM support")
Fixes: c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
 .../net/wireless/mediatek/mt76/mt7921/main.c  | 10 +++++-
 .../net/wireless/mediatek/mt76/mt7925/main.c  |  8 +++++
 drivers/net/wireless/mediatek/mt76/mt792x.h   |  4 +++
 .../net/wireless/mediatek/mt76/mt792x_core.c  | 36 +++++++++++++++++++
 4 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
index eaf8e5098b0c..23f92ce01080 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
@@ -562,7 +562,7 @@ static int mt7921_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 			goto out;
 	}
 
-	mt76_wcid_key_setup(&dev->mt76, wcid, key);
+	mt76_wcid_key_setup(&dev->mt76, wcid, cmd == SET_KEY ? key : NULL);
 	err = mt76_connac_mcu_add_key(&dev->mt76, vif, &msta->deflink.bip,
 				      key, MCU_UNI_CMD(STA_REC_UPDATE),
 				      &msta->deflink.wcid, cmd);
@@ -731,6 +731,8 @@ static void mt7921_bss_info_changed(struct ieee80211_hw *hw,
 		mt7921_mcu_sta_update(dev, NULL, vif, true,
 				      MT76_STA_INFO_STATE_ASSOC);
 		mt7921_mcu_set_beacon_filter(dev, vif, vif->cfg.assoc);
+		if (!vif->cfg.assoc)
+			mt792x_rx_group_pn_forget(vif);
 	}
 
 	if (changed & BSS_CHANGED_ARP_FILTER) {
@@ -1182,6 +1184,10 @@ static int mt7921_resume(struct ieee80211_hw *hw)
 	mt792x_mutex_acquire(dev);
 
 	set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
+	ieee80211_iterate_active_interfaces_mtx(hw,
+						IEEE80211_IFACE_ITER_RESUME_ALL,
+						mt792x_rx_group_pn_reset_iter,
+						NULL);
 	ieee80211_iterate_active_interfaces_mtx(hw,
 						IEEE80211_IFACE_ITER_RESUME_ALL,
 						mt76_connac_mcu_set_suspend_iter,
@@ -1199,10 +1205,12 @@ static void mt7921_set_rekey_data(struct ieee80211_hw *hw,
 				  struct ieee80211_vif *vif,
 				  struct cfg80211_gtk_rekey_data *data)
 {
+	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
 
 	mt792x_mutex_acquire(dev);
 	mt76_connac_mcu_update_gtk_rekey(hw, vif, data);
+	mvif->gtk_rekey_offload = true;
 	mt792x_mutex_release(dev);
 }
 #endif /* CONFIG_PM */
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
index 3e614af35141..6b3f2dafae4d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
@@ -2027,6 +2027,10 @@ static int mt7925_resume(struct ieee80211_hw *hw)
 	mt792x_mutex_acquire(dev);
 
 	set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
+	ieee80211_iterate_active_interfaces_mtx(hw,
+						IEEE80211_IFACE_ITER_RESUME_ALL,
+						mt792x_rx_group_pn_reset_iter,
+						NULL);
 	ieee80211_iterate_active_interfaces_mtx(hw,
 						IEEE80211_IFACE_ITER_RESUME_ALL,
 						mt7925_mcu_set_suspend_iter,
@@ -2044,10 +2048,12 @@ static void mt7925_set_rekey_data(struct ieee80211_hw *hw,
 				  struct ieee80211_vif *vif,
 				  struct cfg80211_gtk_rekey_data *data)
 {
+	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
 
 	mt792x_mutex_acquire(dev);
 	mt76_connac_mcu_update_gtk_rekey(hw, vif, data);
+	mvif->gtk_rekey_offload = true;
 	mt792x_mutex_release(dev);
 }
 #endif /* CONFIG_PM */
@@ -2468,6 +2474,8 @@ static void mt7925_vif_cfg_changed(struct ieee80211_hw *hw,
 				      &mvif->sta.deflink, true,
 				      MT76_STA_INFO_STATE_ASSOC, NULL);
 		mt7925_mcu_set_beacon_filter(dev, vif, vif->cfg.assoc);
+		if (!vif->cfg.assoc)
+			mt792x_rx_group_pn_forget(vif);
 
 		if (ieee80211_vif_is_mld(vif))
 			mvif->mlo_pm_state = MT792x_MLO_LINK_ASSOC;
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x.h b/drivers/net/wireless/mediatek/mt76/mt792x.h
index 260abdc978f8..fa64dd2ae28a 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x.h
+++ b/drivers/net/wireless/mediatek/mt76/mt792x.h
@@ -250,6 +250,7 @@ struct mt792x_vif {
 
 	struct mt792x_phy *phy;
 	bool roc_join_held; /* join ROC kept until the STA is authorized */
+	bool gtk_rekey_offload;
 	u16 valid_links;
 	u8 deflink_id;
 	enum mt792x_mlo_pm_state mlo_pm_state;
@@ -622,6 +623,9 @@ void mt792x_unassign_vif_chanctx(struct ieee80211_hw *hw,
 				 struct ieee80211_bss_conf *link_conf,
 				 struct ieee80211_chanctx_conf *ctx);
 void mt792x_set_wakeup(struct ieee80211_hw *hw, bool enabled);
+void mt792x_rx_group_pn_reset_iter(void *priv, u8 *mac,
+				   struct ieee80211_vif *vif);
+void mt792x_rx_group_pn_forget(struct ieee80211_vif *vif);
 void mt792x_get_et_strings(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 			   u32 sset, u8 *data);
 int mt792x_get_et_sset_count(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_core.c b/drivers/net/wireless/mediatek/mt76/mt792x_core.c
index 7dddce02d600..99bcd90f8e1a 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x_core.c
+++ b/drivers/net/wireless/mediatek/mt76/mt792x_core.c
@@ -559,6 +559,42 @@ void mt792x_set_wakeup(struct ieee80211_hw *hw, bool enabled)
 }
 EXPORT_SYMBOL_GPL(mt792x_set_wakeup);
 
+void mt792x_rx_group_pn_reset_iter(void *priv, u8 *mac,
+				   struct ieee80211_vif *vif)
+{
+	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
+	unsigned long valid = ieee80211_vif_is_mld(vif) ?
+			      mvif->valid_links : BIT(0);
+	unsigned int link_id;
+
+	if (!mvif->gtk_rekey_offload)
+		return;
+
+	for_each_set_bit(link_id, &valid, IEEE80211_MLD_MAX_NUM_LINKS) {
+		struct mt792x_bss_conf *mconf = mt792x_vif_to_link(mvif, link_id);
+
+		mt76_rx_group_pn_reset(&mconf->mt76.rx_group_pn);
+	}
+}
+EXPORT_SYMBOL_GPL(mt792x_rx_group_pn_reset_iter);
+
+void mt792x_rx_group_pn_forget(struct ieee80211_vif *vif)
+{
+	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
+	unsigned long valid = ieee80211_vif_is_mld(vif) ?
+			      mvif->valid_links : BIT(0);
+	unsigned int link_id;
+
+	mvif->gtk_rekey_offload = false;
+	mvif->bss_conf.mt76.rx_group_pn.key_mask = 0;
+	for_each_set_bit(link_id, &valid, IEEE80211_MLD_MAX_NUM_LINKS) {
+		struct mt792x_bss_conf *mconf = mt792x_vif_to_link(mvif, link_id);
+
+		mconf->mt76.rx_group_pn.key_mask = 0;
+	}
+}
+EXPORT_SYMBOL_GPL(mt792x_rx_group_pn_forget);
+
 static const char mt792x_gstrings_stats[][ETH_GSTRING_LEN] = {
 	/* tx counters */
 	"tx_ampdu_cnt",
-- 
2.47.3


  parent reply	other threads:[~2026-11-26 18:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 18:23 [PATCH mt76-next 01/16] wifi: mt76: keep the Null frame of an AP on its AC queue Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 02/16] wifi: mt76: mt7996: limit the HE and EHT maps of a peer to its rx_nss Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 03/16] wifi: mt76: mt7915: send the current SM power save mode in STA_REC_HT Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 04/16] wifi: mt76: mt7996: take the HE caps of the band of each link Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 05/16] wifi: mt76: mt7915: count the WA TX statistics from an unsolicited event Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 06/16] wifi: mt76: keep an RX replay counter per group key id and TID Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 07/16] wifi: mt76: mt7996: check the RX PN of group addressed frames Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 08/16] wifi: mt76: mt7615: " Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 09/16] wifi: mt76: mt7615: reset the group RX PN counters at WoWLAN resume Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 10/16] wifi: mt76: mt7915: check the RX PN of group addressed frames Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 11/16] wifi: mt76: mt792x: " Felix Fietkau
2026-11-26 18:23 ` Felix Fietkau [this message]
2026-11-26 18:23 ` [PATCH mt76-next 13/16] wifi: mt76: mt7603: " Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 14/16] wifi: mt76: mt76x02: find no station for the group wcid of a vif Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 15/16] wifi: mt76: mt7915: stop resets before the hw is unregistered Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 16/16] wifi: mt76: mt7996: " Felix Fietkau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126182325.2516607-12-nbd@nbd.name \
    --to=nbd@nbd.name \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox