mt76: mt7915: fix key set/delete issue
authorFelix Fietkau <nbd@nbd.name>
Mon, 22 Mar 2021 20:39:57 +0000 (21:39 +0100)
committerFelix Fietkau <nbd@nbd.name>
Sun, 11 Apr 2021 22:03:03 +0000 (00:03 +0200)
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

Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7915/main.c

index cde8c1ce3ae09c5996431d1abb00b02e45013e39..b32a435688bcd48c844d4fa61983f33bb6401f92 100644 (file)
@@ -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)