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-2023 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(
28 size_t count, loff_t *ppos,
29 ssize_t (*format)(const void *, char *, int))
32 ssize_t ret = -EINVAL;
34 read_lock(&dev_base_lock);
35 ret = (*format)(data, 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(
46 const char __user *userbuf,
47 size_t count, loff_t *ppos,
48 ssize_t (*write)(void *, const char *, int))
53 if (count >= sizeof(buf))
56 if (copy_from_user(buf, userbuf, count))
61 ret = (*write)(data, buf, count);
67 #define IEEE80211_IF_FMT(name, type, field, format_string) \
68 static ssize_t ieee80211_if_fmt_##name( \
69 const type *data, char *buf, \
72 return scnprintf(buf, buflen, format_string, data->field); \
74 #define IEEE80211_IF_FMT_DEC(name, type, field) \
75 IEEE80211_IF_FMT(name, type, field, "%d\n")
76 #define IEEE80211_IF_FMT_HEX(name, type, field) \
77 IEEE80211_IF_FMT(name, type, field, "%#x\n")
78 #define IEEE80211_IF_FMT_LHEX(name, type, field) \
79 IEEE80211_IF_FMT(name, type, field, "%#lx\n")
81 #define IEEE80211_IF_FMT_HEXARRAY(name, type, field) \
82 static ssize_t ieee80211_if_fmt_##name( \
84 char *buf, int buflen) \
88 for (i = 0; i < sizeof(data->field); i++) { \
89 p += scnprintf(p, buflen + buf - p, "%.2x ", \
92 p += scnprintf(p, buflen + buf - p, "\n"); \
96 #define IEEE80211_IF_FMT_ATOMIC(name, type, field) \
97 static ssize_t ieee80211_if_fmt_##name( \
99 char *buf, int buflen) \
101 return scnprintf(buf, buflen, "%d\n", atomic_read(&data->field));\
104 #define IEEE80211_IF_FMT_MAC(name, type, field) \
105 static ssize_t ieee80211_if_fmt_##name( \
106 const type *data, char *buf, \
109 return scnprintf(buf, buflen, "%pM\n", data->field); \
112 #define IEEE80211_IF_FMT_JIFFIES_TO_MS(name, type, field) \
113 static ssize_t ieee80211_if_fmt_##name( \
115 char *buf, int buflen) \
117 return scnprintf(buf, buflen, "%d\n", \
118 jiffies_to_msecs(data->field)); \
121 #define _IEEE80211_IF_FILE_OPS(name, _read, _write) \
122 static const struct file_operations name##_ops = { \
125 .open = simple_open, \
126 .llseek = generic_file_llseek, \
129 #define _IEEE80211_IF_FILE_R_FN(name, type) \
130 static ssize_t ieee80211_if_read_##name(struct file *file, \
131 char __user *userbuf, \
132 size_t count, loff_t *ppos) \
134 ssize_t (*fn)(const void *, char *, int) = (void *) \
135 ((ssize_t (*)(const type, char *, int)) \
136 ieee80211_if_fmt_##name); \
137 return ieee80211_if_read(file->private_data, \
138 userbuf, count, ppos, fn); \
141 #define _IEEE80211_IF_FILE_W_FN(name, type) \
142 static ssize_t ieee80211_if_write_##name(struct file *file, \
143 const char __user *userbuf, \
144 size_t count, loff_t *ppos) \
146 ssize_t (*fn)(void *, const char *, int) = (void *) \
147 ((ssize_t (*)(type, const char *, int)) \
148 ieee80211_if_parse_##name); \
149 return ieee80211_if_write(file->private_data, userbuf, count, \
153 #define IEEE80211_IF_FILE_R(name) \
154 _IEEE80211_IF_FILE_R_FN(name, struct ieee80211_sub_if_data *) \
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, struct ieee80211_sub_if_data *) \
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, struct ieee80211_sub_if_data *) \
163 _IEEE80211_IF_FILE_W_FN(name, struct ieee80211_sub_if_data *) \
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, struct ieee80211_sub_if_data, field) \
169 IEEE80211_IF_FILE_R(name)
171 /* Same but with a link_ prefix in the ops variable name and different type */
172 #define IEEE80211_IF_LINK_FILE_R(name) \
173 _IEEE80211_IF_FILE_R_FN(name, struct ieee80211_link_data *) \
174 _IEEE80211_IF_FILE_OPS(link_##name, ieee80211_if_read_##name, NULL)
176 #define IEEE80211_IF_LINK_FILE_W(name) \
177 _IEEE80211_IF_FILE_W_FN(name) \
178 _IEEE80211_IF_FILE_OPS(link_##name, NULL, ieee80211_if_write_##name)
180 #define IEEE80211_IF_LINK_FILE_RW(name) \
181 _IEEE80211_IF_FILE_R_FN(name, struct ieee80211_link_data *) \
182 _IEEE80211_IF_FILE_W_FN(name, struct ieee80211_link_data *) \
183 _IEEE80211_IF_FILE_OPS(link_##name, ieee80211_if_read_##name, \
184 ieee80211_if_write_##name)
186 #define IEEE80211_IF_LINK_FILE(name, field, format) \
187 IEEE80211_IF_FMT_##format(name, struct ieee80211_link_data, field) \
188 IEEE80211_IF_LINK_FILE_R(name)
190 /* common attributes */
191 IEEE80211_IF_FILE(rc_rateidx_mask_2ghz, rc_rateidx_mask[NL80211_BAND_2GHZ],
193 IEEE80211_IF_FILE(rc_rateidx_mask_5ghz, rc_rateidx_mask[NL80211_BAND_5GHZ],
195 IEEE80211_IF_FILE(rc_rateidx_mcs_mask_2ghz,
196 rc_rateidx_mcs_mask[NL80211_BAND_2GHZ], HEXARRAY);
197 IEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz,
198 rc_rateidx_mcs_mask[NL80211_BAND_5GHZ], HEXARRAY);
200 static ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_2ghz(
201 const struct ieee80211_sub_if_data *sdata,
202 char *buf, int buflen)
205 const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_2GHZ];
207 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
208 len += scnprintf(buf + len, buflen - len, "%04x ", mask[i]);
209 len += scnprintf(buf + len, buflen - len, "\n");
214 IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_2ghz);
216 static ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_5ghz(
217 const struct ieee80211_sub_if_data *sdata,
218 char *buf, int buflen)
221 const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_5GHZ];
223 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
224 len += scnprintf(buf + len, buflen - len, "%04x ", mask[i]);
225 len += scnprintf(buf + len, buflen - len, "\n");
230 IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_5ghz);
232 IEEE80211_IF_FILE(flags, flags, HEX);
233 IEEE80211_IF_FILE(state, state, LHEX);
234 IEEE80211_IF_LINK_FILE(txpower, conf->txpower, DEC);
235 IEEE80211_IF_LINK_FILE(ap_power_level, ap_power_level, DEC);
236 IEEE80211_IF_LINK_FILE(user_power_level, user_power_level, DEC);
239 ieee80211_if_fmt_hw_queues(const struct ieee80211_sub_if_data *sdata,
240 char *buf, int buflen)
244 len = scnprintf(buf, buflen, "AC queues: VO:%d VI:%d BE:%d BK:%d\n",
245 sdata->vif.hw_queue[IEEE80211_AC_VO],
246 sdata->vif.hw_queue[IEEE80211_AC_VI],
247 sdata->vif.hw_queue[IEEE80211_AC_BE],
248 sdata->vif.hw_queue[IEEE80211_AC_BK]);
250 if (sdata->vif.type == NL80211_IFTYPE_AP)
251 len += scnprintf(buf + len, buflen - len, "cab queue: %d\n",
252 sdata->vif.cab_queue);
256 IEEE80211_IF_FILE_R(hw_queues);
259 IEEE80211_IF_FILE(bssid, deflink.u.mgd.bssid, MAC);
260 IEEE80211_IF_FILE(aid, vif.cfg.aid, DEC);
261 IEEE80211_IF_FILE(beacon_timeout, u.mgd.beacon_timeout, JIFFIES_TO_MS);
263 static int ieee80211_set_smps(struct ieee80211_link_data *link,
264 enum ieee80211_smps_mode smps_mode)
266 struct ieee80211_sub_if_data *sdata = link->sdata;
267 struct ieee80211_local *local = sdata->local;
270 if (sdata->vif.driver_flags & IEEE80211_VIF_DISABLE_SMPS_OVERRIDE)
273 if (!(local->hw.wiphy->features & NL80211_FEATURE_STATIC_SMPS) &&
274 smps_mode == IEEE80211_SMPS_STATIC)
277 /* auto should be dynamic if in PS mode */
278 if (!(local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) &&
279 (smps_mode == IEEE80211_SMPS_DYNAMIC ||
280 smps_mode == IEEE80211_SMPS_AUTOMATIC))
283 if (sdata->vif.type != NL80211_IFTYPE_STATION)
287 err = __ieee80211_request_smps_mgd(link->sdata, link, smps_mode);
293 static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
294 [IEEE80211_SMPS_AUTOMATIC] = "auto",
295 [IEEE80211_SMPS_OFF] = "off",
296 [IEEE80211_SMPS_STATIC] = "static",
297 [IEEE80211_SMPS_DYNAMIC] = "dynamic",
300 static ssize_t ieee80211_if_fmt_smps(const struct ieee80211_link_data *link,
301 char *buf, int buflen)
303 if (link->sdata->vif.type == NL80211_IFTYPE_STATION)
304 return snprintf(buf, buflen, "request: %s\nused: %s\n",
305 smps_modes[link->u.mgd.req_smps],
306 smps_modes[link->smps_mode]);
310 static ssize_t ieee80211_if_parse_smps(struct ieee80211_link_data *link,
311 const char *buf, int buflen)
313 enum ieee80211_smps_mode mode;
315 for (mode = 0; mode < IEEE80211_SMPS_NUM_MODES; mode++) {
316 if (strncmp(buf, smps_modes[mode], buflen) == 0) {
317 int err = ieee80211_set_smps(link, mode);
326 IEEE80211_IF_LINK_FILE_RW(smps);
328 static ssize_t ieee80211_if_parse_tkip_mic_test(
329 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
331 struct ieee80211_local *local = sdata->local;
334 struct ieee80211_hdr *hdr;
337 if (!mac_pton(buf, addr))
340 if (!ieee80211_sdata_running(sdata))
343 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24 + 100);
346 skb_reserve(skb, local->hw.extra_tx_headroom);
348 hdr = skb_put_zero(skb, 24);
349 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
351 switch (sdata->vif.type) {
352 case NL80211_IFTYPE_AP:
353 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
355 memcpy(hdr->addr1, addr, ETH_ALEN);
356 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
357 memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN);
359 case NL80211_IFTYPE_STATION:
360 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
363 if (!sdata->u.mgd.associated) {
368 memcpy(hdr->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
369 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
370 memcpy(hdr->addr3, addr, ETH_ALEN);
377 hdr->frame_control = fc;
380 * Add some length to the test frame to make it look bit more valid.
381 * The exact contents does not matter since the recipient is required
382 * to drop this because of the Michael MIC failure.
384 skb_put_zero(skb, 50);
386 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE;
388 ieee80211_tx_skb(sdata, skb);
392 IEEE80211_IF_FILE_W(tkip_mic_test);
394 static ssize_t ieee80211_if_parse_beacon_loss(
395 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
397 if (!ieee80211_sdata_running(sdata) || !sdata->vif.cfg.assoc)
400 ieee80211_beacon_loss(&sdata->vif);
404 IEEE80211_IF_FILE_W(beacon_loss);
406 static ssize_t ieee80211_if_fmt_uapsd_queues(
407 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
409 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
411 return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_queues);
414 static ssize_t ieee80211_if_parse_uapsd_queues(
415 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
417 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
421 ret = kstrtou8(buf, 0, &val);
425 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
428 ifmgd->uapsd_queues = val;
432 IEEE80211_IF_FILE_RW(uapsd_queues);
434 static ssize_t ieee80211_if_fmt_uapsd_max_sp_len(
435 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
437 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
439 return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_max_sp_len);
442 static ssize_t ieee80211_if_parse_uapsd_max_sp_len(
443 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
445 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
449 ret = kstrtoul(buf, 0, &val);
453 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
456 ifmgd->uapsd_max_sp_len = val;
460 IEEE80211_IF_FILE_RW(uapsd_max_sp_len);
462 static ssize_t ieee80211_if_fmt_tdls_wider_bw(
463 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
465 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
468 tdls_wider_bw = ieee80211_hw_check(&sdata->local->hw, TDLS_WIDER_BW) &&
469 !ifmgd->tdls_wider_bw_prohibited;
471 return snprintf(buf, buflen, "%d\n", tdls_wider_bw);
474 static ssize_t ieee80211_if_parse_tdls_wider_bw(
475 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
477 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
481 ret = kstrtou8(buf, 0, &val);
485 ifmgd->tdls_wider_bw_prohibited = !val;
488 IEEE80211_IF_FILE_RW(tdls_wider_bw);
491 IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC);
492 IEEE80211_IF_FILE(num_sta_ps, u.ap.ps.num_sta_ps, ATOMIC);
493 IEEE80211_IF_FILE(dtim_count, u.ap.ps.dtim_count, DEC);
494 IEEE80211_IF_FILE(num_mcast_sta_vlan, u.vlan.num_mcast_sta, ATOMIC);
496 static ssize_t ieee80211_if_fmt_num_buffered_multicast(
497 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
499 return scnprintf(buf, buflen, "%u\n",
500 skb_queue_len(&sdata->u.ap.ps.bc_buf));
502 IEEE80211_IF_FILE_R(num_buffered_multicast);
504 static ssize_t ieee80211_if_fmt_aqm(
505 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
507 struct ieee80211_local *local = sdata->local;
508 struct txq_info *txqi;
514 txqi = to_txq_info(sdata->vif.txq);
516 spin_lock_bh(&local->fq.lock);
521 "ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n"
522 "%u %u %u %u %u %u %u %u %u %u\n",
524 txqi->tin.backlog_bytes,
525 txqi->tin.backlog_packets,
527 txqi->cstats.drop_count,
528 txqi->cstats.ecn_mark,
530 txqi->tin.collisions,
532 txqi->tin.tx_packets);
535 spin_unlock_bh(&local->fq.lock);
539 IEEE80211_IF_FILE_R(aqm);
541 IEEE80211_IF_FILE(multicast_to_unicast, u.ap.multicast_to_unicast, HEX);
543 /* IBSS attributes */
544 static ssize_t ieee80211_if_fmt_tsf(
545 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
547 struct ieee80211_local *local = sdata->local;
550 tsf = drv_get_tsf(local, (struct ieee80211_sub_if_data *)sdata);
552 return scnprintf(buf, buflen, "0x%016llx\n", (unsigned long long) tsf);
555 static ssize_t ieee80211_if_parse_tsf(
556 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
558 struct ieee80211_local *local = sdata->local;
559 unsigned long long tsf;
561 int tsf_is_delta = 0;
563 if (strncmp(buf, "reset", 5) == 0) {
564 if (local->ops->reset_tsf) {
565 drv_reset_tsf(local, sdata);
566 wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
569 if (buflen > 10 && buf[1] == '=') {
572 else if (buf[0] == '-')
578 ret = kstrtoull(buf, 10, &tsf);
581 if (tsf_is_delta && local->ops->offset_tsf) {
582 drv_offset_tsf(local, sdata, tsf_is_delta * tsf);
583 wiphy_info(local->hw.wiphy,
584 "debugfs offset TSF by %018lld\n",
586 } else if (local->ops->set_tsf) {
588 tsf = drv_get_tsf(local, sdata) +
590 drv_set_tsf(local, sdata, tsf);
591 wiphy_info(local->hw.wiphy,
592 "debugfs set TSF to %#018llx\n", tsf);
596 ieee80211_recalc_dtim(local, sdata);
599 IEEE80211_IF_FILE_RW(tsf);
601 static ssize_t ieee80211_if_fmt_valid_links(const struct ieee80211_sub_if_data *sdata,
602 char *buf, int buflen)
604 return snprintf(buf, buflen, "0x%x\n", sdata->vif.valid_links);
606 IEEE80211_IF_FILE_R(valid_links);
608 static ssize_t ieee80211_if_fmt_active_links(const struct ieee80211_sub_if_data *sdata,
609 char *buf, int buflen)
611 return snprintf(buf, buflen, "0x%x\n", sdata->vif.active_links);
614 static ssize_t ieee80211_if_parse_active_links(struct ieee80211_sub_if_data *sdata,
615 const char *buf, int buflen)
619 if (kstrtou16(buf, 0, &active_links))
622 return ieee80211_set_active_links(&sdata->vif, active_links) ?: buflen;
624 IEEE80211_IF_FILE_RW(active_links);
626 IEEE80211_IF_LINK_FILE(addr, conf->addr, MAC);
628 #ifdef CONFIG_MAC80211_MESH
629 IEEE80211_IF_FILE(estab_plinks, u.mesh.estab_plinks, ATOMIC);
631 /* Mesh stats attributes */
632 IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
633 IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
634 IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
635 IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
636 IEEE80211_IF_FILE(dropped_frames_no_route,
637 u.mesh.mshstats.dropped_frames_no_route, DEC);
639 /* Mesh parameters */
640 IEEE80211_IF_FILE(dot11MeshMaxRetries,
641 u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
642 IEEE80211_IF_FILE(dot11MeshRetryTimeout,
643 u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
644 IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
645 u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
646 IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
647 u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
648 IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
649 IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC);
650 IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
651 IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
652 u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
653 IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
654 u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
655 IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
656 u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
657 IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval,
658 u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC);
659 IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
660 u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
661 IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
662 u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
663 IEEE80211_IF_FILE(path_refresh_time,
664 u.mesh.mshcfg.path_refresh_time, DEC);
665 IEEE80211_IF_FILE(min_discovery_timeout,
666 u.mesh.mshcfg.min_discovery_timeout, DEC);
667 IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
668 u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
669 IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol,
670 u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC);
671 IEEE80211_IF_FILE(dot11MeshHWMPRannInterval,
672 u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC);
673 IEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC);
674 IEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC);
675 IEEE80211_IF_FILE(ht_opmode, u.mesh.mshcfg.ht_opmode, DEC);
676 IEEE80211_IF_FILE(dot11MeshHWMPactivePathToRootTimeout,
677 u.mesh.mshcfg.dot11MeshHWMPactivePathToRootTimeout, DEC);
678 IEEE80211_IF_FILE(dot11MeshHWMProotInterval,
679 u.mesh.mshcfg.dot11MeshHWMProotInterval, DEC);
680 IEEE80211_IF_FILE(dot11MeshHWMPconfirmationInterval,
681 u.mesh.mshcfg.dot11MeshHWMPconfirmationInterval, DEC);
682 IEEE80211_IF_FILE(power_mode, u.mesh.mshcfg.power_mode, DEC);
683 IEEE80211_IF_FILE(dot11MeshAwakeWindowDuration,
684 u.mesh.mshcfg.dot11MeshAwakeWindowDuration, DEC);
685 IEEE80211_IF_FILE(dot11MeshConnectedToMeshGate,
686 u.mesh.mshcfg.dot11MeshConnectedToMeshGate, DEC);
687 IEEE80211_IF_FILE(dot11MeshNolearn, u.mesh.mshcfg.dot11MeshNolearn, DEC);
688 IEEE80211_IF_FILE(dot11MeshConnectedToAuthServer,
689 u.mesh.mshcfg.dot11MeshConnectedToAuthServer, DEC);
692 #define DEBUGFS_ADD_MODE(name, mode) \
693 debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \
696 #define DEBUGFS_ADD_X(_bits, _name, _mode) \
697 debugfs_create_x##_bits(#_name, _mode, sdata->vif.debugfs_dir, \
700 #define DEBUGFS_ADD_X8(_name, _mode) \
701 DEBUGFS_ADD_X(8, _name, _mode)
703 #define DEBUGFS_ADD_X16(_name, _mode) \
704 DEBUGFS_ADD_X(16, _name, _mode)
706 #define DEBUGFS_ADD_X32(_name, _mode) \
707 DEBUGFS_ADD_X(32, _name, _mode)
709 #define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400)
711 static void add_common_files(struct ieee80211_sub_if_data *sdata)
713 DEBUGFS_ADD(rc_rateidx_mask_2ghz);
714 DEBUGFS_ADD(rc_rateidx_mask_5ghz);
715 DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
716 DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
717 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_2ghz);
718 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz);
719 DEBUGFS_ADD(hw_queues);
721 if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE &&
722 sdata->vif.type != NL80211_IFTYPE_NAN)
726 static void add_sta_files(struct ieee80211_sub_if_data *sdata)
730 DEBUGFS_ADD(beacon_timeout);
731 DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
732 DEBUGFS_ADD_MODE(beacon_loss, 0200);
733 DEBUGFS_ADD_MODE(uapsd_queues, 0600);
734 DEBUGFS_ADD_MODE(uapsd_max_sp_len, 0600);
735 DEBUGFS_ADD_MODE(tdls_wider_bw, 0600);
736 DEBUGFS_ADD_MODE(valid_links, 0400);
737 DEBUGFS_ADD_MODE(active_links, 0600);
738 DEBUGFS_ADD_X16(dormant_links, 0400);
741 static void add_ap_files(struct ieee80211_sub_if_data *sdata)
743 DEBUGFS_ADD(num_mcast_sta);
744 DEBUGFS_ADD(num_sta_ps);
745 DEBUGFS_ADD(dtim_count);
746 DEBUGFS_ADD(num_buffered_multicast);
747 DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
748 DEBUGFS_ADD_MODE(multicast_to_unicast, 0600);
751 static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
753 /* add num_mcast_sta_vlan using name num_mcast_sta */
754 debugfs_create_file("num_mcast_sta", 0400, sdata->vif.debugfs_dir,
755 sdata, &num_mcast_sta_vlan_ops);
758 static void add_ibss_files(struct ieee80211_sub_if_data *sdata)
760 DEBUGFS_ADD_MODE(tsf, 0600);
763 #ifdef CONFIG_MAC80211_MESH
765 static void add_mesh_files(struct ieee80211_sub_if_data *sdata)
767 DEBUGFS_ADD_MODE(tsf, 0600);
768 DEBUGFS_ADD_MODE(estab_plinks, 0400);
771 static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
773 struct dentry *dir = debugfs_create_dir("mesh_stats",
774 sdata->vif.debugfs_dir);
775 #define MESHSTATS_ADD(name)\
776 debugfs_create_file(#name, 0400, dir, sdata, &name##_ops)
778 MESHSTATS_ADD(fwded_mcast);
779 MESHSTATS_ADD(fwded_unicast);
780 MESHSTATS_ADD(fwded_frames);
781 MESHSTATS_ADD(dropped_frames_ttl);
782 MESHSTATS_ADD(dropped_frames_no_route);
786 static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
788 struct dentry *dir = debugfs_create_dir("mesh_config",
789 sdata->vif.debugfs_dir);
791 #define MESHPARAMS_ADD(name) \
792 debugfs_create_file(#name, 0600, dir, sdata, &name##_ops)
794 MESHPARAMS_ADD(dot11MeshMaxRetries);
795 MESHPARAMS_ADD(dot11MeshRetryTimeout);
796 MESHPARAMS_ADD(dot11MeshConfirmTimeout);
797 MESHPARAMS_ADD(dot11MeshHoldingTimeout);
798 MESHPARAMS_ADD(dot11MeshTTL);
799 MESHPARAMS_ADD(element_ttl);
800 MESHPARAMS_ADD(auto_open_plinks);
801 MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
802 MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
803 MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
804 MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval);
805 MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
806 MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
807 MESHPARAMS_ADD(path_refresh_time);
808 MESHPARAMS_ADD(min_discovery_timeout);
809 MESHPARAMS_ADD(dot11MeshHWMPRootMode);
810 MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
811 MESHPARAMS_ADD(dot11MeshForwarding);
812 MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
813 MESHPARAMS_ADD(rssi_threshold);
814 MESHPARAMS_ADD(ht_opmode);
815 MESHPARAMS_ADD(dot11MeshHWMPactivePathToRootTimeout);
816 MESHPARAMS_ADD(dot11MeshHWMProotInterval);
817 MESHPARAMS_ADD(dot11MeshHWMPconfirmationInterval);
818 MESHPARAMS_ADD(power_mode);
819 MESHPARAMS_ADD(dot11MeshAwakeWindowDuration);
820 MESHPARAMS_ADD(dot11MeshConnectedToMeshGate);
821 MESHPARAMS_ADD(dot11MeshNolearn);
822 MESHPARAMS_ADD(dot11MeshConnectedToAuthServer);
823 #undef MESHPARAMS_ADD
827 static void add_files(struct ieee80211_sub_if_data *sdata)
829 if (!sdata->vif.debugfs_dir)
835 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
836 add_common_files(sdata);
838 switch (sdata->vif.type) {
839 case NL80211_IFTYPE_MESH_POINT:
840 #ifdef CONFIG_MAC80211_MESH
841 add_mesh_files(sdata);
842 add_mesh_stats(sdata);
843 add_mesh_config(sdata);
846 case NL80211_IFTYPE_STATION:
847 add_sta_files(sdata);
849 case NL80211_IFTYPE_ADHOC:
850 add_ibss_files(sdata);
852 case NL80211_IFTYPE_AP:
855 case NL80211_IFTYPE_AP_VLAN:
856 add_vlan_files(sdata);
863 #undef DEBUGFS_ADD_MODE
866 #define DEBUGFS_ADD_MODE(dentry, name, mode) \
867 debugfs_create_file(#name, mode, dentry, \
868 link, &link_##name##_ops)
870 #define DEBUGFS_ADD(dentry, name) DEBUGFS_ADD_MODE(dentry, name, 0400)
872 static void add_link_files(struct ieee80211_link_data *link,
873 struct dentry *dentry)
875 DEBUGFS_ADD(dentry, txpower);
876 DEBUGFS_ADD(dentry, user_power_level);
877 DEBUGFS_ADD(dentry, ap_power_level);
879 switch (link->sdata->vif.type) {
880 case NL80211_IFTYPE_STATION:
881 DEBUGFS_ADD_MODE(dentry, smps, 0600);
888 void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
890 char buf[10+IFNAMSIZ];
892 sprintf(buf, "netdev:%s", sdata->name);
893 sdata->vif.debugfs_dir = debugfs_create_dir(buf,
894 sdata->local->hw.wiphy->debugfsdir);
895 sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
896 sdata->vif.debugfs_dir);
899 if (!(sdata->local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO))
900 add_link_files(&sdata->deflink, sdata->vif.debugfs_dir);
903 void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
905 if (!sdata->vif.debugfs_dir)
908 debugfs_remove_recursive(sdata->vif.debugfs_dir);
909 sdata->vif.debugfs_dir = NULL;
910 sdata->debugfs.subdir_stations = NULL;
913 void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
916 char buf[10 + IFNAMSIZ];
918 dir = sdata->vif.debugfs_dir;
920 if (IS_ERR_OR_NULL(dir))
923 sprintf(buf, "netdev:%s", sdata->name);
924 debugfs_rename(dir->d_parent, dir, dir->d_parent, buf);
927 void ieee80211_link_debugfs_add(struct ieee80211_link_data *link)
929 char link_dir_name[10];
931 if (WARN_ON(!link->sdata->vif.debugfs_dir))
934 /* For now, this should not be called for non-MLO capable drivers */
935 if (WARN_ON(!(link->sdata->local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO)))
938 snprintf(link_dir_name, sizeof(link_dir_name),
939 "link-%d", link->link_id);
942 debugfs_create_dir(link_dir_name,
943 link->sdata->vif.debugfs_dir);
945 DEBUGFS_ADD(link->debugfs_dir, addr);
946 add_link_files(link, link->debugfs_dir);
949 void ieee80211_link_debugfs_remove(struct ieee80211_link_data *link)
951 if (!link->sdata->vif.debugfs_dir || !link->debugfs_dir) {
952 link->debugfs_dir = NULL;
956 if (link->debugfs_dir == link->sdata->vif.debugfs_dir) {
957 WARN_ON(link != &link->sdata->deflink);
958 link->debugfs_dir = NULL;
962 debugfs_remove_recursive(link->debugfs_dir);
963 link->debugfs_dir = NULL;
966 void ieee80211_link_debugfs_drv_add(struct ieee80211_link_data *link)
968 if (WARN_ON(!link->debugfs_dir))
971 drv_link_add_debugfs(link->sdata->local, link->sdata,
972 link->conf, link->debugfs_dir);
975 void ieee80211_link_debugfs_drv_remove(struct ieee80211_link_data *link)
977 if (!link || !link->debugfs_dir)
980 if (WARN_ON(link->debugfs_dir == link->sdata->vif.debugfs_dir))
983 /* Recreate the directory excluding the driver data */
984 debugfs_remove_recursive(link->debugfs_dir);
985 link->debugfs_dir = NULL;
987 ieee80211_link_debugfs_add(link);