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 | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 5 | * Copyright 2007 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> |
Johannes Berg | 1f5a7e4 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 17 | #include <net/mac80211.h> |
| 18 | #include "ieee80211_i.h" |
| 19 | #include "debugfs_key.h" |
| 20 | #include "aes_ccm.h" |
| 21 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 22 | |
Johannes Berg | dbbea67 | 2008-02-26 14:34:06 +0100 | [diff] [blame] | 23 | /** |
| 24 | * DOC: Key handling basics |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 25 | * |
| 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 | * |
| 36 | * All operations here are called under RTNL so no extra locking is |
| 37 | * required. |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 38 | * |
| 39 | * NOTE: This code requires that sta info *destruction* is done under |
| 40 | * RTNL, otherwise it can try to access already freed STA structs |
| 41 | * when a STA key is being freed. |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 42 | */ |
| 43 | |
| 44 | static const u8 bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; |
| 45 | static const u8 zero_addr[ETH_ALEN]; |
| 46 | |
| 47 | static const u8 *get_mac_for_key(struct ieee80211_key *key) |
| 48 | { |
| 49 | const u8 *addr = bcast_addr; |
| 50 | |
| 51 | /* |
| 52 | * If we're an AP we won't ever receive frames with a non-WEP |
| 53 | * group key so we tell the driver that by using the zero MAC |
| 54 | * address to indicate a transmit-only key. |
| 55 | */ |
| 56 | if (key->conf.alg != ALG_WEP && |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 57 | (key->sdata->vif.type == IEEE80211_IF_TYPE_AP || |
| 58 | key->sdata->vif.type == IEEE80211_IF_TYPE_VLAN)) |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 59 | addr = zero_addr; |
| 60 | |
| 61 | if (key->sta) |
| 62 | addr = key->sta->addr; |
| 63 | |
| 64 | return addr; |
| 65 | } |
| 66 | |
| 67 | static void ieee80211_key_enable_hw_accel(struct ieee80211_key *key) |
| 68 | { |
| 69 | const u8 *addr; |
| 70 | int ret; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 71 | DECLARE_MAC_BUF(mac); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 72 | |
| 73 | if (!key->local->ops->set_key) |
| 74 | return; |
| 75 | |
Johannes Berg | dc6676b | 2008-03-31 19:23:03 +0200 | [diff] [blame] | 76 | /* |
| 77 | * This makes sure that all pending flushes have |
| 78 | * actually completed prior to uploading new key |
| 79 | * material to the hardware. That is necessary to |
| 80 | * avoid races between flushing STAs and adding |
| 81 | * new keys for them. |
| 82 | */ |
| 83 | __ieee80211_run_pending_flush(key->local); |
| 84 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 85 | addr = get_mac_for_key(key); |
| 86 | |
| 87 | ret = key->local->ops->set_key(local_to_hw(key->local), SET_KEY, |
| 88 | key->sdata->dev->dev_addr, addr, |
| 89 | &key->conf); |
| 90 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 91 | if (!ret) |
| 92 | key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE; |
| 93 | |
| 94 | if (ret && ret != -ENOSPC && ret != -EOPNOTSUPP) |
| 95 | printk(KERN_ERR "mac80211-%s: failed to set key " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 96 | "(%d, %s) to hardware (%d)\n", |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 97 | wiphy_name(key->local->hw.wiphy), |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 98 | key->conf.keyidx, print_mac(mac, addr), ret); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 99 | } |
| 100 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 101 | static void ieee80211_key_mark_hw_accel_off(struct ieee80211_key *key) |
| 102 | { |
| 103 | if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { |
| 104 | key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE; |
| 105 | key->flags |= KEY_FLAG_REMOVE_FROM_HARDWARE; |
| 106 | } |
| 107 | } |
| 108 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 109 | static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key) |
| 110 | { |
| 111 | const u8 *addr; |
| 112 | int ret; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 113 | DECLARE_MAC_BUF(mac); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 114 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 115 | if (!key || !key->local->ops->set_key) |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 116 | return; |
| 117 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 118 | if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) && |
| 119 | !(key->flags & KEY_FLAG_REMOVE_FROM_HARDWARE)) |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 120 | return; |
| 121 | |
| 122 | addr = get_mac_for_key(key); |
| 123 | |
| 124 | ret = key->local->ops->set_key(local_to_hw(key->local), DISABLE_KEY, |
| 125 | key->sdata->dev->dev_addr, addr, |
| 126 | &key->conf); |
| 127 | |
| 128 | if (ret) |
| 129 | printk(KERN_ERR "mac80211-%s: failed to remove key " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 130 | "(%d, %s) from hardware (%d)\n", |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 131 | wiphy_name(key->local->hw.wiphy), |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 132 | key->conf.keyidx, print_mac(mac, addr), ret); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 133 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 134 | key->flags &= ~(KEY_FLAG_UPLOADED_TO_HARDWARE | |
| 135 | KEY_FLAG_REMOVE_FROM_HARDWARE); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 136 | } |
| 137 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 138 | struct ieee80211_key *ieee80211_key_alloc(enum ieee80211_key_alg alg, |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 139 | int idx, |
| 140 | size_t key_len, |
| 141 | const u8 *key_data) |
Johannes Berg | 1f5a7e4 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 142 | { |
| 143 | struct ieee80211_key *key; |
| 144 | |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 145 | BUG_ON(idx < 0 || idx >= NUM_DEFAULT_KEYS); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 146 | |
| 147 | key = kzalloc(sizeof(struct ieee80211_key) + key_len, GFP_KERNEL); |
Johannes Berg | 1f5a7e4 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 148 | if (!key) |
| 149 | return NULL; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 150 | |
| 151 | /* |
| 152 | * Default to software encryption; we'll later upload the |
| 153 | * key to the hardware if possible. |
| 154 | */ |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 155 | key->conf.flags = 0; |
| 156 | key->flags = 0; |
| 157 | |
| 158 | key->conf.alg = alg; |
| 159 | key->conf.keyidx = idx; |
| 160 | key->conf.keylen = key_len; |
| 161 | memcpy(key->conf.key, key_data, key_len); |
Johannes Berg | e4861829 | 2008-02-27 13:39:00 +0100 | [diff] [blame] | 162 | INIT_LIST_HEAD(&key->list); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 163 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 164 | if (alg == ALG_CCMP) { |
| 165 | /* |
| 166 | * Initialize AES key state here as an optimization so that |
| 167 | * it does not need to be initialized for every packet. |
| 168 | */ |
| 169 | key->u.ccmp.tfm = ieee80211_aes_key_setup_encrypt(key_data); |
| 170 | if (!key->u.ccmp.tfm) { |
| 171 | ieee80211_key_free(key); |
| 172 | return NULL; |
| 173 | } |
| 174 | } |
| 175 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 176 | return key; |
| 177 | } |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 178 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 179 | static void __ieee80211_key_replace(struct ieee80211_sub_if_data *sdata, |
| 180 | struct sta_info *sta, |
| 181 | struct ieee80211_key *key, |
| 182 | struct ieee80211_key *new) |
| 183 | { |
| 184 | int idx, defkey; |
| 185 | |
Johannes Berg | 96c4654 | 2008-03-01 19:32:18 +0100 | [diff] [blame] | 186 | if (new) |
| 187 | list_add(&new->list, &sdata->key_list); |
| 188 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 189 | if (sta) { |
| 190 | rcu_assign_pointer(sta->key, new); |
| 191 | } else { |
| 192 | WARN_ON(new && key && new->conf.keyidx != key->conf.keyidx); |
| 193 | |
| 194 | if (key) |
| 195 | idx = key->conf.keyidx; |
| 196 | else |
| 197 | idx = new->conf.keyidx; |
| 198 | |
| 199 | defkey = key && sdata->default_key == key; |
| 200 | |
| 201 | if (defkey && !new) |
| 202 | ieee80211_set_default_key(sdata, -1); |
| 203 | |
| 204 | rcu_assign_pointer(sdata->keys[idx], new); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 205 | if (defkey && new) |
| 206 | ieee80211_set_default_key(sdata, new->conf.keyidx); |
| 207 | } |
| 208 | |
| 209 | if (key) { |
| 210 | ieee80211_key_mark_hw_accel_off(key); |
Johannes Berg | e4861829 | 2008-02-27 13:39:00 +0100 | [diff] [blame] | 211 | /* |
| 212 | * We'll use an empty list to indicate that the key |
| 213 | * has already been removed. |
| 214 | */ |
| 215 | list_del_init(&key->list); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
| 219 | void ieee80211_key_link(struct ieee80211_key *key, |
| 220 | struct ieee80211_sub_if_data *sdata, |
| 221 | struct sta_info *sta) |
| 222 | { |
| 223 | struct ieee80211_key *old_key; |
| 224 | int idx; |
| 225 | |
| 226 | ASSERT_RTNL(); |
| 227 | might_sleep(); |
| 228 | |
| 229 | BUG_ON(!sdata); |
| 230 | BUG_ON(!key); |
| 231 | |
| 232 | idx = key->conf.keyidx; |
| 233 | key->local = sdata->local; |
| 234 | key->sdata = sdata; |
| 235 | key->sta = sta; |
| 236 | |
| 237 | ieee80211_debugfs_key_add(key->local, key); |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 238 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 239 | if (sta) { |
| 240 | ieee80211_debugfs_key_sta_link(key, sta); |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 241 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 242 | /* |
| 243 | * some hardware cannot handle TKIP with QoS, so |
| 244 | * we indicate whether QoS could be in use. |
| 245 | */ |
| 246 | if (sta->flags & WLAN_STA_WME) |
| 247 | key->conf.flags |= IEEE80211_KEY_FLAG_WMM_STA; |
| 248 | } else { |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 249 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 250 | struct sta_info *ap; |
| 251 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 252 | rcu_read_lock(); |
| 253 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 254 | /* same here, the AP could be using QoS */ |
| 255 | ap = sta_info_get(key->local, key->sdata->u.sta.bssid); |
| 256 | if (ap) { |
| 257 | if (ap->flags & WLAN_STA_WME) |
| 258 | key->conf.flags |= |
| 259 | IEEE80211_KEY_FLAG_WMM_STA; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 260 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 261 | |
| 262 | rcu_read_unlock(); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 263 | } |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 264 | } |
| 265 | |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 266 | if (sta) |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 267 | old_key = sta->key; |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 268 | else |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 269 | old_key = sdata->keys[idx]; |
| 270 | |
| 271 | __ieee80211_key_replace(sdata, sta, old_key, key); |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 272 | |
Johannes Berg | e4861829 | 2008-02-27 13:39:00 +0100 | [diff] [blame] | 273 | if (old_key) { |
| 274 | synchronize_rcu(); |
| 275 | ieee80211_key_free(old_key); |
| 276 | } |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 277 | |
Johannes Berg | e4861829 | 2008-02-27 13:39:00 +0100 | [diff] [blame] | 278 | if (netif_running(sdata->dev)) |
| 279 | ieee80211_key_enable_hw_accel(key); |
Johannes Berg | 1f5a7e4 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 280 | } |
| 281 | |
Johannes Berg | 1f5a7e4 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 282 | void ieee80211_key_free(struct ieee80211_key *key) |
| 283 | { |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 284 | ASSERT_RTNL(); |
| 285 | might_sleep(); |
| 286 | |
Johannes Berg | 8f37171 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 287 | if (!key) |
| 288 | return; |
| 289 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 290 | if (key->sdata) { |
| 291 | /* |
| 292 | * Replace key with nothingness. |
| 293 | * |
| 294 | * Because other code may have key reference (RCU protected) |
| 295 | * right now, we then wait for a grace period before freeing |
| 296 | * it. |
Johannes Berg | e4861829 | 2008-02-27 13:39:00 +0100 | [diff] [blame] | 297 | * An empty list indicates it was never added to the key list |
| 298 | * or has been removed already. It may, however, still be in |
| 299 | * hardware for acceleration. |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 300 | */ |
Johannes Berg | e4861829 | 2008-02-27 13:39:00 +0100 | [diff] [blame] | 301 | if (!list_empty(&key->list)) |
| 302 | __ieee80211_key_replace(key->sdata, key->sta, |
| 303 | key, NULL); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 304 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 305 | /* |
| 306 | * Do NOT remove this without looking at sta_info_destroy() |
| 307 | */ |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 308 | synchronize_rcu(); |
| 309 | |
| 310 | /* |
| 311 | * Remove from hwaccel if appropriate, this will |
| 312 | * only happen when the key is actually unlinked, |
| 313 | * it will already be done when the key was replaced. |
| 314 | */ |
| 315 | ieee80211_key_disable_hw_accel(key); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 316 | } |
| 317 | |
Johannes Berg | 8f37171 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 318 | if (key->conf.alg == ALG_CCMP) |
| 319 | ieee80211_aes_key_free(key->u.ccmp.tfm); |
| 320 | ieee80211_debugfs_key_remove(key); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 321 | |
Johannes Berg | 8f37171 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 322 | kfree(key); |
Johannes Berg | 1f5a7e4 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 323 | } |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 324 | |
| 325 | void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx) |
| 326 | { |
| 327 | struct ieee80211_key *key = NULL; |
| 328 | |
| 329 | if (idx >= 0 && idx < NUM_DEFAULT_KEYS) |
| 330 | key = sdata->keys[idx]; |
| 331 | |
| 332 | if (sdata->default_key != key) { |
| 333 | ieee80211_debugfs_key_remove_default(sdata); |
| 334 | |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 335 | rcu_assign_pointer(sdata->default_key, key); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 336 | |
| 337 | if (sdata->default_key) |
| 338 | ieee80211_debugfs_key_add_default(sdata); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | |
| 342 | void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata) |
| 343 | { |
| 344 | struct ieee80211_key *key, *tmp; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 345 | LIST_HEAD(tmp_list); |
| 346 | |
| 347 | ASSERT_RTNL(); |
| 348 | might_sleep(); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 349 | |
| 350 | list_for_each_entry_safe(key, tmp, &sdata->key_list, list) |
| 351 | ieee80211_key_free(key); |
| 352 | } |
| 353 | |
| 354 | void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata) |
| 355 | { |
| 356 | struct ieee80211_key *key; |
| 357 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 358 | ASSERT_RTNL(); |
| 359 | might_sleep(); |
| 360 | |
| 361 | if (WARN_ON(!netif_running(sdata->dev))) |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 362 | return; |
| 363 | |
| 364 | list_for_each_entry(key, &sdata->key_list, list) |
| 365 | ieee80211_key_enable_hw_accel(key); |
| 366 | } |
| 367 | |
| 368 | void ieee80211_disable_keys(struct ieee80211_sub_if_data *sdata) |
| 369 | { |
| 370 | struct ieee80211_key *key; |
| 371 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 372 | ASSERT_RTNL(); |
| 373 | might_sleep(); |
| 374 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 375 | list_for_each_entry(key, &sdata->key_list, list) |
| 376 | ieee80211_key_disable_hw_accel(key); |
| 377 | } |