Linux wireless drivers development
 help / color / mirror / Atom feed
From: Felix Fietkau <nbd@nbd.name>
To: linux-wireless@vger.kernel.org
Subject: [PATCH mt76 08/15] wifi: mt76: mt7996: fix updating beacon protection with beacons enabled
Date: Mon, 15 Sep 2025 09:59:03 +0200	[thread overview]
Message-ID: <20250915075910.47558-8-nbd@nbd.name> (raw)
In-Reply-To: <20250915075910.47558-1-nbd@nbd.name>

Disable and re-enable beacon after beacon protection key change, in order
to fully apply the changes.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
 .../net/wireless/mediatek/mt76/mt7996/mac.c   |  3 +-
 .../net/wireless/mediatek/mt76/mt7996/main.c  | 35 ++++++++++++-------
 .../net/wireless/mediatek/mt76/mt7996/mcu.c   |  3 +-
 .../wireless/mediatek/mt76/mt7996/mt7996.h    |  2 +-
 4 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
index fd57569a7da7..289f69cc2bdf 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
@@ -2176,7 +2176,8 @@ mt7996_update_vif_beacon(void *priv, u8 *mac, struct ieee80211_vif *vif)
 		if (!link || link->phy != phy)
 			continue;
 
-		mt7996_mcu_add_beacon(dev->mt76.hw, vif, link_conf);
+		mt7996_mcu_add_beacon(dev->mt76.hw, vif, link_conf,
+				      link_conf->enable_beacon);
 	}
 }
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
index d706b8bb244e..581314368c5b 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
@@ -185,10 +185,13 @@ mt7996_set_hw_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 		  unsigned int link_id, struct ieee80211_key_conf *key)
 {
 	struct mt7996_dev *dev = mt7996_hw_dev(hw);
+	struct ieee80211_bss_conf *link_conf;
 	struct mt7996_sta_link *msta_link;
 	struct mt7996_vif_link *link;
 	int idx = key->keyidx;
 	u8 *wcid_keyidx;
+	bool is_bigtk;
+	int err;
 
 	link = mt7996_vif_link(dev, vif, link_id);
 	if (!link)
@@ -213,12 +216,13 @@ mt7996_set_hw_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 	}
 	wcid_keyidx = &msta_link->wcid.hw_key_idx;
 
+	is_bigtk = key->keyidx == 6 || key->keyidx == 7;
 	switch (key->cipher) {
 	case WLAN_CIPHER_SUITE_AES_CMAC:
 	case WLAN_CIPHER_SUITE_BIP_CMAC_256:
 	case WLAN_CIPHER_SUITE_BIP_GMAC_128:
 	case WLAN_CIPHER_SUITE_BIP_GMAC_256:
-		if (key->keyidx == 6 || key->keyidx == 7) {
+		if (is_bigtk) {
 			wcid_keyidx = &msta_link->wcid.hw_key_idx2;
 			key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE;
 		}
@@ -227,14 +231,11 @@ mt7996_set_hw_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 		break;
 	}
 
+	link_conf = link_conf_dereference_protected(vif, link_id);
+	if (!link_conf)
+		link_conf = &vif->bss_conf;
+
 	if (cmd == SET_KEY && !sta && !link->mt76.cipher) {
-		struct ieee80211_bss_conf *link_conf;
-
-		link_conf = link_conf_dereference_protected(vif,
-							    link_id);
-		if (!link_conf)
-			link_conf = &vif->bss_conf;
-
 		link->mt76.cipher =
 			mt76_connac_mcu_get_cipher(key->cipher);
 		mt7996_mcu_add_bss_info(link->phy, vif, link_conf,
@@ -251,9 +252,17 @@ mt7996_set_hw_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 
 	mt76_wcid_key_setup(&dev->mt76, &msta_link->wcid, key);
 
-	return mt7996_mcu_add_key(&dev->mt76, vif, key,
-				  MCU_WMWA_UNI_CMD(STA_REC_UPDATE),
-				  &msta_link->wcid, cmd);
+	err = mt7996_mcu_add_key(&dev->mt76, vif, key,
+				 MCU_WMWA_UNI_CMD(STA_REC_UPDATE),
+				 &msta_link->wcid, cmd);
+
+	/* remove and add beacon in order to enable beacon protection */
+	if (cmd == SET_KEY && is_bigtk && link_conf->enable_beacon) {
+		mt7996_mcu_add_beacon(hw, vif, link_conf, false);
+		mt7996_mcu_add_beacon(hw, vif, link_conf, true);
+	}
+
+	return err;
 }
 
 struct mt7996_key_iter_data {
@@ -900,7 +909,7 @@ mt7996_link_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 		link->mt76.beacon_rates_idx =
 			mt7996_get_rates_table(phy, info, true, false);
 
-		mt7996_mcu_add_beacon(hw, vif, info);
+		mt7996_mcu_add_beacon(hw, vif, info, info->enable_beacon);
 	}
 
 	if (changed & (BSS_CHANGED_UNSOL_BCAST_PROBE_RESP |
@@ -928,7 +937,7 @@ mt7996_channel_switch_beacon(struct ieee80211_hw *hw,
 	struct mt7996_dev *dev = mt7996_hw_dev(hw);
 
 	mutex_lock(&dev->mt76.mutex);
-	mt7996_mcu_add_beacon(hw, vif, &vif->bss_conf);
+	mt7996_mcu_add_beacon(hw, vif, &vif->bss_conf, vif->bss_conf.enable_beacon);
 	mutex_unlock(&dev->mt76.mutex);
 }
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
index 5707e6b59aea..07a1e542571c 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
@@ -2760,7 +2760,7 @@ mt7996_mcu_beacon_cont(struct mt7996_dev *dev,
 }
 
 int mt7996_mcu_add_beacon(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
-			  struct ieee80211_bss_conf *link_conf)
+			  struct ieee80211_bss_conf *link_conf, bool enabled)
 {
 	struct mt7996_dev *dev = mt7996_hw_dev(hw);
 	struct mt7996_vif_link *link = mt7996_vif_conf_link(dev, vif, link_conf);
@@ -2771,7 +2771,6 @@ int mt7996_mcu_add_beacon(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	struct tlv *tlv;
 	struct bss_bcn_content_tlv *bcn;
 	int len, extra_len = 0;
-	bool enabled = link_conf->enable_beacon;
 
 	if (link_conf->nontransmitted)
 		return 0;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
index fa10aa6f517a..8ec2acdb3319 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
@@ -682,7 +682,7 @@ int mt7996_mcu_update_bss_color(struct mt7996_dev *dev,
 				struct mt76_vif_link *mlink,
 				struct cfg80211_he_bss_color *he_bss_color);
 int mt7996_mcu_add_beacon(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
-			  struct ieee80211_bss_conf *link_conf);
+			  struct ieee80211_bss_conf *link_conf, bool enabled);
 int mt7996_mcu_beacon_inband_discov(struct mt7996_dev *dev,
 				    struct ieee80211_bss_conf *link_conf,
 				    struct mt7996_vif_link *link, u32 changed);
-- 
2.51.0


  parent reply	other threads:[~2025-09-15  7:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-15  7:58 [PATCH mt76 01/15] wifi: mt76: mt7996: remove redundant per-phy mac80211 calls during restart Felix Fietkau
2025-09-15  7:58 ` [PATCH mt76 02/15] wifi: mt76: mt7996: improve hardware restart reliability Felix Fietkau
2025-09-15  7:58 ` [PATCH mt76 03/15] wifi: mt76: mt7996: decrease timeout for commonly issued MCU commands Felix Fietkau
2025-09-15  7:58 ` [PATCH mt76 04/15] wifi: mt76: mt7996: fix setting beacon protection keys Felix Fietkau
2025-09-15  7:59 ` [PATCH mt76 05/15] wifi: mt76: mt7996: fix memory leak on mt7996_mcu_sta_key_tlv error Felix Fietkau
2025-09-15  7:59 ` [PATCH mt76 06/15] wifi: mt76: mt7996: delete vif keys when requested Felix Fietkau
2025-09-15  7:59 ` [PATCH mt76 07/15] wifi: mt76: mt7996: fix key add/remove imbalance Felix Fietkau
2025-09-15  7:59 ` Felix Fietkau [this message]
2025-09-15  7:59 ` [PATCH mt76 09/15] wifi: mt76: use altx queue for offchannel tx on connac+ Felix Fietkau
2025-09-15  7:59 ` [PATCH mt76 10/15] wifi: mt76: mt7996: disable promiscuous mode by default Felix Fietkau
2025-09-15  7:59 ` [PATCH mt76 11/15] wifi: mt76: mt7996: remove the mem_total field of STA_REC_BF command Felix Fietkau
2025-09-15  7:59 ` [PATCH mt76 12/15] wifi: mt76: mt7996: set VTA in txwi Felix Fietkau
2025-09-15  7:59 ` [PATCH mt76 13/15] wifi: mt76: mt7996: fill User Priority in skb->priority for rx packets Felix Fietkau
2025-09-15  7:59 ` [PATCH mt76 14/15] wifi: mt76: improve phy reset on hw restart Felix Fietkau
2025-09-15  7:59 ` [PATCH mt76 15/15] wifi: mt76: abort scan/roc " 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=20250915075910.47558-8-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