debugfs_netdev.c 16.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * Copyright (c) 2006	Jiri Benc <jbenc@suse.cz>
 * Copyright 2007	Johannes Berg <johannes@sipsolutions.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/if.h>
#include <linux/interrupt.h>
#include <linux/netdevice.h>
#include <linux/rtnetlink.h>
#include <linux/notifier.h>
#include <net/mac80211.h>
#include <net/cfg80211.h>
#include "ieee80211_i.h"
Johannes Berg's avatar
Johannes Berg committed
20
#include "rate.h"
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "debugfs.h"
#include "debugfs_netdev.h"

static ssize_t ieee80211_if_read(
	struct ieee80211_sub_if_data *sdata,
	char __user *userbuf,
	size_t count, loff_t *ppos,
	ssize_t (*format)(const struct ieee80211_sub_if_data *, char *, int))
{
	char buf[70];
	ssize_t ret = -EINVAL;

	read_lock(&dev_base_lock);
34
	if (sdata->dev->reg_state == NETREG_REGISTERED)
35
36
		ret = (*format)(sdata, buf, sizeof(buf));
	read_unlock(&dev_base_lock);
37
38
39
40

	if (ret != -EINVAL)
		ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);

41
42
43
	return ret;
}

44
45
46
47
48
49
50
51
52
53
54
55
56
#ifdef CONFIG_MAC80211_MESH
static ssize_t ieee80211_if_write(
	struct ieee80211_sub_if_data *sdata,
	char const __user *userbuf,
	size_t count, loff_t *ppos,
	int (*format)(struct ieee80211_sub_if_data *, char *))
{
	char buf[10];
	int buf_size;

	memset(buf, 0x00, sizeof(buf));
	buf_size = min(count, (sizeof(buf)-1));
	if (copy_from_user(buf, userbuf, buf_size))
57
58
		return count;
	read_lock(&dev_base_lock);
59
60
61
	if (sdata->dev->reg_state == NETREG_REGISTERED)
		(*format)(sdata, buf);
	read_unlock(&dev_base_lock);
62

63
64
65
66
	return count;
}
#endif

67
68
69
70
71
72
73
#define IEEE80211_IF_FMT(name, field, format_string)			\
static ssize_t ieee80211_if_fmt_##name(					\
	const struct ieee80211_sub_if_data *sdata, char *buf,		\
	int buflen)							\
{									\
	return scnprintf(buf, buflen, format_string, sdata->field);	\
}
74
75
76
77
78
79
80
81
82
83
84
85
86
#define IEEE80211_IF_WFMT(name, field, type)				\
static int ieee80211_if_wfmt_##name(					\
	struct ieee80211_sub_if_data *sdata, char *buf)			\
{									\
	unsigned long tmp;						\
	char *endp;							\
									\
	tmp = simple_strtoul(buf, &endp, 0);				\
	if ((endp == buf) || ((type)tmp != tmp))			\
		return -EINVAL;						\
	sdata->field = tmp;						\
	return 0;							\
}
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#define IEEE80211_IF_FMT_DEC(name, field)				\
		IEEE80211_IF_FMT(name, field, "%d\n")
#define IEEE80211_IF_FMT_HEX(name, field)				\
		IEEE80211_IF_FMT(name, field, "%#x\n")
#define IEEE80211_IF_FMT_SIZE(name, field)				\
		IEEE80211_IF_FMT(name, field, "%zd\n")

#define IEEE80211_IF_FMT_ATOMIC(name, field)				\
static ssize_t ieee80211_if_fmt_##name(					\
	const struct ieee80211_sub_if_data *sdata,			\
	char *buf, int buflen)						\
{									\
	return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
}

#define IEEE80211_IF_FMT_MAC(name, field)				\
static ssize_t ieee80211_if_fmt_##name(					\
	const struct ieee80211_sub_if_data *sdata, char *buf,		\
	int buflen)							\
{									\
107
108
	DECLARE_MAC_BUF(mac);						\
	return scnprintf(buf, buflen, "%s\n", print_mac(mac, sdata->field));\
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
}

#define __IEEE80211_IF_FILE(name)					\
static ssize_t ieee80211_if_read_##name(struct file *file,		\
					char __user *userbuf,		\
					size_t count, loff_t *ppos)	\
{									\
	return ieee80211_if_read(file->private_data,			\
				 userbuf, count, ppos,			\
				 ieee80211_if_fmt_##name);		\
}									\
static const struct file_operations name##_ops = {			\
	.read = ieee80211_if_read_##name,				\
	.open = mac80211_open_file_generic,				\
}

#define IEEE80211_IF_FILE(name, field, format)				\
		IEEE80211_IF_FMT_##format(name, field)			\
		__IEEE80211_IF_FILE(name)

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#define __IEEE80211_IF_WFILE(name)					\
static ssize_t ieee80211_if_read_##name(struct file *file,		\
					char __user *userbuf,		\
					size_t count, loff_t *ppos)	\
{									\
	return ieee80211_if_read(file->private_data,			\
				 userbuf, count, ppos,			\
				 ieee80211_if_fmt_##name);		\
}									\
static ssize_t ieee80211_if_write_##name(struct file *file,		\
					const char __user *userbuf,	\
					size_t count, loff_t *ppos)	\
{									\
	return ieee80211_if_write(file->private_data,			\
				 userbuf, count, ppos,			\
				 ieee80211_if_wfmt_##name);		\
}									\
static const struct file_operations name##_ops = {			\
	.read = ieee80211_if_read_##name,				\
	.write = ieee80211_if_write_##name,				\
	.open = mac80211_open_file_generic,				\
}

#define IEEE80211_IF_WFILE(name, field, format, type)			\
		IEEE80211_IF_FMT_##format(name, field)			\
		IEEE80211_IF_WFMT(name, field, type)			\
		__IEEE80211_IF_WFILE(name)

157
158
/* common attributes */
IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC);
159
160
IEEE80211_IF_FILE(force_unicast_rateidx, force_unicast_rateidx, DEC);
IEEE80211_IF_FILE(max_ratectrl_rateidx, max_ratectrl_rateidx, DEC);
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175

/* STA/IBSS attributes */
IEEE80211_IF_FILE(state, u.sta.state, DEC);
IEEE80211_IF_FILE(bssid, u.sta.bssid, MAC);
IEEE80211_IF_FILE(prev_bssid, u.sta.prev_bssid, MAC);
IEEE80211_IF_FILE(ssid_len, u.sta.ssid_len, SIZE);
IEEE80211_IF_FILE(aid, u.sta.aid, DEC);
IEEE80211_IF_FILE(ap_capab, u.sta.ap_capab, HEX);
IEEE80211_IF_FILE(capab, u.sta.capab, HEX);
IEEE80211_IF_FILE(extra_ie_len, u.sta.extra_ie_len, SIZE);
IEEE80211_IF_FILE(auth_tries, u.sta.auth_tries, DEC);
IEEE80211_IF_FILE(assoc_tries, u.sta.assoc_tries, DEC);
IEEE80211_IF_FILE(auth_algs, u.sta.auth_algs, HEX);
IEEE80211_IF_FILE(auth_alg, u.sta.auth_alg, DEC);
IEEE80211_IF_FILE(auth_transaction, u.sta.auth_transaction, DEC);
176
IEEE80211_IF_FILE(num_beacons_sta, u.sta.num_beacons, DEC);
177
178
179
180
181

static ssize_t ieee80211_if_fmt_flags(
	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
{
	return scnprintf(buf, buflen, "%s%s%s%s%s%s%s\n",
182
183
184
185
186
187
		 sdata->u.sta.flags & IEEE80211_STA_SSID_SET ? "SSID\n" : "",
		 sdata->u.sta.flags & IEEE80211_STA_BSSID_SET ? "BSSID\n" : "",
		 sdata->u.sta.flags & IEEE80211_STA_PREV_BSSID_SET ? "prev BSSID\n" : "",
		 sdata->u.sta.flags & IEEE80211_STA_AUTHENTICATED ? "AUTH\n" : "",
		 sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED ? "ASSOC\n" : "",
		 sdata->u.sta.flags & IEEE80211_STA_PROBEREQ_POLL ? "PROBEREQ POLL\n" : "",
188
		 sdata->bss_conf.use_cts_prot ? "CTS prot\n" : "");
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
}
__IEEE80211_IF_FILE(flags);

/* AP attributes */
IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC);
IEEE80211_IF_FILE(num_beacons, u.ap.num_beacons, DEC);

static ssize_t ieee80211_if_fmt_num_buffered_multicast(
	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
{
	return scnprintf(buf, buflen, "%u\n",
			 skb_queue_len(&sdata->u.ap.ps_bc_buf));
}
__IEEE80211_IF_FILE(num_buffered_multicast);

/* WDS attributes */
IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);

208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#ifdef CONFIG_MAC80211_MESH
/* Mesh stats attributes */
IEEE80211_IF_FILE(fwded_frames, u.sta.mshstats.fwded_frames, DEC);
IEEE80211_IF_FILE(dropped_frames_ttl, u.sta.mshstats.dropped_frames_ttl, DEC);
IEEE80211_IF_FILE(dropped_frames_no_route,
		u.sta.mshstats.dropped_frames_no_route, DEC);
IEEE80211_IF_FILE(estab_plinks, u.sta.mshstats.estab_plinks, ATOMIC);

/* Mesh parameters */
IEEE80211_IF_WFILE(dot11MeshMaxRetries,
		u.sta.mshcfg.dot11MeshMaxRetries, DEC, u8);
IEEE80211_IF_WFILE(dot11MeshRetryTimeout,
		u.sta.mshcfg.dot11MeshRetryTimeout, DEC, u16);
IEEE80211_IF_WFILE(dot11MeshConfirmTimeout,
		u.sta.mshcfg.dot11MeshConfirmTimeout, DEC, u16);
IEEE80211_IF_WFILE(dot11MeshHoldingTimeout,
		u.sta.mshcfg.dot11MeshHoldingTimeout, DEC, u16);
IEEE80211_IF_WFILE(dot11MeshTTL, u.sta.mshcfg.dot11MeshTTL, DEC, u8);
226
IEEE80211_IF_WFILE(auto_open_plinks, u.sta.mshcfg.auto_open_plinks, DEC, u8);
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
IEEE80211_IF_WFILE(dot11MeshMaxPeerLinks,
		u.sta.mshcfg.dot11MeshMaxPeerLinks, DEC, u16);
IEEE80211_IF_WFILE(dot11MeshHWMPactivePathTimeout,
		u.sta.mshcfg.dot11MeshHWMPactivePathTimeout, DEC, u32);
IEEE80211_IF_WFILE(dot11MeshHWMPpreqMinInterval,
		u.sta.mshcfg.dot11MeshHWMPpreqMinInterval, DEC, u16);
IEEE80211_IF_WFILE(dot11MeshHWMPnetDiameterTraversalTime,
		u.sta.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC, u16);
IEEE80211_IF_WFILE(dot11MeshHWMPmaxPREQretries,
		u.sta.mshcfg.dot11MeshHWMPmaxPREQretries, DEC, u8);
IEEE80211_IF_WFILE(path_refresh_time,
		u.sta.mshcfg.path_refresh_time, DEC, u32);
IEEE80211_IF_WFILE(min_discovery_timeout,
		u.sta.mshcfg.min_discovery_timeout, DEC, u16);
#endif


244
#define DEBUGFS_ADD(name, type)\
245
	sdata->debugfs.type.name = debugfs_create_file(#name, 0400,\
246
247
248
249
250
		sdata->debugfsdir, sdata, &name##_ops);

static void add_sta_files(struct ieee80211_sub_if_data *sdata)
{
	DEBUGFS_ADD(drop_unencrypted, sta);
251
252
253
	DEBUGFS_ADD(force_unicast_rateidx, ap);
	DEBUGFS_ADD(max_ratectrl_rateidx, ap);

254
255
256
257
258
259
260
261
262
263
264
265
266
267
	DEBUGFS_ADD(state, sta);
	DEBUGFS_ADD(bssid, sta);
	DEBUGFS_ADD(prev_bssid, sta);
	DEBUGFS_ADD(ssid_len, sta);
	DEBUGFS_ADD(aid, sta);
	DEBUGFS_ADD(ap_capab, sta);
	DEBUGFS_ADD(capab, sta);
	DEBUGFS_ADD(extra_ie_len, sta);
	DEBUGFS_ADD(auth_tries, sta);
	DEBUGFS_ADD(assoc_tries, sta);
	DEBUGFS_ADD(auth_algs, sta);
	DEBUGFS_ADD(auth_alg, sta);
	DEBUGFS_ADD(auth_transaction, sta);
	DEBUGFS_ADD(flags, sta);
268
	DEBUGFS_ADD(num_beacons_sta, sta);
269
270
271
272
273
}

static void add_ap_files(struct ieee80211_sub_if_data *sdata)
{
	DEBUGFS_ADD(drop_unencrypted, ap);
274
275
276
	DEBUGFS_ADD(force_unicast_rateidx, ap);
	DEBUGFS_ADD(max_ratectrl_rateidx, ap);

277
278
279
280
281
282
283
284
285
	DEBUGFS_ADD(num_sta_ps, ap);
	DEBUGFS_ADD(dtim_count, ap);
	DEBUGFS_ADD(num_beacons, ap);
	DEBUGFS_ADD(num_buffered_multicast, ap);
}

static void add_wds_files(struct ieee80211_sub_if_data *sdata)
{
	DEBUGFS_ADD(drop_unencrypted, wds);
286
287
288
	DEBUGFS_ADD(force_unicast_rateidx, ap);
	DEBUGFS_ADD(max_ratectrl_rateidx, ap);

289
290
291
292
293
294
	DEBUGFS_ADD(peer, wds);
}

static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
{
	DEBUGFS_ADD(drop_unencrypted, vlan);
295
296
	DEBUGFS_ADD(force_unicast_rateidx, ap);
	DEBUGFS_ADD(max_ratectrl_rateidx, ap);
297
298
299
300
301
302
}

static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
{
}

303
304
#ifdef CONFIG_MAC80211_MESH
#define MESHSTATS_ADD(name)\
305
	sdata->mesh_stats.name = debugfs_create_file(#name, 0400,\
306
307
308
309
310
311
312
313
314
315
316
317
318
		sdata->mesh_stats_dir, sdata, &name##_ops);

static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
{
	sdata->mesh_stats_dir = debugfs_create_dir("mesh_stats",
				sdata->debugfsdir);
	MESHSTATS_ADD(fwded_frames);
	MESHSTATS_ADD(dropped_frames_ttl);
	MESHSTATS_ADD(dropped_frames_no_route);
	MESHSTATS_ADD(estab_plinks);
}

#define MESHPARAMS_ADD(name)\
319
	sdata->mesh_config.name = debugfs_create_file(#name, 0600,\
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
		sdata->mesh_config_dir, sdata, &name##_ops);

static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
{
	sdata->mesh_config_dir = debugfs_create_dir("mesh_config",
				sdata->debugfsdir);
	MESHPARAMS_ADD(dot11MeshMaxRetries);
	MESHPARAMS_ADD(dot11MeshRetryTimeout);
	MESHPARAMS_ADD(dot11MeshConfirmTimeout);
	MESHPARAMS_ADD(dot11MeshHoldingTimeout);
	MESHPARAMS_ADD(dot11MeshTTL);
	MESHPARAMS_ADD(auto_open_plinks);
	MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
	MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
	MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
	MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
	MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
	MESHPARAMS_ADD(path_refresh_time);
	MESHPARAMS_ADD(min_discovery_timeout);
}
#endif

342
343
344
345
346
static void add_files(struct ieee80211_sub_if_data *sdata)
{
	if (!sdata->debugfsdir)
		return;

347
	switch (sdata->vif.type) {
348
349
350
351
352
353
	case IEEE80211_IF_TYPE_MESH_POINT:
#ifdef CONFIG_MAC80211_MESH
		add_mesh_stats(sdata);
		add_mesh_config(sdata);
#endif
		/* fall through */
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
	case IEEE80211_IF_TYPE_STA:
	case IEEE80211_IF_TYPE_IBSS:
		add_sta_files(sdata);
		break;
	case IEEE80211_IF_TYPE_AP:
		add_ap_files(sdata);
		break;
	case IEEE80211_IF_TYPE_WDS:
		add_wds_files(sdata);
		break;
	case IEEE80211_IF_TYPE_MNTR:
		add_monitor_files(sdata);
		break;
	case IEEE80211_IF_TYPE_VLAN:
		add_vlan_files(sdata);
		break;
	default:
		break;
	}
}

375
376
377
378
379
#define DEBUGFS_DEL(name, type)					\
	do {							\
		debugfs_remove(sdata->debugfs.type.name);	\
		sdata->debugfs.type.name = NULL;		\
	} while (0)
380
381
382
383

static void del_sta_files(struct ieee80211_sub_if_data *sdata)
{
	DEBUGFS_DEL(drop_unencrypted, sta);
384
385
386
	DEBUGFS_DEL(force_unicast_rateidx, ap);
	DEBUGFS_DEL(max_ratectrl_rateidx, ap);

387
388
389
390
391
392
393
394
395
396
397
398
399
400
	DEBUGFS_DEL(state, sta);
	DEBUGFS_DEL(bssid, sta);
	DEBUGFS_DEL(prev_bssid, sta);
	DEBUGFS_DEL(ssid_len, sta);
	DEBUGFS_DEL(aid, sta);
	DEBUGFS_DEL(ap_capab, sta);
	DEBUGFS_DEL(capab, sta);
	DEBUGFS_DEL(extra_ie_len, sta);
	DEBUGFS_DEL(auth_tries, sta);
	DEBUGFS_DEL(assoc_tries, sta);
	DEBUGFS_DEL(auth_algs, sta);
	DEBUGFS_DEL(auth_alg, sta);
	DEBUGFS_DEL(auth_transaction, sta);
	DEBUGFS_DEL(flags, sta);
401
	DEBUGFS_DEL(num_beacons_sta, sta);
402
403
404
405
406
}

static void del_ap_files(struct ieee80211_sub_if_data *sdata)
{
	DEBUGFS_DEL(drop_unencrypted, ap);
407
408
409
	DEBUGFS_DEL(force_unicast_rateidx, ap);
	DEBUGFS_DEL(max_ratectrl_rateidx, ap);

410
411
412
413
414
415
416
417
418
	DEBUGFS_DEL(num_sta_ps, ap);
	DEBUGFS_DEL(dtim_count, ap);
	DEBUGFS_DEL(num_beacons, ap);
	DEBUGFS_DEL(num_buffered_multicast, ap);
}

static void del_wds_files(struct ieee80211_sub_if_data *sdata)
{
	DEBUGFS_DEL(drop_unencrypted, wds);
419
420
421
	DEBUGFS_DEL(force_unicast_rateidx, ap);
	DEBUGFS_DEL(max_ratectrl_rateidx, ap);

422
423
424
425
426
427
	DEBUGFS_DEL(peer, wds);
}

static void del_vlan_files(struct ieee80211_sub_if_data *sdata)
{
	DEBUGFS_DEL(drop_unencrypted, vlan);
428
429
	DEBUGFS_DEL(force_unicast_rateidx, ap);
	DEBUGFS_DEL(max_ratectrl_rateidx, ap);
430
431
432
433
434
435
}

static void del_monitor_files(struct ieee80211_sub_if_data *sdata)
{
}

436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
#ifdef CONFIG_MAC80211_MESH
#define MESHSTATS_DEL(name)			\
	do {						\
		debugfs_remove(sdata->mesh_stats.name);	\
		sdata->mesh_stats.name = NULL;		\
	} while (0)

static void del_mesh_stats(struct ieee80211_sub_if_data *sdata)
{
	MESHSTATS_DEL(fwded_frames);
	MESHSTATS_DEL(dropped_frames_ttl);
	MESHSTATS_DEL(dropped_frames_no_route);
	MESHSTATS_DEL(estab_plinks);
	debugfs_remove(sdata->mesh_stats_dir);
	sdata->mesh_stats_dir = NULL;
}

#define MESHPARAMS_DEL(name)			\
	do {						\
		debugfs_remove(sdata->mesh_config.name);	\
		sdata->mesh_config.name = NULL;		\
	} while (0)

static void del_mesh_config(struct ieee80211_sub_if_data *sdata)
{
	MESHPARAMS_DEL(dot11MeshMaxRetries);
	MESHPARAMS_DEL(dot11MeshRetryTimeout);
	MESHPARAMS_DEL(dot11MeshConfirmTimeout);
	MESHPARAMS_DEL(dot11MeshHoldingTimeout);
	MESHPARAMS_DEL(dot11MeshTTL);
	MESHPARAMS_DEL(auto_open_plinks);
	MESHPARAMS_DEL(dot11MeshMaxPeerLinks);
	MESHPARAMS_DEL(dot11MeshHWMPactivePathTimeout);
	MESHPARAMS_DEL(dot11MeshHWMPpreqMinInterval);
	MESHPARAMS_DEL(dot11MeshHWMPnetDiameterTraversalTime);
	MESHPARAMS_DEL(dot11MeshHWMPmaxPREQretries);
	MESHPARAMS_DEL(path_refresh_time);
	MESHPARAMS_DEL(min_discovery_timeout);
	debugfs_remove(sdata->mesh_config_dir);
	sdata->mesh_config_dir = NULL;
}
#endif

479
static void del_files(struct ieee80211_sub_if_data *sdata)
480
481
482
483
{
	if (!sdata->debugfsdir)
		return;

484
	switch (sdata->vif.type) {
485
486
487
488
489
490
	case IEEE80211_IF_TYPE_MESH_POINT:
#ifdef CONFIG_MAC80211_MESH
		del_mesh_stats(sdata);
		del_mesh_config(sdata);
#endif
		/* fall through */
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
	case IEEE80211_IF_TYPE_STA:
	case IEEE80211_IF_TYPE_IBSS:
		del_sta_files(sdata);
		break;
	case IEEE80211_IF_TYPE_AP:
		del_ap_files(sdata);
		break;
	case IEEE80211_IF_TYPE_WDS:
		del_wds_files(sdata);
		break;
	case IEEE80211_IF_TYPE_MNTR:
		del_monitor_files(sdata);
		break;
	case IEEE80211_IF_TYPE_VLAN:
		del_vlan_files(sdata);
		break;
	default:
		break;
	}
}

static int notif_registered;

void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
{
	char buf[10+IFNAMSIZ];

	if (!notif_registered)
		return;

	sprintf(buf, "netdev:%s", sdata->dev->name);
	sdata->debugfsdir = debugfs_create_dir(buf,
		sdata->local->hw.wiphy->debugfsdir);
524
	add_files(sdata);
525
526
527
528
}

void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
{
529
	del_files(sdata);
530
531
532
533
	debugfs_remove(sdata->debugfsdir);
	sdata->debugfsdir = NULL;
}

Johannes Berg's avatar
Johannes Berg committed
534
static int netdev_notify(struct notifier_block *nb,
535
536
537
538
			 unsigned long state,
			 void *ndev)
{
	struct net_device *dev = ndev;
539
	struct dentry *dir;
540
	struct ieee80211_sub_if_data *sdata;
541
542
543
544
545
546
547
548
549
550
551
	char buf[10+IFNAMSIZ];

	if (state != NETDEV_CHANGENAME)
		return 0;

	if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
		return 0;

	if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
		return 0;

552
553
	sdata = IEEE80211_DEV_TO_SUB_IF(dev);

554
	sprintf(buf, "netdev:%s", dev->name);
555
556
557
558
	dir = sdata->debugfsdir;
	if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
		printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs "
		       "dir to %s\n", buf);
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584

	return 0;
}

static struct notifier_block mac80211_debugfs_netdev_notifier = {
	.notifier_call = netdev_notify,
};

void ieee80211_debugfs_netdev_init(void)
{
	int err;

	err = register_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
	if (err) {
		printk(KERN_ERR
		       "mac80211: failed to install netdev notifier,"
		       " disabling per-netdev debugfs!\n");
	} else
		notif_registered = 1;
}

void ieee80211_debugfs_netdev_exit(void)
{
	unregister_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
	notif_registered = 0;
}