blob: d2d3c076c8537ff8d7bf24f083e32ceca5164d60 [file] [log] [blame]
Jiri Bence9f207f2007-05-05 11:46:38 -07001/*
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{ \
Joe Perches0795af52007-10-03 17:59:30 -070069 DECLARE_MAC_BUF(mac); \
70 return scnprintf(buf, buflen, "%s\n", print_mac(mac, sdata->field));\
Jiri Bence9f207f2007-05-05 11:46:38 -070071}
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);
Johannes Bergce3edf6d02007-12-19 01:31:22 +010094IEEE80211_IF_FILE(ieee802_1x_pac, ieee802_1x_pac, DEC);
Jiri Bence9f207f2007-05-05 11:46:38 -070095
96/* STA/IBSS attributes */
97IEEE80211_IF_FILE(state, u.sta.state, DEC);
98IEEE80211_IF_FILE(bssid, u.sta.bssid, MAC);
99IEEE80211_IF_FILE(prev_bssid, u.sta.prev_bssid, MAC);
100IEEE80211_IF_FILE(ssid_len, u.sta.ssid_len, SIZE);
101IEEE80211_IF_FILE(aid, u.sta.aid, DEC);
102IEEE80211_IF_FILE(ap_capab, u.sta.ap_capab, HEX);
103IEEE80211_IF_FILE(capab, u.sta.capab, HEX);
104IEEE80211_IF_FILE(extra_ie_len, u.sta.extra_ie_len, SIZE);
105IEEE80211_IF_FILE(auth_tries, u.sta.auth_tries, DEC);
106IEEE80211_IF_FILE(assoc_tries, u.sta.assoc_tries, DEC);
107IEEE80211_IF_FILE(auth_algs, u.sta.auth_algs, HEX);
108IEEE80211_IF_FILE(auth_alg, u.sta.auth_alg, DEC);
109IEEE80211_IF_FILE(auth_transaction, u.sta.auth_transaction, DEC);
110
111static ssize_t ieee80211_if_fmt_flags(
112 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
113{
114 return scnprintf(buf, buflen, "%s%s%s%s%s%s%s\n",
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400115 sdata->u.sta.flags & IEEE80211_STA_SSID_SET ? "SSID\n" : "",
116 sdata->u.sta.flags & IEEE80211_STA_BSSID_SET ? "BSSID\n" : "",
117 sdata->u.sta.flags & IEEE80211_STA_PREV_BSSID_SET ? "prev BSSID\n" : "",
118 sdata->u.sta.flags & IEEE80211_STA_AUTHENTICATED ? "AUTH\n" : "",
119 sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED ? "ASSOC\n" : "",
120 sdata->u.sta.flags & IEEE80211_STA_PROBEREQ_POLL ? "PROBEREQ POLL\n" : "",
Jiri Slaby13262ff2007-08-28 17:01:54 -0400121 sdata->flags & IEEE80211_SDATA_USE_PROTECTION ? "CTS prot\n" : "");
Jiri Bence9f207f2007-05-05 11:46:38 -0700122}
123__IEEE80211_IF_FILE(flags);
124
125/* AP attributes */
126IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
127IEEE80211_IF_FILE(dtim_period, u.ap.dtim_period, DEC);
128IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC);
129IEEE80211_IF_FILE(num_beacons, u.ap.num_beacons, DEC);
130IEEE80211_IF_FILE(force_unicast_rateidx, u.ap.force_unicast_rateidx, DEC);
131IEEE80211_IF_FILE(max_ratectrl_rateidx, u.ap.max_ratectrl_rateidx, DEC);
132
133static ssize_t ieee80211_if_fmt_num_buffered_multicast(
134 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
135{
136 return scnprintf(buf, buflen, "%u\n",
137 skb_queue_len(&sdata->u.ap.ps_bc_buf));
138}
139__IEEE80211_IF_FILE(num_buffered_multicast);
140
141static ssize_t ieee80211_if_fmt_beacon_head_len(
142 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
143{
144 if (sdata->u.ap.beacon_head)
145 return scnprintf(buf, buflen, "%d\n",
146 sdata->u.ap.beacon_head_len);
147 return scnprintf(buf, buflen, "\n");
148}
149__IEEE80211_IF_FILE(beacon_head_len);
150
151static ssize_t ieee80211_if_fmt_beacon_tail_len(
152 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
153{
154 if (sdata->u.ap.beacon_tail)
155 return scnprintf(buf, buflen, "%d\n",
156 sdata->u.ap.beacon_tail_len);
157 return scnprintf(buf, buflen, "\n");
158}
159__IEEE80211_IF_FILE(beacon_tail_len);
160
161/* WDS attributes */
162IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
163
Jiri Bence9f207f2007-05-05 11:46:38 -0700164#define DEBUGFS_ADD(name, type)\
165 sdata->debugfs.type.name = debugfs_create_file(#name, 0444,\
166 sdata->debugfsdir, sdata, &name##_ops);
167
168static void add_sta_files(struct ieee80211_sub_if_data *sdata)
169{
170 DEBUGFS_ADD(channel_use, sta);
171 DEBUGFS_ADD(drop_unencrypted, sta);
Johannes Bergce3edf6d02007-12-19 01:31:22 +0100172 DEBUGFS_ADD(ieee802_1x_pac, sta);
Jiri Bence9f207f2007-05-05 11:46:38 -0700173 DEBUGFS_ADD(state, sta);
174 DEBUGFS_ADD(bssid, sta);
175 DEBUGFS_ADD(prev_bssid, sta);
176 DEBUGFS_ADD(ssid_len, sta);
177 DEBUGFS_ADD(aid, sta);
178 DEBUGFS_ADD(ap_capab, sta);
179 DEBUGFS_ADD(capab, sta);
180 DEBUGFS_ADD(extra_ie_len, sta);
181 DEBUGFS_ADD(auth_tries, sta);
182 DEBUGFS_ADD(assoc_tries, sta);
183 DEBUGFS_ADD(auth_algs, sta);
184 DEBUGFS_ADD(auth_alg, sta);
185 DEBUGFS_ADD(auth_transaction, sta);
186 DEBUGFS_ADD(flags, sta);
187}
188
189static void add_ap_files(struct ieee80211_sub_if_data *sdata)
190{
191 DEBUGFS_ADD(channel_use, ap);
192 DEBUGFS_ADD(drop_unencrypted, ap);
Johannes Bergce3edf6d02007-12-19 01:31:22 +0100193 DEBUGFS_ADD(ieee802_1x_pac, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700194 DEBUGFS_ADD(num_sta_ps, ap);
195 DEBUGFS_ADD(dtim_period, ap);
196 DEBUGFS_ADD(dtim_count, ap);
197 DEBUGFS_ADD(num_beacons, ap);
198 DEBUGFS_ADD(force_unicast_rateidx, ap);
199 DEBUGFS_ADD(max_ratectrl_rateidx, ap);
200 DEBUGFS_ADD(num_buffered_multicast, ap);
201 DEBUGFS_ADD(beacon_head_len, ap);
202 DEBUGFS_ADD(beacon_tail_len, ap);
203}
204
205static void add_wds_files(struct ieee80211_sub_if_data *sdata)
206{
207 DEBUGFS_ADD(channel_use, wds);
208 DEBUGFS_ADD(drop_unencrypted, wds);
Johannes Bergce3edf6d02007-12-19 01:31:22 +0100209 DEBUGFS_ADD(ieee802_1x_pac, wds);
Jiri Bence9f207f2007-05-05 11:46:38 -0700210 DEBUGFS_ADD(peer, wds);
211}
212
213static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
214{
215 DEBUGFS_ADD(channel_use, vlan);
216 DEBUGFS_ADD(drop_unencrypted, vlan);
Johannes Bergce3edf6d02007-12-19 01:31:22 +0100217 DEBUGFS_ADD(ieee802_1x_pac, vlan);
Jiri Bence9f207f2007-05-05 11:46:38 -0700218}
219
220static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
221{
Jiri Bence9f207f2007-05-05 11:46:38 -0700222}
223
224static void add_files(struct ieee80211_sub_if_data *sdata)
225{
226 if (!sdata->debugfsdir)
227 return;
228
Johannes Berg51fb61e2007-12-19 01:31:27 +0100229 switch (sdata->vif.type) {
Jiri Bence9f207f2007-05-05 11:46:38 -0700230 case IEEE80211_IF_TYPE_STA:
231 case IEEE80211_IF_TYPE_IBSS:
232 add_sta_files(sdata);
233 break;
234 case IEEE80211_IF_TYPE_AP:
235 add_ap_files(sdata);
236 break;
237 case IEEE80211_IF_TYPE_WDS:
238 add_wds_files(sdata);
239 break;
240 case IEEE80211_IF_TYPE_MNTR:
241 add_monitor_files(sdata);
242 break;
243 case IEEE80211_IF_TYPE_VLAN:
244 add_vlan_files(sdata);
245 break;
246 default:
247 break;
248 }
249}
250
Zhu Yi21887b22007-07-27 15:43:23 +0200251#define DEBUGFS_DEL(name, type) \
252 do { \
253 debugfs_remove(sdata->debugfs.type.name); \
254 sdata->debugfs.type.name = NULL; \
255 } while (0)
Jiri Bence9f207f2007-05-05 11:46:38 -0700256
257static void del_sta_files(struct ieee80211_sub_if_data *sdata)
258{
259 DEBUGFS_DEL(channel_use, sta);
260 DEBUGFS_DEL(drop_unencrypted, sta);
Johannes Bergce3edf6d02007-12-19 01:31:22 +0100261 DEBUGFS_DEL(ieee802_1x_pac, sta);
Jiri Bence9f207f2007-05-05 11:46:38 -0700262 DEBUGFS_DEL(state, sta);
263 DEBUGFS_DEL(bssid, sta);
264 DEBUGFS_DEL(prev_bssid, sta);
265 DEBUGFS_DEL(ssid_len, sta);
266 DEBUGFS_DEL(aid, sta);
267 DEBUGFS_DEL(ap_capab, sta);
268 DEBUGFS_DEL(capab, sta);
269 DEBUGFS_DEL(extra_ie_len, sta);
270 DEBUGFS_DEL(auth_tries, sta);
271 DEBUGFS_DEL(assoc_tries, sta);
272 DEBUGFS_DEL(auth_algs, sta);
273 DEBUGFS_DEL(auth_alg, sta);
274 DEBUGFS_DEL(auth_transaction, sta);
275 DEBUGFS_DEL(flags, sta);
276}
277
278static void del_ap_files(struct ieee80211_sub_if_data *sdata)
279{
280 DEBUGFS_DEL(channel_use, ap);
281 DEBUGFS_DEL(drop_unencrypted, ap);
Johannes Bergce3edf6d02007-12-19 01:31:22 +0100282 DEBUGFS_DEL(ieee802_1x_pac, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700283 DEBUGFS_DEL(num_sta_ps, ap);
284 DEBUGFS_DEL(dtim_period, ap);
285 DEBUGFS_DEL(dtim_count, ap);
286 DEBUGFS_DEL(num_beacons, ap);
287 DEBUGFS_DEL(force_unicast_rateidx, ap);
288 DEBUGFS_DEL(max_ratectrl_rateidx, ap);
289 DEBUGFS_DEL(num_buffered_multicast, ap);
290 DEBUGFS_DEL(beacon_head_len, ap);
291 DEBUGFS_DEL(beacon_tail_len, ap);
292}
293
294static void del_wds_files(struct ieee80211_sub_if_data *sdata)
295{
296 DEBUGFS_DEL(channel_use, wds);
297 DEBUGFS_DEL(drop_unencrypted, wds);
Johannes Bergce3edf6d02007-12-19 01:31:22 +0100298 DEBUGFS_DEL(ieee802_1x_pac, wds);
Jiri Bence9f207f2007-05-05 11:46:38 -0700299 DEBUGFS_DEL(peer, wds);
300}
301
302static void del_vlan_files(struct ieee80211_sub_if_data *sdata)
303{
304 DEBUGFS_DEL(channel_use, vlan);
305 DEBUGFS_DEL(drop_unencrypted, vlan);
Johannes Bergce3edf6d02007-12-19 01:31:22 +0100306 DEBUGFS_DEL(ieee802_1x_pac, vlan);
Jiri Bence9f207f2007-05-05 11:46:38 -0700307}
308
309static void del_monitor_files(struct ieee80211_sub_if_data *sdata)
310{
Jiri Bence9f207f2007-05-05 11:46:38 -0700311}
312
313static void del_files(struct ieee80211_sub_if_data *sdata, int type)
314{
315 if (!sdata->debugfsdir)
316 return;
317
318 switch (type) {
319 case IEEE80211_IF_TYPE_STA:
320 case IEEE80211_IF_TYPE_IBSS:
321 del_sta_files(sdata);
322 break;
323 case IEEE80211_IF_TYPE_AP:
324 del_ap_files(sdata);
325 break;
326 case IEEE80211_IF_TYPE_WDS:
327 del_wds_files(sdata);
328 break;
329 case IEEE80211_IF_TYPE_MNTR:
330 del_monitor_files(sdata);
331 break;
332 case IEEE80211_IF_TYPE_VLAN:
333 del_vlan_files(sdata);
334 break;
335 default:
336 break;
337 }
338}
339
340static int notif_registered;
341
342void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
343{
344 char buf[10+IFNAMSIZ];
345
346 if (!notif_registered)
347 return;
348
349 sprintf(buf, "netdev:%s", sdata->dev->name);
350 sdata->debugfsdir = debugfs_create_dir(buf,
351 sdata->local->hw.wiphy->debugfsdir);
352}
353
354void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
355{
Johannes Berg51fb61e2007-12-19 01:31:27 +0100356 del_files(sdata, sdata->vif.type);
Jiri Bence9f207f2007-05-05 11:46:38 -0700357 debugfs_remove(sdata->debugfsdir);
358 sdata->debugfsdir = NULL;
359}
360
361void ieee80211_debugfs_change_if_type(struct ieee80211_sub_if_data *sdata,
362 int oldtype)
363{
364 del_files(sdata, oldtype);
365 add_files(sdata);
366}
367
368static int netdev_notify(struct notifier_block * nb,
369 unsigned long state,
370 void *ndev)
371{
372 struct net_device *dev = ndev;
Johannes Berg7c8081e2007-06-21 18:30:19 +0200373 struct dentry *dir;
374 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bence9f207f2007-05-05 11:46:38 -0700375 char buf[10+IFNAMSIZ];
376
377 if (state != NETDEV_CHANGENAME)
378 return 0;
379
380 if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
381 return 0;
382
383 if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
384 return 0;
385
Jiri Bence9f207f2007-05-05 11:46:38 -0700386 sprintf(buf, "netdev:%s", dev->name);
Johannes Berg7c8081e2007-06-21 18:30:19 +0200387 dir = sdata->debugfsdir;
388 if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
389 printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs "
390 "dir to %s\n", buf);
Jiri Bence9f207f2007-05-05 11:46:38 -0700391
392 return 0;
393}
394
395static struct notifier_block mac80211_debugfs_netdev_notifier = {
396 .notifier_call = netdev_notify,
397};
398
399void ieee80211_debugfs_netdev_init(void)
400{
401 int err;
402
403 err = register_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
404 if (err) {
405 printk(KERN_ERR
406 "mac80211: failed to install netdev notifier,"
407 " disabling per-netdev debugfs!\n");
408 } else
409 notif_registered = 1;
410}
411
412void ieee80211_debugfs_netdev_exit(void)
413{
414 unregister_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
415 notif_registered = 0;
416}