2 * Copyright 2003-2005 Devicescape Software, Inc.
3 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
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.
11 #include <linux/kobject.h>
12 #include "ieee80211_i.h"
13 #include "ieee80211_key.h"
15 #include "debugfs_key.h"
17 #define KEY_READ(name, prop, buflen, format_string) \
18 static ssize_t key_##name##_read(struct file *file, \
19 char __user *userbuf, \
20 size_t count, loff_t *ppos) \
23 struct ieee80211_key *key = file->private_data; \
24 int res = scnprintf(buf, buflen, format_string, key->prop); \
25 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
27 #define KEY_READ_D(name) KEY_READ(name, name, 20, "%d\n")
28 #define KEY_READ_X(name) KEY_READ(name, name, 20, "0x%x\n")
30 #define KEY_OPS(name) \
31 static const struct file_operations key_ ##name## _ops = { \
32 .read = key_##name##_read, \
33 .open = mac80211_open_file_generic, \
36 #define KEY_FILE(name, format) \
37 KEY_READ_##format(name) \
40 #define KEY_CONF_READ(name, buflen, format_string) \
41 KEY_READ(conf_##name, conf.name, buflen, format_string)
42 #define KEY_CONF_READ_D(name) KEY_CONF_READ(name, 20, "%d\n")
44 #define KEY_CONF_OPS(name) \
45 static const struct file_operations key_ ##name## _ops = { \
46 .read = key_conf_##name##_read, \
47 .open = mac80211_open_file_generic, \
50 #define KEY_CONF_FILE(name, format) \
51 KEY_CONF_READ_##format(name) \
54 KEY_CONF_FILE(keylen
, D
);
55 KEY_CONF_FILE(keyidx
, D
);
56 KEY_CONF_FILE(hw_key_idx
, D
);
58 KEY_FILE(tx_rx_count
, D
);
59 KEY_READ(ifindex
, sdata
->dev
->ifindex
, 20, "%d\n");
62 static ssize_t
key_algorithm_read(struct file
*file
,
64 size_t count
, loff_t
*ppos
)
67 struct ieee80211_key
*key
= file
->private_data
;
69 switch (key
->conf
.alg
) {
82 return simple_read_from_buffer(userbuf
, count
, ppos
, alg
, strlen(alg
));
86 static ssize_t
key_tx_spec_read(struct file
*file
, char __user
*userbuf
,
87 size_t count
, loff_t
*ppos
)
92 struct ieee80211_key
*key
= file
->private_data
;
94 switch (key
->conf
.alg
) {
96 len
= scnprintf(buf
, sizeof(buf
), "\n");
99 len
= scnprintf(buf
, sizeof(buf
), "%08x %04x\n",
104 tpn
= key
->u
.ccmp
.tx_pn
;
105 len
= scnprintf(buf
, sizeof(buf
), "%02x%02x%02x%02x%02x%02x\n",
106 tpn
[0], tpn
[1], tpn
[2], tpn
[3], tpn
[4], tpn
[5]);
111 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, len
);
115 static ssize_t
key_rx_spec_read(struct file
*file
, char __user
*userbuf
,
116 size_t count
, loff_t
*ppos
)
118 struct ieee80211_key
*key
= file
->private_data
;
119 char buf
[14*NUM_RX_DATA_QUEUES
+1], *p
= buf
;
123 switch (key
->conf
.alg
) {
125 len
= scnprintf(buf
, sizeof(buf
), "\n");
128 for (i
= 0; i
< NUM_RX_DATA_QUEUES
; i
++)
129 p
+= scnprintf(p
, sizeof(buf
)+buf
-p
,
131 key
->u
.tkip
.iv32_rx
[i
],
132 key
->u
.tkip
.iv16_rx
[i
]);
136 for (i
= 0; i
< NUM_RX_DATA_QUEUES
; i
++) {
137 rpn
= key
->u
.ccmp
.rx_pn
[i
];
138 p
+= scnprintf(p
, sizeof(buf
)+buf
-p
,
139 "%02x%02x%02x%02x%02x%02x\n",
140 rpn
[0], rpn
[1], rpn
[2],
141 rpn
[3], rpn
[4], rpn
[5]);
148 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, len
);
152 static ssize_t
key_replays_read(struct file
*file
, char __user
*userbuf
,
153 size_t count
, loff_t
*ppos
)
155 struct ieee80211_key
*key
= file
->private_data
;
159 if (key
->conf
.alg
!= ALG_CCMP
)
161 len
= scnprintf(buf
, sizeof(buf
), "%u\n", key
->u
.ccmp
.replays
);
162 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, len
);
166 static ssize_t
key_key_read(struct file
*file
, char __user
*userbuf
,
167 size_t count
, loff_t
*ppos
)
169 struct ieee80211_key
*key
= file
->private_data
;
170 int i
, res
, bufsize
= 2 * key
->conf
.keylen
+ 2;
171 char *buf
= kmalloc(bufsize
, GFP_KERNEL
);
174 for (i
= 0; i
< key
->conf
.keylen
; i
++)
175 p
+= scnprintf(p
, bufsize
+ buf
- p
, "%02x", key
->conf
.key
[i
]);
176 p
+= scnprintf(p
, bufsize
+buf
-p
, "\n");
177 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, p
- buf
);
183 #define DEBUGFS_ADD(name) \
184 key->debugfs.name = debugfs_create_file(#name, 0400,\
185 key->debugfs.dir, key, &key_##name##_ops);
187 void ieee80211_debugfs_key_add(struct ieee80211_local
*local
,
188 struct ieee80211_key
*key
)
193 if (!local
->debugfs
.keys
)
196 sprintf(buf
, "%d", keycount
);
198 key
->debugfs
.dir
= debugfs_create_dir(buf
,
199 local
->debugfs
.keys
);
201 if (!key
->debugfs
.dir
)
207 DEBUGFS_ADD(hw_key_idx
);
208 DEBUGFS_ADD(tx_rx_count
);
209 DEBUGFS_ADD(algorithm
);
210 DEBUGFS_ADD(tx_spec
);
211 DEBUGFS_ADD(rx_spec
);
212 DEBUGFS_ADD(replays
);
214 DEBUGFS_ADD(ifindex
);
217 #define DEBUGFS_DEL(name) \
218 debugfs_remove(key->debugfs.name); key->debugfs.name = NULL;
220 void ieee80211_debugfs_key_remove(struct ieee80211_key
*key
)
228 DEBUGFS_DEL(hw_key_idx
);
229 DEBUGFS_DEL(tx_rx_count
);
230 DEBUGFS_DEL(algorithm
);
231 DEBUGFS_DEL(tx_spec
);
232 DEBUGFS_DEL(rx_spec
);
233 DEBUGFS_DEL(replays
);
235 DEBUGFS_DEL(ifindex
);
237 debugfs_remove(key
->debugfs
.stalink
);
238 key
->debugfs
.stalink
= NULL
;
239 debugfs_remove(key
->debugfs
.dir
);
240 key
->debugfs
.dir
= NULL
;
242 void ieee80211_debugfs_key_add_default(struct ieee80211_sub_if_data
*sdata
)
246 if (!sdata
->debugfsdir
)
249 sprintf(buf
, "../keys/%d", sdata
->default_key
->conf
.keyidx
);
250 sdata
->debugfs
.default_key
=
251 debugfs_create_symlink("default_key", sdata
->debugfsdir
, buf
);
253 void ieee80211_debugfs_key_remove_default(struct ieee80211_sub_if_data
*sdata
)
258 debugfs_remove(sdata
->debugfs
.default_key
);
259 sdata
->debugfs
.default_key
= NULL
;
261 void ieee80211_debugfs_key_sta_link(struct ieee80211_key
*key
,
262 struct sta_info
*sta
)
265 DECLARE_MAC_BUF(mac
);
267 if (!key
->debugfs
.dir
)
270 sprintf(buf
, "../../stations/%s", print_mac(mac
, sta
->addr
));
271 key
->debugfs
.stalink
=
272 debugfs_create_symlink("station", key
->debugfs
.dir
, buf
);
275 void ieee80211_debugfs_key_sta_del(struct ieee80211_key
*key
,
276 struct sta_info
*sta
)
278 debugfs_remove(key
->debugfs
.stalink
);
279 key
->debugfs
.stalink
= NULL
;