blob: a2ef95f16f116ae905049c595742bcee3e78c6c7 [file] [log] [blame]
Jiri Bence9f207f2007-05-05 11:46:38 -07001/*
2 * Copyright 2003-2005 Devicescape Software, Inc.
3 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
Johannes Bergd0a77c62015-09-23 10:42:28 +02005 * Copyright (C) 2015 Intel Deutschland GmbH
Jiri Bence9f207f2007-05-05 11:46:38 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/kobject.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Jiri Bence9f207f2007-05-05 11:46:38 -070014#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040015#include "key.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070016#include "debugfs.h"
17#include "debugfs_key.h"
18
Eliad Peller07caf9d2010-10-27 14:58:29 +020019#define KEY_READ(name, prop, format_string) \
Jiri Bence9f207f2007-05-05 11:46:38 -070020static ssize_t key_##name##_read(struct file *file, \
21 char __user *userbuf, \
22 size_t count, loff_t *ppos) \
23{ \
Jiri Bence9f207f2007-05-05 11:46:38 -070024 struct ieee80211_key *key = file->private_data; \
Eliad Peller07caf9d2010-10-27 14:58:29 +020025 return mac80211_format_buffer(userbuf, count, ppos, \
26 format_string, key->prop); \
Jiri Bence9f207f2007-05-05 11:46:38 -070027}
Eliad Peller07caf9d2010-10-27 14:58:29 +020028#define KEY_READ_D(name) KEY_READ(name, name, "%d\n")
29#define KEY_READ_X(name) KEY_READ(name, name, "0x%x\n")
Jiri Bence9f207f2007-05-05 11:46:38 -070030
31#define KEY_OPS(name) \
32static const struct file_operations key_ ##name## _ops = { \
33 .read = key_##name##_read, \
Stephen Boyd234e3402012-04-05 14:25:11 -070034 .open = simple_open, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020035 .llseek = generic_file_llseek, \
Jiri Bence9f207f2007-05-05 11:46:38 -070036}
37
Johannes Bergd0a77c62015-09-23 10:42:28 +020038#define KEY_OPS_W(name) \
39static const struct file_operations key_ ##name## _ops = { \
40 .read = key_##name##_read, \
41 .write = key_##name##_write, \
42 .open = simple_open, \
43 .llseek = generic_file_llseek, \
44}
45
Jiri Bence9f207f2007-05-05 11:46:38 -070046#define KEY_FILE(name, format) \
47 KEY_READ_##format(name) \
48 KEY_OPS(name)
49
Eliad Peller07caf9d2010-10-27 14:58:29 +020050#define KEY_CONF_READ(name, format_string) \
51 KEY_READ(conf_##name, conf.name, format_string)
52#define KEY_CONF_READ_D(name) KEY_CONF_READ(name, "%d\n")
Johannes Berg8f20fc22007-08-28 17:01:54 -040053
54#define KEY_CONF_OPS(name) \
55static const struct file_operations key_ ##name## _ops = { \
56 .read = key_conf_##name##_read, \
Stephen Boyd234e3402012-04-05 14:25:11 -070057 .open = simple_open, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020058 .llseek = generic_file_llseek, \
Johannes Berg8f20fc22007-08-28 17:01:54 -040059}
60
61#define KEY_CONF_FILE(name, format) \
62 KEY_CONF_READ_##format(name) \
63 KEY_CONF_OPS(name)
64
65KEY_CONF_FILE(keylen, D);
66KEY_CONF_FILE(keyidx, D);
67KEY_CONF_FILE(hw_key_idx, D);
Johannes Berg11a843b2007-08-28 17:01:55 -040068KEY_FILE(flags, X);
Eliad Peller07caf9d2010-10-27 14:58:29 +020069KEY_READ(ifindex, sdata->name, "%s\n");
Johannes Berge7a64f12007-08-28 17:01:55 -040070KEY_OPS(ifindex);
Jiri Bence9f207f2007-05-05 11:46:38 -070071
72static ssize_t key_algorithm_read(struct file *file,
73 char __user *userbuf,
74 size_t count, loff_t *ppos)
75{
Johannes Berg97359d12010-08-10 09:46:38 +020076 char buf[15];
Jiri Bence9f207f2007-05-05 11:46:38 -070077 struct ieee80211_key *key = file->private_data;
Johannes Berg97359d12010-08-10 09:46:38 +020078 u32 c = key->conf.cipher;
Jiri Bence9f207f2007-05-05 11:46:38 -070079
Johannes Berg97359d12010-08-10 09:46:38 +020080 sprintf(buf, "%.2x-%.2x-%.2x:%d\n",
81 c >> 24, (c >> 16) & 0xff, (c >> 8) & 0xff, c & 0xff);
82 return simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
Jiri Bence9f207f2007-05-05 11:46:38 -070083}
84KEY_OPS(algorithm);
85
Johannes Bergd0a77c62015-09-23 10:42:28 +020086static ssize_t key_tx_spec_write(struct file *file, const char __user *userbuf,
87 size_t count, loff_t *ppos)
88{
89 struct ieee80211_key *key = file->private_data;
90 u64 pn;
91 int ret;
92
93 switch (key->conf.cipher) {
94 case WLAN_CIPHER_SUITE_WEP40:
95 case WLAN_CIPHER_SUITE_WEP104:
96 return -EINVAL;
97 case WLAN_CIPHER_SUITE_TKIP:
98 /* not supported yet */
99 return -EOPNOTSUPP;
100 case WLAN_CIPHER_SUITE_CCMP:
101 case WLAN_CIPHER_SUITE_CCMP_256:
102 case WLAN_CIPHER_SUITE_AES_CMAC:
103 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
104 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
105 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
106 case WLAN_CIPHER_SUITE_GCMP:
107 case WLAN_CIPHER_SUITE_GCMP_256:
108 ret = kstrtou64_from_user(userbuf, count, 16, &pn);
109 if (ret)
110 return ret;
111 /* PN is a 48-bit counter */
112 if (pn >= (1ULL << 48))
113 return -ERANGE;
114 atomic64_set(&key->conf.tx_pn, pn);
115 return count;
116 default:
117 return 0;
118 }
119}
120
Jiri Bence9f207f2007-05-05 11:46:38 -0700121static ssize_t key_tx_spec_read(struct file *file, char __user *userbuf,
122 size_t count, loff_t *ppos)
123{
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200124 u64 pn;
Jiri Bence9f207f2007-05-05 11:46:38 -0700125 char buf[20];
126 int len;
127 struct ieee80211_key *key = file->private_data;
128
Johannes Berg97359d12010-08-10 09:46:38 +0200129 switch (key->conf.cipher) {
130 case WLAN_CIPHER_SUITE_WEP40:
131 case WLAN_CIPHER_SUITE_WEP104:
Jiri Bence9f207f2007-05-05 11:46:38 -0700132 len = scnprintf(buf, sizeof(buf), "\n");
Johannes Berg50339a62007-08-28 17:01:52 -0400133 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200134 case WLAN_CIPHER_SUITE_TKIP:
Eliad Pellerf8079d42016-02-14 13:56:35 +0200135 pn = atomic64_read(&key->conf.tx_pn);
Jiri Bence9f207f2007-05-05 11:46:38 -0700136 len = scnprintf(buf, sizeof(buf), "%08x %04x\n",
Eliad Pellerf8079d42016-02-14 13:56:35 +0200137 TKIP_PN_TO_IV32(pn),
138 TKIP_PN_TO_IV16(pn));
Johannes Berg50339a62007-08-28 17:01:52 -0400139 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200140 case WLAN_CIPHER_SUITE_CCMP:
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +0200141 case WLAN_CIPHER_SUITE_CCMP_256:
Johannes Berg97359d12010-08-10 09:46:38 +0200142 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen56c52da2015-01-24 19:52:08 +0200143 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
Jouni Malinen8ade5382015-01-24 19:52:09 +0200144 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
145 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
Jouni Malinen00b9cfa2015-01-24 19:52:06 +0200146 case WLAN_CIPHER_SUITE_GCMP:
147 case WLAN_CIPHER_SUITE_GCMP_256:
Johannes Bergdb388a52015-06-01 15:36:51 +0200148 pn = atomic64_read(&key->conf.tx_pn);
Jouni Malinen00b9cfa2015-01-24 19:52:06 +0200149 len = scnprintf(buf, sizeof(buf), "%02x%02x%02x%02x%02x%02x\n",
150 (u8)(pn >> 40), (u8)(pn >> 32), (u8)(pn >> 24),
151 (u8)(pn >> 16), (u8)(pn >> 8), (u8)pn);
152 break;
Jiri Bence9f207f2007-05-05 11:46:38 -0700153 default:
154 return 0;
155 }
156 return simple_read_from_buffer(userbuf, count, ppos, buf, len);
157}
Johannes Bergd0a77c62015-09-23 10:42:28 +0200158KEY_OPS_W(tx_spec);
Jiri Bence9f207f2007-05-05 11:46:38 -0700159
160static ssize_t key_rx_spec_read(struct file *file, char __user *userbuf,
161 size_t count, loff_t *ppos)
162{
163 struct ieee80211_key *key = file->private_data;
Johannes Berg5a306f52012-11-14 23:22:21 +0100164 char buf[14*IEEE80211_NUM_TIDS+1], *p = buf;
Jiri Bence9f207f2007-05-05 11:46:38 -0700165 int i, len;
166 const u8 *rpn;
167
Johannes Berg97359d12010-08-10 09:46:38 +0200168 switch (key->conf.cipher) {
169 case WLAN_CIPHER_SUITE_WEP40:
170 case WLAN_CIPHER_SUITE_WEP104:
Jiri Bence9f207f2007-05-05 11:46:38 -0700171 len = scnprintf(buf, sizeof(buf), "\n");
Johannes Berg50339a62007-08-28 17:01:52 -0400172 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200173 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg5a306f52012-11-14 23:22:21 +0100174 for (i = 0; i < IEEE80211_NUM_TIDS; i++)
Jiri Bence9f207f2007-05-05 11:46:38 -0700175 p += scnprintf(p, sizeof(buf)+buf-p,
176 "%08x %04x\n",
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700177 key->u.tkip.rx[i].iv32,
178 key->u.tkip.rx[i].iv16);
Jiri Bence9f207f2007-05-05 11:46:38 -0700179 len = p - buf;
Johannes Berg50339a62007-08-28 17:01:52 -0400180 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200181 case WLAN_CIPHER_SUITE_CCMP:
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +0200182 case WLAN_CIPHER_SUITE_CCMP_256:
Johannes Berg5a306f52012-11-14 23:22:21 +0100183 for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) {
Jiri Bence9f207f2007-05-05 11:46:38 -0700184 rpn = key->u.ccmp.rx_pn[i];
185 p += scnprintf(p, sizeof(buf)+buf-p,
186 "%02x%02x%02x%02x%02x%02x\n",
187 rpn[0], rpn[1], rpn[2],
188 rpn[3], rpn[4], rpn[5]);
189 }
190 len = p - buf;
Johannes Berg50339a62007-08-28 17:01:52 -0400191 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200192 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen56c52da2015-01-24 19:52:08 +0200193 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200194 rpn = key->u.aes_cmac.rx_pn;
195 p += scnprintf(p, sizeof(buf)+buf-p,
196 "%02x%02x%02x%02x%02x%02x\n",
197 rpn[0], rpn[1], rpn[2],
198 rpn[3], rpn[4], rpn[5]);
199 len = p - buf;
200 break;
Jouni Malinen8ade5382015-01-24 19:52:09 +0200201 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
202 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
203 rpn = key->u.aes_gmac.rx_pn;
204 p += scnprintf(p, sizeof(buf)+buf-p,
205 "%02x%02x%02x%02x%02x%02x\n",
206 rpn[0], rpn[1], rpn[2],
207 rpn[3], rpn[4], rpn[5]);
208 len = p - buf;
209 break;
Jouni Malinen00b9cfa2015-01-24 19:52:06 +0200210 case WLAN_CIPHER_SUITE_GCMP:
211 case WLAN_CIPHER_SUITE_GCMP_256:
212 for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) {
213 rpn = key->u.gcmp.rx_pn[i];
214 p += scnprintf(p, sizeof(buf)+buf-p,
215 "%02x%02x%02x%02x%02x%02x\n",
216 rpn[0], rpn[1], rpn[2],
217 rpn[3], rpn[4], rpn[5]);
218 }
219 len = p - buf;
220 break;
Jiri Bence9f207f2007-05-05 11:46:38 -0700221 default:
222 return 0;
223 }
224 return simple_read_from_buffer(userbuf, count, ppos, buf, len);
225}
226KEY_OPS(rx_spec);
227
228static ssize_t key_replays_read(struct file *file, char __user *userbuf,
229 size_t count, loff_t *ppos)
230{
231 struct ieee80211_key *key = file->private_data;
232 char buf[20];
233 int len;
234
Johannes Berg97359d12010-08-10 09:46:38 +0200235 switch (key->conf.cipher) {
236 case WLAN_CIPHER_SUITE_CCMP:
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +0200237 case WLAN_CIPHER_SUITE_CCMP_256:
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200238 len = scnprintf(buf, sizeof(buf), "%u\n", key->u.ccmp.replays);
239 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200240 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen56c52da2015-01-24 19:52:08 +0200241 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200242 len = scnprintf(buf, sizeof(buf), "%u\n",
243 key->u.aes_cmac.replays);
244 break;
Jouni Malinen8ade5382015-01-24 19:52:09 +0200245 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
246 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
247 len = scnprintf(buf, sizeof(buf), "%u\n",
248 key->u.aes_gmac.replays);
249 break;
Jouni Malinen00b9cfa2015-01-24 19:52:06 +0200250 case WLAN_CIPHER_SUITE_GCMP:
251 case WLAN_CIPHER_SUITE_GCMP_256:
252 len = scnprintf(buf, sizeof(buf), "%u\n", key->u.gcmp.replays);
253 break;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200254 default:
Jiri Bence9f207f2007-05-05 11:46:38 -0700255 return 0;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200256 }
Jiri Bence9f207f2007-05-05 11:46:38 -0700257 return simple_read_from_buffer(userbuf, count, ppos, buf, len);
258}
259KEY_OPS(replays);
260
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200261static ssize_t key_icverrors_read(struct file *file, char __user *userbuf,
262 size_t count, loff_t *ppos)
263{
264 struct ieee80211_key *key = file->private_data;
265 char buf[20];
266 int len;
267
Johannes Berg97359d12010-08-10 09:46:38 +0200268 switch (key->conf.cipher) {
269 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen56c52da2015-01-24 19:52:08 +0200270 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200271 len = scnprintf(buf, sizeof(buf), "%u\n",
272 key->u.aes_cmac.icverrors);
273 break;
Jouni Malinen8ade5382015-01-24 19:52:09 +0200274 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
275 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
276 len = scnprintf(buf, sizeof(buf), "%u\n",
277 key->u.aes_gmac.icverrors);
278 break;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200279 default:
280 return 0;
281 }
282 return simple_read_from_buffer(userbuf, count, ppos, buf, len);
283}
284KEY_OPS(icverrors);
285
Saravanab98ea052012-12-04 19:47:42 +0530286static ssize_t key_mic_failures_read(struct file *file, char __user *userbuf,
287 size_t count, loff_t *ppos)
288{
289 struct ieee80211_key *key = file->private_data;
290 char buf[20];
291 int len;
292
293 if (key->conf.cipher != WLAN_CIPHER_SUITE_TKIP)
294 return -EINVAL;
295
296 len = scnprintf(buf, sizeof(buf), "%u\n", key->u.tkip.mic_failures);
297
298 return simple_read_from_buffer(userbuf, count, ppos, buf, len);
299}
300KEY_OPS(mic_failures);
301
Jiri Bence9f207f2007-05-05 11:46:38 -0700302static ssize_t key_key_read(struct file *file, char __user *userbuf,
303 size_t count, loff_t *ppos)
304{
305 struct ieee80211_key *key = file->private_data;
Jesper Juhl520efd12010-10-29 16:10:26 +0200306 int i, bufsize = 2 * key->conf.keylen + 2;
Jiri Bence9f207f2007-05-05 11:46:38 -0700307 char *buf = kmalloc(bufsize, GFP_KERNEL);
308 char *p = buf;
Jesper Juhl520efd12010-10-29 16:10:26 +0200309 ssize_t res;
310
311 if (!buf)
312 return -ENOMEM;
Jiri Bence9f207f2007-05-05 11:46:38 -0700313
Johannes Berg8f20fc22007-08-28 17:01:54 -0400314 for (i = 0; i < key->conf.keylen; i++)
315 p += scnprintf(p, bufsize + buf - p, "%02x", key->conf.key[i]);
Jiri Bence9f207f2007-05-05 11:46:38 -0700316 p += scnprintf(p, bufsize+buf-p, "\n");
317 res = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
318 kfree(buf);
319 return res;
320}
321KEY_OPS(key);
322
323#define DEBUGFS_ADD(name) \
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100324 debugfs_create_file(#name, 0400, key->debugfs.dir, \
325 key, &key_##name##_ops);
Johannes Bergd0a77c62015-09-23 10:42:28 +0200326#define DEBUGFS_ADD_W(name) \
327 debugfs_create_file(#name, 0600, key->debugfs.dir, \
328 key, &key_##name##_ops);
Jiri Bence9f207f2007-05-05 11:46:38 -0700329
Johannes Berg3b967662008-04-08 17:56:52 +0200330void ieee80211_debugfs_key_add(struct ieee80211_key *key)
Johannes Berg9446f3e2012-01-17 10:32:01 +0100331{
Johannes Berg50339a62007-08-28 17:01:52 -0400332 static int keycount;
Johannes Berg9446f3e2012-01-17 10:32:01 +0100333 char buf[100];
Johannes Berg3b967662008-04-08 17:56:52 +0200334 struct sta_info *sta;
Jiri Bence9f207f2007-05-05 11:46:38 -0700335
Johannes Berg3b967662008-04-08 17:56:52 +0200336 if (!key->local->debugfs.keys)
Jiri Bence9f207f2007-05-05 11:46:38 -0700337 return;
338
Johannes Berg50339a62007-08-28 17:01:52 -0400339 sprintf(buf, "%d", keycount);
Johannes Bergd9c58f32008-04-08 16:46:36 -0400340 key->debugfs.cnt = keycount;
Johannes Berg50339a62007-08-28 17:01:52 -0400341 keycount++;
Jiri Bence9f207f2007-05-05 11:46:38 -0700342 key->debugfs.dir = debugfs_create_dir(buf,
Johannes Berg3b967662008-04-08 17:56:52 +0200343 key->local->debugfs.keys);
Jiri Bence9f207f2007-05-05 11:46:38 -0700344
345 if (!key->debugfs.dir)
346 return;
347
Johannes Berg40b275b2011-05-13 14:15:49 +0200348 sta = key->sta;
349 if (sta) {
Johannes Berg9446f3e2012-01-17 10:32:01 +0100350 sprintf(buf, "../../netdev:%s/stations/%pM",
351 sta->sdata->name, sta->sta.addr);
Johannes Berg3b967662008-04-08 17:56:52 +0200352 key->debugfs.stalink =
353 debugfs_create_symlink("station", key->debugfs.dir, buf);
Johannes Berg40b275b2011-05-13 14:15:49 +0200354 }
Johannes Berg3b967662008-04-08 17:56:52 +0200355
Jiri Bence9f207f2007-05-05 11:46:38 -0700356 DEBUGFS_ADD(keylen);
Johannes Berg8f20fc22007-08-28 17:01:54 -0400357 DEBUGFS_ADD(flags);
Jiri Bence9f207f2007-05-05 11:46:38 -0700358 DEBUGFS_ADD(keyidx);
359 DEBUGFS_ADD(hw_key_idx);
Jiri Bence9f207f2007-05-05 11:46:38 -0700360 DEBUGFS_ADD(algorithm);
Johannes Bergd0a77c62015-09-23 10:42:28 +0200361 DEBUGFS_ADD_W(tx_spec);
Jiri Bence9f207f2007-05-05 11:46:38 -0700362 DEBUGFS_ADD(rx_spec);
363 DEBUGFS_ADD(replays);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200364 DEBUGFS_ADD(icverrors);
Saravanab98ea052012-12-04 19:47:42 +0530365 DEBUGFS_ADD(mic_failures);
Jiri Bence9f207f2007-05-05 11:46:38 -0700366 DEBUGFS_ADD(key);
Johannes Berge7a64f12007-08-28 17:01:55 -0400367 DEBUGFS_ADD(ifindex);
Jiri Bence9f207f2007-05-05 11:46:38 -0700368};
369
Jiri Bence9f207f2007-05-05 11:46:38 -0700370void ieee80211_debugfs_key_remove(struct ieee80211_key *key)
371{
372 if (!key)
373 return;
374
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100375 debugfs_remove_recursive(key->debugfs.dir);
Jiri Bence9f207f2007-05-05 11:46:38 -0700376 key->debugfs.dir = NULL;
377}
Johannes Bergf7e01042010-12-09 19:49:02 +0100378
379void ieee80211_debugfs_key_update_default(struct ieee80211_sub_if_data *sdata)
Jiri Bence9f207f2007-05-05 11:46:38 -0700380{
381 char buf[50];
Johannes Berg78520ca2008-05-03 01:04:47 +0200382 struct ieee80211_key *key;
Jiri Bence9f207f2007-05-05 11:46:38 -0700383
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100384 if (!sdata->vif.debugfs_dir)
Jiri Bence9f207f2007-05-05 11:46:38 -0700385 return;
386
Johannes Bergf7e01042010-12-09 19:49:02 +0100387 lockdep_assert_held(&sdata->local->key_mtx);
Johannes Berg78520ca2008-05-03 01:04:47 +0200388
Fabian Frederick5c6761a2014-10-21 18:20:12 +0200389 debugfs_remove(sdata->debugfs.default_unicast_key);
390 sdata->debugfs.default_unicast_key = NULL;
Johannes Berg135792e2012-07-05 21:37:05 +0200391
Johannes Bergf7e01042010-12-09 19:49:02 +0100392 if (sdata->default_unicast_key) {
Johannes Berg40b275b2011-05-13 14:15:49 +0200393 key = key_mtx_dereference(sdata->local,
394 sdata->default_unicast_key);
Johannes Berg78520ca2008-05-03 01:04:47 +0200395 sprintf(buf, "../keys/%d", key->debugfs.cnt);
Johannes Bergf7e01042010-12-09 19:49:02 +0100396 sdata->debugfs.default_unicast_key =
397 debugfs_create_symlink("default_unicast_key",
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100398 sdata->vif.debugfs_dir, buf);
Johannes Berg135792e2012-07-05 21:37:05 +0200399 }
400
Fabian Frederick5c6761a2014-10-21 18:20:12 +0200401 debugfs_remove(sdata->debugfs.default_multicast_key);
402 sdata->debugfs.default_multicast_key = NULL;
Johannes Berg78520ca2008-05-03 01:04:47 +0200403
Johannes Bergf7e01042010-12-09 19:49:02 +0100404 if (sdata->default_multicast_key) {
Johannes Berg40b275b2011-05-13 14:15:49 +0200405 key = key_mtx_dereference(sdata->local,
406 sdata->default_multicast_key);
Johannes Bergf7e01042010-12-09 19:49:02 +0100407 sprintf(buf, "../keys/%d", key->debugfs.cnt);
408 sdata->debugfs.default_multicast_key =
409 debugfs_create_symlink("default_multicast_key",
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100410 sdata->vif.debugfs_dir, buf);
Johannes Bergf7e01042010-12-09 19:49:02 +0100411 }
Jiri Bence9f207f2007-05-05 11:46:38 -0700412}
Jiri Bence9f207f2007-05-05 11:46:38 -0700413
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200414void ieee80211_debugfs_key_add_mgmt_default(struct ieee80211_sub_if_data *sdata)
415{
416 char buf[50];
417 struct ieee80211_key *key;
418
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100419 if (!sdata->vif.debugfs_dir)
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200420 return;
421
Johannes Berg40b275b2011-05-13 14:15:49 +0200422 key = key_mtx_dereference(sdata->local,
423 sdata->default_mgmt_key);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200424 if (key) {
425 sprintf(buf, "../keys/%d", key->debugfs.cnt);
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100426 sdata->debugfs.default_mgmt_key =
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200427 debugfs_create_symlink("default_mgmt_key",
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100428 sdata->vif.debugfs_dir, buf);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200429 } else
430 ieee80211_debugfs_key_remove_mgmt_default(sdata);
431}
432
433void ieee80211_debugfs_key_remove_mgmt_default(struct ieee80211_sub_if_data *sdata)
434{
435 if (!sdata)
436 return;
437
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100438 debugfs_remove(sdata->debugfs.default_mgmt_key);
439 sdata->debugfs.default_mgmt_key = NULL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200440}
441
Jiri Bence9f207f2007-05-05 11:46:38 -0700442void ieee80211_debugfs_key_sta_del(struct ieee80211_key *key,
443 struct sta_info *sta)
444{
445 debugfs_remove(key->debugfs.stalink);
446 key->debugfs.stalink = NULL;
447}