blob: 69b2fbf35145e1e2911489e98e057e253e0a3546 [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{ \
Johannes Berg0c68ae262008-10-27 15:56:10 -0700107 return scnprintf(buf, buflen, "%pM\n", sdata->field); \
Jiri Bence9f207f2007-05-05 11:46:38 -0700108}
109
110#define __IEEE80211_IF_FILE(name) \
111static ssize_t ieee80211_if_read_##name(struct file *file, \
112 char __user *userbuf, \
113 size_t count, loff_t *ppos) \
114{ \
115 return ieee80211_if_read(file->private_data, \
116 userbuf, count, ppos, \
117 ieee80211_if_fmt_##name); \
118} \
119static const struct file_operations name##_ops = { \
120 .read = ieee80211_if_read_##name, \
121 .open = mac80211_open_file_generic, \
122}
123
124#define IEEE80211_IF_FILE(name, field, format) \
125 IEEE80211_IF_FMT_##format(name, field) \
126 __IEEE80211_IF_FILE(name)
127
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100128#define __IEEE80211_IF_WFILE(name) \
129static ssize_t ieee80211_if_read_##name(struct file *file, \
130 char __user *userbuf, \
131 size_t count, loff_t *ppos) \
132{ \
133 return ieee80211_if_read(file->private_data, \
134 userbuf, count, ppos, \
135 ieee80211_if_fmt_##name); \
136} \
137static ssize_t ieee80211_if_write_##name(struct file *file, \
138 const char __user *userbuf, \
139 size_t count, loff_t *ppos) \
140{ \
141 return ieee80211_if_write(file->private_data, \
142 userbuf, count, ppos, \
143 ieee80211_if_wfmt_##name); \
144} \
145static const struct file_operations name##_ops = { \
146 .read = ieee80211_if_read_##name, \
147 .write = ieee80211_if_write_##name, \
148 .open = mac80211_open_file_generic, \
149}
150
151#define IEEE80211_IF_WFILE(name, field, format, type) \
152 IEEE80211_IF_FMT_##format(name, field) \
153 IEEE80211_IF_WFMT(name, field, type) \
154 __IEEE80211_IF_WFILE(name)
155
Jiri Bence9f207f2007-05-05 11:46:38 -0700156/* common attributes */
Jiri Bence9f207f2007-05-05 11:46:38 -0700157IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC);
Johannes Berg3e122be2008-07-09 14:40:34 +0200158IEEE80211_IF_FILE(force_unicast_rateidx, force_unicast_rateidx, DEC);
159IEEE80211_IF_FILE(max_ratectrl_rateidx, max_ratectrl_rateidx, DEC);
Jiri Bence9f207f2007-05-05 11:46:38 -0700160
161/* STA/IBSS attributes */
162IEEE80211_IF_FILE(state, u.sta.state, DEC);
163IEEE80211_IF_FILE(bssid, u.sta.bssid, MAC);
164IEEE80211_IF_FILE(prev_bssid, u.sta.prev_bssid, MAC);
165IEEE80211_IF_FILE(ssid_len, u.sta.ssid_len, SIZE);
166IEEE80211_IF_FILE(aid, u.sta.aid, DEC);
167IEEE80211_IF_FILE(ap_capab, u.sta.ap_capab, HEX);
168IEEE80211_IF_FILE(capab, u.sta.capab, HEX);
169IEEE80211_IF_FILE(extra_ie_len, u.sta.extra_ie_len, SIZE);
170IEEE80211_IF_FILE(auth_tries, u.sta.auth_tries, DEC);
171IEEE80211_IF_FILE(assoc_tries, u.sta.assoc_tries, DEC);
172IEEE80211_IF_FILE(auth_algs, u.sta.auth_algs, HEX);
173IEEE80211_IF_FILE(auth_alg, u.sta.auth_alg, DEC);
174IEEE80211_IF_FILE(auth_transaction, u.sta.auth_transaction, DEC);
175
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);
Jiri Bence9f207f2007-05-05 11:46:38 -0700193
194static ssize_t ieee80211_if_fmt_num_buffered_multicast(
195 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
196{
197 return scnprintf(buf, buflen, "%u\n",
198 skb_queue_len(&sdata->u.ap.ps_bc_buf));
199}
200__IEEE80211_IF_FILE(num_buffered_multicast);
201
Jiri Bence9f207f2007-05-05 11:46:38 -0700202/* WDS attributes */
203IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
204
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100205#ifdef CONFIG_MAC80211_MESH
206/* Mesh stats attributes */
Johannes Berg472dbc42008-09-11 00:01:49 +0200207IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
208IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100209IEEE80211_IF_FILE(dropped_frames_no_route,
Johannes Berg472dbc42008-09-11 00:01:49 +0200210 u.mesh.mshstats.dropped_frames_no_route, DEC);
211IEEE80211_IF_FILE(estab_plinks, u.mesh.mshstats.estab_plinks, ATOMIC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100212
213/* Mesh parameters */
214IEEE80211_IF_WFILE(dot11MeshMaxRetries,
Johannes Berg472dbc42008-09-11 00:01:49 +0200215 u.mesh.mshcfg.dot11MeshMaxRetries, DEC, u8);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100216IEEE80211_IF_WFILE(dot11MeshRetryTimeout,
Johannes Berg472dbc42008-09-11 00:01:49 +0200217 u.mesh.mshcfg.dot11MeshRetryTimeout, DEC, u16);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100218IEEE80211_IF_WFILE(dot11MeshConfirmTimeout,
Johannes Berg472dbc42008-09-11 00:01:49 +0200219 u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC, u16);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100220IEEE80211_IF_WFILE(dot11MeshHoldingTimeout,
Johannes Berg472dbc42008-09-11 00:01:49 +0200221 u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC, u16);
222IEEE80211_IF_WFILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC, u8);
223IEEE80211_IF_WFILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC, u8);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100224IEEE80211_IF_WFILE(dot11MeshMaxPeerLinks,
Johannes Berg472dbc42008-09-11 00:01:49 +0200225 u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC, u16);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100226IEEE80211_IF_WFILE(dot11MeshHWMPactivePathTimeout,
Johannes Berg472dbc42008-09-11 00:01:49 +0200227 u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC, u32);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100228IEEE80211_IF_WFILE(dot11MeshHWMPpreqMinInterval,
Johannes Berg472dbc42008-09-11 00:01:49 +0200229 u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC, u16);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100230IEEE80211_IF_WFILE(dot11MeshHWMPnetDiameterTraversalTime,
Johannes Berg472dbc42008-09-11 00:01:49 +0200231 u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC, u16);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100232IEEE80211_IF_WFILE(dot11MeshHWMPmaxPREQretries,
Johannes Berg472dbc42008-09-11 00:01:49 +0200233 u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC, u8);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100234IEEE80211_IF_WFILE(path_refresh_time,
Johannes Berg472dbc42008-09-11 00:01:49 +0200235 u.mesh.mshcfg.path_refresh_time, DEC, u32);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100236IEEE80211_IF_WFILE(min_discovery_timeout,
Johannes Berg472dbc42008-09-11 00:01:49 +0200237 u.mesh.mshcfg.min_discovery_timeout, DEC, u16);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100238#endif
239
240
Jiri Bence9f207f2007-05-05 11:46:38 -0700241#define DEBUGFS_ADD(name, type)\
Johannes Bergbebb8a52008-04-04 23:33:37 +0200242 sdata->debugfs.type.name = debugfs_create_file(#name, 0400,\
Jiri Bence9f207f2007-05-05 11:46:38 -0700243 sdata->debugfsdir, sdata, &name##_ops);
244
245static void add_sta_files(struct ieee80211_sub_if_data *sdata)
246{
Jiri Bence9f207f2007-05-05 11:46:38 -0700247 DEBUGFS_ADD(drop_unencrypted, sta);
Jouni Malinen93015f02008-08-25 11:57:06 +0300248 DEBUGFS_ADD(force_unicast_rateidx, sta);
249 DEBUGFS_ADD(max_ratectrl_rateidx, sta);
Johannes Berg3e122be2008-07-09 14:40:34 +0200250
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);
265}
266
267static void add_ap_files(struct ieee80211_sub_if_data *sdata)
268{
Jiri Bence9f207f2007-05-05 11:46:38 -0700269 DEBUGFS_ADD(drop_unencrypted, ap);
Johannes Berg3e122be2008-07-09 14:40:34 +0200270 DEBUGFS_ADD(force_unicast_rateidx, ap);
271 DEBUGFS_ADD(max_ratectrl_rateidx, ap);
272
Jiri Bence9f207f2007-05-05 11:46:38 -0700273 DEBUGFS_ADD(num_sta_ps, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700274 DEBUGFS_ADD(dtim_count, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700275 DEBUGFS_ADD(num_buffered_multicast, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700276}
277
278static void add_wds_files(struct ieee80211_sub_if_data *sdata)
279{
Jiri Bence9f207f2007-05-05 11:46:38 -0700280 DEBUGFS_ADD(drop_unencrypted, wds);
Jouni Malinen93015f02008-08-25 11:57:06 +0300281 DEBUGFS_ADD(force_unicast_rateidx, wds);
282 DEBUGFS_ADD(max_ratectrl_rateidx, wds);
Johannes Berg3e122be2008-07-09 14:40:34 +0200283
Jiri Bence9f207f2007-05-05 11:46:38 -0700284 DEBUGFS_ADD(peer, wds);
285}
286
287static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
288{
Jiri Bence9f207f2007-05-05 11:46:38 -0700289 DEBUGFS_ADD(drop_unencrypted, vlan);
Jouni Malinen93015f02008-08-25 11:57:06 +0300290 DEBUGFS_ADD(force_unicast_rateidx, vlan);
291 DEBUGFS_ADD(max_ratectrl_rateidx, vlan);
Jiri Bence9f207f2007-05-05 11:46:38 -0700292}
293
294static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
295{
Jiri Bence9f207f2007-05-05 11:46:38 -0700296}
297
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100298#ifdef CONFIG_MAC80211_MESH
299#define MESHSTATS_ADD(name)\
Johannes Bergbebb8a52008-04-04 23:33:37 +0200300 sdata->mesh_stats.name = debugfs_create_file(#name, 0400,\
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100301 sdata->mesh_stats_dir, sdata, &name##_ops);
302
303static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
304{
305 sdata->mesh_stats_dir = debugfs_create_dir("mesh_stats",
306 sdata->debugfsdir);
307 MESHSTATS_ADD(fwded_frames);
308 MESHSTATS_ADD(dropped_frames_ttl);
309 MESHSTATS_ADD(dropped_frames_no_route);
310 MESHSTATS_ADD(estab_plinks);
311}
312
313#define MESHPARAMS_ADD(name)\
Johannes Bergbebb8a52008-04-04 23:33:37 +0200314 sdata->mesh_config.name = debugfs_create_file(#name, 0600,\
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100315 sdata->mesh_config_dir, sdata, &name##_ops);
316
317static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
318{
319 sdata->mesh_config_dir = debugfs_create_dir("mesh_config",
320 sdata->debugfsdir);
321 MESHPARAMS_ADD(dot11MeshMaxRetries);
322 MESHPARAMS_ADD(dot11MeshRetryTimeout);
323 MESHPARAMS_ADD(dot11MeshConfirmTimeout);
324 MESHPARAMS_ADD(dot11MeshHoldingTimeout);
325 MESHPARAMS_ADD(dot11MeshTTL);
326 MESHPARAMS_ADD(auto_open_plinks);
327 MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
328 MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
329 MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
330 MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
331 MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
332 MESHPARAMS_ADD(path_refresh_time);
333 MESHPARAMS_ADD(min_discovery_timeout);
334}
335#endif
336
Jiri Bence9f207f2007-05-05 11:46:38 -0700337static void add_files(struct ieee80211_sub_if_data *sdata)
338{
339 if (!sdata->debugfsdir)
340 return;
341
Johannes Berg51fb61e2007-12-19 01:31:27 +0100342 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200343 case NL80211_IFTYPE_MESH_POINT:
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100344#ifdef CONFIG_MAC80211_MESH
345 add_mesh_stats(sdata);
346 add_mesh_config(sdata);
347#endif
Johannes Berg472dbc42008-09-11 00:01:49 +0200348 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200349 case NL80211_IFTYPE_STATION:
350 case NL80211_IFTYPE_ADHOC:
Jiri Bence9f207f2007-05-05 11:46:38 -0700351 add_sta_files(sdata);
352 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200353 case NL80211_IFTYPE_AP:
Jiri Bence9f207f2007-05-05 11:46:38 -0700354 add_ap_files(sdata);
355 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200356 case NL80211_IFTYPE_WDS:
Jiri Bence9f207f2007-05-05 11:46:38 -0700357 add_wds_files(sdata);
358 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200359 case NL80211_IFTYPE_MONITOR:
Jiri Bence9f207f2007-05-05 11:46:38 -0700360 add_monitor_files(sdata);
361 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200362 case NL80211_IFTYPE_AP_VLAN:
Jiri Bence9f207f2007-05-05 11:46:38 -0700363 add_vlan_files(sdata);
364 break;
365 default:
366 break;
367 }
368}
369
Zhu Yi21887b22007-07-27 15:43:23 +0200370#define DEBUGFS_DEL(name, type) \
371 do { \
372 debugfs_remove(sdata->debugfs.type.name); \
373 sdata->debugfs.type.name = NULL; \
374 } while (0)
Jiri Bence9f207f2007-05-05 11:46:38 -0700375
376static void del_sta_files(struct ieee80211_sub_if_data *sdata)
377{
Jiri Bence9f207f2007-05-05 11:46:38 -0700378 DEBUGFS_DEL(drop_unencrypted, sta);
Jouni Malinen93015f02008-08-25 11:57:06 +0300379 DEBUGFS_DEL(force_unicast_rateidx, sta);
380 DEBUGFS_DEL(max_ratectrl_rateidx, sta);
Johannes Berg3e122be2008-07-09 14:40:34 +0200381
Jiri Bence9f207f2007-05-05 11:46:38 -0700382 DEBUGFS_DEL(state, sta);
383 DEBUGFS_DEL(bssid, sta);
384 DEBUGFS_DEL(prev_bssid, sta);
385 DEBUGFS_DEL(ssid_len, sta);
386 DEBUGFS_DEL(aid, sta);
387 DEBUGFS_DEL(ap_capab, sta);
388 DEBUGFS_DEL(capab, sta);
389 DEBUGFS_DEL(extra_ie_len, sta);
390 DEBUGFS_DEL(auth_tries, sta);
391 DEBUGFS_DEL(assoc_tries, sta);
392 DEBUGFS_DEL(auth_algs, sta);
393 DEBUGFS_DEL(auth_alg, sta);
394 DEBUGFS_DEL(auth_transaction, sta);
395 DEBUGFS_DEL(flags, sta);
396}
397
398static void del_ap_files(struct ieee80211_sub_if_data *sdata)
399{
Jiri Bence9f207f2007-05-05 11:46:38 -0700400 DEBUGFS_DEL(drop_unencrypted, ap);
Johannes Berg3e122be2008-07-09 14:40:34 +0200401 DEBUGFS_DEL(force_unicast_rateidx, ap);
402 DEBUGFS_DEL(max_ratectrl_rateidx, ap);
403
Jiri Bence9f207f2007-05-05 11:46:38 -0700404 DEBUGFS_DEL(num_sta_ps, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700405 DEBUGFS_DEL(dtim_count, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700406 DEBUGFS_DEL(num_buffered_multicast, ap);
Jiri Bence9f207f2007-05-05 11:46:38 -0700407}
408
409static void del_wds_files(struct ieee80211_sub_if_data *sdata)
410{
Jiri Bence9f207f2007-05-05 11:46:38 -0700411 DEBUGFS_DEL(drop_unencrypted, wds);
Jouni Malinen93015f02008-08-25 11:57:06 +0300412 DEBUGFS_DEL(force_unicast_rateidx, wds);
413 DEBUGFS_DEL(max_ratectrl_rateidx, wds);
Johannes Berg3e122be2008-07-09 14:40:34 +0200414
Jiri Bence9f207f2007-05-05 11:46:38 -0700415 DEBUGFS_DEL(peer, wds);
416}
417
418static void del_vlan_files(struct ieee80211_sub_if_data *sdata)
419{
Jiri Bence9f207f2007-05-05 11:46:38 -0700420 DEBUGFS_DEL(drop_unencrypted, vlan);
Jouni Malinen93015f02008-08-25 11:57:06 +0300421 DEBUGFS_DEL(force_unicast_rateidx, vlan);
422 DEBUGFS_DEL(max_ratectrl_rateidx, vlan);
Jiri Bence9f207f2007-05-05 11:46:38 -0700423}
424
425static void del_monitor_files(struct ieee80211_sub_if_data *sdata)
426{
Jiri Bence9f207f2007-05-05 11:46:38 -0700427}
428
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100429#ifdef CONFIG_MAC80211_MESH
430#define MESHSTATS_DEL(name) \
431 do { \
432 debugfs_remove(sdata->mesh_stats.name); \
433 sdata->mesh_stats.name = NULL; \
434 } while (0)
435
436static void del_mesh_stats(struct ieee80211_sub_if_data *sdata)
437{
438 MESHSTATS_DEL(fwded_frames);
439 MESHSTATS_DEL(dropped_frames_ttl);
440 MESHSTATS_DEL(dropped_frames_no_route);
441 MESHSTATS_DEL(estab_plinks);
442 debugfs_remove(sdata->mesh_stats_dir);
443 sdata->mesh_stats_dir = NULL;
444}
445
446#define MESHPARAMS_DEL(name) \
447 do { \
448 debugfs_remove(sdata->mesh_config.name); \
449 sdata->mesh_config.name = NULL; \
450 } while (0)
451
452static void del_mesh_config(struct ieee80211_sub_if_data *sdata)
453{
454 MESHPARAMS_DEL(dot11MeshMaxRetries);
455 MESHPARAMS_DEL(dot11MeshRetryTimeout);
456 MESHPARAMS_DEL(dot11MeshConfirmTimeout);
457 MESHPARAMS_DEL(dot11MeshHoldingTimeout);
458 MESHPARAMS_DEL(dot11MeshTTL);
459 MESHPARAMS_DEL(auto_open_plinks);
460 MESHPARAMS_DEL(dot11MeshMaxPeerLinks);
461 MESHPARAMS_DEL(dot11MeshHWMPactivePathTimeout);
462 MESHPARAMS_DEL(dot11MeshHWMPpreqMinInterval);
463 MESHPARAMS_DEL(dot11MeshHWMPnetDiameterTraversalTime);
464 MESHPARAMS_DEL(dot11MeshHWMPmaxPREQretries);
465 MESHPARAMS_DEL(path_refresh_time);
466 MESHPARAMS_DEL(min_discovery_timeout);
467 debugfs_remove(sdata->mesh_config_dir);
468 sdata->mesh_config_dir = NULL;
469}
470#endif
471
Johannes Berg75636522008-07-09 14:40:35 +0200472static void del_files(struct ieee80211_sub_if_data *sdata)
Jiri Bence9f207f2007-05-05 11:46:38 -0700473{
474 if (!sdata->debugfsdir)
475 return;
476
Johannes Berg75636522008-07-09 14:40:35 +0200477 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200478 case NL80211_IFTYPE_MESH_POINT:
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100479#ifdef CONFIG_MAC80211_MESH
480 del_mesh_stats(sdata);
481 del_mesh_config(sdata);
482#endif
Johannes Berg472dbc42008-09-11 00:01:49 +0200483 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200484 case NL80211_IFTYPE_STATION:
485 case NL80211_IFTYPE_ADHOC:
Jiri Bence9f207f2007-05-05 11:46:38 -0700486 del_sta_files(sdata);
487 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200488 case NL80211_IFTYPE_AP:
Jiri Bence9f207f2007-05-05 11:46:38 -0700489 del_ap_files(sdata);
490 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200491 case NL80211_IFTYPE_WDS:
Jiri Bence9f207f2007-05-05 11:46:38 -0700492 del_wds_files(sdata);
493 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200494 case NL80211_IFTYPE_MONITOR:
Jiri Bence9f207f2007-05-05 11:46:38 -0700495 del_monitor_files(sdata);
496 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200497 case NL80211_IFTYPE_AP_VLAN:
Jiri Bence9f207f2007-05-05 11:46:38 -0700498 del_vlan_files(sdata);
499 break;
500 default:
501 break;
502 }
503}
504
505static int notif_registered;
506
507void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
508{
509 char buf[10+IFNAMSIZ];
510
511 if (!notif_registered)
512 return;
513
514 sprintf(buf, "netdev:%s", sdata->dev->name);
515 sdata->debugfsdir = debugfs_create_dir(buf,
516 sdata->local->hw.wiphy->debugfsdir);
Johannes Berg75636522008-07-09 14:40:35 +0200517 add_files(sdata);
Jiri Bence9f207f2007-05-05 11:46:38 -0700518}
519
520void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
521{
Johannes Berg75636522008-07-09 14:40:35 +0200522 del_files(sdata);
Jiri Bence9f207f2007-05-05 11:46:38 -0700523 debugfs_remove(sdata->debugfsdir);
524 sdata->debugfsdir = NULL;
525}
526
Johannes Berg988c0f72008-04-17 19:21:22 +0200527static int netdev_notify(struct notifier_block *nb,
Jiri Bence9f207f2007-05-05 11:46:38 -0700528 unsigned long state,
529 void *ndev)
530{
531 struct net_device *dev = ndev;
Johannes Berg7c8081e2007-06-21 18:30:19 +0200532 struct dentry *dir;
Johannes Berg3e122be2008-07-09 14:40:34 +0200533 struct ieee80211_sub_if_data *sdata;
Jiri Bence9f207f2007-05-05 11:46:38 -0700534 char buf[10+IFNAMSIZ];
535
536 if (state != NETDEV_CHANGENAME)
537 return 0;
538
539 if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
540 return 0;
541
542 if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
543 return 0;
544
Johannes Berg3e122be2008-07-09 14:40:34 +0200545 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
546
Johannes Berg7c8081e2007-06-21 18:30:19 +0200547 dir = sdata->debugfsdir;
Johannes Bergc74e90a2008-10-08 10:18:36 +0200548
549 if (!dir)
550 return 0;
551
552 sprintf(buf, "netdev:%s", dev->name);
Johannes Berg7c8081e2007-06-21 18:30:19 +0200553 if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
554 printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs "
555 "dir to %s\n", buf);
Jiri Bence9f207f2007-05-05 11:46:38 -0700556
557 return 0;
558}
559
560static struct notifier_block mac80211_debugfs_netdev_notifier = {
561 .notifier_call = netdev_notify,
562};
563
564void ieee80211_debugfs_netdev_init(void)
565{
566 int err;
567
568 err = register_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
569 if (err) {
570 printk(KERN_ERR
571 "mac80211: failed to install netdev notifier,"
572 " disabling per-netdev debugfs!\n");
573 } else
574 notif_registered = 1;
575}
576
577void ieee80211_debugfs_netdev_exit(void)
578{
579 unregister_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
580 notif_registered = 0;
581}