Johannes Berg | 1f5a7e4 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2002-2005, Instant802 Networks, Inc. |
| 3 | * Copyright 2005-2006, Devicescape Software, Inc. |
| 4 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 5 | * Copyright 2007-2008 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 1f5a7e4 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 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 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/etherdevice.h> |
| 14 | #include <linux/list.h> |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 15 | #include <linux/rcupdate.h> |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 16 | #include <linux/rtnetlink.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Johannes Berg | 1f5a7e4 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 18 | #include <net/mac80211.h> |
| 19 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 20 | #include "driver-ops.h" |
Johannes Berg | 1f5a7e4 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 21 | #include "debugfs_key.h" |
| 22 | #include "aes_ccm.h" |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 23 | #include "aes_cmac.h" |
Johannes Berg | 1f5a7e4 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 24 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 25 | |
Johannes Berg | dbbea67 | 2008-02-26 14:34:06 +0100 | [diff] [blame] | 26 | /** |
| 27 | * DOC: Key handling basics |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 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 | * |
| 33 | * Hardware acceleration is done on a best-effort basis, for each key |
| 34 | * that is eligible the hardware is asked to enable that key but if |
| 35 | * it cannot do that they key is simply kept for software encryption. |
| 36 | * There is currently no way of knowing this except by looking into |
| 37 | * debugfs. |
| 38 | * |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 39 | * All key operations are protected internally so you can call them at |
| 40 | * any time. |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 41 | * |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 42 | * Within mac80211, key references are, just as STA structure references, |
| 43 | * protected by RCU. Note, however, that some things are unprotected, |
| 44 | * namely the key->sta dereferences within the hardware acceleration |
| 45 | * functions. This means that sta_info_destroy() must flush the key todo |
| 46 | * list. |
| 47 | * |
| 48 | * All the direct key list manipulation functions must not sleep because |
| 49 | * they can operate on STA info structs that are protected by RCU. |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 50 | */ |
| 51 | |
| 52 | static const u8 bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 53 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 54 | /* key mutex: used to synchronise todo runners */ |
| 55 | static DEFINE_MUTEX(key_mutex); |
| 56 | static DEFINE_SPINLOCK(todo_lock); |
| 57 | static LIST_HEAD(todo_list); |
| 58 | |
| 59 | static void key_todo(struct work_struct *work) |
| 60 | { |
| 61 | ieee80211_key_todo(); |
| 62 | } |
| 63 | |
| 64 | static DECLARE_WORK(todo_work, key_todo); |
| 65 | |
| 66 | /** |
| 67 | * add_todo - add todo item for a key |
| 68 | * |
| 69 | * @key: key to add to do item for |
| 70 | * @flag: todo flag(s) |
Johannes Berg | 523d2f6 | 2009-07-01 21:26:43 +0200 | [diff] [blame] | 71 | * |
| 72 | * Must be called with IRQs or softirqs disabled. |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 73 | */ |
| 74 | static void add_todo(struct ieee80211_key *key, u32 flag) |
| 75 | { |
| 76 | if (!key) |
| 77 | return; |
| 78 | |
| 79 | spin_lock(&todo_lock); |
| 80 | key->flags |= flag; |
Johannes Berg | 245cbe7 | 2008-04-13 10:43:50 +0200 | [diff] [blame] | 81 | /* |
| 82 | * Remove again if already on the list so that we move it to the end. |
| 83 | */ |
| 84 | if (!list_empty(&key->todo)) |
| 85 | list_del(&key->todo); |
| 86 | list_add_tail(&key->todo, &todo_list); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 87 | schedule_work(&todo_work); |
| 88 | spin_unlock(&todo_lock); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * ieee80211_key_lock - lock the mac80211 key operation lock |
| 93 | * |
| 94 | * This locks the (global) mac80211 key operation lock, all |
| 95 | * key operations must be done under this lock. |
| 96 | */ |
| 97 | static void ieee80211_key_lock(void) |
| 98 | { |
| 99 | mutex_lock(&key_mutex); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * ieee80211_key_unlock - unlock the mac80211 key operation lock |
| 104 | */ |
| 105 | static void ieee80211_key_unlock(void) |
| 106 | { |
| 107 | mutex_unlock(&key_mutex); |
| 108 | } |
| 109 | |
| 110 | static void assert_key_lock(void) |
| 111 | { |
| 112 | WARN_ON(!mutex_is_locked(&key_mutex)); |
| 113 | } |
| 114 | |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 115 | static struct ieee80211_sta *get_sta_for_key(struct ieee80211_key *key) |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 116 | { |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 117 | if (key->sta) |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 118 | return &key->sta->sta; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 119 | |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 120 | return NULL; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | static void ieee80211_key_enable_hw_accel(struct ieee80211_key *key) |
| 124 | { |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 125 | struct ieee80211_sub_if_data *sdata; |
| 126 | struct ieee80211_sta *sta; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 127 | int ret; |
| 128 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 129 | assert_key_lock(); |
| 130 | might_sleep(); |
| 131 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 132 | if (!key->local->ops->set_key) |
| 133 | return; |
| 134 | |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 135 | sta = get_sta_for_key(key); |
| 136 | |
| 137 | sdata = key->sdata; |
| 138 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 139 | sdata = container_of(sdata->bss, |
| 140 | struct ieee80211_sub_if_data, |
| 141 | u.ap); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 142 | |
Daniel Yingqiang Ma | 03ceede | 2010-04-13 15:12:07 +0800 | [diff] [blame] | 143 | key->conf.ap_addr = sdata->dev->dev_addr; |
Johannes Berg | 12375ef | 2009-11-25 20:30:31 +0100 | [diff] [blame] | 144 | ret = drv_set_key(key->local, SET_KEY, sdata, sta, &key->conf); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 145 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 146 | if (!ret) { |
Johannes Berg | 523d2f6 | 2009-07-01 21:26:43 +0200 | [diff] [blame] | 147 | spin_lock_bh(&todo_lock); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 148 | key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE; |
Johannes Berg | 523d2f6 | 2009-07-01 21:26:43 +0200 | [diff] [blame] | 149 | spin_unlock_bh(&todo_lock); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 150 | } |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 151 | |
| 152 | if (ret && ret != -ENOSPC && ret != -EOPNOTSUPP) |
| 153 | printk(KERN_ERR "mac80211-%s: failed to set key " |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 154 | "(%d, %pM) to hardware (%d)\n", |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 155 | wiphy_name(key->local->hw.wiphy), |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 156 | key->conf.keyidx, sta ? sta->addr : bcast_addr, ret); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key) |
| 160 | { |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 161 | struct ieee80211_sub_if_data *sdata; |
| 162 | struct ieee80211_sta *sta; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 163 | int ret; |
| 164 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 165 | assert_key_lock(); |
| 166 | might_sleep(); |
| 167 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 168 | if (!key || !key->local->ops->set_key) |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 169 | return; |
| 170 | |
Johannes Berg | 523d2f6 | 2009-07-01 21:26:43 +0200 | [diff] [blame] | 171 | spin_lock_bh(&todo_lock); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 172 | if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) { |
Johannes Berg | 523d2f6 | 2009-07-01 21:26:43 +0200 | [diff] [blame] | 173 | spin_unlock_bh(&todo_lock); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 174 | return; |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 175 | } |
Johannes Berg | 523d2f6 | 2009-07-01 21:26:43 +0200 | [diff] [blame] | 176 | spin_unlock_bh(&todo_lock); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 177 | |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 178 | sta = get_sta_for_key(key); |
| 179 | sdata = key->sdata; |
| 180 | |
| 181 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 182 | sdata = container_of(sdata->bss, |
| 183 | struct ieee80211_sub_if_data, |
| 184 | u.ap); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 185 | |
Johannes Berg | 12375ef | 2009-11-25 20:30:31 +0100 | [diff] [blame] | 186 | ret = drv_set_key(key->local, DISABLE_KEY, sdata, |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 187 | sta, &key->conf); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 188 | |
| 189 | if (ret) |
| 190 | printk(KERN_ERR "mac80211-%s: failed to remove key " |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 191 | "(%d, %pM) from hardware (%d)\n", |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 192 | wiphy_name(key->local->hw.wiphy), |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 193 | key->conf.keyidx, sta ? sta->addr : bcast_addr, ret); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 194 | |
Johannes Berg | 523d2f6 | 2009-07-01 21:26:43 +0200 | [diff] [blame] | 195 | spin_lock_bh(&todo_lock); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 196 | key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE; |
Johannes Berg | 523d2f6 | 2009-07-01 21:26:43 +0200 | [diff] [blame] | 197 | spin_unlock_bh(&todo_lock); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | static void __ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, |
| 201 | int idx) |
| 202 | { |
| 203 | struct ieee80211_key *key = NULL; |
| 204 | |
| 205 | if (idx >= 0 && idx < NUM_DEFAULT_KEYS) |
| 206 | key = sdata->keys[idx]; |
| 207 | |
| 208 | rcu_assign_pointer(sdata->default_key, key); |
| 209 | |
| 210 | if (key) |
| 211 | add_todo(key, KEY_FLAG_TODO_DEFKEY); |
| 212 | } |
| 213 | |
| 214 | void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx) |
| 215 | { |
| 216 | unsigned long flags; |
| 217 | |
Johannes Berg | b16bd15 | 2008-04-11 21:40:35 +0200 | [diff] [blame] | 218 | spin_lock_irqsave(&sdata->local->key_lock, flags); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 219 | __ieee80211_set_default_key(sdata, idx); |
Johannes Berg | b16bd15 | 2008-04-11 21:40:35 +0200 | [diff] [blame] | 220 | spin_unlock_irqrestore(&sdata->local->key_lock, flags); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 221 | } |
| 222 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 223 | static void |
| 224 | __ieee80211_set_default_mgmt_key(struct ieee80211_sub_if_data *sdata, int idx) |
| 225 | { |
| 226 | struct ieee80211_key *key = NULL; |
| 227 | |
| 228 | if (idx >= NUM_DEFAULT_KEYS && |
| 229 | idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) |
| 230 | key = sdata->keys[idx]; |
| 231 | |
| 232 | rcu_assign_pointer(sdata->default_mgmt_key, key); |
| 233 | |
| 234 | if (key) |
| 235 | add_todo(key, KEY_FLAG_TODO_DEFMGMTKEY); |
| 236 | } |
| 237 | |
| 238 | void ieee80211_set_default_mgmt_key(struct ieee80211_sub_if_data *sdata, |
| 239 | int idx) |
| 240 | { |
| 241 | unsigned long flags; |
| 242 | |
| 243 | spin_lock_irqsave(&sdata->local->key_lock, flags); |
| 244 | __ieee80211_set_default_mgmt_key(sdata, idx); |
| 245 | spin_unlock_irqrestore(&sdata->local->key_lock, flags); |
| 246 | } |
| 247 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 248 | |
| 249 | static void __ieee80211_key_replace(struct ieee80211_sub_if_data *sdata, |
| 250 | struct sta_info *sta, |
| 251 | struct ieee80211_key *old, |
| 252 | struct ieee80211_key *new) |
| 253 | { |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 254 | int idx, defkey, defmgmtkey; |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 255 | |
| 256 | if (new) |
| 257 | list_add(&new->list, &sdata->key_list); |
| 258 | |
| 259 | if (sta) { |
| 260 | rcu_assign_pointer(sta->key, new); |
| 261 | } else { |
| 262 | WARN_ON(new && old && new->conf.keyidx != old->conf.keyidx); |
| 263 | |
| 264 | if (old) |
| 265 | idx = old->conf.keyidx; |
| 266 | else |
| 267 | idx = new->conf.keyidx; |
| 268 | |
| 269 | defkey = old && sdata->default_key == old; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 270 | defmgmtkey = old && sdata->default_mgmt_key == old; |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 271 | |
| 272 | if (defkey && !new) |
| 273 | __ieee80211_set_default_key(sdata, -1); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 274 | if (defmgmtkey && !new) |
| 275 | __ieee80211_set_default_mgmt_key(sdata, -1); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 276 | |
| 277 | rcu_assign_pointer(sdata->keys[idx], new); |
| 278 | if (defkey && new) |
| 279 | __ieee80211_set_default_key(sdata, new->conf.keyidx); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 280 | if (defmgmtkey && new) |
| 281 | __ieee80211_set_default_mgmt_key(sdata, |
| 282 | new->conf.keyidx); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | if (old) { |
| 286 | /* |
| 287 | * We'll use an empty list to indicate that the key |
| 288 | * has already been removed. |
| 289 | */ |
| 290 | list_del_init(&old->list); |
| 291 | } |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 292 | } |
| 293 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 294 | struct ieee80211_key *ieee80211_key_alloc(enum ieee80211_key_alg alg, |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 295 | int idx, |
| 296 | size_t key_len, |
Jouni Malinen | faa8fdc | 2009-05-11 21:57:58 +0300 | [diff] [blame] | 297 | const u8 *key_data, |
| 298 | size_t seq_len, const u8 *seq) |
Johannes Berg | 1f5a7e4 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 299 | { |
| 300 | struct ieee80211_key *key; |
Jouni Malinen | faa8fdc | 2009-05-11 21:57:58 +0300 | [diff] [blame] | 301 | int i, j; |
Johannes Berg | 1f5a7e4 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 302 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 303 | BUG_ON(idx < 0 || idx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 304 | |
| 305 | key = kzalloc(sizeof(struct ieee80211_key) + key_len, GFP_KERNEL); |
Johannes Berg | 1f5a7e4 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 306 | if (!key) |
| 307 | return NULL; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 308 | |
| 309 | /* |
| 310 | * Default to software encryption; we'll later upload the |
| 311 | * key to the hardware if possible. |
| 312 | */ |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 313 | key->conf.flags = 0; |
| 314 | key->flags = 0; |
| 315 | |
| 316 | key->conf.alg = alg; |
| 317 | key->conf.keyidx = idx; |
| 318 | key->conf.keylen = key_len; |
Felix Fietkau | 76708de | 2008-10-05 18:02:48 +0200 | [diff] [blame] | 319 | switch (alg) { |
| 320 | case ALG_WEP: |
| 321 | key->conf.iv_len = WEP_IV_LEN; |
| 322 | key->conf.icv_len = WEP_ICV_LEN; |
| 323 | break; |
| 324 | case ALG_TKIP: |
| 325 | key->conf.iv_len = TKIP_IV_LEN; |
| 326 | key->conf.icv_len = TKIP_ICV_LEN; |
Jouni Malinen | 9f26a95 | 2009-05-15 12:38:32 +0300 | [diff] [blame] | 327 | if (seq) { |
Jouni Malinen | faa8fdc | 2009-05-11 21:57:58 +0300 | [diff] [blame] | 328 | for (i = 0; i < NUM_RX_DATA_QUEUES; i++) { |
| 329 | key->u.tkip.rx[i].iv32 = |
| 330 | get_unaligned_le32(&seq[2]); |
| 331 | key->u.tkip.rx[i].iv16 = |
| 332 | get_unaligned_le16(seq); |
| 333 | } |
| 334 | } |
Felix Fietkau | 76708de | 2008-10-05 18:02:48 +0200 | [diff] [blame] | 335 | break; |
| 336 | case ALG_CCMP: |
| 337 | key->conf.iv_len = CCMP_HDR_LEN; |
| 338 | key->conf.icv_len = CCMP_MIC_LEN; |
Jouni Malinen | 9f26a95 | 2009-05-15 12:38:32 +0300 | [diff] [blame] | 339 | if (seq) { |
Jouni Malinen | faa8fdc | 2009-05-11 21:57:58 +0300 | [diff] [blame] | 340 | for (i = 0; i < NUM_RX_DATA_QUEUES; i++) |
| 341 | for (j = 0; j < CCMP_PN_LEN; j++) |
| 342 | key->u.ccmp.rx_pn[i][j] = |
| 343 | seq[CCMP_PN_LEN - j - 1]; |
| 344 | } |
Felix Fietkau | 76708de | 2008-10-05 18:02:48 +0200 | [diff] [blame] | 345 | break; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 346 | case ALG_AES_CMAC: |
| 347 | key->conf.iv_len = 0; |
| 348 | key->conf.icv_len = sizeof(struct ieee80211_mmie); |
Jouni Malinen | 9f26a95 | 2009-05-15 12:38:32 +0300 | [diff] [blame] | 349 | if (seq) |
Jouni Malinen | faa8fdc | 2009-05-11 21:57:58 +0300 | [diff] [blame] | 350 | for (j = 0; j < 6; j++) |
| 351 | key->u.aes_cmac.rx_pn[j] = seq[6 - j - 1]; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 352 | break; |
Felix Fietkau | 76708de | 2008-10-05 18:02:48 +0200 | [diff] [blame] | 353 | } |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 354 | memcpy(key->conf.key, key_data, key_len); |
Johannes Berg | e4861829 | 2008-02-27 13:39:00 +0100 | [diff] [blame] | 355 | INIT_LIST_HEAD(&key->list); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 356 | INIT_LIST_HEAD(&key->todo); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 357 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 358 | if (alg == ALG_CCMP) { |
| 359 | /* |
| 360 | * Initialize AES key state here as an optimization so that |
| 361 | * it does not need to be initialized for every packet. |
| 362 | */ |
| 363 | key->u.ccmp.tfm = ieee80211_aes_key_setup_encrypt(key_data); |
| 364 | if (!key->u.ccmp.tfm) { |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 365 | kfree(key); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 366 | return NULL; |
| 367 | } |
| 368 | } |
| 369 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 370 | if (alg == ALG_AES_CMAC) { |
| 371 | /* |
| 372 | * Initialize AES key state here as an optimization so that |
| 373 | * it does not need to be initialized for every packet. |
| 374 | */ |
| 375 | key->u.aes_cmac.tfm = |
| 376 | ieee80211_aes_cmac_key_setup(key_data); |
| 377 | if (!key->u.aes_cmac.tfm) { |
| 378 | kfree(key); |
| 379 | return NULL; |
| 380 | } |
| 381 | } |
| 382 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 383 | return key; |
| 384 | } |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 385 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 386 | void ieee80211_key_link(struct ieee80211_key *key, |
| 387 | struct ieee80211_sub_if_data *sdata, |
| 388 | struct sta_info *sta) |
| 389 | { |
| 390 | struct ieee80211_key *old_key; |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 391 | unsigned long flags; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 392 | int idx; |
| 393 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 394 | BUG_ON(!sdata); |
| 395 | BUG_ON(!key); |
| 396 | |
| 397 | idx = key->conf.keyidx; |
| 398 | key->local = sdata->local; |
| 399 | key->sdata = sdata; |
| 400 | key->sta = sta; |
| 401 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 402 | if (sta) { |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 403 | /* |
| 404 | * some hardware cannot handle TKIP with QoS, so |
| 405 | * we indicate whether QoS could be in use. |
| 406 | */ |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 407 | if (test_sta_flags(sta, WLAN_STA_WME)) |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 408 | key->conf.flags |= IEEE80211_KEY_FLAG_WMM_STA; |
Ivo van Doorn | c6adbd2 | 2008-04-17 21:11:18 +0200 | [diff] [blame] | 409 | |
| 410 | /* |
| 411 | * This key is for a specific sta interface, |
| 412 | * inform the driver that it should try to store |
| 413 | * this key as pairwise key. |
| 414 | */ |
| 415 | key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 416 | } else { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 417 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 418 | struct sta_info *ap; |
| 419 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 420 | /* |
| 421 | * We're getting a sta pointer in, |
| 422 | * so must be under RCU read lock. |
| 423 | */ |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 424 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 425 | /* same here, the AP could be using QoS */ |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 426 | ap = sta_info_get(key->sdata, key->sdata->u.mgd.bssid); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 427 | if (ap) { |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 428 | if (test_sta_flags(ap, WLAN_STA_WME)) |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 429 | key->conf.flags |= |
| 430 | IEEE80211_KEY_FLAG_WMM_STA; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 431 | } |
| 432 | } |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 433 | } |
| 434 | |
Johannes Berg | b16bd15 | 2008-04-11 21:40:35 +0200 | [diff] [blame] | 435 | spin_lock_irqsave(&sdata->local->key_lock, flags); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 436 | |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 437 | if (sta) |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 438 | old_key = sta->key; |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 439 | else |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 440 | old_key = sdata->keys[idx]; |
| 441 | |
| 442 | __ieee80211_key_replace(sdata, sta, old_key, key); |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 443 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 444 | /* free old key later */ |
| 445 | add_todo(old_key, KEY_FLAG_TODO_DELETE); |
| 446 | |
| 447 | add_todo(key, KEY_FLAG_TODO_ADD_DEBUGFS); |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 448 | if (ieee80211_sdata_running(sdata)) |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 449 | add_todo(key, KEY_FLAG_TODO_HWACCEL_ADD); |
Johannes Berg | 523d2f6 | 2009-07-01 21:26:43 +0200 | [diff] [blame] | 450 | |
| 451 | spin_unlock_irqrestore(&sdata->local->key_lock, flags); |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | static void __ieee80211_key_free(struct ieee80211_key *key) |
| 455 | { |
| 456 | /* |
| 457 | * Replace key with nothingness if it was ever used. |
| 458 | */ |
| 459 | if (key->sdata) |
| 460 | __ieee80211_key_replace(key->sdata, key->sta, |
| 461 | key, NULL); |
| 462 | |
| 463 | add_todo(key, KEY_FLAG_TODO_DELETE); |
Johannes Berg | 1f5a7e4 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 464 | } |
| 465 | |
Johannes Berg | 1f5a7e4 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 466 | void ieee80211_key_free(struct ieee80211_key *key) |
| 467 | { |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 468 | unsigned long flags; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 469 | |
Johannes Berg | 8f37171 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 470 | if (!key) |
| 471 | return; |
| 472 | |
Emmanuel Grumbach | 00eb7fe | 2008-06-26 12:13:46 +0300 | [diff] [blame] | 473 | if (!key->sdata) { |
| 474 | /* The key has not been linked yet, simply free it |
| 475 | * and don't Oops */ |
| 476 | if (key->conf.alg == ALG_CCMP) |
| 477 | ieee80211_aes_key_free(key->u.ccmp.tfm); |
| 478 | kfree(key); |
| 479 | return; |
| 480 | } |
| 481 | |
Johannes Berg | b16bd15 | 2008-04-11 21:40:35 +0200 | [diff] [blame] | 482 | spin_lock_irqsave(&key->sdata->local->key_lock, flags); |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 483 | __ieee80211_key_free(key); |
Johannes Berg | b16bd15 | 2008-04-11 21:40:35 +0200 | [diff] [blame] | 484 | spin_unlock_irqrestore(&key->sdata->local->key_lock, flags); |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 485 | } |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 486 | |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 487 | /* |
| 488 | * To be safe against concurrent manipulations of the list (which shouldn't |
| 489 | * actually happen) we need to hold the spinlock. But under the spinlock we |
| 490 | * can't actually do much, so we defer processing to the todo list. Then run |
| 491 | * the todo list to be sure the operation and possibly previously pending |
| 492 | * operations are completed. |
| 493 | */ |
| 494 | static void ieee80211_todo_for_each_key(struct ieee80211_sub_if_data *sdata, |
| 495 | u32 todo_flags) |
| 496 | { |
| 497 | struct ieee80211_key *key; |
| 498 | unsigned long flags; |
| 499 | |
| 500 | might_sleep(); |
| 501 | |
Johannes Berg | b16bd15 | 2008-04-11 21:40:35 +0200 | [diff] [blame] | 502 | spin_lock_irqsave(&sdata->local->key_lock, flags); |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 503 | list_for_each_entry(key, &sdata->key_list, list) |
| 504 | add_todo(key, todo_flags); |
Johannes Berg | b16bd15 | 2008-04-11 21:40:35 +0200 | [diff] [blame] | 505 | spin_unlock_irqrestore(&sdata->local->key_lock, flags); |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 506 | |
| 507 | ieee80211_key_todo(); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata) |
| 511 | { |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 512 | ASSERT_RTNL(); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 513 | |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 514 | if (WARN_ON(!ieee80211_sdata_running(sdata))) |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 515 | return; |
| 516 | |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 517 | ieee80211_todo_for_each_key(sdata, KEY_FLAG_TODO_HWACCEL_ADD); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | void ieee80211_disable_keys(struct ieee80211_sub_if_data *sdata) |
| 521 | { |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 522 | ASSERT_RTNL(); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 523 | |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 524 | ieee80211_todo_for_each_key(sdata, KEY_FLAG_TODO_HWACCEL_REMOVE); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 525 | } |
| 526 | |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 527 | static void __ieee80211_key_destroy(struct ieee80211_key *key) |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 528 | { |
| 529 | if (!key) |
| 530 | return; |
| 531 | |
| 532 | ieee80211_key_disable_hw_accel(key); |
| 533 | |
Johannes Berg | 8f37171 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 534 | if (key->conf.alg == ALG_CCMP) |
| 535 | ieee80211_aes_key_free(key->u.ccmp.tfm); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 536 | if (key->conf.alg == ALG_AES_CMAC) |
| 537 | ieee80211_aes_cmac_key_free(key->u.aes_cmac.tfm); |
Johannes Berg | 8f37171 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 538 | ieee80211_debugfs_key_remove(key); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 539 | |
Johannes Berg | 8f37171 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 540 | kfree(key); |
Johannes Berg | 1f5a7e4 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 541 | } |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 542 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 543 | static void __ieee80211_key_todo(void) |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 544 | { |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 545 | struct ieee80211_key *key; |
| 546 | bool work_done; |
| 547 | u32 todoflags; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 548 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 549 | /* |
| 550 | * NB: sta_info_destroy relies on this! |
| 551 | */ |
| 552 | synchronize_rcu(); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 553 | |
Johannes Berg | 523d2f6 | 2009-07-01 21:26:43 +0200 | [diff] [blame] | 554 | spin_lock_bh(&todo_lock); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 555 | while (!list_empty(&todo_list)) { |
| 556 | key = list_first_entry(&todo_list, struct ieee80211_key, todo); |
| 557 | list_del_init(&key->todo); |
| 558 | todoflags = key->flags & (KEY_FLAG_TODO_ADD_DEBUGFS | |
| 559 | KEY_FLAG_TODO_DEFKEY | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 560 | KEY_FLAG_TODO_DEFMGMTKEY | |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 561 | KEY_FLAG_TODO_HWACCEL_ADD | |
| 562 | KEY_FLAG_TODO_HWACCEL_REMOVE | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 563 | KEY_FLAG_TODO_DELETE); |
| 564 | key->flags &= ~todoflags; |
Johannes Berg | 523d2f6 | 2009-07-01 21:26:43 +0200 | [diff] [blame] | 565 | spin_unlock_bh(&todo_lock); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 566 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 567 | work_done = false; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 568 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 569 | if (todoflags & KEY_FLAG_TODO_ADD_DEBUGFS) { |
| 570 | ieee80211_debugfs_key_add(key); |
| 571 | work_done = true; |
| 572 | } |
| 573 | if (todoflags & KEY_FLAG_TODO_DEFKEY) { |
| 574 | ieee80211_debugfs_key_remove_default(key->sdata); |
| 575 | ieee80211_debugfs_key_add_default(key->sdata); |
| 576 | work_done = true; |
| 577 | } |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 578 | if (todoflags & KEY_FLAG_TODO_DEFMGMTKEY) { |
| 579 | ieee80211_debugfs_key_remove_mgmt_default(key->sdata); |
| 580 | ieee80211_debugfs_key_add_mgmt_default(key->sdata); |
| 581 | work_done = true; |
| 582 | } |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 583 | if (todoflags & KEY_FLAG_TODO_HWACCEL_ADD) { |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 584 | ieee80211_key_enable_hw_accel(key); |
| 585 | work_done = true; |
| 586 | } |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 587 | if (todoflags & KEY_FLAG_TODO_HWACCEL_REMOVE) { |
| 588 | ieee80211_key_disable_hw_accel(key); |
| 589 | work_done = true; |
| 590 | } |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 591 | if (todoflags & KEY_FLAG_TODO_DELETE) { |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 592 | __ieee80211_key_destroy(key); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 593 | work_done = true; |
| 594 | } |
| 595 | |
| 596 | WARN_ON(!work_done); |
| 597 | |
Johannes Berg | 523d2f6 | 2009-07-01 21:26:43 +0200 | [diff] [blame] | 598 | spin_lock_bh(&todo_lock); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 599 | } |
Johannes Berg | 523d2f6 | 2009-07-01 21:26:43 +0200 | [diff] [blame] | 600 | spin_unlock_bh(&todo_lock); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | void ieee80211_key_todo(void) |
| 604 | { |
| 605 | ieee80211_key_lock(); |
| 606 | __ieee80211_key_todo(); |
| 607 | ieee80211_key_unlock(); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata) |
| 611 | { |
| 612 | struct ieee80211_key *key, *tmp; |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 613 | unsigned long flags; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 614 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 615 | ieee80211_key_lock(); |
| 616 | |
| 617 | ieee80211_debugfs_key_remove_default(sdata); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 618 | ieee80211_debugfs_key_remove_mgmt_default(sdata); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 619 | |
Johannes Berg | b16bd15 | 2008-04-11 21:40:35 +0200 | [diff] [blame] | 620 | spin_lock_irqsave(&sdata->local->key_lock, flags); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 621 | list_for_each_entry_safe(key, tmp, &sdata->key_list, list) |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 622 | __ieee80211_key_free(key); |
Johannes Berg | b16bd15 | 2008-04-11 21:40:35 +0200 | [diff] [blame] | 623 | spin_unlock_irqrestore(&sdata->local->key_lock, flags); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 624 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 625 | __ieee80211_key_todo(); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 626 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 627 | ieee80211_key_unlock(); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 628 | } |