rb532: fix a module dependency issue
[openwrt/staging/dedeckeh.git] / package / mac80211 / patches / 522-ath9k_remove_duplicate_code.patch
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
4 return chanmode;
5 }
6
7 -static int ath_setkey_tkip(struct ath_common *common, u16 keyix, const u8 *key,
8 - struct ath9k_keyval *hk, const u8 *addr,
9 - bool authenticator)
10 -{
11 - struct ath_hw *ah = common->ah;
12 - const u8 *key_rxmic;
13 - const u8 *key_txmic;
14 -
15 - key_txmic = key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
16 - key_rxmic = key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
17 -
18 - if (addr == NULL) {
19 - /*
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.
23 - */
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));
27 - } else {
28 - memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
29 - memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic));
30 - }
31 - return ath9k_hw_set_keycache_entry(ah, keyix, hk, addr);
32 - }
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);
38 - }
39 -
40 - /* Separate key cache entries for TX and RX */
41 -
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");
48 - return 0;
49 - }
50 -
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);
54 -}
55 -
56 -static int ath_reserve_key_cache_slot_tkip(struct ath_common *common)
57 -{
58 - int i;
59 -
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 */
68 -
69 - /* Found a free slot for a TKIP key */
70 - return i;
71 - }
72 - return -1;
73 -}
74 -
75 -static int ath_reserve_key_cache_slot(struct ath_common *common)
76 -{
77 - int i;
78 -
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)))
86 - return i;
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)))
91 - return i + 32;
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)))
96 - return i + 64;
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;
102 - }
103 - } else {
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))
107 - return i;
108 - if (test_bit(i, common->keymap) &&
109 - !test_bit(i + 64, common->keymap))
110 - return i + 64;
111 - }
112 - }
113 -
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)
120 - continue;
121 - if (common->splitmic) {
122 - if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
123 - continue;
124 - if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
125 - continue;
126 - }
127 -
128 - if (!test_bit(i, common->keymap))
129 - return i; /* Found a free slot for a key */
130 - }
131 -
132 - /* No free slot found */
133 - return -1;
134 -}
135 -
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)
140 -{
141 - struct ath_hw *ah = common->ah;
142 - struct ath9k_keyval hk;
143 - const u8 *mac = NULL;
144 - int ret = 0;
145 - int idx;
146 -
147 - memset(&hk, 0, sizeof(hk));
148 -
149 - switch (key->alg) {
150 - case ALG_WEP:
151 - hk.kv_type = ATH9K_CIPHER_WEP;
152 - break;
153 - case ALG_TKIP:
154 - hk.kv_type = ATH9K_CIPHER_TKIP;
155 - break;
156 - case ALG_CCMP:
157 - hk.kv_type = ATH9K_CIPHER_AES_CCM;
158 - break;
159 - default:
160 - return -EOPNOTSUPP;
161 - }
162 -
163 - hk.kv_len = key->keylen;
164 - memcpy(hk.kv_val, key->key, key->keylen);
165 -
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. */
169 - idx = key->keyidx;
170 - } else if (key->keyidx) {
171 - if (WARN_ON(!sta))
172 - return -EOPNOTSUPP;
173 - mac = sta->addr;
174 -
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. */
178 - idx = key->keyidx;
179 - } else
180 - return -EIO;
181 - } else {
182 - if (WARN_ON(!sta))
183 - return -EOPNOTSUPP;
184 - mac = sta->addr;
185 -
186 - if (key->alg == ALG_TKIP)
187 - idx = ath_reserve_key_cache_slot_tkip(common);
188 - else
189 - idx = ath_reserve_key_cache_slot(common);
190 - if (idx < 0)
191 - return -ENOSPC; /* no free key cache entries */
192 - }
193 -
194 - if (key->alg == ALG_TKIP)
195 - ret = ath_setkey_tkip(common, idx, key->key, &hk, mac,
196 - vif->type == NL80211_IFTYPE_AP);
197 - else
198 - ret = ath9k_hw_set_keycache_entry(ah, idx, &hk, mac);
199 -
200 - if (!ret)
201 - return -EIO;
202 -
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);
209 - }
210 - }
211 -
212 - return idx;
213 -}
214 -
215 -static void ath_key_delete(struct ath_common *common, struct ieee80211_key_conf *key)
216 -{
217 - struct ath_hw *ah = common->ah;
218 -
219 - ath9k_hw_keyreset(ah, key->hw_key_idx);
220 - if (key->hw_key_idx < IEEE80211_WEP_NKID)
221 - return;
222 -
223 - clear_bit(key->hw_key_idx, common->keymap);
224 - if (key->alg != ALG_TKIP)
225 - return;
226 -
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);
232 - }
233 -}
234 -
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
239
240 switch (cmd) {
241 case SET_KEY:
242 - ret = ath_key_config(common, vif, sta, key);
243 + ret = ath9k_cmn_key_config(common, vif, sta, key);
244 if (ret >= 0) {
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
248 }
249 break;
250 case DISABLE_KEY:
251 - ath_key_delete(common, key);
252 + ath9k_cmn_key_delete(common, key);
253 break;
254 default:
255 ret = -EINVAL;