blob: f53dec8a3d5cdc575c820b3d2cb81e97861d7b5d [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Jiri Bence9f207f2007-05-05 11:46:38 -07002/*
3 * Copyright 2003-2005 Devicescape Software, Inc.
4 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
5 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
Johannes Bergd0a77c62015-09-23 10:42:28 +02006 * Copyright (C) 2015 Intel Deutschland GmbH
Jiri Bence9f207f2007-05-05 11:46:38 -07007 */
8
9#include <linux/kobject.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Jiri Bence9f207f2007-05-05 11:46:38 -070011#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040012#include "key.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070013#include "debugfs.h"
14#include "debugfs_key.h"
15
Eliad Peller07caf9d2010-10-27 14:58:29 +020016#define KEY_READ(name, prop, format_string) \
Jiri Bence9f207f2007-05-05 11:46:38 -070017static ssize_t key_##name##_read(struct file *file, \
18 char __user *userbuf, \
19 size_t count, loff_t *ppos) \
20{ \
Jiri Bence9f207f2007-05-05 11:46:38 -070021 struct ieee80211_key *key = file->private_data; \
Eliad Peller07caf9d2010-10-27 14:58:29 +020022 return mac80211_format_buffer(userbuf, count, ppos, \
23 format_string, key->prop); \
Jiri Bence9f207f2007-05-05 11:46:38 -070024}
Eliad Peller07caf9d2010-10-27 14:58:29 +020025#define KEY_READ_D(name) KEY_READ(name, name, "%d\n")
26#define KEY_READ_X(name) KEY_READ(name, name, "0x%x\n")
Jiri Bence9f207f2007-05-05 11:46:38 -070027
28#define KEY_OPS(name) \
29static const struct file_operations key_ ##name## _ops = { \
30 .read = key_##name##_read, \
Stephen Boyd234e3402012-04-05 14:25:11 -070031 .open = simple_open, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020032 .llseek = generic_file_llseek, \
Jiri Bence9f207f2007-05-05 11:46:38 -070033}
34
Johannes Bergd0a77c62015-09-23 10:42:28 +020035#define KEY_OPS_W(name) \
36static const struct file_operations key_ ##name## _ops = { \
37 .read = key_##name##_read, \
38 .write = key_##name##_write, \
39 .open = simple_open, \
40 .llseek = generic_file_llseek, \
41}
42
Jiri Bence9f207f2007-05-05 11:46:38 -070043#define KEY_FILE(name, format) \
44 KEY_READ_##format(name) \
45 KEY_OPS(name)
46
Eliad Peller07caf9d2010-10-27 14:58:29 +020047#define KEY_CONF_READ(name, format_string) \
48 KEY_READ(conf_##name, conf.name, format_string)
49#define KEY_CONF_READ_D(name) KEY_CONF_READ(name, "%d\n")
Johannes Berg8f20fc22007-08-28 17:01:54 -040050
51#define KEY_CONF_OPS(name) \
52static const struct file_operations key_ ##name## _ops = { \
53 .read = key_conf_##name##_read, \
Stephen Boyd234e3402012-04-05 14:25:11 -070054 .open = simple_open, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020055 .llseek = generic_file_llseek, \
Johannes Berg8f20fc22007-08-28 17:01:54 -040056}
57
58#define KEY_CONF_FILE(name, format) \
59 KEY_CONF_READ_##format(name) \
60 KEY_CONF_OPS(name)
61
62KEY_CONF_FILE(keylen, D);
63KEY_CONF_FILE(keyidx, D);
64KEY_CONF_FILE(hw_key_idx, D);
Johannes Berg11a843b2007-08-28 17:01:55 -040065KEY_FILE(flags, X);
Eliad Peller07caf9d2010-10-27 14:58:29 +020066KEY_READ(ifindex, sdata->name, "%s\n");
Johannes Berge7a64f12007-08-28 17:01:55 -040067KEY_OPS(ifindex);
Jiri Bence9f207f2007-05-05 11:46:38 -070068
69static ssize_t key_algorithm_read(struct file *file,
70 char __user *userbuf,
71 size_t count, loff_t *ppos)
72{
Johannes Berg97359d12010-08-10 09:46:38 +020073 char buf[15];
Jiri Bence9f207f2007-05-05 11:46:38 -070074 struct ieee80211_key *key = file->private_data;
Johannes Berg97359d12010-08-10 09:46:38 +020075 u32 c = key->conf.cipher;
Jiri Bence9f207f2007-05-05 11:46:38 -070076
Johannes Berg97359d12010-08-10 09:46:38 +020077 sprintf(buf, "%.2x-%.2x-%.2x:%d\n",
78 c >> 24, (c >> 16) & 0xff, (c >> 8) & 0xff, c & 0xff);
79 return simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
Jiri Bence9f207f2007-05-05 11:46:38 -070080}
81KEY_OPS(algorithm);
82
Johannes Bergd0a77c62015-09-23 10:42:28 +020083static ssize_t key_tx_spec_write(struct file *file, const char __user *userbuf,
84 size_t count, loff_t *ppos)
85{
86 struct ieee80211_key *key = file->private_data;
87 u64 pn;
88 int ret;
89
90 switch (key->conf.cipher) {
91 case WLAN_CIPHER_SUITE_WEP40:
92 case WLAN_CIPHER_SUITE_WEP104:
93 return -EINVAL;
94 case WLAN_CIPHER_SUITE_TKIP:
95 /* not supported yet */
96 return -EOPNOTSUPP;
97 case WLAN_CIPHER_SUITE_CCMP:
98 case WLAN_CIPHER_SUITE_CCMP_256:
99 case WLAN_CIPHER_SUITE_AES_CMAC:
100 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
101 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
102 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
103 case WLAN_CIPHER_SUITE_GCMP:
104 case WLAN_CIPHER_SUITE_GCMP_256:
105 ret = kstrtou64_from_user(userbuf, count, 16, &pn);
106 if (ret)
107 return ret;
108 /* PN is a 48-bit counter */
109 if (pn >= (1ULL << 48))
110 return -ERANGE;
111 atomic64_set(&key->conf.tx_pn, pn);
112 return count;
113 default:
114 return 0;
115 }
116}
117
Jiri Bence9f207f2007-05-05 11:46:38 -0700118static ssize_t key_tx_spec_read(struct file *file, char __user *userbuf,
119 size_t count, loff_t *ppos)
120{
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200121 u64 pn;
Jiri Bence9f207f2007-05-05 11:46:38 -0700122 char buf[20];
123 int len;
124 struct ieee80211_key *key = file->private_data;
125
Johannes Berg97359d12010-08-10 09:46:38 +0200126 switch (key->conf.cipher) {
127 case WLAN_CIPHER_SUITE_WEP40:
128 case WLAN_CIPHER_SUITE_WEP104:
Jiri Bence9f207f2007-05-05 11:46:38 -0700129 len = scnprintf(buf, sizeof(buf), "\n");
Johannes Berg50339a62007-08-28 17:01:52 -0400130 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200131 case WLAN_CIPHER_SUITE_TKIP:
Eliad Pellerf8079d42016-02-14 13:56:35 +0200132 pn = atomic64_read(&key->conf.tx_pn);
Jiri Bence9f207f2007-05-05 11:46:38 -0700133 len = scnprintf(buf, sizeof(buf), "%08x %04x\n",
Eliad Pellerf8079d42016-02-14 13:56:35 +0200134 TKIP_PN_TO_IV32(pn),
135 TKIP_PN_TO_IV16(pn));
Johannes Berg50339a62007-08-28 17:01:52 -0400136 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200137 case WLAN_CIPHER_SUITE_CCMP:
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +0200138 case WLAN_CIPHER_SUITE_CCMP_256:
Johannes Berg97359d12010-08-10 09:46:38 +0200139 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen56c52da2015-01-24 19:52:08 +0200140 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
Jouni Malinen8ade5382015-01-24 19:52:09 +0200141 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
142 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
Jouni Malinen00b9cfa2015-01-24 19:52:06 +0200143 case WLAN_CIPHER_SUITE_GCMP:
144 case WLAN_CIPHER_SUITE_GCMP_256:
Johannes Bergdb388a52015-06-01 15:36:51 +0200145 pn = atomic64_read(&key->conf.tx_pn);
Jouni Malinen00b9cfa2015-01-24 19:52:06 +0200146 len = scnprintf(buf, sizeof(buf), "%02x%02x%02x%02x%02x%02x\n",
147 (u8)(pn >> 40), (u8)(pn >> 32), (u8)(pn >> 24),
148 (u8)(pn >> 16), (u8)(pn >> 8), (u8)pn);
149 break;
Jiri Bence9f207f2007-05-05 11:46:38 -0700150 default:
151 return 0;
152 }
153 return simple_read_from_buffer(userbuf, count, ppos, buf, len);
154}
Johannes Bergd0a77c62015-09-23 10:42:28 +0200155KEY_OPS_W(tx_spec);
Jiri Bence9f207f2007-05-05 11:46:38 -0700156
157static ssize_t key_rx_spec_read(struct file *file, char __user *userbuf,
158 size_t count, loff_t *ppos)
159{
160 struct ieee80211_key *key = file->private_data;
Johannes Berg5a306f52012-11-14 23:22:21 +0100161 char buf[14*IEEE80211_NUM_TIDS+1], *p = buf;
Jiri Bence9f207f2007-05-05 11:46:38 -0700162 int i, len;
163 const u8 *rpn;
164
Johannes Berg97359d12010-08-10 09:46:38 +0200165 switch (key->conf.cipher) {
166 case WLAN_CIPHER_SUITE_WEP40:
167 case WLAN_CIPHER_SUITE_WEP104:
Jiri Bence9f207f2007-05-05 11:46:38 -0700168 len = scnprintf(buf, sizeof(buf), "\n");
Johannes Berg50339a62007-08-28 17:01:52 -0400169 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200170 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg5a306f52012-11-14 23:22:21 +0100171 for (i = 0; i < IEEE80211_NUM_TIDS; i++)
Jiri Bence9f207f2007-05-05 11:46:38 -0700172 p += scnprintf(p, sizeof(buf)+buf-p,
173 "%08x %04x\n",
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700174 key->u.tkip.rx[i].iv32,
175 key->u.tkip.rx[i].iv16);
Jiri Bence9f207f2007-05-05 11:46:38 -0700176 len = p - buf;
Johannes Berg50339a62007-08-28 17:01:52 -0400177 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200178 case WLAN_CIPHER_SUITE_CCMP:
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +0200179 case WLAN_CIPHER_SUITE_CCMP_256:
Johannes Berg5a306f52012-11-14 23:22:21 +0100180 for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) {
Jiri Bence9f207f2007-05-05 11:46:38 -0700181 rpn = key->u.ccmp.rx_pn[i];
182 p += scnprintf(p, sizeof(buf)+buf-p,
183 "%02x%02x%02x%02x%02x%02x\n",
184 rpn[0], rpn[1], rpn[2],
185 rpn[3], rpn[4], rpn[5]);
186 }
187 len = p - buf;
Johannes Berg50339a62007-08-28 17:01:52 -0400188 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200189 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen56c52da2015-01-24 19:52:08 +0200190 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200191 rpn = key->u.aes_cmac.rx_pn;
192 p += scnprintf(p, sizeof(buf)+buf-p,
193 "%02x%02x%02x%02x%02x%02x\n",
194 rpn[0], rpn[1], rpn[2],
195 rpn[3], rpn[4], rpn[5]);
196 len = p - buf;
197 break;
Jouni Malinen8ade5382015-01-24 19:52:09 +0200198 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
199 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
200 rpn = key->u.aes_gmac.rx_pn;
201 p += scnprintf(p, sizeof(buf)+buf-p,
202 "%02x%02x%02x%02x%02x%02x\n",
203 rpn[0], rpn[1], rpn[2],
204 rpn[3], rpn[4], rpn[5]);
205 len = p - buf;
206 break;
Jouni Malinen00b9cfa2015-01-24 19:52:06 +0200207 case WLAN_CIPHER_SUITE_GCMP:
208 case WLAN_CIPHER_SUITE_GCMP_256:
209 for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) {
210 rpn = key->u.gcmp.rx_pn[i];
211 p += scnprintf(p, sizeof(buf)+buf-p,
212 "%02x%02x%02x%02x%02x%02x\n",
213 rpn[0], rpn[1], rpn[2],
214 rpn[3], rpn[4], rpn[5]);
215 }
216 len = p - buf;
217 break;
Jiri Bence9f207f2007-05-05 11:46:38 -0700218 default:
219 return 0;
220 }
221 return simple_read_from_buffer(userbuf, count, ppos, buf, len);
222}
223KEY_OPS(rx_spec);
224
225static ssize_t key_replays_read(struct file *file, char __user *userbuf,
226 size_t count, loff_t *ppos)
227{
228 struct ieee80211_key *key = file->private_data;
229 char buf[20];
230 int len;
231
Johannes Berg97359d12010-08-10 09:46:38 +0200232 switch (key->conf.cipher) {
233 case WLAN_CIPHER_SUITE_CCMP:
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +0200234 case WLAN_CIPHER_SUITE_CCMP_256:
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200235 len = scnprintf(buf, sizeof(buf), "%u\n", key->u.ccmp.replays);
236 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200237 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen56c52da2015-01-24 19:52:08 +0200238 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200239 len = scnprintf(buf, sizeof(buf), "%u\n",
240 key->u.aes_cmac.replays);
241 break;
Jouni Malinen8ade5382015-01-24 19:52:09 +0200242 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
243 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
244 len = scnprintf(buf, sizeof(buf), "%u\n",
245 key->u.aes_gmac.replays);
246 break;
Jouni Malinen00b9cfa2015-01-24 19:52:06 +0200247 case WLAN_CIPHER_SUITE_GCMP:
248 case WLAN_CIPHER_SUITE_GCMP_256:
249 len = scnprintf(buf, sizeof(buf), "%u\n", key->u.gcmp.replays);
250 break;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200251 default:
Jiri Bence9f207f2007-05-05 11:46:38 -0700252 return 0;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200253 }
Jiri Bence9f207f2007-05-05 11:46:38 -0700254 return simple_read_from_buffer(userbuf, count, ppos, buf, len);
255}
256KEY_OPS(replays);
257
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200258static ssize_t key_icverrors_read(struct file *file, char __user *userbuf,
259 size_t count, loff_t *ppos)
260{
261 struct ieee80211_key *key = file->private_data;
262 char buf[20];
263 int len;
264
Johannes Berg97359d12010-08-10 09:46:38 +0200265 switch (key->conf.cipher) {
266 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen56c52da2015-01-24 19:52:08 +0200267 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200268 len = scnprintf(buf, sizeof(buf), "%u\n",
269 key->u.aes_cmac.icverrors);
270 break;
Jouni Malinen8ade5382015-01-24 19:52:09 +0200271 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
272 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
273 len = scnprintf(buf, sizeof(buf), "%u\n",
274 key->u.aes_gmac.icverrors);
275 break;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200276 default:
277 return 0;
278 }
279 return simple_read_from_buffer(userbuf, count, ppos, buf, len);
280}
281KEY_OPS(icverrors);
282
Saravanab98ea052012-12-04 19:47:42 +0530283static ssize_t key_mic_failures_read(struct file *file, char __user *userbuf,
284 size_t count, loff_t *ppos)
285{
286 struct ieee80211_key *key = file->private_data;
287 char buf[20];
288 int len;
289
290 if (key->conf.cipher != WLAN_CIPHER_SUITE_TKIP)
291 return -EINVAL;
292
293 len = scnprintf(buf, sizeof(buf), "%u\n", key->u.tkip.mic_failures);
294
295 return simple_read_from_buffer(userbuf, count, ppos, buf, len);
296}
297KEY_OPS(mic_failures);
298
Jiri Bence9f207f2007-05-05 11:46:38 -0700299static ssize_t key_key_read(struct file *file, char __user *userbuf,
300 size_t count, loff_t *ppos)
301{
302 struct ieee80211_key *key = file->private_data;
Jesper Juhl520efd12010-10-29 16:10:26 +0200303 int i, bufsize = 2 * key->conf.keylen + 2;
Jiri Bence9f207f2007-05-05 11:46:38 -0700304 char *buf = kmalloc(bufsize, GFP_KERNEL);
305 char *p = buf;
Jesper Juhl520efd12010-10-29 16:10:26 +0200306 ssize_t res;
307
308 if (!buf)
309 return -ENOMEM;
Jiri Bence9f207f2007-05-05 11:46:38 -0700310
Johannes Berg8f20fc22007-08-28 17:01:54 -0400311 for (i = 0; i < key->conf.keylen; i++)
312 p += scnprintf(p, bufsize + buf - p, "%02x", key->conf.key[i]);
Jiri Bence9f207f2007-05-05 11:46:38 -0700313 p += scnprintf(p, bufsize+buf-p, "\n");
314 res = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
315 kfree(buf);
316 return res;
317}
318KEY_OPS(key);
319
320#define DEBUGFS_ADD(name) \
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100321 debugfs_create_file(#name, 0400, key->debugfs.dir, \
Tom Rix84674ef2020-11-27 11:38:42 -0800322 key, &key_##name##_ops)
Johannes Bergd0a77c62015-09-23 10:42:28 +0200323#define DEBUGFS_ADD_W(name) \
324 debugfs_create_file(#name, 0600, key->debugfs.dir, \
325 key, &key_##name##_ops);
Jiri Bence9f207f2007-05-05 11:46:38 -0700326
Johannes Berg3b967662008-04-08 17:56:52 +0200327void ieee80211_debugfs_key_add(struct ieee80211_key *key)
Johannes Berg9446f3e2012-01-17 10:32:01 +0100328{
Johannes Berg50339a62007-08-28 17:01:52 -0400329 static int keycount;
Johannes Berg9446f3e2012-01-17 10:32:01 +0100330 char buf[100];
Johannes Berg3b967662008-04-08 17:56:52 +0200331 struct sta_info *sta;
Jiri Bence9f207f2007-05-05 11:46:38 -0700332
Johannes Berg3b967662008-04-08 17:56:52 +0200333 if (!key->local->debugfs.keys)
Jiri Bence9f207f2007-05-05 11:46:38 -0700334 return;
335
Johannes Berg50339a62007-08-28 17:01:52 -0400336 sprintf(buf, "%d", keycount);
Johannes Bergd9c58f32008-04-08 16:46:36 -0400337 key->debugfs.cnt = keycount;
Johannes Berg50339a62007-08-28 17:01:52 -0400338 keycount++;
Jiri Bence9f207f2007-05-05 11:46:38 -0700339 key->debugfs.dir = debugfs_create_dir(buf,
Johannes Berg3b967662008-04-08 17:56:52 +0200340 key->local->debugfs.keys);
Jiri Bence9f207f2007-05-05 11:46:38 -0700341
Johannes Berg40b275b2011-05-13 14:15:49 +0200342 sta = key->sta;
343 if (sta) {
Johannes Berg9446f3e2012-01-17 10:32:01 +0100344 sprintf(buf, "../../netdev:%s/stations/%pM",
345 sta->sdata->name, sta->sta.addr);
Johannes Berg3b967662008-04-08 17:56:52 +0200346 key->debugfs.stalink =
347 debugfs_create_symlink("station", key->debugfs.dir, buf);
Johannes Berg40b275b2011-05-13 14:15:49 +0200348 }
Johannes Berg3b967662008-04-08 17:56:52 +0200349
Jiri Bence9f207f2007-05-05 11:46:38 -0700350 DEBUGFS_ADD(keylen);
Johannes Berg8f20fc22007-08-28 17:01:54 -0400351 DEBUGFS_ADD(flags);
Jiri Bence9f207f2007-05-05 11:46:38 -0700352 DEBUGFS_ADD(keyidx);
353 DEBUGFS_ADD(hw_key_idx);
Jiri Bence9f207f2007-05-05 11:46:38 -0700354 DEBUGFS_ADD(algorithm);
Johannes Bergd0a77c62015-09-23 10:42:28 +0200355 DEBUGFS_ADD_W(tx_spec);
Jiri Bence9f207f2007-05-05 11:46:38 -0700356 DEBUGFS_ADD(rx_spec);
357 DEBUGFS_ADD(replays);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200358 DEBUGFS_ADD(icverrors);
Saravanab98ea052012-12-04 19:47:42 +0530359 DEBUGFS_ADD(mic_failures);
Jiri Bence9f207f2007-05-05 11:46:38 -0700360 DEBUGFS_ADD(key);
Johannes Berge7a64f12007-08-28 17:01:55 -0400361 DEBUGFS_ADD(ifindex);
Jiri Bence9f207f2007-05-05 11:46:38 -0700362};
363
Jiri Bence9f207f2007-05-05 11:46:38 -0700364void ieee80211_debugfs_key_remove(struct ieee80211_key *key)
365{
366 if (!key)
367 return;
368
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100369 debugfs_remove_recursive(key->debugfs.dir);
Jiri Bence9f207f2007-05-05 11:46:38 -0700370 key->debugfs.dir = NULL;
371}
Johannes Bergf7e01042010-12-09 19:49:02 +0100372
373void ieee80211_debugfs_key_update_default(struct ieee80211_sub_if_data *sdata)
Jiri Bence9f207f2007-05-05 11:46:38 -0700374{
375 char buf[50];
Johannes Berg78520ca2008-05-03 01:04:47 +0200376 struct ieee80211_key *key;
Jiri Bence9f207f2007-05-05 11:46:38 -0700377
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100378 if (!sdata->vif.debugfs_dir)
Jiri Bence9f207f2007-05-05 11:46:38 -0700379 return;
380
Johannes Bergf7e01042010-12-09 19:49:02 +0100381 lockdep_assert_held(&sdata->local->key_mtx);
Johannes Berg78520ca2008-05-03 01:04:47 +0200382
Fabian Frederick5c6761a2014-10-21 18:20:12 +0200383 debugfs_remove(sdata->debugfs.default_unicast_key);
384 sdata->debugfs.default_unicast_key = NULL;
Johannes Berg135792e2012-07-05 21:37:05 +0200385
Johannes Bergf7e01042010-12-09 19:49:02 +0100386 if (sdata->default_unicast_key) {
Johannes Berg40b275b2011-05-13 14:15:49 +0200387 key = key_mtx_dereference(sdata->local,
388 sdata->default_unicast_key);
Johannes Berg78520ca2008-05-03 01:04:47 +0200389 sprintf(buf, "../keys/%d", key->debugfs.cnt);
Johannes Bergf7e01042010-12-09 19:49:02 +0100390 sdata->debugfs.default_unicast_key =
391 debugfs_create_symlink("default_unicast_key",
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100392 sdata->vif.debugfs_dir, buf);
Johannes Berg135792e2012-07-05 21:37:05 +0200393 }
394
Fabian Frederick5c6761a2014-10-21 18:20:12 +0200395 debugfs_remove(sdata->debugfs.default_multicast_key);
396 sdata->debugfs.default_multicast_key = NULL;
Johannes Berg78520ca2008-05-03 01:04:47 +0200397
Johannes Bergf7e01042010-12-09 19:49:02 +0100398 if (sdata->default_multicast_key) {
Johannes Berg40b275b2011-05-13 14:15:49 +0200399 key = key_mtx_dereference(sdata->local,
400 sdata->default_multicast_key);
Johannes Bergf7e01042010-12-09 19:49:02 +0100401 sprintf(buf, "../keys/%d", key->debugfs.cnt);
402 sdata->debugfs.default_multicast_key =
403 debugfs_create_symlink("default_multicast_key",
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100404 sdata->vif.debugfs_dir, buf);
Johannes Bergf7e01042010-12-09 19:49:02 +0100405 }
Jiri Bence9f207f2007-05-05 11:46:38 -0700406}
Jiri Bence9f207f2007-05-05 11:46:38 -0700407
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200408void ieee80211_debugfs_key_add_mgmt_default(struct ieee80211_sub_if_data *sdata)
409{
410 char buf[50];
411 struct ieee80211_key *key;
412
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100413 if (!sdata->vif.debugfs_dir)
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200414 return;
415
Johannes Berg40b275b2011-05-13 14:15:49 +0200416 key = key_mtx_dereference(sdata->local,
417 sdata->default_mgmt_key);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200418 if (key) {
419 sprintf(buf, "../keys/%d", key->debugfs.cnt);
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100420 sdata->debugfs.default_mgmt_key =
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200421 debugfs_create_symlink("default_mgmt_key",
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100422 sdata->vif.debugfs_dir, buf);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200423 } else
424 ieee80211_debugfs_key_remove_mgmt_default(sdata);
425}
426
427void ieee80211_debugfs_key_remove_mgmt_default(struct ieee80211_sub_if_data *sdata)
428{
429 if (!sdata)
430 return;
431
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100432 debugfs_remove(sdata->debugfs.default_mgmt_key);
433 sdata->debugfs.default_mgmt_key = NULL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200434}
435
Jouni Malinene5473e82020-02-22 15:25:44 +0200436void
437ieee80211_debugfs_key_add_beacon_default(struct ieee80211_sub_if_data *sdata)
438{
439 char buf[50];
440 struct ieee80211_key *key;
441
442 if (!sdata->vif.debugfs_dir)
443 return;
444
445 key = key_mtx_dereference(sdata->local,
446 sdata->default_beacon_key);
447 if (key) {
448 sprintf(buf, "../keys/%d", key->debugfs.cnt);
449 sdata->debugfs.default_beacon_key =
450 debugfs_create_symlink("default_beacon_key",
451 sdata->vif.debugfs_dir, buf);
452 } else {
453 ieee80211_debugfs_key_remove_beacon_default(sdata);
454 }
455}
456
457void
458ieee80211_debugfs_key_remove_beacon_default(struct ieee80211_sub_if_data *sdata)
459{
460 if (!sdata)
461 return;
462
463 debugfs_remove(sdata->debugfs.default_beacon_key);
464 sdata->debugfs.default_beacon_key = NULL;
465}
466
Jiri Bence9f207f2007-05-05 11:46:38 -0700467void ieee80211_debugfs_key_sta_del(struct ieee80211_key *key,
468 struct sta_info *sta)
469{
470 debugfs_remove(key->debugfs.stalink);
471 key->debugfs.stalink = NULL;
472}