blob: e9ec6cae2d391a7b14dcb5abe3275a0c468a1eb9 [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
Johannes Berg46900292009-02-15 12:44:28 +010097/* STA attributes */
Johannes Berg46900292009-02-15 12:44:28 +010098IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
Johannes Berg46900292009-02-15 12:44:28 +010099IEEE80211_IF_FILE(aid, u.mgd.aid, DEC);
Johannes Berg46900292009-02-15 12:44:28 +0100100IEEE80211_IF_FILE(capab, u.mgd.capab, HEX);
Jiri Bence9f207f2007-05-05 11:46:38 -0700101
102/* AP attributes */
103IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
Jiri Bence9f207f2007-05-05 11:46:38 -0700104IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC);
Jiri Bence9f207f2007-05-05 11:46:38 -0700105
106static ssize_t ieee80211_if_fmt_num_buffered_multicast(
107 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
108{
109 return scnprintf(buf, buflen, "%u\n",
110 skb_queue_len(&sdata->u.ap.ps_bc_buf));
111}
112__IEEE80211_IF_FILE(num_buffered_multicast);
113
Jiri Bence9f207f2007-05-05 11:46:38 -0700114/* WDS attributes */
115IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
116
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100117#ifdef CONFIG_MAC80211_MESH
118/* Mesh stats attributes */
Johannes Berg472dbc42008-09-11 00:01:49 +0200119IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
120IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100121IEEE80211_IF_FILE(dropped_frames_no_route,
Johannes Berg472dbc42008-09-11 00:01:49 +0200122 u.mesh.mshstats.dropped_frames_no_route, DEC);
123IEEE80211_IF_FILE(estab_plinks, u.mesh.mshstats.estab_plinks, ATOMIC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100124
125/* Mesh parameters */
Johannes Berg36ff3822008-10-07 12:04:31 +0200126IEEE80211_IF_FILE(dot11MeshMaxRetries,
127 u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
128IEEE80211_IF_FILE(dot11MeshRetryTimeout,
129 u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
130IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
131 u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
132IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
133 u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
134IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
135IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
136IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
137 u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
138IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
139 u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
140IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
141 u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
142IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
143 u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
144IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
145 u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
146IEEE80211_IF_FILE(path_refresh_time,
147 u.mesh.mshcfg.path_refresh_time, DEC);
148IEEE80211_IF_FILE(min_discovery_timeout,
149 u.mesh.mshcfg.min_discovery_timeout, DEC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100150#endif
151
152
Jiri Bence9f207f2007-05-05 11:46:38 -0700153#define DEBUGFS_ADD(name, type)\
Johannes Bergbebb8a52008-04-04 23:33:37 +0200154 sdata->debugfs.type.name = debugfs_create_file(#name, 0400,\
Jiri Bence9f207f2007-05-05 11:46:38 -0700155 sdata->debugfsdir, sdata, &name##_ops);
156
157static void add_sta_files(struct ieee80211_sub_if_data *sdata)
158{
Jiri Bence9f207f2007-05-05 11:46:38 -0700159 DEBUGFS_ADD(drop_unencrypted, sta);
Jouni Malinen93015f02008-08-25 11:57:06 +0300160 DEBUGFS_ADD(force_unicast_rateidx, sta);
161 DEBUGFS_ADD(max_ratectrl_rateidx, sta);
Johannes Berg3e122be2008-07-09 14:40:34 +0200162
Jiri Bence9f207f2007-05-05 11:46:38 -0700163 DEBUGFS_ADD(bssid, sta);
Jiri Bence9f207f2007-05-05 11:46:38 -0700164 DEBUGFS_ADD(aid, sta);
Jiri Bence9f207f2007-05-05 11:46:38 -0700165 DEBUGFS_ADD(capab, sta);
Jiri Bence9f207f2007-05-05 11:46:38 -0700166}
167
168static void add_ap_files(struct ieee80211_sub_if_data *sdata)
169{
Jiri Bence9f207f2007-05-05 11:46:38 -0700170 DEBUGFS_ADD(drop_unencrypted, ap);
Johannes Berg3e122be2008-07-09 14:40:34 +0200171 DEBUGFS_ADD(force_unicast_rateidx, ap);
172 DEBUGFS_ADD(max_ratectrl_rateidx, ap);
173
Jiri Bence9f207f2007-05-05 11:46:38 -0700174 DEBUGFS_ADD(num_sta_ps, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700175 DEBUGFS_ADD(dtim_count, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700176 DEBUGFS_ADD(num_buffered_multicast, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700177}
178
179static void add_wds_files(struct ieee80211_sub_if_data *sdata)
180{
Jiri Bence9f207f2007-05-05 11:46:38 -0700181 DEBUGFS_ADD(drop_unencrypted, wds);
Jouni Malinen93015f02008-08-25 11:57:06 +0300182 DEBUGFS_ADD(force_unicast_rateidx, wds);
183 DEBUGFS_ADD(max_ratectrl_rateidx, wds);
Johannes Berg3e122be2008-07-09 14:40:34 +0200184
Jiri Bence9f207f2007-05-05 11:46:38 -0700185 DEBUGFS_ADD(peer, wds);
186}
187
188static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
189{
Jiri Bence9f207f2007-05-05 11:46:38 -0700190 DEBUGFS_ADD(drop_unencrypted, vlan);
Jouni Malinen93015f02008-08-25 11:57:06 +0300191 DEBUGFS_ADD(force_unicast_rateidx, vlan);
192 DEBUGFS_ADD(max_ratectrl_rateidx, vlan);
Jiri Bence9f207f2007-05-05 11:46:38 -0700193}
194
195static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
196{
Jiri Bence9f207f2007-05-05 11:46:38 -0700197}
198
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100199#ifdef CONFIG_MAC80211_MESH
200#define MESHSTATS_ADD(name)\
Johannes Bergbebb8a52008-04-04 23:33:37 +0200201 sdata->mesh_stats.name = debugfs_create_file(#name, 0400,\
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100202 sdata->mesh_stats_dir, sdata, &name##_ops);
203
204static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
205{
206 sdata->mesh_stats_dir = debugfs_create_dir("mesh_stats",
207 sdata->debugfsdir);
208 MESHSTATS_ADD(fwded_frames);
209 MESHSTATS_ADD(dropped_frames_ttl);
210 MESHSTATS_ADD(dropped_frames_no_route);
211 MESHSTATS_ADD(estab_plinks);
212}
213
214#define MESHPARAMS_ADD(name)\
Johannes Bergbebb8a52008-04-04 23:33:37 +0200215 sdata->mesh_config.name = debugfs_create_file(#name, 0600,\
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100216 sdata->mesh_config_dir, sdata, &name##_ops);
217
218static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
219{
220 sdata->mesh_config_dir = debugfs_create_dir("mesh_config",
221 sdata->debugfsdir);
222 MESHPARAMS_ADD(dot11MeshMaxRetries);
223 MESHPARAMS_ADD(dot11MeshRetryTimeout);
224 MESHPARAMS_ADD(dot11MeshConfirmTimeout);
225 MESHPARAMS_ADD(dot11MeshHoldingTimeout);
226 MESHPARAMS_ADD(dot11MeshTTL);
227 MESHPARAMS_ADD(auto_open_plinks);
228 MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
229 MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
230 MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
231 MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
232 MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
233 MESHPARAMS_ADD(path_refresh_time);
234 MESHPARAMS_ADD(min_discovery_timeout);
235}
236#endif
237
Jiri Bence9f207f2007-05-05 11:46:38 -0700238static void add_files(struct ieee80211_sub_if_data *sdata)
239{
240 if (!sdata->debugfsdir)
241 return;
242
Johannes Berg51fb61e2007-12-19 01:31:27 +0100243 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200244 case NL80211_IFTYPE_MESH_POINT:
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100245#ifdef CONFIG_MAC80211_MESH
246 add_mesh_stats(sdata);
247 add_mesh_config(sdata);
248#endif
Johannes Berg472dbc42008-09-11 00:01:49 +0200249 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200250 case NL80211_IFTYPE_STATION:
Jiri Bence9f207f2007-05-05 11:46:38 -0700251 add_sta_files(sdata);
252 break;
Johannes Berg46900292009-02-15 12:44:28 +0100253 case NL80211_IFTYPE_ADHOC:
254 /* XXX */
255 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200256 case NL80211_IFTYPE_AP:
Jiri Bence9f207f2007-05-05 11:46:38 -0700257 add_ap_files(sdata);
258 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200259 case NL80211_IFTYPE_WDS:
Jiri Bence9f207f2007-05-05 11:46:38 -0700260 add_wds_files(sdata);
261 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200262 case NL80211_IFTYPE_MONITOR:
Jiri Bence9f207f2007-05-05 11:46:38 -0700263 add_monitor_files(sdata);
264 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200265 case NL80211_IFTYPE_AP_VLAN:
Jiri Bence9f207f2007-05-05 11:46:38 -0700266 add_vlan_files(sdata);
267 break;
268 default:
269 break;
270 }
271}
272
Zhu Yi21887b22007-07-27 15:43:23 +0200273#define DEBUGFS_DEL(name, type) \
274 do { \
275 debugfs_remove(sdata->debugfs.type.name); \
276 sdata->debugfs.type.name = NULL; \
277 } while (0)
Jiri Bence9f207f2007-05-05 11:46:38 -0700278
279static void del_sta_files(struct ieee80211_sub_if_data *sdata)
280{
Jiri Bence9f207f2007-05-05 11:46:38 -0700281 DEBUGFS_DEL(drop_unencrypted, sta);
Jouni Malinen93015f02008-08-25 11:57:06 +0300282 DEBUGFS_DEL(force_unicast_rateidx, sta);
283 DEBUGFS_DEL(max_ratectrl_rateidx, sta);
Johannes Berg3e122be2008-07-09 14:40:34 +0200284
Jiri Bence9f207f2007-05-05 11:46:38 -0700285 DEBUGFS_DEL(bssid, sta);
Jiri Bence9f207f2007-05-05 11:46:38 -0700286 DEBUGFS_DEL(aid, sta);
Jiri Bence9f207f2007-05-05 11:46:38 -0700287 DEBUGFS_DEL(capab, sta);
Jiri Bence9f207f2007-05-05 11:46:38 -0700288}
289
290static void del_ap_files(struct ieee80211_sub_if_data *sdata)
291{
Jiri Bence9f207f2007-05-05 11:46:38 -0700292 DEBUGFS_DEL(drop_unencrypted, ap);
Johannes Berg3e122be2008-07-09 14:40:34 +0200293 DEBUGFS_DEL(force_unicast_rateidx, ap);
294 DEBUGFS_DEL(max_ratectrl_rateidx, ap);
295
Jiri Bence9f207f2007-05-05 11:46:38 -0700296 DEBUGFS_DEL(num_sta_ps, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700297 DEBUGFS_DEL(dtim_count, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700298 DEBUGFS_DEL(num_buffered_multicast, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700299}
300
301static void del_wds_files(struct ieee80211_sub_if_data *sdata)
302{
Jiri Bence9f207f2007-05-05 11:46:38 -0700303 DEBUGFS_DEL(drop_unencrypted, wds);
Jouni Malinen93015f02008-08-25 11:57:06 +0300304 DEBUGFS_DEL(force_unicast_rateidx, wds);
305 DEBUGFS_DEL(max_ratectrl_rateidx, wds);
Johannes Berg3e122be2008-07-09 14:40:34 +0200306
Jiri Bence9f207f2007-05-05 11:46:38 -0700307 DEBUGFS_DEL(peer, wds);
308}
309
310static void del_vlan_files(struct ieee80211_sub_if_data *sdata)
311{
Jiri Bence9f207f2007-05-05 11:46:38 -0700312 DEBUGFS_DEL(drop_unencrypted, vlan);
Jouni Malinen93015f02008-08-25 11:57:06 +0300313 DEBUGFS_DEL(force_unicast_rateidx, vlan);
314 DEBUGFS_DEL(max_ratectrl_rateidx, vlan);
Jiri Bence9f207f2007-05-05 11:46:38 -0700315}
316
317static void del_monitor_files(struct ieee80211_sub_if_data *sdata)
318{
Jiri Bence9f207f2007-05-05 11:46:38 -0700319}
320
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100321#ifdef CONFIG_MAC80211_MESH
322#define MESHSTATS_DEL(name) \
323 do { \
324 debugfs_remove(sdata->mesh_stats.name); \
325 sdata->mesh_stats.name = NULL; \
326 } while (0)
327
328static void del_mesh_stats(struct ieee80211_sub_if_data *sdata)
329{
330 MESHSTATS_DEL(fwded_frames);
331 MESHSTATS_DEL(dropped_frames_ttl);
332 MESHSTATS_DEL(dropped_frames_no_route);
333 MESHSTATS_DEL(estab_plinks);
334 debugfs_remove(sdata->mesh_stats_dir);
335 sdata->mesh_stats_dir = NULL;
336}
337
338#define MESHPARAMS_DEL(name) \
339 do { \
340 debugfs_remove(sdata->mesh_config.name); \
341 sdata->mesh_config.name = NULL; \
342 } while (0)
343
344static void del_mesh_config(struct ieee80211_sub_if_data *sdata)
345{
346 MESHPARAMS_DEL(dot11MeshMaxRetries);
347 MESHPARAMS_DEL(dot11MeshRetryTimeout);
348 MESHPARAMS_DEL(dot11MeshConfirmTimeout);
349 MESHPARAMS_DEL(dot11MeshHoldingTimeout);
350 MESHPARAMS_DEL(dot11MeshTTL);
351 MESHPARAMS_DEL(auto_open_plinks);
352 MESHPARAMS_DEL(dot11MeshMaxPeerLinks);
353 MESHPARAMS_DEL(dot11MeshHWMPactivePathTimeout);
354 MESHPARAMS_DEL(dot11MeshHWMPpreqMinInterval);
355 MESHPARAMS_DEL(dot11MeshHWMPnetDiameterTraversalTime);
356 MESHPARAMS_DEL(dot11MeshHWMPmaxPREQretries);
357 MESHPARAMS_DEL(path_refresh_time);
358 MESHPARAMS_DEL(min_discovery_timeout);
359 debugfs_remove(sdata->mesh_config_dir);
360 sdata->mesh_config_dir = NULL;
361}
362#endif
363
Johannes Berg75636522008-07-09 14:40:35 +0200364static void del_files(struct ieee80211_sub_if_data *sdata)
Jiri Bence9f207f2007-05-05 11:46:38 -0700365{
366 if (!sdata->debugfsdir)
367 return;
368
Johannes Berg75636522008-07-09 14:40:35 +0200369 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200370 case NL80211_IFTYPE_MESH_POINT:
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100371#ifdef CONFIG_MAC80211_MESH
372 del_mesh_stats(sdata);
373 del_mesh_config(sdata);
374#endif
Johannes Berg472dbc42008-09-11 00:01:49 +0200375 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200376 case NL80211_IFTYPE_STATION:
Jiri Bence9f207f2007-05-05 11:46:38 -0700377 del_sta_files(sdata);
378 break;
Johannes Berg46900292009-02-15 12:44:28 +0100379 case NL80211_IFTYPE_ADHOC:
380 /* XXX */
381 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200382 case NL80211_IFTYPE_AP:
Jiri Bence9f207f2007-05-05 11:46:38 -0700383 del_ap_files(sdata);
384 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200385 case NL80211_IFTYPE_WDS:
Jiri Bence9f207f2007-05-05 11:46:38 -0700386 del_wds_files(sdata);
387 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200388 case NL80211_IFTYPE_MONITOR:
Jiri Bence9f207f2007-05-05 11:46:38 -0700389 del_monitor_files(sdata);
390 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200391 case NL80211_IFTYPE_AP_VLAN:
Jiri Bence9f207f2007-05-05 11:46:38 -0700392 del_vlan_files(sdata);
393 break;
394 default:
395 break;
396 }
397}
398
399static int notif_registered;
400
401void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
402{
403 char buf[10+IFNAMSIZ];
404
405 if (!notif_registered)
406 return;
407
408 sprintf(buf, "netdev:%s", sdata->dev->name);
409 sdata->debugfsdir = debugfs_create_dir(buf,
410 sdata->local->hw.wiphy->debugfsdir);
Johannes Berg75636522008-07-09 14:40:35 +0200411 add_files(sdata);
Jiri Bence9f207f2007-05-05 11:46:38 -0700412}
413
414void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
415{
Johannes Berg75636522008-07-09 14:40:35 +0200416 del_files(sdata);
Jiri Bence9f207f2007-05-05 11:46:38 -0700417 debugfs_remove(sdata->debugfsdir);
418 sdata->debugfsdir = NULL;
419}
420
Johannes Berg988c0f72008-04-17 19:21:22 +0200421static int netdev_notify(struct notifier_block *nb,
Jiri Bence9f207f2007-05-05 11:46:38 -0700422 unsigned long state,
423 void *ndev)
424{
425 struct net_device *dev = ndev;
Johannes Berg7c8081e2007-06-21 18:30:19 +0200426 struct dentry *dir;
Johannes Berg3e122be2008-07-09 14:40:34 +0200427 struct ieee80211_sub_if_data *sdata;
Jiri Bence9f207f2007-05-05 11:46:38 -0700428 char buf[10+IFNAMSIZ];
429
430 if (state != NETDEV_CHANGENAME)
431 return 0;
432
433 if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
434 return 0;
435
436 if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
437 return 0;
438
Johannes Berg3e122be2008-07-09 14:40:34 +0200439 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
440
Johannes Berg7c8081e2007-06-21 18:30:19 +0200441 dir = sdata->debugfsdir;
Johannes Bergc74e90a2008-10-08 10:18:36 +0200442
443 if (!dir)
444 return 0;
445
446 sprintf(buf, "netdev:%s", dev->name);
Johannes Berg7c8081e2007-06-21 18:30:19 +0200447 if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
448 printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs "
449 "dir to %s\n", buf);
Jiri Bence9f207f2007-05-05 11:46:38 -0700450
451 return 0;
452}
453
454static struct notifier_block mac80211_debugfs_netdev_notifier = {
455 .notifier_call = netdev_notify,
456};
457
458void ieee80211_debugfs_netdev_init(void)
459{
460 int err;
461
462 err = register_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
463 if (err) {
464 printk(KERN_ERR
465 "mac80211: failed to install netdev notifier,"
466 " disabling per-netdev debugfs!\n");
467 } else
468 notif_registered = 1;
469}
470
471void ieee80211_debugfs_netdev_exit(void)
472{
473 unregister_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
474 notif_registered = 0;
475}