Linux 4.10-rc3
[linux/fpc-iii.git] / net / mac80211 / debugfs_netdev.c
blob1a05f85cb1f0610b41ea212df2624a9078ea16cd
1 /*
2 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
3 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
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 */
10 #include <linux/kernel.h>
11 #include <linux/device.h>
12 #include <linux/if.h>
13 #include <linux/if_ether.h>
14 #include <linux/interrupt.h>
15 #include <linux/netdevice.h>
16 #include <linux/rtnetlink.h>
17 #include <linux/slab.h>
18 #include <linux/notifier.h>
19 #include <net/mac80211.h>
20 #include <net/cfg80211.h>
21 #include "ieee80211_i.h"
22 #include "rate.h"
23 #include "debugfs.h"
24 #include "debugfs_netdev.h"
25 #include "driver-ops.h"
27 static ssize_t ieee80211_if_read(
28 struct ieee80211_sub_if_data *sdata,
29 char __user *userbuf,
30 size_t count, loff_t *ppos,
31 ssize_t (*format)(const struct ieee80211_sub_if_data *, char *, int))
33 char buf[200];
34 ssize_t ret = -EINVAL;
36 read_lock(&dev_base_lock);
37 ret = (*format)(sdata, buf, sizeof(buf));
38 read_unlock(&dev_base_lock);
40 if (ret >= 0)
41 ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);
43 return ret;
46 static ssize_t ieee80211_if_write(
47 struct ieee80211_sub_if_data *sdata,
48 const char __user *userbuf,
49 size_t count, loff_t *ppos,
50 ssize_t (*write)(struct ieee80211_sub_if_data *, const char *, int))
52 char buf[64];
53 ssize_t ret;
55 if (count >= sizeof(buf))
56 return -E2BIG;
58 if (copy_from_user(buf, userbuf, count))
59 return -EFAULT;
60 buf[count] = '\0';
62 ret = -ENODEV;
63 rtnl_lock();
64 ret = (*write)(sdata, buf, count);
65 rtnl_unlock();
67 return ret;
70 #define IEEE80211_IF_FMT(name, field, format_string) \
71 static ssize_t ieee80211_if_fmt_##name( \
72 const struct ieee80211_sub_if_data *sdata, char *buf, \
73 int buflen) \
74 { \
75 return scnprintf(buf, buflen, format_string, sdata->field); \
77 #define IEEE80211_IF_FMT_DEC(name, field) \
78 IEEE80211_IF_FMT(name, field, "%d\n")
79 #define IEEE80211_IF_FMT_HEX(name, field) \
80 IEEE80211_IF_FMT(name, field, "%#x\n")
81 #define IEEE80211_IF_FMT_LHEX(name, field) \
82 IEEE80211_IF_FMT(name, field, "%#lx\n")
83 #define IEEE80211_IF_FMT_SIZE(name, field) \
84 IEEE80211_IF_FMT(name, field, "%zd\n")
86 #define IEEE80211_IF_FMT_HEXARRAY(name, field) \
87 static ssize_t ieee80211_if_fmt_##name( \
88 const struct ieee80211_sub_if_data *sdata, \
89 char *buf, int buflen) \
90 { \
91 char *p = buf; \
92 int i; \
93 for (i = 0; i < sizeof(sdata->field); i++) { \
94 p += scnprintf(p, buflen + buf - p, "%.2x ", \
95 sdata->field[i]); \
96 } \
97 p += scnprintf(p, buflen + buf - p, "\n"); \
98 return p - buf; \
101 #define IEEE80211_IF_FMT_ATOMIC(name, field) \
102 static ssize_t ieee80211_if_fmt_##name( \
103 const struct ieee80211_sub_if_data *sdata, \
104 char *buf, int buflen) \
106 return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
109 #define IEEE80211_IF_FMT_MAC(name, field) \
110 static ssize_t ieee80211_if_fmt_##name( \
111 const struct ieee80211_sub_if_data *sdata, char *buf, \
112 int buflen) \
114 return scnprintf(buf, buflen, "%pM\n", sdata->field); \
117 #define IEEE80211_IF_FMT_JIFFIES_TO_MS(name, field) \
118 static ssize_t ieee80211_if_fmt_##name( \
119 const struct ieee80211_sub_if_data *sdata, \
120 char *buf, int buflen) \
122 return scnprintf(buf, buflen, "%d\n", \
123 jiffies_to_msecs(sdata->field)); \
126 #define _IEEE80211_IF_FILE_OPS(name, _read, _write) \
127 static const struct file_operations name##_ops = { \
128 .read = (_read), \
129 .write = (_write), \
130 .open = simple_open, \
131 .llseek = generic_file_llseek, \
134 #define _IEEE80211_IF_FILE_R_FN(name) \
135 static ssize_t ieee80211_if_read_##name(struct file *file, \
136 char __user *userbuf, \
137 size_t count, loff_t *ppos) \
139 return ieee80211_if_read(file->private_data, \
140 userbuf, count, ppos, \
141 ieee80211_if_fmt_##name); \
144 #define _IEEE80211_IF_FILE_W_FN(name) \
145 static ssize_t ieee80211_if_write_##name(struct file *file, \
146 const char __user *userbuf, \
147 size_t count, loff_t *ppos) \
149 return ieee80211_if_write(file->private_data, userbuf, count, \
150 ppos, ieee80211_if_parse_##name); \
153 #define IEEE80211_IF_FILE_R(name) \
154 _IEEE80211_IF_FILE_R_FN(name) \
155 _IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, NULL)
157 #define IEEE80211_IF_FILE_W(name) \
158 _IEEE80211_IF_FILE_W_FN(name) \
159 _IEEE80211_IF_FILE_OPS(name, NULL, ieee80211_if_write_##name)
161 #define IEEE80211_IF_FILE_RW(name) \
162 _IEEE80211_IF_FILE_R_FN(name) \
163 _IEEE80211_IF_FILE_W_FN(name) \
164 _IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, \
165 ieee80211_if_write_##name)
167 #define IEEE80211_IF_FILE(name, field, format) \
168 IEEE80211_IF_FMT_##format(name, field) \
169 IEEE80211_IF_FILE_R(name)
171 /* common attributes */
172 IEEE80211_IF_FILE(rc_rateidx_mask_2ghz, rc_rateidx_mask[NL80211_BAND_2GHZ],
173 HEX);
174 IEEE80211_IF_FILE(rc_rateidx_mask_5ghz, rc_rateidx_mask[NL80211_BAND_5GHZ],
175 HEX);
176 IEEE80211_IF_FILE(rc_rateidx_mcs_mask_2ghz,
177 rc_rateidx_mcs_mask[NL80211_BAND_2GHZ], HEXARRAY);
178 IEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz,
179 rc_rateidx_mcs_mask[NL80211_BAND_5GHZ], HEXARRAY);
181 static ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_2ghz(
182 const struct ieee80211_sub_if_data *sdata,
183 char *buf, int buflen)
185 int i, len = 0;
186 const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_2GHZ];
188 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
189 len += scnprintf(buf + len, buflen - len, "%04x ", mask[i]);
190 len += scnprintf(buf + len, buflen - len, "\n");
192 return len;
195 IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_2ghz);
197 static ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_5ghz(
198 const struct ieee80211_sub_if_data *sdata,
199 char *buf, int buflen)
201 int i, len = 0;
202 const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_5GHZ];
204 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
205 len += scnprintf(buf + len, buflen - len, "%04x ", mask[i]);
206 len += scnprintf(buf + len, buflen - len, "\n");
208 return len;
211 IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_5ghz);
213 IEEE80211_IF_FILE(flags, flags, HEX);
214 IEEE80211_IF_FILE(state, state, LHEX);
215 IEEE80211_IF_FILE(txpower, vif.bss_conf.txpower, DEC);
216 IEEE80211_IF_FILE(ap_power_level, ap_power_level, DEC);
217 IEEE80211_IF_FILE(user_power_level, user_power_level, DEC);
219 static ssize_t
220 ieee80211_if_fmt_hw_queues(const struct ieee80211_sub_if_data *sdata,
221 char *buf, int buflen)
223 int len;
225 len = scnprintf(buf, buflen, "AC queues: VO:%d VI:%d BE:%d BK:%d\n",
226 sdata->vif.hw_queue[IEEE80211_AC_VO],
227 sdata->vif.hw_queue[IEEE80211_AC_VI],
228 sdata->vif.hw_queue[IEEE80211_AC_BE],
229 sdata->vif.hw_queue[IEEE80211_AC_BK]);
231 if (sdata->vif.type == NL80211_IFTYPE_AP)
232 len += scnprintf(buf + len, buflen - len, "cab queue: %d\n",
233 sdata->vif.cab_queue);
235 return len;
237 IEEE80211_IF_FILE_R(hw_queues);
239 /* STA attributes */
240 IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
241 IEEE80211_IF_FILE(aid, u.mgd.aid, DEC);
242 IEEE80211_IF_FILE(beacon_timeout, u.mgd.beacon_timeout, JIFFIES_TO_MS);
244 static int ieee80211_set_smps(struct ieee80211_sub_if_data *sdata,
245 enum ieee80211_smps_mode smps_mode)
247 struct ieee80211_local *local = sdata->local;
248 int err;
250 if (!(local->hw.wiphy->features & NL80211_FEATURE_STATIC_SMPS) &&
251 smps_mode == IEEE80211_SMPS_STATIC)
252 return -EINVAL;
254 /* auto should be dynamic if in PS mode */
255 if (!(local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) &&
256 (smps_mode == IEEE80211_SMPS_DYNAMIC ||
257 smps_mode == IEEE80211_SMPS_AUTOMATIC))
258 return -EINVAL;
260 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
261 sdata->vif.type != NL80211_IFTYPE_AP)
262 return -EOPNOTSUPP;
264 sdata_lock(sdata);
265 if (sdata->vif.type == NL80211_IFTYPE_STATION)
266 err = __ieee80211_request_smps_mgd(sdata, smps_mode);
267 else
268 err = __ieee80211_request_smps_ap(sdata, smps_mode);
269 sdata_unlock(sdata);
271 return err;
274 static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
275 [IEEE80211_SMPS_AUTOMATIC] = "auto",
276 [IEEE80211_SMPS_OFF] = "off",
277 [IEEE80211_SMPS_STATIC] = "static",
278 [IEEE80211_SMPS_DYNAMIC] = "dynamic",
281 static ssize_t ieee80211_if_fmt_smps(const struct ieee80211_sub_if_data *sdata,
282 char *buf, int buflen)
284 if (sdata->vif.type == NL80211_IFTYPE_STATION)
285 return snprintf(buf, buflen, "request: %s\nused: %s\n",
286 smps_modes[sdata->u.mgd.req_smps],
287 smps_modes[sdata->smps_mode]);
288 if (sdata->vif.type == NL80211_IFTYPE_AP)
289 return snprintf(buf, buflen, "request: %s\nused: %s\n",
290 smps_modes[sdata->u.ap.req_smps],
291 smps_modes[sdata->smps_mode]);
292 return -EINVAL;
295 static ssize_t ieee80211_if_parse_smps(struct ieee80211_sub_if_data *sdata,
296 const char *buf, int buflen)
298 enum ieee80211_smps_mode mode;
300 for (mode = 0; mode < IEEE80211_SMPS_NUM_MODES; mode++) {
301 if (strncmp(buf, smps_modes[mode], buflen) == 0) {
302 int err = ieee80211_set_smps(sdata, mode);
303 if (!err)
304 return buflen;
305 return err;
309 return -EINVAL;
311 IEEE80211_IF_FILE_RW(smps);
313 static ssize_t ieee80211_if_parse_tkip_mic_test(
314 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
316 struct ieee80211_local *local = sdata->local;
317 u8 addr[ETH_ALEN];
318 struct sk_buff *skb;
319 struct ieee80211_hdr *hdr;
320 __le16 fc;
322 if (!mac_pton(buf, addr))
323 return -EINVAL;
325 if (!ieee80211_sdata_running(sdata))
326 return -ENOTCONN;
328 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24 + 100);
329 if (!skb)
330 return -ENOMEM;
331 skb_reserve(skb, local->hw.extra_tx_headroom);
333 hdr = (struct ieee80211_hdr *) skb_put(skb, 24);
334 memset(hdr, 0, 24);
335 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
337 switch (sdata->vif.type) {
338 case NL80211_IFTYPE_AP:
339 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
340 /* DA BSSID SA */
341 memcpy(hdr->addr1, addr, ETH_ALEN);
342 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
343 memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN);
344 break;
345 case NL80211_IFTYPE_STATION:
346 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
347 /* BSSID SA DA */
348 sdata_lock(sdata);
349 if (!sdata->u.mgd.associated) {
350 sdata_unlock(sdata);
351 dev_kfree_skb(skb);
352 return -ENOTCONN;
354 memcpy(hdr->addr1, sdata->u.mgd.associated->bssid, ETH_ALEN);
355 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
356 memcpy(hdr->addr3, addr, ETH_ALEN);
357 sdata_unlock(sdata);
358 break;
359 default:
360 dev_kfree_skb(skb);
361 return -EOPNOTSUPP;
363 hdr->frame_control = fc;
366 * Add some length to the test frame to make it look bit more valid.
367 * The exact contents does not matter since the recipient is required
368 * to drop this because of the Michael MIC failure.
370 memset(skb_put(skb, 50), 0, 50);
372 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE;
374 ieee80211_tx_skb(sdata, skb);
376 return buflen;
378 IEEE80211_IF_FILE_W(tkip_mic_test);
380 static ssize_t ieee80211_if_parse_beacon_loss(
381 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
383 if (!ieee80211_sdata_running(sdata) || !sdata->vif.bss_conf.assoc)
384 return -ENOTCONN;
386 ieee80211_beacon_loss(&sdata->vif);
388 return buflen;
390 IEEE80211_IF_FILE_W(beacon_loss);
392 static ssize_t ieee80211_if_fmt_uapsd_queues(
393 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
395 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
397 return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_queues);
400 static ssize_t ieee80211_if_parse_uapsd_queues(
401 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
403 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
404 u8 val;
405 int ret;
407 ret = kstrtou8(buf, 0, &val);
408 if (ret)
409 return ret;
411 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
412 return -ERANGE;
414 ifmgd->uapsd_queues = val;
416 return buflen;
418 IEEE80211_IF_FILE_RW(uapsd_queues);
420 static ssize_t ieee80211_if_fmt_uapsd_max_sp_len(
421 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
423 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
425 return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_max_sp_len);
428 static ssize_t ieee80211_if_parse_uapsd_max_sp_len(
429 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
431 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
432 unsigned long val;
433 int ret;
435 ret = kstrtoul(buf, 0, &val);
436 if (ret)
437 return -EINVAL;
439 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
440 return -ERANGE;
442 ifmgd->uapsd_max_sp_len = val;
444 return buflen;
446 IEEE80211_IF_FILE_RW(uapsd_max_sp_len);
448 static ssize_t ieee80211_if_fmt_tdls_wider_bw(
449 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
451 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
452 bool tdls_wider_bw;
454 tdls_wider_bw = ieee80211_hw_check(&sdata->local->hw, TDLS_WIDER_BW) &&
455 !ifmgd->tdls_wider_bw_prohibited;
457 return snprintf(buf, buflen, "%d\n", tdls_wider_bw);
460 static ssize_t ieee80211_if_parse_tdls_wider_bw(
461 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
463 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
464 u8 val;
465 int ret;
467 ret = kstrtou8(buf, 0, &val);
468 if (ret)
469 return ret;
471 ifmgd->tdls_wider_bw_prohibited = !val;
472 return buflen;
474 IEEE80211_IF_FILE_RW(tdls_wider_bw);
476 /* AP attributes */
477 IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC);
478 IEEE80211_IF_FILE(num_sta_ps, u.ap.ps.num_sta_ps, ATOMIC);
479 IEEE80211_IF_FILE(dtim_count, u.ap.ps.dtim_count, DEC);
480 IEEE80211_IF_FILE(num_mcast_sta_vlan, u.vlan.num_mcast_sta, ATOMIC);
482 static ssize_t ieee80211_if_fmt_num_buffered_multicast(
483 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
485 return scnprintf(buf, buflen, "%u\n",
486 skb_queue_len(&sdata->u.ap.ps.bc_buf));
488 IEEE80211_IF_FILE_R(num_buffered_multicast);
490 static ssize_t ieee80211_if_fmt_aqm(
491 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
493 struct ieee80211_local *local = sdata->local;
494 struct txq_info *txqi = to_txq_info(sdata->vif.txq);
495 int len;
497 spin_lock_bh(&local->fq.lock);
498 rcu_read_lock();
500 len = scnprintf(buf,
501 buflen,
502 "ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n"
503 "%u %u %u %u %u %u %u %u %u %u\n",
504 txqi->txq.ac,
505 txqi->tin.backlog_bytes,
506 txqi->tin.backlog_packets,
507 txqi->tin.flows,
508 txqi->cstats.drop_count,
509 txqi->cstats.ecn_mark,
510 txqi->tin.overlimit,
511 txqi->tin.collisions,
512 txqi->tin.tx_bytes,
513 txqi->tin.tx_packets);
515 rcu_read_unlock();
516 spin_unlock_bh(&local->fq.lock);
518 return len;
520 IEEE80211_IF_FILE_R(aqm);
522 /* IBSS attributes */
523 static ssize_t ieee80211_if_fmt_tsf(
524 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
526 struct ieee80211_local *local = sdata->local;
527 u64 tsf;
529 tsf = drv_get_tsf(local, (struct ieee80211_sub_if_data *)sdata);
531 return scnprintf(buf, buflen, "0x%016llx\n", (unsigned long long) tsf);
534 static ssize_t ieee80211_if_parse_tsf(
535 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
537 struct ieee80211_local *local = sdata->local;
538 unsigned long long tsf;
539 int ret;
540 int tsf_is_delta = 0;
542 if (strncmp(buf, "reset", 5) == 0) {
543 if (local->ops->reset_tsf) {
544 drv_reset_tsf(local, sdata);
545 wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
547 } else {
548 if (buflen > 10 && buf[1] == '=') {
549 if (buf[0] == '+')
550 tsf_is_delta = 1;
551 else if (buf[0] == '-')
552 tsf_is_delta = -1;
553 else
554 return -EINVAL;
555 buf += 2;
557 ret = kstrtoull(buf, 10, &tsf);
558 if (ret < 0)
559 return ret;
560 if (tsf_is_delta && local->ops->offset_tsf) {
561 drv_offset_tsf(local, sdata, tsf_is_delta * tsf);
562 wiphy_info(local->hw.wiphy,
563 "debugfs offset TSF by %018lld\n",
564 tsf_is_delta * tsf);
565 } else if (local->ops->set_tsf) {
566 if (tsf_is_delta)
567 tsf = drv_get_tsf(local, sdata) +
568 tsf_is_delta * tsf;
569 drv_set_tsf(local, sdata, tsf);
570 wiphy_info(local->hw.wiphy,
571 "debugfs set TSF to %#018llx\n", tsf);
575 ieee80211_recalc_dtim(local, sdata);
576 return buflen;
578 IEEE80211_IF_FILE_RW(tsf);
581 /* WDS attributes */
582 IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
584 #ifdef CONFIG_MAC80211_MESH
585 IEEE80211_IF_FILE(estab_plinks, u.mesh.estab_plinks, ATOMIC);
587 /* Mesh stats attributes */
588 IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
589 IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
590 IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
591 IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
592 IEEE80211_IF_FILE(dropped_frames_congestion,
593 u.mesh.mshstats.dropped_frames_congestion, DEC);
594 IEEE80211_IF_FILE(dropped_frames_no_route,
595 u.mesh.mshstats.dropped_frames_no_route, DEC);
597 /* Mesh parameters */
598 IEEE80211_IF_FILE(dot11MeshMaxRetries,
599 u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
600 IEEE80211_IF_FILE(dot11MeshRetryTimeout,
601 u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
602 IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
603 u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
604 IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
605 u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
606 IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
607 IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC);
608 IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
609 IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
610 u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
611 IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
612 u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
613 IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
614 u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
615 IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval,
616 u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC);
617 IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
618 u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
619 IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
620 u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
621 IEEE80211_IF_FILE(path_refresh_time,
622 u.mesh.mshcfg.path_refresh_time, DEC);
623 IEEE80211_IF_FILE(min_discovery_timeout,
624 u.mesh.mshcfg.min_discovery_timeout, DEC);
625 IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
626 u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
627 IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol,
628 u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC);
629 IEEE80211_IF_FILE(dot11MeshHWMPRannInterval,
630 u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC);
631 IEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC);
632 IEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC);
633 IEEE80211_IF_FILE(ht_opmode, u.mesh.mshcfg.ht_opmode, DEC);
634 IEEE80211_IF_FILE(dot11MeshHWMPactivePathToRootTimeout,
635 u.mesh.mshcfg.dot11MeshHWMPactivePathToRootTimeout, DEC);
636 IEEE80211_IF_FILE(dot11MeshHWMProotInterval,
637 u.mesh.mshcfg.dot11MeshHWMProotInterval, DEC);
638 IEEE80211_IF_FILE(dot11MeshHWMPconfirmationInterval,
639 u.mesh.mshcfg.dot11MeshHWMPconfirmationInterval, DEC);
640 IEEE80211_IF_FILE(power_mode, u.mesh.mshcfg.power_mode, DEC);
641 IEEE80211_IF_FILE(dot11MeshAwakeWindowDuration,
642 u.mesh.mshcfg.dot11MeshAwakeWindowDuration, DEC);
643 #endif
645 #define DEBUGFS_ADD_MODE(name, mode) \
646 debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \
647 sdata, &name##_ops);
649 #define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400)
651 static void add_common_files(struct ieee80211_sub_if_data *sdata)
653 DEBUGFS_ADD(rc_rateidx_mask_2ghz);
654 DEBUGFS_ADD(rc_rateidx_mask_5ghz);
655 DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
656 DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
657 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_2ghz);
658 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz);
659 DEBUGFS_ADD(hw_queues);
661 if (sdata->local->ops->wake_tx_queue)
662 DEBUGFS_ADD(aqm);
665 static void add_sta_files(struct ieee80211_sub_if_data *sdata)
667 DEBUGFS_ADD(bssid);
668 DEBUGFS_ADD(aid);
669 DEBUGFS_ADD(beacon_timeout);
670 DEBUGFS_ADD_MODE(smps, 0600);
671 DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
672 DEBUGFS_ADD_MODE(beacon_loss, 0200);
673 DEBUGFS_ADD_MODE(uapsd_queues, 0600);
674 DEBUGFS_ADD_MODE(uapsd_max_sp_len, 0600);
675 DEBUGFS_ADD_MODE(tdls_wider_bw, 0600);
678 static void add_ap_files(struct ieee80211_sub_if_data *sdata)
680 DEBUGFS_ADD(num_mcast_sta);
681 DEBUGFS_ADD_MODE(smps, 0600);
682 DEBUGFS_ADD(num_sta_ps);
683 DEBUGFS_ADD(dtim_count);
684 DEBUGFS_ADD(num_buffered_multicast);
685 DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
688 static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
690 /* add num_mcast_sta_vlan using name num_mcast_sta */
691 debugfs_create_file("num_mcast_sta", 0400, sdata->vif.debugfs_dir,
692 sdata, &num_mcast_sta_vlan_ops);
695 static void add_ibss_files(struct ieee80211_sub_if_data *sdata)
697 DEBUGFS_ADD_MODE(tsf, 0600);
700 static void add_wds_files(struct ieee80211_sub_if_data *sdata)
702 DEBUGFS_ADD(peer);
705 #ifdef CONFIG_MAC80211_MESH
707 static void add_mesh_files(struct ieee80211_sub_if_data *sdata)
709 DEBUGFS_ADD_MODE(tsf, 0600);
710 DEBUGFS_ADD_MODE(estab_plinks, 0400);
713 static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
715 struct dentry *dir = debugfs_create_dir("mesh_stats",
716 sdata->vif.debugfs_dir);
717 #define MESHSTATS_ADD(name)\
718 debugfs_create_file(#name, 0400, dir, sdata, &name##_ops);
720 MESHSTATS_ADD(fwded_mcast);
721 MESHSTATS_ADD(fwded_unicast);
722 MESHSTATS_ADD(fwded_frames);
723 MESHSTATS_ADD(dropped_frames_ttl);
724 MESHSTATS_ADD(dropped_frames_no_route);
725 MESHSTATS_ADD(dropped_frames_congestion);
726 #undef MESHSTATS_ADD
729 static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
731 struct dentry *dir = debugfs_create_dir("mesh_config",
732 sdata->vif.debugfs_dir);
734 #define MESHPARAMS_ADD(name) \
735 debugfs_create_file(#name, 0600, dir, sdata, &name##_ops);
737 MESHPARAMS_ADD(dot11MeshMaxRetries);
738 MESHPARAMS_ADD(dot11MeshRetryTimeout);
739 MESHPARAMS_ADD(dot11MeshConfirmTimeout);
740 MESHPARAMS_ADD(dot11MeshHoldingTimeout);
741 MESHPARAMS_ADD(dot11MeshTTL);
742 MESHPARAMS_ADD(element_ttl);
743 MESHPARAMS_ADD(auto_open_plinks);
744 MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
745 MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
746 MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
747 MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval);
748 MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
749 MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
750 MESHPARAMS_ADD(path_refresh_time);
751 MESHPARAMS_ADD(min_discovery_timeout);
752 MESHPARAMS_ADD(dot11MeshHWMPRootMode);
753 MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
754 MESHPARAMS_ADD(dot11MeshForwarding);
755 MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
756 MESHPARAMS_ADD(rssi_threshold);
757 MESHPARAMS_ADD(ht_opmode);
758 MESHPARAMS_ADD(dot11MeshHWMPactivePathToRootTimeout);
759 MESHPARAMS_ADD(dot11MeshHWMProotInterval);
760 MESHPARAMS_ADD(dot11MeshHWMPconfirmationInterval);
761 MESHPARAMS_ADD(power_mode);
762 MESHPARAMS_ADD(dot11MeshAwakeWindowDuration);
763 #undef MESHPARAMS_ADD
765 #endif
767 static void add_files(struct ieee80211_sub_if_data *sdata)
769 if (!sdata->vif.debugfs_dir)
770 return;
772 DEBUGFS_ADD(flags);
773 DEBUGFS_ADD(state);
774 DEBUGFS_ADD(txpower);
775 DEBUGFS_ADD(user_power_level);
776 DEBUGFS_ADD(ap_power_level);
778 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
779 add_common_files(sdata);
781 switch (sdata->vif.type) {
782 case NL80211_IFTYPE_MESH_POINT:
783 #ifdef CONFIG_MAC80211_MESH
784 add_mesh_files(sdata);
785 add_mesh_stats(sdata);
786 add_mesh_config(sdata);
787 #endif
788 break;
789 case NL80211_IFTYPE_STATION:
790 add_sta_files(sdata);
791 break;
792 case NL80211_IFTYPE_ADHOC:
793 add_ibss_files(sdata);
794 break;
795 case NL80211_IFTYPE_AP:
796 add_ap_files(sdata);
797 break;
798 case NL80211_IFTYPE_AP_VLAN:
799 add_vlan_files(sdata);
800 break;
801 case NL80211_IFTYPE_WDS:
802 add_wds_files(sdata);
803 break;
804 default:
805 break;
809 void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
811 char buf[10+IFNAMSIZ];
813 sprintf(buf, "netdev:%s", sdata->name);
814 sdata->vif.debugfs_dir = debugfs_create_dir(buf,
815 sdata->local->hw.wiphy->debugfsdir);
816 if (sdata->vif.debugfs_dir)
817 sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
818 sdata->vif.debugfs_dir);
819 add_files(sdata);
822 void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
824 if (!sdata->vif.debugfs_dir)
825 return;
827 debugfs_remove_recursive(sdata->vif.debugfs_dir);
828 sdata->vif.debugfs_dir = NULL;
829 sdata->debugfs.subdir_stations = NULL;
832 void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
834 struct dentry *dir;
835 char buf[10 + IFNAMSIZ];
837 dir = sdata->vif.debugfs_dir;
839 if (!dir)
840 return;
842 sprintf(buf, "netdev:%s", sdata->name);
843 if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
844 sdata_err(sdata,
845 "debugfs: failed to rename debugfs dir to %s\n",
846 buf);