Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright 2003-2005	Devicescape Software, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (c) 2006	Jiri Benc <jbenc@suse.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright 2007	Johannes Berg <johannes@sipsolutions.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2015	Intel Deutschland GmbH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/kobject.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "ieee80211_i.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "key.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "debugfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "debugfs_key.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define KEY_READ(name, prop, format_string)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static ssize_t key_##name##_read(struct file *file,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 				 char __user *userbuf,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 				 size_t count, loff_t *ppos)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	struct ieee80211_key *key = file->private_data;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	return mac80211_format_buffer(userbuf, count, ppos, 		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 				      format_string, key->prop);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define KEY_READ_D(name) KEY_READ(name, name, "%d\n")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define KEY_READ_X(name) KEY_READ(name, name, "0x%x\n")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define KEY_OPS(name)							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static const struct file_operations key_ ##name## _ops = {		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	.read = key_##name##_read,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	.open = simple_open,						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	.llseek = generic_file_llseek,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define KEY_OPS_W(name)							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static const struct file_operations key_ ##name## _ops = {		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	.read = key_##name##_read,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	.write = key_##name##_write,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	.open = simple_open,						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	.llseek = generic_file_llseek,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define KEY_FILE(name, format)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		 KEY_READ_##format(name)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		 KEY_OPS(name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define KEY_CONF_READ(name, format_string)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	KEY_READ(conf_##name, conf.name, format_string)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define KEY_CONF_READ_D(name) KEY_CONF_READ(name, "%d\n")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define KEY_CONF_OPS(name)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static const struct file_operations key_ ##name## _ops = {		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	.read = key_conf_##name##_read,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	.open = simple_open,						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	.llseek = generic_file_llseek,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define KEY_CONF_FILE(name, format)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		 KEY_CONF_READ_##format(name)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		 KEY_CONF_OPS(name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) KEY_CONF_FILE(keylen, D);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) KEY_CONF_FILE(keyidx, D);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) KEY_CONF_FILE(hw_key_idx, D);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) KEY_FILE(flags, X);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) KEY_READ(ifindex, sdata->name, "%s\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) KEY_OPS(ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static ssize_t key_algorithm_read(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 				  char __user *userbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 				  size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	char buf[15];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct ieee80211_key *key = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	u32 c = key->conf.cipher;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	sprintf(buf, "%.2x-%.2x-%.2x:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		c >> 24, (c >> 16) & 0xff, (c >> 8) & 0xff, c & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	return simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) KEY_OPS(algorithm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static ssize_t key_tx_spec_write(struct file *file, const char __user *userbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 				 size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct ieee80211_key *key = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	u64 pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	switch (key->conf.cipher) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	case WLAN_CIPHER_SUITE_WEP40:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	case WLAN_CIPHER_SUITE_WEP104:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	case WLAN_CIPHER_SUITE_TKIP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		/* not supported yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	case WLAN_CIPHER_SUITE_CCMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	case WLAN_CIPHER_SUITE_CCMP_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	case WLAN_CIPHER_SUITE_AES_CMAC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	case WLAN_CIPHER_SUITE_BIP_CMAC_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	case WLAN_CIPHER_SUITE_BIP_GMAC_128:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	case WLAN_CIPHER_SUITE_BIP_GMAC_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	case WLAN_CIPHER_SUITE_GCMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	case WLAN_CIPHER_SUITE_GCMP_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		ret = kstrtou64_from_user(userbuf, count, 16, &pn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		/* PN is a 48-bit counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		if (pn >= (1ULL << 48))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		atomic64_set(&key->conf.tx_pn, pn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static ssize_t key_tx_spec_read(struct file *file, char __user *userbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 				size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	u64 pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	char buf[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct ieee80211_key *key = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	switch (key->conf.cipher) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	case WLAN_CIPHER_SUITE_WEP40:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	case WLAN_CIPHER_SUITE_WEP104:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		len = scnprintf(buf, sizeof(buf), "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	case WLAN_CIPHER_SUITE_TKIP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		pn = atomic64_read(&key->conf.tx_pn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		len = scnprintf(buf, sizeof(buf), "%08x %04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 				TKIP_PN_TO_IV32(pn),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 				TKIP_PN_TO_IV16(pn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	case WLAN_CIPHER_SUITE_CCMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	case WLAN_CIPHER_SUITE_CCMP_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	case WLAN_CIPHER_SUITE_AES_CMAC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	case WLAN_CIPHER_SUITE_BIP_CMAC_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	case WLAN_CIPHER_SUITE_BIP_GMAC_128:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	case WLAN_CIPHER_SUITE_BIP_GMAC_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	case WLAN_CIPHER_SUITE_GCMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	case WLAN_CIPHER_SUITE_GCMP_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		pn = atomic64_read(&key->conf.tx_pn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		len = scnprintf(buf, sizeof(buf), "%02x%02x%02x%02x%02x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 				(u8)(pn >> 40), (u8)(pn >> 32), (u8)(pn >> 24),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 				(u8)(pn >> 16), (u8)(pn >> 8), (u8)pn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	return simple_read_from_buffer(userbuf, count, ppos, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) KEY_OPS_W(tx_spec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static ssize_t key_rx_spec_read(struct file *file, char __user *userbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 				size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct ieee80211_key *key = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	char buf[14*IEEE80211_NUM_TIDS+1], *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	int i, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	const u8 *rpn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	switch (key->conf.cipher) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	case WLAN_CIPHER_SUITE_WEP40:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	case WLAN_CIPHER_SUITE_WEP104:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		len = scnprintf(buf, sizeof(buf), "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	case WLAN_CIPHER_SUITE_TKIP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		for (i = 0; i < IEEE80211_NUM_TIDS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			p += scnprintf(p, sizeof(buf)+buf-p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 				       "%08x %04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 				       key->u.tkip.rx[i].iv32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 				       key->u.tkip.rx[i].iv16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		len = p - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	case WLAN_CIPHER_SUITE_CCMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	case WLAN_CIPHER_SUITE_CCMP_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			rpn = key->u.ccmp.rx_pn[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			p += scnprintf(p, sizeof(buf)+buf-p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 				       "%02x%02x%02x%02x%02x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 				       rpn[0], rpn[1], rpn[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 				       rpn[3], rpn[4], rpn[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		len = p - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	case WLAN_CIPHER_SUITE_AES_CMAC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	case WLAN_CIPHER_SUITE_BIP_CMAC_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		rpn = key->u.aes_cmac.rx_pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		p += scnprintf(p, sizeof(buf)+buf-p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			       "%02x%02x%02x%02x%02x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			       rpn[0], rpn[1], rpn[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			       rpn[3], rpn[4], rpn[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		len = p - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	case WLAN_CIPHER_SUITE_BIP_GMAC_128:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	case WLAN_CIPHER_SUITE_BIP_GMAC_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		rpn = key->u.aes_gmac.rx_pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		p += scnprintf(p, sizeof(buf)+buf-p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			       "%02x%02x%02x%02x%02x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			       rpn[0], rpn[1], rpn[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			       rpn[3], rpn[4], rpn[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		len = p - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	case WLAN_CIPHER_SUITE_GCMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	case WLAN_CIPHER_SUITE_GCMP_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			rpn = key->u.gcmp.rx_pn[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			p += scnprintf(p, sizeof(buf)+buf-p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 				       "%02x%02x%02x%02x%02x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 				       rpn[0], rpn[1], rpn[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 				       rpn[3], rpn[4], rpn[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		len = p - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	return simple_read_from_buffer(userbuf, count, ppos, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) KEY_OPS(rx_spec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static ssize_t key_replays_read(struct file *file, char __user *userbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 				size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	struct ieee80211_key *key = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	char buf[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	switch (key->conf.cipher) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	case WLAN_CIPHER_SUITE_CCMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	case WLAN_CIPHER_SUITE_CCMP_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		len = scnprintf(buf, sizeof(buf), "%u\n", key->u.ccmp.replays);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	case WLAN_CIPHER_SUITE_AES_CMAC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	case WLAN_CIPHER_SUITE_BIP_CMAC_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		len = scnprintf(buf, sizeof(buf), "%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 				key->u.aes_cmac.replays);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	case WLAN_CIPHER_SUITE_BIP_GMAC_128:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	case WLAN_CIPHER_SUITE_BIP_GMAC_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		len = scnprintf(buf, sizeof(buf), "%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 				key->u.aes_gmac.replays);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	case WLAN_CIPHER_SUITE_GCMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	case WLAN_CIPHER_SUITE_GCMP_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		len = scnprintf(buf, sizeof(buf), "%u\n", key->u.gcmp.replays);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	return simple_read_from_buffer(userbuf, count, ppos, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) KEY_OPS(replays);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static ssize_t key_icverrors_read(struct file *file, char __user *userbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 				  size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	struct ieee80211_key *key = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	char buf[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	switch (key->conf.cipher) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	case WLAN_CIPHER_SUITE_AES_CMAC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	case WLAN_CIPHER_SUITE_BIP_CMAC_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		len = scnprintf(buf, sizeof(buf), "%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 				key->u.aes_cmac.icverrors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	case WLAN_CIPHER_SUITE_BIP_GMAC_128:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	case WLAN_CIPHER_SUITE_BIP_GMAC_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		len = scnprintf(buf, sizeof(buf), "%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 				key->u.aes_gmac.icverrors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	return simple_read_from_buffer(userbuf, count, ppos, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) KEY_OPS(icverrors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static ssize_t key_mic_failures_read(struct file *file, char __user *userbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 				     size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	struct ieee80211_key *key = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	char buf[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	if (key->conf.cipher != WLAN_CIPHER_SUITE_TKIP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	len = scnprintf(buf, sizeof(buf), "%u\n", key->u.tkip.mic_failures);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	return simple_read_from_buffer(userbuf, count, ppos, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) KEY_OPS(mic_failures);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static ssize_t key_key_read(struct file *file, char __user *userbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			    size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	struct ieee80211_key *key = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	int i, bufsize = 2 * key->conf.keylen + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	char *buf = kmalloc(bufsize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	char *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	ssize_t res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	for (i = 0; i < key->conf.keylen; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		p += scnprintf(p, bufsize + buf - p, "%02x", key->conf.key[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	p += scnprintf(p, bufsize+buf-p, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	res = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) KEY_OPS(key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) #define DEBUGFS_ADD(name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	debugfs_create_file(#name, 0400, key->debugfs.dir, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 			    key, &key_##name##_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) #define DEBUGFS_ADD_W(name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	debugfs_create_file(#name, 0600, key->debugfs.dir, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			    key, &key_##name##_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) void ieee80211_debugfs_key_add(struct ieee80211_key *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	static int keycount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	char buf[100];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	if (!key->local->debugfs.keys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	sprintf(buf, "%d", keycount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	key->debugfs.cnt = keycount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	keycount++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	key->debugfs.dir = debugfs_create_dir(buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 					key->local->debugfs.keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	sta = key->sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	if (sta) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		sprintf(buf, "../../netdev:%s/stations/%pM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			sta->sdata->name, sta->sta.addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		key->debugfs.stalink =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 			debugfs_create_symlink("station", key->debugfs.dir, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	DEBUGFS_ADD(keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	DEBUGFS_ADD(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	DEBUGFS_ADD(keyidx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	DEBUGFS_ADD(hw_key_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	DEBUGFS_ADD(algorithm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	DEBUGFS_ADD_W(tx_spec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	DEBUGFS_ADD(rx_spec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	DEBUGFS_ADD(replays);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	DEBUGFS_ADD(icverrors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	DEBUGFS_ADD(mic_failures);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	DEBUGFS_ADD(key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	DEBUGFS_ADD(ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) void ieee80211_debugfs_key_remove(struct ieee80211_key *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	if (!key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	debugfs_remove_recursive(key->debugfs.dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	key->debugfs.dir = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) void ieee80211_debugfs_key_update_default(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	char buf[50];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	struct ieee80211_key *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	if (!sdata->vif.debugfs_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	lockdep_assert_held(&sdata->local->key_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	debugfs_remove(sdata->debugfs.default_unicast_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	sdata->debugfs.default_unicast_key = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	if (sdata->default_unicast_key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		key = key_mtx_dereference(sdata->local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 					  sdata->default_unicast_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		sprintf(buf, "../keys/%d", key->debugfs.cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		sdata->debugfs.default_unicast_key =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 			debugfs_create_symlink("default_unicast_key",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 					       sdata->vif.debugfs_dir, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	debugfs_remove(sdata->debugfs.default_multicast_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	sdata->debugfs.default_multicast_key = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	if (sdata->default_multicast_key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		key = key_mtx_dereference(sdata->local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 					  sdata->default_multicast_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		sprintf(buf, "../keys/%d", key->debugfs.cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		sdata->debugfs.default_multicast_key =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 			debugfs_create_symlink("default_multicast_key",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 					       sdata->vif.debugfs_dir, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) void ieee80211_debugfs_key_add_mgmt_default(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	char buf[50];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	struct ieee80211_key *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	if (!sdata->vif.debugfs_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	key = key_mtx_dereference(sdata->local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 				  sdata->default_mgmt_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	if (key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		sprintf(buf, "../keys/%d", key->debugfs.cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		sdata->debugfs.default_mgmt_key =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 			debugfs_create_symlink("default_mgmt_key",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 					       sdata->vif.debugfs_dir, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		ieee80211_debugfs_key_remove_mgmt_default(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) void ieee80211_debugfs_key_remove_mgmt_default(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	if (!sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	debugfs_remove(sdata->debugfs.default_mgmt_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	sdata->debugfs.default_mgmt_key = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) ieee80211_debugfs_key_add_beacon_default(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	char buf[50];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	struct ieee80211_key *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	if (!sdata->vif.debugfs_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	key = key_mtx_dereference(sdata->local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 				  sdata->default_beacon_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	if (key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		sprintf(buf, "../keys/%d", key->debugfs.cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		sdata->debugfs.default_beacon_key =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 			debugfs_create_symlink("default_beacon_key",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 					       sdata->vif.debugfs_dir, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		ieee80211_debugfs_key_remove_beacon_default(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) ieee80211_debugfs_key_remove_beacon_default(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	if (!sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	debugfs_remove(sdata->debugfs.default_beacon_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	sdata->debugfs.default_beacon_key = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) void ieee80211_debugfs_key_sta_del(struct ieee80211_key *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 				   struct sta_info *sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	debugfs_remove(key->debugfs.stalink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	key->debugfs.stalink = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }