Johannes Berg | 1f5a7e47 | 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 | d98ad83 | 2014-09-03 15:24:57 +0300 | [diff] [blame] | 6 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
Johannes Berg | 1f5a7e47 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 13 | #include <linux/if_ether.h> |
| 14 | #include <linux/etherdevice.h> |
| 15 | #include <linux/list.h> |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 16 | #include <linux/rcupdate.h> |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 17 | #include <linux/rtnetlink.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 19 | #include <linux/export.h> |
Johannes Berg | 1f5a7e47 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 20 | #include <net/mac80211.h> |
Johannes Berg | d26ad37 | 2012-02-20 11:38:41 +0100 | [diff] [blame] | 21 | #include <asm/unaligned.h> |
Johannes Berg | 1f5a7e47 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 22 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 23 | #include "driver-ops.h" |
Johannes Berg | 1f5a7e47 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 24 | #include "debugfs_key.h" |
| 25 | #include "aes_ccm.h" |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 26 | #include "aes_cmac.h" |
Johannes Berg | 1f5a7e47 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 27 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 28 | |
Johannes Berg | dbbea67 | 2008-02-26 14:34:06 +0100 | [diff] [blame] | 29 | /** |
| 30 | * DOC: Key handling basics |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 31 | * |
| 32 | * Key handling in mac80211 is done based on per-interface (sub_if_data) |
| 33 | * keys and per-station keys. Since each station belongs to an interface, |
| 34 | * each station key also belongs to that interface. |
| 35 | * |
Johannes Berg | b5c34f6 | 2011-01-03 19:51:09 +0100 | [diff] [blame] | 36 | * Hardware acceleration is done on a best-effort basis for algorithms |
| 37 | * that are implemented in software, for each key the hardware is asked |
| 38 | * to enable that key for offloading but if it cannot do that the key is |
| 39 | * simply kept for software encryption (unless it is for an algorithm |
| 40 | * that isn't implemented in software). |
| 41 | * There is currently no way of knowing whether a key is handled in SW |
| 42 | * or HW except by looking into debugfs. |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 43 | * |
Johannes Berg | b5c34f6 | 2011-01-03 19:51:09 +0100 | [diff] [blame] | 44 | * All key management is internally protected by a mutex. Within all |
| 45 | * other parts of mac80211, key references are, just as STA structure |
| 46 | * references, protected by RCU. Note, however, that some things are |
| 47 | * unprotected, namely the key->sta dereferences within the hardware |
| 48 | * acceleration functions. This means that sta_info_destroy() must |
| 49 | * remove the key which waits for an RCU grace period. |
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 | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 54 | static void assert_key_lock(struct ieee80211_local *local) |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 55 | { |
Johannes Berg | 46a5eba | 2010-09-15 13:28:15 +0200 | [diff] [blame] | 56 | lockdep_assert_held(&local->key_mtx); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 57 | } |
| 58 | |
Yogesh Ashok Powar | 3bff186 | 2011-06-28 18:41:37 +0530 | [diff] [blame] | 59 | static void increment_tailroom_need_count(struct ieee80211_sub_if_data *sdata) |
| 60 | { |
| 61 | /* |
| 62 | * When this count is zero, SKB resizing for allocating tailroom |
| 63 | * for IV or MMIC is skipped. But, this check has created two race |
| 64 | * cases in xmit path while transiting from zero count to one: |
| 65 | * |
| 66 | * 1. SKB resize was skipped because no key was added but just before |
| 67 | * the xmit key is added and SW encryption kicks off. |
| 68 | * |
| 69 | * 2. SKB resize was skipped because all the keys were hw planted but |
| 70 | * just before xmit one of the key is deleted and SW encryption kicks |
| 71 | * off. |
| 72 | * |
| 73 | * In both the above case SW encryption will find not enough space for |
| 74 | * tailroom and exits with WARN_ON. (See WARN_ONs at wpa.c) |
| 75 | * |
| 76 | * Solution has been explained at |
| 77 | * http://mid.gmane.org/1308590980.4322.19.camel@jlt3.sipsolutions.net |
| 78 | */ |
| 79 | |
| 80 | if (!sdata->crypto_tx_tailroom_needed_cnt++) { |
| 81 | /* |
| 82 | * Flush all XMIT packets currently using HW encryption or no |
| 83 | * encryption at all if the count transition is from 0 -> 1. |
| 84 | */ |
| 85 | synchronize_net(); |
| 86 | } |
| 87 | } |
| 88 | |
Johannes Berg | 3ffc2a9 | 2010-08-27 14:26:52 +0300 | [diff] [blame] | 89 | static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key) |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 90 | { |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 91 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 89c91ca | 2012-01-20 13:55:19 +0100 | [diff] [blame] | 92 | struct sta_info *sta; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 93 | int ret; |
| 94 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 95 | might_sleep(); |
| 96 | |
Johannes Berg | 27b3eb9 | 2013-08-07 20:11:55 +0200 | [diff] [blame] | 97 | if (key->flags & KEY_FLAG_TAINTED) |
| 98 | return -EINVAL; |
| 99 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 100 | if (!key->local->ops->set_key) |
Johannes Berg | 3ffc2a9 | 2010-08-27 14:26:52 +0300 | [diff] [blame] | 101 | goto out_unsupported; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 102 | |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 103 | assert_key_lock(key->local); |
| 104 | |
Johannes Berg | 89c91ca | 2012-01-20 13:55:19 +0100 | [diff] [blame] | 105 | sta = key->sta; |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 106 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 107 | /* |
| 108 | * If this is a per-STA GTK, check if it |
| 109 | * is supported; if not, return. |
| 110 | */ |
| 111 | if (sta && !(key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE) && |
| 112 | !(key->local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK)) |
| 113 | goto out_unsupported; |
| 114 | |
Johannes Berg | 89c91ca | 2012-01-20 13:55:19 +0100 | [diff] [blame] | 115 | if (sta && !sta->uploaded) |
| 116 | goto out_unsupported; |
| 117 | |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 118 | sdata = key->sdata; |
Helmut Schaa | 18890d4 | 2010-11-19 08:11:01 +0100 | [diff] [blame] | 119 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) { |
| 120 | /* |
| 121 | * The driver doesn't know anything about VLAN interfaces. |
| 122 | * Hence, don't send GTKs for VLAN interfaces to the driver. |
| 123 | */ |
| 124 | if (!(key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE)) |
| 125 | goto out_unsupported; |
Helmut Schaa | 18890d4 | 2010-11-19 08:11:01 +0100 | [diff] [blame] | 126 | } |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 127 | |
Johannes Berg | 89c91ca | 2012-01-20 13:55:19 +0100 | [diff] [blame] | 128 | ret = drv_set_key(key->local, SET_KEY, sdata, |
| 129 | sta ? &sta->sta : NULL, &key->conf); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 130 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 131 | if (!ret) { |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 132 | key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE; |
Yogesh Ashok Powar | 3bff186 | 2011-06-28 18:41:37 +0530 | [diff] [blame] | 133 | |
Ido Yariv | ca34e3b | 2014-07-29 15:38:53 +0300 | [diff] [blame] | 134 | if (!(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC)) |
Yogesh Ashok Powar | 3bff186 | 2011-06-28 18:41:37 +0530 | [diff] [blame] | 135 | sdata->crypto_tx_tailroom_needed_cnt--; |
| 136 | |
Arik Nemtsov | 077a915 | 2011-10-23 08:21:41 +0200 | [diff] [blame] | 137 | WARN_ON((key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) && |
| 138 | (key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)); |
| 139 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 140 | return 0; |
| 141 | } |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 142 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 143 | if (ret != -ENOSPC && ret != -EOPNOTSUPP) |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 144 | sdata_err(sdata, |
Joe Perches | 0fb9a9e | 2010-08-20 16:25:38 -0700 | [diff] [blame] | 145 | "failed to set key (%d, %pM) to hardware (%d)\n", |
Johannes Berg | 89c91ca | 2012-01-20 13:55:19 +0100 | [diff] [blame] | 146 | key->conf.keyidx, |
| 147 | sta ? sta->sta.addr : bcast_addr, ret); |
Johannes Berg | 3ffc2a9 | 2010-08-27 14:26:52 +0300 | [diff] [blame] | 148 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 149 | out_unsupported: |
| 150 | switch (key->conf.cipher) { |
| 151 | case WLAN_CIPHER_SUITE_WEP40: |
| 152 | case WLAN_CIPHER_SUITE_WEP104: |
| 153 | case WLAN_CIPHER_SUITE_TKIP: |
| 154 | case WLAN_CIPHER_SUITE_CCMP: |
| 155 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 156 | /* all of these we can do in software */ |
| 157 | return 0; |
| 158 | default: |
| 159 | return -EINVAL; |
Johannes Berg | 3ffc2a9 | 2010-08-27 14:26:52 +0300 | [diff] [blame] | 160 | } |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key) |
| 164 | { |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 165 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 89c91ca | 2012-01-20 13:55:19 +0100 | [diff] [blame] | 166 | struct sta_info *sta; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 167 | int ret; |
| 168 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 169 | might_sleep(); |
| 170 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 171 | if (!key || !key->local->ops->set_key) |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 172 | return; |
| 173 | |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 174 | assert_key_lock(key->local); |
| 175 | |
| 176 | if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 177 | return; |
| 178 | |
Johannes Berg | 89c91ca | 2012-01-20 13:55:19 +0100 | [diff] [blame] | 179 | sta = key->sta; |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 180 | sdata = key->sdata; |
| 181 | |
Ido Yariv | ca34e3b | 2014-07-29 15:38:53 +0300 | [diff] [blame] | 182 | if (!(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC)) |
Yogesh Ashok Powar | 3bff186 | 2011-06-28 18:41:37 +0530 | [diff] [blame] | 183 | increment_tailroom_need_count(sdata); |
| 184 | |
Johannes Berg | 12375ef | 2009-11-25 20:30:31 +0100 | [diff] [blame] | 185 | ret = drv_set_key(key->local, DISABLE_KEY, sdata, |
Johannes Berg | 89c91ca | 2012-01-20 13:55:19 +0100 | [diff] [blame] | 186 | sta ? &sta->sta : NULL, &key->conf); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 187 | |
| 188 | if (ret) |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 189 | sdata_err(sdata, |
Joe Perches | 0fb9a9e | 2010-08-20 16:25:38 -0700 | [diff] [blame] | 190 | "failed to remove key (%d, %pM) from hardware (%d)\n", |
Johannes Berg | 89c91ca | 2012-01-20 13:55:19 +0100 | [diff] [blame] | 191 | key->conf.keyidx, |
| 192 | sta ? sta->sta.addr : bcast_addr, ret); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 193 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 194 | key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE; |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | static void __ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 198 | int idx, bool uni, bool multi) |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 199 | { |
| 200 | struct ieee80211_key *key = NULL; |
| 201 | |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 202 | assert_key_lock(sdata->local); |
| 203 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 204 | if (idx >= 0 && idx < NUM_DEFAULT_KEYS) |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 205 | key = key_mtx_dereference(sdata->local, sdata->keys[idx]); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 206 | |
Yoni Divinsky | de5fad8 | 2012-05-30 11:36:39 +0300 | [diff] [blame] | 207 | if (uni) { |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 208 | rcu_assign_pointer(sdata->default_unicast_key, key); |
Yoni Divinsky | de5fad8 | 2012-05-30 11:36:39 +0300 | [diff] [blame] | 209 | drv_set_default_unicast_key(sdata->local, sdata, idx); |
| 210 | } |
| 211 | |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 212 | if (multi) |
| 213 | rcu_assign_pointer(sdata->default_multicast_key, key); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 214 | |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 215 | ieee80211_debugfs_key_update_default(sdata); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 216 | } |
| 217 | |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 218 | void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx, |
| 219 | bool uni, bool multi) |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 220 | { |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 221 | mutex_lock(&sdata->local->key_mtx); |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 222 | __ieee80211_set_default_key(sdata, idx, uni, multi); |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 223 | mutex_unlock(&sdata->local->key_mtx); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 224 | } |
| 225 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 226 | static void |
| 227 | __ieee80211_set_default_mgmt_key(struct ieee80211_sub_if_data *sdata, int idx) |
| 228 | { |
| 229 | struct ieee80211_key *key = NULL; |
| 230 | |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 231 | assert_key_lock(sdata->local); |
| 232 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 233 | if (idx >= NUM_DEFAULT_KEYS && |
| 234 | idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 235 | key = key_mtx_dereference(sdata->local, sdata->keys[idx]); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 236 | |
| 237 | rcu_assign_pointer(sdata->default_mgmt_key, key); |
| 238 | |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 239 | ieee80211_debugfs_key_update_default(sdata); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | void ieee80211_set_default_mgmt_key(struct ieee80211_sub_if_data *sdata, |
| 243 | int idx) |
| 244 | { |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 245 | mutex_lock(&sdata->local->key_mtx); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 246 | __ieee80211_set_default_mgmt_key(sdata, idx); |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 247 | mutex_unlock(&sdata->local->key_mtx); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 248 | } |
| 249 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 250 | |
Johannes Berg | 3b8d9c2 | 2013-03-06 22:58:23 +0100 | [diff] [blame] | 251 | static void ieee80211_key_replace(struct ieee80211_sub_if_data *sdata, |
| 252 | struct sta_info *sta, |
| 253 | bool pairwise, |
| 254 | struct ieee80211_key *old, |
| 255 | struct ieee80211_key *new) |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 256 | { |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 257 | int idx; |
| 258 | bool defunikey, defmultikey, defmgmtkey; |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 259 | |
Johannes Berg | 5282c3b | 2013-10-29 10:00:08 +0100 | [diff] [blame] | 260 | /* caller must provide at least one old/new */ |
| 261 | if (WARN_ON(!new && !old)) |
| 262 | return; |
| 263 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 264 | if (new) |
Johannes Berg | f850e00 | 2011-07-13 19:50:53 +0200 | [diff] [blame] | 265 | list_add_tail(&new->list, &sdata->key_list); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 266 | |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 267 | WARN_ON(new && old && new->conf.keyidx != old->conf.keyidx); |
| 268 | |
| 269 | if (old) |
| 270 | idx = old->conf.keyidx; |
| 271 | else |
| 272 | idx = new->conf.keyidx; |
| 273 | |
| 274 | if (sta) { |
| 275 | if (pairwise) { |
| 276 | rcu_assign_pointer(sta->ptk[idx], new); |
| 277 | sta->ptk_idx = idx; |
| 278 | } else { |
| 279 | rcu_assign_pointer(sta->gtk[idx], new); |
| 280 | sta->gtk_idx = idx; |
| 281 | } |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 282 | } else { |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 283 | defunikey = old && |
| 284 | old == key_mtx_dereference(sdata->local, |
| 285 | sdata->default_unicast_key); |
| 286 | defmultikey = old && |
| 287 | old == key_mtx_dereference(sdata->local, |
| 288 | sdata->default_multicast_key); |
| 289 | defmgmtkey = old && |
| 290 | old == key_mtx_dereference(sdata->local, |
| 291 | sdata->default_mgmt_key); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 292 | |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 293 | if (defunikey && !new) |
| 294 | __ieee80211_set_default_key(sdata, -1, true, false); |
| 295 | if (defmultikey && !new) |
| 296 | __ieee80211_set_default_key(sdata, -1, false, true); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 297 | if (defmgmtkey && !new) |
| 298 | __ieee80211_set_default_mgmt_key(sdata, -1); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 299 | |
| 300 | rcu_assign_pointer(sdata->keys[idx], new); |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 301 | if (defunikey && new) |
| 302 | __ieee80211_set_default_key(sdata, new->conf.keyidx, |
| 303 | true, false); |
| 304 | if (defmultikey && new) |
| 305 | __ieee80211_set_default_key(sdata, new->conf.keyidx, |
| 306 | false, true); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 307 | if (defmgmtkey && new) |
| 308 | __ieee80211_set_default_mgmt_key(sdata, |
| 309 | new->conf.keyidx); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 310 | } |
| 311 | |
Johannes Berg | b5c34f6 | 2011-01-03 19:51:09 +0100 | [diff] [blame] | 312 | if (old) |
| 313 | list_del(&old->list); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 314 | } |
| 315 | |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 316 | struct ieee80211_key * |
| 317 | ieee80211_key_alloc(u32 cipher, int idx, size_t key_len, |
| 318 | const u8 *key_data, |
| 319 | size_t seq_len, const u8 *seq, |
| 320 | const struct ieee80211_cipher_scheme *cs) |
Johannes Berg | 1f5a7e47 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 321 | { |
| 322 | struct ieee80211_key *key; |
Ben Hutchings | 1ac62ba | 2010-08-01 17:37:03 +0100 | [diff] [blame] | 323 | int i, j, err; |
Johannes Berg | 1f5a7e47 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 324 | |
Johannes Berg | 8c5bb1f | 2014-04-29 17:55:26 +0200 | [diff] [blame] | 325 | if (WARN_ON(idx < 0 || idx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)) |
| 326 | return ERR_PTR(-EINVAL); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 327 | |
| 328 | key = kzalloc(sizeof(struct ieee80211_key) + key_len, GFP_KERNEL); |
Johannes Berg | 1f5a7e47 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 329 | if (!key) |
Ben Hutchings | 1ac62ba | 2010-08-01 17:37:03 +0100 | [diff] [blame] | 330 | return ERR_PTR(-ENOMEM); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 331 | |
| 332 | /* |
| 333 | * Default to software encryption; we'll later upload the |
| 334 | * key to the hardware if possible. |
| 335 | */ |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 336 | key->conf.flags = 0; |
| 337 | key->flags = 0; |
| 338 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 339 | key->conf.cipher = cipher; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 340 | key->conf.keyidx = idx; |
| 341 | key->conf.keylen = key_len; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 342 | switch (cipher) { |
| 343 | case WLAN_CIPHER_SUITE_WEP40: |
| 344 | case WLAN_CIPHER_SUITE_WEP104: |
Johannes Berg | 4325f6c | 2013-05-08 13:09:08 +0200 | [diff] [blame] | 345 | key->conf.iv_len = IEEE80211_WEP_IV_LEN; |
| 346 | key->conf.icv_len = IEEE80211_WEP_ICV_LEN; |
Felix Fietkau | 76708de | 2008-10-05 18:02:48 +0200 | [diff] [blame] | 347 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 348 | case WLAN_CIPHER_SUITE_TKIP: |
Johannes Berg | 4325f6c | 2013-05-08 13:09:08 +0200 | [diff] [blame] | 349 | key->conf.iv_len = IEEE80211_TKIP_IV_LEN; |
| 350 | key->conf.icv_len = IEEE80211_TKIP_ICV_LEN; |
Jouni Malinen | 9f26a95 | 2009-05-15 12:38:32 +0300 | [diff] [blame] | 351 | if (seq) { |
Johannes Berg | 5a306f5 | 2012-11-14 23:22:21 +0100 | [diff] [blame] | 352 | for (i = 0; i < IEEE80211_NUM_TIDS; i++) { |
Jouni Malinen | faa8fdc | 2009-05-11 21:57:58 +0300 | [diff] [blame] | 353 | key->u.tkip.rx[i].iv32 = |
| 354 | get_unaligned_le32(&seq[2]); |
| 355 | key->u.tkip.rx[i].iv16 = |
| 356 | get_unaligned_le16(seq); |
| 357 | } |
| 358 | } |
Johannes Berg | 523b02e | 2011-07-07 22:28:01 +0200 | [diff] [blame] | 359 | spin_lock_init(&key->u.tkip.txlock); |
Felix Fietkau | 76708de | 2008-10-05 18:02:48 +0200 | [diff] [blame] | 360 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 361 | case WLAN_CIPHER_SUITE_CCMP: |
Johannes Berg | 4325f6c | 2013-05-08 13:09:08 +0200 | [diff] [blame] | 362 | key->conf.iv_len = IEEE80211_CCMP_HDR_LEN; |
| 363 | key->conf.icv_len = IEEE80211_CCMP_MIC_LEN; |
Jouni Malinen | 9f26a95 | 2009-05-15 12:38:32 +0300 | [diff] [blame] | 364 | if (seq) { |
Johannes Berg | 5a306f5 | 2012-11-14 23:22:21 +0100 | [diff] [blame] | 365 | for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) |
Johannes Berg | 4325f6c | 2013-05-08 13:09:08 +0200 | [diff] [blame] | 366 | for (j = 0; j < IEEE80211_CCMP_PN_LEN; j++) |
Jouni Malinen | faa8fdc | 2009-05-11 21:57:58 +0300 | [diff] [blame] | 367 | key->u.ccmp.rx_pn[i][j] = |
Johannes Berg | 4325f6c | 2013-05-08 13:09:08 +0200 | [diff] [blame] | 368 | seq[IEEE80211_CCMP_PN_LEN - j - 1]; |
Jouni Malinen | faa8fdc | 2009-05-11 21:57:58 +0300 | [diff] [blame] | 369 | } |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 370 | /* |
| 371 | * Initialize AES key state here as an optimization so that |
| 372 | * it does not need to be initialized for every packet. |
| 373 | */ |
| 374 | key->u.ccmp.tfm = ieee80211_aes_key_setup_encrypt(key_data); |
Ben Hutchings | 1ac62ba | 2010-08-01 17:37:03 +0100 | [diff] [blame] | 375 | if (IS_ERR(key->u.ccmp.tfm)) { |
| 376 | err = PTR_ERR(key->u.ccmp.tfm); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 377 | kfree(key); |
Petr Å tetiar | 1f951a7 | 2011-03-27 13:31:26 +0200 | [diff] [blame] | 378 | return ERR_PTR(err); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 379 | } |
Johannes Berg | 60ae0f2 | 2010-08-10 09:46:39 +0200 | [diff] [blame] | 380 | break; |
| 381 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 382 | key->conf.iv_len = 0; |
| 383 | key->conf.icv_len = sizeof(struct ieee80211_mmie); |
| 384 | if (seq) |
Johannes Berg | 4325f6c | 2013-05-08 13:09:08 +0200 | [diff] [blame] | 385 | for (j = 0; j < IEEE80211_CMAC_PN_LEN; j++) |
Johannes Berg | 0f92732 | 2012-11-14 23:15:11 +0100 | [diff] [blame] | 386 | key->u.aes_cmac.rx_pn[j] = |
Johannes Berg | 4325f6c | 2013-05-08 13:09:08 +0200 | [diff] [blame] | 387 | seq[IEEE80211_CMAC_PN_LEN - j - 1]; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 388 | /* |
| 389 | * Initialize AES key state here as an optimization so that |
| 390 | * it does not need to be initialized for every packet. |
| 391 | */ |
| 392 | key->u.aes_cmac.tfm = |
| 393 | ieee80211_aes_cmac_key_setup(key_data); |
Ben Hutchings | 1ac62ba | 2010-08-01 17:37:03 +0100 | [diff] [blame] | 394 | if (IS_ERR(key->u.aes_cmac.tfm)) { |
| 395 | err = PTR_ERR(key->u.aes_cmac.tfm); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 396 | kfree(key); |
Petr Å tetiar | 1f951a7 | 2011-03-27 13:31:26 +0200 | [diff] [blame] | 397 | return ERR_PTR(err); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 398 | } |
Johannes Berg | 60ae0f2 | 2010-08-10 09:46:39 +0200 | [diff] [blame] | 399 | break; |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 400 | default: |
| 401 | if (cs) { |
| 402 | size_t len = (seq_len > MAX_PN_LEN) ? |
| 403 | MAX_PN_LEN : seq_len; |
| 404 | |
| 405 | key->conf.iv_len = cs->hdr_len; |
| 406 | key->conf.icv_len = cs->mic_len; |
| 407 | for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) |
| 408 | for (j = 0; j < len; j++) |
| 409 | key->u.gen.rx_pn[i][j] = |
| 410 | seq[len - j - 1]; |
| 411 | } |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 412 | } |
Johannes Berg | 60ae0f2 | 2010-08-10 09:46:39 +0200 | [diff] [blame] | 413 | memcpy(key->conf.key, key_data, key_len); |
| 414 | INIT_LIST_HEAD(&key->list); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 415 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 416 | return key; |
| 417 | } |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 418 | |
Johannes Berg | 79cf2df | 2013-03-06 22:53:52 +0100 | [diff] [blame] | 419 | static void ieee80211_key_free_common(struct ieee80211_key *key) |
| 420 | { |
| 421 | if (key->conf.cipher == WLAN_CIPHER_SUITE_CCMP) |
| 422 | ieee80211_aes_key_free(key->u.ccmp.tfm); |
| 423 | if (key->conf.cipher == WLAN_CIPHER_SUITE_AES_CMAC) |
| 424 | ieee80211_aes_cmac_key_free(key->u.aes_cmac.tfm); |
Johannes Berg | 29c3f9c | 2014-09-10 13:39:55 +0300 | [diff] [blame] | 425 | kzfree(key); |
Johannes Berg | 79cf2df | 2013-03-06 22:53:52 +0100 | [diff] [blame] | 426 | } |
| 427 | |
Johannes Berg | 6d10e46 | 2013-03-06 23:09:11 +0100 | [diff] [blame] | 428 | static void __ieee80211_key_destroy(struct ieee80211_key *key, |
| 429 | bool delay_tailroom) |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 430 | { |
Jouni Malinen | 32162a4 | 2010-07-26 15:52:03 -0700 | [diff] [blame] | 431 | if (key->local) |
| 432 | ieee80211_key_disable_hw_accel(key); |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 433 | |
Yogesh Ashok Powar | 3bff186 | 2011-06-28 18:41:37 +0530 | [diff] [blame] | 434 | if (key->local) { |
Johannes Berg | 8d1f7ec | 2013-02-23 00:59:03 +0100 | [diff] [blame] | 435 | struct ieee80211_sub_if_data *sdata = key->sdata; |
| 436 | |
Jouni Malinen | 32162a4 | 2010-07-26 15:52:03 -0700 | [diff] [blame] | 437 | ieee80211_debugfs_key_remove(key); |
Johannes Berg | 8d1f7ec | 2013-02-23 00:59:03 +0100 | [diff] [blame] | 438 | |
| 439 | if (delay_tailroom) { |
| 440 | /* see ieee80211_delayed_tailroom_dec */ |
| 441 | sdata->crypto_tx_tailroom_pending_dec++; |
| 442 | schedule_delayed_work(&sdata->dec_tailroom_needed_wk, |
| 443 | HZ/2); |
| 444 | } else { |
| 445 | sdata->crypto_tx_tailroom_needed_cnt--; |
| 446 | } |
Yogesh Ashok Powar | 3bff186 | 2011-06-28 18:41:37 +0530 | [diff] [blame] | 447 | } |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 448 | |
Johannes Berg | 79cf2df | 2013-03-06 22:53:52 +0100 | [diff] [blame] | 449 | ieee80211_key_free_common(key); |
| 450 | } |
| 451 | |
Johannes Berg | 6d10e46 | 2013-03-06 23:09:11 +0100 | [diff] [blame] | 452 | static void ieee80211_key_destroy(struct ieee80211_key *key, |
| 453 | bool delay_tailroom) |
| 454 | { |
| 455 | if (!key) |
| 456 | return; |
| 457 | |
| 458 | /* |
| 459 | * Synchronize so the TX path can no longer be using |
| 460 | * this key before we free/remove it. |
| 461 | */ |
| 462 | synchronize_net(); |
| 463 | |
| 464 | __ieee80211_key_destroy(key, delay_tailroom); |
| 465 | } |
| 466 | |
Johannes Berg | 79cf2df | 2013-03-06 22:53:52 +0100 | [diff] [blame] | 467 | void ieee80211_key_free_unused(struct ieee80211_key *key) |
| 468 | { |
| 469 | WARN_ON(key->sdata || key->local); |
| 470 | ieee80211_key_free_common(key); |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 471 | } |
| 472 | |
Johannes Berg | 3ffc2a9 | 2010-08-27 14:26:52 +0300 | [diff] [blame] | 473 | int ieee80211_key_link(struct ieee80211_key *key, |
| 474 | struct ieee80211_sub_if_data *sdata, |
| 475 | struct sta_info *sta) |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 476 | { |
Johannes Berg | 27b3eb9 | 2013-08-07 20:11:55 +0200 | [diff] [blame] | 477 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 478 | struct ieee80211_key *old_key; |
Johannes Berg | 3ffc2a9 | 2010-08-27 14:26:52 +0300 | [diff] [blame] | 479 | int idx, ret; |
Mariusz Kozlowski | 67aa030 | 2011-03-26 18:58:51 +0100 | [diff] [blame] | 480 | bool pairwise; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 481 | |
Mariusz Kozlowski | 67aa030 | 2011-03-26 18:58:51 +0100 | [diff] [blame] | 482 | pairwise = key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 483 | idx = key->conf.keyidx; |
| 484 | key->local = sdata->local; |
| 485 | key->sdata = sdata; |
| 486 | key->sta = sta; |
| 487 | |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 488 | mutex_lock(&sdata->local->key_mtx); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 489 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 490 | if (sta && pairwise) |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 491 | old_key = key_mtx_dereference(sdata->local, sta->ptk[idx]); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 492 | else if (sta) |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 493 | old_key = key_mtx_dereference(sdata->local, sta->gtk[idx]); |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 494 | else |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 495 | old_key = key_mtx_dereference(sdata->local, sdata->keys[idx]); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 496 | |
Yogesh Ashok Powar | 3bff186 | 2011-06-28 18:41:37 +0530 | [diff] [blame] | 497 | increment_tailroom_need_count(sdata); |
| 498 | |
Johannes Berg | 3b8d9c2 | 2013-03-06 22:58:23 +0100 | [diff] [blame] | 499 | ieee80211_key_replace(sdata, sta, pairwise, old_key, key); |
| 500 | ieee80211_key_destroy(old_key, true); |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 501 | |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 502 | ieee80211_debugfs_key_add(key); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 503 | |
Johannes Berg | 27b3eb9 | 2013-08-07 20:11:55 +0200 | [diff] [blame] | 504 | if (!local->wowlan) { |
| 505 | ret = ieee80211_key_enable_hw_accel(key); |
| 506 | if (ret) |
| 507 | ieee80211_key_free(key, true); |
| 508 | } else { |
| 509 | ret = 0; |
| 510 | } |
Johannes Berg | 79cf2df | 2013-03-06 22:53:52 +0100 | [diff] [blame] | 511 | |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 512 | mutex_unlock(&sdata->local->key_mtx); |
Johannes Berg | 3ffc2a9 | 2010-08-27 14:26:52 +0300 | [diff] [blame] | 513 | |
| 514 | return ret; |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 515 | } |
| 516 | |
Johannes Berg | 3b8d9c2 | 2013-03-06 22:58:23 +0100 | [diff] [blame] | 517 | void ieee80211_key_free(struct ieee80211_key *key, bool delay_tailroom) |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 518 | { |
Johannes Berg | 5c0c364 | 2011-05-12 14:31:49 +0200 | [diff] [blame] | 519 | if (!key) |
| 520 | return; |
| 521 | |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 522 | /* |
| 523 | * Replace key with nothingness if it was ever used. |
| 524 | */ |
| 525 | if (key->sdata) |
Johannes Berg | 3b8d9c2 | 2013-03-06 22:58:23 +0100 | [diff] [blame] | 526 | ieee80211_key_replace(key->sdata, key->sta, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 527 | key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE, |
| 528 | key, NULL); |
Johannes Berg | 3b8d9c2 | 2013-03-06 22:58:23 +0100 | [diff] [blame] | 529 | ieee80211_key_destroy(key, delay_tailroom); |
Johannes Berg | 1f5a7e47 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 530 | } |
| 531 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 532 | void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata) |
| 533 | { |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 534 | struct ieee80211_key *key; |
| 535 | |
Johannes Berg | 3a24576 | 2008-04-09 16:45:37 +0200 | [diff] [blame] | 536 | ASSERT_RTNL(); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 537 | |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 538 | if (WARN_ON(!ieee80211_sdata_running(sdata))) |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 539 | return; |
| 540 | |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 541 | mutex_lock(&sdata->local->key_mtx); |
| 542 | |
Yogesh Ashok Powar | 3bff186 | 2011-06-28 18:41:37 +0530 | [diff] [blame] | 543 | sdata->crypto_tx_tailroom_needed_cnt = 0; |
| 544 | |
| 545 | list_for_each_entry(key, &sdata->key_list, list) { |
| 546 | increment_tailroom_need_count(sdata); |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 547 | ieee80211_key_enable_hw_accel(key); |
Yogesh Ashok Powar | 3bff186 | 2011-06-28 18:41:37 +0530 | [diff] [blame] | 548 | } |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 549 | |
| 550 | mutex_unlock(&sdata->local->key_mtx); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 551 | } |
| 552 | |
Johannes Berg | 830af02 | 2011-07-05 16:35:39 +0200 | [diff] [blame] | 553 | void ieee80211_iter_keys(struct ieee80211_hw *hw, |
| 554 | struct ieee80211_vif *vif, |
| 555 | void (*iter)(struct ieee80211_hw *hw, |
| 556 | struct ieee80211_vif *vif, |
| 557 | struct ieee80211_sta *sta, |
| 558 | struct ieee80211_key_conf *key, |
| 559 | void *data), |
| 560 | void *iter_data) |
| 561 | { |
| 562 | struct ieee80211_local *local = hw_to_local(hw); |
Johannes Berg | 27b3eb9 | 2013-08-07 20:11:55 +0200 | [diff] [blame] | 563 | struct ieee80211_key *key, *tmp; |
Johannes Berg | 830af02 | 2011-07-05 16:35:39 +0200 | [diff] [blame] | 564 | struct ieee80211_sub_if_data *sdata; |
| 565 | |
| 566 | ASSERT_RTNL(); |
| 567 | |
| 568 | mutex_lock(&local->key_mtx); |
| 569 | if (vif) { |
| 570 | sdata = vif_to_sdata(vif); |
Johannes Berg | 27b3eb9 | 2013-08-07 20:11:55 +0200 | [diff] [blame] | 571 | list_for_each_entry_safe(key, tmp, &sdata->key_list, list) |
Johannes Berg | 830af02 | 2011-07-05 16:35:39 +0200 | [diff] [blame] | 572 | iter(hw, &sdata->vif, |
| 573 | key->sta ? &key->sta->sta : NULL, |
| 574 | &key->conf, iter_data); |
| 575 | } else { |
| 576 | list_for_each_entry(sdata, &local->interfaces, list) |
Johannes Berg | 27b3eb9 | 2013-08-07 20:11:55 +0200 | [diff] [blame] | 577 | list_for_each_entry_safe(key, tmp, |
| 578 | &sdata->key_list, list) |
Johannes Berg | 830af02 | 2011-07-05 16:35:39 +0200 | [diff] [blame] | 579 | iter(hw, &sdata->vif, |
| 580 | key->sta ? &key->sta->sta : NULL, |
| 581 | &key->conf, iter_data); |
| 582 | } |
| 583 | mutex_unlock(&local->key_mtx); |
| 584 | } |
| 585 | EXPORT_SYMBOL(ieee80211_iter_keys); |
| 586 | |
Johannes Berg | 7907c7d | 2013-12-04 23:47:09 +0100 | [diff] [blame] | 587 | static void ieee80211_free_keys_iface(struct ieee80211_sub_if_data *sdata, |
| 588 | struct list_head *keys) |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 589 | { |
| 590 | struct ieee80211_key *key, *tmp; |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 591 | |
Johannes Berg | 8d1f7ec | 2013-02-23 00:59:03 +0100 | [diff] [blame] | 592 | sdata->crypto_tx_tailroom_needed_cnt -= |
| 593 | sdata->crypto_tx_tailroom_pending_dec; |
| 594 | sdata->crypto_tx_tailroom_pending_dec = 0; |
| 595 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 596 | ieee80211_debugfs_key_remove_mgmt_default(sdata); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 597 | |
Johannes Berg | 6d10e46 | 2013-03-06 23:09:11 +0100 | [diff] [blame] | 598 | list_for_each_entry_safe(key, tmp, &sdata->key_list, list) { |
| 599 | ieee80211_key_replace(key->sdata, key->sta, |
| 600 | key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE, |
| 601 | key, NULL); |
Johannes Berg | 7907c7d | 2013-12-04 23:47:09 +0100 | [diff] [blame] | 602 | list_add_tail(&key->list, keys); |
Johannes Berg | 6d10e46 | 2013-03-06 23:09:11 +0100 | [diff] [blame] | 603 | } |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 604 | |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 605 | ieee80211_debugfs_key_update_default(sdata); |
Johannes Berg | 7907c7d | 2013-12-04 23:47:09 +0100 | [diff] [blame] | 606 | } |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 607 | |
Johannes Berg | 7907c7d | 2013-12-04 23:47:09 +0100 | [diff] [blame] | 608 | void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata, |
| 609 | bool force_synchronize) |
| 610 | { |
| 611 | struct ieee80211_local *local = sdata->local; |
| 612 | struct ieee80211_sub_if_data *vlan; |
| 613 | struct ieee80211_key *key, *tmp; |
| 614 | LIST_HEAD(keys); |
| 615 | |
| 616 | cancel_delayed_work_sync(&sdata->dec_tailroom_needed_wk); |
| 617 | |
| 618 | mutex_lock(&local->key_mtx); |
| 619 | |
| 620 | ieee80211_free_keys_iface(sdata, &keys); |
| 621 | |
| 622 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
| 623 | list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) |
| 624 | ieee80211_free_keys_iface(vlan, &keys); |
Johannes Berg | 6d10e46 | 2013-03-06 23:09:11 +0100 | [diff] [blame] | 625 | } |
| 626 | |
Johannes Berg | 7907c7d | 2013-12-04 23:47:09 +0100 | [diff] [blame] | 627 | if (!list_empty(&keys) || force_synchronize) |
| 628 | synchronize_net(); |
| 629 | list_for_each_entry_safe(key, tmp, &keys, list) |
| 630 | __ieee80211_key_destroy(key, false); |
| 631 | |
Johannes Berg | 8d1f7ec | 2013-02-23 00:59:03 +0100 | [diff] [blame] | 632 | WARN_ON_ONCE(sdata->crypto_tx_tailroom_needed_cnt || |
| 633 | sdata->crypto_tx_tailroom_pending_dec); |
Johannes Berg | 7907c7d | 2013-12-04 23:47:09 +0100 | [diff] [blame] | 634 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
| 635 | list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) |
| 636 | WARN_ON_ONCE(vlan->crypto_tx_tailroom_needed_cnt || |
| 637 | vlan->crypto_tx_tailroom_pending_dec); |
| 638 | } |
Johannes Berg | 8d1f7ec | 2013-02-23 00:59:03 +0100 | [diff] [blame] | 639 | |
Johannes Berg | 7907c7d | 2013-12-04 23:47:09 +0100 | [diff] [blame] | 640 | mutex_unlock(&local->key_mtx); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 641 | } |
Johannes Berg | c68f4b8 | 2011-07-05 16:35:41 +0200 | [diff] [blame] | 642 | |
Johannes Berg | 6d10e46 | 2013-03-06 23:09:11 +0100 | [diff] [blame] | 643 | void ieee80211_free_sta_keys(struct ieee80211_local *local, |
| 644 | struct sta_info *sta) |
| 645 | { |
Johannes Berg | c878207 | 2013-12-04 23:05:45 +0100 | [diff] [blame] | 646 | struct ieee80211_key *key; |
Johannes Berg | 6d10e46 | 2013-03-06 23:09:11 +0100 | [diff] [blame] | 647 | int i; |
| 648 | |
| 649 | mutex_lock(&local->key_mtx); |
| 650 | for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 651 | key = key_mtx_dereference(local, sta->gtk[i]); |
| 652 | if (!key) |
| 653 | continue; |
| 654 | ieee80211_key_replace(key->sdata, key->sta, |
| 655 | key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE, |
| 656 | key, NULL); |
Johannes Berg | c878207 | 2013-12-04 23:05:45 +0100 | [diff] [blame] | 657 | __ieee80211_key_destroy(key, true); |
Johannes Berg | 6d10e46 | 2013-03-06 23:09:11 +0100 | [diff] [blame] | 658 | } |
| 659 | |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 660 | for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 661 | key = key_mtx_dereference(local, sta->ptk[i]); |
| 662 | if (!key) |
| 663 | continue; |
Johannes Berg | 6d10e46 | 2013-03-06 23:09:11 +0100 | [diff] [blame] | 664 | ieee80211_key_replace(key->sdata, key->sta, |
| 665 | key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE, |
| 666 | key, NULL); |
Johannes Berg | 6d10e46 | 2013-03-06 23:09:11 +0100 | [diff] [blame] | 667 | __ieee80211_key_destroy(key, true); |
Johannes Berg | c878207 | 2013-12-04 23:05:45 +0100 | [diff] [blame] | 668 | } |
Johannes Berg | 6d10e46 | 2013-03-06 23:09:11 +0100 | [diff] [blame] | 669 | |
| 670 | mutex_unlock(&local->key_mtx); |
| 671 | } |
| 672 | |
Johannes Berg | 8d1f7ec | 2013-02-23 00:59:03 +0100 | [diff] [blame] | 673 | void ieee80211_delayed_tailroom_dec(struct work_struct *wk) |
| 674 | { |
| 675 | struct ieee80211_sub_if_data *sdata; |
| 676 | |
| 677 | sdata = container_of(wk, struct ieee80211_sub_if_data, |
| 678 | dec_tailroom_needed_wk.work); |
| 679 | |
| 680 | /* |
| 681 | * The reason for the delayed tailroom needed decrementing is to |
| 682 | * make roaming faster: during roaming, all keys are first deleted |
| 683 | * and then new keys are installed. The first new key causes the |
| 684 | * crypto_tx_tailroom_needed_cnt to go from 0 to 1, which invokes |
| 685 | * the cost of synchronize_net() (which can be slow). Avoid this |
| 686 | * by deferring the crypto_tx_tailroom_needed_cnt decrementing on |
| 687 | * key removal for a while, so if we roam the value is larger than |
| 688 | * zero and no 0->1 transition happens. |
| 689 | * |
| 690 | * The cost is that if the AP switching was from an AP with keys |
| 691 | * to one without, we still allocate tailroom while it would no |
| 692 | * longer be needed. However, in the typical (fast) roaming case |
| 693 | * within an ESS this usually won't happen. |
| 694 | */ |
| 695 | |
| 696 | mutex_lock(&sdata->local->key_mtx); |
| 697 | sdata->crypto_tx_tailroom_needed_cnt -= |
| 698 | sdata->crypto_tx_tailroom_pending_dec; |
| 699 | sdata->crypto_tx_tailroom_pending_dec = 0; |
| 700 | mutex_unlock(&sdata->local->key_mtx); |
| 701 | } |
Johannes Berg | c68f4b8 | 2011-07-05 16:35:41 +0200 | [diff] [blame] | 702 | |
| 703 | void ieee80211_gtk_rekey_notify(struct ieee80211_vif *vif, const u8 *bssid, |
| 704 | const u8 *replay_ctr, gfp_t gfp) |
| 705 | { |
| 706 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 707 | |
| 708 | trace_api_gtk_rekey_notify(sdata, bssid, replay_ctr); |
| 709 | |
| 710 | cfg80211_gtk_rekey_notify(sdata->dev, bssid, replay_ctr, gfp); |
| 711 | } |
| 712 | EXPORT_SYMBOL_GPL(ieee80211_gtk_rekey_notify); |
Johannes Berg | 3ea542d | 2011-07-07 18:58:00 +0200 | [diff] [blame] | 713 | |
| 714 | void ieee80211_get_key_tx_seq(struct ieee80211_key_conf *keyconf, |
| 715 | struct ieee80211_key_seq *seq) |
| 716 | { |
| 717 | struct ieee80211_key *key; |
| 718 | u64 pn64; |
| 719 | |
| 720 | if (WARN_ON(!(keyconf->flags & IEEE80211_KEY_FLAG_GENERATE_IV))) |
| 721 | return; |
| 722 | |
| 723 | key = container_of(keyconf, struct ieee80211_key, conf); |
| 724 | |
| 725 | switch (key->conf.cipher) { |
| 726 | case WLAN_CIPHER_SUITE_TKIP: |
| 727 | seq->tkip.iv32 = key->u.tkip.tx.iv32; |
| 728 | seq->tkip.iv16 = key->u.tkip.tx.iv16; |
| 729 | break; |
| 730 | case WLAN_CIPHER_SUITE_CCMP: |
| 731 | pn64 = atomic64_read(&key->u.ccmp.tx_pn); |
| 732 | seq->ccmp.pn[5] = pn64; |
| 733 | seq->ccmp.pn[4] = pn64 >> 8; |
| 734 | seq->ccmp.pn[3] = pn64 >> 16; |
| 735 | seq->ccmp.pn[2] = pn64 >> 24; |
| 736 | seq->ccmp.pn[1] = pn64 >> 32; |
| 737 | seq->ccmp.pn[0] = pn64 >> 40; |
| 738 | break; |
| 739 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 740 | pn64 = atomic64_read(&key->u.aes_cmac.tx_pn); |
| 741 | seq->ccmp.pn[5] = pn64; |
| 742 | seq->ccmp.pn[4] = pn64 >> 8; |
| 743 | seq->ccmp.pn[3] = pn64 >> 16; |
| 744 | seq->ccmp.pn[2] = pn64 >> 24; |
| 745 | seq->ccmp.pn[1] = pn64 >> 32; |
| 746 | seq->ccmp.pn[0] = pn64 >> 40; |
| 747 | break; |
| 748 | default: |
| 749 | WARN_ON(1); |
| 750 | } |
| 751 | } |
| 752 | EXPORT_SYMBOL(ieee80211_get_key_tx_seq); |
| 753 | |
| 754 | void ieee80211_get_key_rx_seq(struct ieee80211_key_conf *keyconf, |
| 755 | int tid, struct ieee80211_key_seq *seq) |
| 756 | { |
| 757 | struct ieee80211_key *key; |
| 758 | const u8 *pn; |
| 759 | |
| 760 | key = container_of(keyconf, struct ieee80211_key, conf); |
| 761 | |
| 762 | switch (key->conf.cipher) { |
| 763 | case WLAN_CIPHER_SUITE_TKIP: |
Johannes Berg | 5a306f5 | 2012-11-14 23:22:21 +0100 | [diff] [blame] | 764 | if (WARN_ON(tid < 0 || tid >= IEEE80211_NUM_TIDS)) |
Johannes Berg | 3ea542d | 2011-07-07 18:58:00 +0200 | [diff] [blame] | 765 | return; |
| 766 | seq->tkip.iv32 = key->u.tkip.rx[tid].iv32; |
| 767 | seq->tkip.iv16 = key->u.tkip.rx[tid].iv16; |
| 768 | break; |
| 769 | case WLAN_CIPHER_SUITE_CCMP: |
Johannes Berg | 5a306f5 | 2012-11-14 23:22:21 +0100 | [diff] [blame] | 770 | if (WARN_ON(tid < -1 || tid >= IEEE80211_NUM_TIDS)) |
Johannes Berg | 3ea542d | 2011-07-07 18:58:00 +0200 | [diff] [blame] | 771 | return; |
| 772 | if (tid < 0) |
Johannes Berg | 5a306f5 | 2012-11-14 23:22:21 +0100 | [diff] [blame] | 773 | pn = key->u.ccmp.rx_pn[IEEE80211_NUM_TIDS]; |
Johannes Berg | 3ea542d | 2011-07-07 18:58:00 +0200 | [diff] [blame] | 774 | else |
| 775 | pn = key->u.ccmp.rx_pn[tid]; |
Johannes Berg | 4325f6c | 2013-05-08 13:09:08 +0200 | [diff] [blame] | 776 | memcpy(seq->ccmp.pn, pn, IEEE80211_CCMP_PN_LEN); |
Johannes Berg | 3ea542d | 2011-07-07 18:58:00 +0200 | [diff] [blame] | 777 | break; |
| 778 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 779 | if (WARN_ON(tid != 0)) |
| 780 | return; |
| 781 | pn = key->u.aes_cmac.rx_pn; |
Johannes Berg | 4325f6c | 2013-05-08 13:09:08 +0200 | [diff] [blame] | 782 | memcpy(seq->aes_cmac.pn, pn, IEEE80211_CMAC_PN_LEN); |
Johannes Berg | 3ea542d | 2011-07-07 18:58:00 +0200 | [diff] [blame] | 783 | break; |
| 784 | } |
| 785 | } |
| 786 | EXPORT_SYMBOL(ieee80211_get_key_rx_seq); |
Johannes Berg | 27b3eb9 | 2013-08-07 20:11:55 +0200 | [diff] [blame] | 787 | |
| 788 | void ieee80211_set_key_tx_seq(struct ieee80211_key_conf *keyconf, |
| 789 | struct ieee80211_key_seq *seq) |
| 790 | { |
| 791 | struct ieee80211_key *key; |
| 792 | u64 pn64; |
| 793 | |
| 794 | key = container_of(keyconf, struct ieee80211_key, conf); |
| 795 | |
| 796 | switch (key->conf.cipher) { |
| 797 | case WLAN_CIPHER_SUITE_TKIP: |
| 798 | key->u.tkip.tx.iv32 = seq->tkip.iv32; |
| 799 | key->u.tkip.tx.iv16 = seq->tkip.iv16; |
| 800 | break; |
| 801 | case WLAN_CIPHER_SUITE_CCMP: |
| 802 | pn64 = (u64)seq->ccmp.pn[5] | |
| 803 | ((u64)seq->ccmp.pn[4] << 8) | |
| 804 | ((u64)seq->ccmp.pn[3] << 16) | |
| 805 | ((u64)seq->ccmp.pn[2] << 24) | |
| 806 | ((u64)seq->ccmp.pn[1] << 32) | |
| 807 | ((u64)seq->ccmp.pn[0] << 40); |
| 808 | atomic64_set(&key->u.ccmp.tx_pn, pn64); |
| 809 | break; |
| 810 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 811 | pn64 = (u64)seq->aes_cmac.pn[5] | |
| 812 | ((u64)seq->aes_cmac.pn[4] << 8) | |
| 813 | ((u64)seq->aes_cmac.pn[3] << 16) | |
| 814 | ((u64)seq->aes_cmac.pn[2] << 24) | |
| 815 | ((u64)seq->aes_cmac.pn[1] << 32) | |
| 816 | ((u64)seq->aes_cmac.pn[0] << 40); |
| 817 | atomic64_set(&key->u.aes_cmac.tx_pn, pn64); |
| 818 | break; |
| 819 | default: |
| 820 | WARN_ON(1); |
| 821 | break; |
| 822 | } |
| 823 | } |
| 824 | EXPORT_SYMBOL_GPL(ieee80211_set_key_tx_seq); |
| 825 | |
| 826 | void ieee80211_set_key_rx_seq(struct ieee80211_key_conf *keyconf, |
| 827 | int tid, struct ieee80211_key_seq *seq) |
| 828 | { |
| 829 | struct ieee80211_key *key; |
| 830 | u8 *pn; |
| 831 | |
| 832 | key = container_of(keyconf, struct ieee80211_key, conf); |
| 833 | |
| 834 | switch (key->conf.cipher) { |
| 835 | case WLAN_CIPHER_SUITE_TKIP: |
| 836 | if (WARN_ON(tid < 0 || tid >= IEEE80211_NUM_TIDS)) |
| 837 | return; |
| 838 | key->u.tkip.rx[tid].iv32 = seq->tkip.iv32; |
| 839 | key->u.tkip.rx[tid].iv16 = seq->tkip.iv16; |
| 840 | break; |
| 841 | case WLAN_CIPHER_SUITE_CCMP: |
| 842 | if (WARN_ON(tid < -1 || tid >= IEEE80211_NUM_TIDS)) |
| 843 | return; |
| 844 | if (tid < 0) |
| 845 | pn = key->u.ccmp.rx_pn[IEEE80211_NUM_TIDS]; |
| 846 | else |
| 847 | pn = key->u.ccmp.rx_pn[tid]; |
| 848 | memcpy(pn, seq->ccmp.pn, IEEE80211_CCMP_PN_LEN); |
| 849 | break; |
| 850 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 851 | if (WARN_ON(tid != 0)) |
| 852 | return; |
| 853 | pn = key->u.aes_cmac.rx_pn; |
| 854 | memcpy(pn, seq->aes_cmac.pn, IEEE80211_CMAC_PN_LEN); |
| 855 | break; |
| 856 | default: |
| 857 | WARN_ON(1); |
| 858 | break; |
| 859 | } |
| 860 | } |
| 861 | EXPORT_SYMBOL_GPL(ieee80211_set_key_rx_seq); |
| 862 | |
| 863 | void ieee80211_remove_key(struct ieee80211_key_conf *keyconf) |
| 864 | { |
| 865 | struct ieee80211_key *key; |
| 866 | |
| 867 | key = container_of(keyconf, struct ieee80211_key, conf); |
| 868 | |
| 869 | assert_key_lock(key->local); |
| 870 | |
| 871 | /* |
| 872 | * if key was uploaded, we assume the driver will/has remove(d) |
| 873 | * it, so adjust bookkeeping accordingly |
| 874 | */ |
| 875 | if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { |
| 876 | key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE; |
| 877 | |
Ido Yariv | ca34e3b | 2014-07-29 15:38:53 +0300 | [diff] [blame] | 878 | if (!(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC)) |
Johannes Berg | 27b3eb9 | 2013-08-07 20:11:55 +0200 | [diff] [blame] | 879 | increment_tailroom_need_count(key->sdata); |
| 880 | } |
| 881 | |
| 882 | ieee80211_key_free(key, false); |
| 883 | } |
| 884 | EXPORT_SYMBOL_GPL(ieee80211_remove_key); |
| 885 | |
| 886 | struct ieee80211_key_conf * |
| 887 | ieee80211_gtk_rekey_add(struct ieee80211_vif *vif, |
| 888 | struct ieee80211_key_conf *keyconf) |
| 889 | { |
| 890 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 891 | struct ieee80211_local *local = sdata->local; |
| 892 | struct ieee80211_key *key; |
| 893 | int err; |
| 894 | |
| 895 | if (WARN_ON(!local->wowlan)) |
| 896 | return ERR_PTR(-EINVAL); |
| 897 | |
| 898 | if (WARN_ON(vif->type != NL80211_IFTYPE_STATION)) |
| 899 | return ERR_PTR(-EINVAL); |
| 900 | |
| 901 | key = ieee80211_key_alloc(keyconf->cipher, keyconf->keyidx, |
| 902 | keyconf->keylen, keyconf->key, |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 903 | 0, NULL, NULL); |
Johannes Berg | 27b3eb9 | 2013-08-07 20:11:55 +0200 | [diff] [blame] | 904 | if (IS_ERR(key)) |
Johannes Berg | c5dc164 | 2013-08-28 19:03:36 +0200 | [diff] [blame] | 905 | return ERR_CAST(key); |
Johannes Berg | 27b3eb9 | 2013-08-07 20:11:55 +0200 | [diff] [blame] | 906 | |
| 907 | if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED) |
| 908 | key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT; |
| 909 | |
| 910 | err = ieee80211_key_link(key, sdata, NULL); |
| 911 | if (err) |
| 912 | return ERR_PTR(err); |
| 913 | |
| 914 | return &key->conf; |
| 915 | } |
| 916 | EXPORT_SYMBOL_GPL(ieee80211_gtk_rekey_add); |