2 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
3 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
10 #include <linux/kernel.h>
11 #include <linux/device.h>
13 #include <linux/interrupt.h>
14 #include <linux/netdevice.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/notifier.h>
17 #include <net/mac80211.h>
18 #include <net/cfg80211.h>
19 #include "ieee80211_i.h"
20 #include "ieee80211_rate.h"
22 #include "debugfs_netdev.h"
24 static ssize_t
ieee80211_if_read(
25 struct ieee80211_sub_if_data
*sdata
,
27 size_t count
, loff_t
*ppos
,
28 ssize_t (*format
)(const struct ieee80211_sub_if_data
*, char *, int))
31 ssize_t ret
= -EINVAL
;
33 read_lock(&dev_base_lock
);
34 if (sdata
->dev
->reg_state
== NETREG_REGISTERED
) {
35 ret
= (*format
)(sdata
, buf
, sizeof(buf
));
36 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, ret
);
38 read_unlock(&dev_base_lock
);
42 #define IEEE80211_IF_FMT(name, field, format_string) \
43 static ssize_t ieee80211_if_fmt_##name( \
44 const struct ieee80211_sub_if_data *sdata, char *buf, \
47 return scnprintf(buf, buflen, format_string, sdata->field); \
49 #define IEEE80211_IF_FMT_DEC(name, field) \
50 IEEE80211_IF_FMT(name, field, "%d\n")
51 #define IEEE80211_IF_FMT_HEX(name, field) \
52 IEEE80211_IF_FMT(name, field, "%#x\n")
53 #define IEEE80211_IF_FMT_SIZE(name, field) \
54 IEEE80211_IF_FMT(name, field, "%zd\n")
56 #define IEEE80211_IF_FMT_ATOMIC(name, field) \
57 static ssize_t ieee80211_if_fmt_##name( \
58 const struct ieee80211_sub_if_data *sdata, \
59 char *buf, int buflen) \
61 return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
64 #define IEEE80211_IF_FMT_MAC(name, field) \
65 static ssize_t ieee80211_if_fmt_##name( \
66 const struct ieee80211_sub_if_data *sdata, char *buf, \
69 DECLARE_MAC_BUF(mac); \
70 return scnprintf(buf, buflen, "%s\n", print_mac(mac, sdata->field));\
73 #define __IEEE80211_IF_FILE(name) \
74 static ssize_t ieee80211_if_read_##name(struct file *file, \
75 char __user *userbuf, \
76 size_t count, loff_t *ppos) \
78 return ieee80211_if_read(file->private_data, \
79 userbuf, count, ppos, \
80 ieee80211_if_fmt_##name); \
82 static const struct file_operations name##_ops = { \
83 .read = ieee80211_if_read_##name, \
84 .open = mac80211_open_file_generic, \
87 #define IEEE80211_IF_FILE(name, field, format) \
88 IEEE80211_IF_FMT_##format(name, field) \
89 __IEEE80211_IF_FILE(name)
91 /* common attributes */
92 IEEE80211_IF_FILE(channel_use
, channel_use
, DEC
);
93 IEEE80211_IF_FILE(drop_unencrypted
, drop_unencrypted
, DEC
);
94 IEEE80211_IF_FILE(eapol
, eapol
, DEC
);
95 IEEE80211_IF_FILE(ieee8021_x
, ieee802_1x
, DEC
);
97 /* STA/IBSS attributes */
98 IEEE80211_IF_FILE(state
, u
.sta
.state
, DEC
);
99 IEEE80211_IF_FILE(bssid
, u
.sta
.bssid
, MAC
);
100 IEEE80211_IF_FILE(prev_bssid
, u
.sta
.prev_bssid
, MAC
);
101 IEEE80211_IF_FILE(ssid_len
, u
.sta
.ssid_len
, SIZE
);
102 IEEE80211_IF_FILE(aid
, u
.sta
.aid
, DEC
);
103 IEEE80211_IF_FILE(ap_capab
, u
.sta
.ap_capab
, HEX
);
104 IEEE80211_IF_FILE(capab
, u
.sta
.capab
, HEX
);
105 IEEE80211_IF_FILE(extra_ie_len
, u
.sta
.extra_ie_len
, SIZE
);
106 IEEE80211_IF_FILE(auth_tries
, u
.sta
.auth_tries
, DEC
);
107 IEEE80211_IF_FILE(assoc_tries
, u
.sta
.assoc_tries
, DEC
);
108 IEEE80211_IF_FILE(auth_algs
, u
.sta
.auth_algs
, HEX
);
109 IEEE80211_IF_FILE(auth_alg
, u
.sta
.auth_alg
, DEC
);
110 IEEE80211_IF_FILE(auth_transaction
, u
.sta
.auth_transaction
, DEC
);
112 static ssize_t
ieee80211_if_fmt_flags(
113 const struct ieee80211_sub_if_data
*sdata
, char *buf
, int buflen
)
115 return scnprintf(buf
, buflen
, "%s%s%s%s%s%s%s\n",
116 sdata
->u
.sta
.flags
& IEEE80211_STA_SSID_SET
? "SSID\n" : "",
117 sdata
->u
.sta
.flags
& IEEE80211_STA_BSSID_SET
? "BSSID\n" : "",
118 sdata
->u
.sta
.flags
& IEEE80211_STA_PREV_BSSID_SET
? "prev BSSID\n" : "",
119 sdata
->u
.sta
.flags
& IEEE80211_STA_AUTHENTICATED
? "AUTH\n" : "",
120 sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
? "ASSOC\n" : "",
121 sdata
->u
.sta
.flags
& IEEE80211_STA_PROBEREQ_POLL
? "PROBEREQ POLL\n" : "",
122 sdata
->flags
& IEEE80211_SDATA_USE_PROTECTION
? "CTS prot\n" : "");
124 __IEEE80211_IF_FILE(flags
);
127 IEEE80211_IF_FILE(num_sta_ps
, u
.ap
.num_sta_ps
, ATOMIC
);
128 IEEE80211_IF_FILE(dtim_period
, u
.ap
.dtim_period
, DEC
);
129 IEEE80211_IF_FILE(dtim_count
, u
.ap
.dtim_count
, DEC
);
130 IEEE80211_IF_FILE(num_beacons
, u
.ap
.num_beacons
, DEC
);
131 IEEE80211_IF_FILE(force_unicast_rateidx
, u
.ap
.force_unicast_rateidx
, DEC
);
132 IEEE80211_IF_FILE(max_ratectrl_rateidx
, u
.ap
.max_ratectrl_rateidx
, DEC
);
134 static ssize_t
ieee80211_if_fmt_num_buffered_multicast(
135 const struct ieee80211_sub_if_data
*sdata
, char *buf
, int buflen
)
137 return scnprintf(buf
, buflen
, "%u\n",
138 skb_queue_len(&sdata
->u
.ap
.ps_bc_buf
));
140 __IEEE80211_IF_FILE(num_buffered_multicast
);
142 static ssize_t
ieee80211_if_fmt_beacon_head_len(
143 const struct ieee80211_sub_if_data
*sdata
, char *buf
, int buflen
)
145 if (sdata
->u
.ap
.beacon_head
)
146 return scnprintf(buf
, buflen
, "%d\n",
147 sdata
->u
.ap
.beacon_head_len
);
148 return scnprintf(buf
, buflen
, "\n");
150 __IEEE80211_IF_FILE(beacon_head_len
);
152 static ssize_t
ieee80211_if_fmt_beacon_tail_len(
153 const struct ieee80211_sub_if_data
*sdata
, char *buf
, int buflen
)
155 if (sdata
->u
.ap
.beacon_tail
)
156 return scnprintf(buf
, buflen
, "%d\n",
157 sdata
->u
.ap
.beacon_tail_len
);
158 return scnprintf(buf
, buflen
, "\n");
160 __IEEE80211_IF_FILE(beacon_tail_len
);
163 IEEE80211_IF_FILE(peer
, u
.wds
.remote_addr
, MAC
);
165 /* VLAN attributes */
166 IEEE80211_IF_FILE(vlan_id
, u
.vlan
.id
, DEC
);
168 /* MONITOR attributes */
169 static ssize_t
ieee80211_if_fmt_mode(
170 const struct ieee80211_sub_if_data
*sdata
, char *buf
, int buflen
)
172 struct ieee80211_local
*local
= sdata
->local
;
174 return scnprintf(buf
, buflen
, "%s\n",
175 ((local
->hw
.flags
& IEEE80211_HW_MONITOR_DURING_OPER
) ||
176 local
->open_count
== local
->monitors
) ?
179 __IEEE80211_IF_FILE(mode
);
182 #define DEBUGFS_ADD(name, type)\
183 sdata->debugfs.type.name = debugfs_create_file(#name, 0444,\
184 sdata->debugfsdir, sdata, &name##_ops);
186 static void add_sta_files(struct ieee80211_sub_if_data
*sdata
)
188 DEBUGFS_ADD(channel_use
, sta
);
189 DEBUGFS_ADD(drop_unencrypted
, sta
);
190 DEBUGFS_ADD(eapol
, sta
);
191 DEBUGFS_ADD(ieee8021_x
, sta
);
192 DEBUGFS_ADD(state
, sta
);
193 DEBUGFS_ADD(bssid
, sta
);
194 DEBUGFS_ADD(prev_bssid
, sta
);
195 DEBUGFS_ADD(ssid_len
, sta
);
196 DEBUGFS_ADD(aid
, sta
);
197 DEBUGFS_ADD(ap_capab
, sta
);
198 DEBUGFS_ADD(capab
, sta
);
199 DEBUGFS_ADD(extra_ie_len
, sta
);
200 DEBUGFS_ADD(auth_tries
, sta
);
201 DEBUGFS_ADD(assoc_tries
, sta
);
202 DEBUGFS_ADD(auth_algs
, sta
);
203 DEBUGFS_ADD(auth_alg
, sta
);
204 DEBUGFS_ADD(auth_transaction
, sta
);
205 DEBUGFS_ADD(flags
, sta
);
208 static void add_ap_files(struct ieee80211_sub_if_data
*sdata
)
210 DEBUGFS_ADD(channel_use
, ap
);
211 DEBUGFS_ADD(drop_unencrypted
, ap
);
212 DEBUGFS_ADD(eapol
, ap
);
213 DEBUGFS_ADD(ieee8021_x
, ap
);
214 DEBUGFS_ADD(num_sta_ps
, ap
);
215 DEBUGFS_ADD(dtim_period
, ap
);
216 DEBUGFS_ADD(dtim_count
, ap
);
217 DEBUGFS_ADD(num_beacons
, ap
);
218 DEBUGFS_ADD(force_unicast_rateidx
, ap
);
219 DEBUGFS_ADD(max_ratectrl_rateidx
, ap
);
220 DEBUGFS_ADD(num_buffered_multicast
, ap
);
221 DEBUGFS_ADD(beacon_head_len
, ap
);
222 DEBUGFS_ADD(beacon_tail_len
, ap
);
225 static void add_wds_files(struct ieee80211_sub_if_data
*sdata
)
227 DEBUGFS_ADD(channel_use
, wds
);
228 DEBUGFS_ADD(drop_unencrypted
, wds
);
229 DEBUGFS_ADD(eapol
, wds
);
230 DEBUGFS_ADD(ieee8021_x
, wds
);
231 DEBUGFS_ADD(peer
, wds
);
234 static void add_vlan_files(struct ieee80211_sub_if_data
*sdata
)
236 DEBUGFS_ADD(channel_use
, vlan
);
237 DEBUGFS_ADD(drop_unencrypted
, vlan
);
238 DEBUGFS_ADD(eapol
, vlan
);
239 DEBUGFS_ADD(ieee8021_x
, vlan
);
240 DEBUGFS_ADD(vlan_id
, vlan
);
243 static void add_monitor_files(struct ieee80211_sub_if_data
*sdata
)
245 DEBUGFS_ADD(mode
, monitor
);
248 static void add_files(struct ieee80211_sub_if_data
*sdata
)
250 if (!sdata
->debugfsdir
)
253 switch (sdata
->type
) {
254 case IEEE80211_IF_TYPE_STA
:
255 case IEEE80211_IF_TYPE_IBSS
:
256 add_sta_files(sdata
);
258 case IEEE80211_IF_TYPE_AP
:
261 case IEEE80211_IF_TYPE_WDS
:
262 add_wds_files(sdata
);
264 case IEEE80211_IF_TYPE_MNTR
:
265 add_monitor_files(sdata
);
267 case IEEE80211_IF_TYPE_VLAN
:
268 add_vlan_files(sdata
);
275 #define DEBUGFS_DEL(name, type) \
277 debugfs_remove(sdata->debugfs.type.name); \
278 sdata->debugfs.type.name = NULL; \
281 static void del_sta_files(struct ieee80211_sub_if_data
*sdata
)
283 DEBUGFS_DEL(channel_use
, sta
);
284 DEBUGFS_DEL(drop_unencrypted
, sta
);
285 DEBUGFS_DEL(eapol
, sta
);
286 DEBUGFS_DEL(ieee8021_x
, sta
);
287 DEBUGFS_DEL(state
, sta
);
288 DEBUGFS_DEL(bssid
, sta
);
289 DEBUGFS_DEL(prev_bssid
, sta
);
290 DEBUGFS_DEL(ssid_len
, sta
);
291 DEBUGFS_DEL(aid
, sta
);
292 DEBUGFS_DEL(ap_capab
, sta
);
293 DEBUGFS_DEL(capab
, sta
);
294 DEBUGFS_DEL(extra_ie_len
, sta
);
295 DEBUGFS_DEL(auth_tries
, sta
);
296 DEBUGFS_DEL(assoc_tries
, sta
);
297 DEBUGFS_DEL(auth_algs
, sta
);
298 DEBUGFS_DEL(auth_alg
, sta
);
299 DEBUGFS_DEL(auth_transaction
, sta
);
300 DEBUGFS_DEL(flags
, sta
);
303 static void del_ap_files(struct ieee80211_sub_if_data
*sdata
)
305 DEBUGFS_DEL(channel_use
, ap
);
306 DEBUGFS_DEL(drop_unencrypted
, ap
);
307 DEBUGFS_DEL(eapol
, ap
);
308 DEBUGFS_DEL(ieee8021_x
, ap
);
309 DEBUGFS_DEL(num_sta_ps
, ap
);
310 DEBUGFS_DEL(dtim_period
, ap
);
311 DEBUGFS_DEL(dtim_count
, ap
);
312 DEBUGFS_DEL(num_beacons
, ap
);
313 DEBUGFS_DEL(force_unicast_rateidx
, ap
);
314 DEBUGFS_DEL(max_ratectrl_rateidx
, ap
);
315 DEBUGFS_DEL(num_buffered_multicast
, ap
);
316 DEBUGFS_DEL(beacon_head_len
, ap
);
317 DEBUGFS_DEL(beacon_tail_len
, ap
);
320 static void del_wds_files(struct ieee80211_sub_if_data
*sdata
)
322 DEBUGFS_DEL(channel_use
, wds
);
323 DEBUGFS_DEL(drop_unencrypted
, wds
);
324 DEBUGFS_DEL(eapol
, wds
);
325 DEBUGFS_DEL(ieee8021_x
, wds
);
326 DEBUGFS_DEL(peer
, wds
);
329 static void del_vlan_files(struct ieee80211_sub_if_data
*sdata
)
331 DEBUGFS_DEL(channel_use
, vlan
);
332 DEBUGFS_DEL(drop_unencrypted
, vlan
);
333 DEBUGFS_DEL(eapol
, vlan
);
334 DEBUGFS_DEL(ieee8021_x
, vlan
);
335 DEBUGFS_DEL(vlan_id
, vlan
);
338 static void del_monitor_files(struct ieee80211_sub_if_data
*sdata
)
340 DEBUGFS_DEL(mode
, monitor
);
343 static void del_files(struct ieee80211_sub_if_data
*sdata
, int type
)
345 if (!sdata
->debugfsdir
)
349 case IEEE80211_IF_TYPE_STA
:
350 case IEEE80211_IF_TYPE_IBSS
:
351 del_sta_files(sdata
);
353 case IEEE80211_IF_TYPE_AP
:
356 case IEEE80211_IF_TYPE_WDS
:
357 del_wds_files(sdata
);
359 case IEEE80211_IF_TYPE_MNTR
:
360 del_monitor_files(sdata
);
362 case IEEE80211_IF_TYPE_VLAN
:
363 del_vlan_files(sdata
);
370 static int notif_registered
;
372 void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data
*sdata
)
374 char buf
[10+IFNAMSIZ
];
376 if (!notif_registered
)
379 sprintf(buf
, "netdev:%s", sdata
->dev
->name
);
380 sdata
->debugfsdir
= debugfs_create_dir(buf
,
381 sdata
->local
->hw
.wiphy
->debugfsdir
);
384 void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data
*sdata
)
386 del_files(sdata
, sdata
->type
);
387 debugfs_remove(sdata
->debugfsdir
);
388 sdata
->debugfsdir
= NULL
;
391 void ieee80211_debugfs_change_if_type(struct ieee80211_sub_if_data
*sdata
,
394 del_files(sdata
, oldtype
);
398 static int netdev_notify(struct notifier_block
* nb
,
402 struct net_device
*dev
= ndev
;
404 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
405 char buf
[10+IFNAMSIZ
];
407 if (state
!= NETDEV_CHANGENAME
)
410 if (!dev
->ieee80211_ptr
|| !dev
->ieee80211_ptr
->wiphy
)
413 if (dev
->ieee80211_ptr
->wiphy
->privid
!= mac80211_wiphy_privid
)
416 sprintf(buf
, "netdev:%s", dev
->name
);
417 dir
= sdata
->debugfsdir
;
418 if (!debugfs_rename(dir
->d_parent
, dir
, dir
->d_parent
, buf
))
419 printk(KERN_ERR
"mac80211: debugfs: failed to rename debugfs "
425 static struct notifier_block mac80211_debugfs_netdev_notifier
= {
426 .notifier_call
= netdev_notify
,
429 void ieee80211_debugfs_netdev_init(void)
433 err
= register_netdevice_notifier(&mac80211_debugfs_netdev_notifier
);
436 "mac80211: failed to install netdev notifier,"
437 " disabling per-netdev debugfs!\n");
439 notif_registered
= 1;
442 void ieee80211_debugfs_netdev_exit(void)
444 unregister_netdevice_notifier(&mac80211_debugfs_netdev_notifier
);
445 notif_registered
= 0;