1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2020-2022 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 (!(local->hw.wiphy->features & NL80211_FEATURE_STATIC_SMPS) &&
271 smps_mode == IEEE80211_SMPS_STATIC)
274 /* auto should be dynamic if in PS mode */
275 if (!(local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) &&
276 (smps_mode == IEEE80211_SMPS_DYNAMIC ||
277 smps_mode == IEEE80211_SMPS_AUTOMATIC))
280 if (sdata->vif.type != NL80211_IFTYPE_STATION)
284 err = __ieee80211_request_smps_mgd(link->sdata, link, smps_mode);
290 static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
291 [IEEE80211_SMPS_AUTOMATIC] = "auto",
292 [IEEE80211_SMPS_OFF] = "off",
293 [IEEE80211_SMPS_STATIC] = "static",
294 [IEEE80211_SMPS_DYNAMIC] = "dynamic",
297 static ssize_t ieee80211_if_fmt_smps(const struct ieee80211_link_data *link,
298 char *buf, int buflen)
300 if (link->sdata->vif.type == NL80211_IFTYPE_STATION)
301 return snprintf(buf, buflen, "request: %s\nused: %s\n",
302 smps_modes[link->u.mgd.req_smps],
303 smps_modes[link->smps_mode]);
307 static ssize_t ieee80211_if_parse_smps(struct ieee80211_link_data *link,
308 const char *buf, int buflen)
310 enum ieee80211_smps_mode mode;
312 for (mode = 0; mode < IEEE80211_SMPS_NUM_MODES; mode++) {
313 if (strncmp(buf, smps_modes[mode], buflen) == 0) {
314 int err = ieee80211_set_smps(link, mode);
323 IEEE80211_IF_LINK_FILE_RW(smps);
325 static ssize_t ieee80211_if_parse_tkip_mic_test(
326 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
328 struct ieee80211_local *local = sdata->local;
331 struct ieee80211_hdr *hdr;
334 if (!mac_pton(buf, addr))
337 if (!ieee80211_sdata_running(sdata))
340 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24 + 100);
343 skb_reserve(skb, local->hw.extra_tx_headroom);
345 hdr = skb_put_zero(skb, 24);
346 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
348 switch (sdata->vif.type) {
349 case NL80211_IFTYPE_AP:
350 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
352 memcpy(hdr->addr1, addr, ETH_ALEN);
353 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
354 memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN);
356 case NL80211_IFTYPE_STATION:
357 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
360 if (!sdata->u.mgd.associated) {
365 memcpy(hdr->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
366 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
367 memcpy(hdr->addr3, addr, ETH_ALEN);
374 hdr->frame_control = fc;
377 * Add some length to the test frame to make it look bit more valid.
378 * The exact contents does not matter since the recipient is required
379 * to drop this because of the Michael MIC failure.
381 skb_put_zero(skb, 50);
383 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE;
385 ieee80211_tx_skb(sdata, skb);
389 IEEE80211_IF_FILE_W(tkip_mic_test);
391 static ssize_t ieee80211_if_parse_beacon_loss(
392 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
394 if (!ieee80211_sdata_running(sdata) || !sdata->vif.cfg.assoc)
397 ieee80211_beacon_loss(&sdata->vif);
401 IEEE80211_IF_FILE_W(beacon_loss);
403 static ssize_t ieee80211_if_fmt_uapsd_queues(
404 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
406 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
408 return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_queues);
411 static ssize_t ieee80211_if_parse_uapsd_queues(
412 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
414 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
418 ret = kstrtou8(buf, 0, &val);
422 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
425 ifmgd->uapsd_queues = val;
429 IEEE80211_IF_FILE_RW(uapsd_queues);
431 static ssize_t ieee80211_if_fmt_uapsd_max_sp_len(
432 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
434 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
436 return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_max_sp_len);
439 static ssize_t ieee80211_if_parse_uapsd_max_sp_len(
440 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
442 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
446 ret = kstrtoul(buf, 0, &val);
450 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
453 ifmgd->uapsd_max_sp_len = val;
457 IEEE80211_IF_FILE_RW(uapsd_max_sp_len);
459 static ssize_t ieee80211_if_fmt_tdls_wider_bw(
460 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
462 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
465 tdls_wider_bw = ieee80211_hw_check(&sdata->local->hw, TDLS_WIDER_BW) &&
466 !ifmgd->tdls_wider_bw_prohibited;
468 return snprintf(buf, buflen, "%d\n", tdls_wider_bw);
471 static ssize_t ieee80211_if_parse_tdls_wider_bw(
472 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
474 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
478 ret = kstrtou8(buf, 0, &val);
482 ifmgd->tdls_wider_bw_prohibited = !val;
485 IEEE80211_IF_FILE_RW(tdls_wider_bw);
488 IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC);
489 IEEE80211_IF_FILE(num_sta_ps, u.ap.ps.num_sta_ps, ATOMIC);
490 IEEE80211_IF_FILE(dtim_count, u.ap.ps.dtim_count, DEC);
491 IEEE80211_IF_FILE(num_mcast_sta_vlan, u.vlan.num_mcast_sta, ATOMIC);
493 static ssize_t ieee80211_if_fmt_num_buffered_multicast(
494 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
496 return scnprintf(buf, buflen, "%u\n",
497 skb_queue_len(&sdata->u.ap.ps.bc_buf));
499 IEEE80211_IF_FILE_R(num_buffered_multicast);
501 static ssize_t ieee80211_if_fmt_aqm(
502 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
504 struct ieee80211_local *local = sdata->local;
505 struct txq_info *txqi;
511 txqi = to_txq_info(sdata->vif.txq);
513 spin_lock_bh(&local->fq.lock);
518 "ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n"
519 "%u %u %u %u %u %u %u %u %u %u\n",
521 txqi->tin.backlog_bytes,
522 txqi->tin.backlog_packets,
524 txqi->cstats.drop_count,
525 txqi->cstats.ecn_mark,
527 txqi->tin.collisions,
529 txqi->tin.tx_packets);
532 spin_unlock_bh(&local->fq.lock);
536 IEEE80211_IF_FILE_R(aqm);
538 IEEE80211_IF_FILE(multicast_to_unicast, u.ap.multicast_to_unicast, HEX);
540 /* IBSS attributes */
541 static ssize_t ieee80211_if_fmt_tsf(
542 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
544 struct ieee80211_local *local = sdata->local;
547 tsf = drv_get_tsf(local, (struct ieee80211_sub_if_data *)sdata);
549 return scnprintf(buf, buflen, "0x%016llx\n", (unsigned long long) tsf);
552 static ssize_t ieee80211_if_parse_tsf(
553 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
555 struct ieee80211_local *local = sdata->local;
556 unsigned long long tsf;
558 int tsf_is_delta = 0;
560 if (strncmp(buf, "reset", 5) == 0) {
561 if (local->ops->reset_tsf) {
562 drv_reset_tsf(local, sdata);
563 wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
566 if (buflen > 10 && buf[1] == '=') {
569 else if (buf[0] == '-')
575 ret = kstrtoull(buf, 10, &tsf);
578 if (tsf_is_delta && local->ops->offset_tsf) {
579 drv_offset_tsf(local, sdata, tsf_is_delta * tsf);
580 wiphy_info(local->hw.wiphy,
581 "debugfs offset TSF by %018lld\n",
583 } else if (local->ops->set_tsf) {
585 tsf = drv_get_tsf(local, sdata) +
587 drv_set_tsf(local, sdata, tsf);
588 wiphy_info(local->hw.wiphy,
589 "debugfs set TSF to %#018llx\n", tsf);
593 ieee80211_recalc_dtim(local, sdata);
596 IEEE80211_IF_FILE_RW(tsf);
598 static ssize_t ieee80211_if_fmt_valid_links(const struct ieee80211_sub_if_data *sdata,
599 char *buf, int buflen)
601 return snprintf(buf, buflen, "0x%x\n", sdata->vif.valid_links);
603 IEEE80211_IF_FILE_R(valid_links);
605 static ssize_t ieee80211_if_fmt_active_links(const struct ieee80211_sub_if_data *sdata,
606 char *buf, int buflen)
608 return snprintf(buf, buflen, "0x%x\n", sdata->vif.active_links);
611 static ssize_t ieee80211_if_parse_active_links(struct ieee80211_sub_if_data *sdata,
612 const char *buf, int buflen)
616 if (kstrtou16(buf, 0, &active_links))
619 return ieee80211_set_active_links(&sdata->vif, active_links) ?: buflen;
621 IEEE80211_IF_FILE_RW(active_links);
623 IEEE80211_IF_LINK_FILE(addr, conf->addr, MAC);
625 #ifdef CONFIG_MAC80211_MESH
626 IEEE80211_IF_FILE(estab_plinks, u.mesh.estab_plinks, ATOMIC);
628 /* Mesh stats attributes */
629 IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
630 IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
631 IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
632 IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
633 IEEE80211_IF_FILE(dropped_frames_no_route,
634 u.mesh.mshstats.dropped_frames_no_route, DEC);
636 /* Mesh parameters */
637 IEEE80211_IF_FILE(dot11MeshMaxRetries,
638 u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
639 IEEE80211_IF_FILE(dot11MeshRetryTimeout,
640 u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
641 IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
642 u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
643 IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
644 u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
645 IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
646 IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC);
647 IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
648 IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
649 u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
650 IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
651 u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
652 IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
653 u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
654 IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval,
655 u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC);
656 IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
657 u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
658 IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
659 u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
660 IEEE80211_IF_FILE(path_refresh_time,
661 u.mesh.mshcfg.path_refresh_time, DEC);
662 IEEE80211_IF_FILE(min_discovery_timeout,
663 u.mesh.mshcfg.min_discovery_timeout, DEC);
664 IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
665 u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
666 IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol,
667 u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC);
668 IEEE80211_IF_FILE(dot11MeshHWMPRannInterval,
669 u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC);
670 IEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC);
671 IEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC);
672 IEEE80211_IF_FILE(ht_opmode, u.mesh.mshcfg.ht_opmode, DEC);
673 IEEE80211_IF_FILE(dot11MeshHWMPactivePathToRootTimeout,
674 u.mesh.mshcfg.dot11MeshHWMPactivePathToRootTimeout, DEC);
675 IEEE80211_IF_FILE(dot11MeshHWMProotInterval,
676 u.mesh.mshcfg.dot11MeshHWMProotInterval, DEC);
677 IEEE80211_IF_FILE(dot11MeshHWMPconfirmationInterval,
678 u.mesh.mshcfg.dot11MeshHWMPconfirmationInterval, DEC);
679 IEEE80211_IF_FILE(power_mode, u.mesh.mshcfg.power_mode, DEC);
680 IEEE80211_IF_FILE(dot11MeshAwakeWindowDuration,
681 u.mesh.mshcfg.dot11MeshAwakeWindowDuration, DEC);
682 IEEE80211_IF_FILE(dot11MeshConnectedToMeshGate,
683 u.mesh.mshcfg.dot11MeshConnectedToMeshGate, DEC);
684 IEEE80211_IF_FILE(dot11MeshNolearn, u.mesh.mshcfg.dot11MeshNolearn, DEC);
685 IEEE80211_IF_FILE(dot11MeshConnectedToAuthServer,
686 u.mesh.mshcfg.dot11MeshConnectedToAuthServer, DEC);
689 #define DEBUGFS_ADD_MODE(name, mode) \
690 debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \
693 #define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400)
695 static void add_common_files(struct ieee80211_sub_if_data *sdata)
697 DEBUGFS_ADD(rc_rateidx_mask_2ghz);
698 DEBUGFS_ADD(rc_rateidx_mask_5ghz);
699 DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
700 DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
701 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_2ghz);
702 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz);
703 DEBUGFS_ADD(hw_queues);
705 if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE &&
706 sdata->vif.type != NL80211_IFTYPE_NAN)
710 static void add_sta_files(struct ieee80211_sub_if_data *sdata)
714 DEBUGFS_ADD(beacon_timeout);
715 DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
716 DEBUGFS_ADD_MODE(beacon_loss, 0200);
717 DEBUGFS_ADD_MODE(uapsd_queues, 0600);
718 DEBUGFS_ADD_MODE(uapsd_max_sp_len, 0600);
719 DEBUGFS_ADD_MODE(tdls_wider_bw, 0600);
720 DEBUGFS_ADD_MODE(valid_links, 0200);
721 DEBUGFS_ADD_MODE(active_links, 0600);
724 static void add_ap_files(struct ieee80211_sub_if_data *sdata)
726 DEBUGFS_ADD(num_mcast_sta);
727 DEBUGFS_ADD(num_sta_ps);
728 DEBUGFS_ADD(dtim_count);
729 DEBUGFS_ADD(num_buffered_multicast);
730 DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
731 DEBUGFS_ADD_MODE(multicast_to_unicast, 0600);
734 static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
736 /* add num_mcast_sta_vlan using name num_mcast_sta */
737 debugfs_create_file("num_mcast_sta", 0400, sdata->vif.debugfs_dir,
738 sdata, &num_mcast_sta_vlan_ops);
741 static void add_ibss_files(struct ieee80211_sub_if_data *sdata)
743 DEBUGFS_ADD_MODE(tsf, 0600);
746 #ifdef CONFIG_MAC80211_MESH
748 static void add_mesh_files(struct ieee80211_sub_if_data *sdata)
750 DEBUGFS_ADD_MODE(tsf, 0600);
751 DEBUGFS_ADD_MODE(estab_plinks, 0400);
754 static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
756 struct dentry *dir = debugfs_create_dir("mesh_stats",
757 sdata->vif.debugfs_dir);
758 #define MESHSTATS_ADD(name)\
759 debugfs_create_file(#name, 0400, dir, sdata, &name##_ops)
761 MESHSTATS_ADD(fwded_mcast);
762 MESHSTATS_ADD(fwded_unicast);
763 MESHSTATS_ADD(fwded_frames);
764 MESHSTATS_ADD(dropped_frames_ttl);
765 MESHSTATS_ADD(dropped_frames_no_route);
769 static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
771 struct dentry *dir = debugfs_create_dir("mesh_config",
772 sdata->vif.debugfs_dir);
774 #define MESHPARAMS_ADD(name) \
775 debugfs_create_file(#name, 0600, dir, sdata, &name##_ops)
777 MESHPARAMS_ADD(dot11MeshMaxRetries);
778 MESHPARAMS_ADD(dot11MeshRetryTimeout);
779 MESHPARAMS_ADD(dot11MeshConfirmTimeout);
780 MESHPARAMS_ADD(dot11MeshHoldingTimeout);
781 MESHPARAMS_ADD(dot11MeshTTL);
782 MESHPARAMS_ADD(element_ttl);
783 MESHPARAMS_ADD(auto_open_plinks);
784 MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
785 MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
786 MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
787 MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval);
788 MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
789 MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
790 MESHPARAMS_ADD(path_refresh_time);
791 MESHPARAMS_ADD(min_discovery_timeout);
792 MESHPARAMS_ADD(dot11MeshHWMPRootMode);
793 MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
794 MESHPARAMS_ADD(dot11MeshForwarding);
795 MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
796 MESHPARAMS_ADD(rssi_threshold);
797 MESHPARAMS_ADD(ht_opmode);
798 MESHPARAMS_ADD(dot11MeshHWMPactivePathToRootTimeout);
799 MESHPARAMS_ADD(dot11MeshHWMProotInterval);
800 MESHPARAMS_ADD(dot11MeshHWMPconfirmationInterval);
801 MESHPARAMS_ADD(power_mode);
802 MESHPARAMS_ADD(dot11MeshAwakeWindowDuration);
803 MESHPARAMS_ADD(dot11MeshConnectedToMeshGate);
804 MESHPARAMS_ADD(dot11MeshNolearn);
805 MESHPARAMS_ADD(dot11MeshConnectedToAuthServer);
806 #undef MESHPARAMS_ADD
810 static void add_files(struct ieee80211_sub_if_data *sdata)
812 if (!sdata->vif.debugfs_dir)
818 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
819 add_common_files(sdata);
821 switch (sdata->vif.type) {
822 case NL80211_IFTYPE_MESH_POINT:
823 #ifdef CONFIG_MAC80211_MESH
824 add_mesh_files(sdata);
825 add_mesh_stats(sdata);
826 add_mesh_config(sdata);
829 case NL80211_IFTYPE_STATION:
830 add_sta_files(sdata);
832 case NL80211_IFTYPE_ADHOC:
833 add_ibss_files(sdata);
835 case NL80211_IFTYPE_AP:
838 case NL80211_IFTYPE_AP_VLAN:
839 add_vlan_files(sdata);
846 #undef DEBUGFS_ADD_MODE
849 #define DEBUGFS_ADD_MODE(dentry, name, mode) \
850 debugfs_create_file(#name, mode, dentry, \
851 link, &link_##name##_ops)
853 #define DEBUGFS_ADD(dentry, name) DEBUGFS_ADD_MODE(dentry, name, 0400)
855 static void add_link_files(struct ieee80211_link_data *link,
856 struct dentry *dentry)
858 DEBUGFS_ADD(dentry, txpower);
859 DEBUGFS_ADD(dentry, user_power_level);
860 DEBUGFS_ADD(dentry, ap_power_level);
862 switch (link->sdata->vif.type) {
863 case NL80211_IFTYPE_STATION:
864 DEBUGFS_ADD_MODE(dentry, smps, 0600);
871 void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
873 char buf[10+IFNAMSIZ];
875 sprintf(buf, "netdev:%s", sdata->name);
876 sdata->vif.debugfs_dir = debugfs_create_dir(buf,
877 sdata->local->hw.wiphy->debugfsdir);
878 sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
879 sdata->vif.debugfs_dir);
882 if (!(sdata->local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO))
883 add_link_files(&sdata->deflink, sdata->vif.debugfs_dir);
886 void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
888 if (!sdata->vif.debugfs_dir)
891 debugfs_remove_recursive(sdata->vif.debugfs_dir);
892 sdata->vif.debugfs_dir = NULL;
893 sdata->debugfs.subdir_stations = NULL;
896 void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
899 char buf[10 + IFNAMSIZ];
901 dir = sdata->vif.debugfs_dir;
903 if (IS_ERR_OR_NULL(dir))
906 sprintf(buf, "netdev:%s", sdata->name);
907 debugfs_rename(dir->d_parent, dir, dir->d_parent, buf);
910 void ieee80211_link_debugfs_add(struct ieee80211_link_data *link)
912 char link_dir_name[10];
914 if (WARN_ON(!link->sdata->vif.debugfs_dir))
917 /* For now, this should not be called for non-MLO capable drivers */
918 if (WARN_ON(!(link->sdata->local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO)))
921 snprintf(link_dir_name, sizeof(link_dir_name),
922 "link-%d", link->link_id);
925 debugfs_create_dir(link_dir_name,
926 link->sdata->vif.debugfs_dir);
928 DEBUGFS_ADD(link->debugfs_dir, addr);
929 add_link_files(link, link->debugfs_dir);
932 void ieee80211_link_debugfs_remove(struct ieee80211_link_data *link)
934 if (!link->sdata->vif.debugfs_dir || !link->debugfs_dir) {
935 link->debugfs_dir = NULL;
939 if (link->debugfs_dir == link->sdata->vif.debugfs_dir) {
940 WARN_ON(link != &link->sdata->deflink);
941 link->debugfs_dir = NULL;
945 debugfs_remove_recursive(link->debugfs_dir);
946 link->debugfs_dir = NULL;
949 void ieee80211_link_debugfs_drv_add(struct ieee80211_link_data *link)
951 if (WARN_ON(!link->debugfs_dir))
954 drv_link_add_debugfs(link->sdata->local, link->sdata,
955 link->conf, link->debugfs_dir);
958 void ieee80211_link_debugfs_drv_remove(struct ieee80211_link_data *link)
960 if (!link || !link->debugfs_dir)
963 if (WARN_ON(link->debugfs_dir == link->sdata->vif.debugfs_dir))
966 /* Recreate the directory excluding the driver data */
967 debugfs_remove_recursive(link->debugfs_dir);
968 link->debugfs_dir = NULL;
970 ieee80211_link_debugfs_add(link);