]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - net/mac80211/debugfs_netdev.c
[PATCH] mac80211: revamp interface and filter configuration
[mirror_ubuntu-hirsute-kernel.git] / net / mac80211 / debugfs_netdev.c
CommitLineData
e9f207f0
JB
1/*
2 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
3 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
4 *
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.
8 */
9
10#include <linux/kernel.h>
11#include <linux/device.h>
12#include <linux/if.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"
21#include "debugfs.h"
22#include "debugfs_netdev.h"
23
24static ssize_t ieee80211_if_read(
25 struct ieee80211_sub_if_data *sdata,
26 char __user *userbuf,
27 size_t count, loff_t *ppos,
28 ssize_t (*format)(const struct ieee80211_sub_if_data *, char *, int))
29{
30 char buf[70];
31 ssize_t ret = -EINVAL;
32
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);
37 }
38 read_unlock(&dev_base_lock);
39 return ret;
40}
41
42#define IEEE80211_IF_FMT(name, field, format_string) \
43static ssize_t ieee80211_if_fmt_##name( \
44 const struct ieee80211_sub_if_data *sdata, char *buf, \
45 int buflen) \
46{ \
47 return scnprintf(buf, buflen, format_string, sdata->field); \
48}
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")
55
56#define IEEE80211_IF_FMT_ATOMIC(name, field) \
57static ssize_t ieee80211_if_fmt_##name( \
58 const struct ieee80211_sub_if_data *sdata, \
59 char *buf, int buflen) \
60{ \
61 return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
62}
63
64#define IEEE80211_IF_FMT_MAC(name, field) \
65static ssize_t ieee80211_if_fmt_##name( \
66 const struct ieee80211_sub_if_data *sdata, char *buf, \
67 int buflen) \
68{ \
0795af57
JP
69 DECLARE_MAC_BUF(mac); \
70 return scnprintf(buf, buflen, "%s\n", print_mac(mac, sdata->field));\
e9f207f0
JB
71}
72
73#define __IEEE80211_IF_FILE(name) \
74static ssize_t ieee80211_if_read_##name(struct file *file, \
75 char __user *userbuf, \
76 size_t count, loff_t *ppos) \
77{ \
78 return ieee80211_if_read(file->private_data, \
79 userbuf, count, ppos, \
80 ieee80211_if_fmt_##name); \
81} \
82static const struct file_operations name##_ops = { \
83 .read = ieee80211_if_read_##name, \
84 .open = mac80211_open_file_generic, \
85}
86
87#define IEEE80211_IF_FILE(name, field, format) \
88 IEEE80211_IF_FMT_##format(name, field) \
89 __IEEE80211_IF_FILE(name)
90
91/* common attributes */
92IEEE80211_IF_FILE(channel_use, channel_use, DEC);
93IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC);
94IEEE80211_IF_FILE(eapol, eapol, DEC);
95IEEE80211_IF_FILE(ieee8021_x, ieee802_1x, DEC);
96
97/* STA/IBSS attributes */
98IEEE80211_IF_FILE(state, u.sta.state, DEC);
99IEEE80211_IF_FILE(bssid, u.sta.bssid, MAC);
100IEEE80211_IF_FILE(prev_bssid, u.sta.prev_bssid, MAC);
101IEEE80211_IF_FILE(ssid_len, u.sta.ssid_len, SIZE);
102IEEE80211_IF_FILE(aid, u.sta.aid, DEC);
103IEEE80211_IF_FILE(ap_capab, u.sta.ap_capab, HEX);
104IEEE80211_IF_FILE(capab, u.sta.capab, HEX);
105IEEE80211_IF_FILE(extra_ie_len, u.sta.extra_ie_len, SIZE);
106IEEE80211_IF_FILE(auth_tries, u.sta.auth_tries, DEC);
107IEEE80211_IF_FILE(assoc_tries, u.sta.assoc_tries, DEC);
108IEEE80211_IF_FILE(auth_algs, u.sta.auth_algs, HEX);
109IEEE80211_IF_FILE(auth_alg, u.sta.auth_alg, DEC);
110IEEE80211_IF_FILE(auth_transaction, u.sta.auth_transaction, DEC);
111
112static ssize_t ieee80211_if_fmt_flags(
113 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
114{
115 return scnprintf(buf, buflen, "%s%s%s%s%s%s%s\n",
d6f2da5b
JS
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" : "",
13262ffd 122 sdata->flags & IEEE80211_SDATA_USE_PROTECTION ? "CTS prot\n" : "");
e9f207f0
JB
123}
124__IEEE80211_IF_FILE(flags);
125
126/* AP attributes */
127IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
128IEEE80211_IF_FILE(dtim_period, u.ap.dtim_period, DEC);
129IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC);
130IEEE80211_IF_FILE(num_beacons, u.ap.num_beacons, DEC);
131IEEE80211_IF_FILE(force_unicast_rateidx, u.ap.force_unicast_rateidx, DEC);
132IEEE80211_IF_FILE(max_ratectrl_rateidx, u.ap.max_ratectrl_rateidx, DEC);
133
134static ssize_t ieee80211_if_fmt_num_buffered_multicast(
135 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
136{
137 return scnprintf(buf, buflen, "%u\n",
138 skb_queue_len(&sdata->u.ap.ps_bc_buf));
139}
140__IEEE80211_IF_FILE(num_buffered_multicast);
141
142static ssize_t ieee80211_if_fmt_beacon_head_len(
143 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
144{
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");
149}
150__IEEE80211_IF_FILE(beacon_head_len);
151
152static ssize_t ieee80211_if_fmt_beacon_tail_len(
153 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
154{
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");
159}
160__IEEE80211_IF_FILE(beacon_tail_len);
161
162/* WDS attributes */
163IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
164
165/* VLAN attributes */
166IEEE80211_IF_FILE(vlan_id, u.vlan.id, DEC);
167
e9f207f0
JB
168#define DEBUGFS_ADD(name, type)\
169 sdata->debugfs.type.name = debugfs_create_file(#name, 0444,\
170 sdata->debugfsdir, sdata, &name##_ops);
171
172static void add_sta_files(struct ieee80211_sub_if_data *sdata)
173{
174 DEBUGFS_ADD(channel_use, sta);
175 DEBUGFS_ADD(drop_unencrypted, sta);
176 DEBUGFS_ADD(eapol, sta);
177 DEBUGFS_ADD(ieee8021_x, sta);
178 DEBUGFS_ADD(state, sta);
179 DEBUGFS_ADD(bssid, sta);
180 DEBUGFS_ADD(prev_bssid, sta);
181 DEBUGFS_ADD(ssid_len, sta);
182 DEBUGFS_ADD(aid, sta);
183 DEBUGFS_ADD(ap_capab, sta);
184 DEBUGFS_ADD(capab, sta);
185 DEBUGFS_ADD(extra_ie_len, sta);
186 DEBUGFS_ADD(auth_tries, sta);
187 DEBUGFS_ADD(assoc_tries, sta);
188 DEBUGFS_ADD(auth_algs, sta);
189 DEBUGFS_ADD(auth_alg, sta);
190 DEBUGFS_ADD(auth_transaction, sta);
191 DEBUGFS_ADD(flags, sta);
192}
193
194static void add_ap_files(struct ieee80211_sub_if_data *sdata)
195{
196 DEBUGFS_ADD(channel_use, ap);
197 DEBUGFS_ADD(drop_unencrypted, ap);
198 DEBUGFS_ADD(eapol, ap);
199 DEBUGFS_ADD(ieee8021_x, ap);
200 DEBUGFS_ADD(num_sta_ps, ap);
201 DEBUGFS_ADD(dtim_period, ap);
202 DEBUGFS_ADD(dtim_count, ap);
203 DEBUGFS_ADD(num_beacons, ap);
204 DEBUGFS_ADD(force_unicast_rateidx, ap);
205 DEBUGFS_ADD(max_ratectrl_rateidx, ap);
206 DEBUGFS_ADD(num_buffered_multicast, ap);
207 DEBUGFS_ADD(beacon_head_len, ap);
208 DEBUGFS_ADD(beacon_tail_len, ap);
209}
210
211static void add_wds_files(struct ieee80211_sub_if_data *sdata)
212{
213 DEBUGFS_ADD(channel_use, wds);
214 DEBUGFS_ADD(drop_unencrypted, wds);
215 DEBUGFS_ADD(eapol, wds);
216 DEBUGFS_ADD(ieee8021_x, wds);
217 DEBUGFS_ADD(peer, wds);
218}
219
220static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
221{
222 DEBUGFS_ADD(channel_use, vlan);
223 DEBUGFS_ADD(drop_unencrypted, vlan);
224 DEBUGFS_ADD(eapol, vlan);
225 DEBUGFS_ADD(ieee8021_x, vlan);
226 DEBUGFS_ADD(vlan_id, vlan);
227}
228
229static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
230{
e9f207f0
JB
231}
232
233static void add_files(struct ieee80211_sub_if_data *sdata)
234{
235 if (!sdata->debugfsdir)
236 return;
237
238 switch (sdata->type) {
239 case IEEE80211_IF_TYPE_STA:
240 case IEEE80211_IF_TYPE_IBSS:
241 add_sta_files(sdata);
242 break;
243 case IEEE80211_IF_TYPE_AP:
244 add_ap_files(sdata);
245 break;
246 case IEEE80211_IF_TYPE_WDS:
247 add_wds_files(sdata);
248 break;
249 case IEEE80211_IF_TYPE_MNTR:
250 add_monitor_files(sdata);
251 break;
252 case IEEE80211_IF_TYPE_VLAN:
253 add_vlan_files(sdata);
254 break;
255 default:
256 break;
257 }
258}
259
21887b2f
ZY
260#define DEBUGFS_DEL(name, type) \
261 do { \
262 debugfs_remove(sdata->debugfs.type.name); \
263 sdata->debugfs.type.name = NULL; \
264 } while (0)
e9f207f0
JB
265
266static void del_sta_files(struct ieee80211_sub_if_data *sdata)
267{
268 DEBUGFS_DEL(channel_use, sta);
269 DEBUGFS_DEL(drop_unencrypted, sta);
270 DEBUGFS_DEL(eapol, sta);
271 DEBUGFS_DEL(ieee8021_x, sta);
272 DEBUGFS_DEL(state, sta);
273 DEBUGFS_DEL(bssid, sta);
274 DEBUGFS_DEL(prev_bssid, sta);
275 DEBUGFS_DEL(ssid_len, sta);
276 DEBUGFS_DEL(aid, sta);
277 DEBUGFS_DEL(ap_capab, sta);
278 DEBUGFS_DEL(capab, sta);
279 DEBUGFS_DEL(extra_ie_len, sta);
280 DEBUGFS_DEL(auth_tries, sta);
281 DEBUGFS_DEL(assoc_tries, sta);
282 DEBUGFS_DEL(auth_algs, sta);
283 DEBUGFS_DEL(auth_alg, sta);
284 DEBUGFS_DEL(auth_transaction, sta);
285 DEBUGFS_DEL(flags, sta);
286}
287
288static void del_ap_files(struct ieee80211_sub_if_data *sdata)
289{
290 DEBUGFS_DEL(channel_use, ap);
291 DEBUGFS_DEL(drop_unencrypted, ap);
292 DEBUGFS_DEL(eapol, ap);
293 DEBUGFS_DEL(ieee8021_x, ap);
294 DEBUGFS_DEL(num_sta_ps, ap);
295 DEBUGFS_DEL(dtim_period, ap);
296 DEBUGFS_DEL(dtim_count, ap);
297 DEBUGFS_DEL(num_beacons, ap);
298 DEBUGFS_DEL(force_unicast_rateidx, ap);
299 DEBUGFS_DEL(max_ratectrl_rateidx, ap);
300 DEBUGFS_DEL(num_buffered_multicast, ap);
301 DEBUGFS_DEL(beacon_head_len, ap);
302 DEBUGFS_DEL(beacon_tail_len, ap);
303}
304
305static void del_wds_files(struct ieee80211_sub_if_data *sdata)
306{
307 DEBUGFS_DEL(channel_use, wds);
308 DEBUGFS_DEL(drop_unencrypted, wds);
309 DEBUGFS_DEL(eapol, wds);
310 DEBUGFS_DEL(ieee8021_x, wds);
311 DEBUGFS_DEL(peer, wds);
312}
313
314static void del_vlan_files(struct ieee80211_sub_if_data *sdata)
315{
316 DEBUGFS_DEL(channel_use, vlan);
317 DEBUGFS_DEL(drop_unencrypted, vlan);
318 DEBUGFS_DEL(eapol, vlan);
319 DEBUGFS_DEL(ieee8021_x, vlan);
320 DEBUGFS_DEL(vlan_id, vlan);
321}
322
323static void del_monitor_files(struct ieee80211_sub_if_data *sdata)
324{
e9f207f0
JB
325}
326
327static void del_files(struct ieee80211_sub_if_data *sdata, int type)
328{
329 if (!sdata->debugfsdir)
330 return;
331
332 switch (type) {
333 case IEEE80211_IF_TYPE_STA:
334 case IEEE80211_IF_TYPE_IBSS:
335 del_sta_files(sdata);
336 break;
337 case IEEE80211_IF_TYPE_AP:
338 del_ap_files(sdata);
339 break;
340 case IEEE80211_IF_TYPE_WDS:
341 del_wds_files(sdata);
342 break;
343 case IEEE80211_IF_TYPE_MNTR:
344 del_monitor_files(sdata);
345 break;
346 case IEEE80211_IF_TYPE_VLAN:
347 del_vlan_files(sdata);
348 break;
349 default:
350 break;
351 }
352}
353
354static int notif_registered;
355
356void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
357{
358 char buf[10+IFNAMSIZ];
359
360 if (!notif_registered)
361 return;
362
363 sprintf(buf, "netdev:%s", sdata->dev->name);
364 sdata->debugfsdir = debugfs_create_dir(buf,
365 sdata->local->hw.wiphy->debugfsdir);
366}
367
368void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
369{
370 del_files(sdata, sdata->type);
371 debugfs_remove(sdata->debugfsdir);
372 sdata->debugfsdir = NULL;
373}
374
375void ieee80211_debugfs_change_if_type(struct ieee80211_sub_if_data *sdata,
376 int oldtype)
377{
378 del_files(sdata, oldtype);
379 add_files(sdata);
380}
381
382static int netdev_notify(struct notifier_block * nb,
383 unsigned long state,
384 void *ndev)
385{
386 struct net_device *dev = ndev;
7c8081eb
JB
387 struct dentry *dir;
388 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
e9f207f0
JB
389 char buf[10+IFNAMSIZ];
390
391 if (state != NETDEV_CHANGENAME)
392 return 0;
393
394 if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
395 return 0;
396
397 if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
398 return 0;
399
e9f207f0 400 sprintf(buf, "netdev:%s", dev->name);
7c8081eb
JB
401 dir = sdata->debugfsdir;
402 if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
403 printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs "
404 "dir to %s\n", buf);
e9f207f0
JB
405
406 return 0;
407}
408
409static struct notifier_block mac80211_debugfs_netdev_notifier = {
410 .notifier_call = netdev_notify,
411};
412
413void ieee80211_debugfs_netdev_init(void)
414{
415 int err;
416
417 err = register_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
418 if (err) {
419 printk(KERN_ERR
420 "mac80211: failed to install netdev notifier,"
421 " disabling per-netdev debugfs!\n");
422 } else
423 notif_registered = 1;
424}
425
426void ieee80211_debugfs_netdev_exit(void)
427{
428 unregister_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
429 notif_registered = 0;
430}