xref: /openbmc/linux/net/mac80211/debugfs_key.c (revision 00b9cfa3)
1e9f207f0SJiri Benc /*
2e9f207f0SJiri Benc  * Copyright 2003-2005	Devicescape Software, Inc.
3e9f207f0SJiri Benc  * Copyright (c) 2006	Jiri Benc <jbenc@suse.cz>
4e9f207f0SJiri Benc  * Copyright 2007	Johannes Berg <johannes@sipsolutions.net>
5e9f207f0SJiri Benc  *
6e9f207f0SJiri Benc  * This program is free software; you can redistribute it and/or modify
7e9f207f0SJiri Benc  * it under the terms of the GNU General Public License version 2 as
8e9f207f0SJiri Benc  * published by the Free Software Foundation.
9e9f207f0SJiri Benc  */
10e9f207f0SJiri Benc 
11e9f207f0SJiri Benc #include <linux/kobject.h>
125a0e3ad6STejun Heo #include <linux/slab.h>
13e9f207f0SJiri Benc #include "ieee80211_i.h"
142c8dccc7SJohannes Berg #include "key.h"
15e9f207f0SJiri Benc #include "debugfs.h"
16e9f207f0SJiri Benc #include "debugfs_key.h"
17e9f207f0SJiri Benc 
1807caf9d6SEliad Peller #define KEY_READ(name, prop, format_string)				\
19e9f207f0SJiri Benc static ssize_t key_##name##_read(struct file *file,			\
20e9f207f0SJiri Benc 				 char __user *userbuf,			\
21e9f207f0SJiri Benc 				 size_t count, loff_t *ppos)		\
22e9f207f0SJiri Benc {									\
23e9f207f0SJiri Benc 	struct ieee80211_key *key = file->private_data;			\
2407caf9d6SEliad Peller 	return mac80211_format_buffer(userbuf, count, ppos, 		\
2507caf9d6SEliad Peller 				      format_string, key->prop);	\
26e9f207f0SJiri Benc }
2707caf9d6SEliad Peller #define KEY_READ_D(name) KEY_READ(name, name, "%d\n")
2807caf9d6SEliad Peller #define KEY_READ_X(name) KEY_READ(name, name, "0x%x\n")
29e9f207f0SJiri Benc 
30e9f207f0SJiri Benc #define KEY_OPS(name)							\
31e9f207f0SJiri Benc static const struct file_operations key_ ##name## _ops = {		\
32e9f207f0SJiri Benc 	.read = key_##name##_read,					\
33234e3405SStephen Boyd 	.open = simple_open,						\
342b18ab36SArnd Bergmann 	.llseek = generic_file_llseek,					\
35e9f207f0SJiri Benc }
36e9f207f0SJiri Benc 
37e9f207f0SJiri Benc #define KEY_FILE(name, format)						\
38e9f207f0SJiri Benc 		 KEY_READ_##format(name)				\
39e9f207f0SJiri Benc 		 KEY_OPS(name)
40e9f207f0SJiri Benc 
4107caf9d6SEliad Peller #define KEY_CONF_READ(name, format_string)				\
4207caf9d6SEliad Peller 	KEY_READ(conf_##name, conf.name, format_string)
4307caf9d6SEliad Peller #define KEY_CONF_READ_D(name) KEY_CONF_READ(name, "%d\n")
448f20fc24SJohannes Berg 
458f20fc24SJohannes Berg #define KEY_CONF_OPS(name)						\
468f20fc24SJohannes Berg static const struct file_operations key_ ##name## _ops = {		\
478f20fc24SJohannes Berg 	.read = key_conf_##name##_read,					\
48234e3405SStephen Boyd 	.open = simple_open,						\
492b18ab36SArnd Bergmann 	.llseek = generic_file_llseek,					\
508f20fc24SJohannes Berg }
518f20fc24SJohannes Berg 
528f20fc24SJohannes Berg #define KEY_CONF_FILE(name, format)					\
538f20fc24SJohannes Berg 		 KEY_CONF_READ_##format(name)				\
548f20fc24SJohannes Berg 		 KEY_CONF_OPS(name)
558f20fc24SJohannes Berg 
568f20fc24SJohannes Berg KEY_CONF_FILE(keylen, D);
578f20fc24SJohannes Berg KEY_CONF_FILE(keyidx, D);
588f20fc24SJohannes Berg KEY_CONF_FILE(hw_key_idx, D);
5911a843b7SJohannes Berg KEY_FILE(flags, X);
60e9f207f0SJiri Benc KEY_FILE(tx_rx_count, D);
6107caf9d6SEliad Peller KEY_READ(ifindex, sdata->name, "%s\n");
62e7a64f12SJohannes Berg KEY_OPS(ifindex);
63e9f207f0SJiri Benc 
64e9f207f0SJiri Benc static ssize_t key_algorithm_read(struct file *file,
65e9f207f0SJiri Benc 				  char __user *userbuf,
66e9f207f0SJiri Benc 				  size_t count, loff_t *ppos)
67e9f207f0SJiri Benc {
6897359d12SJohannes Berg 	char buf[15];
69e9f207f0SJiri Benc 	struct ieee80211_key *key = file->private_data;
7097359d12SJohannes Berg 	u32 c = key->conf.cipher;
71e9f207f0SJiri Benc 
7297359d12SJohannes Berg 	sprintf(buf, "%.2x-%.2x-%.2x:%d\n",
7397359d12SJohannes Berg 		c >> 24, (c >> 16) & 0xff, (c >> 8) & 0xff, c & 0xff);
7497359d12SJohannes Berg 	return simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
75e9f207f0SJiri Benc }
76e9f207f0SJiri Benc KEY_OPS(algorithm);
77e9f207f0SJiri Benc 
78e9f207f0SJiri Benc static ssize_t key_tx_spec_read(struct file *file, char __user *userbuf,
79e9f207f0SJiri Benc 				size_t count, loff_t *ppos)
80e9f207f0SJiri Benc {
81aba83a0bSJohannes Berg 	u64 pn;
82e9f207f0SJiri Benc 	char buf[20];
83e9f207f0SJiri Benc 	int len;
84e9f207f0SJiri Benc 	struct ieee80211_key *key = file->private_data;
85e9f207f0SJiri Benc 
8697359d12SJohannes Berg 	switch (key->conf.cipher) {
8797359d12SJohannes Berg 	case WLAN_CIPHER_SUITE_WEP40:
8897359d12SJohannes Berg 	case WLAN_CIPHER_SUITE_WEP104:
89e9f207f0SJiri Benc 		len = scnprintf(buf, sizeof(buf), "\n");
9050339a67SJohannes Berg 		break;
9197359d12SJohannes Berg 	case WLAN_CIPHER_SUITE_TKIP:
92e9f207f0SJiri Benc 		len = scnprintf(buf, sizeof(buf), "%08x %04x\n",
93b0f76b33SHarvey Harrison 				key->u.tkip.tx.iv32,
94b0f76b33SHarvey Harrison 				key->u.tkip.tx.iv16);
9550339a67SJohannes Berg 		break;
9697359d12SJohannes Berg 	case WLAN_CIPHER_SUITE_CCMP:
97aba83a0bSJohannes Berg 		pn = atomic64_read(&key->u.ccmp.tx_pn);
98e9f207f0SJiri Benc 		len = scnprintf(buf, sizeof(buf), "%02x%02x%02x%02x%02x%02x\n",
99aba83a0bSJohannes Berg 				(u8)(pn >> 40), (u8)(pn >> 32), (u8)(pn >> 24),
100aba83a0bSJohannes Berg 				(u8)(pn >> 16), (u8)(pn >> 8), (u8)pn);
10150339a67SJohannes Berg 		break;
10297359d12SJohannes Berg 	case WLAN_CIPHER_SUITE_AES_CMAC:
10375396ae6SJohannes Berg 		pn = atomic64_read(&key->u.aes_cmac.tx_pn);
1043cfcf6acSJouni Malinen 		len = scnprintf(buf, sizeof(buf), "%02x%02x%02x%02x%02x%02x\n",
10575396ae6SJohannes Berg 				(u8)(pn >> 40), (u8)(pn >> 32), (u8)(pn >> 24),
10675396ae6SJohannes Berg 				(u8)(pn >> 16), (u8)(pn >> 8), (u8)pn);
1073cfcf6acSJouni Malinen 		break;
10800b9cfa3SJouni Malinen 	case WLAN_CIPHER_SUITE_GCMP:
10900b9cfa3SJouni Malinen 	case WLAN_CIPHER_SUITE_GCMP_256:
11000b9cfa3SJouni Malinen 		pn = atomic64_read(&key->u.gcmp.tx_pn);
11100b9cfa3SJouni Malinen 		len = scnprintf(buf, sizeof(buf), "%02x%02x%02x%02x%02x%02x\n",
11200b9cfa3SJouni Malinen 				(u8)(pn >> 40), (u8)(pn >> 32), (u8)(pn >> 24),
11300b9cfa3SJouni Malinen 				(u8)(pn >> 16), (u8)(pn >> 8), (u8)pn);
11400b9cfa3SJouni Malinen 		break;
115e9f207f0SJiri Benc 	default:
116e9f207f0SJiri Benc 		return 0;
117e9f207f0SJiri Benc 	}
118e9f207f0SJiri Benc 	return simple_read_from_buffer(userbuf, count, ppos, buf, len);
119e9f207f0SJiri Benc }
120e9f207f0SJiri Benc KEY_OPS(tx_spec);
121e9f207f0SJiri Benc 
122e9f207f0SJiri Benc static ssize_t key_rx_spec_read(struct file *file, char __user *userbuf,
123e9f207f0SJiri Benc 				size_t count, loff_t *ppos)
124e9f207f0SJiri Benc {
125e9f207f0SJiri Benc 	struct ieee80211_key *key = file->private_data;
1265a306f58SJohannes Berg 	char buf[14*IEEE80211_NUM_TIDS+1], *p = buf;
127e9f207f0SJiri Benc 	int i, len;
128e9f207f0SJiri Benc 	const u8 *rpn;
129e9f207f0SJiri Benc 
13097359d12SJohannes Berg 	switch (key->conf.cipher) {
13197359d12SJohannes Berg 	case WLAN_CIPHER_SUITE_WEP40:
13297359d12SJohannes Berg 	case WLAN_CIPHER_SUITE_WEP104:
133e9f207f0SJiri Benc 		len = scnprintf(buf, sizeof(buf), "\n");
13450339a67SJohannes Berg 		break;
13597359d12SJohannes Berg 	case WLAN_CIPHER_SUITE_TKIP:
1365a306f58SJohannes Berg 		for (i = 0; i < IEEE80211_NUM_TIDS; i++)
137e9f207f0SJiri Benc 			p += scnprintf(p, sizeof(buf)+buf-p,
138e9f207f0SJiri Benc 				       "%08x %04x\n",
139b0f76b33SHarvey Harrison 				       key->u.tkip.rx[i].iv32,
140b0f76b33SHarvey Harrison 				       key->u.tkip.rx[i].iv16);
141e9f207f0SJiri Benc 		len = p - buf;
14250339a67SJohannes Berg 		break;
14397359d12SJohannes Berg 	case WLAN_CIPHER_SUITE_CCMP:
1445a306f58SJohannes Berg 		for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) {
145e9f207f0SJiri Benc 			rpn = key->u.ccmp.rx_pn[i];
146e9f207f0SJiri Benc 			p += scnprintf(p, sizeof(buf)+buf-p,
147e9f207f0SJiri Benc 				       "%02x%02x%02x%02x%02x%02x\n",
148e9f207f0SJiri Benc 				       rpn[0], rpn[1], rpn[2],
149e9f207f0SJiri Benc 				       rpn[3], rpn[4], rpn[5]);
150e9f207f0SJiri Benc 		}
151e9f207f0SJiri Benc 		len = p - buf;
15250339a67SJohannes Berg 		break;
15397359d12SJohannes Berg 	case WLAN_CIPHER_SUITE_AES_CMAC:
1543cfcf6acSJouni Malinen 		rpn = key->u.aes_cmac.rx_pn;
1553cfcf6acSJouni Malinen 		p += scnprintf(p, sizeof(buf)+buf-p,
1563cfcf6acSJouni Malinen 			       "%02x%02x%02x%02x%02x%02x\n",
1573cfcf6acSJouni Malinen 			       rpn[0], rpn[1], rpn[2],
1583cfcf6acSJouni Malinen 			       rpn[3], rpn[4], rpn[5]);
1593cfcf6acSJouni Malinen 		len = p - buf;
1603cfcf6acSJouni Malinen 		break;
16100b9cfa3SJouni Malinen 	case WLAN_CIPHER_SUITE_GCMP:
16200b9cfa3SJouni Malinen 	case WLAN_CIPHER_SUITE_GCMP_256:
16300b9cfa3SJouni Malinen 		for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) {
16400b9cfa3SJouni Malinen 			rpn = key->u.gcmp.rx_pn[i];
16500b9cfa3SJouni Malinen 			p += scnprintf(p, sizeof(buf)+buf-p,
16600b9cfa3SJouni Malinen 				       "%02x%02x%02x%02x%02x%02x\n",
16700b9cfa3SJouni Malinen 				       rpn[0], rpn[1], rpn[2],
16800b9cfa3SJouni Malinen 				       rpn[3], rpn[4], rpn[5]);
16900b9cfa3SJouni Malinen 		}
17000b9cfa3SJouni Malinen 		len = p - buf;
17100b9cfa3SJouni Malinen 		break;
172e9f207f0SJiri Benc 	default:
173e9f207f0SJiri Benc 		return 0;
174e9f207f0SJiri Benc 	}
175e9f207f0SJiri Benc 	return simple_read_from_buffer(userbuf, count, ppos, buf, len);
176e9f207f0SJiri Benc }
177e9f207f0SJiri Benc KEY_OPS(rx_spec);
178e9f207f0SJiri Benc 
179e9f207f0SJiri Benc static ssize_t key_replays_read(struct file *file, char __user *userbuf,
180e9f207f0SJiri Benc 				size_t count, loff_t *ppos)
181e9f207f0SJiri Benc {
182e9f207f0SJiri Benc 	struct ieee80211_key *key = file->private_data;
183e9f207f0SJiri Benc 	char buf[20];
184e9f207f0SJiri Benc 	int len;
185e9f207f0SJiri Benc 
18697359d12SJohannes Berg 	switch (key->conf.cipher) {
18797359d12SJohannes Berg 	case WLAN_CIPHER_SUITE_CCMP:
188e9f207f0SJiri Benc 		len = scnprintf(buf, sizeof(buf), "%u\n", key->u.ccmp.replays);
1893cfcf6acSJouni Malinen 		break;
19097359d12SJohannes Berg 	case WLAN_CIPHER_SUITE_AES_CMAC:
1913cfcf6acSJouni Malinen 		len = scnprintf(buf, sizeof(buf), "%u\n",
1923cfcf6acSJouni Malinen 				key->u.aes_cmac.replays);
1933cfcf6acSJouni Malinen 		break;
19400b9cfa3SJouni Malinen 	case WLAN_CIPHER_SUITE_GCMP:
19500b9cfa3SJouni Malinen 	case WLAN_CIPHER_SUITE_GCMP_256:
19600b9cfa3SJouni Malinen 		len = scnprintf(buf, sizeof(buf), "%u\n", key->u.gcmp.replays);
19700b9cfa3SJouni Malinen 		break;
1983cfcf6acSJouni Malinen 	default:
1993cfcf6acSJouni Malinen 		return 0;
2003cfcf6acSJouni Malinen 	}
201e9f207f0SJiri Benc 	return simple_read_from_buffer(userbuf, count, ppos, buf, len);
202e9f207f0SJiri Benc }
203e9f207f0SJiri Benc KEY_OPS(replays);
204e9f207f0SJiri Benc 
2053cfcf6acSJouni Malinen static ssize_t key_icverrors_read(struct file *file, char __user *userbuf,
2063cfcf6acSJouni Malinen 				  size_t count, loff_t *ppos)
2073cfcf6acSJouni Malinen {
2083cfcf6acSJouni Malinen 	struct ieee80211_key *key = file->private_data;
2093cfcf6acSJouni Malinen 	char buf[20];
2103cfcf6acSJouni Malinen 	int len;
2113cfcf6acSJouni Malinen 
21297359d12SJohannes Berg 	switch (key->conf.cipher) {
21397359d12SJohannes Berg 	case WLAN_CIPHER_SUITE_AES_CMAC:
2143cfcf6acSJouni Malinen 		len = scnprintf(buf, sizeof(buf), "%u\n",
2153cfcf6acSJouni Malinen 				key->u.aes_cmac.icverrors);
2163cfcf6acSJouni Malinen 		break;
2173cfcf6acSJouni Malinen 	default:
2183cfcf6acSJouni Malinen 		return 0;
2193cfcf6acSJouni Malinen 	}
2203cfcf6acSJouni Malinen 	return simple_read_from_buffer(userbuf, count, ppos, buf, len);
2213cfcf6acSJouni Malinen }
2223cfcf6acSJouni Malinen KEY_OPS(icverrors);
2233cfcf6acSJouni Malinen 
224b98ea058SSaravana static ssize_t key_mic_failures_read(struct file *file, char __user *userbuf,
225b98ea058SSaravana 				     size_t count, loff_t *ppos)
226b98ea058SSaravana {
227b98ea058SSaravana 	struct ieee80211_key *key = file->private_data;
228b98ea058SSaravana 	char buf[20];
229b98ea058SSaravana 	int len;
230b98ea058SSaravana 
231b98ea058SSaravana 	if (key->conf.cipher != WLAN_CIPHER_SUITE_TKIP)
232b98ea058SSaravana 		return -EINVAL;
233b98ea058SSaravana 
234b98ea058SSaravana 	len = scnprintf(buf, sizeof(buf), "%u\n", key->u.tkip.mic_failures);
235b98ea058SSaravana 
236b98ea058SSaravana 	return simple_read_from_buffer(userbuf, count, ppos, buf, len);
237b98ea058SSaravana }
238b98ea058SSaravana KEY_OPS(mic_failures);
239b98ea058SSaravana 
240e9f207f0SJiri Benc static ssize_t key_key_read(struct file *file, char __user *userbuf,
241e9f207f0SJiri Benc 			    size_t count, loff_t *ppos)
242e9f207f0SJiri Benc {
243e9f207f0SJiri Benc 	struct ieee80211_key *key = file->private_data;
244520efd1aSJesper Juhl 	int i, bufsize = 2 * key->conf.keylen + 2;
245e9f207f0SJiri Benc 	char *buf = kmalloc(bufsize, GFP_KERNEL);
246e9f207f0SJiri Benc 	char *p = buf;
247520efd1aSJesper Juhl 	ssize_t res;
248520efd1aSJesper Juhl 
249520efd1aSJesper Juhl 	if (!buf)
250520efd1aSJesper Juhl 		return -ENOMEM;
251e9f207f0SJiri Benc 
2528f20fc24SJohannes Berg 	for (i = 0; i < key->conf.keylen; i++)
2538f20fc24SJohannes Berg 		p += scnprintf(p, bufsize + buf - p, "%02x", key->conf.key[i]);
254e9f207f0SJiri Benc 	p += scnprintf(p, bufsize+buf-p, "\n");
255e9f207f0SJiri Benc 	res = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
256e9f207f0SJiri Benc 	kfree(buf);
257e9f207f0SJiri Benc 	return res;
258e9f207f0SJiri Benc }
259e9f207f0SJiri Benc KEY_OPS(key);
260e9f207f0SJiri Benc 
261e9f207f0SJiri Benc #define DEBUGFS_ADD(name) \
2627bcfaf2fSJohannes Berg 	debugfs_create_file(#name, 0400, key->debugfs.dir, \
2637bcfaf2fSJohannes Berg 			    key, &key_##name##_ops);
264e9f207f0SJiri Benc 
2653b96766fSJohannes Berg void ieee80211_debugfs_key_add(struct ieee80211_key *key)
266e9f207f0SJiri Benc {
26750339a67SJohannes Berg 	static int keycount;
2689446f3efSJohannes Berg 	char buf[100];
2693b96766fSJohannes Berg 	struct sta_info *sta;
270e9f207f0SJiri Benc 
2713b96766fSJohannes Berg 	if (!key->local->debugfs.keys)
272e9f207f0SJiri Benc 		return;
273e9f207f0SJiri Benc 
27450339a67SJohannes Berg 	sprintf(buf, "%d", keycount);
275d9c58f30SJohannes Berg 	key->debugfs.cnt = keycount;
27650339a67SJohannes Berg 	keycount++;
277e9f207f0SJiri Benc 	key->debugfs.dir = debugfs_create_dir(buf,
2783b96766fSJohannes Berg 					key->local->debugfs.keys);
279e9f207f0SJiri Benc 
280e9f207f0SJiri Benc 	if (!key->debugfs.dir)
281e9f207f0SJiri Benc 		return;
282e9f207f0SJiri Benc 
28340b275b6SJohannes Berg 	sta = key->sta;
28440b275b6SJohannes Berg 	if (sta) {
2859446f3efSJohannes Berg 		sprintf(buf, "../../netdev:%s/stations/%pM",
2869446f3efSJohannes Berg 			sta->sdata->name, sta->sta.addr);
2873b96766fSJohannes Berg 		key->debugfs.stalink =
2883b96766fSJohannes Berg 			debugfs_create_symlink("station", key->debugfs.dir, buf);
28940b275b6SJohannes Berg 	}
2903b96766fSJohannes Berg 
291e9f207f0SJiri Benc 	DEBUGFS_ADD(keylen);
2928f20fc24SJohannes Berg 	DEBUGFS_ADD(flags);
293e9f207f0SJiri Benc 	DEBUGFS_ADD(keyidx);
294e9f207f0SJiri Benc 	DEBUGFS_ADD(hw_key_idx);
295e9f207f0SJiri Benc 	DEBUGFS_ADD(tx_rx_count);
296e9f207f0SJiri Benc 	DEBUGFS_ADD(algorithm);
297e9f207f0SJiri Benc 	DEBUGFS_ADD(tx_spec);
298e9f207f0SJiri Benc 	DEBUGFS_ADD(rx_spec);
299e9f207f0SJiri Benc 	DEBUGFS_ADD(replays);
3003cfcf6acSJouni Malinen 	DEBUGFS_ADD(icverrors);
301b98ea058SSaravana 	DEBUGFS_ADD(mic_failures);
302e9f207f0SJiri Benc 	DEBUGFS_ADD(key);
303e7a64f12SJohannes Berg 	DEBUGFS_ADD(ifindex);
304e9f207f0SJiri Benc };
305e9f207f0SJiri Benc 
306e9f207f0SJiri Benc void ieee80211_debugfs_key_remove(struct ieee80211_key *key)
307e9f207f0SJiri Benc {
308e9f207f0SJiri Benc 	if (!key)
309e9f207f0SJiri Benc 		return;
310e9f207f0SJiri Benc 
3117bcfaf2fSJohannes Berg 	debugfs_remove_recursive(key->debugfs.dir);
312e9f207f0SJiri Benc 	key->debugfs.dir = NULL;
313e9f207f0SJiri Benc }
314f7e0104cSJohannes Berg 
315f7e0104cSJohannes Berg void ieee80211_debugfs_key_update_default(struct ieee80211_sub_if_data *sdata)
316e9f207f0SJiri Benc {
317e9f207f0SJiri Benc 	char buf[50];
31878520cadSJohannes Berg 	struct ieee80211_key *key;
319e9f207f0SJiri Benc 
320ddbfe860SStanislaw Gruszka 	if (!sdata->vif.debugfs_dir)
321e9f207f0SJiri Benc 		return;
322e9f207f0SJiri Benc 
323f7e0104cSJohannes Berg 	lockdep_assert_held(&sdata->local->key_mtx);
32478520cadSJohannes Berg 
325135792ecSJohannes Berg 	debugfs_remove(sdata->debugfs.default_unicast_key);
326135792ecSJohannes Berg 	sdata->debugfs.default_unicast_key = NULL;
327135792ecSJohannes Berg 
328f7e0104cSJohannes Berg 	if (sdata->default_unicast_key) {
32940b275b6SJohannes Berg 		key = key_mtx_dereference(sdata->local,
33040b275b6SJohannes Berg 					  sdata->default_unicast_key);
33178520cadSJohannes Berg 		sprintf(buf, "../keys/%d", key->debugfs.cnt);
332f7e0104cSJohannes Berg 		sdata->debugfs.default_unicast_key =
333f7e0104cSJohannes Berg 			debugfs_create_symlink("default_unicast_key",
334ddbfe860SStanislaw Gruszka 					       sdata->vif.debugfs_dir, buf);
335135792ecSJohannes Berg 	}
336135792ecSJohannes Berg 
337135792ecSJohannes Berg 	debugfs_remove(sdata->debugfs.default_multicast_key);
338135792ecSJohannes Berg 	sdata->debugfs.default_multicast_key = NULL;
33978520cadSJohannes Berg 
340f7e0104cSJohannes Berg 	if (sdata->default_multicast_key) {
34140b275b6SJohannes Berg 		key = key_mtx_dereference(sdata->local,
34240b275b6SJohannes Berg 					  sdata->default_multicast_key);
343f7e0104cSJohannes Berg 		sprintf(buf, "../keys/%d", key->debugfs.cnt);
344f7e0104cSJohannes Berg 		sdata->debugfs.default_multicast_key =
345f7e0104cSJohannes Berg 			debugfs_create_symlink("default_multicast_key",
346ddbfe860SStanislaw Gruszka 					       sdata->vif.debugfs_dir, buf);
347f7e0104cSJohannes Berg 	}
348e9f207f0SJiri Benc }
349e9f207f0SJiri Benc 
3503cfcf6acSJouni Malinen void ieee80211_debugfs_key_add_mgmt_default(struct ieee80211_sub_if_data *sdata)
3513cfcf6acSJouni Malinen {
3523cfcf6acSJouni Malinen 	char buf[50];
3533cfcf6acSJouni Malinen 	struct ieee80211_key *key;
3543cfcf6acSJouni Malinen 
355ddbfe860SStanislaw Gruszka 	if (!sdata->vif.debugfs_dir)
3563cfcf6acSJouni Malinen 		return;
3573cfcf6acSJouni Malinen 
35840b275b6SJohannes Berg 	key = key_mtx_dereference(sdata->local,
35940b275b6SJohannes Berg 				  sdata->default_mgmt_key);
3603cfcf6acSJouni Malinen 	if (key) {
3613cfcf6acSJouni Malinen 		sprintf(buf, "../keys/%d", key->debugfs.cnt);
3627bcfaf2fSJohannes Berg 		sdata->debugfs.default_mgmt_key =
3633cfcf6acSJouni Malinen 			debugfs_create_symlink("default_mgmt_key",
364ddbfe860SStanislaw Gruszka 					       sdata->vif.debugfs_dir, buf);
3653cfcf6acSJouni Malinen 	} else
3663cfcf6acSJouni Malinen 		ieee80211_debugfs_key_remove_mgmt_default(sdata);
3673cfcf6acSJouni Malinen }
3683cfcf6acSJouni Malinen 
3693cfcf6acSJouni Malinen void ieee80211_debugfs_key_remove_mgmt_default(struct ieee80211_sub_if_data *sdata)
3703cfcf6acSJouni Malinen {
3713cfcf6acSJouni Malinen 	if (!sdata)
3723cfcf6acSJouni Malinen 		return;
3733cfcf6acSJouni Malinen 
3747bcfaf2fSJohannes Berg 	debugfs_remove(sdata->debugfs.default_mgmt_key);
3757bcfaf2fSJohannes Berg 	sdata->debugfs.default_mgmt_key = NULL;
3763cfcf6acSJouni Malinen }
3773cfcf6acSJouni Malinen 
378e9f207f0SJiri Benc void ieee80211_debugfs_key_sta_del(struct ieee80211_key *key,
379e9f207f0SJiri Benc 				   struct sta_info *sta)
380e9f207f0SJiri Benc {
381e9f207f0SJiri Benc 	debugfs_remove(key->debugfs.stalink);
382e9f207f0SJiri Benc 	key->debugfs.stalink = NULL;
383e9f207f0SJiri Benc }
384