blob: b2089b2da48a2c6b0f6e963532335558109c4ecb [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"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040020#include "rate.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070021#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);
Luis Carlos Cobo73bb3e42008-03-31 15:10:22 -070034 if (sdata->dev->reg_state == NETREG_REGISTERED)
Jiri Bence9f207f2007-05-05 11:46:38 -070035 ret = (*format)(sdata, buf, sizeof(buf));
Jiri Bence9f207f2007-05-05 11:46:38 -070036 read_unlock(&dev_base_lock);
Luis Carlos Cobo73bb3e42008-03-31 15:10:22 -070037
38 if (ret != -EINVAL)
39 ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);
40
Jiri Bence9f207f2007-05-05 11:46:38 -070041 return ret;
42}
43
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +010044#ifdef CONFIG_MAC80211_MESH
45static ssize_t ieee80211_if_write(
46 struct ieee80211_sub_if_data *sdata,
47 char const __user *userbuf,
48 size_t count, loff_t *ppos,
49 int (*format)(struct ieee80211_sub_if_data *, char *))
50{
51 char buf[10];
52 int buf_size;
53
54 memset(buf, 0x00, sizeof(buf));
55 buf_size = min(count, (sizeof(buf)-1));
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +010056 if (copy_from_user(buf, userbuf, buf_size))
Luis Carlos Cobo73bb3e42008-03-31 15:10:22 -070057 return count;
58 read_lock(&dev_base_lock);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +010059 if (sdata->dev->reg_state == NETREG_REGISTERED)
60 (*format)(sdata, buf);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +010061 read_unlock(&dev_base_lock);
Luis Carlos Cobo73bb3e42008-03-31 15:10:22 -070062
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +010063 return count;
64}
65#endif
66
Jiri Bence9f207f2007-05-05 11:46:38 -070067#define IEEE80211_IF_FMT(name, field, format_string) \
68static ssize_t ieee80211_if_fmt_##name( \
69 const struct ieee80211_sub_if_data *sdata, char *buf, \
70 int buflen) \
71{ \
72 return scnprintf(buf, buflen, format_string, sdata->field); \
73}
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +010074#define IEEE80211_IF_WFMT(name, field, type) \
75static int ieee80211_if_wfmt_##name( \
76 struct ieee80211_sub_if_data *sdata, char *buf) \
77{ \
78 unsigned long tmp; \
79 char *endp; \
80 \
81 tmp = simple_strtoul(buf, &endp, 0); \
82 if ((endp == buf) || ((type)tmp != tmp)) \
83 return -EINVAL; \
84 sdata->field = tmp; \
85 return 0; \
86}
Jiri Bence9f207f2007-05-05 11:46:38 -070087#define IEEE80211_IF_FMT_DEC(name, field) \
88 IEEE80211_IF_FMT(name, field, "%d\n")
89#define IEEE80211_IF_FMT_HEX(name, field) \
90 IEEE80211_IF_FMT(name, field, "%#x\n")
91#define IEEE80211_IF_FMT_SIZE(name, field) \
92 IEEE80211_IF_FMT(name, field, "%zd\n")
93
94#define IEEE80211_IF_FMT_ATOMIC(name, field) \
95static ssize_t ieee80211_if_fmt_##name( \
96 const struct ieee80211_sub_if_data *sdata, \
97 char *buf, int buflen) \
98{ \
99 return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
100}
101
102#define IEEE80211_IF_FMT_MAC(name, field) \
103static ssize_t ieee80211_if_fmt_##name( \
104 const struct ieee80211_sub_if_data *sdata, char *buf, \
105 int buflen) \
106{ \
Joe Perches0795af52007-10-03 17:59:30 -0700107 DECLARE_MAC_BUF(mac); \
108 return scnprintf(buf, buflen, "%s\n", print_mac(mac, sdata->field));\
Jiri Bence9f207f2007-05-05 11:46:38 -0700109}
110
111#define __IEEE80211_IF_FILE(name) \
112static ssize_t ieee80211_if_read_##name(struct file *file, \
113 char __user *userbuf, \
114 size_t count, loff_t *ppos) \
115{ \
116 return ieee80211_if_read(file->private_data, \
117 userbuf, count, ppos, \
118 ieee80211_if_fmt_##name); \
119} \
120static const struct file_operations name##_ops = { \
121 .read = ieee80211_if_read_##name, \
122 .open = mac80211_open_file_generic, \
123}
124
125#define IEEE80211_IF_FILE(name, field, format) \
126 IEEE80211_IF_FMT_##format(name, field) \
127 __IEEE80211_IF_FILE(name)
128
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100129#define __IEEE80211_IF_WFILE(name) \
130static ssize_t ieee80211_if_read_##name(struct file *file, \
131 char __user *userbuf, \
132 size_t count, loff_t *ppos) \
133{ \
134 return ieee80211_if_read(file->private_data, \
135 userbuf, count, ppos, \
136 ieee80211_if_fmt_##name); \
137} \
138static ssize_t ieee80211_if_write_##name(struct file *file, \
139 const char __user *userbuf, \
140 size_t count, loff_t *ppos) \
141{ \
142 return ieee80211_if_write(file->private_data, \
143 userbuf, count, ppos, \
144 ieee80211_if_wfmt_##name); \
145} \
146static const struct file_operations name##_ops = { \
147 .read = ieee80211_if_read_##name, \
148 .write = ieee80211_if_write_##name, \
149 .open = mac80211_open_file_generic, \
150}
151
152#define IEEE80211_IF_WFILE(name, field, format, type) \
153 IEEE80211_IF_FMT_##format(name, field) \
154 IEEE80211_IF_WFMT(name, field, type) \
155 __IEEE80211_IF_WFILE(name)
156
Jiri Bence9f207f2007-05-05 11:46:38 -0700157/* common attributes */
Jiri Bence9f207f2007-05-05 11:46:38 -0700158IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC);
Jiri Bence9f207f2007-05-05 11:46:38 -0700159
160/* STA/IBSS attributes */
161IEEE80211_IF_FILE(state, u.sta.state, DEC);
162IEEE80211_IF_FILE(bssid, u.sta.bssid, MAC);
163IEEE80211_IF_FILE(prev_bssid, u.sta.prev_bssid, MAC);
164IEEE80211_IF_FILE(ssid_len, u.sta.ssid_len, SIZE);
165IEEE80211_IF_FILE(aid, u.sta.aid, DEC);
166IEEE80211_IF_FILE(ap_capab, u.sta.ap_capab, HEX);
167IEEE80211_IF_FILE(capab, u.sta.capab, HEX);
168IEEE80211_IF_FILE(extra_ie_len, u.sta.extra_ie_len, SIZE);
169IEEE80211_IF_FILE(auth_tries, u.sta.auth_tries, DEC);
170IEEE80211_IF_FILE(assoc_tries, u.sta.assoc_tries, DEC);
171IEEE80211_IF_FILE(auth_algs, u.sta.auth_algs, HEX);
172IEEE80211_IF_FILE(auth_alg, u.sta.auth_alg, DEC);
173IEEE80211_IF_FILE(auth_transaction, u.sta.auth_transaction, DEC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100174IEEE80211_IF_FILE(num_beacons_sta, u.sta.num_beacons, DEC);
Jiri Bence9f207f2007-05-05 11:46:38 -0700175
176static ssize_t ieee80211_if_fmt_flags(
177 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
178{
179 return scnprintf(buf, buflen, "%s%s%s%s%s%s%s\n",
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400180 sdata->u.sta.flags & IEEE80211_STA_SSID_SET ? "SSID\n" : "",
181 sdata->u.sta.flags & IEEE80211_STA_BSSID_SET ? "BSSID\n" : "",
182 sdata->u.sta.flags & IEEE80211_STA_PREV_BSSID_SET ? "prev BSSID\n" : "",
183 sdata->u.sta.flags & IEEE80211_STA_AUTHENTICATED ? "AUTH\n" : "",
184 sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED ? "ASSOC\n" : "",
185 sdata->u.sta.flags & IEEE80211_STA_PROBEREQ_POLL ? "PROBEREQ POLL\n" : "",
Johannes Berg471b3ef2007-12-28 14:32:58 +0100186 sdata->bss_conf.use_cts_prot ? "CTS prot\n" : "");
Jiri Bence9f207f2007-05-05 11:46:38 -0700187}
188__IEEE80211_IF_FILE(flags);
189
190/* AP attributes */
191IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
Jiri Bence9f207f2007-05-05 11:46:38 -0700192IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC);
193IEEE80211_IF_FILE(num_beacons, u.ap.num_beacons, DEC);
194IEEE80211_IF_FILE(force_unicast_rateidx, u.ap.force_unicast_rateidx, DEC);
195IEEE80211_IF_FILE(max_ratectrl_rateidx, u.ap.max_ratectrl_rateidx, DEC);
196
197static ssize_t ieee80211_if_fmt_num_buffered_multicast(
198 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
199{
200 return scnprintf(buf, buflen, "%u\n",
201 skb_queue_len(&sdata->u.ap.ps_bc_buf));
202}
203__IEEE80211_IF_FILE(num_buffered_multicast);
204
Jiri Bence9f207f2007-05-05 11:46:38 -0700205/* WDS attributes */
206IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
207
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100208#ifdef CONFIG_MAC80211_MESH
209/* Mesh stats attributes */
210IEEE80211_IF_FILE(fwded_frames, u.sta.mshstats.fwded_frames, DEC);
211IEEE80211_IF_FILE(dropped_frames_ttl, u.sta.mshstats.dropped_frames_ttl, DEC);
212IEEE80211_IF_FILE(dropped_frames_no_route,
213 u.sta.mshstats.dropped_frames_no_route, DEC);
214IEEE80211_IF_FILE(estab_plinks, u.sta.mshstats.estab_plinks, ATOMIC);
215
216/* Mesh parameters */
217IEEE80211_IF_WFILE(dot11MeshMaxRetries,
218 u.sta.mshcfg.dot11MeshMaxRetries, DEC, u8);
219IEEE80211_IF_WFILE(dot11MeshRetryTimeout,
220 u.sta.mshcfg.dot11MeshRetryTimeout, DEC, u16);
221IEEE80211_IF_WFILE(dot11MeshConfirmTimeout,
222 u.sta.mshcfg.dot11MeshConfirmTimeout, DEC, u16);
223IEEE80211_IF_WFILE(dot11MeshHoldingTimeout,
224 u.sta.mshcfg.dot11MeshHoldingTimeout, DEC, u16);
225IEEE80211_IF_WFILE(dot11MeshTTL, u.sta.mshcfg.dot11MeshTTL, DEC, u8);
Andrew Morton0675abd2008-03-27 23:25:27 -0700226IEEE80211_IF_WFILE(auto_open_plinks, u.sta.mshcfg.auto_open_plinks, DEC, u8);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100227IEEE80211_IF_WFILE(dot11MeshMaxPeerLinks,
228 u.sta.mshcfg.dot11MeshMaxPeerLinks, DEC, u16);
229IEEE80211_IF_WFILE(dot11MeshHWMPactivePathTimeout,
230 u.sta.mshcfg.dot11MeshHWMPactivePathTimeout, DEC, u32);
231IEEE80211_IF_WFILE(dot11MeshHWMPpreqMinInterval,
232 u.sta.mshcfg.dot11MeshHWMPpreqMinInterval, DEC, u16);
233IEEE80211_IF_WFILE(dot11MeshHWMPnetDiameterTraversalTime,
234 u.sta.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC, u16);
235IEEE80211_IF_WFILE(dot11MeshHWMPmaxPREQretries,
236 u.sta.mshcfg.dot11MeshHWMPmaxPREQretries, DEC, u8);
237IEEE80211_IF_WFILE(path_refresh_time,
238 u.sta.mshcfg.path_refresh_time, DEC, u32);
239IEEE80211_IF_WFILE(min_discovery_timeout,
240 u.sta.mshcfg.min_discovery_timeout, DEC, u16);
241#endif
242
243
Jiri Bence9f207f2007-05-05 11:46:38 -0700244#define DEBUGFS_ADD(name, type)\
Johannes Bergbebb8a52008-04-04 23:33:37 +0200245 sdata->debugfs.type.name = debugfs_create_file(#name, 0400,\
Jiri Bence9f207f2007-05-05 11:46:38 -0700246 sdata->debugfsdir, sdata, &name##_ops);
247
248static void add_sta_files(struct ieee80211_sub_if_data *sdata)
249{
Jiri Bence9f207f2007-05-05 11:46:38 -0700250 DEBUGFS_ADD(drop_unencrypted, sta);
Jiri Bence9f207f2007-05-05 11:46:38 -0700251 DEBUGFS_ADD(state, sta);
252 DEBUGFS_ADD(bssid, sta);
253 DEBUGFS_ADD(prev_bssid, sta);
254 DEBUGFS_ADD(ssid_len, sta);
255 DEBUGFS_ADD(aid, sta);
256 DEBUGFS_ADD(ap_capab, sta);
257 DEBUGFS_ADD(capab, sta);
258 DEBUGFS_ADD(extra_ie_len, sta);
259 DEBUGFS_ADD(auth_tries, sta);
260 DEBUGFS_ADD(assoc_tries, sta);
261 DEBUGFS_ADD(auth_algs, sta);
262 DEBUGFS_ADD(auth_alg, sta);
263 DEBUGFS_ADD(auth_transaction, sta);
264 DEBUGFS_ADD(flags, sta);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100265 DEBUGFS_ADD(num_beacons_sta, sta);
Jiri Bence9f207f2007-05-05 11:46:38 -0700266}
267
268static void add_ap_files(struct ieee80211_sub_if_data *sdata)
269{
Jiri Bence9f207f2007-05-05 11:46:38 -0700270 DEBUGFS_ADD(drop_unencrypted, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700271 DEBUGFS_ADD(num_sta_ps, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700272 DEBUGFS_ADD(dtim_count, ap);
273 DEBUGFS_ADD(num_beacons, ap);
274 DEBUGFS_ADD(force_unicast_rateidx, ap);
275 DEBUGFS_ADD(max_ratectrl_rateidx, ap);
276 DEBUGFS_ADD(num_buffered_multicast, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700277}
278
279static void add_wds_files(struct ieee80211_sub_if_data *sdata)
280{
Jiri Bence9f207f2007-05-05 11:46:38 -0700281 DEBUGFS_ADD(drop_unencrypted, wds);
Jiri Bence9f207f2007-05-05 11:46:38 -0700282 DEBUGFS_ADD(peer, wds);
283}
284
285static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
286{
Jiri Bence9f207f2007-05-05 11:46:38 -0700287 DEBUGFS_ADD(drop_unencrypted, vlan);
Jiri Bence9f207f2007-05-05 11:46:38 -0700288}
289
290static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
291{
Jiri Bence9f207f2007-05-05 11:46:38 -0700292}
293
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100294#ifdef CONFIG_MAC80211_MESH
295#define MESHSTATS_ADD(name)\
Johannes Bergbebb8a52008-04-04 23:33:37 +0200296 sdata->mesh_stats.name = debugfs_create_file(#name, 0400,\
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100297 sdata->mesh_stats_dir, sdata, &name##_ops);
298
299static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
300{
301 sdata->mesh_stats_dir = debugfs_create_dir("mesh_stats",
302 sdata->debugfsdir);
303 MESHSTATS_ADD(fwded_frames);
304 MESHSTATS_ADD(dropped_frames_ttl);
305 MESHSTATS_ADD(dropped_frames_no_route);
306 MESHSTATS_ADD(estab_plinks);
307}
308
309#define MESHPARAMS_ADD(name)\
Johannes Bergbebb8a52008-04-04 23:33:37 +0200310 sdata->mesh_config.name = debugfs_create_file(#name, 0600,\
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100311 sdata->mesh_config_dir, sdata, &name##_ops);
312
313static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
314{
315 sdata->mesh_config_dir = debugfs_create_dir("mesh_config",
316 sdata->debugfsdir);
317 MESHPARAMS_ADD(dot11MeshMaxRetries);
318 MESHPARAMS_ADD(dot11MeshRetryTimeout);
319 MESHPARAMS_ADD(dot11MeshConfirmTimeout);
320 MESHPARAMS_ADD(dot11MeshHoldingTimeout);
321 MESHPARAMS_ADD(dot11MeshTTL);
322 MESHPARAMS_ADD(auto_open_plinks);
323 MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
324 MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
325 MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
326 MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
327 MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
328 MESHPARAMS_ADD(path_refresh_time);
329 MESHPARAMS_ADD(min_discovery_timeout);
330}
331#endif
332
Jiri Bence9f207f2007-05-05 11:46:38 -0700333static void add_files(struct ieee80211_sub_if_data *sdata)
334{
335 if (!sdata->debugfsdir)
336 return;
337
Johannes Berg51fb61e2007-12-19 01:31:27 +0100338 switch (sdata->vif.type) {
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100339 case IEEE80211_IF_TYPE_MESH_POINT:
340#ifdef CONFIG_MAC80211_MESH
341 add_mesh_stats(sdata);
342 add_mesh_config(sdata);
343#endif
344 /* fall through */
Jiri Bence9f207f2007-05-05 11:46:38 -0700345 case IEEE80211_IF_TYPE_STA:
346 case IEEE80211_IF_TYPE_IBSS:
347 add_sta_files(sdata);
348 break;
349 case IEEE80211_IF_TYPE_AP:
350 add_ap_files(sdata);
351 break;
352 case IEEE80211_IF_TYPE_WDS:
353 add_wds_files(sdata);
354 break;
355 case IEEE80211_IF_TYPE_MNTR:
356 add_monitor_files(sdata);
357 break;
358 case IEEE80211_IF_TYPE_VLAN:
359 add_vlan_files(sdata);
360 break;
361 default:
362 break;
363 }
364}
365
Zhu Yi21887b22007-07-27 15:43:23 +0200366#define DEBUGFS_DEL(name, type) \
367 do { \
368 debugfs_remove(sdata->debugfs.type.name); \
369 sdata->debugfs.type.name = NULL; \
370 } while (0)
Jiri Bence9f207f2007-05-05 11:46:38 -0700371
372static void del_sta_files(struct ieee80211_sub_if_data *sdata)
373{
Jiri Bence9f207f2007-05-05 11:46:38 -0700374 DEBUGFS_DEL(drop_unencrypted, sta);
Jiri Bence9f207f2007-05-05 11:46:38 -0700375 DEBUGFS_DEL(state, sta);
376 DEBUGFS_DEL(bssid, sta);
377 DEBUGFS_DEL(prev_bssid, sta);
378 DEBUGFS_DEL(ssid_len, sta);
379 DEBUGFS_DEL(aid, sta);
380 DEBUGFS_DEL(ap_capab, sta);
381 DEBUGFS_DEL(capab, sta);
382 DEBUGFS_DEL(extra_ie_len, sta);
383 DEBUGFS_DEL(auth_tries, sta);
384 DEBUGFS_DEL(assoc_tries, sta);
385 DEBUGFS_DEL(auth_algs, sta);
386 DEBUGFS_DEL(auth_alg, sta);
387 DEBUGFS_DEL(auth_transaction, sta);
388 DEBUGFS_DEL(flags, sta);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100389 DEBUGFS_DEL(num_beacons_sta, sta);
Jiri Bence9f207f2007-05-05 11:46:38 -0700390}
391
392static void del_ap_files(struct ieee80211_sub_if_data *sdata)
393{
Jiri Bence9f207f2007-05-05 11:46:38 -0700394 DEBUGFS_DEL(drop_unencrypted, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700395 DEBUGFS_DEL(num_sta_ps, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700396 DEBUGFS_DEL(dtim_count, ap);
397 DEBUGFS_DEL(num_beacons, ap);
398 DEBUGFS_DEL(force_unicast_rateidx, ap);
399 DEBUGFS_DEL(max_ratectrl_rateidx, ap);
400 DEBUGFS_DEL(num_buffered_multicast, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700401}
402
403static void del_wds_files(struct ieee80211_sub_if_data *sdata)
404{
Jiri Bence9f207f2007-05-05 11:46:38 -0700405 DEBUGFS_DEL(drop_unencrypted, wds);
Jiri Bence9f207f2007-05-05 11:46:38 -0700406 DEBUGFS_DEL(peer, wds);
407}
408
409static void del_vlan_files(struct ieee80211_sub_if_data *sdata)
410{
Jiri Bence9f207f2007-05-05 11:46:38 -0700411 DEBUGFS_DEL(drop_unencrypted, vlan);
Jiri Bence9f207f2007-05-05 11:46:38 -0700412}
413
414static void del_monitor_files(struct ieee80211_sub_if_data *sdata)
415{
Jiri Bence9f207f2007-05-05 11:46:38 -0700416}
417
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100418#ifdef CONFIG_MAC80211_MESH
419#define MESHSTATS_DEL(name) \
420 do { \
421 debugfs_remove(sdata->mesh_stats.name); \
422 sdata->mesh_stats.name = NULL; \
423 } while (0)
424
425static void del_mesh_stats(struct ieee80211_sub_if_data *sdata)
426{
427 MESHSTATS_DEL(fwded_frames);
428 MESHSTATS_DEL(dropped_frames_ttl);
429 MESHSTATS_DEL(dropped_frames_no_route);
430 MESHSTATS_DEL(estab_plinks);
431 debugfs_remove(sdata->mesh_stats_dir);
432 sdata->mesh_stats_dir = NULL;
433}
434
435#define MESHPARAMS_DEL(name) \
436 do { \
437 debugfs_remove(sdata->mesh_config.name); \
438 sdata->mesh_config.name = NULL; \
439 } while (0)
440
441static void del_mesh_config(struct ieee80211_sub_if_data *sdata)
442{
443 MESHPARAMS_DEL(dot11MeshMaxRetries);
444 MESHPARAMS_DEL(dot11MeshRetryTimeout);
445 MESHPARAMS_DEL(dot11MeshConfirmTimeout);
446 MESHPARAMS_DEL(dot11MeshHoldingTimeout);
447 MESHPARAMS_DEL(dot11MeshTTL);
448 MESHPARAMS_DEL(auto_open_plinks);
449 MESHPARAMS_DEL(dot11MeshMaxPeerLinks);
450 MESHPARAMS_DEL(dot11MeshHWMPactivePathTimeout);
451 MESHPARAMS_DEL(dot11MeshHWMPpreqMinInterval);
452 MESHPARAMS_DEL(dot11MeshHWMPnetDiameterTraversalTime);
453 MESHPARAMS_DEL(dot11MeshHWMPmaxPREQretries);
454 MESHPARAMS_DEL(path_refresh_time);
455 MESHPARAMS_DEL(min_discovery_timeout);
456 debugfs_remove(sdata->mesh_config_dir);
457 sdata->mesh_config_dir = NULL;
458}
459#endif
460
Jiri Bence9f207f2007-05-05 11:46:38 -0700461static void del_files(struct ieee80211_sub_if_data *sdata, int type)
462{
463 if (!sdata->debugfsdir)
464 return;
465
466 switch (type) {
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100467 case IEEE80211_IF_TYPE_MESH_POINT:
468#ifdef CONFIG_MAC80211_MESH
469 del_mesh_stats(sdata);
470 del_mesh_config(sdata);
471#endif
472 /* fall through */
Jiri Bence9f207f2007-05-05 11:46:38 -0700473 case IEEE80211_IF_TYPE_STA:
474 case IEEE80211_IF_TYPE_IBSS:
475 del_sta_files(sdata);
476 break;
477 case IEEE80211_IF_TYPE_AP:
478 del_ap_files(sdata);
479 break;
480 case IEEE80211_IF_TYPE_WDS:
481 del_wds_files(sdata);
482 break;
483 case IEEE80211_IF_TYPE_MNTR:
484 del_monitor_files(sdata);
485 break;
486 case IEEE80211_IF_TYPE_VLAN:
487 del_vlan_files(sdata);
488 break;
489 default:
490 break;
491 }
492}
493
494static int notif_registered;
495
496void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
497{
498 char buf[10+IFNAMSIZ];
499
500 if (!notif_registered)
501 return;
502
503 sprintf(buf, "netdev:%s", sdata->dev->name);
504 sdata->debugfsdir = debugfs_create_dir(buf,
505 sdata->local->hw.wiphy->debugfsdir);
506}
507
508void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
509{
Johannes Berg51fb61e2007-12-19 01:31:27 +0100510 del_files(sdata, sdata->vif.type);
Jiri Bence9f207f2007-05-05 11:46:38 -0700511 debugfs_remove(sdata->debugfsdir);
512 sdata->debugfsdir = NULL;
513}
514
515void ieee80211_debugfs_change_if_type(struct ieee80211_sub_if_data *sdata,
516 int oldtype)
517{
518 del_files(sdata, oldtype);
519 add_files(sdata);
520}
521
Johannes Berg988c0f72008-04-17 19:21:22 +0200522static int netdev_notify(struct notifier_block *nb,
Jiri Bence9f207f2007-05-05 11:46:38 -0700523 unsigned long state,
524 void *ndev)
525{
526 struct net_device *dev = ndev;
Johannes Berg7c8081e2007-06-21 18:30:19 +0200527 struct dentry *dir;
528 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bence9f207f2007-05-05 11:46:38 -0700529 char buf[10+IFNAMSIZ];
530
531 if (state != NETDEV_CHANGENAME)
532 return 0;
533
534 if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
535 return 0;
536
537 if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
538 return 0;
539
Jiri Bence9f207f2007-05-05 11:46:38 -0700540 sprintf(buf, "netdev:%s", dev->name);
Johannes Berg7c8081e2007-06-21 18:30:19 +0200541 dir = sdata->debugfsdir;
542 if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
543 printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs "
544 "dir to %s\n", buf);
Jiri Bence9f207f2007-05-05 11:46:38 -0700545
546 return 0;
547}
548
549static struct notifier_block mac80211_debugfs_netdev_notifier = {
550 .notifier_call = netdev_notify,
551};
552
553void ieee80211_debugfs_netdev_init(void)
554{
555 int err;
556
557 err = register_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
558 if (err) {
559 printk(KERN_ERR
560 "mac80211: failed to install netdev notifier,"
561 " disabling per-netdev debugfs!\n");
562 } else
563 notif_registered = 1;
564}
565
566void ieee80211_debugfs_netdev_exit(void)
567{
568 unregister_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
569 notif_registered = 0;
570}