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