1 --- a/drivers/net/wireless/ath/ath9k/main.c
2 +++ b/drivers/net/wireless/ath/ath9k/main.c
3 @@ -622,234 +622,6 @@ static u32 ath_get_extchanmode(struct at
7 -static int ath_setkey_tkip(struct ath_common *common, u16 keyix, const u8 *key,
8 - struct ath9k_keyval *hk, const u8 *addr,
11 - struct ath_hw *ah = common->ah;
12 - const u8 *key_rxmic;
13 - const u8 *key_txmic;
15 - key_txmic = key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
16 - key_rxmic = key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
20 - * Group key installation - only two key cache entries are used
21 - * regardless of splitmic capability since group key is only
22 - * used either for TX or RX.
24 - if (authenticator) {
25 - memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
26 - memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_mic));
28 - memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
29 - memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic));
31 - return ath9k_hw_set_keycache_entry(ah, keyix, hk, addr);
33 - if (!common->splitmic) {
34 - /* TX and RX keys share the same key cache entry. */
35 - memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
36 - memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
37 - return ath9k_hw_set_keycache_entry(ah, keyix, hk, addr);
40 - /* Separate key cache entries for TX and RX */
42 - /* TX key goes at first index, RX key at +32. */
43 - memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
44 - if (!ath9k_hw_set_keycache_entry(ah, keyix, hk, NULL)) {
45 - /* TX MIC entry failed. No need to proceed further */
46 - ath_print(common, ATH_DBG_FATAL,
47 - "Setting TX MIC Key Failed\n");
51 - memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
52 - /* XXX delete tx key on failure? */
53 - return ath9k_hw_set_keycache_entry(ah, keyix + 32, hk, addr);
56 -static int ath_reserve_key_cache_slot_tkip(struct ath_common *common)
60 - for (i = IEEE80211_WEP_NKID; i < common->keymax / 2; i++) {
61 - if (test_bit(i, common->keymap) ||
62 - test_bit(i + 64, common->keymap))
63 - continue; /* At least one part of TKIP key allocated */
64 - if (common->splitmic &&
65 - (test_bit(i + 32, common->keymap) ||
66 - test_bit(i + 64 + 32, common->keymap)))
67 - continue; /* At least one part of TKIP key allocated */
69 - /* Found a free slot for a TKIP key */
75 -static int ath_reserve_key_cache_slot(struct ath_common *common)
79 - /* First, try to find slots that would not be available for TKIP. */
80 - if (common->splitmic) {
81 - for (i = IEEE80211_WEP_NKID; i < common->keymax / 4; i++) {
82 - if (!test_bit(i, common->keymap) &&
83 - (test_bit(i + 32, common->keymap) ||
84 - test_bit(i + 64, common->keymap) ||
85 - test_bit(i + 64 + 32, common->keymap)))
87 - if (!test_bit(i + 32, common->keymap) &&
88 - (test_bit(i, common->keymap) ||
89 - test_bit(i + 64, common->keymap) ||
90 - test_bit(i + 64 + 32, common->keymap)))
92 - if (!test_bit(i + 64, common->keymap) &&
93 - (test_bit(i , common->keymap) ||
94 - test_bit(i + 32, common->keymap) ||
95 - test_bit(i + 64 + 32, common->keymap)))
97 - if (!test_bit(i + 64 + 32, common->keymap) &&
98 - (test_bit(i, common->keymap) ||
99 - test_bit(i + 32, common->keymap) ||
100 - test_bit(i + 64, common->keymap)))
101 - return i + 64 + 32;
104 - for (i = IEEE80211_WEP_NKID; i < common->keymax / 2; i++) {
105 - if (!test_bit(i, common->keymap) &&
106 - test_bit(i + 64, common->keymap))
108 - if (test_bit(i, common->keymap) &&
109 - !test_bit(i + 64, common->keymap))
114 - /* No partially used TKIP slots, pick any available slot */
115 - for (i = IEEE80211_WEP_NKID; i < common->keymax; i++) {
116 - /* Do not allow slots that could be needed for TKIP group keys
117 - * to be used. This limitation could be removed if we know that
118 - * TKIP will not be used. */
119 - if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
121 - if (common->splitmic) {
122 - if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
124 - if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
128 - if (!test_bit(i, common->keymap))
129 - return i; /* Found a free slot for a key */
132 - /* No free slot found */
136 -static int ath_key_config(struct ath_common *common,
137 - struct ieee80211_vif *vif,
138 - struct ieee80211_sta *sta,
139 - struct ieee80211_key_conf *key)
141 - struct ath_hw *ah = common->ah;
142 - struct ath9k_keyval hk;
143 - const u8 *mac = NULL;
147 - memset(&hk, 0, sizeof(hk));
149 - switch (key->alg) {
151 - hk.kv_type = ATH9K_CIPHER_WEP;
154 - hk.kv_type = ATH9K_CIPHER_TKIP;
157 - hk.kv_type = ATH9K_CIPHER_AES_CCM;
160 - return -EOPNOTSUPP;
163 - hk.kv_len = key->keylen;
164 - memcpy(hk.kv_val, key->key, key->keylen);
166 - if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
167 - /* For now, use the default keys for broadcast keys. This may
168 - * need to change with virtual interfaces. */
170 - } else if (key->keyidx) {
172 - return -EOPNOTSUPP;
175 - if (vif->type != NL80211_IFTYPE_AP) {
176 - /* Only keyidx 0 should be used with unicast key, but
177 - * allow this for client mode for now. */
183 - return -EOPNOTSUPP;
186 - if (key->alg == ALG_TKIP)
187 - idx = ath_reserve_key_cache_slot_tkip(common);
189 - idx = ath_reserve_key_cache_slot(common);
191 - return -ENOSPC; /* no free key cache entries */
194 - if (key->alg == ALG_TKIP)
195 - ret = ath_setkey_tkip(common, idx, key->key, &hk, mac,
196 - vif->type == NL80211_IFTYPE_AP);
198 - ret = ath9k_hw_set_keycache_entry(ah, idx, &hk, mac);
203 - set_bit(idx, common->keymap);
204 - if (key->alg == ALG_TKIP) {
205 - set_bit(idx + 64, common->keymap);
206 - if (common->splitmic) {
207 - set_bit(idx + 32, common->keymap);
208 - set_bit(idx + 64 + 32, common->keymap);
215 -static void ath_key_delete(struct ath_common *common, struct ieee80211_key_conf *key)
217 - struct ath_hw *ah = common->ah;
219 - ath9k_hw_keyreset(ah, key->hw_key_idx);
220 - if (key->hw_key_idx < IEEE80211_WEP_NKID)
223 - clear_bit(key->hw_key_idx, common->keymap);
224 - if (key->alg != ALG_TKIP)
227 - clear_bit(key->hw_key_idx + 64, common->keymap);
228 - if (common->splitmic) {
229 - ath9k_hw_keyreset(ah, key->hw_key_idx + 32);
230 - clear_bit(key->hw_key_idx + 32, common->keymap);
231 - clear_bit(key->hw_key_idx + 64 + 32, common->keymap);
235 static void ath9k_bss_assoc_info(struct ath_softc *sc,
236 struct ieee80211_vif *vif,
237 struct ieee80211_bss_conf *bss_conf)
238 @@ -1814,7 +1586,7 @@ static int ath9k_set_key(struct ieee8021
242 - ret = ath_key_config(common, vif, sta, key);
243 + ret = ath9k_cmn_key_config(common, vif, sta, key);
245 key->hw_key_idx = ret;
246 /* push IV and Michael MIC generation to stack */
247 @@ -1827,7 +1599,7 @@ static int ath9k_set_key(struct ieee8021
251 - ath_key_delete(common, key);
252 + ath9k_cmn_key_delete(common, key);