Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2003-2005 Devicescape Software, Inc. |
| 3 | * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz> |
| 4 | * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/kobject.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 13 | #include "ieee80211_i.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 14 | #include "key.h" |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 15 | #include "debugfs.h" |
| 16 | #include "debugfs_key.h" |
| 17 | |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 18 | #define KEY_READ(name, prop, format_string) \ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 19 | static ssize_t key_##name##_read(struct file *file, \ |
| 20 | char __user *userbuf, \ |
| 21 | size_t count, loff_t *ppos) \ |
| 22 | { \ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 23 | struct ieee80211_key *key = file->private_data; \ |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 24 | return mac80211_format_buffer(userbuf, count, ppos, \ |
| 25 | format_string, key->prop); \ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 26 | } |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 27 | #define KEY_READ_D(name) KEY_READ(name, name, "%d\n") |
| 28 | #define KEY_READ_X(name) KEY_READ(name, name, "0x%x\n") |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 29 | |
| 30 | #define KEY_OPS(name) \ |
| 31 | static const struct file_operations key_ ##name## _ops = { \ |
| 32 | .read = key_##name##_read, \ |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 33 | .open = simple_open, \ |
Arnd Bergmann | 2b18ab36 | 2010-07-06 19:05:31 +0200 | [diff] [blame] | 34 | .llseek = generic_file_llseek, \ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | #define KEY_FILE(name, format) \ |
| 38 | KEY_READ_##format(name) \ |
| 39 | KEY_OPS(name) |
| 40 | |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 41 | #define KEY_CONF_READ(name, format_string) \ |
| 42 | KEY_READ(conf_##name, conf.name, format_string) |
| 43 | #define KEY_CONF_READ_D(name) KEY_CONF_READ(name, "%d\n") |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 44 | |
| 45 | #define KEY_CONF_OPS(name) \ |
| 46 | static const struct file_operations key_ ##name## _ops = { \ |
| 47 | .read = key_conf_##name##_read, \ |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 48 | .open = simple_open, \ |
Arnd Bergmann | 2b18ab36 | 2010-07-06 19:05:31 +0200 | [diff] [blame] | 49 | .llseek = generic_file_llseek, \ |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | #define KEY_CONF_FILE(name, format) \ |
| 53 | KEY_CONF_READ_##format(name) \ |
| 54 | KEY_CONF_OPS(name) |
| 55 | |
| 56 | KEY_CONF_FILE(keylen, D); |
| 57 | KEY_CONF_FILE(keyidx, D); |
| 58 | KEY_CONF_FILE(hw_key_idx, D); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 59 | KEY_FILE(flags, X); |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 60 | KEY_READ(ifindex, sdata->name, "%s\n"); |
Johannes Berg | e7a64f1 | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 61 | KEY_OPS(ifindex); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 62 | |
| 63 | static ssize_t key_algorithm_read(struct file *file, |
| 64 | char __user *userbuf, |
| 65 | size_t count, loff_t *ppos) |
| 66 | { |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 67 | char buf[15]; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 68 | struct ieee80211_key *key = file->private_data; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 69 | u32 c = key->conf.cipher; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 70 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 71 | sprintf(buf, "%.2x-%.2x-%.2x:%d\n", |
| 72 | c >> 24, (c >> 16) & 0xff, (c >> 8) & 0xff, c & 0xff); |
| 73 | return simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf)); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 74 | } |
| 75 | KEY_OPS(algorithm); |
| 76 | |
| 77 | static ssize_t key_tx_spec_read(struct file *file, char __user *userbuf, |
| 78 | size_t count, loff_t *ppos) |
| 79 | { |
Johannes Berg | aba83a0b | 2011-07-06 21:59:39 +0200 | [diff] [blame] | 80 | u64 pn; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 81 | char buf[20]; |
| 82 | int len; |
| 83 | struct ieee80211_key *key = file->private_data; |
| 84 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 85 | switch (key->conf.cipher) { |
| 86 | case WLAN_CIPHER_SUITE_WEP40: |
| 87 | case WLAN_CIPHER_SUITE_WEP104: |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 88 | len = scnprintf(buf, sizeof(buf), "\n"); |
Johannes Berg | 50339a6 | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 89 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 90 | case WLAN_CIPHER_SUITE_TKIP: |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 91 | len = scnprintf(buf, sizeof(buf), "%08x %04x\n", |
Harvey Harrison | b0f76b3 | 2008-05-14 16:26:19 -0700 | [diff] [blame] | 92 | key->u.tkip.tx.iv32, |
| 93 | key->u.tkip.tx.iv16); |
Johannes Berg | 50339a6 | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 94 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 95 | case WLAN_CIPHER_SUITE_CCMP: |
Jouni Malinen | 2b2ba0d | 2015-01-24 19:52:07 +0200 | [diff] [blame] | 96 | case WLAN_CIPHER_SUITE_CCMP_256: |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 97 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Jouni Malinen | 56c52da | 2015-01-24 19:52:08 +0200 | [diff] [blame] | 98 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
Jouni Malinen | 8ade538 | 2015-01-24 19:52:09 +0200 | [diff] [blame] | 99 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 100 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
Jouni Malinen | 00b9cfa | 2015-01-24 19:52:06 +0200 | [diff] [blame] | 101 | case WLAN_CIPHER_SUITE_GCMP: |
| 102 | case WLAN_CIPHER_SUITE_GCMP_256: |
Johannes Berg | db388a5 | 2015-06-01 15:36:51 +0200 | [diff] [blame] | 103 | pn = atomic64_read(&key->conf.tx_pn); |
Jouni Malinen | 00b9cfa | 2015-01-24 19:52:06 +0200 | [diff] [blame] | 104 | len = scnprintf(buf, sizeof(buf), "%02x%02x%02x%02x%02x%02x\n", |
| 105 | (u8)(pn >> 40), (u8)(pn >> 32), (u8)(pn >> 24), |
| 106 | (u8)(pn >> 16), (u8)(pn >> 8), (u8)pn); |
| 107 | break; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 108 | default: |
| 109 | return 0; |
| 110 | } |
| 111 | return simple_read_from_buffer(userbuf, count, ppos, buf, len); |
| 112 | } |
| 113 | KEY_OPS(tx_spec); |
| 114 | |
| 115 | static ssize_t key_rx_spec_read(struct file *file, char __user *userbuf, |
| 116 | size_t count, loff_t *ppos) |
| 117 | { |
| 118 | struct ieee80211_key *key = file->private_data; |
Johannes Berg | 5a306f5 | 2012-11-14 23:22:21 +0100 | [diff] [blame] | 119 | char buf[14*IEEE80211_NUM_TIDS+1], *p = buf; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 120 | int i, len; |
| 121 | const u8 *rpn; |
| 122 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 123 | switch (key->conf.cipher) { |
| 124 | case WLAN_CIPHER_SUITE_WEP40: |
| 125 | case WLAN_CIPHER_SUITE_WEP104: |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 126 | len = scnprintf(buf, sizeof(buf), "\n"); |
Johannes Berg | 50339a6 | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 127 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 128 | case WLAN_CIPHER_SUITE_TKIP: |
Johannes Berg | 5a306f5 | 2012-11-14 23:22:21 +0100 | [diff] [blame] | 129 | for (i = 0; i < IEEE80211_NUM_TIDS; i++) |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 130 | p += scnprintf(p, sizeof(buf)+buf-p, |
| 131 | "%08x %04x\n", |
Harvey Harrison | b0f76b3 | 2008-05-14 16:26:19 -0700 | [diff] [blame] | 132 | key->u.tkip.rx[i].iv32, |
| 133 | key->u.tkip.rx[i].iv16); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 134 | len = p - buf; |
Johannes Berg | 50339a6 | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 135 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 136 | case WLAN_CIPHER_SUITE_CCMP: |
Jouni Malinen | 2b2ba0d | 2015-01-24 19:52:07 +0200 | [diff] [blame] | 137 | case WLAN_CIPHER_SUITE_CCMP_256: |
Johannes Berg | 5a306f5 | 2012-11-14 23:22:21 +0100 | [diff] [blame] | 138 | for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) { |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 139 | rpn = key->u.ccmp.rx_pn[i]; |
| 140 | p += scnprintf(p, sizeof(buf)+buf-p, |
| 141 | "%02x%02x%02x%02x%02x%02x\n", |
| 142 | rpn[0], rpn[1], rpn[2], |
| 143 | rpn[3], rpn[4], rpn[5]); |
| 144 | } |
| 145 | len = p - buf; |
Johannes Berg | 50339a6 | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 146 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 147 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Jouni Malinen | 56c52da | 2015-01-24 19:52:08 +0200 | [diff] [blame] | 148 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 149 | rpn = key->u.aes_cmac.rx_pn; |
| 150 | p += scnprintf(p, sizeof(buf)+buf-p, |
| 151 | "%02x%02x%02x%02x%02x%02x\n", |
| 152 | rpn[0], rpn[1], rpn[2], |
| 153 | rpn[3], rpn[4], rpn[5]); |
| 154 | len = p - buf; |
| 155 | break; |
Jouni Malinen | 8ade538 | 2015-01-24 19:52:09 +0200 | [diff] [blame] | 156 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 157 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 158 | rpn = key->u.aes_gmac.rx_pn; |
| 159 | p += scnprintf(p, sizeof(buf)+buf-p, |
| 160 | "%02x%02x%02x%02x%02x%02x\n", |
| 161 | rpn[0], rpn[1], rpn[2], |
| 162 | rpn[3], rpn[4], rpn[5]); |
| 163 | len = p - buf; |
| 164 | break; |
Jouni Malinen | 00b9cfa | 2015-01-24 19:52:06 +0200 | [diff] [blame] | 165 | case WLAN_CIPHER_SUITE_GCMP: |
| 166 | case WLAN_CIPHER_SUITE_GCMP_256: |
| 167 | for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) { |
| 168 | rpn = key->u.gcmp.rx_pn[i]; |
| 169 | p += scnprintf(p, sizeof(buf)+buf-p, |
| 170 | "%02x%02x%02x%02x%02x%02x\n", |
| 171 | rpn[0], rpn[1], rpn[2], |
| 172 | rpn[3], rpn[4], rpn[5]); |
| 173 | } |
| 174 | len = p - buf; |
| 175 | break; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 176 | default: |
| 177 | return 0; |
| 178 | } |
| 179 | return simple_read_from_buffer(userbuf, count, ppos, buf, len); |
| 180 | } |
| 181 | KEY_OPS(rx_spec); |
| 182 | |
| 183 | static ssize_t key_replays_read(struct file *file, char __user *userbuf, |
| 184 | size_t count, loff_t *ppos) |
| 185 | { |
| 186 | struct ieee80211_key *key = file->private_data; |
| 187 | char buf[20]; |
| 188 | int len; |
| 189 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 190 | switch (key->conf.cipher) { |
| 191 | case WLAN_CIPHER_SUITE_CCMP: |
Jouni Malinen | 2b2ba0d | 2015-01-24 19:52:07 +0200 | [diff] [blame] | 192 | case WLAN_CIPHER_SUITE_CCMP_256: |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 193 | len = scnprintf(buf, sizeof(buf), "%u\n", key->u.ccmp.replays); |
| 194 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 195 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Jouni Malinen | 56c52da | 2015-01-24 19:52:08 +0200 | [diff] [blame] | 196 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 197 | len = scnprintf(buf, sizeof(buf), "%u\n", |
| 198 | key->u.aes_cmac.replays); |
| 199 | break; |
Jouni Malinen | 8ade538 | 2015-01-24 19:52:09 +0200 | [diff] [blame] | 200 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 201 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 202 | len = scnprintf(buf, sizeof(buf), "%u\n", |
| 203 | key->u.aes_gmac.replays); |
| 204 | break; |
Jouni Malinen | 00b9cfa | 2015-01-24 19:52:06 +0200 | [diff] [blame] | 205 | case WLAN_CIPHER_SUITE_GCMP: |
| 206 | case WLAN_CIPHER_SUITE_GCMP_256: |
| 207 | len = scnprintf(buf, sizeof(buf), "%u\n", key->u.gcmp.replays); |
| 208 | break; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 209 | default: |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 210 | return 0; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 211 | } |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 212 | return simple_read_from_buffer(userbuf, count, ppos, buf, len); |
| 213 | } |
| 214 | KEY_OPS(replays); |
| 215 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 216 | static ssize_t key_icverrors_read(struct file *file, char __user *userbuf, |
| 217 | size_t count, loff_t *ppos) |
| 218 | { |
| 219 | struct ieee80211_key *key = file->private_data; |
| 220 | char buf[20]; |
| 221 | int len; |
| 222 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 223 | switch (key->conf.cipher) { |
| 224 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Jouni Malinen | 56c52da | 2015-01-24 19:52:08 +0200 | [diff] [blame] | 225 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 226 | len = scnprintf(buf, sizeof(buf), "%u\n", |
| 227 | key->u.aes_cmac.icverrors); |
| 228 | break; |
Jouni Malinen | 8ade538 | 2015-01-24 19:52:09 +0200 | [diff] [blame] | 229 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 230 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 231 | len = scnprintf(buf, sizeof(buf), "%u\n", |
| 232 | key->u.aes_gmac.icverrors); |
| 233 | break; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 234 | default: |
| 235 | return 0; |
| 236 | } |
| 237 | return simple_read_from_buffer(userbuf, count, ppos, buf, len); |
| 238 | } |
| 239 | KEY_OPS(icverrors); |
| 240 | |
Saravana | b98ea05 | 2012-12-04 19:47:42 +0530 | [diff] [blame] | 241 | static ssize_t key_mic_failures_read(struct file *file, char __user *userbuf, |
| 242 | size_t count, loff_t *ppos) |
| 243 | { |
| 244 | struct ieee80211_key *key = file->private_data; |
| 245 | char buf[20]; |
| 246 | int len; |
| 247 | |
| 248 | if (key->conf.cipher != WLAN_CIPHER_SUITE_TKIP) |
| 249 | return -EINVAL; |
| 250 | |
| 251 | len = scnprintf(buf, sizeof(buf), "%u\n", key->u.tkip.mic_failures); |
| 252 | |
| 253 | return simple_read_from_buffer(userbuf, count, ppos, buf, len); |
| 254 | } |
| 255 | KEY_OPS(mic_failures); |
| 256 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 257 | static ssize_t key_key_read(struct file *file, char __user *userbuf, |
| 258 | size_t count, loff_t *ppos) |
| 259 | { |
| 260 | struct ieee80211_key *key = file->private_data; |
Jesper Juhl | 520efd1 | 2010-10-29 16:10:26 +0200 | [diff] [blame] | 261 | int i, bufsize = 2 * key->conf.keylen + 2; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 262 | char *buf = kmalloc(bufsize, GFP_KERNEL); |
| 263 | char *p = buf; |
Jesper Juhl | 520efd1 | 2010-10-29 16:10:26 +0200 | [diff] [blame] | 264 | ssize_t res; |
| 265 | |
| 266 | if (!buf) |
| 267 | return -ENOMEM; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 268 | |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 269 | for (i = 0; i < key->conf.keylen; i++) |
| 270 | p += scnprintf(p, bufsize + buf - p, "%02x", key->conf.key[i]); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 271 | p += scnprintf(p, bufsize+buf-p, "\n"); |
| 272 | res = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf); |
| 273 | kfree(buf); |
| 274 | return res; |
| 275 | } |
| 276 | KEY_OPS(key); |
| 277 | |
| 278 | #define DEBUGFS_ADD(name) \ |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame] | 279 | debugfs_create_file(#name, 0400, key->debugfs.dir, \ |
| 280 | key, &key_##name##_ops); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 281 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 282 | void ieee80211_debugfs_key_add(struct ieee80211_key *key) |
Johannes Berg | 9446f3e | 2012-01-17 10:32:01 +0100 | [diff] [blame] | 283 | { |
Johannes Berg | 50339a6 | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 284 | static int keycount; |
Johannes Berg | 9446f3e | 2012-01-17 10:32:01 +0100 | [diff] [blame] | 285 | char buf[100]; |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 286 | struct sta_info *sta; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 287 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 288 | if (!key->local->debugfs.keys) |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 289 | return; |
| 290 | |
Johannes Berg | 50339a6 | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 291 | sprintf(buf, "%d", keycount); |
Johannes Berg | d9c58f3 | 2008-04-08 16:46:36 -0400 | [diff] [blame] | 292 | key->debugfs.cnt = keycount; |
Johannes Berg | 50339a6 | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 293 | keycount++; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 294 | key->debugfs.dir = debugfs_create_dir(buf, |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 295 | key->local->debugfs.keys); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 296 | |
| 297 | if (!key->debugfs.dir) |
| 298 | return; |
| 299 | |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 300 | sta = key->sta; |
| 301 | if (sta) { |
Johannes Berg | 9446f3e | 2012-01-17 10:32:01 +0100 | [diff] [blame] | 302 | sprintf(buf, "../../netdev:%s/stations/%pM", |
| 303 | sta->sdata->name, sta->sta.addr); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 304 | key->debugfs.stalink = |
| 305 | debugfs_create_symlink("station", key->debugfs.dir, buf); |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 306 | } |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 307 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 308 | DEBUGFS_ADD(keylen); |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 309 | DEBUGFS_ADD(flags); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 310 | DEBUGFS_ADD(keyidx); |
| 311 | DEBUGFS_ADD(hw_key_idx); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 312 | DEBUGFS_ADD(algorithm); |
| 313 | DEBUGFS_ADD(tx_spec); |
| 314 | DEBUGFS_ADD(rx_spec); |
| 315 | DEBUGFS_ADD(replays); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 316 | DEBUGFS_ADD(icverrors); |
Saravana | b98ea05 | 2012-12-04 19:47:42 +0530 | [diff] [blame] | 317 | DEBUGFS_ADD(mic_failures); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 318 | DEBUGFS_ADD(key); |
Johannes Berg | e7a64f1 | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 319 | DEBUGFS_ADD(ifindex); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 320 | }; |
| 321 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 322 | void ieee80211_debugfs_key_remove(struct ieee80211_key *key) |
| 323 | { |
| 324 | if (!key) |
| 325 | return; |
| 326 | |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame] | 327 | debugfs_remove_recursive(key->debugfs.dir); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 328 | key->debugfs.dir = NULL; |
| 329 | } |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 330 | |
| 331 | void ieee80211_debugfs_key_update_default(struct ieee80211_sub_if_data *sdata) |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 332 | { |
| 333 | char buf[50]; |
Johannes Berg | 78520ca | 2008-05-03 01:04:47 +0200 | [diff] [blame] | 334 | struct ieee80211_key *key; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 335 | |
Stanislaw Gruszka | ddbfe86 | 2013-03-08 14:46:14 +0100 | [diff] [blame] | 336 | if (!sdata->vif.debugfs_dir) |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 337 | return; |
| 338 | |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 339 | lockdep_assert_held(&sdata->local->key_mtx); |
Johannes Berg | 78520ca | 2008-05-03 01:04:47 +0200 | [diff] [blame] | 340 | |
Fabian Frederick | 5c6761a | 2014-10-21 18:20:12 +0200 | [diff] [blame] | 341 | debugfs_remove(sdata->debugfs.default_unicast_key); |
| 342 | sdata->debugfs.default_unicast_key = NULL; |
Johannes Berg | 135792e | 2012-07-05 21:37:05 +0200 | [diff] [blame] | 343 | |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 344 | if (sdata->default_unicast_key) { |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 345 | key = key_mtx_dereference(sdata->local, |
| 346 | sdata->default_unicast_key); |
Johannes Berg | 78520ca | 2008-05-03 01:04:47 +0200 | [diff] [blame] | 347 | sprintf(buf, "../keys/%d", key->debugfs.cnt); |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 348 | sdata->debugfs.default_unicast_key = |
| 349 | debugfs_create_symlink("default_unicast_key", |
Stanislaw Gruszka | ddbfe86 | 2013-03-08 14:46:14 +0100 | [diff] [blame] | 350 | sdata->vif.debugfs_dir, buf); |
Johannes Berg | 135792e | 2012-07-05 21:37:05 +0200 | [diff] [blame] | 351 | } |
| 352 | |
Fabian Frederick | 5c6761a | 2014-10-21 18:20:12 +0200 | [diff] [blame] | 353 | debugfs_remove(sdata->debugfs.default_multicast_key); |
| 354 | sdata->debugfs.default_multicast_key = NULL; |
Johannes Berg | 78520ca | 2008-05-03 01:04:47 +0200 | [diff] [blame] | 355 | |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 356 | if (sdata->default_multicast_key) { |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 357 | key = key_mtx_dereference(sdata->local, |
| 358 | sdata->default_multicast_key); |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 359 | sprintf(buf, "../keys/%d", key->debugfs.cnt); |
| 360 | sdata->debugfs.default_multicast_key = |
| 361 | debugfs_create_symlink("default_multicast_key", |
Stanislaw Gruszka | ddbfe86 | 2013-03-08 14:46:14 +0100 | [diff] [blame] | 362 | sdata->vif.debugfs_dir, buf); |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 363 | } |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 364 | } |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 365 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 366 | void ieee80211_debugfs_key_add_mgmt_default(struct ieee80211_sub_if_data *sdata) |
| 367 | { |
| 368 | char buf[50]; |
| 369 | struct ieee80211_key *key; |
| 370 | |
Stanislaw Gruszka | ddbfe86 | 2013-03-08 14:46:14 +0100 | [diff] [blame] | 371 | if (!sdata->vif.debugfs_dir) |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 372 | return; |
| 373 | |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 374 | key = key_mtx_dereference(sdata->local, |
| 375 | sdata->default_mgmt_key); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 376 | if (key) { |
| 377 | sprintf(buf, "../keys/%d", key->debugfs.cnt); |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame] | 378 | sdata->debugfs.default_mgmt_key = |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 379 | debugfs_create_symlink("default_mgmt_key", |
Stanislaw Gruszka | ddbfe86 | 2013-03-08 14:46:14 +0100 | [diff] [blame] | 380 | sdata->vif.debugfs_dir, buf); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 381 | } else |
| 382 | ieee80211_debugfs_key_remove_mgmt_default(sdata); |
| 383 | } |
| 384 | |
| 385 | void ieee80211_debugfs_key_remove_mgmt_default(struct ieee80211_sub_if_data *sdata) |
| 386 | { |
| 387 | if (!sdata) |
| 388 | return; |
| 389 | |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame] | 390 | debugfs_remove(sdata->debugfs.default_mgmt_key); |
| 391 | sdata->debugfs.default_mgmt_key = NULL; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 392 | } |
| 393 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 394 | void ieee80211_debugfs_key_sta_del(struct ieee80211_key *key, |
| 395 | struct sta_info *sta) |
| 396 | { |
| 397 | debugfs_remove(key->debugfs.stalink); |
| 398 | key->debugfs.stalink = NULL; |
| 399 | } |