Skip to content

Commit

Permalink
mt76: mt7921: fix key set/delete issue
Browse files Browse the repository at this point in the history
Similar to the mt7915 driver, 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: Lorenzo Bianconi <lorenzo@kernel.org>
  • Loading branch information
LorenzoBianconi authored and nbd168 committed Mar 27, 2021
1 parent 465dda6 commit 62b13f5
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions mt7921/main.c
Expand Up @@ -412,7 +412,8 @@ static int mt7921_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
struct mt7921_sta *msta = sta ? (struct mt7921_sta *)sta->drv_priv :
&mvif->sta;
struct mt76_wcid *wcid = &msta->wcid;
int idx = key->keyidx;
u8 *wcid_keyidx = &wcid->hw_key_idx;
int idx = key->keyidx, err = 0;

/* The hardware does not support per-STA RX GTK, fallback
* to software mode for these.
Expand All @@ -428,6 +429,7 @@ static int mt7921_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
switch (key->cipher) {
case WLAN_CIPHER_SUITE_AES_CMAC:
key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE;
wcid_keyidx = &wcid->hw_key_idx2;
break;
case WLAN_CIPHER_SUITE_TKIP:
case WLAN_CIPHER_SUITE_CCMP:
Expand All @@ -442,16 +444,23 @@ static int mt7921_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;
}
mt7921_mutex_acquire(dev);

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 mt7921_mcu_add_key(dev, vif, msta, key, cmd);
err = mt7921_mcu_add_key(dev, vif, msta, key, cmd);
out:
mt7921_mutex_release(dev);

return err;
}

static int mt7921_config(struct ieee80211_hw *hw, u32 changed)
Expand Down

0 comments on commit 62b13f5

Please sign in to comment.