2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * Purpose: Implement functions for 802.11i Key management
34 static int vnt_set_keymode(struct ieee80211_hw *hw, u8 *mac_addr,
35 struct ieee80211_key_conf *key, u32 key_type, u32 mode,
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;
65 case VNT_KEY_DEFAULTKEY:
66 /* default key last entry */
67 entry = MAX_KEY_TABLE - 1;
68 key->hw_key_idx = entry;
69 case VNT_KEY_ALLGROUP:
70 key_mode |= VNT_KEY_ALLGROUP;
72 key_mode |= VNT_KEY_ONFLY_ALL;
73 case VNT_KEY_GROUP_ADDRESS:
76 key_mode |= (mode << 4);
77 key_mode |= VNT_KEY_GROUP;
79 case VNT_KEY_PAIRWISE:
88 key_mode |= VNT_KEY_ONFLY;
90 if (mode == KEY_CTL_WEP) {
91 if (key->keylen == WLAN_KEY_LEN_WEP40)
93 if (key->keylen == WLAN_KEY_LEN_WEP104)
97 MACvSetKeyEntry(priv, key_mode, entry, key_inx,
98 bssid, (u32 *)key->key, priv->byLocalID);
103 int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
104 struct ieee80211_vif *vif, struct ieee80211_key_conf *key)
106 struct ieee80211_bss_conf *conf = &vif->bss_conf;
107 struct vnt_private *priv = hw->priv;
114 mac_addr = &sta->addr[0];
116 switch (key->cipher) {
118 for (u = 0 ; u < MAX_KEY_TABLE; u++)
119 MACvDisableKeyEntry(priv, u);
122 case WLAN_CIPHER_SUITE_WEP40:
123 case WLAN_CIPHER_SUITE_WEP104:
124 for (u = 0; u < MAX_KEY_TABLE; u++)
125 MACvDisableKeyEntry(priv, u);
127 vnt_set_keymode(hw, mac_addr,
128 key, VNT_KEY_DEFAULTKEY, KEY_CTL_WEP, true);
130 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
133 case WLAN_CIPHER_SUITE_TKIP:
134 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
135 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
137 key_dec_mode = KEY_CTL_TKIP;
140 case WLAN_CIPHER_SUITE_CCMP:
141 key_dec_mode = KEY_CTL_CCMP;
143 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
146 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
147 vnt_set_keymode(hw, mac_addr,
148 key, VNT_KEY_PAIRWISE, key_dec_mode, true);
150 vnt_set_keymode(hw, mac_addr,
151 key, VNT_KEY_DEFAULTKEY, key_dec_mode, true);
153 vnt_set_keymode(hw, (u8 *)conf->bssid,
154 key, VNT_KEY_GROUP_ADDRESS, key_dec_mode, true);