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