1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
6 * Purpose: Implement functions for 802.11i Key management
22 int vnt_key_init_table(struct vnt_private *priv)
25 u8 data[MAX_KEY_TABLE];
27 for (i = 0; i < MAX_KEY_TABLE; i++)
30 return vnt_control_out(priv, MESSAGE_TYPE_CLRKEYENTRY,
31 0, 0, ARRAY_SIZE(data), data);
34 static int vnt_set_keymode(struct ieee80211_hw *hw, u8 *mac_addr,
35 struct ieee80211_key_conf *key, u32 key_type,
38 struct vnt_private *priv = hw->priv;
39 u8 broadcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
43 u8 key_inx = key->keyidx;
49 bssid = &broadcast[0];
51 if (key_type != VNT_KEY_DEFAULTKEY) {
52 for (i = 0; i < (MAX_KEY_TABLE - 1); i++) {
53 if (!test_bit(i, &priv->key_entry_inuse)) {
54 set_bit(i, &priv->key_entry_inuse);
57 entry = key->hw_key_idx;
64 case VNT_KEY_DEFAULTKEY:
65 /* default key last entry */
66 entry = MAX_KEY_TABLE - 1;
67 key->hw_key_idx = entry;
69 case VNT_KEY_GROUP_ADDRESS:
70 key_mode = mode | (mode << 4);
75 case VNT_KEY_PAIRWISE:
85 if (mode == KEY_CTL_WEP) {
86 if (key->keylen == WLAN_KEY_LEN_WEP40)
88 if (key->keylen == WLAN_KEY_LEN_WEP104)
92 return vnt_mac_set_keyentry(priv, key_mode, entry,
93 key_inx, bssid, key->key);
96 int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
97 struct ieee80211_vif *vif, struct ieee80211_key_conf *key)
99 struct vnt_private *priv = hw->priv;
104 mac_addr = &sta->addr[0];
106 switch (key->cipher) {
107 case WLAN_CIPHER_SUITE_WEP40:
108 case WLAN_CIPHER_SUITE_WEP104:
109 vnt_set_keymode(hw, mac_addr, key, VNT_KEY_DEFAULTKEY,
112 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
114 return vnt_set_keymode(hw, mac_addr, key, VNT_KEY_DEFAULTKEY,
117 case WLAN_CIPHER_SUITE_TKIP:
118 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
119 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
121 key_dec_mode = KEY_CTL_TKIP;
124 case WLAN_CIPHER_SUITE_CCMP:
125 if (priv->local_id <= MAC_REVISION_A1)
128 key_dec_mode = KEY_CTL_CCMP;
130 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
136 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
137 return vnt_set_keymode(hw, mac_addr, key, VNT_KEY_PAIRWISE,
140 return vnt_set_keymode(hw, mac_addr, key,
141 VNT_KEY_GROUP_ADDRESS, key_dec_mode);