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")
29 #define KEY_OPS(name) \
30 static const struct file_operations key_ ##name## _ops = { \
31 .read = key_##name##_read, \
32 .open = mac80211_open_file_generic, \
35 #define KEY_FILE(name, format) \
36 KEY_READ_##format(name) \
39 #define KEY_CONF_READ(name, buflen, format_string) \
40 KEY_READ(conf_##name, conf.name, buflen, format_string)
41 #define KEY_CONF_READ_D(name) KEY_CONF_READ(name, 20, "%d\n")
42 #define KEY_CONF_READ_X(name) KEY_CONF_READ(name, 20, "0x%x\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
);
57 KEY_CONF_FILE(flags
, X
);
58 KEY_FILE(tx_rx_count
, D
);
60 static ssize_t
key_algorithm_read(struct file
*file
,
62 size_t count
, loff_t
*ppos
)
65 struct ieee80211_key
*key
= file
->private_data
;
67 switch (key
->conf
.alg
) {
80 return simple_read_from_buffer(userbuf
, count
, ppos
, alg
, strlen(alg
));
84 static ssize_t
key_tx_spec_read(struct file
*file
, char __user
*userbuf
,
85 size_t count
, loff_t
*ppos
)
90 struct ieee80211_key
*key
= file
->private_data
;
92 switch (key
->conf
.alg
) {
94 len
= scnprintf(buf
, sizeof(buf
), "\n");
97 len
= scnprintf(buf
, sizeof(buf
), "%08x %04x\n",
102 tpn
= key
->u
.ccmp
.tx_pn
;
103 len
= scnprintf(buf
, sizeof(buf
), "%02x%02x%02x%02x%02x%02x\n",
104 tpn
[0], tpn
[1], tpn
[2], tpn
[3], tpn
[4], tpn
[5]);
109 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, len
);
113 static ssize_t
key_rx_spec_read(struct file
*file
, char __user
*userbuf
,
114 size_t count
, loff_t
*ppos
)
116 struct ieee80211_key
*key
= file
->private_data
;
117 char buf
[14*NUM_RX_DATA_QUEUES
+1], *p
= buf
;
121 switch (key
->conf
.alg
) {
123 len
= scnprintf(buf
, sizeof(buf
), "\n");
126 for (i
= 0; i
< NUM_RX_DATA_QUEUES
; i
++)
127 p
+= scnprintf(p
, sizeof(buf
)+buf
-p
,
129 key
->u
.tkip
.iv32_rx
[i
],
130 key
->u
.tkip
.iv16_rx
[i
]);
134 for (i
= 0; i
< NUM_RX_DATA_QUEUES
; i
++) {
135 rpn
= key
->u
.ccmp
.rx_pn
[i
];
136 p
+= scnprintf(p
, sizeof(buf
)+buf
-p
,
137 "%02x%02x%02x%02x%02x%02x\n",
138 rpn
[0], rpn
[1], rpn
[2],
139 rpn
[3], rpn
[4], rpn
[5]);
146 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, len
);
150 static ssize_t
key_replays_read(struct file
*file
, char __user
*userbuf
,
151 size_t count
, loff_t
*ppos
)
153 struct ieee80211_key
*key
= file
->private_data
;
157 if (key
->conf
.alg
!= ALG_CCMP
)
159 len
= scnprintf(buf
, sizeof(buf
), "%u\n", key
->u
.ccmp
.replays
);
160 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, len
);
164 static ssize_t
key_key_read(struct file
*file
, char __user
*userbuf
,
165 size_t count
, loff_t
*ppos
)
167 struct ieee80211_key
*key
= file
->private_data
;
168 int i
, res
, bufsize
= 2 * key
->conf
.keylen
+ 2;
169 char *buf
= kmalloc(bufsize
, GFP_KERNEL
);
172 for (i
= 0; i
< key
->conf
.keylen
; i
++)
173 p
+= scnprintf(p
, bufsize
+ buf
- p
, "%02x", key
->conf
.key
[i
]);
174 p
+= scnprintf(p
, bufsize
+buf
-p
, "\n");
175 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, p
- buf
);
181 #define DEBUGFS_ADD(name) \
182 key->debugfs.name = debugfs_create_file(#name, 0400,\
183 key->debugfs.dir, key, &key_##name##_ops);
185 void ieee80211_debugfs_key_add(struct ieee80211_local
*local
,
186 struct ieee80211_key
*key
)
191 if (!local
->debugfs
.keys
)
194 sprintf(buf
, "%d", keycount
);
196 key
->debugfs
.dir
= debugfs_create_dir(buf
,
197 local
->debugfs
.keys
);
199 if (!key
->debugfs
.dir
)
205 DEBUGFS_ADD(hw_key_idx
);
206 DEBUGFS_ADD(tx_rx_count
);
207 DEBUGFS_ADD(algorithm
);
208 DEBUGFS_ADD(tx_spec
);
209 DEBUGFS_ADD(rx_spec
);
210 DEBUGFS_ADD(replays
);
214 #define DEBUGFS_DEL(name) \
215 debugfs_remove(key->debugfs.name); key->debugfs.name = NULL;
217 void ieee80211_debugfs_key_remove(struct ieee80211_key
*key
)
225 DEBUGFS_DEL(hw_key_idx
);
226 DEBUGFS_DEL(tx_rx_count
);
227 DEBUGFS_DEL(algorithm
);
228 DEBUGFS_DEL(tx_spec
);
229 DEBUGFS_DEL(rx_spec
);
230 DEBUGFS_DEL(replays
);
233 debugfs_remove(key
->debugfs
.stalink
);
234 key
->debugfs
.stalink
= NULL
;
235 debugfs_remove(key
->debugfs
.dir
);
236 key
->debugfs
.dir
= NULL
;
238 void ieee80211_debugfs_key_add_default(struct ieee80211_sub_if_data
*sdata
)
242 if (!sdata
->debugfsdir
)
245 sprintf(buf
, "../keys/%d", sdata
->default_key
->conf
.keyidx
);
246 sdata
->debugfs
.default_key
=
247 debugfs_create_symlink("default_key", sdata
->debugfsdir
, buf
);
249 void ieee80211_debugfs_key_remove_default(struct ieee80211_sub_if_data
*sdata
)
254 debugfs_remove(sdata
->debugfs
.default_key
);
255 sdata
->debugfs
.default_key
= NULL
;
257 void ieee80211_debugfs_key_sta_link(struct ieee80211_key
*key
,
258 struct sta_info
*sta
)
262 if (!key
->debugfs
.dir
)
265 sprintf(buf
, "../../stations/" MAC_FMT
, MAC_ARG(sta
->addr
));
266 key
->debugfs
.stalink
=
267 debugfs_create_symlink("station", key
->debugfs
.dir
, buf
);
270 void ieee80211_debugfs_key_sta_del(struct ieee80211_key
*key
,
271 struct sta_info
*sta
)
273 debugfs_remove(key
->debugfs
.stalink
);
274 key
->debugfs
.stalink
= NULL
;
This page took 0.152654 seconds and 5 git commands to generate.