]>
Commit | Line | Data |
---|---|---|
1f5a7e47 JB |
1 | /* |
2 | * Copyright 2002-2005, Instant802 Networks, Inc. | |
3 | * Copyright 2005-2006, Devicescape Software, Inc. | |
4 | * Copyright 2006-2007 Jiri Benc <[email protected]> | |
3b96766f | 5 | * Copyright 2007-2008 Johannes Berg <[email protected]> |
1f5a7e47 JB |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License version 2 as | |
9 | * published by the Free Software Foundation. | |
10 | */ | |
11 | ||
11a843b7 JB |
12 | #include <linux/if_ether.h> |
13 | #include <linux/etherdevice.h> | |
14 | #include <linux/list.h> | |
d4e46a3d | 15 | #include <linux/rcupdate.h> |
db4d1169 | 16 | #include <linux/rtnetlink.h> |
5a0e3ad6 | 17 | #include <linux/slab.h> |
1f5a7e47 JB |
18 | #include <net/mac80211.h> |
19 | #include "ieee80211_i.h" | |
24487981 | 20 | #include "driver-ops.h" |
1f5a7e47 JB |
21 | #include "debugfs_key.h" |
22 | #include "aes_ccm.h" | |
3cfcf6ac | 23 | #include "aes_cmac.h" |
1f5a7e47 | 24 | |
11a843b7 | 25 | |
dbbea671 JB |
26 | /** |
27 | * DOC: Key handling basics | |
11a843b7 JB |
28 | * |
29 | * Key handling in mac80211 is done based on per-interface (sub_if_data) | |
30 | * keys and per-station keys. Since each station belongs to an interface, | |
31 | * each station key also belongs to that interface. | |
32 | * | |
b5c34f66 JB |
33 | * Hardware acceleration is done on a best-effort basis for algorithms |
34 | * that are implemented in software, for each key the hardware is asked | |
35 | * to enable that key for offloading but if it cannot do that the key is | |
36 | * simply kept for software encryption (unless it is for an algorithm | |
37 | * that isn't implemented in software). | |
38 | * There is currently no way of knowing whether a key is handled in SW | |
39 | * or HW except by looking into debugfs. | |
11a843b7 | 40 | * |
b5c34f66 JB |
41 | * All key management is internally protected by a mutex. Within all |
42 | * other parts of mac80211, key references are, just as STA structure | |
43 | * references, protected by RCU. Note, however, that some things are | |
44 | * unprotected, namely the key->sta dereferences within the hardware | |
45 | * acceleration functions. This means that sta_info_destroy() must | |
46 | * remove the key which waits for an RCU grace period. | |
11a843b7 JB |
47 | */ |
48 | ||
49 | static const u8 bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; | |
11a843b7 | 50 | |
ad0e2b5a | 51 | static void assert_key_lock(struct ieee80211_local *local) |
3b96766f | 52 | { |
46a5ebaf | 53 | lockdep_assert_held(&local->key_mtx); |
3b96766f JB |
54 | } |
55 | ||
dc822b5d | 56 | static struct ieee80211_sta *get_sta_for_key(struct ieee80211_key *key) |
11a843b7 | 57 | { |
11a843b7 | 58 | if (key->sta) |
dc822b5d | 59 | return &key->sta->sta; |
11a843b7 | 60 | |
dc822b5d | 61 | return NULL; |
11a843b7 JB |
62 | } |
63 | ||
3ffc2a90 | 64 | static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key) |
11a843b7 | 65 | { |
dc822b5d JB |
66 | struct ieee80211_sub_if_data *sdata; |
67 | struct ieee80211_sta *sta; | |
11a843b7 JB |
68 | int ret; |
69 | ||
3b96766f JB |
70 | might_sleep(); |
71 | ||
e31b8213 | 72 | if (!key->local->ops->set_key) |
3ffc2a90 | 73 | goto out_unsupported; |
11a843b7 | 74 | |
ad0e2b5a JB |
75 | assert_key_lock(key->local); |
76 | ||
dc822b5d JB |
77 | sta = get_sta_for_key(key); |
78 | ||
e31b8213 JB |
79 | /* |
80 | * If this is a per-STA GTK, check if it | |
81 | * is supported; if not, return. | |
82 | */ | |
83 | if (sta && !(key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE) && | |
84 | !(key->local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK)) | |
85 | goto out_unsupported; | |
86 | ||
dc822b5d | 87 | sdata = key->sdata; |
18890d4b HS |
88 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) { |
89 | /* | |
90 | * The driver doesn't know anything about VLAN interfaces. | |
91 | * Hence, don't send GTKs for VLAN interfaces to the driver. | |
92 | */ | |
93 | if (!(key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE)) | |
94 | goto out_unsupported; | |
dc822b5d JB |
95 | sdata = container_of(sdata->bss, |
96 | struct ieee80211_sub_if_data, | |
97 | u.ap); | |
18890d4b | 98 | } |
11a843b7 | 99 | |
12375ef9 | 100 | ret = drv_set_key(key->local, SET_KEY, sdata, sta, &key->conf); |
11a843b7 | 101 | |
e31b8213 | 102 | if (!ret) { |
11a843b7 | 103 | key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE; |
e31b8213 JB |
104 | return 0; |
105 | } | |
11a843b7 | 106 | |
e31b8213 | 107 | if (ret != -ENOSPC && ret != -EOPNOTSUPP) |
0fb9a9ec JP |
108 | wiphy_err(key->local->hw.wiphy, |
109 | "failed to set key (%d, %pM) to hardware (%d)\n", | |
110 | key->conf.keyidx, sta ? sta->addr : bcast_addr, ret); | |
3ffc2a90 | 111 | |
e31b8213 JB |
112 | out_unsupported: |
113 | switch (key->conf.cipher) { | |
114 | case WLAN_CIPHER_SUITE_WEP40: | |
115 | case WLAN_CIPHER_SUITE_WEP104: | |
116 | case WLAN_CIPHER_SUITE_TKIP: | |
117 | case WLAN_CIPHER_SUITE_CCMP: | |
118 | case WLAN_CIPHER_SUITE_AES_CMAC: | |
119 | /* all of these we can do in software */ | |
120 | return 0; | |
121 | default: | |
122 | return -EINVAL; | |
3ffc2a90 | 123 | } |
11a843b7 JB |
124 | } |
125 | ||
126 | static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key) | |
127 | { | |
dc822b5d JB |
128 | struct ieee80211_sub_if_data *sdata; |
129 | struct ieee80211_sta *sta; | |
11a843b7 JB |
130 | int ret; |
131 | ||
3b96766f JB |
132 | might_sleep(); |
133 | ||
db4d1169 | 134 | if (!key || !key->local->ops->set_key) |
11a843b7 JB |
135 | return; |
136 | ||
ad0e2b5a JB |
137 | assert_key_lock(key->local); |
138 | ||
139 | if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) | |
11a843b7 JB |
140 | return; |
141 | ||
dc822b5d JB |
142 | sta = get_sta_for_key(key); |
143 | sdata = key->sdata; | |
144 | ||
145 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) | |
146 | sdata = container_of(sdata->bss, | |
147 | struct ieee80211_sub_if_data, | |
148 | u.ap); | |
11a843b7 | 149 | |
12375ef9 | 150 | ret = drv_set_key(key->local, DISABLE_KEY, sdata, |
24487981 | 151 | sta, &key->conf); |
11a843b7 JB |
152 | |
153 | if (ret) | |
0fb9a9ec JP |
154 | wiphy_err(key->local->hw.wiphy, |
155 | "failed to remove key (%d, %pM) from hardware (%d)\n", | |
156 | key->conf.keyidx, sta ? sta->addr : bcast_addr, ret); | |
11a843b7 | 157 | |
3b96766f | 158 | key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE; |
3b96766f JB |
159 | } |
160 | ||
e31b8213 JB |
161 | void ieee80211_key_removed(struct ieee80211_key_conf *key_conf) |
162 | { | |
163 | struct ieee80211_key *key; | |
164 | ||
165 | key = container_of(key_conf, struct ieee80211_key, conf); | |
166 | ||
167 | might_sleep(); | |
168 | assert_key_lock(key->local); | |
169 | ||
170 | key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE; | |
171 | ||
172 | /* | |
173 | * Flush TX path to avoid attempts to use this key | |
174 | * after this function returns. Until then, drivers | |
175 | * must be prepared to handle the key. | |
176 | */ | |
177 | synchronize_rcu(); | |
178 | } | |
179 | EXPORT_SYMBOL_GPL(ieee80211_key_removed); | |
180 | ||
3b96766f | 181 | static void __ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, |
f7e0104c | 182 | int idx, bool uni, bool multi) |
3b96766f JB |
183 | { |
184 | struct ieee80211_key *key = NULL; | |
185 | ||
ad0e2b5a JB |
186 | assert_key_lock(sdata->local); |
187 | ||
3b96766f JB |
188 | if (idx >= 0 && idx < NUM_DEFAULT_KEYS) |
189 | key = sdata->keys[idx]; | |
190 | ||
f7e0104c JB |
191 | if (uni) |
192 | rcu_assign_pointer(sdata->default_unicast_key, key); | |
193 | if (multi) | |
194 | rcu_assign_pointer(sdata->default_multicast_key, key); | |
3b96766f | 195 | |
f7e0104c | 196 | ieee80211_debugfs_key_update_default(sdata); |
3b96766f JB |
197 | } |
198 | ||
f7e0104c JB |
199 | void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx, |
200 | bool uni, bool multi) | |
3b96766f | 201 | { |
ad0e2b5a | 202 | mutex_lock(&sdata->local->key_mtx); |
f7e0104c | 203 | __ieee80211_set_default_key(sdata, idx, uni, multi); |
ad0e2b5a | 204 | mutex_unlock(&sdata->local->key_mtx); |
3b96766f JB |
205 | } |
206 | ||
3cfcf6ac JM |
207 | static void |
208 | __ieee80211_set_default_mgmt_key(struct ieee80211_sub_if_data *sdata, int idx) | |
209 | { | |
210 | struct ieee80211_key *key = NULL; | |
211 | ||
ad0e2b5a JB |
212 | assert_key_lock(sdata->local); |
213 | ||
3cfcf6ac JM |
214 | if (idx >= NUM_DEFAULT_KEYS && |
215 | idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) | |
216 | key = sdata->keys[idx]; | |
217 | ||
218 | rcu_assign_pointer(sdata->default_mgmt_key, key); | |
219 | ||
f7e0104c | 220 | ieee80211_debugfs_key_update_default(sdata); |
3cfcf6ac JM |
221 | } |
222 | ||
223 | void ieee80211_set_default_mgmt_key(struct ieee80211_sub_if_data *sdata, | |
224 | int idx) | |
225 | { | |
ad0e2b5a | 226 | mutex_lock(&sdata->local->key_mtx); |
3cfcf6ac | 227 | __ieee80211_set_default_mgmt_key(sdata, idx); |
ad0e2b5a | 228 | mutex_unlock(&sdata->local->key_mtx); |
3cfcf6ac JM |
229 | } |
230 | ||
3b96766f JB |
231 | |
232 | static void __ieee80211_key_replace(struct ieee80211_sub_if_data *sdata, | |
233 | struct sta_info *sta, | |
e31b8213 | 234 | bool pairwise, |
3b96766f JB |
235 | struct ieee80211_key *old, |
236 | struct ieee80211_key *new) | |
237 | { | |
f7e0104c JB |
238 | int idx; |
239 | bool defunikey, defmultikey, defmgmtkey; | |
3b96766f JB |
240 | |
241 | if (new) | |
242 | list_add(&new->list, &sdata->key_list); | |
243 | ||
e31b8213 JB |
244 | if (sta && pairwise) { |
245 | rcu_assign_pointer(sta->ptk, new); | |
246 | } else if (sta) { | |
247 | if (old) | |
248 | idx = old->conf.keyidx; | |
249 | else | |
250 | idx = new->conf.keyidx; | |
251 | rcu_assign_pointer(sta->gtk[idx], new); | |
3b96766f JB |
252 | } else { |
253 | WARN_ON(new && old && new->conf.keyidx != old->conf.keyidx); | |
254 | ||
255 | if (old) | |
256 | idx = old->conf.keyidx; | |
257 | else | |
258 | idx = new->conf.keyidx; | |
259 | ||
f7e0104c JB |
260 | defunikey = old && sdata->default_unicast_key == old; |
261 | defmultikey = old && sdata->default_multicast_key == old; | |
3cfcf6ac | 262 | defmgmtkey = old && sdata->default_mgmt_key == old; |
3b96766f | 263 | |
f7e0104c JB |
264 | if (defunikey && !new) |
265 | __ieee80211_set_default_key(sdata, -1, true, false); | |
266 | if (defmultikey && !new) | |
267 | __ieee80211_set_default_key(sdata, -1, false, true); | |
3cfcf6ac JM |
268 | if (defmgmtkey && !new) |
269 | __ieee80211_set_default_mgmt_key(sdata, -1); | |
3b96766f JB |
270 | |
271 | rcu_assign_pointer(sdata->keys[idx], new); | |
f7e0104c JB |
272 | if (defunikey && new) |
273 | __ieee80211_set_default_key(sdata, new->conf.keyidx, | |
274 | true, false); | |
275 | if (defmultikey && new) | |
276 | __ieee80211_set_default_key(sdata, new->conf.keyidx, | |
277 | false, true); | |
3cfcf6ac JM |
278 | if (defmgmtkey && new) |
279 | __ieee80211_set_default_mgmt_key(sdata, | |
280 | new->conf.keyidx); | |
3b96766f JB |
281 | } |
282 | ||
b5c34f66 JB |
283 | if (old) |
284 | list_del(&old->list); | |
11a843b7 JB |
285 | } |
286 | ||
97359d12 | 287 | struct ieee80211_key *ieee80211_key_alloc(u32 cipher, int idx, size_t key_len, |
faa8fdc8 JM |
288 | const u8 *key_data, |
289 | size_t seq_len, const u8 *seq) | |
1f5a7e47 JB |
290 | { |
291 | struct ieee80211_key *key; | |
1ac62ba7 | 292 | int i, j, err; |
1f5a7e47 | 293 | |
3cfcf6ac | 294 | BUG_ON(idx < 0 || idx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS); |
11a843b7 JB |
295 | |
296 | key = kzalloc(sizeof(struct ieee80211_key) + key_len, GFP_KERNEL); | |
1f5a7e47 | 297 | if (!key) |
1ac62ba7 | 298 | return ERR_PTR(-ENOMEM); |
11a843b7 JB |
299 | |
300 | /* | |
301 | * Default to software encryption; we'll later upload the | |
302 | * key to the hardware if possible. | |
303 | */ | |
11a843b7 JB |
304 | key->conf.flags = 0; |
305 | key->flags = 0; | |
306 | ||
97359d12 | 307 | key->conf.cipher = cipher; |
11a843b7 JB |
308 | key->conf.keyidx = idx; |
309 | key->conf.keylen = key_len; | |
97359d12 JB |
310 | switch (cipher) { |
311 | case WLAN_CIPHER_SUITE_WEP40: | |
312 | case WLAN_CIPHER_SUITE_WEP104: | |
76708dee FF |
313 | key->conf.iv_len = WEP_IV_LEN; |
314 | key->conf.icv_len = WEP_ICV_LEN; | |
315 | break; | |
97359d12 | 316 | case WLAN_CIPHER_SUITE_TKIP: |
76708dee FF |
317 | key->conf.iv_len = TKIP_IV_LEN; |
318 | key->conf.icv_len = TKIP_ICV_LEN; | |
9f26a952 | 319 | if (seq) { |
faa8fdc8 JM |
320 | for (i = 0; i < NUM_RX_DATA_QUEUES; i++) { |
321 | key->u.tkip.rx[i].iv32 = | |
322 | get_unaligned_le32(&seq[2]); | |
323 | key->u.tkip.rx[i].iv16 = | |
324 | get_unaligned_le16(seq); | |
325 | } | |
326 | } | |
76708dee | 327 | break; |
97359d12 | 328 | case WLAN_CIPHER_SUITE_CCMP: |
76708dee FF |
329 | key->conf.iv_len = CCMP_HDR_LEN; |
330 | key->conf.icv_len = CCMP_MIC_LEN; | |
9f26a952 | 331 | if (seq) { |
9190252c | 332 | for (i = 0; i < NUM_RX_DATA_QUEUES + 1; i++) |
faa8fdc8 JM |
333 | for (j = 0; j < CCMP_PN_LEN; j++) |
334 | key->u.ccmp.rx_pn[i][j] = | |
335 | seq[CCMP_PN_LEN - j - 1]; | |
336 | } | |
11a843b7 JB |
337 | /* |
338 | * Initialize AES key state here as an optimization so that | |
339 | * it does not need to be initialized for every packet. | |
340 | */ | |
341 | key->u.ccmp.tfm = ieee80211_aes_key_setup_encrypt(key_data); | |
1ac62ba7 BH |
342 | if (IS_ERR(key->u.ccmp.tfm)) { |
343 | err = PTR_ERR(key->u.ccmp.tfm); | |
3b96766f | 344 | kfree(key); |
1ac62ba7 | 345 | key = ERR_PTR(err); |
11a843b7 | 346 | } |
60ae0f20 JB |
347 | break; |
348 | case WLAN_CIPHER_SUITE_AES_CMAC: | |
349 | key->conf.iv_len = 0; | |
350 | key->conf.icv_len = sizeof(struct ieee80211_mmie); | |
351 | if (seq) | |
352 | for (j = 0; j < 6; j++) | |
353 | key->u.aes_cmac.rx_pn[j] = seq[6 - j - 1]; | |
3cfcf6ac JM |
354 | /* |
355 | * Initialize AES key state here as an optimization so that | |
356 | * it does not need to be initialized for every packet. | |
357 | */ | |
358 | key->u.aes_cmac.tfm = | |
359 | ieee80211_aes_cmac_key_setup(key_data); | |
1ac62ba7 BH |
360 | if (IS_ERR(key->u.aes_cmac.tfm)) { |
361 | err = PTR_ERR(key->u.aes_cmac.tfm); | |
3cfcf6ac | 362 | kfree(key); |
1ac62ba7 | 363 | key = ERR_PTR(err); |
3cfcf6ac | 364 | } |
60ae0f20 | 365 | break; |
3cfcf6ac | 366 | } |
60ae0f20 JB |
367 | memcpy(key->conf.key, key_data, key_len); |
368 | INIT_LIST_HEAD(&key->list); | |
3cfcf6ac | 369 | |
db4d1169 JB |
370 | return key; |
371 | } | |
11a843b7 | 372 | |
ad0e2b5a JB |
373 | static void __ieee80211_key_destroy(struct ieee80211_key *key) |
374 | { | |
375 | if (!key) | |
376 | return; | |
377 | ||
d2460f4b JB |
378 | /* |
379 | * Synchronize so the TX path can no longer be using | |
380 | * this key before we free/remove it. | |
381 | */ | |
382 | synchronize_rcu(); | |
383 | ||
32162a4d JM |
384 | if (key->local) |
385 | ieee80211_key_disable_hw_accel(key); | |
ad0e2b5a | 386 | |
97359d12 | 387 | if (key->conf.cipher == WLAN_CIPHER_SUITE_CCMP) |
ad0e2b5a | 388 | ieee80211_aes_key_free(key->u.ccmp.tfm); |
97359d12 | 389 | if (key->conf.cipher == WLAN_CIPHER_SUITE_AES_CMAC) |
ad0e2b5a | 390 | ieee80211_aes_cmac_key_free(key->u.aes_cmac.tfm); |
32162a4d JM |
391 | if (key->local) |
392 | ieee80211_debugfs_key_remove(key); | |
ad0e2b5a JB |
393 | |
394 | kfree(key); | |
395 | } | |
396 | ||
3ffc2a90 JB |
397 | int ieee80211_key_link(struct ieee80211_key *key, |
398 | struct ieee80211_sub_if_data *sdata, | |
399 | struct sta_info *sta) | |
db4d1169 JB |
400 | { |
401 | struct ieee80211_key *old_key; | |
3ffc2a90 | 402 | int idx, ret; |
e31b8213 | 403 | bool pairwise = key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE; |
db4d1169 | 404 | |
db4d1169 JB |
405 | BUG_ON(!sdata); |
406 | BUG_ON(!key); | |
407 | ||
408 | idx = key->conf.keyidx; | |
409 | key->local = sdata->local; | |
410 | key->sdata = sdata; | |
411 | key->sta = sta; | |
412 | ||
11a843b7 | 413 | if (sta) { |
11a843b7 JB |
414 | /* |
415 | * some hardware cannot handle TKIP with QoS, so | |
416 | * we indicate whether QoS could be in use. | |
417 | */ | |
07346f81 | 418 | if (test_sta_flags(sta, WLAN_STA_WME)) |
11a843b7 JB |
419 | key->conf.flags |= IEEE80211_KEY_FLAG_WMM_STA; |
420 | } else { | |
05c914fe | 421 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
11a843b7 JB |
422 | struct sta_info *ap; |
423 | ||
3b96766f | 424 | /* |
b5c34f66 JB |
425 | * We're getting a sta pointer in, so must be under |
426 | * appropriate locking for sta_info_get(). | |
3b96766f | 427 | */ |
d0709a65 | 428 | |
11a843b7 | 429 | /* same here, the AP could be using QoS */ |
abe60632 | 430 | ap = sta_info_get(key->sdata, key->sdata->u.mgd.bssid); |
11a843b7 | 431 | if (ap) { |
07346f81 | 432 | if (test_sta_flags(ap, WLAN_STA_WME)) |
11a843b7 JB |
433 | key->conf.flags |= |
434 | IEEE80211_KEY_FLAG_WMM_STA; | |
11a843b7 JB |
435 | } |
436 | } | |
11a843b7 JB |
437 | } |
438 | ||
ad0e2b5a | 439 | mutex_lock(&sdata->local->key_mtx); |
3b96766f | 440 | |
e31b8213 JB |
441 | if (sta && pairwise) |
442 | old_key = sta->ptk; | |
443 | else if (sta) | |
444 | old_key = sta->gtk[idx]; | |
d4e46a3d | 445 | else |
db4d1169 JB |
446 | old_key = sdata->keys[idx]; |
447 | ||
e31b8213 | 448 | __ieee80211_key_replace(sdata, sta, pairwise, old_key, key); |
ad0e2b5a | 449 | __ieee80211_key_destroy(old_key); |
d4e46a3d | 450 | |
ad0e2b5a | 451 | ieee80211_debugfs_key_add(key); |
db4d1169 | 452 | |
3ffc2a90 | 453 | ret = ieee80211_key_enable_hw_accel(key); |
523d2f69 | 454 | |
ad0e2b5a | 455 | mutex_unlock(&sdata->local->key_mtx); |
3ffc2a90 JB |
456 | |
457 | return ret; | |
1f5a7e47 JB |
458 | } |
459 | ||
3a245766 | 460 | static void __ieee80211_key_free(struct ieee80211_key *key) |
1f5a7e47 | 461 | { |
3b96766f JB |
462 | /* |
463 | * Replace key with nothingness if it was ever used. | |
464 | */ | |
3a245766 | 465 | if (key->sdata) |
3b96766f | 466 | __ieee80211_key_replace(key->sdata, key->sta, |
e31b8213 JB |
467 | key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE, |
468 | key, NULL); | |
ad0e2b5a | 469 | __ieee80211_key_destroy(key); |
3b96766f | 470 | } |
d4e46a3d | 471 | |
32162a4d JM |
472 | void ieee80211_key_free(struct ieee80211_local *local, |
473 | struct ieee80211_key *key) | |
3b96766f | 474 | { |
3a245766 | 475 | if (!key) |
3b96766f JB |
476 | return; |
477 | ||
ad0e2b5a | 478 | mutex_lock(&local->key_mtx); |
3a245766 | 479 | __ieee80211_key_free(key); |
ad0e2b5a | 480 | mutex_unlock(&local->key_mtx); |
3a245766 JB |
481 | } |
482 | ||
ad0e2b5a | 483 | void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata) |
3a245766 JB |
484 | { |
485 | struct ieee80211_key *key; | |
11a843b7 | 486 | |
3a245766 | 487 | ASSERT_RTNL(); |
11a843b7 | 488 | |
9607e6b6 | 489 | if (WARN_ON(!ieee80211_sdata_running(sdata))) |
3a245766 | 490 | return; |
11a843b7 | 491 | |
ad0e2b5a | 492 | mutex_lock(&sdata->local->key_mtx); |
11a843b7 | 493 | |
ad0e2b5a JB |
494 | list_for_each_entry(key, &sdata->key_list, list) |
495 | ieee80211_key_enable_hw_accel(key); | |
3b96766f | 496 | |
ad0e2b5a | 497 | mutex_unlock(&sdata->local->key_mtx); |
11a843b7 JB |
498 | } |
499 | ||
ad0e2b5a | 500 | void ieee80211_disable_keys(struct ieee80211_sub_if_data *sdata) |
11a843b7 JB |
501 | { |
502 | struct ieee80211_key *key; | |
503 | ||
ad0e2b5a | 504 | ASSERT_RTNL(); |
db4d1169 | 505 | |
ad0e2b5a | 506 | mutex_lock(&sdata->local->key_mtx); |
11a843b7 | 507 | |
ad0e2b5a JB |
508 | list_for_each_entry(key, &sdata->key_list, list) |
509 | ieee80211_key_disable_hw_accel(key); | |
11a843b7 | 510 | |
ad0e2b5a | 511 | mutex_unlock(&sdata->local->key_mtx); |
3b96766f | 512 | } |
11a843b7 | 513 | |
3b96766f JB |
514 | void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata) |
515 | { | |
516 | struct ieee80211_key *key, *tmp; | |
db4d1169 | 517 | |
ad0e2b5a | 518 | mutex_lock(&sdata->local->key_mtx); |
3b96766f | 519 | |
3cfcf6ac | 520 | ieee80211_debugfs_key_remove_mgmt_default(sdata); |
3b96766f JB |
521 | |
522 | list_for_each_entry_safe(key, tmp, &sdata->key_list, list) | |
3a245766 | 523 | __ieee80211_key_free(key); |
3b96766f | 524 | |
f7e0104c JB |
525 | ieee80211_debugfs_key_update_default(sdata); |
526 | ||
ad0e2b5a | 527 | mutex_unlock(&sdata->local->key_mtx); |
11a843b7 | 528 | } |