blob: a5b06fe7198019c5a178f0ac21118e222bcb04d7 [file] [log] [blame]
Johannes Berg1f5a7e42007-07-27 15:43:23 +02001/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
Johannes Berg3b967662008-04-08 17:56:52 +02005 * Copyright 2007-2008 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg1f5a7e42007-07-27 15:43:23 +02006 *
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
Johannes Berg11a843b2007-08-28 17:01:55 -040012#include <linux/if_ether.h>
13#include <linux/etherdevice.h>
14#include <linux/list.h>
Johannes Bergd4e46a32007-09-14 11:10:24 -040015#include <linux/rcupdate.h>
Johannes Bergdb4d1162008-02-25 16:27:45 +010016#include <linux/rtnetlink.h>
Johannes Berg1f5a7e42007-07-27 15:43:23 +020017#include <net/mac80211.h>
18#include "ieee80211_i.h"
19#include "debugfs_key.h"
20#include "aes_ccm.h"
21
Johannes Berg11a843b2007-08-28 17:01:55 -040022
Johannes Bergdbbea672008-02-26 14:34:06 +010023/**
24 * DOC: Key handling basics
Johannes Berg11a843b2007-08-28 17:01:55 -040025 *
26 * Key handling in mac80211 is done based on per-interface (sub_if_data)
27 * keys and per-station keys. Since each station belongs to an interface,
28 * each station key also belongs to that interface.
29 *
30 * Hardware acceleration is done on a best-effort basis, for each key
31 * that is eligible the hardware is asked to enable that key but if
32 * it cannot do that they key is simply kept for software encryption.
33 * There is currently no way of knowing this except by looking into
34 * debugfs.
35 *
Johannes Berg3b967662008-04-08 17:56:52 +020036 * All key operations are protected internally so you can call them at
37 * any time.
Johannes Bergdb4d1162008-02-25 16:27:45 +010038 *
Johannes Berg3b967662008-04-08 17:56:52 +020039 * Within mac80211, key references are, just as STA structure references,
40 * protected by RCU. Note, however, that some things are unprotected,
41 * namely the key->sta dereferences within the hardware acceleration
42 * functions. This means that sta_info_destroy() must flush the key todo
43 * list.
44 *
45 * All the direct key list manipulation functions must not sleep because
46 * they can operate on STA info structs that are protected by RCU.
Johannes Berg11a843b2007-08-28 17:01:55 -040047 */
48
49static const u8 bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
50static const u8 zero_addr[ETH_ALEN];
51
Johannes Berg3b967662008-04-08 17:56:52 +020052/* key mutex: used to synchronise todo runners */
53static DEFINE_MUTEX(key_mutex);
54static DEFINE_SPINLOCK(todo_lock);
55static LIST_HEAD(todo_list);
56
57static void key_todo(struct work_struct *work)
58{
59 ieee80211_key_todo();
60}
61
62static DECLARE_WORK(todo_work, key_todo);
63
64/**
65 * add_todo - add todo item for a key
66 *
67 * @key: key to add to do item for
68 * @flag: todo flag(s)
69 */
70static void add_todo(struct ieee80211_key *key, u32 flag)
71{
72 if (!key)
73 return;
74
75 spin_lock(&todo_lock);
76 key->flags |= flag;
Johannes Berg245cbe72008-04-13 10:43:50 +020077 /*
78 * Remove again if already on the list so that we move it to the end.
79 */
80 if (!list_empty(&key->todo))
81 list_del(&key->todo);
82 list_add_tail(&key->todo, &todo_list);
Johannes Berg3b967662008-04-08 17:56:52 +020083 schedule_work(&todo_work);
84 spin_unlock(&todo_lock);
85}
86
87/**
88 * ieee80211_key_lock - lock the mac80211 key operation lock
89 *
90 * This locks the (global) mac80211 key operation lock, all
91 * key operations must be done under this lock.
92 */
93static void ieee80211_key_lock(void)
94{
95 mutex_lock(&key_mutex);
96}
97
98/**
99 * ieee80211_key_unlock - unlock the mac80211 key operation lock
100 */
101static void ieee80211_key_unlock(void)
102{
103 mutex_unlock(&key_mutex);
104}
105
106static void assert_key_lock(void)
107{
108 WARN_ON(!mutex_is_locked(&key_mutex));
109}
110
Johannes Berg11a843b2007-08-28 17:01:55 -0400111static const u8 *get_mac_for_key(struct ieee80211_key *key)
112{
113 const u8 *addr = bcast_addr;
114
115 /*
116 * If we're an AP we won't ever receive frames with a non-WEP
117 * group key so we tell the driver that by using the zero MAC
118 * address to indicate a transmit-only key.
119 */
120 if (key->conf.alg != ALG_WEP &&
Johannes Berg05c914f2008-09-11 00:01:58 +0200121 (key->sdata->vif.type == NL80211_IFTYPE_AP ||
122 key->sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
Johannes Berg11a843b2007-08-28 17:01:55 -0400123 addr = zero_addr;
124
125 if (key->sta)
Johannes Berg17741cd2008-09-11 00:02:02 +0200126 addr = key->sta->sta.addr;
Johannes Berg11a843b2007-08-28 17:01:55 -0400127
128 return addr;
129}
130
131static void ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
132{
133 const u8 *addr;
134 int ret;
Joe Perches0795af52007-10-03 17:59:30 -0700135 DECLARE_MAC_BUF(mac);
Johannes Berg11a843b2007-08-28 17:01:55 -0400136
Johannes Berg3b967662008-04-08 17:56:52 +0200137 assert_key_lock();
138 might_sleep();
139
Johannes Berg11a843b2007-08-28 17:01:55 -0400140 if (!key->local->ops->set_key)
141 return;
142
143 addr = get_mac_for_key(key);
144
145 ret = key->local->ops->set_key(local_to_hw(key->local), SET_KEY,
146 key->sdata->dev->dev_addr, addr,
147 &key->conf);
148
Johannes Berg3b967662008-04-08 17:56:52 +0200149 if (!ret) {
150 spin_lock(&todo_lock);
Johannes Berg11a843b2007-08-28 17:01:55 -0400151 key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE;
Johannes Berg3b967662008-04-08 17:56:52 +0200152 spin_unlock(&todo_lock);
153 }
Johannes Berg11a843b2007-08-28 17:01:55 -0400154
155 if (ret && ret != -ENOSPC && ret != -EOPNOTSUPP)
156 printk(KERN_ERR "mac80211-%s: failed to set key "
Joe Perches0795af52007-10-03 17:59:30 -0700157 "(%d, %s) to hardware (%d)\n",
Johannes Berg11a843b2007-08-28 17:01:55 -0400158 wiphy_name(key->local->hw.wiphy),
Joe Perches0795af52007-10-03 17:59:30 -0700159 key->conf.keyidx, print_mac(mac, addr), ret);
Johannes Berg11a843b2007-08-28 17:01:55 -0400160}
161
162static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
163{
164 const u8 *addr;
165 int ret;
Joe Perches0795af52007-10-03 17:59:30 -0700166 DECLARE_MAC_BUF(mac);
Johannes Berg11a843b2007-08-28 17:01:55 -0400167
Johannes Berg3b967662008-04-08 17:56:52 +0200168 assert_key_lock();
169 might_sleep();
170
Johannes Bergdb4d1162008-02-25 16:27:45 +0100171 if (!key || !key->local->ops->set_key)
Johannes Berg11a843b2007-08-28 17:01:55 -0400172 return;
173
Johannes Berg3b967662008-04-08 17:56:52 +0200174 spin_lock(&todo_lock);
175 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) {
176 spin_unlock(&todo_lock);
Johannes Berg11a843b2007-08-28 17:01:55 -0400177 return;
Johannes Berg3b967662008-04-08 17:56:52 +0200178 }
179 spin_unlock(&todo_lock);
Johannes Berg11a843b2007-08-28 17:01:55 -0400180
181 addr = get_mac_for_key(key);
182
183 ret = key->local->ops->set_key(local_to_hw(key->local), DISABLE_KEY,
184 key->sdata->dev->dev_addr, addr,
185 &key->conf);
186
187 if (ret)
188 printk(KERN_ERR "mac80211-%s: failed to remove key "
Joe Perches0795af52007-10-03 17:59:30 -0700189 "(%d, %s) from hardware (%d)\n",
Johannes Berg11a843b2007-08-28 17:01:55 -0400190 wiphy_name(key->local->hw.wiphy),
Joe Perches0795af52007-10-03 17:59:30 -0700191 key->conf.keyidx, print_mac(mac, addr), ret);
Johannes Berg11a843b2007-08-28 17:01:55 -0400192
Johannes Berg3b967662008-04-08 17:56:52 +0200193 spin_lock(&todo_lock);
194 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
195 spin_unlock(&todo_lock);
196}
197
198static void __ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata,
199 int idx)
200{
201 struct ieee80211_key *key = NULL;
202
203 if (idx >= 0 && idx < NUM_DEFAULT_KEYS)
204 key = sdata->keys[idx];
205
206 rcu_assign_pointer(sdata->default_key, key);
207
208 if (key)
209 add_todo(key, KEY_FLAG_TODO_DEFKEY);
210}
211
212void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx)
213{
214 unsigned long flags;
215
Johannes Bergb16bd152008-04-11 21:40:35 +0200216 spin_lock_irqsave(&sdata->local->key_lock, flags);
Johannes Berg3b967662008-04-08 17:56:52 +0200217 __ieee80211_set_default_key(sdata, idx);
Johannes Bergb16bd152008-04-11 21:40:35 +0200218 spin_unlock_irqrestore(&sdata->local->key_lock, flags);
Johannes Berg3b967662008-04-08 17:56:52 +0200219}
220
221
222static void __ieee80211_key_replace(struct ieee80211_sub_if_data *sdata,
223 struct sta_info *sta,
224 struct ieee80211_key *old,
225 struct ieee80211_key *new)
226{
227 int idx, defkey;
228
229 if (new)
230 list_add(&new->list, &sdata->key_list);
231
232 if (sta) {
233 rcu_assign_pointer(sta->key, new);
234 } else {
235 WARN_ON(new && old && new->conf.keyidx != old->conf.keyidx);
236
237 if (old)
238 idx = old->conf.keyidx;
239 else
240 idx = new->conf.keyidx;
241
242 defkey = old && sdata->default_key == old;
243
244 if (defkey && !new)
245 __ieee80211_set_default_key(sdata, -1);
246
247 rcu_assign_pointer(sdata->keys[idx], new);
248 if (defkey && new)
249 __ieee80211_set_default_key(sdata, new->conf.keyidx);
250 }
251
252 if (old) {
253 /*
254 * We'll use an empty list to indicate that the key
255 * has already been removed.
256 */
257 list_del_init(&old->list);
258 }
Johannes Berg11a843b2007-08-28 17:01:55 -0400259}
260
Johannes Bergdb4d1162008-02-25 16:27:45 +0100261struct ieee80211_key *ieee80211_key_alloc(enum ieee80211_key_alg alg,
Johannes Berg11a843b2007-08-28 17:01:55 -0400262 int idx,
263 size_t key_len,
264 const u8 *key_data)
Johannes Berg1f5a7e42007-07-27 15:43:23 +0200265{
266 struct ieee80211_key *key;
267
Johannes Bergd4e46a32007-09-14 11:10:24 -0400268 BUG_ON(idx < 0 || idx >= NUM_DEFAULT_KEYS);
Johannes Berg11a843b2007-08-28 17:01:55 -0400269
270 key = kzalloc(sizeof(struct ieee80211_key) + key_len, GFP_KERNEL);
Johannes Berg1f5a7e42007-07-27 15:43:23 +0200271 if (!key)
272 return NULL;
Johannes Berg11a843b2007-08-28 17:01:55 -0400273
274 /*
275 * Default to software encryption; we'll later upload the
276 * key to the hardware if possible.
277 */
Johannes Berg11a843b2007-08-28 17:01:55 -0400278 key->conf.flags = 0;
279 key->flags = 0;
280
281 key->conf.alg = alg;
282 key->conf.keyidx = idx;
283 key->conf.keylen = key_len;
Felix Fietkau76708de2008-10-05 18:02:48 +0200284 switch (alg) {
285 case ALG_WEP:
286 key->conf.iv_len = WEP_IV_LEN;
287 key->conf.icv_len = WEP_ICV_LEN;
288 break;
289 case ALG_TKIP:
290 key->conf.iv_len = TKIP_IV_LEN;
291 key->conf.icv_len = TKIP_ICV_LEN;
292 break;
293 case ALG_CCMP:
294 key->conf.iv_len = CCMP_HDR_LEN;
295 key->conf.icv_len = CCMP_MIC_LEN;
296 break;
297 }
Johannes Berg11a843b2007-08-28 17:01:55 -0400298 memcpy(key->conf.key, key_data, key_len);
Johannes Berge48618292008-02-27 13:39:00 +0100299 INIT_LIST_HEAD(&key->list);
Johannes Berg3b967662008-04-08 17:56:52 +0200300 INIT_LIST_HEAD(&key->todo);
Johannes Berg11a843b2007-08-28 17:01:55 -0400301
Johannes Berg11a843b2007-08-28 17:01:55 -0400302 if (alg == ALG_CCMP) {
303 /*
304 * Initialize AES key state here as an optimization so that
305 * it does not need to be initialized for every packet.
306 */
307 key->u.ccmp.tfm = ieee80211_aes_key_setup_encrypt(key_data);
308 if (!key->u.ccmp.tfm) {
Johannes Berg3b967662008-04-08 17:56:52 +0200309 kfree(key);
Johannes Berg11a843b2007-08-28 17:01:55 -0400310 return NULL;
311 }
312 }
313
Johannes Bergdb4d1162008-02-25 16:27:45 +0100314 return key;
315}
Johannes Berg11a843b2007-08-28 17:01:55 -0400316
Johannes Bergdb4d1162008-02-25 16:27:45 +0100317void ieee80211_key_link(struct ieee80211_key *key,
318 struct ieee80211_sub_if_data *sdata,
319 struct sta_info *sta)
320{
321 struct ieee80211_key *old_key;
Johannes Berg3b967662008-04-08 17:56:52 +0200322 unsigned long flags;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100323 int idx;
324
Johannes Bergdb4d1162008-02-25 16:27:45 +0100325 BUG_ON(!sdata);
326 BUG_ON(!key);
327
328 idx = key->conf.keyidx;
329 key->local = sdata->local;
330 key->sdata = sdata;
331 key->sta = sta;
332
Johannes Berg11a843b2007-08-28 17:01:55 -0400333 if (sta) {
Johannes Berg11a843b2007-08-28 17:01:55 -0400334 /*
335 * some hardware cannot handle TKIP with QoS, so
336 * we indicate whether QoS could be in use.
337 */
Johannes Berg07346f812008-05-03 01:02:02 +0200338 if (test_sta_flags(sta, WLAN_STA_WME))
Johannes Berg11a843b2007-08-28 17:01:55 -0400339 key->conf.flags |= IEEE80211_KEY_FLAG_WMM_STA;
Ivo van Doornc6adbd22008-04-17 21:11:18 +0200340
341 /*
342 * This key is for a specific sta interface,
343 * inform the driver that it should try to store
344 * this key as pairwise key.
345 */
346 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
Johannes Berg11a843b2007-08-28 17:01:55 -0400347 } else {
Johannes Berg05c914f2008-09-11 00:01:58 +0200348 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Berg11a843b2007-08-28 17:01:55 -0400349 struct sta_info *ap;
350
Johannes Berg3b967662008-04-08 17:56:52 +0200351 /*
352 * We're getting a sta pointer in,
353 * so must be under RCU read lock.
354 */
Johannes Bergd0709a62008-02-25 16:27:46 +0100355
Johannes Berg11a843b2007-08-28 17:01:55 -0400356 /* same here, the AP could be using QoS */
357 ap = sta_info_get(key->local, key->sdata->u.sta.bssid);
358 if (ap) {
Johannes Berg07346f812008-05-03 01:02:02 +0200359 if (test_sta_flags(ap, WLAN_STA_WME))
Johannes Berg11a843b2007-08-28 17:01:55 -0400360 key->conf.flags |=
361 IEEE80211_KEY_FLAG_WMM_STA;
Johannes Berg11a843b2007-08-28 17:01:55 -0400362 }
363 }
Johannes Berg11a843b2007-08-28 17:01:55 -0400364 }
365
Johannes Bergb16bd152008-04-11 21:40:35 +0200366 spin_lock_irqsave(&sdata->local->key_lock, flags);
Johannes Berg3b967662008-04-08 17:56:52 +0200367
Johannes Bergd4e46a32007-09-14 11:10:24 -0400368 if (sta)
Johannes Bergdb4d1162008-02-25 16:27:45 +0100369 old_key = sta->key;
Johannes Bergd4e46a32007-09-14 11:10:24 -0400370 else
Johannes Bergdb4d1162008-02-25 16:27:45 +0100371 old_key = sdata->keys[idx];
372
373 __ieee80211_key_replace(sdata, sta, old_key, key);
Johannes Bergd4e46a32007-09-14 11:10:24 -0400374
Johannes Bergb16bd152008-04-11 21:40:35 +0200375 spin_unlock_irqrestore(&sdata->local->key_lock, flags);
Johannes Bergd4e46a32007-09-14 11:10:24 -0400376
Johannes Berg3b967662008-04-08 17:56:52 +0200377 /* free old key later */
378 add_todo(old_key, KEY_FLAG_TODO_DELETE);
379
380 add_todo(key, KEY_FLAG_TODO_ADD_DEBUGFS);
Johannes Berge48618292008-02-27 13:39:00 +0100381 if (netif_running(sdata->dev))
Johannes Berg3a245762008-04-09 16:45:37 +0200382 add_todo(key, KEY_FLAG_TODO_HWACCEL_ADD);
383}
384
385static void __ieee80211_key_free(struct ieee80211_key *key)
386{
387 /*
388 * Replace key with nothingness if it was ever used.
389 */
390 if (key->sdata)
391 __ieee80211_key_replace(key->sdata, key->sta,
392 key, NULL);
393
394 add_todo(key, KEY_FLAG_TODO_DELETE);
Johannes Berg1f5a7e42007-07-27 15:43:23 +0200395}
396
Johannes Berg1f5a7e42007-07-27 15:43:23 +0200397void ieee80211_key_free(struct ieee80211_key *key)
398{
Johannes Berg3b967662008-04-08 17:56:52 +0200399 unsigned long flags;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100400
Johannes Berg8f371712007-08-28 17:01:54 -0400401 if (!key)
402 return;
403
Emmanuel Grumbach00eb7fe2008-06-26 12:13:46 +0300404 if (!key->sdata) {
405 /* The key has not been linked yet, simply free it
406 * and don't Oops */
407 if (key->conf.alg == ALG_CCMP)
408 ieee80211_aes_key_free(key->u.ccmp.tfm);
409 kfree(key);
410 return;
411 }
412
Johannes Bergb16bd152008-04-11 21:40:35 +0200413 spin_lock_irqsave(&key->sdata->local->key_lock, flags);
Johannes Berg3a245762008-04-09 16:45:37 +0200414 __ieee80211_key_free(key);
Johannes Bergb16bd152008-04-11 21:40:35 +0200415 spin_unlock_irqrestore(&key->sdata->local->key_lock, flags);
Johannes Berg3a245762008-04-09 16:45:37 +0200416}
Johannes Berg11a843b2007-08-28 17:01:55 -0400417
Johannes Berg3a245762008-04-09 16:45:37 +0200418/*
419 * To be safe against concurrent manipulations of the list (which shouldn't
420 * actually happen) we need to hold the spinlock. But under the spinlock we
421 * can't actually do much, so we defer processing to the todo list. Then run
422 * the todo list to be sure the operation and possibly previously pending
423 * operations are completed.
424 */
425static void ieee80211_todo_for_each_key(struct ieee80211_sub_if_data *sdata,
426 u32 todo_flags)
427{
428 struct ieee80211_key *key;
429 unsigned long flags;
430
431 might_sleep();
432
Johannes Bergb16bd152008-04-11 21:40:35 +0200433 spin_lock_irqsave(&sdata->local->key_lock, flags);
Johannes Berg3a245762008-04-09 16:45:37 +0200434 list_for_each_entry(key, &sdata->key_list, list)
435 add_todo(key, todo_flags);
Johannes Bergb16bd152008-04-11 21:40:35 +0200436 spin_unlock_irqrestore(&sdata->local->key_lock, flags);
Johannes Berg3a245762008-04-09 16:45:37 +0200437
438 ieee80211_key_todo();
Johannes Berg3b967662008-04-08 17:56:52 +0200439}
440
441void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata)
442{
Johannes Berg3a245762008-04-09 16:45:37 +0200443 ASSERT_RTNL();
Johannes Berg3b967662008-04-08 17:56:52 +0200444
445 if (WARN_ON(!netif_running(sdata->dev)))
446 return;
447
Johannes Berg3a245762008-04-09 16:45:37 +0200448 ieee80211_todo_for_each_key(sdata, KEY_FLAG_TODO_HWACCEL_ADD);
Johannes Berg3b967662008-04-08 17:56:52 +0200449}
450
451void ieee80211_disable_keys(struct ieee80211_sub_if_data *sdata)
452{
Johannes Berg3a245762008-04-09 16:45:37 +0200453 ASSERT_RTNL();
Johannes Berg3b967662008-04-08 17:56:52 +0200454
Johannes Berg3a245762008-04-09 16:45:37 +0200455 ieee80211_todo_for_each_key(sdata, KEY_FLAG_TODO_HWACCEL_REMOVE);
Johannes Berg3b967662008-04-08 17:56:52 +0200456}
457
Johannes Berg3a245762008-04-09 16:45:37 +0200458static void __ieee80211_key_destroy(struct ieee80211_key *key)
Johannes Berg3b967662008-04-08 17:56:52 +0200459{
460 if (!key)
461 return;
462
463 ieee80211_key_disable_hw_accel(key);
464
Johannes Berg8f371712007-08-28 17:01:54 -0400465 if (key->conf.alg == ALG_CCMP)
466 ieee80211_aes_key_free(key->u.ccmp.tfm);
467 ieee80211_debugfs_key_remove(key);
Johannes Berg11a843b2007-08-28 17:01:55 -0400468
Johannes Berg8f371712007-08-28 17:01:54 -0400469 kfree(key);
Johannes Berg1f5a7e42007-07-27 15:43:23 +0200470}
Johannes Berg11a843b2007-08-28 17:01:55 -0400471
Johannes Berg3b967662008-04-08 17:56:52 +0200472static void __ieee80211_key_todo(void)
Johannes Berg11a843b2007-08-28 17:01:55 -0400473{
Johannes Berg3b967662008-04-08 17:56:52 +0200474 struct ieee80211_key *key;
475 bool work_done;
476 u32 todoflags;
Johannes Berg11a843b2007-08-28 17:01:55 -0400477
Johannes Berg3b967662008-04-08 17:56:52 +0200478 /*
479 * NB: sta_info_destroy relies on this!
480 */
481 synchronize_rcu();
Johannes Berg11a843b2007-08-28 17:01:55 -0400482
Johannes Berg3b967662008-04-08 17:56:52 +0200483 spin_lock(&todo_lock);
484 while (!list_empty(&todo_list)) {
485 key = list_first_entry(&todo_list, struct ieee80211_key, todo);
486 list_del_init(&key->todo);
487 todoflags = key->flags & (KEY_FLAG_TODO_ADD_DEBUGFS |
488 KEY_FLAG_TODO_DEFKEY |
Johannes Berg3a245762008-04-09 16:45:37 +0200489 KEY_FLAG_TODO_HWACCEL_ADD |
490 KEY_FLAG_TODO_HWACCEL_REMOVE |
Johannes Berg3b967662008-04-08 17:56:52 +0200491 KEY_FLAG_TODO_DELETE);
492 key->flags &= ~todoflags;
493 spin_unlock(&todo_lock);
Johannes Berg11a843b2007-08-28 17:01:55 -0400494
Johannes Berg3b967662008-04-08 17:56:52 +0200495 work_done = false;
Johannes Berg11a843b2007-08-28 17:01:55 -0400496
Johannes Berg3b967662008-04-08 17:56:52 +0200497 if (todoflags & KEY_FLAG_TODO_ADD_DEBUGFS) {
498 ieee80211_debugfs_key_add(key);
499 work_done = true;
500 }
501 if (todoflags & KEY_FLAG_TODO_DEFKEY) {
502 ieee80211_debugfs_key_remove_default(key->sdata);
503 ieee80211_debugfs_key_add_default(key->sdata);
504 work_done = true;
505 }
Johannes Berg3a245762008-04-09 16:45:37 +0200506 if (todoflags & KEY_FLAG_TODO_HWACCEL_ADD) {
Johannes Berg3b967662008-04-08 17:56:52 +0200507 ieee80211_key_enable_hw_accel(key);
508 work_done = true;
509 }
Johannes Berg3a245762008-04-09 16:45:37 +0200510 if (todoflags & KEY_FLAG_TODO_HWACCEL_REMOVE) {
511 ieee80211_key_disable_hw_accel(key);
512 work_done = true;
513 }
Johannes Berg3b967662008-04-08 17:56:52 +0200514 if (todoflags & KEY_FLAG_TODO_DELETE) {
Johannes Berg3a245762008-04-09 16:45:37 +0200515 __ieee80211_key_destroy(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200516 work_done = true;
517 }
518
519 WARN_ON(!work_done);
520
521 spin_lock(&todo_lock);
Johannes Berg11a843b2007-08-28 17:01:55 -0400522 }
Johannes Berg3b967662008-04-08 17:56:52 +0200523 spin_unlock(&todo_lock);
524}
525
526void ieee80211_key_todo(void)
527{
528 ieee80211_key_lock();
529 __ieee80211_key_todo();
530 ieee80211_key_unlock();
Johannes Berg11a843b2007-08-28 17:01:55 -0400531}
532
533void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata)
534{
535 struct ieee80211_key *key, *tmp;
Johannes Berg3a245762008-04-09 16:45:37 +0200536 unsigned long flags;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100537
Johannes Berg3b967662008-04-08 17:56:52 +0200538 ieee80211_key_lock();
539
540 ieee80211_debugfs_key_remove_default(sdata);
Johannes Berg11a843b2007-08-28 17:01:55 -0400541
Johannes Bergb16bd152008-04-11 21:40:35 +0200542 spin_lock_irqsave(&sdata->local->key_lock, flags);
Johannes Berg11a843b2007-08-28 17:01:55 -0400543 list_for_each_entry_safe(key, tmp, &sdata->key_list, list)
Johannes Berg3a245762008-04-09 16:45:37 +0200544 __ieee80211_key_free(key);
Johannes Bergb16bd152008-04-11 21:40:35 +0200545 spin_unlock_irqrestore(&sdata->local->key_lock, flags);
Johannes Berg11a843b2007-08-28 17:01:55 -0400546
Johannes Berg3b967662008-04-08 17:56:52 +0200547 __ieee80211_key_todo();
Johannes Berg11a843b2007-08-28 17:01:55 -0400548
Johannes Berg3b967662008-04-08 17:56:52 +0200549 ieee80211_key_unlock();
Johannes Berg11a843b2007-08-28 17:01:55 -0400550}