blob: c54219301724e1198c824294550edf77d7cc6bdb [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
44#define IEEE80211_IF_FMT(name, field, format_string) \
45static ssize_t ieee80211_if_fmt_##name( \
46 const struct ieee80211_sub_if_data *sdata, char *buf, \
47 int buflen) \
48{ \
49 return scnprintf(buf, buflen, format_string, sdata->field); \
50}
51#define IEEE80211_IF_FMT_DEC(name, field) \
52 IEEE80211_IF_FMT(name, field, "%d\n")
53#define IEEE80211_IF_FMT_HEX(name, field) \
54 IEEE80211_IF_FMT(name, field, "%#x\n")
55#define IEEE80211_IF_FMT_SIZE(name, field) \
56 IEEE80211_IF_FMT(name, field, "%zd\n")
57
58#define IEEE80211_IF_FMT_ATOMIC(name, field) \
59static ssize_t ieee80211_if_fmt_##name( \
60 const struct ieee80211_sub_if_data *sdata, \
61 char *buf, int buflen) \
62{ \
63 return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
64}
65
66#define IEEE80211_IF_FMT_MAC(name, field) \
67static ssize_t ieee80211_if_fmt_##name( \
68 const struct ieee80211_sub_if_data *sdata, char *buf, \
69 int buflen) \
70{ \
Johannes Berg0c68ae262008-10-27 15:56:10 -070071 return scnprintf(buf, buflen, "%pM\n", sdata->field); \
Jiri Bence9f207f2007-05-05 11:46:38 -070072}
73
74#define __IEEE80211_IF_FILE(name) \
75static ssize_t ieee80211_if_read_##name(struct file *file, \
76 char __user *userbuf, \
77 size_t count, loff_t *ppos) \
78{ \
79 return ieee80211_if_read(file->private_data, \
80 userbuf, count, ppos, \
81 ieee80211_if_fmt_##name); \
82} \
83static const struct file_operations name##_ops = { \
84 .read = ieee80211_if_read_##name, \
85 .open = mac80211_open_file_generic, \
86}
87
88#define IEEE80211_IF_FILE(name, field, format) \
89 IEEE80211_IF_FMT_##format(name, field) \
90 __IEEE80211_IF_FILE(name)
91
92/* common attributes */
Jiri Bence9f207f2007-05-05 11:46:38 -070093IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC);
Johannes Berg3e122be2008-07-09 14:40:34 +020094IEEE80211_IF_FILE(force_unicast_rateidx, force_unicast_rateidx, DEC);
95IEEE80211_IF_FILE(max_ratectrl_rateidx, max_ratectrl_rateidx, DEC);
Jiri Bence9f207f2007-05-05 11:46:38 -070096
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",
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400116 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" : "",
Johannes Bergbda39332008-10-11 01:51:51 +0200122 sdata->vif.bss_conf.use_cts_prot ? "CTS prot\n" : "");
Jiri Bence9f207f2007-05-05 11:46:38 -0700123}
124__IEEE80211_IF_FILE(flags);
125
126/* AP attributes */
127IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
Jiri Bence9f207f2007-05-05 11:46:38 -0700128IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC);
Jiri Bence9f207f2007-05-05 11:46:38 -0700129
130static ssize_t ieee80211_if_fmt_num_buffered_multicast(
131 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
132{
133 return scnprintf(buf, buflen, "%u\n",
134 skb_queue_len(&sdata->u.ap.ps_bc_buf));
135}
136__IEEE80211_IF_FILE(num_buffered_multicast);
137
Jiri Bence9f207f2007-05-05 11:46:38 -0700138/* WDS attributes */
139IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
140
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100141#ifdef CONFIG_MAC80211_MESH
142/* Mesh stats attributes */
Johannes Berg472dbc42008-09-11 00:01:49 +0200143IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
144IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100145IEEE80211_IF_FILE(dropped_frames_no_route,
Johannes Berg472dbc42008-09-11 00:01:49 +0200146 u.mesh.mshstats.dropped_frames_no_route, DEC);
147IEEE80211_IF_FILE(estab_plinks, u.mesh.mshstats.estab_plinks, ATOMIC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100148
149/* Mesh parameters */
Johannes Berg36ff3822008-10-07 12:04:31 +0200150IEEE80211_IF_FILE(dot11MeshMaxRetries,
151 u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
152IEEE80211_IF_FILE(dot11MeshRetryTimeout,
153 u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
154IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
155 u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
156IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
157 u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
158IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
159IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
160IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
161 u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
162IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
163 u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
164IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
165 u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
166IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
167 u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
168IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
169 u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
170IEEE80211_IF_FILE(path_refresh_time,
171 u.mesh.mshcfg.path_refresh_time, DEC);
172IEEE80211_IF_FILE(min_discovery_timeout,
173 u.mesh.mshcfg.min_discovery_timeout, DEC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100174#endif
175
176
Jiri Bence9f207f2007-05-05 11:46:38 -0700177#define DEBUGFS_ADD(name, type)\
Johannes Bergbebb8a52008-04-04 23:33:37 +0200178 sdata->debugfs.type.name = debugfs_create_file(#name, 0400,\
Jiri Bence9f207f2007-05-05 11:46:38 -0700179 sdata->debugfsdir, sdata, &name##_ops);
180
181static void add_sta_files(struct ieee80211_sub_if_data *sdata)
182{
Jiri Bence9f207f2007-05-05 11:46:38 -0700183 DEBUGFS_ADD(drop_unencrypted, sta);
Jouni Malinen93015f02008-08-25 11:57:06 +0300184 DEBUGFS_ADD(force_unicast_rateidx, sta);
185 DEBUGFS_ADD(max_ratectrl_rateidx, sta);
Johannes Berg3e122be2008-07-09 14:40:34 +0200186
Jiri Bence9f207f2007-05-05 11:46:38 -0700187 DEBUGFS_ADD(state, sta);
188 DEBUGFS_ADD(bssid, sta);
189 DEBUGFS_ADD(prev_bssid, sta);
190 DEBUGFS_ADD(ssid_len, sta);
191 DEBUGFS_ADD(aid, sta);
192 DEBUGFS_ADD(ap_capab, sta);
193 DEBUGFS_ADD(capab, sta);
194 DEBUGFS_ADD(extra_ie_len, sta);
195 DEBUGFS_ADD(auth_tries, sta);
196 DEBUGFS_ADD(assoc_tries, sta);
197 DEBUGFS_ADD(auth_algs, sta);
198 DEBUGFS_ADD(auth_alg, sta);
199 DEBUGFS_ADD(auth_transaction, sta);
200 DEBUGFS_ADD(flags, sta);
201}
202
203static void add_ap_files(struct ieee80211_sub_if_data *sdata)
204{
Jiri Bence9f207f2007-05-05 11:46:38 -0700205 DEBUGFS_ADD(drop_unencrypted, ap);
Johannes Berg3e122be2008-07-09 14:40:34 +0200206 DEBUGFS_ADD(force_unicast_rateidx, ap);
207 DEBUGFS_ADD(max_ratectrl_rateidx, ap);
208
Jiri Bence9f207f2007-05-05 11:46:38 -0700209 DEBUGFS_ADD(num_sta_ps, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700210 DEBUGFS_ADD(dtim_count, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700211 DEBUGFS_ADD(num_buffered_multicast, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700212}
213
214static void add_wds_files(struct ieee80211_sub_if_data *sdata)
215{
Jiri Bence9f207f2007-05-05 11:46:38 -0700216 DEBUGFS_ADD(drop_unencrypted, wds);
Jouni Malinen93015f02008-08-25 11:57:06 +0300217 DEBUGFS_ADD(force_unicast_rateidx, wds);
218 DEBUGFS_ADD(max_ratectrl_rateidx, wds);
Johannes Berg3e122be2008-07-09 14:40:34 +0200219
Jiri Bence9f207f2007-05-05 11:46:38 -0700220 DEBUGFS_ADD(peer, wds);
221}
222
223static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
224{
Jiri Bence9f207f2007-05-05 11:46:38 -0700225 DEBUGFS_ADD(drop_unencrypted, vlan);
Jouni Malinen93015f02008-08-25 11:57:06 +0300226 DEBUGFS_ADD(force_unicast_rateidx, vlan);
227 DEBUGFS_ADD(max_ratectrl_rateidx, vlan);
Jiri Bence9f207f2007-05-05 11:46:38 -0700228}
229
230static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
231{
Jiri Bence9f207f2007-05-05 11:46:38 -0700232}
233
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100234#ifdef CONFIG_MAC80211_MESH
235#define MESHSTATS_ADD(name)\
Johannes Bergbebb8a52008-04-04 23:33:37 +0200236 sdata->mesh_stats.name = debugfs_create_file(#name, 0400,\
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100237 sdata->mesh_stats_dir, sdata, &name##_ops);
238
239static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
240{
241 sdata->mesh_stats_dir = debugfs_create_dir("mesh_stats",
242 sdata->debugfsdir);
243 MESHSTATS_ADD(fwded_frames);
244 MESHSTATS_ADD(dropped_frames_ttl);
245 MESHSTATS_ADD(dropped_frames_no_route);
246 MESHSTATS_ADD(estab_plinks);
247}
248
249#define MESHPARAMS_ADD(name)\
Johannes Bergbebb8a52008-04-04 23:33:37 +0200250 sdata->mesh_config.name = debugfs_create_file(#name, 0600,\
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100251 sdata->mesh_config_dir, sdata, &name##_ops);
252
253static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
254{
255 sdata->mesh_config_dir = debugfs_create_dir("mesh_config",
256 sdata->debugfsdir);
257 MESHPARAMS_ADD(dot11MeshMaxRetries);
258 MESHPARAMS_ADD(dot11MeshRetryTimeout);
259 MESHPARAMS_ADD(dot11MeshConfirmTimeout);
260 MESHPARAMS_ADD(dot11MeshHoldingTimeout);
261 MESHPARAMS_ADD(dot11MeshTTL);
262 MESHPARAMS_ADD(auto_open_plinks);
263 MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
264 MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
265 MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
266 MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
267 MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
268 MESHPARAMS_ADD(path_refresh_time);
269 MESHPARAMS_ADD(min_discovery_timeout);
270}
271#endif
272
Jiri Bence9f207f2007-05-05 11:46:38 -0700273static void add_files(struct ieee80211_sub_if_data *sdata)
274{
275 if (!sdata->debugfsdir)
276 return;
277
Johannes Berg51fb61e2007-12-19 01:31:27 +0100278 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200279 case NL80211_IFTYPE_MESH_POINT:
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100280#ifdef CONFIG_MAC80211_MESH
281 add_mesh_stats(sdata);
282 add_mesh_config(sdata);
283#endif
Johannes Berg472dbc42008-09-11 00:01:49 +0200284 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200285 case NL80211_IFTYPE_STATION:
286 case NL80211_IFTYPE_ADHOC:
Jiri Bence9f207f2007-05-05 11:46:38 -0700287 add_sta_files(sdata);
288 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200289 case NL80211_IFTYPE_AP:
Jiri Bence9f207f2007-05-05 11:46:38 -0700290 add_ap_files(sdata);
291 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200292 case NL80211_IFTYPE_WDS:
Jiri Bence9f207f2007-05-05 11:46:38 -0700293 add_wds_files(sdata);
294 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200295 case NL80211_IFTYPE_MONITOR:
Jiri Bence9f207f2007-05-05 11:46:38 -0700296 add_monitor_files(sdata);
297 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200298 case NL80211_IFTYPE_AP_VLAN:
Jiri Bence9f207f2007-05-05 11:46:38 -0700299 add_vlan_files(sdata);
300 break;
301 default:
302 break;
303 }
304}
305
Zhu Yi21887b22007-07-27 15:43:23 +0200306#define DEBUGFS_DEL(name, type) \
307 do { \
308 debugfs_remove(sdata->debugfs.type.name); \
309 sdata->debugfs.type.name = NULL; \
310 } while (0)
Jiri Bence9f207f2007-05-05 11:46:38 -0700311
312static void del_sta_files(struct ieee80211_sub_if_data *sdata)
313{
Jiri Bence9f207f2007-05-05 11:46:38 -0700314 DEBUGFS_DEL(drop_unencrypted, sta);
Jouni Malinen93015f02008-08-25 11:57:06 +0300315 DEBUGFS_DEL(force_unicast_rateidx, sta);
316 DEBUGFS_DEL(max_ratectrl_rateidx, sta);
Johannes Berg3e122be2008-07-09 14:40:34 +0200317
Jiri Bence9f207f2007-05-05 11:46:38 -0700318 DEBUGFS_DEL(state, sta);
319 DEBUGFS_DEL(bssid, sta);
320 DEBUGFS_DEL(prev_bssid, sta);
321 DEBUGFS_DEL(ssid_len, sta);
322 DEBUGFS_DEL(aid, sta);
323 DEBUGFS_DEL(ap_capab, sta);
324 DEBUGFS_DEL(capab, sta);
325 DEBUGFS_DEL(extra_ie_len, sta);
326 DEBUGFS_DEL(auth_tries, sta);
327 DEBUGFS_DEL(assoc_tries, sta);
328 DEBUGFS_DEL(auth_algs, sta);
329 DEBUGFS_DEL(auth_alg, sta);
330 DEBUGFS_DEL(auth_transaction, sta);
331 DEBUGFS_DEL(flags, sta);
332}
333
334static void del_ap_files(struct ieee80211_sub_if_data *sdata)
335{
Jiri Bence9f207f2007-05-05 11:46:38 -0700336 DEBUGFS_DEL(drop_unencrypted, ap);
Johannes Berg3e122be2008-07-09 14:40:34 +0200337 DEBUGFS_DEL(force_unicast_rateidx, ap);
338 DEBUGFS_DEL(max_ratectrl_rateidx, ap);
339
Jiri Bence9f207f2007-05-05 11:46:38 -0700340 DEBUGFS_DEL(num_sta_ps, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700341 DEBUGFS_DEL(dtim_count, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700342 DEBUGFS_DEL(num_buffered_multicast, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700343}
344
345static void del_wds_files(struct ieee80211_sub_if_data *sdata)
346{
Jiri Bence9f207f2007-05-05 11:46:38 -0700347 DEBUGFS_DEL(drop_unencrypted, wds);
Jouni Malinen93015f02008-08-25 11:57:06 +0300348 DEBUGFS_DEL(force_unicast_rateidx, wds);
349 DEBUGFS_DEL(max_ratectrl_rateidx, wds);
Johannes Berg3e122be2008-07-09 14:40:34 +0200350
Jiri Bence9f207f2007-05-05 11:46:38 -0700351 DEBUGFS_DEL(peer, wds);
352}
353
354static void del_vlan_files(struct ieee80211_sub_if_data *sdata)
355{
Jiri Bence9f207f2007-05-05 11:46:38 -0700356 DEBUGFS_DEL(drop_unencrypted, vlan);
Jouni Malinen93015f02008-08-25 11:57:06 +0300357 DEBUGFS_DEL(force_unicast_rateidx, vlan);
358 DEBUGFS_DEL(max_ratectrl_rateidx, vlan);
Jiri Bence9f207f2007-05-05 11:46:38 -0700359}
360
361static void del_monitor_files(struct ieee80211_sub_if_data *sdata)
362{
Jiri Bence9f207f2007-05-05 11:46:38 -0700363}
364
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100365#ifdef CONFIG_MAC80211_MESH
366#define MESHSTATS_DEL(name) \
367 do { \
368 debugfs_remove(sdata->mesh_stats.name); \
369 sdata->mesh_stats.name = NULL; \
370 } while (0)
371
372static void del_mesh_stats(struct ieee80211_sub_if_data *sdata)
373{
374 MESHSTATS_DEL(fwded_frames);
375 MESHSTATS_DEL(dropped_frames_ttl);
376 MESHSTATS_DEL(dropped_frames_no_route);
377 MESHSTATS_DEL(estab_plinks);
378 debugfs_remove(sdata->mesh_stats_dir);
379 sdata->mesh_stats_dir = NULL;
380}
381
382#define MESHPARAMS_DEL(name) \
383 do { \
384 debugfs_remove(sdata->mesh_config.name); \
385 sdata->mesh_config.name = NULL; \
386 } while (0)
387
388static void del_mesh_config(struct ieee80211_sub_if_data *sdata)
389{
390 MESHPARAMS_DEL(dot11MeshMaxRetries);
391 MESHPARAMS_DEL(dot11MeshRetryTimeout);
392 MESHPARAMS_DEL(dot11MeshConfirmTimeout);
393 MESHPARAMS_DEL(dot11MeshHoldingTimeout);
394 MESHPARAMS_DEL(dot11MeshTTL);
395 MESHPARAMS_DEL(auto_open_plinks);
396 MESHPARAMS_DEL(dot11MeshMaxPeerLinks);
397 MESHPARAMS_DEL(dot11MeshHWMPactivePathTimeout);
398 MESHPARAMS_DEL(dot11MeshHWMPpreqMinInterval);
399 MESHPARAMS_DEL(dot11MeshHWMPnetDiameterTraversalTime);
400 MESHPARAMS_DEL(dot11MeshHWMPmaxPREQretries);
401 MESHPARAMS_DEL(path_refresh_time);
402 MESHPARAMS_DEL(min_discovery_timeout);
403 debugfs_remove(sdata->mesh_config_dir);
404 sdata->mesh_config_dir = NULL;
405}
406#endif
407
Johannes Berg75636522008-07-09 14:40:35 +0200408static void del_files(struct ieee80211_sub_if_data *sdata)
Jiri Bence9f207f2007-05-05 11:46:38 -0700409{
410 if (!sdata->debugfsdir)
411 return;
412
Johannes Berg75636522008-07-09 14:40:35 +0200413 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200414 case NL80211_IFTYPE_MESH_POINT:
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100415#ifdef CONFIG_MAC80211_MESH
416 del_mesh_stats(sdata);
417 del_mesh_config(sdata);
418#endif
Johannes Berg472dbc42008-09-11 00:01:49 +0200419 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200420 case NL80211_IFTYPE_STATION:
421 case NL80211_IFTYPE_ADHOC:
Jiri Bence9f207f2007-05-05 11:46:38 -0700422 del_sta_files(sdata);
423 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200424 case NL80211_IFTYPE_AP:
Jiri Bence9f207f2007-05-05 11:46:38 -0700425 del_ap_files(sdata);
426 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200427 case NL80211_IFTYPE_WDS:
Jiri Bence9f207f2007-05-05 11:46:38 -0700428 del_wds_files(sdata);
429 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200430 case NL80211_IFTYPE_MONITOR:
Jiri Bence9f207f2007-05-05 11:46:38 -0700431 del_monitor_files(sdata);
432 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200433 case NL80211_IFTYPE_AP_VLAN:
Jiri Bence9f207f2007-05-05 11:46:38 -0700434 del_vlan_files(sdata);
435 break;
436 default:
437 break;
438 }
439}
440
441static int notif_registered;
442
443void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
444{
445 char buf[10+IFNAMSIZ];
446
447 if (!notif_registered)
448 return;
449
450 sprintf(buf, "netdev:%s", sdata->dev->name);
451 sdata->debugfsdir = debugfs_create_dir(buf,
452 sdata->local->hw.wiphy->debugfsdir);
Johannes Berg75636522008-07-09 14:40:35 +0200453 add_files(sdata);
Jiri Bence9f207f2007-05-05 11:46:38 -0700454}
455
456void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
457{
Johannes Berg75636522008-07-09 14:40:35 +0200458 del_files(sdata);
Jiri Bence9f207f2007-05-05 11:46:38 -0700459 debugfs_remove(sdata->debugfsdir);
460 sdata->debugfsdir = NULL;
461}
462
Johannes Berg988c0f72008-04-17 19:21:22 +0200463static int netdev_notify(struct notifier_block *nb,
Jiri Bence9f207f2007-05-05 11:46:38 -0700464 unsigned long state,
465 void *ndev)
466{
467 struct net_device *dev = ndev;
Johannes Berg7c8081e2007-06-21 18:30:19 +0200468 struct dentry *dir;
Johannes Berg3e122be2008-07-09 14:40:34 +0200469 struct ieee80211_sub_if_data *sdata;
Jiri Bence9f207f2007-05-05 11:46:38 -0700470 char buf[10+IFNAMSIZ];
471
472 if (state != NETDEV_CHANGENAME)
473 return 0;
474
475 if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
476 return 0;
477
478 if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
479 return 0;
480
Johannes Berg3e122be2008-07-09 14:40:34 +0200481 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
482
Johannes Berg7c8081e2007-06-21 18:30:19 +0200483 dir = sdata->debugfsdir;
Johannes Bergc74e90a2008-10-08 10:18:36 +0200484
485 if (!dir)
486 return 0;
487
488 sprintf(buf, "netdev:%s", dev->name);
Johannes Berg7c8081e2007-06-21 18:30:19 +0200489 if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
490 printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs "
491 "dir to %s\n", buf);
Jiri Bence9f207f2007-05-05 11:46:38 -0700492
493 return 0;
494}
495
496static struct notifier_block mac80211_debugfs_netdev_notifier = {
497 .notifier_call = netdev_notify,
498};
499
500void ieee80211_debugfs_netdev_init(void)
501{
502 int err;
503
504 err = register_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
505 if (err) {
506 printk(KERN_ERR
507 "mac80211: failed to install netdev notifier,"
508 " disabling per-netdev debugfs!\n");
509 } else
510 notif_registered = 1;
511}
512
513void ieee80211_debugfs_netdev_exit(void)
514{
515 unregister_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
516 notif_registered = 0;
517}