1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright (C) 2020 Intel Corporation
8 #include <linux/kernel.h>
9 #include <linux/device.h>
11 #include <linux/if_ether.h>
12 #include <linux/interrupt.h>
13 #include <linux/netdevice.h>
14 #include <linux/rtnetlink.h>
15 #include <linux/slab.h>
16 #include <linux/notifier.h>
17 #include <net/mac80211.h>
18 #include <net/cfg80211.h>
19 #include "ieee80211_i.h"
22 #include "debugfs_netdev.h"
23 #include "driver-ops.h"
25 static ssize_t ieee80211_if_read(
26 struct ieee80211_sub_if_data *sdata,
28 size_t count, loff_t *ppos,
29 ssize_t (*format)(const struct ieee80211_sub_if_data *, char *, int))
32 ssize_t ret = -EINVAL;
34 read_lock(&dev_base_lock);
35 ret = (*format)(sdata, buf, sizeof(buf));
36 read_unlock(&dev_base_lock);
39 ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);
44 static ssize_t ieee80211_if_write(
45 struct ieee80211_sub_if_data *sdata,
46 const char __user *userbuf,
47 size_t count, loff_t *ppos,
48 ssize_t (*write)(struct ieee80211_sub_if_data *, const char *, int))
53 if (count >= sizeof(buf))
56 if (copy_from_user(buf, userbuf, count))
61 ret = (*write)(sdata, buf, count);
67 #define IEEE80211_IF_FMT(name, field, format_string) \
68 static ssize_t ieee80211_if_fmt_##name( \
69 const struct ieee80211_sub_if_data *sdata, char *buf, \
72 return scnprintf(buf, buflen, format_string, sdata->field); \
74 #define IEEE80211_IF_FMT_DEC(name, field) \
75 IEEE80211_IF_FMT(name, field, "%d\n")
76 #define IEEE80211_IF_FMT_HEX(name, field) \
77 IEEE80211_IF_FMT(name, field, "%#x\n")
78 #define IEEE80211_IF_FMT_LHEX(name, field) \
79 IEEE80211_IF_FMT(name, field, "%#lx\n")
80 #define IEEE80211_IF_FMT_SIZE(name, field) \
81 IEEE80211_IF_FMT(name, field, "%zd\n")
83 #define IEEE80211_IF_FMT_HEXARRAY(name, field) \
84 static ssize_t ieee80211_if_fmt_##name( \
85 const struct ieee80211_sub_if_data *sdata, \
86 char *buf, int buflen) \
90 for (i = 0; i < sizeof(sdata->field); i++) { \
91 p += scnprintf(p, buflen + buf - p, "%.2x ", \
94 p += scnprintf(p, buflen + buf - p, "\n"); \
98 #define IEEE80211_IF_FMT_ATOMIC(name, field) \
99 static ssize_t ieee80211_if_fmt_##name( \
100 const struct ieee80211_sub_if_data *sdata, \
101 char *buf, int buflen) \
103 return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
106 #define IEEE80211_IF_FMT_MAC(name, field) \
107 static ssize_t ieee80211_if_fmt_##name( \
108 const struct ieee80211_sub_if_data *sdata, char *buf, \
111 return scnprintf(buf, buflen, "%pM\n", sdata->field); \
114 #define IEEE80211_IF_FMT_JIFFIES_TO_MS(name, field) \
115 static ssize_t ieee80211_if_fmt_##name( \
116 const struct ieee80211_sub_if_data *sdata, \
117 char *buf, int buflen) \
119 return scnprintf(buf, buflen, "%d\n", \
120 jiffies_to_msecs(sdata->field)); \
123 #define _IEEE80211_IF_FILE_OPS(name, _read, _write) \
124 static const struct file_operations name##_ops = { \
127 .open = simple_open, \
128 .llseek = generic_file_llseek, \
131 #define _IEEE80211_IF_FILE_R_FN(name) \
132 static ssize_t ieee80211_if_read_##name(struct file *file, \
133 char __user *userbuf, \
134 size_t count, loff_t *ppos) \
136 return ieee80211_if_read(file->private_data, \
137 userbuf, count, ppos, \
138 ieee80211_if_fmt_##name); \
141 #define _IEEE80211_IF_FILE_W_FN(name) \
142 static ssize_t ieee80211_if_write_##name(struct file *file, \
143 const char __user *userbuf, \
144 size_t count, loff_t *ppos) \
146 return ieee80211_if_write(file->private_data, userbuf, count, \
147 ppos, ieee80211_if_parse_##name); \
150 #define IEEE80211_IF_FILE_R(name) \
151 _IEEE80211_IF_FILE_R_FN(name) \
152 _IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, NULL)
154 #define IEEE80211_IF_FILE_W(name) \
155 _IEEE80211_IF_FILE_W_FN(name) \
156 _IEEE80211_IF_FILE_OPS(name, NULL, ieee80211_if_write_##name)
158 #define IEEE80211_IF_FILE_RW(name) \
159 _IEEE80211_IF_FILE_R_FN(name) \
160 _IEEE80211_IF_FILE_W_FN(name) \
161 _IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, \
162 ieee80211_if_write_##name)
164 #define IEEE80211_IF_FILE(name, field, format) \
165 IEEE80211_IF_FMT_##format(name, field) \
166 IEEE80211_IF_FILE_R(name)
168 /* common attributes */
169 IEEE80211_IF_FILE(rc_rateidx_mask_2ghz, rc_rateidx_mask[NL80211_BAND_2GHZ],
171 IEEE80211_IF_FILE(rc_rateidx_mask_5ghz, rc_rateidx_mask[NL80211_BAND_5GHZ],
173 IEEE80211_IF_FILE(rc_rateidx_mcs_mask_2ghz,
174 rc_rateidx_mcs_mask[NL80211_BAND_2GHZ], HEXARRAY);
175 IEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz,
176 rc_rateidx_mcs_mask[NL80211_BAND_5GHZ], HEXARRAY);
178 static ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_2ghz(
179 const struct ieee80211_sub_if_data *sdata,
180 char *buf, int buflen)
183 const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_2GHZ];
185 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
186 len += scnprintf(buf + len, buflen - len, "%04x ", mask[i]);
187 len += scnprintf(buf + len, buflen - len, "\n");
192 IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_2ghz);
194 static ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_5ghz(
195 const struct ieee80211_sub_if_data *sdata,
196 char *buf, int buflen)
199 const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_5GHZ];
201 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
202 len += scnprintf(buf + len, buflen - len, "%04x ", mask[i]);
203 len += scnprintf(buf + len, buflen - len, "\n");
208 IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_5ghz);
210 IEEE80211_IF_FILE(flags, flags, HEX);
211 IEEE80211_IF_FILE(state, state, LHEX);
212 IEEE80211_IF_FILE(txpower, vif.bss_conf.txpower, DEC);
213 IEEE80211_IF_FILE(ap_power_level, ap_power_level, DEC);
214 IEEE80211_IF_FILE(user_power_level, user_power_level, DEC);
217 ieee80211_if_fmt_hw_queues(const struct ieee80211_sub_if_data *sdata,
218 char *buf, int buflen)
222 len = scnprintf(buf, buflen, "AC queues: VO:%d VI:%d BE:%d BK:%d\n",
223 sdata->vif.hw_queue[IEEE80211_AC_VO],
224 sdata->vif.hw_queue[IEEE80211_AC_VI],
225 sdata->vif.hw_queue[IEEE80211_AC_BE],
226 sdata->vif.hw_queue[IEEE80211_AC_BK]);
228 if (sdata->vif.type == NL80211_IFTYPE_AP)
229 len += scnprintf(buf + len, buflen - len, "cab queue: %d\n",
230 sdata->vif.cab_queue);
234 IEEE80211_IF_FILE_R(hw_queues);
237 IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
238 IEEE80211_IF_FILE(aid, vif.bss_conf.aid, DEC);
239 IEEE80211_IF_FILE(beacon_timeout, u.mgd.beacon_timeout, JIFFIES_TO_MS);
241 static int ieee80211_set_smps(struct ieee80211_sub_if_data *sdata,
242 enum ieee80211_smps_mode smps_mode)
244 struct ieee80211_local *local = sdata->local;
247 if (!(local->hw.wiphy->features & NL80211_FEATURE_STATIC_SMPS) &&
248 smps_mode == IEEE80211_SMPS_STATIC)
251 /* auto should be dynamic if in PS mode */
252 if (!(local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) &&
253 (smps_mode == IEEE80211_SMPS_DYNAMIC ||
254 smps_mode == IEEE80211_SMPS_AUTOMATIC))
257 if (sdata->vif.type != NL80211_IFTYPE_STATION)
261 err = __ieee80211_request_smps_mgd(sdata, smps_mode);
267 static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
268 [IEEE80211_SMPS_AUTOMATIC] = "auto",
269 [IEEE80211_SMPS_OFF] = "off",
270 [IEEE80211_SMPS_STATIC] = "static",
271 [IEEE80211_SMPS_DYNAMIC] = "dynamic",
274 static ssize_t ieee80211_if_fmt_smps(const struct ieee80211_sub_if_data *sdata,
275 char *buf, int buflen)
277 if (sdata->vif.type == NL80211_IFTYPE_STATION)
278 return snprintf(buf, buflen, "request: %s\nused: %s\n",
279 smps_modes[sdata->u.mgd.req_smps],
280 smps_modes[sdata->smps_mode]);
284 static ssize_t ieee80211_if_parse_smps(struct ieee80211_sub_if_data *sdata,
285 const char *buf, int buflen)
287 enum ieee80211_smps_mode mode;
289 for (mode = 0; mode < IEEE80211_SMPS_NUM_MODES; mode++) {
290 if (strncmp(buf, smps_modes[mode], buflen) == 0) {
291 int err = ieee80211_set_smps(sdata, mode);
300 IEEE80211_IF_FILE_RW(smps);
302 static ssize_t ieee80211_if_parse_tkip_mic_test(
303 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
305 struct ieee80211_local *local = sdata->local;
308 struct ieee80211_hdr *hdr;
311 if (!mac_pton(buf, addr))
314 if (!ieee80211_sdata_running(sdata))
317 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24 + 100);
320 skb_reserve(skb, local->hw.extra_tx_headroom);
322 hdr = skb_put_zero(skb, 24);
323 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
325 switch (sdata->vif.type) {
326 case NL80211_IFTYPE_AP:
327 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
329 memcpy(hdr->addr1, addr, ETH_ALEN);
330 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
331 memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN);
333 case NL80211_IFTYPE_STATION:
334 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
337 if (!sdata->u.mgd.associated) {
342 memcpy(hdr->addr1, sdata->u.mgd.associated->bssid, ETH_ALEN);
343 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
344 memcpy(hdr->addr3, addr, ETH_ALEN);
351 hdr->frame_control = fc;
354 * Add some length to the test frame to make it look bit more valid.
355 * The exact contents does not matter since the recipient is required
356 * to drop this because of the Michael MIC failure.
358 skb_put_zero(skb, 50);
360 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE;
362 ieee80211_tx_skb(sdata, skb);
366 IEEE80211_IF_FILE_W(tkip_mic_test);
368 static ssize_t ieee80211_if_parse_beacon_loss(
369 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
371 if (!ieee80211_sdata_running(sdata) || !sdata->vif.bss_conf.assoc)
374 ieee80211_beacon_loss(&sdata->vif);
378 IEEE80211_IF_FILE_W(beacon_loss);
380 static ssize_t ieee80211_if_fmt_uapsd_queues(
381 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
383 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
385 return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_queues);
388 static ssize_t ieee80211_if_parse_uapsd_queues(
389 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
391 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
395 ret = kstrtou8(buf, 0, &val);
399 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
402 ifmgd->uapsd_queues = val;
406 IEEE80211_IF_FILE_RW(uapsd_queues);
408 static ssize_t ieee80211_if_fmt_uapsd_max_sp_len(
409 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
411 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
413 return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_max_sp_len);
416 static ssize_t ieee80211_if_parse_uapsd_max_sp_len(
417 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
419 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
423 ret = kstrtoul(buf, 0, &val);
427 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
430 ifmgd->uapsd_max_sp_len = val;
434 IEEE80211_IF_FILE_RW(uapsd_max_sp_len);
436 static ssize_t ieee80211_if_fmt_tdls_wider_bw(
437 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
439 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
442 tdls_wider_bw = ieee80211_hw_check(&sdata->local->hw, TDLS_WIDER_BW) &&
443 !ifmgd->tdls_wider_bw_prohibited;
445 return snprintf(buf, buflen, "%d\n", tdls_wider_bw);
448 static ssize_t ieee80211_if_parse_tdls_wider_bw(
449 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
451 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
455 ret = kstrtou8(buf, 0, &val);
459 ifmgd->tdls_wider_bw_prohibited = !val;
462 IEEE80211_IF_FILE_RW(tdls_wider_bw);
465 IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC);
466 IEEE80211_IF_FILE(num_sta_ps, u.ap.ps.num_sta_ps, ATOMIC);
467 IEEE80211_IF_FILE(dtim_count, u.ap.ps.dtim_count, DEC);
468 IEEE80211_IF_FILE(num_mcast_sta_vlan, u.vlan.num_mcast_sta, ATOMIC);
470 static ssize_t ieee80211_if_fmt_num_buffered_multicast(
471 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
473 return scnprintf(buf, buflen, "%u\n",
474 skb_queue_len(&sdata->u.ap.ps.bc_buf));
476 IEEE80211_IF_FILE_R(num_buffered_multicast);
478 static ssize_t ieee80211_if_fmt_aqm(
479 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
481 struct ieee80211_local *local = sdata->local;
482 struct txq_info *txqi;
488 txqi = to_txq_info(sdata->vif.txq);
490 spin_lock_bh(&local->fq.lock);
495 "ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n"
496 "%u %u %u %u %u %u %u %u %u %u\n",
498 txqi->tin.backlog_bytes,
499 txqi->tin.backlog_packets,
501 txqi->cstats.drop_count,
502 txqi->cstats.ecn_mark,
504 txqi->tin.collisions,
506 txqi->tin.tx_packets);
509 spin_unlock_bh(&local->fq.lock);
513 IEEE80211_IF_FILE_R(aqm);
515 static ssize_t ieee80211_if_fmt_airtime(
516 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
518 struct ieee80211_local *local = sdata->local;
519 struct ieee80211_txq *txq = sdata->vif.txq;
520 struct airtime_info *air_info;
526 spin_lock_bh(&local->airtime[txq->ac].lock);
527 air_info = to_airtime_info(txq);
530 "RX: %llu us\nTX: %llu us\nWeight: %u\n"
532 air_info->rx_airtime,
533 air_info->tx_airtime,
536 spin_unlock_bh(&local->airtime[txq->ac].lock);
541 IEEE80211_IF_FILE_R(airtime);
543 IEEE80211_IF_FILE(multicast_to_unicast, u.ap.multicast_to_unicast, HEX);
545 /* IBSS attributes */
546 static ssize_t ieee80211_if_fmt_tsf(
547 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
549 struct ieee80211_local *local = sdata->local;
552 tsf = drv_get_tsf(local, (struct ieee80211_sub_if_data *)sdata);
554 return scnprintf(buf, buflen, "0x%016llx\n", (unsigned long long) tsf);
557 static ssize_t ieee80211_if_parse_tsf(
558 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
560 struct ieee80211_local *local = sdata->local;
561 unsigned long long tsf;
563 int tsf_is_delta = 0;
565 if (strncmp(buf, "reset", 5) == 0) {
566 if (local->ops->reset_tsf) {
567 drv_reset_tsf(local, sdata);
568 wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
571 if (buflen > 10 && buf[1] == '=') {
574 else if (buf[0] == '-')
580 ret = kstrtoull(buf, 10, &tsf);
583 if (tsf_is_delta && local->ops->offset_tsf) {
584 drv_offset_tsf(local, sdata, tsf_is_delta * tsf);
585 wiphy_info(local->hw.wiphy,
586 "debugfs offset TSF by %018lld\n",
588 } else if (local->ops->set_tsf) {
590 tsf = drv_get_tsf(local, sdata) +
592 drv_set_tsf(local, sdata, tsf);
593 wiphy_info(local->hw.wiphy,
594 "debugfs set TSF to %#018llx\n", tsf);
598 ieee80211_recalc_dtim(local, sdata);
601 IEEE80211_IF_FILE_RW(tsf);
604 #ifdef CONFIG_MAC80211_MESH
605 IEEE80211_IF_FILE(estab_plinks, u.mesh.estab_plinks, ATOMIC);
607 /* Mesh stats attributes */
608 IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
609 IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
610 IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
611 IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
612 IEEE80211_IF_FILE(dropped_frames_congestion,
613 u.mesh.mshstats.dropped_frames_congestion, DEC);
614 IEEE80211_IF_FILE(dropped_frames_no_route,
615 u.mesh.mshstats.dropped_frames_no_route, DEC);
617 /* Mesh parameters */
618 IEEE80211_IF_FILE(dot11MeshMaxRetries,
619 u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
620 IEEE80211_IF_FILE(dot11MeshRetryTimeout,
621 u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
622 IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
623 u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
624 IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
625 u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
626 IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
627 IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC);
628 IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
629 IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
630 u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
631 IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
632 u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
633 IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
634 u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
635 IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval,
636 u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC);
637 IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
638 u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
639 IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
640 u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
641 IEEE80211_IF_FILE(path_refresh_time,
642 u.mesh.mshcfg.path_refresh_time, DEC);
643 IEEE80211_IF_FILE(min_discovery_timeout,
644 u.mesh.mshcfg.min_discovery_timeout, DEC);
645 IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
646 u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
647 IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol,
648 u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC);
649 IEEE80211_IF_FILE(dot11MeshHWMPRannInterval,
650 u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC);
651 IEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC);
652 IEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC);
653 IEEE80211_IF_FILE(ht_opmode, u.mesh.mshcfg.ht_opmode, DEC);
654 IEEE80211_IF_FILE(dot11MeshHWMPactivePathToRootTimeout,
655 u.mesh.mshcfg.dot11MeshHWMPactivePathToRootTimeout, DEC);
656 IEEE80211_IF_FILE(dot11MeshHWMProotInterval,
657 u.mesh.mshcfg.dot11MeshHWMProotInterval, DEC);
658 IEEE80211_IF_FILE(dot11MeshHWMPconfirmationInterval,
659 u.mesh.mshcfg.dot11MeshHWMPconfirmationInterval, DEC);
660 IEEE80211_IF_FILE(power_mode, u.mesh.mshcfg.power_mode, DEC);
661 IEEE80211_IF_FILE(dot11MeshAwakeWindowDuration,
662 u.mesh.mshcfg.dot11MeshAwakeWindowDuration, DEC);
663 IEEE80211_IF_FILE(dot11MeshConnectedToMeshGate,
664 u.mesh.mshcfg.dot11MeshConnectedToMeshGate, DEC);
665 IEEE80211_IF_FILE(dot11MeshNolearn, u.mesh.mshcfg.dot11MeshNolearn, DEC);
666 IEEE80211_IF_FILE(dot11MeshConnectedToAuthServer,
667 u.mesh.mshcfg.dot11MeshConnectedToAuthServer, DEC);
670 #define DEBUGFS_ADD_MODE(name, mode) \
671 debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \
674 #define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400)
676 static void add_common_files(struct ieee80211_sub_if_data *sdata)
678 DEBUGFS_ADD(rc_rateidx_mask_2ghz);
679 DEBUGFS_ADD(rc_rateidx_mask_5ghz);
680 DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
681 DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
682 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_2ghz);
683 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz);
684 DEBUGFS_ADD(hw_queues);
686 if (sdata->local->ops->wake_tx_queue &&
687 sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE &&
688 sdata->vif.type != NL80211_IFTYPE_NAN) {
690 DEBUGFS_ADD(airtime);
694 static void add_sta_files(struct ieee80211_sub_if_data *sdata)
698 DEBUGFS_ADD(beacon_timeout);
699 DEBUGFS_ADD_MODE(smps, 0600);
700 DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
701 DEBUGFS_ADD_MODE(beacon_loss, 0200);
702 DEBUGFS_ADD_MODE(uapsd_queues, 0600);
703 DEBUGFS_ADD_MODE(uapsd_max_sp_len, 0600);
704 DEBUGFS_ADD_MODE(tdls_wider_bw, 0600);
707 static void add_ap_files(struct ieee80211_sub_if_data *sdata)
709 DEBUGFS_ADD(num_mcast_sta);
710 DEBUGFS_ADD_MODE(smps, 0600);
711 DEBUGFS_ADD(num_sta_ps);
712 DEBUGFS_ADD(dtim_count);
713 DEBUGFS_ADD(num_buffered_multicast);
714 DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
715 DEBUGFS_ADD_MODE(multicast_to_unicast, 0600);
718 static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
720 /* add num_mcast_sta_vlan using name num_mcast_sta */
721 debugfs_create_file("num_mcast_sta", 0400, sdata->vif.debugfs_dir,
722 sdata, &num_mcast_sta_vlan_ops);
725 static void add_ibss_files(struct ieee80211_sub_if_data *sdata)
727 DEBUGFS_ADD_MODE(tsf, 0600);
730 #ifdef CONFIG_MAC80211_MESH
732 static void add_mesh_files(struct ieee80211_sub_if_data *sdata)
734 DEBUGFS_ADD_MODE(tsf, 0600);
735 DEBUGFS_ADD_MODE(estab_plinks, 0400);
738 static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
740 struct dentry *dir = debugfs_create_dir("mesh_stats",
741 sdata->vif.debugfs_dir);
742 #define MESHSTATS_ADD(name)\
743 debugfs_create_file(#name, 0400, dir, sdata, &name##_ops)
745 MESHSTATS_ADD(fwded_mcast);
746 MESHSTATS_ADD(fwded_unicast);
747 MESHSTATS_ADD(fwded_frames);
748 MESHSTATS_ADD(dropped_frames_ttl);
749 MESHSTATS_ADD(dropped_frames_no_route);
750 MESHSTATS_ADD(dropped_frames_congestion);
754 static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
756 struct dentry *dir = debugfs_create_dir("mesh_config",
757 sdata->vif.debugfs_dir);
759 #define MESHPARAMS_ADD(name) \
760 debugfs_create_file(#name, 0600, dir, sdata, &name##_ops)
762 MESHPARAMS_ADD(dot11MeshMaxRetries);
763 MESHPARAMS_ADD(dot11MeshRetryTimeout);
764 MESHPARAMS_ADD(dot11MeshConfirmTimeout);
765 MESHPARAMS_ADD(dot11MeshHoldingTimeout);
766 MESHPARAMS_ADD(dot11MeshTTL);
767 MESHPARAMS_ADD(element_ttl);
768 MESHPARAMS_ADD(auto_open_plinks);
769 MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
770 MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
771 MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
772 MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval);
773 MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
774 MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
775 MESHPARAMS_ADD(path_refresh_time);
776 MESHPARAMS_ADD(min_discovery_timeout);
777 MESHPARAMS_ADD(dot11MeshHWMPRootMode);
778 MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
779 MESHPARAMS_ADD(dot11MeshForwarding);
780 MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
781 MESHPARAMS_ADD(rssi_threshold);
782 MESHPARAMS_ADD(ht_opmode);
783 MESHPARAMS_ADD(dot11MeshHWMPactivePathToRootTimeout);
784 MESHPARAMS_ADD(dot11MeshHWMProotInterval);
785 MESHPARAMS_ADD(dot11MeshHWMPconfirmationInterval);
786 MESHPARAMS_ADD(power_mode);
787 MESHPARAMS_ADD(dot11MeshAwakeWindowDuration);
788 MESHPARAMS_ADD(dot11MeshConnectedToMeshGate);
789 MESHPARAMS_ADD(dot11MeshNolearn);
790 MESHPARAMS_ADD(dot11MeshConnectedToAuthServer);
791 #undef MESHPARAMS_ADD
795 static void add_files(struct ieee80211_sub_if_data *sdata)
797 if (!sdata->vif.debugfs_dir)
802 DEBUGFS_ADD(txpower);
803 DEBUGFS_ADD(user_power_level);
804 DEBUGFS_ADD(ap_power_level);
806 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
807 add_common_files(sdata);
809 switch (sdata->vif.type) {
810 case NL80211_IFTYPE_MESH_POINT:
811 #ifdef CONFIG_MAC80211_MESH
812 add_mesh_files(sdata);
813 add_mesh_stats(sdata);
814 add_mesh_config(sdata);
817 case NL80211_IFTYPE_STATION:
818 add_sta_files(sdata);
820 case NL80211_IFTYPE_ADHOC:
821 add_ibss_files(sdata);
823 case NL80211_IFTYPE_AP:
826 case NL80211_IFTYPE_AP_VLAN:
827 add_vlan_files(sdata);
834 void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
836 char buf[10+IFNAMSIZ];
838 sprintf(buf, "netdev:%s", sdata->name);
839 sdata->vif.debugfs_dir = debugfs_create_dir(buf,
840 sdata->local->hw.wiphy->debugfsdir);
841 sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
842 sdata->vif.debugfs_dir);
846 void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
848 if (!sdata->vif.debugfs_dir)
851 debugfs_remove_recursive(sdata->vif.debugfs_dir);
852 sdata->vif.debugfs_dir = NULL;
853 sdata->debugfs.subdir_stations = NULL;
856 void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
859 char buf[10 + IFNAMSIZ];
861 dir = sdata->vif.debugfs_dir;
863 if (IS_ERR_OR_NULL(dir))
866 sprintf(buf, "netdev:%s", sdata->name);
867 debugfs_rename(dir->d_parent, dir, dir->d_parent, buf);