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.
17 * Purpose: Implement functions for 802.11i Key management
29 static int vnt_set_keymode(struct ieee80211_hw *hw, u8 *mac_addr,
30 struct ieee80211_key_conf *key, u32 key_type,
31 u32 mode, bool onfly_latch)
33 struct vnt_private *priv = hw->priv;
34 u8 broadcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
38 u8 key_inx = key->keyidx;
44 bssid = &broadcast[0];
46 if (key_type != VNT_KEY_DEFAULTKEY) {
47 for (i = 0; i < (MAX_KEY_TABLE - 1); i++) {
48 if (!test_bit(i, &priv->key_entry_inuse)) {
49 set_bit(i, &priv->key_entry_inuse);
52 entry = key->hw_key_idx;
60 case VNT_KEY_DEFAULTKEY:
61 /* default key last entry */
62 entry = MAX_KEY_TABLE - 1;
63 key->hw_key_idx = entry;
64 case VNT_KEY_ALLGROUP:
65 key_mode |= VNT_KEY_ALLGROUP;
67 key_mode |= VNT_KEY_ONFLY_ALL;
68 case VNT_KEY_GROUP_ADDRESS:
71 key_mode |= (mode << 4);
72 key_mode |= VNT_KEY_GROUP;
74 case VNT_KEY_PAIRWISE:
83 key_mode |= VNT_KEY_ONFLY;
85 if (mode == KEY_CTL_WEP) {
86 if (key->keylen == WLAN_KEY_LEN_WEP40)
88 if (key->keylen == WLAN_KEY_LEN_WEP104)
92 MACvSetKeyEntry(priv, key_mode, entry, key_inx,
93 bssid, (u32 *)key->key, priv->byLocalID);
98 int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
99 struct ieee80211_vif *vif, struct ieee80211_key_conf *key)
101 struct ieee80211_bss_conf *conf = &vif->bss_conf;
102 struct vnt_private *priv = hw->priv;
109 mac_addr = &sta->addr[0];
111 switch (key->cipher) {
113 for (u = 0 ; u < MAX_KEY_TABLE; u++)
114 MACvDisableKeyEntry(priv, u);
117 case WLAN_CIPHER_SUITE_WEP40:
118 case WLAN_CIPHER_SUITE_WEP104:
119 for (u = 0; u < MAX_KEY_TABLE; u++)
120 MACvDisableKeyEntry(priv, u);
122 vnt_set_keymode(hw, mac_addr,
123 key, VNT_KEY_DEFAULTKEY, KEY_CTL_WEP, true);
125 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
128 case WLAN_CIPHER_SUITE_TKIP:
129 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
130 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
132 key_dec_mode = KEY_CTL_TKIP;
135 case WLAN_CIPHER_SUITE_CCMP:
136 key_dec_mode = KEY_CTL_CCMP;
138 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
141 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
142 vnt_set_keymode(hw, mac_addr,
143 key, VNT_KEY_PAIRWISE, key_dec_mode, true);
145 vnt_set_keymode(hw, mac_addr,
146 key, VNT_KEY_DEFAULTKEY, key_dec_mode, true);
148 vnt_set_keymode(hw, (u8 *)conf->bssid,
149 key, VNT_KEY_GROUP_ADDRESS, key_dec_mode, true);