Skip to contentSkip to conversation

mt76: mt7915: fix key set/delete issue

PATCH New Felix Fietkau 2 participants 3 messages Mar 26, 2021 – Mar 29, 2021

Subsystems (2)
lore
Share & tools
lore

Felix Fietkau

author maintainer
#0 lore raw

PATCH 1/2 mt76: mt7915: fix key set/delete issue

Deleting a key with the previous key index deletes the current key Rework the code to better keep track of multiple keys and check for the key index before deleting the current key

---
 .../net/wireless/mediatek/mt76/mt7915/main.c  | 25 +++++++++++++------
 1 file changed, 18 insertions(+), 7 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/main.c +18 -7
index cde8c1ce3ae0..b32a435688bc 100644
@@ -346,7 +346,9 @@ static int mt7915_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 	struct mt7915_sta *msta = sta ? (struct mt7915_sta *)sta->drv_priv :
 				  &mvif->sta;
 	struct mt76_wcid *wcid = &msta->wcid;
+	u8 *wcid_keyidx = &wcid->hw_key_idx;
 	int idx = key->keyidx;
+	int err = 0;
 
 	/* The hardware does not support per-STA RX GTK, fallback
 	 * to software mode for these.
@@ -361,6 +363,7 @@ static int mt7915_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 	/* fall back to sw encryption for unsupported ciphers */
 	switch (key->cipher) {
 	case WLAN_CIPHER_SUITE_AES_CMAC:
+		wcid_keyidx = &wcid->hw_key_idx2;
 		key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE;
 		break;
 	case WLAN_CIPHER_SUITE_TKIP:
@@ -376,16 +379,24 @@ static int mt7915_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 		return -EOPNOTSUPP;
 	}
 
-	if (cmd == SET_KEY) {
-		key->hw_key_idx = wcid->idx;
-		wcid->hw_key_idx = idx;
-	} else if (idx == wcid->hw_key_idx) {
-		wcid->hw_key_idx = -1;
-	}
+	mutex_lock(&dev->mt76.mutex);
+
+	if (cmd == SET_KEY)
+		*wcid_keyidx = idx;
+	else if (idx == *wcid_keyidx)
+		*wcid_keyidx = -1;
+	else
+		goto out;
+
 	mt76_wcid_key_setup(&dev->mt76, wcid,
 			    cmd == SET_KEY ? key : NULL);
 
-	return mt7915_mcu_add_key(dev, vif, msta, key, cmd);
+	err = mt7915_mcu_add_key(dev, vif, msta, key, cmd);
+
+out:
+	mutex_unlock(&dev->mt76.mutex);
+
+	return err;
 }
 
 static int mt7915_config(struct ieee80211_hw *hw, u32 changed)
Signature · 1 line
2.30.1
author maintainer
#1 lore raw

PATCH 2/2 mt76: mt7915: refresh repeater entry MAC address when setting BSSID

When disassociating and clearing the BSSID of a repeater entry used by a client mode interface, the corresponding MAC address entry can get lost too, causing the client interface to not be able to associate anymore.
Fix this by also refreshing the MAC address when setting the BSSID

---
 drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +3 -1
index 29b5039cc286..9d0911ac1d90 100644
@@ -1008,8 +1008,10 @@ int mt7915_mcu_add_bss_info(struct mt7915_phy *phy,
 	struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
 	struct sk_buff *skb;
 
-	if (mvif->omac_idx >= REPEATER_BSSID_START)
+	if (mvif->omac_idx >= REPEATER_BSSID_START) {
+		mt7915_mcu_muar_config(phy, vif, false, enable);
 		mt7915_mcu_muar_config(phy, vif, true, enable);
+	}
 
 	skb = mt7915_mcu_alloc_sta_req(phy->dev, mvif, NULL,
 				       MT7915_BSS_UPDATE_MAX_SIZE);
Signature · 1 line
2.30.1
#2 lore raw
In reply to Felix Fietkau
I love your patch! Yet something to improve:

Hi Felix,

I love your patch! Yet something to improve:

[auto build test ERROR on wireless-drivers-next/master]
[also build test ERROR on wireless-drivers/master v5.12-rc5 next-20210326] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Felix-Fietkau/mt76-mt7915-fix-key-set-delete-issue/20210326-161822
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/wireless-drivers-next.git master
config: x86_64-allyesconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/43916f806ad4074c7fd5177238f448cf09d2e4df
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Felix-Fietkau/mt76-mt7915-fix-key-set-delete-issue/20210326-161822
        git checkout 43916f806ad4074c7fd5177238f448cf09d2e4df
        # save the attached .config to linux build tree
        make W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

drivers/net/wireless/mediatek/mt76/mt7915/main.c: In function 'mt7915_set_key':

>> drivers/net/wireless/mediatek/mt76/mt7915/main.c:337:24: error: 'struct mt76_wcid' has no member named 'hw_key_idx2'; did you mean 'hw_key_idx'?
     337 |   wcid_keyidx = &wcid->hw_key_idx2;
         |                        ^~~~~~~~~~~
         |                        hw_key_idx

vim +337 drivers/net/wireless/mediatek/mt76/mt7915/main.c

310
311 static int mt7915_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
312 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
313 struct ieee80211_key_conf *key)
314 {
315 struct mt7915_dev *dev = mt7915_hw_dev(hw);
316 struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
317 struct mt7915_sta *msta = sta ? (struct mt7915_sta *)sta->drv_priv :
318 &mvif->sta;
319 struct mt76_wcid *wcid = &msta->wcid;
320 u8 *wcid_keyidx = &wcid->hw_key_idx;
321 int idx = key->keyidx;
322 int err = 0;
323
324 /* The hardware does not support per-STA RX GTK, fallback
325 * to software mode for these.
326 */
327 if ((vif->type == NL80211_IFTYPE_ADHOC ||
328 vif->type == NL80211_IFTYPE_MESH_POINT) &&
329 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
330 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
331 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
332 return -EOPNOTSUPP;
333
334 /* fall back to sw encryption for unsupported ciphers */
335 switch (key->cipher) {
336 case WLAN_CIPHER_SUITE_AES_CMAC:

 > 337			wcid_keyidx = &wcid->hw_key_idx2;

338 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE;
339 break;
340 case WLAN_CIPHER_SUITE_TKIP:
341 case WLAN_CIPHER_SUITE_CCMP:
342 case WLAN_CIPHER_SUITE_CCMP_256:
343 case WLAN_CIPHER_SUITE_GCMP:
344 case WLAN_CIPHER_SUITE_GCMP_256:
345 case WLAN_CIPHER_SUITE_SMS4:
346 break;
347 case WLAN_CIPHER_SUITE_WEP40:
348 case WLAN_CIPHER_SUITE_WEP104:
349 default:
350 return -EOPNOTSUPP;
351 }
352
353 mutex_lock(&dev->mt76.mutex);
354
355 if (cmd == SET_KEY)
356 *wcid_keyidx = idx;
357 else if (idx == *wcid_keyidx)
358 *wcid_keyidx = -1;
359 else
360 goto out;
361
362 mt76_wcid_key_setup(&dev->mt76, wcid,
363 cmd == SET_KEY ? key : NULL);
364
365 err = mt7915_mcu_add_key(dev, vif, msta, key, cmd);
366
367 out:
368 mutex_unlock(&dev->mt76.mutex);
369
370 return err;
371 }
372

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org