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_sdata(
26 struct ieee80211_sub_if_data
*sdata
,
28 size_t count
, loff_t
*ppos
,
29 ssize_t (*format
)(const struct ieee80211_sub_if_data
*sdata
, char *, int))
32 ssize_t ret
= -EINVAL
;
34 wiphy_lock(sdata
->local
->hw
.wiphy
);
35 ret
= (*format
)(sdata
, buf
, sizeof(buf
));
36 wiphy_unlock(sdata
->local
->hw
.wiphy
);
39 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, ret
);
44 static ssize_t
ieee80211_if_write_sdata(
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
*sdata
, const char *, int))
53 if (count
>= sizeof(buf
))
56 if (copy_from_user(buf
, userbuf
, count
))
60 wiphy_lock(sdata
->local
->hw
.wiphy
);
61 ret
= (*write
)(sdata
, buf
, count
);
62 wiphy_unlock(sdata
->local
->hw
.wiphy
);
67 static ssize_t
ieee80211_if_read_link(
68 struct ieee80211_link_data
*link
,
70 size_t count
, loff_t
*ppos
,
71 ssize_t (*format
)(const struct ieee80211_link_data
*link
, char *, int))
74 ssize_t ret
= -EINVAL
;
76 wiphy_lock(link
->sdata
->local
->hw
.wiphy
);
77 ret
= (*format
)(link
, buf
, sizeof(buf
));
78 wiphy_unlock(link
->sdata
->local
->hw
.wiphy
);
81 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, ret
);
86 static ssize_t
ieee80211_if_write_link(
87 struct ieee80211_link_data
*link
,
88 const char __user
*userbuf
,
89 size_t count
, loff_t
*ppos
,
90 ssize_t (*write
)(struct ieee80211_link_data
*link
, const char *, int))
95 if (count
>= sizeof(buf
))
98 if (copy_from_user(buf
, userbuf
, count
))
102 wiphy_lock(link
->sdata
->local
->hw
.wiphy
);
103 ret
= (*write
)(link
, buf
, count
);
104 wiphy_unlock(link
->sdata
->local
->hw
.wiphy
);
109 #define IEEE80211_IF_FMT(name, type, field, format_string) \
110 static ssize_t ieee80211_if_fmt_##name( \
111 const type *data, char *buf, \
114 return scnprintf(buf, buflen, format_string, data->field); \
116 #define IEEE80211_IF_FMT_DEC(name, type, field) \
117 IEEE80211_IF_FMT(name, type, field, "%d\n")
118 #define IEEE80211_IF_FMT_HEX(name, type, field) \
119 IEEE80211_IF_FMT(name, type, field, "%#x\n")
120 #define IEEE80211_IF_FMT_LHEX(name, type, field) \
121 IEEE80211_IF_FMT(name, type, field, "%#lx\n")
123 #define IEEE80211_IF_FMT_HEXARRAY(name, type, field) \
124 static ssize_t ieee80211_if_fmt_##name( \
126 char *buf, int buflen) \
130 for (i = 0; i < sizeof(data->field); i++) { \
131 p += scnprintf(p, buflen + buf - p, "%.2x ", \
134 p += scnprintf(p, buflen + buf - p, "\n"); \
138 #define IEEE80211_IF_FMT_ATOMIC(name, type, field) \
139 static ssize_t ieee80211_if_fmt_##name( \
141 char *buf, int buflen) \
143 return scnprintf(buf, buflen, "%d\n", atomic_read(&data->field));\
146 #define IEEE80211_IF_FMT_MAC(name, type, field) \
147 static ssize_t ieee80211_if_fmt_##name( \
148 const type *data, char *buf, \
151 return scnprintf(buf, buflen, "%pM\n", data->field); \
154 #define IEEE80211_IF_FMT_JIFFIES_TO_MS(name, type, field) \
155 static ssize_t ieee80211_if_fmt_##name( \
157 char *buf, int buflen) \
159 return scnprintf(buf, buflen, "%d\n", \
160 jiffies_to_msecs(data->field)); \
163 #define _IEEE80211_IF_FILE_OPS(name, _read, _write) \
164 static const struct file_operations name##_ops = { \
167 .open = simple_open, \
168 .llseek = generic_file_llseek, \
171 #define _IEEE80211_IF_FILE_R_FN(name) \
172 static ssize_t ieee80211_if_read_##name(struct file *file, \
173 char __user *userbuf, \
174 size_t count, loff_t *ppos) \
176 return ieee80211_if_read_sdata(file->private_data, \
177 userbuf, count, ppos, \
178 ieee80211_if_fmt_##name); \
181 #define _IEEE80211_IF_FILE_W_FN(name) \
182 static ssize_t ieee80211_if_write_##name(struct file *file, \
183 const char __user *userbuf, \
184 size_t count, loff_t *ppos) \
186 return ieee80211_if_write_sdata(file->private_data, userbuf, \
188 ieee80211_if_parse_##name); \
191 #define IEEE80211_IF_FILE_R(name) \
192 _IEEE80211_IF_FILE_R_FN(name) \
193 _IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, NULL)
195 #define IEEE80211_IF_FILE_W(name) \
196 _IEEE80211_IF_FILE_W_FN(name) \
197 _IEEE80211_IF_FILE_OPS(name, NULL, ieee80211_if_write_##name)
199 #define IEEE80211_IF_FILE_RW(name) \
200 _IEEE80211_IF_FILE_R_FN(name) \
201 _IEEE80211_IF_FILE_W_FN(name) \
202 _IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, \
203 ieee80211_if_write_##name)
205 #define IEEE80211_IF_FILE(name, field, format) \
206 IEEE80211_IF_FMT_##format(name, struct ieee80211_sub_if_data, field) \
207 IEEE80211_IF_FILE_R(name)
209 #define _IEEE80211_IF_LINK_R_FN(name) \
210 static ssize_t ieee80211_if_read_##name(struct file *file, \
211 char __user *userbuf, \
212 size_t count, loff_t *ppos) \
214 return ieee80211_if_read_link(file->private_data, \
215 userbuf, count, ppos, \
216 ieee80211_if_fmt_##name); \
219 #define _IEEE80211_IF_LINK_W_FN(name) \
220 static ssize_t ieee80211_if_write_##name(struct file *file, \
221 const char __user *userbuf, \
222 size_t count, loff_t *ppos) \
224 return ieee80211_if_write_link(file->private_data, userbuf, \
226 ieee80211_if_parse_##name); \
229 #define IEEE80211_IF_LINK_FILE_R(name) \
230 _IEEE80211_IF_LINK_R_FN(name) \
231 _IEEE80211_IF_FILE_OPS(link_##name, ieee80211_if_read_##name, NULL)
233 #define IEEE80211_IF_LINK_FILE_W(name) \
234 _IEEE80211_IF_LINK_W_FN(name) \
235 _IEEE80211_IF_FILE_OPS(link_##name, NULL, ieee80211_if_write_##name)
237 #define IEEE80211_IF_LINK_FILE_RW(name) \
238 _IEEE80211_IF_LINK_R_FN(name) \
239 _IEEE80211_IF_LINK_W_FN(name) \
240 _IEEE80211_IF_FILE_OPS(link_##name, ieee80211_if_read_##name, \
241 ieee80211_if_write_##name)
243 #define IEEE80211_IF_LINK_FILE(name, field, format) \
244 IEEE80211_IF_FMT_##format(name, struct ieee80211_link_data, field) \
245 IEEE80211_IF_LINK_FILE_R(name)
247 /* common attributes */
248 IEEE80211_IF_FILE(rc_rateidx_mask_2ghz
, rc_rateidx_mask
[NL80211_BAND_2GHZ
],
250 IEEE80211_IF_FILE(rc_rateidx_mask_5ghz
, rc_rateidx_mask
[NL80211_BAND_5GHZ
],
252 IEEE80211_IF_FILE(rc_rateidx_mcs_mask_2ghz
,
253 rc_rateidx_mcs_mask
[NL80211_BAND_2GHZ
], HEXARRAY
);
254 IEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz
,
255 rc_rateidx_mcs_mask
[NL80211_BAND_5GHZ
], HEXARRAY
);
257 static ssize_t
ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_2ghz(
258 const struct ieee80211_sub_if_data
*sdata
,
259 char *buf
, int buflen
)
262 const u16
*mask
= sdata
->rc_rateidx_vht_mcs_mask
[NL80211_BAND_2GHZ
];
264 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
265 len
+= scnprintf(buf
+ len
, buflen
- len
, "%04x ", mask
[i
]);
266 len
+= scnprintf(buf
+ len
, buflen
- len
, "\n");
271 IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_2ghz
);
273 static ssize_t
ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_5ghz(
274 const struct ieee80211_sub_if_data
*sdata
,
275 char *buf
, int buflen
)
278 const u16
*mask
= sdata
->rc_rateidx_vht_mcs_mask
[NL80211_BAND_5GHZ
];
280 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
281 len
+= scnprintf(buf
+ len
, buflen
- len
, "%04x ", mask
[i
]);
282 len
+= scnprintf(buf
+ len
, buflen
- len
, "\n");
287 IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_5ghz
);
289 IEEE80211_IF_FILE(flags
, flags
, HEX
);
290 IEEE80211_IF_FILE(state
, state
, LHEX
);
291 IEEE80211_IF_LINK_FILE(txpower
, conf
->txpower
, DEC
);
292 IEEE80211_IF_LINK_FILE(ap_power_level
, ap_power_level
, DEC
);
293 IEEE80211_IF_LINK_FILE(user_power_level
, user_power_level
, DEC
);
296 ieee80211_if_fmt_hw_queues(const struct ieee80211_sub_if_data
*sdata
,
297 char *buf
, int buflen
)
301 len
= scnprintf(buf
, buflen
, "AC queues: VO:%d VI:%d BE:%d BK:%d\n",
302 sdata
->vif
.hw_queue
[IEEE80211_AC_VO
],
303 sdata
->vif
.hw_queue
[IEEE80211_AC_VI
],
304 sdata
->vif
.hw_queue
[IEEE80211_AC_BE
],
305 sdata
->vif
.hw_queue
[IEEE80211_AC_BK
]);
307 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
)
308 len
+= scnprintf(buf
+ len
, buflen
- len
, "cab queue: %d\n",
309 sdata
->vif
.cab_queue
);
313 IEEE80211_IF_FILE_R(hw_queues
);
316 IEEE80211_IF_FILE(bssid
, deflink
.u
.mgd
.bssid
, MAC
);
317 IEEE80211_IF_FILE(aid
, vif
.cfg
.aid
, DEC
);
318 IEEE80211_IF_FILE(beacon_timeout
, u
.mgd
.beacon_timeout
, JIFFIES_TO_MS
);
320 static int ieee80211_set_smps(struct ieee80211_link_data
*link
,
321 enum ieee80211_smps_mode smps_mode
)
323 struct ieee80211_sub_if_data
*sdata
= link
->sdata
;
324 struct ieee80211_local
*local
= sdata
->local
;
326 /* The driver indicated that EML is enabled for the interface, thus do
327 * not allow to override the SMPS state.
329 if (sdata
->vif
.driver_flags
& IEEE80211_VIF_EML_ACTIVE
)
332 if (!(local
->hw
.wiphy
->features
& NL80211_FEATURE_STATIC_SMPS
) &&
333 smps_mode
== IEEE80211_SMPS_STATIC
)
336 /* auto should be dynamic if in PS mode */
337 if (!(local
->hw
.wiphy
->features
& NL80211_FEATURE_DYNAMIC_SMPS
) &&
338 (smps_mode
== IEEE80211_SMPS_DYNAMIC
||
339 smps_mode
== IEEE80211_SMPS_AUTOMATIC
))
342 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
345 return __ieee80211_request_smps_mgd(link
->sdata
, link
, smps_mode
);
348 static const char *smps_modes
[IEEE80211_SMPS_NUM_MODES
] = {
349 [IEEE80211_SMPS_AUTOMATIC
] = "auto",
350 [IEEE80211_SMPS_OFF
] = "off",
351 [IEEE80211_SMPS_STATIC
] = "static",
352 [IEEE80211_SMPS_DYNAMIC
] = "dynamic",
355 static ssize_t
ieee80211_if_fmt_smps(const struct ieee80211_link_data
*link
,
356 char *buf
, int buflen
)
358 if (link
->sdata
->vif
.type
== NL80211_IFTYPE_STATION
)
359 return snprintf(buf
, buflen
, "request: %s\nused: %s\n",
360 smps_modes
[link
->u
.mgd
.req_smps
],
361 smps_modes
[link
->smps_mode
]);
365 static ssize_t
ieee80211_if_parse_smps(struct ieee80211_link_data
*link
,
366 const char *buf
, int buflen
)
368 enum ieee80211_smps_mode mode
;
370 for (mode
= 0; mode
< IEEE80211_SMPS_NUM_MODES
; mode
++) {
371 if (strncmp(buf
, smps_modes
[mode
], buflen
) == 0) {
372 int err
= ieee80211_set_smps(link
, mode
);
381 IEEE80211_IF_LINK_FILE_RW(smps
);
383 static ssize_t
ieee80211_if_parse_tkip_mic_test(
384 struct ieee80211_sub_if_data
*sdata
, const char *buf
, int buflen
)
386 struct ieee80211_local
*local
= sdata
->local
;
389 struct ieee80211_hdr
*hdr
;
392 if (!mac_pton(buf
, addr
))
395 if (!ieee80211_sdata_running(sdata
))
398 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 24 + 100);
401 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
403 hdr
= skb_put_zero(skb
, 24);
404 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_DATA
);
406 switch (sdata
->vif
.type
) {
407 case NL80211_IFTYPE_AP
:
408 fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
);
410 memcpy(hdr
->addr1
, addr
, ETH_ALEN
);
411 memcpy(hdr
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
412 memcpy(hdr
->addr3
, sdata
->vif
.addr
, ETH_ALEN
);
414 case NL80211_IFTYPE_STATION
:
415 fc
|= cpu_to_le16(IEEE80211_FCTL_TODS
);
417 if (!sdata
->u
.mgd
.associated
) {
421 memcpy(hdr
->addr1
, sdata
->deflink
.u
.mgd
.bssid
, ETH_ALEN
);
422 memcpy(hdr
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
423 memcpy(hdr
->addr3
, addr
, ETH_ALEN
);
429 hdr
->frame_control
= fc
;
432 * Add some length to the test frame to make it look bit more valid.
433 * The exact contents does not matter since the recipient is required
434 * to drop this because of the Michael MIC failure.
436 skb_put_zero(skb
, 50);
438 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE
;
440 ieee80211_tx_skb(sdata
, skb
);
444 IEEE80211_IF_FILE_W(tkip_mic_test
);
446 static ssize_t
ieee80211_if_parse_beacon_loss(
447 struct ieee80211_sub_if_data
*sdata
, const char *buf
, int buflen
)
449 if (!ieee80211_sdata_running(sdata
) || !sdata
->vif
.cfg
.assoc
)
452 ieee80211_beacon_loss(&sdata
->vif
);
456 IEEE80211_IF_FILE_W(beacon_loss
);
458 static ssize_t
ieee80211_if_fmt_uapsd_queues(
459 const struct ieee80211_sub_if_data
*sdata
, char *buf
, int buflen
)
461 const struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
463 return snprintf(buf
, buflen
, "0x%x\n", ifmgd
->uapsd_queues
);
466 static ssize_t
ieee80211_if_parse_uapsd_queues(
467 struct ieee80211_sub_if_data
*sdata
, const char *buf
, int buflen
)
469 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
473 ret
= kstrtou8(buf
, 0, &val
);
477 if (val
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
480 ifmgd
->uapsd_queues
= val
;
484 IEEE80211_IF_FILE_RW(uapsd_queues
);
486 static ssize_t
ieee80211_if_fmt_uapsd_max_sp_len(
487 const struct ieee80211_sub_if_data
*sdata
, char *buf
, int buflen
)
489 const struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
491 return snprintf(buf
, buflen
, "0x%x\n", ifmgd
->uapsd_max_sp_len
);
494 static ssize_t
ieee80211_if_parse_uapsd_max_sp_len(
495 struct ieee80211_sub_if_data
*sdata
, const char *buf
, int buflen
)
497 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
501 ret
= kstrtoul(buf
, 0, &val
);
505 if (val
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
508 ifmgd
->uapsd_max_sp_len
= val
;
512 IEEE80211_IF_FILE_RW(uapsd_max_sp_len
);
514 static ssize_t
ieee80211_if_fmt_tdls_wider_bw(
515 const struct ieee80211_sub_if_data
*sdata
, char *buf
, int buflen
)
517 const struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
520 tdls_wider_bw
= ieee80211_hw_check(&sdata
->local
->hw
, TDLS_WIDER_BW
) &&
521 !ifmgd
->tdls_wider_bw_prohibited
;
523 return snprintf(buf
, buflen
, "%d\n", tdls_wider_bw
);
526 static ssize_t
ieee80211_if_parse_tdls_wider_bw(
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 ifmgd
->tdls_wider_bw_prohibited
= !val
;
540 IEEE80211_IF_FILE_RW(tdls_wider_bw
);
543 IEEE80211_IF_FILE(num_mcast_sta
, u
.ap
.num_mcast_sta
, ATOMIC
);
544 IEEE80211_IF_FILE(num_sta_ps
, u
.ap
.ps
.num_sta_ps
, ATOMIC
);
545 IEEE80211_IF_FILE(dtim_count
, u
.ap
.ps
.dtim_count
, DEC
);
546 IEEE80211_IF_FILE(num_mcast_sta_vlan
, u
.vlan
.num_mcast_sta
, ATOMIC
);
548 static ssize_t
ieee80211_if_fmt_num_buffered_multicast(
549 const struct ieee80211_sub_if_data
*sdata
, char *buf
, int buflen
)
551 return scnprintf(buf
, buflen
, "%u\n",
552 skb_queue_len(&sdata
->u
.ap
.ps
.bc_buf
));
554 IEEE80211_IF_FILE_R(num_buffered_multicast
);
556 static ssize_t
ieee80211_if_fmt_aqm(
557 const struct ieee80211_sub_if_data
*sdata
, char *buf
, int buflen
)
559 struct ieee80211_local
*local
= sdata
->local
;
560 struct txq_info
*txqi
;
566 txqi
= to_txq_info(sdata
->vif
.txq
);
568 spin_lock_bh(&local
->fq
.lock
);
573 "ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n"
574 "%u %u %u %u %u %u %u %u %u %u\n",
576 txqi
->tin
.backlog_bytes
,
577 txqi
->tin
.backlog_packets
,
579 txqi
->cstats
.drop_count
,
580 txqi
->cstats
.ecn_mark
,
582 txqi
->tin
.collisions
,
584 txqi
->tin
.tx_packets
);
587 spin_unlock_bh(&local
->fq
.lock
);
591 IEEE80211_IF_FILE_R(aqm
);
593 IEEE80211_IF_FILE(multicast_to_unicast
, u
.ap
.multicast_to_unicast
, HEX
);
595 /* IBSS attributes */
596 static ssize_t
ieee80211_if_fmt_tsf(
597 const struct ieee80211_sub_if_data
*sdata
, char *buf
, int buflen
)
599 struct ieee80211_local
*local
= sdata
->local
;
602 tsf
= drv_get_tsf(local
, (struct ieee80211_sub_if_data
*)sdata
);
604 return scnprintf(buf
, buflen
, "0x%016llx\n", (unsigned long long) tsf
);
607 static ssize_t
ieee80211_if_parse_tsf(
608 struct ieee80211_sub_if_data
*sdata
, const char *buf
, int buflen
)
610 struct ieee80211_local
*local
= sdata
->local
;
611 unsigned long long tsf
;
613 int tsf_is_delta
= 0;
615 if (strncmp(buf
, "reset", 5) == 0) {
616 if (local
->ops
->reset_tsf
) {
617 drv_reset_tsf(local
, sdata
);
618 wiphy_info(local
->hw
.wiphy
, "debugfs reset TSF\n");
621 if (buflen
> 10 && buf
[1] == '=') {
624 else if (buf
[0] == '-')
630 ret
= kstrtoull(buf
, 10, &tsf
);
633 if (tsf_is_delta
&& local
->ops
->offset_tsf
) {
634 drv_offset_tsf(local
, sdata
, tsf_is_delta
* tsf
);
635 wiphy_info(local
->hw
.wiphy
,
636 "debugfs offset TSF by %018lld\n",
638 } else if (local
->ops
->set_tsf
) {
640 tsf
= drv_get_tsf(local
, sdata
) +
642 drv_set_tsf(local
, sdata
, tsf
);
643 wiphy_info(local
->hw
.wiphy
,
644 "debugfs set TSF to %#018llx\n", tsf
);
648 ieee80211_recalc_dtim(local
, sdata
);
651 IEEE80211_IF_FILE_RW(tsf
);
653 static ssize_t
ieee80211_if_fmt_valid_links(const struct ieee80211_sub_if_data
*sdata
,
654 char *buf
, int buflen
)
656 return snprintf(buf
, buflen
, "0x%x\n", sdata
->vif
.valid_links
);
658 IEEE80211_IF_FILE_R(valid_links
);
660 static ssize_t
ieee80211_if_fmt_active_links(const struct ieee80211_sub_if_data
*sdata
,
661 char *buf
, int buflen
)
663 return snprintf(buf
, buflen
, "0x%x\n", sdata
->vif
.active_links
);
666 static ssize_t
ieee80211_if_parse_active_links(struct ieee80211_sub_if_data
*sdata
,
667 const char *buf
, int buflen
)
671 if (kstrtou16(buf
, 0, &active_links
))
674 return ieee80211_set_active_links(&sdata
->vif
, active_links
) ?: buflen
;
676 IEEE80211_IF_FILE_RW(active_links
);
678 IEEE80211_IF_LINK_FILE(addr
, conf
->addr
, MAC
);
680 #ifdef CONFIG_MAC80211_MESH
681 IEEE80211_IF_FILE(estab_plinks
, u
.mesh
.estab_plinks
, ATOMIC
);
683 /* Mesh stats attributes */
684 IEEE80211_IF_FILE(fwded_mcast
, u
.mesh
.mshstats
.fwded_mcast
, DEC
);
685 IEEE80211_IF_FILE(fwded_unicast
, u
.mesh
.mshstats
.fwded_unicast
, DEC
);
686 IEEE80211_IF_FILE(fwded_frames
, u
.mesh
.mshstats
.fwded_frames
, DEC
);
687 IEEE80211_IF_FILE(dropped_frames_ttl
, u
.mesh
.mshstats
.dropped_frames_ttl
, DEC
);
688 IEEE80211_IF_FILE(dropped_frames_no_route
,
689 u
.mesh
.mshstats
.dropped_frames_no_route
, DEC
);
691 /* Mesh parameters */
692 IEEE80211_IF_FILE(dot11MeshMaxRetries
,
693 u
.mesh
.mshcfg
.dot11MeshMaxRetries
, DEC
);
694 IEEE80211_IF_FILE(dot11MeshRetryTimeout
,
695 u
.mesh
.mshcfg
.dot11MeshRetryTimeout
, DEC
);
696 IEEE80211_IF_FILE(dot11MeshConfirmTimeout
,
697 u
.mesh
.mshcfg
.dot11MeshConfirmTimeout
, DEC
);
698 IEEE80211_IF_FILE(dot11MeshHoldingTimeout
,
699 u
.mesh
.mshcfg
.dot11MeshHoldingTimeout
, DEC
);
700 IEEE80211_IF_FILE(dot11MeshTTL
, u
.mesh
.mshcfg
.dot11MeshTTL
, DEC
);
701 IEEE80211_IF_FILE(element_ttl
, u
.mesh
.mshcfg
.element_ttl
, DEC
);
702 IEEE80211_IF_FILE(auto_open_plinks
, u
.mesh
.mshcfg
.auto_open_plinks
, DEC
);
703 IEEE80211_IF_FILE(dot11MeshMaxPeerLinks
,
704 u
.mesh
.mshcfg
.dot11MeshMaxPeerLinks
, DEC
);
705 IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout
,
706 u
.mesh
.mshcfg
.dot11MeshHWMPactivePathTimeout
, DEC
);
707 IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval
,
708 u
.mesh
.mshcfg
.dot11MeshHWMPpreqMinInterval
, DEC
);
709 IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval
,
710 u
.mesh
.mshcfg
.dot11MeshHWMPperrMinInterval
, DEC
);
711 IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime
,
712 u
.mesh
.mshcfg
.dot11MeshHWMPnetDiameterTraversalTime
, DEC
);
713 IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries
,
714 u
.mesh
.mshcfg
.dot11MeshHWMPmaxPREQretries
, DEC
);
715 IEEE80211_IF_FILE(path_refresh_time
,
716 u
.mesh
.mshcfg
.path_refresh_time
, DEC
);
717 IEEE80211_IF_FILE(min_discovery_timeout
,
718 u
.mesh
.mshcfg
.min_discovery_timeout
, DEC
);
719 IEEE80211_IF_FILE(dot11MeshHWMPRootMode
,
720 u
.mesh
.mshcfg
.dot11MeshHWMPRootMode
, DEC
);
721 IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol
,
722 u
.mesh
.mshcfg
.dot11MeshGateAnnouncementProtocol
, DEC
);
723 IEEE80211_IF_FILE(dot11MeshHWMPRannInterval
,
724 u
.mesh
.mshcfg
.dot11MeshHWMPRannInterval
, DEC
);
725 IEEE80211_IF_FILE(dot11MeshForwarding
, u
.mesh
.mshcfg
.dot11MeshForwarding
, DEC
);
726 IEEE80211_IF_FILE(rssi_threshold
, u
.mesh
.mshcfg
.rssi_threshold
, DEC
);
727 IEEE80211_IF_FILE(ht_opmode
, u
.mesh
.mshcfg
.ht_opmode
, DEC
);
728 IEEE80211_IF_FILE(dot11MeshHWMPactivePathToRootTimeout
,
729 u
.mesh
.mshcfg
.dot11MeshHWMPactivePathToRootTimeout
, DEC
);
730 IEEE80211_IF_FILE(dot11MeshHWMProotInterval
,
731 u
.mesh
.mshcfg
.dot11MeshHWMProotInterval
, DEC
);
732 IEEE80211_IF_FILE(dot11MeshHWMPconfirmationInterval
,
733 u
.mesh
.mshcfg
.dot11MeshHWMPconfirmationInterval
, DEC
);
734 IEEE80211_IF_FILE(power_mode
, u
.mesh
.mshcfg
.power_mode
, DEC
);
735 IEEE80211_IF_FILE(dot11MeshAwakeWindowDuration
,
736 u
.mesh
.mshcfg
.dot11MeshAwakeWindowDuration
, DEC
);
737 IEEE80211_IF_FILE(dot11MeshConnectedToMeshGate
,
738 u
.mesh
.mshcfg
.dot11MeshConnectedToMeshGate
, DEC
);
739 IEEE80211_IF_FILE(dot11MeshNolearn
, u
.mesh
.mshcfg
.dot11MeshNolearn
, DEC
);
740 IEEE80211_IF_FILE(dot11MeshConnectedToAuthServer
,
741 u
.mesh
.mshcfg
.dot11MeshConnectedToAuthServer
, DEC
);
744 #define DEBUGFS_ADD_MODE(name, mode) \
745 debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \
748 #define DEBUGFS_ADD_X(_bits, _name, _mode) \
749 debugfs_create_x##_bits(#_name, _mode, sdata->vif.debugfs_dir, \
752 #define DEBUGFS_ADD_X8(_name, _mode) \
753 DEBUGFS_ADD_X(8, _name, _mode)
755 #define DEBUGFS_ADD_X16(_name, _mode) \
756 DEBUGFS_ADD_X(16, _name, _mode)
758 #define DEBUGFS_ADD_X32(_name, _mode) \
759 DEBUGFS_ADD_X(32, _name, _mode)
761 #define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400)
763 static void add_common_files(struct ieee80211_sub_if_data
*sdata
)
765 DEBUGFS_ADD(rc_rateidx_mask_2ghz
);
766 DEBUGFS_ADD(rc_rateidx_mask_5ghz
);
767 DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz
);
768 DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz
);
769 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_2ghz
);
770 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz
);
771 DEBUGFS_ADD(hw_queues
);
773 if (sdata
->vif
.type
!= NL80211_IFTYPE_P2P_DEVICE
&&
774 sdata
->vif
.type
!= NL80211_IFTYPE_NAN
)
778 static void add_sta_files(struct ieee80211_sub_if_data
*sdata
)
782 DEBUGFS_ADD(beacon_timeout
);
783 DEBUGFS_ADD_MODE(tkip_mic_test
, 0200);
784 DEBUGFS_ADD_MODE(beacon_loss
, 0200);
785 DEBUGFS_ADD_MODE(uapsd_queues
, 0600);
786 DEBUGFS_ADD_MODE(uapsd_max_sp_len
, 0600);
787 DEBUGFS_ADD_MODE(tdls_wider_bw
, 0600);
788 DEBUGFS_ADD_MODE(valid_links
, 0400);
789 DEBUGFS_ADD_MODE(active_links
, 0600);
790 DEBUGFS_ADD_X16(dormant_links
, 0400);
793 static void add_ap_files(struct ieee80211_sub_if_data
*sdata
)
795 DEBUGFS_ADD(num_mcast_sta
);
796 DEBUGFS_ADD(num_sta_ps
);
797 DEBUGFS_ADD(dtim_count
);
798 DEBUGFS_ADD(num_buffered_multicast
);
799 DEBUGFS_ADD_MODE(tkip_mic_test
, 0200);
800 DEBUGFS_ADD_MODE(multicast_to_unicast
, 0600);
803 static void add_vlan_files(struct ieee80211_sub_if_data
*sdata
)
805 /* add num_mcast_sta_vlan using name num_mcast_sta */
806 debugfs_create_file("num_mcast_sta", 0400, sdata
->vif
.debugfs_dir
,
807 sdata
, &num_mcast_sta_vlan_ops
);
810 static void add_ibss_files(struct ieee80211_sub_if_data
*sdata
)
812 DEBUGFS_ADD_MODE(tsf
, 0600);
815 #ifdef CONFIG_MAC80211_MESH
817 static void add_mesh_files(struct ieee80211_sub_if_data
*sdata
)
819 DEBUGFS_ADD_MODE(tsf
, 0600);
820 DEBUGFS_ADD_MODE(estab_plinks
, 0400);
823 static void add_mesh_stats(struct ieee80211_sub_if_data
*sdata
)
825 struct dentry
*dir
= debugfs_create_dir("mesh_stats",
826 sdata
->vif
.debugfs_dir
);
827 #define MESHSTATS_ADD(name)\
828 debugfs_create_file(#name, 0400, dir, sdata, &name##_ops)
830 MESHSTATS_ADD(fwded_mcast
);
831 MESHSTATS_ADD(fwded_unicast
);
832 MESHSTATS_ADD(fwded_frames
);
833 MESHSTATS_ADD(dropped_frames_ttl
);
834 MESHSTATS_ADD(dropped_frames_no_route
);
838 static void add_mesh_config(struct ieee80211_sub_if_data
*sdata
)
840 struct dentry
*dir
= debugfs_create_dir("mesh_config",
841 sdata
->vif
.debugfs_dir
);
843 #define MESHPARAMS_ADD(name) \
844 debugfs_create_file(#name, 0600, dir, sdata, &name##_ops)
846 MESHPARAMS_ADD(dot11MeshMaxRetries
);
847 MESHPARAMS_ADD(dot11MeshRetryTimeout
);
848 MESHPARAMS_ADD(dot11MeshConfirmTimeout
);
849 MESHPARAMS_ADD(dot11MeshHoldingTimeout
);
850 MESHPARAMS_ADD(dot11MeshTTL
);
851 MESHPARAMS_ADD(element_ttl
);
852 MESHPARAMS_ADD(auto_open_plinks
);
853 MESHPARAMS_ADD(dot11MeshMaxPeerLinks
);
854 MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout
);
855 MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval
);
856 MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval
);
857 MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime
);
858 MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries
);
859 MESHPARAMS_ADD(path_refresh_time
);
860 MESHPARAMS_ADD(min_discovery_timeout
);
861 MESHPARAMS_ADD(dot11MeshHWMPRootMode
);
862 MESHPARAMS_ADD(dot11MeshHWMPRannInterval
);
863 MESHPARAMS_ADD(dot11MeshForwarding
);
864 MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol
);
865 MESHPARAMS_ADD(rssi_threshold
);
866 MESHPARAMS_ADD(ht_opmode
);
867 MESHPARAMS_ADD(dot11MeshHWMPactivePathToRootTimeout
);
868 MESHPARAMS_ADD(dot11MeshHWMProotInterval
);
869 MESHPARAMS_ADD(dot11MeshHWMPconfirmationInterval
);
870 MESHPARAMS_ADD(power_mode
);
871 MESHPARAMS_ADD(dot11MeshAwakeWindowDuration
);
872 MESHPARAMS_ADD(dot11MeshConnectedToMeshGate
);
873 MESHPARAMS_ADD(dot11MeshNolearn
);
874 MESHPARAMS_ADD(dot11MeshConnectedToAuthServer
);
875 #undef MESHPARAMS_ADD
879 static void add_files(struct ieee80211_sub_if_data
*sdata
)
881 if (!sdata
->vif
.debugfs_dir
)
887 if (sdata
->vif
.type
!= NL80211_IFTYPE_MONITOR
)
888 add_common_files(sdata
);
890 switch (sdata
->vif
.type
) {
891 case NL80211_IFTYPE_MESH_POINT
:
892 #ifdef CONFIG_MAC80211_MESH
893 add_mesh_files(sdata
);
894 add_mesh_stats(sdata
);
895 add_mesh_config(sdata
);
898 case NL80211_IFTYPE_STATION
:
899 add_sta_files(sdata
);
901 case NL80211_IFTYPE_ADHOC
:
902 add_ibss_files(sdata
);
904 case NL80211_IFTYPE_AP
:
907 case NL80211_IFTYPE_AP_VLAN
:
908 add_vlan_files(sdata
);
915 #undef DEBUGFS_ADD_MODE
918 #define DEBUGFS_ADD_MODE(dentry, name, mode) \
919 debugfs_create_file(#name, mode, dentry, \
920 link, &link_##name##_ops)
922 #define DEBUGFS_ADD(dentry, name) DEBUGFS_ADD_MODE(dentry, name, 0400)
924 static void add_link_files(struct ieee80211_link_data
*link
,
925 struct dentry
*dentry
)
927 DEBUGFS_ADD(dentry
, txpower
);
928 DEBUGFS_ADD(dentry
, user_power_level
);
929 DEBUGFS_ADD(dentry
, ap_power_level
);
931 switch (link
->sdata
->vif
.type
) {
932 case NL80211_IFTYPE_STATION
:
933 DEBUGFS_ADD_MODE(dentry
, smps
, 0600);
940 void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data
*sdata
,
943 char buf
[10+IFNAMSIZ
];
945 sprintf(buf
, "netdev:%s", sdata
->name
);
946 sdata
->vif
.debugfs_dir
= debugfs_create_dir(buf
,
947 sdata
->local
->hw
.wiphy
->debugfsdir
);
948 /* deflink also has this */
949 sdata
->deflink
.debugfs_dir
= sdata
->vif
.debugfs_dir
;
950 sdata
->debugfs
.subdir_stations
= debugfs_create_dir("stations",
951 sdata
->vif
.debugfs_dir
);
954 add_link_files(&sdata
->deflink
, sdata
->vif
.debugfs_dir
);
957 void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data
*sdata
)
959 if (!sdata
->vif
.debugfs_dir
)
962 debugfs_remove_recursive(sdata
->vif
.debugfs_dir
);
963 sdata
->vif
.debugfs_dir
= NULL
;
964 sdata
->debugfs
.subdir_stations
= NULL
;
967 void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data
*sdata
)
970 char buf
[10 + IFNAMSIZ
];
972 dir
= sdata
->vif
.debugfs_dir
;
974 if (IS_ERR_OR_NULL(dir
))
977 sprintf(buf
, "netdev:%s", sdata
->name
);
978 debugfs_rename(dir
->d_parent
, dir
, dir
->d_parent
, buf
);
981 void ieee80211_debugfs_recreate_netdev(struct ieee80211_sub_if_data
*sdata
,
984 ieee80211_debugfs_remove_netdev(sdata
);
985 ieee80211_debugfs_add_netdev(sdata
, mld_vif
);
986 drv_vif_add_debugfs(sdata
->local
, sdata
);
988 ieee80211_link_debugfs_drv_add(&sdata
->deflink
);
991 void ieee80211_link_debugfs_add(struct ieee80211_link_data
*link
)
993 char link_dir_name
[10];
995 if (WARN_ON(!link
->sdata
->vif
.debugfs_dir
|| link
->debugfs_dir
))
998 /* For now, this should not be called for non-MLO capable drivers */
999 if (WARN_ON(!(link
->sdata
->local
->hw
.wiphy
->flags
& WIPHY_FLAG_SUPPORTS_MLO
)))
1002 snprintf(link_dir_name
, sizeof(link_dir_name
),
1003 "link-%d", link
->link_id
);
1006 debugfs_create_dir(link_dir_name
,
1007 link
->sdata
->vif
.debugfs_dir
);
1009 DEBUGFS_ADD(link
->debugfs_dir
, addr
);
1010 add_link_files(link
, link
->debugfs_dir
);
1013 void ieee80211_link_debugfs_remove(struct ieee80211_link_data
*link
)
1015 if (!link
->sdata
->vif
.debugfs_dir
|| !link
->debugfs_dir
) {
1016 link
->debugfs_dir
= NULL
;
1020 if (link
->debugfs_dir
== link
->sdata
->vif
.debugfs_dir
) {
1021 WARN_ON(link
!= &link
->sdata
->deflink
);
1022 link
->debugfs_dir
= NULL
;
1026 debugfs_remove_recursive(link
->debugfs_dir
);
1027 link
->debugfs_dir
= NULL
;
1030 void ieee80211_link_debugfs_drv_add(struct ieee80211_link_data
*link
)
1032 if (link
->sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
||
1033 WARN_ON(!link
->debugfs_dir
))
1036 drv_link_add_debugfs(link
->sdata
->local
, link
->sdata
,
1037 link
->conf
, link
->debugfs_dir
);
1040 void ieee80211_link_debugfs_drv_remove(struct ieee80211_link_data
*link
)
1042 if (!link
|| !link
->debugfs_dir
)
1045 if (WARN_ON(link
->debugfs_dir
== link
->sdata
->vif
.debugfs_dir
))
1048 /* Recreate the directory excluding the driver data */
1049 debugfs_remove_recursive(link
->debugfs_dir
);
1050 link
->debugfs_dir
= NULL
;
1052 ieee80211_link_debugfs_add(link
);