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 struct ieee80211_if_read_sdata_data
{
26 ssize_t (*format
)(const struct ieee80211_sub_if_data
*, char *, int);
27 struct ieee80211_sub_if_data
*sdata
;
30 static ssize_t
ieee80211_if_read_sdata_handler(struct wiphy
*wiphy
,
36 struct ieee80211_if_read_sdata_data
*d
= data
;
38 return d
->format(d
->sdata
, buf
, bufsize
);
41 static ssize_t
ieee80211_if_read_sdata(
44 size_t count
, loff_t
*ppos
,
45 ssize_t (*format
)(const struct ieee80211_sub_if_data
*sdata
, char *, int))
47 struct ieee80211_sub_if_data
*sdata
= file
->private_data
;
48 struct ieee80211_if_read_sdata_data data
= {
54 return wiphy_locked_debugfs_read(sdata
->local
->hw
.wiphy
,
55 file
, buf
, sizeof(buf
),
57 ieee80211_if_read_sdata_handler
,
61 struct ieee80211_if_write_sdata_data
{
62 ssize_t (*write
)(struct ieee80211_sub_if_data
*, const char *, int);
63 struct ieee80211_sub_if_data
*sdata
;
66 static ssize_t
ieee80211_if_write_sdata_handler(struct wiphy
*wiphy
,
72 struct ieee80211_if_write_sdata_data
*d
= data
;
74 return d
->write(d
->sdata
, buf
, count
);
77 static ssize_t
ieee80211_if_write_sdata(
79 const char __user
*userbuf
,
80 size_t count
, loff_t
*ppos
,
81 ssize_t (*write
)(struct ieee80211_sub_if_data
*sdata
, const char *, int))
83 struct ieee80211_sub_if_data
*sdata
= file
->private_data
;
84 struct ieee80211_if_write_sdata_data data
= {
90 return wiphy_locked_debugfs_write(sdata
->local
->hw
.wiphy
,
91 file
, buf
, sizeof(buf
),
93 ieee80211_if_write_sdata_handler
,
97 struct ieee80211_if_read_link_data
{
98 ssize_t (*format
)(const struct ieee80211_link_data
*, char *, int);
99 struct ieee80211_link_data
*link
;
102 static ssize_t
ieee80211_if_read_link_handler(struct wiphy
*wiphy
,
108 struct ieee80211_if_read_link_data
*d
= data
;
110 return d
->format(d
->link
, buf
, bufsize
);
113 static ssize_t
ieee80211_if_read_link(
115 char __user
*userbuf
,
116 size_t count
, loff_t
*ppos
,
117 ssize_t (*format
)(const struct ieee80211_link_data
*link
, char *, int))
119 struct ieee80211_link_data
*link
= file
->private_data
;
120 struct ieee80211_if_read_link_data data
= {
126 return wiphy_locked_debugfs_read(link
->sdata
->local
->hw
.wiphy
,
127 file
, buf
, sizeof(buf
),
128 userbuf
, count
, ppos
,
129 ieee80211_if_read_link_handler
,
133 struct ieee80211_if_write_link_data
{
134 ssize_t (*write
)(struct ieee80211_link_data
*, const char *, int);
135 struct ieee80211_link_data
*link
;
138 static ssize_t
ieee80211_if_write_link_handler(struct wiphy
*wiphy
,
144 struct ieee80211_if_write_sdata_data
*d
= data
;
146 return d
->write(d
->sdata
, buf
, count
);
149 static ssize_t
ieee80211_if_write_link(
151 const char __user
*userbuf
,
152 size_t count
, loff_t
*ppos
,
153 ssize_t (*write
)(struct ieee80211_link_data
*link
, const char *, int))
155 struct ieee80211_link_data
*link
= file
->private_data
;
156 struct ieee80211_if_write_link_data data
= {
162 return wiphy_locked_debugfs_write(link
->sdata
->local
->hw
.wiphy
,
163 file
, buf
, sizeof(buf
),
165 ieee80211_if_write_link_handler
,
169 #define IEEE80211_IF_FMT(name, type, field, format_string) \
170 static ssize_t ieee80211_if_fmt_##name( \
171 const type *data, char *buf, \
174 return scnprintf(buf, buflen, format_string, data->field); \
176 #define IEEE80211_IF_FMT_DEC(name, type, field) \
177 IEEE80211_IF_FMT(name, type, field, "%d\n")
178 #define IEEE80211_IF_FMT_HEX(name, type, field) \
179 IEEE80211_IF_FMT(name, type, field, "%#x\n")
180 #define IEEE80211_IF_FMT_LHEX(name, type, field) \
181 IEEE80211_IF_FMT(name, type, field, "%#lx\n")
183 #define IEEE80211_IF_FMT_HEXARRAY(name, type, field) \
184 static ssize_t ieee80211_if_fmt_##name( \
186 char *buf, int buflen) \
190 for (i = 0; i < sizeof(data->field); i++) { \
191 p += scnprintf(p, buflen + buf - p, "%.2x ", \
194 p += scnprintf(p, buflen + buf - p, "\n"); \
198 #define IEEE80211_IF_FMT_ATOMIC(name, type, field) \
199 static ssize_t ieee80211_if_fmt_##name( \
201 char *buf, int buflen) \
203 return scnprintf(buf, buflen, "%d\n", atomic_read(&data->field));\
206 #define IEEE80211_IF_FMT_MAC(name, type, field) \
207 static ssize_t ieee80211_if_fmt_##name( \
208 const type *data, char *buf, \
211 return scnprintf(buf, buflen, "%pM\n", data->field); \
214 #define IEEE80211_IF_FMT_JIFFIES_TO_MS(name, type, field) \
215 static ssize_t ieee80211_if_fmt_##name( \
217 char *buf, int buflen) \
219 return scnprintf(buf, buflen, "%d\n", \
220 jiffies_to_msecs(data->field)); \
223 #define _IEEE80211_IF_FILE_OPS(name, _read, _write) \
224 static const struct file_operations name##_ops = { \
227 .open = simple_open, \
228 .llseek = generic_file_llseek, \
231 #define _IEEE80211_IF_FILE_R_FN(name) \
232 static ssize_t ieee80211_if_read_##name(struct file *file, \
233 char __user *userbuf, \
234 size_t count, loff_t *ppos) \
236 return ieee80211_if_read_sdata(file, \
237 userbuf, count, ppos, \
238 ieee80211_if_fmt_##name); \
241 #define _IEEE80211_IF_FILE_W_FN(name) \
242 static ssize_t ieee80211_if_write_##name(struct file *file, \
243 const char __user *userbuf, \
244 size_t count, loff_t *ppos) \
246 return ieee80211_if_write_sdata(file, userbuf, \
248 ieee80211_if_parse_##name); \
251 #define IEEE80211_IF_FILE_R(name) \
252 _IEEE80211_IF_FILE_R_FN(name) \
253 _IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, NULL)
255 #define IEEE80211_IF_FILE_W(name) \
256 _IEEE80211_IF_FILE_W_FN(name) \
257 _IEEE80211_IF_FILE_OPS(name, NULL, ieee80211_if_write_##name)
259 #define IEEE80211_IF_FILE_RW(name) \
260 _IEEE80211_IF_FILE_R_FN(name) \
261 _IEEE80211_IF_FILE_W_FN(name) \
262 _IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, \
263 ieee80211_if_write_##name)
265 #define IEEE80211_IF_FILE(name, field, format) \
266 IEEE80211_IF_FMT_##format(name, struct ieee80211_sub_if_data, field) \
267 IEEE80211_IF_FILE_R(name)
269 #define _IEEE80211_IF_LINK_R_FN(name) \
270 static ssize_t ieee80211_if_read_##name(struct file *file, \
271 char __user *userbuf, \
272 size_t count, loff_t *ppos) \
274 return ieee80211_if_read_link(file, \
275 userbuf, count, ppos, \
276 ieee80211_if_fmt_##name); \
279 #define _IEEE80211_IF_LINK_W_FN(name) \
280 static ssize_t ieee80211_if_write_##name(struct file *file, \
281 const char __user *userbuf, \
282 size_t count, loff_t *ppos) \
284 return ieee80211_if_write_link(file, userbuf, \
286 ieee80211_if_parse_##name); \
289 #define IEEE80211_IF_LINK_FILE_R(name) \
290 _IEEE80211_IF_LINK_R_FN(name) \
291 _IEEE80211_IF_FILE_OPS(link_##name, ieee80211_if_read_##name, NULL)
293 #define IEEE80211_IF_LINK_FILE_W(name) \
294 _IEEE80211_IF_LINK_W_FN(name) \
295 _IEEE80211_IF_FILE_OPS(link_##name, NULL, ieee80211_if_write_##name)
297 #define IEEE80211_IF_LINK_FILE_RW(name) \
298 _IEEE80211_IF_LINK_R_FN(name) \
299 _IEEE80211_IF_LINK_W_FN(name) \
300 _IEEE80211_IF_FILE_OPS(link_##name, ieee80211_if_read_##name, \
301 ieee80211_if_write_##name)
303 #define IEEE80211_IF_LINK_FILE(name, field, format) \
304 IEEE80211_IF_FMT_##format(name, struct ieee80211_link_data, field) \
305 IEEE80211_IF_LINK_FILE_R(name)
307 /* common attributes */
308 IEEE80211_IF_FILE(rc_rateidx_mask_2ghz
, rc_rateidx_mask
[NL80211_BAND_2GHZ
],
310 IEEE80211_IF_FILE(rc_rateidx_mask_5ghz
, rc_rateidx_mask
[NL80211_BAND_5GHZ
],
312 IEEE80211_IF_FILE(rc_rateidx_mcs_mask_2ghz
,
313 rc_rateidx_mcs_mask
[NL80211_BAND_2GHZ
], HEXARRAY
);
314 IEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz
,
315 rc_rateidx_mcs_mask
[NL80211_BAND_5GHZ
], HEXARRAY
);
317 static ssize_t
ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_2ghz(
318 const struct ieee80211_sub_if_data
*sdata
,
319 char *buf
, int buflen
)
322 const u16
*mask
= sdata
->rc_rateidx_vht_mcs_mask
[NL80211_BAND_2GHZ
];
324 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
325 len
+= scnprintf(buf
+ len
, buflen
- len
, "%04x ", mask
[i
]);
326 len
+= scnprintf(buf
+ len
, buflen
- len
, "\n");
331 IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_2ghz
);
333 static ssize_t
ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_5ghz(
334 const struct ieee80211_sub_if_data
*sdata
,
335 char *buf
, int buflen
)
338 const u16
*mask
= sdata
->rc_rateidx_vht_mcs_mask
[NL80211_BAND_5GHZ
];
340 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
341 len
+= scnprintf(buf
+ len
, buflen
- len
, "%04x ", mask
[i
]);
342 len
+= scnprintf(buf
+ len
, buflen
- len
, "\n");
347 IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_5ghz
);
349 IEEE80211_IF_FILE(flags
, flags
, HEX
);
350 IEEE80211_IF_FILE(state
, state
, LHEX
);
351 IEEE80211_IF_LINK_FILE(txpower
, conf
->txpower
, DEC
);
352 IEEE80211_IF_LINK_FILE(ap_power_level
, ap_power_level
, DEC
);
353 IEEE80211_IF_LINK_FILE(user_power_level
, user_power_level
, DEC
);
356 ieee80211_if_fmt_hw_queues(const struct ieee80211_sub_if_data
*sdata
,
357 char *buf
, int buflen
)
361 len
= scnprintf(buf
, buflen
, "AC queues: VO:%d VI:%d BE:%d BK:%d\n",
362 sdata
->vif
.hw_queue
[IEEE80211_AC_VO
],
363 sdata
->vif
.hw_queue
[IEEE80211_AC_VI
],
364 sdata
->vif
.hw_queue
[IEEE80211_AC_BE
],
365 sdata
->vif
.hw_queue
[IEEE80211_AC_BK
]);
367 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
)
368 len
+= scnprintf(buf
+ len
, buflen
- len
, "cab queue: %d\n",
369 sdata
->vif
.cab_queue
);
373 IEEE80211_IF_FILE_R(hw_queues
);
376 IEEE80211_IF_FILE(bssid
, deflink
.u
.mgd
.bssid
, MAC
);
377 IEEE80211_IF_FILE(aid
, vif
.cfg
.aid
, DEC
);
378 IEEE80211_IF_FILE(beacon_timeout
, u
.mgd
.beacon_timeout
, JIFFIES_TO_MS
);
380 static int ieee80211_set_smps(struct ieee80211_link_data
*link
,
381 enum ieee80211_smps_mode smps_mode
)
383 struct ieee80211_sub_if_data
*sdata
= link
->sdata
;
384 struct ieee80211_local
*local
= sdata
->local
;
386 /* The driver indicated that EML is enabled for the interface, thus do
387 * not allow to override the SMPS state.
389 if (sdata
->vif
.driver_flags
& IEEE80211_VIF_EML_ACTIVE
)
392 if (!(local
->hw
.wiphy
->features
& NL80211_FEATURE_STATIC_SMPS
) &&
393 smps_mode
== IEEE80211_SMPS_STATIC
)
396 /* auto should be dynamic if in PS mode */
397 if (!(local
->hw
.wiphy
->features
& NL80211_FEATURE_DYNAMIC_SMPS
) &&
398 (smps_mode
== IEEE80211_SMPS_DYNAMIC
||
399 smps_mode
== IEEE80211_SMPS_AUTOMATIC
))
402 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
405 return __ieee80211_request_smps_mgd(link
->sdata
, link
, smps_mode
);
408 static const char *smps_modes
[IEEE80211_SMPS_NUM_MODES
] = {
409 [IEEE80211_SMPS_AUTOMATIC
] = "auto",
410 [IEEE80211_SMPS_OFF
] = "off",
411 [IEEE80211_SMPS_STATIC
] = "static",
412 [IEEE80211_SMPS_DYNAMIC
] = "dynamic",
415 static ssize_t
ieee80211_if_fmt_smps(const struct ieee80211_link_data
*link
,
416 char *buf
, int buflen
)
418 if (link
->sdata
->vif
.type
== NL80211_IFTYPE_STATION
)
419 return snprintf(buf
, buflen
, "request: %s\nused: %s\n",
420 smps_modes
[link
->u
.mgd
.req_smps
],
421 smps_modes
[link
->smps_mode
]);
425 static ssize_t
ieee80211_if_parse_smps(struct ieee80211_link_data
*link
,
426 const char *buf
, int buflen
)
428 enum ieee80211_smps_mode mode
;
430 for (mode
= 0; mode
< IEEE80211_SMPS_NUM_MODES
; mode
++) {
431 if (strncmp(buf
, smps_modes
[mode
], buflen
) == 0) {
432 int err
= ieee80211_set_smps(link
, mode
);
441 IEEE80211_IF_LINK_FILE_RW(smps
);
443 static ssize_t
ieee80211_if_parse_tkip_mic_test(
444 struct ieee80211_sub_if_data
*sdata
, const char *buf
, int buflen
)
446 struct ieee80211_local
*local
= sdata
->local
;
449 struct ieee80211_hdr
*hdr
;
452 if (!mac_pton(buf
, addr
))
455 if (!ieee80211_sdata_running(sdata
))
458 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 24 + 100);
461 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
463 hdr
= skb_put_zero(skb
, 24);
464 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_DATA
);
466 switch (sdata
->vif
.type
) {
467 case NL80211_IFTYPE_AP
:
468 fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
);
470 memcpy(hdr
->addr1
, addr
, ETH_ALEN
);
471 memcpy(hdr
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
472 memcpy(hdr
->addr3
, sdata
->vif
.addr
, ETH_ALEN
);
474 case NL80211_IFTYPE_STATION
:
475 fc
|= cpu_to_le16(IEEE80211_FCTL_TODS
);
477 if (!sdata
->u
.mgd
.associated
) {
481 memcpy(hdr
->addr1
, sdata
->deflink
.u
.mgd
.bssid
, ETH_ALEN
);
482 memcpy(hdr
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
483 memcpy(hdr
->addr3
, addr
, ETH_ALEN
);
489 hdr
->frame_control
= fc
;
492 * Add some length to the test frame to make it look bit more valid.
493 * The exact contents does not matter since the recipient is required
494 * to drop this because of the Michael MIC failure.
496 skb_put_zero(skb
, 50);
498 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE
;
500 ieee80211_tx_skb(sdata
, skb
);
504 IEEE80211_IF_FILE_W(tkip_mic_test
);
506 static ssize_t
ieee80211_if_parse_beacon_loss(
507 struct ieee80211_sub_if_data
*sdata
, const char *buf
, int buflen
)
509 if (!ieee80211_sdata_running(sdata
) || !sdata
->vif
.cfg
.assoc
)
512 ieee80211_beacon_loss(&sdata
->vif
);
516 IEEE80211_IF_FILE_W(beacon_loss
);
518 static ssize_t
ieee80211_if_fmt_uapsd_queues(
519 const struct ieee80211_sub_if_data
*sdata
, char *buf
, int buflen
)
521 const struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
523 return snprintf(buf
, buflen
, "0x%x\n", ifmgd
->uapsd_queues
);
526 static ssize_t
ieee80211_if_parse_uapsd_queues(
527 struct ieee80211_sub_if_data
*sdata
, const char *buf
, int buflen
)
529 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
533 ret
= kstrtou8(buf
, 0, &val
);
537 if (val
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
540 ifmgd
->uapsd_queues
= val
;
544 IEEE80211_IF_FILE_RW(uapsd_queues
);
546 static ssize_t
ieee80211_if_fmt_uapsd_max_sp_len(
547 const struct ieee80211_sub_if_data
*sdata
, char *buf
, int buflen
)
549 const struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
551 return snprintf(buf
, buflen
, "0x%x\n", ifmgd
->uapsd_max_sp_len
);
554 static ssize_t
ieee80211_if_parse_uapsd_max_sp_len(
555 struct ieee80211_sub_if_data
*sdata
, const char *buf
, int buflen
)
557 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
561 ret
= kstrtoul(buf
, 0, &val
);
565 if (val
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
568 ifmgd
->uapsd_max_sp_len
= val
;
572 IEEE80211_IF_FILE_RW(uapsd_max_sp_len
);
574 static ssize_t
ieee80211_if_fmt_tdls_wider_bw(
575 const struct ieee80211_sub_if_data
*sdata
, char *buf
, int buflen
)
577 const struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
580 tdls_wider_bw
= ieee80211_hw_check(&sdata
->local
->hw
, TDLS_WIDER_BW
) &&
581 !ifmgd
->tdls_wider_bw_prohibited
;
583 return snprintf(buf
, buflen
, "%d\n", tdls_wider_bw
);
586 static ssize_t
ieee80211_if_parse_tdls_wider_bw(
587 struct ieee80211_sub_if_data
*sdata
, const char *buf
, int buflen
)
589 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
593 ret
= kstrtou8(buf
, 0, &val
);
597 ifmgd
->tdls_wider_bw_prohibited
= !val
;
600 IEEE80211_IF_FILE_RW(tdls_wider_bw
);
603 IEEE80211_IF_FILE(num_mcast_sta
, u
.ap
.num_mcast_sta
, ATOMIC
);
604 IEEE80211_IF_FILE(num_sta_ps
, u
.ap
.ps
.num_sta_ps
, ATOMIC
);
605 IEEE80211_IF_FILE(dtim_count
, u
.ap
.ps
.dtim_count
, DEC
);
606 IEEE80211_IF_FILE(num_mcast_sta_vlan
, u
.vlan
.num_mcast_sta
, ATOMIC
);
608 static ssize_t
ieee80211_if_fmt_num_buffered_multicast(
609 const struct ieee80211_sub_if_data
*sdata
, char *buf
, int buflen
)
611 return scnprintf(buf
, buflen
, "%u\n",
612 skb_queue_len(&sdata
->u
.ap
.ps
.bc_buf
));
614 IEEE80211_IF_FILE_R(num_buffered_multicast
);
616 static ssize_t
ieee80211_if_fmt_aqm(
617 const struct ieee80211_sub_if_data
*sdata
, char *buf
, int buflen
)
619 struct ieee80211_local
*local
= sdata
->local
;
620 struct txq_info
*txqi
;
626 txqi
= to_txq_info(sdata
->vif
.txq
);
628 spin_lock_bh(&local
->fq
.lock
);
633 "ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n"
634 "%u %u %u %u %u %u %u %u %u %u\n",
636 txqi
->tin
.backlog_bytes
,
637 txqi
->tin
.backlog_packets
,
639 txqi
->cstats
.drop_count
,
640 txqi
->cstats
.ecn_mark
,
642 txqi
->tin
.collisions
,
644 txqi
->tin
.tx_packets
);
647 spin_unlock_bh(&local
->fq
.lock
);
651 IEEE80211_IF_FILE_R(aqm
);
653 IEEE80211_IF_FILE(multicast_to_unicast
, u
.ap
.multicast_to_unicast
, HEX
);
655 /* IBSS attributes */
656 static ssize_t
ieee80211_if_fmt_tsf(
657 const struct ieee80211_sub_if_data
*sdata
, char *buf
, int buflen
)
659 struct ieee80211_local
*local
= sdata
->local
;
662 tsf
= drv_get_tsf(local
, (struct ieee80211_sub_if_data
*)sdata
);
664 return scnprintf(buf
, buflen
, "0x%016llx\n", (unsigned long long) tsf
);
667 static ssize_t
ieee80211_if_parse_tsf(
668 struct ieee80211_sub_if_data
*sdata
, const char *buf
, int buflen
)
670 struct ieee80211_local
*local
= sdata
->local
;
671 unsigned long long tsf
;
673 int tsf_is_delta
= 0;
675 if (strncmp(buf
, "reset", 5) == 0) {
676 if (local
->ops
->reset_tsf
) {
677 drv_reset_tsf(local
, sdata
);
678 wiphy_info(local
->hw
.wiphy
, "debugfs reset TSF\n");
681 if (buflen
> 10 && buf
[1] == '=') {
684 else if (buf
[0] == '-')
690 ret
= kstrtoull(buf
, 10, &tsf
);
693 if (tsf_is_delta
&& local
->ops
->offset_tsf
) {
694 drv_offset_tsf(local
, sdata
, tsf_is_delta
* tsf
);
695 wiphy_info(local
->hw
.wiphy
,
696 "debugfs offset TSF by %018lld\n",
698 } else if (local
->ops
->set_tsf
) {
700 tsf
= drv_get_tsf(local
, sdata
) +
702 drv_set_tsf(local
, sdata
, tsf
);
703 wiphy_info(local
->hw
.wiphy
,
704 "debugfs set TSF to %#018llx\n", tsf
);
708 ieee80211_recalc_dtim(local
, sdata
);
711 IEEE80211_IF_FILE_RW(tsf
);
713 static ssize_t
ieee80211_if_fmt_valid_links(const struct ieee80211_sub_if_data
*sdata
,
714 char *buf
, int buflen
)
716 return snprintf(buf
, buflen
, "0x%x\n", sdata
->vif
.valid_links
);
718 IEEE80211_IF_FILE_R(valid_links
);
720 static ssize_t
ieee80211_if_fmt_active_links(const struct ieee80211_sub_if_data
*sdata
,
721 char *buf
, int buflen
)
723 return snprintf(buf
, buflen
, "0x%x\n", sdata
->vif
.active_links
);
726 static ssize_t
ieee80211_if_parse_active_links(struct ieee80211_sub_if_data
*sdata
,
727 const char *buf
, int buflen
)
731 if (kstrtou16(buf
, 0, &active_links
))
734 return ieee80211_set_active_links(&sdata
->vif
, active_links
) ?: buflen
;
736 IEEE80211_IF_FILE_RW(active_links
);
738 IEEE80211_IF_LINK_FILE(addr
, conf
->addr
, MAC
);
740 #ifdef CONFIG_MAC80211_MESH
741 IEEE80211_IF_FILE(estab_plinks
, u
.mesh
.estab_plinks
, ATOMIC
);
743 /* Mesh stats attributes */
744 IEEE80211_IF_FILE(fwded_mcast
, u
.mesh
.mshstats
.fwded_mcast
, DEC
);
745 IEEE80211_IF_FILE(fwded_unicast
, u
.mesh
.mshstats
.fwded_unicast
, DEC
);
746 IEEE80211_IF_FILE(fwded_frames
, u
.mesh
.mshstats
.fwded_frames
, DEC
);
747 IEEE80211_IF_FILE(dropped_frames_ttl
, u
.mesh
.mshstats
.dropped_frames_ttl
, DEC
);
748 IEEE80211_IF_FILE(dropped_frames_no_route
,
749 u
.mesh
.mshstats
.dropped_frames_no_route
, DEC
);
751 /* Mesh parameters */
752 IEEE80211_IF_FILE(dot11MeshMaxRetries
,
753 u
.mesh
.mshcfg
.dot11MeshMaxRetries
, DEC
);
754 IEEE80211_IF_FILE(dot11MeshRetryTimeout
,
755 u
.mesh
.mshcfg
.dot11MeshRetryTimeout
, DEC
);
756 IEEE80211_IF_FILE(dot11MeshConfirmTimeout
,
757 u
.mesh
.mshcfg
.dot11MeshConfirmTimeout
, DEC
);
758 IEEE80211_IF_FILE(dot11MeshHoldingTimeout
,
759 u
.mesh
.mshcfg
.dot11MeshHoldingTimeout
, DEC
);
760 IEEE80211_IF_FILE(dot11MeshTTL
, u
.mesh
.mshcfg
.dot11MeshTTL
, DEC
);
761 IEEE80211_IF_FILE(element_ttl
, u
.mesh
.mshcfg
.element_ttl
, DEC
);
762 IEEE80211_IF_FILE(auto_open_plinks
, u
.mesh
.mshcfg
.auto_open_plinks
, DEC
);
763 IEEE80211_IF_FILE(dot11MeshMaxPeerLinks
,
764 u
.mesh
.mshcfg
.dot11MeshMaxPeerLinks
, DEC
);
765 IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout
,
766 u
.mesh
.mshcfg
.dot11MeshHWMPactivePathTimeout
, DEC
);
767 IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval
,
768 u
.mesh
.mshcfg
.dot11MeshHWMPpreqMinInterval
, DEC
);
769 IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval
,
770 u
.mesh
.mshcfg
.dot11MeshHWMPperrMinInterval
, DEC
);
771 IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime
,
772 u
.mesh
.mshcfg
.dot11MeshHWMPnetDiameterTraversalTime
, DEC
);
773 IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries
,
774 u
.mesh
.mshcfg
.dot11MeshHWMPmaxPREQretries
, DEC
);
775 IEEE80211_IF_FILE(path_refresh_time
,
776 u
.mesh
.mshcfg
.path_refresh_time
, DEC
);
777 IEEE80211_IF_FILE(min_discovery_timeout
,
778 u
.mesh
.mshcfg
.min_discovery_timeout
, DEC
);
779 IEEE80211_IF_FILE(dot11MeshHWMPRootMode
,
780 u
.mesh
.mshcfg
.dot11MeshHWMPRootMode
, DEC
);
781 IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol
,
782 u
.mesh
.mshcfg
.dot11MeshGateAnnouncementProtocol
, DEC
);
783 IEEE80211_IF_FILE(dot11MeshHWMPRannInterval
,
784 u
.mesh
.mshcfg
.dot11MeshHWMPRannInterval
, DEC
);
785 IEEE80211_IF_FILE(dot11MeshForwarding
, u
.mesh
.mshcfg
.dot11MeshForwarding
, DEC
);
786 IEEE80211_IF_FILE(rssi_threshold
, u
.mesh
.mshcfg
.rssi_threshold
, DEC
);
787 IEEE80211_IF_FILE(ht_opmode
, u
.mesh
.mshcfg
.ht_opmode
, DEC
);
788 IEEE80211_IF_FILE(dot11MeshHWMPactivePathToRootTimeout
,
789 u
.mesh
.mshcfg
.dot11MeshHWMPactivePathToRootTimeout
, DEC
);
790 IEEE80211_IF_FILE(dot11MeshHWMProotInterval
,
791 u
.mesh
.mshcfg
.dot11MeshHWMProotInterval
, DEC
);
792 IEEE80211_IF_FILE(dot11MeshHWMPconfirmationInterval
,
793 u
.mesh
.mshcfg
.dot11MeshHWMPconfirmationInterval
, DEC
);
794 IEEE80211_IF_FILE(power_mode
, u
.mesh
.mshcfg
.power_mode
, DEC
);
795 IEEE80211_IF_FILE(dot11MeshAwakeWindowDuration
,
796 u
.mesh
.mshcfg
.dot11MeshAwakeWindowDuration
, DEC
);
797 IEEE80211_IF_FILE(dot11MeshConnectedToMeshGate
,
798 u
.mesh
.mshcfg
.dot11MeshConnectedToMeshGate
, DEC
);
799 IEEE80211_IF_FILE(dot11MeshNolearn
, u
.mesh
.mshcfg
.dot11MeshNolearn
, DEC
);
800 IEEE80211_IF_FILE(dot11MeshConnectedToAuthServer
,
801 u
.mesh
.mshcfg
.dot11MeshConnectedToAuthServer
, DEC
);
804 #define DEBUGFS_ADD_MODE(name, mode) \
805 debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \
808 #define DEBUGFS_ADD_X(_bits, _name, _mode) \
809 debugfs_create_x##_bits(#_name, _mode, sdata->vif.debugfs_dir, \
812 #define DEBUGFS_ADD_X8(_name, _mode) \
813 DEBUGFS_ADD_X(8, _name, _mode)
815 #define DEBUGFS_ADD_X16(_name, _mode) \
816 DEBUGFS_ADD_X(16, _name, _mode)
818 #define DEBUGFS_ADD_X32(_name, _mode) \
819 DEBUGFS_ADD_X(32, _name, _mode)
821 #define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400)
823 static void add_common_files(struct ieee80211_sub_if_data
*sdata
)
825 DEBUGFS_ADD(rc_rateidx_mask_2ghz
);
826 DEBUGFS_ADD(rc_rateidx_mask_5ghz
);
827 DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz
);
828 DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz
);
829 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_2ghz
);
830 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz
);
831 DEBUGFS_ADD(hw_queues
);
833 if (sdata
->vif
.type
!= NL80211_IFTYPE_P2P_DEVICE
&&
834 sdata
->vif
.type
!= NL80211_IFTYPE_NAN
)
838 static void add_sta_files(struct ieee80211_sub_if_data
*sdata
)
842 DEBUGFS_ADD(beacon_timeout
);
843 DEBUGFS_ADD_MODE(tkip_mic_test
, 0200);
844 DEBUGFS_ADD_MODE(beacon_loss
, 0200);
845 DEBUGFS_ADD_MODE(uapsd_queues
, 0600);
846 DEBUGFS_ADD_MODE(uapsd_max_sp_len
, 0600);
847 DEBUGFS_ADD_MODE(tdls_wider_bw
, 0600);
848 DEBUGFS_ADD_MODE(valid_links
, 0400);
849 DEBUGFS_ADD_MODE(active_links
, 0600);
850 DEBUGFS_ADD_X16(dormant_links
, 0400);
853 static void add_ap_files(struct ieee80211_sub_if_data
*sdata
)
855 DEBUGFS_ADD(num_mcast_sta
);
856 DEBUGFS_ADD(num_sta_ps
);
857 DEBUGFS_ADD(dtim_count
);
858 DEBUGFS_ADD(num_buffered_multicast
);
859 DEBUGFS_ADD_MODE(tkip_mic_test
, 0200);
860 DEBUGFS_ADD_MODE(multicast_to_unicast
, 0600);
863 static void add_vlan_files(struct ieee80211_sub_if_data
*sdata
)
865 /* add num_mcast_sta_vlan using name num_mcast_sta */
866 debugfs_create_file("num_mcast_sta", 0400, sdata
->vif
.debugfs_dir
,
867 sdata
, &num_mcast_sta_vlan_ops
);
870 static void add_ibss_files(struct ieee80211_sub_if_data
*sdata
)
872 DEBUGFS_ADD_MODE(tsf
, 0600);
875 #ifdef CONFIG_MAC80211_MESH
877 static void add_mesh_files(struct ieee80211_sub_if_data
*sdata
)
879 DEBUGFS_ADD_MODE(tsf
, 0600);
880 DEBUGFS_ADD_MODE(estab_plinks
, 0400);
883 static void add_mesh_stats(struct ieee80211_sub_if_data
*sdata
)
885 struct dentry
*dir
= debugfs_create_dir("mesh_stats",
886 sdata
->vif
.debugfs_dir
);
887 #define MESHSTATS_ADD(name)\
888 debugfs_create_file(#name, 0400, dir, sdata, &name##_ops)
890 MESHSTATS_ADD(fwded_mcast
);
891 MESHSTATS_ADD(fwded_unicast
);
892 MESHSTATS_ADD(fwded_frames
);
893 MESHSTATS_ADD(dropped_frames_ttl
);
894 MESHSTATS_ADD(dropped_frames_no_route
);
898 static void add_mesh_config(struct ieee80211_sub_if_data
*sdata
)
900 struct dentry
*dir
= debugfs_create_dir("mesh_config",
901 sdata
->vif
.debugfs_dir
);
903 #define MESHPARAMS_ADD(name) \
904 debugfs_create_file(#name, 0600, dir, sdata, &name##_ops)
906 MESHPARAMS_ADD(dot11MeshMaxRetries
);
907 MESHPARAMS_ADD(dot11MeshRetryTimeout
);
908 MESHPARAMS_ADD(dot11MeshConfirmTimeout
);
909 MESHPARAMS_ADD(dot11MeshHoldingTimeout
);
910 MESHPARAMS_ADD(dot11MeshTTL
);
911 MESHPARAMS_ADD(element_ttl
);
912 MESHPARAMS_ADD(auto_open_plinks
);
913 MESHPARAMS_ADD(dot11MeshMaxPeerLinks
);
914 MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout
);
915 MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval
);
916 MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval
);
917 MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime
);
918 MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries
);
919 MESHPARAMS_ADD(path_refresh_time
);
920 MESHPARAMS_ADD(min_discovery_timeout
);
921 MESHPARAMS_ADD(dot11MeshHWMPRootMode
);
922 MESHPARAMS_ADD(dot11MeshHWMPRannInterval
);
923 MESHPARAMS_ADD(dot11MeshForwarding
);
924 MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol
);
925 MESHPARAMS_ADD(rssi_threshold
);
926 MESHPARAMS_ADD(ht_opmode
);
927 MESHPARAMS_ADD(dot11MeshHWMPactivePathToRootTimeout
);
928 MESHPARAMS_ADD(dot11MeshHWMProotInterval
);
929 MESHPARAMS_ADD(dot11MeshHWMPconfirmationInterval
);
930 MESHPARAMS_ADD(power_mode
);
931 MESHPARAMS_ADD(dot11MeshAwakeWindowDuration
);
932 MESHPARAMS_ADD(dot11MeshConnectedToMeshGate
);
933 MESHPARAMS_ADD(dot11MeshNolearn
);
934 MESHPARAMS_ADD(dot11MeshConnectedToAuthServer
);
935 #undef MESHPARAMS_ADD
939 static void add_files(struct ieee80211_sub_if_data
*sdata
)
941 if (!sdata
->vif
.debugfs_dir
)
947 if (sdata
->vif
.type
!= NL80211_IFTYPE_MONITOR
)
948 add_common_files(sdata
);
950 switch (sdata
->vif
.type
) {
951 case NL80211_IFTYPE_MESH_POINT
:
952 #ifdef CONFIG_MAC80211_MESH
953 add_mesh_files(sdata
);
954 add_mesh_stats(sdata
);
955 add_mesh_config(sdata
);
958 case NL80211_IFTYPE_STATION
:
959 add_sta_files(sdata
);
961 case NL80211_IFTYPE_ADHOC
:
962 add_ibss_files(sdata
);
964 case NL80211_IFTYPE_AP
:
967 case NL80211_IFTYPE_AP_VLAN
:
968 add_vlan_files(sdata
);
975 #undef DEBUGFS_ADD_MODE
978 #define DEBUGFS_ADD_MODE(dentry, name, mode) \
979 debugfs_create_file(#name, mode, dentry, \
980 link, &link_##name##_ops)
982 #define DEBUGFS_ADD(dentry, name) DEBUGFS_ADD_MODE(dentry, name, 0400)
984 static void add_link_files(struct ieee80211_link_data
*link
,
985 struct dentry
*dentry
)
987 DEBUGFS_ADD(dentry
, txpower
);
988 DEBUGFS_ADD(dentry
, user_power_level
);
989 DEBUGFS_ADD(dentry
, ap_power_level
);
991 switch (link
->sdata
->vif
.type
) {
992 case NL80211_IFTYPE_STATION
:
993 DEBUGFS_ADD_MODE(dentry
, smps
, 0600);
1000 static void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data
*sdata
,
1003 char buf
[10+IFNAMSIZ
];
1005 sprintf(buf
, "netdev:%s", sdata
->name
);
1006 sdata
->vif
.debugfs_dir
= debugfs_create_dir(buf
,
1007 sdata
->local
->hw
.wiphy
->debugfsdir
);
1008 /* deflink also has this */
1009 sdata
->deflink
.debugfs_dir
= sdata
->vif
.debugfs_dir
;
1010 sdata
->debugfs
.subdir_stations
= debugfs_create_dir("stations",
1011 sdata
->vif
.debugfs_dir
);
1014 add_link_files(&sdata
->deflink
, sdata
->vif
.debugfs_dir
);
1017 void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data
*sdata
)
1019 if (!sdata
->vif
.debugfs_dir
)
1022 debugfs_remove_recursive(sdata
->vif
.debugfs_dir
);
1023 sdata
->vif
.debugfs_dir
= NULL
;
1024 sdata
->debugfs
.subdir_stations
= NULL
;
1027 void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data
*sdata
)
1030 char buf
[10 + IFNAMSIZ
];
1032 dir
= sdata
->vif
.debugfs_dir
;
1034 if (IS_ERR_OR_NULL(dir
))
1037 sprintf(buf
, "netdev:%s", sdata
->name
);
1038 debugfs_rename(dir
->d_parent
, dir
, dir
->d_parent
, buf
);
1041 void ieee80211_debugfs_recreate_netdev(struct ieee80211_sub_if_data
*sdata
,
1044 ieee80211_debugfs_remove_netdev(sdata
);
1045 ieee80211_debugfs_add_netdev(sdata
, mld_vif
);
1047 if (sdata
->flags
& IEEE80211_SDATA_IN_DRIVER
) {
1048 drv_vif_add_debugfs(sdata
->local
, sdata
);
1050 ieee80211_link_debugfs_drv_add(&sdata
->deflink
);
1054 void ieee80211_link_debugfs_add(struct ieee80211_link_data
*link
)
1056 char link_dir_name
[10];
1058 if (WARN_ON(!link
->sdata
->vif
.debugfs_dir
|| link
->debugfs_dir
))
1061 /* For now, this should not be called for non-MLO capable drivers */
1062 if (WARN_ON(!(link
->sdata
->local
->hw
.wiphy
->flags
& WIPHY_FLAG_SUPPORTS_MLO
)))
1065 snprintf(link_dir_name
, sizeof(link_dir_name
),
1066 "link-%d", link
->link_id
);
1069 debugfs_create_dir(link_dir_name
,
1070 link
->sdata
->vif
.debugfs_dir
);
1072 DEBUGFS_ADD(link
->debugfs_dir
, addr
);
1073 add_link_files(link
, link
->debugfs_dir
);
1076 void ieee80211_link_debugfs_remove(struct ieee80211_link_data
*link
)
1078 if (!link
->sdata
->vif
.debugfs_dir
|| !link
->debugfs_dir
) {
1079 link
->debugfs_dir
= NULL
;
1083 if (link
->debugfs_dir
== link
->sdata
->vif
.debugfs_dir
) {
1084 WARN_ON(link
!= &link
->sdata
->deflink
);
1085 link
->debugfs_dir
= NULL
;
1089 debugfs_remove_recursive(link
->debugfs_dir
);
1090 link
->debugfs_dir
= NULL
;
1093 void ieee80211_link_debugfs_drv_add(struct ieee80211_link_data
*link
)
1095 if (link
->sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
||
1096 WARN_ON(!link
->debugfs_dir
))
1099 drv_link_add_debugfs(link
->sdata
->local
, link
->sdata
,
1100 link
->conf
, link
->debugfs_dir
);
1103 void ieee80211_link_debugfs_drv_remove(struct ieee80211_link_data
*link
)
1105 if (!link
|| !link
->debugfs_dir
)
1108 if (WARN_ON(link
->debugfs_dir
== link
->sdata
->vif
.debugfs_dir
))
1111 /* Recreate the directory excluding the driver data */
1112 debugfs_remove_recursive(link
->debugfs_dir
);
1113 link
->debugfs_dir
= NULL
;
1115 ieee80211_link_debugfs_add(link
);