1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * cfg80211 debugfs
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright 2009 Luis R. Rodriguez <lrodriguez@atheros.com>
6*4882a593Smuzhiyun * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
7*4882a593Smuzhiyun */
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #include <linux/slab.h>
10*4882a593Smuzhiyun #include "core.h"
11*4882a593Smuzhiyun #include "debugfs.h"
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
14*4882a593Smuzhiyun static ssize_t name## _read(struct file *file, char __user *userbuf, \
15*4882a593Smuzhiyun size_t count, loff_t *ppos) \
16*4882a593Smuzhiyun { \
17*4882a593Smuzhiyun struct wiphy *wiphy = file->private_data; \
18*4882a593Smuzhiyun char buf[buflen]; \
19*4882a593Smuzhiyun int res; \
20*4882a593Smuzhiyun \
21*4882a593Smuzhiyun res = scnprintf(buf, buflen, fmt "\n", ##value); \
22*4882a593Smuzhiyun return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
23*4882a593Smuzhiyun } \
24*4882a593Smuzhiyun \
25*4882a593Smuzhiyun static const struct file_operations name## _ops = { \
26*4882a593Smuzhiyun .read = name## _read, \
27*4882a593Smuzhiyun .open = simple_open, \
28*4882a593Smuzhiyun .llseek = generic_file_llseek, \
29*4882a593Smuzhiyun }
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
32*4882a593Smuzhiyun wiphy->rts_threshold);
33*4882a593Smuzhiyun DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
34*4882a593Smuzhiyun wiphy->frag_threshold);
35*4882a593Smuzhiyun DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
36*4882a593Smuzhiyun wiphy->retry_short);
37*4882a593Smuzhiyun DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
38*4882a593Smuzhiyun wiphy->retry_long);
39*4882a593Smuzhiyun
ht_print_chan(struct ieee80211_channel * chan,char * buf,int buf_size,int offset)40*4882a593Smuzhiyun static int ht_print_chan(struct ieee80211_channel *chan,
41*4882a593Smuzhiyun char *buf, int buf_size, int offset)
42*4882a593Smuzhiyun {
43*4882a593Smuzhiyun if (WARN_ON(offset > buf_size))
44*4882a593Smuzhiyun return 0;
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun if (chan->flags & IEEE80211_CHAN_DISABLED)
47*4882a593Smuzhiyun return scnprintf(buf + offset,
48*4882a593Smuzhiyun buf_size - offset,
49*4882a593Smuzhiyun "%d Disabled\n",
50*4882a593Smuzhiyun chan->center_freq);
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun return scnprintf(buf + offset,
53*4882a593Smuzhiyun buf_size - offset,
54*4882a593Smuzhiyun "%d HT40 %c%c\n",
55*4882a593Smuzhiyun chan->center_freq,
56*4882a593Smuzhiyun (chan->flags & IEEE80211_CHAN_NO_HT40MINUS) ?
57*4882a593Smuzhiyun ' ' : '-',
58*4882a593Smuzhiyun (chan->flags & IEEE80211_CHAN_NO_HT40PLUS) ?
59*4882a593Smuzhiyun ' ' : '+');
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun
ht40allow_map_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)62*4882a593Smuzhiyun static ssize_t ht40allow_map_read(struct file *file,
63*4882a593Smuzhiyun char __user *user_buf,
64*4882a593Smuzhiyun size_t count, loff_t *ppos)
65*4882a593Smuzhiyun {
66*4882a593Smuzhiyun struct wiphy *wiphy = file->private_data;
67*4882a593Smuzhiyun char *buf;
68*4882a593Smuzhiyun unsigned int offset = 0, buf_size = PAGE_SIZE, i;
69*4882a593Smuzhiyun enum nl80211_band band;
70*4882a593Smuzhiyun struct ieee80211_supported_band *sband;
71*4882a593Smuzhiyun ssize_t r;
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun buf = kzalloc(buf_size, GFP_KERNEL);
74*4882a593Smuzhiyun if (!buf)
75*4882a593Smuzhiyun return -ENOMEM;
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun rtnl_lock();
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun for (band = 0; band < NUM_NL80211_BANDS; band++) {
80*4882a593Smuzhiyun sband = wiphy->bands[band];
81*4882a593Smuzhiyun if (!sband)
82*4882a593Smuzhiyun continue;
83*4882a593Smuzhiyun for (i = 0; i < sband->n_channels; i++)
84*4882a593Smuzhiyun offset += ht_print_chan(&sband->channels[i],
85*4882a593Smuzhiyun buf, buf_size, offset);
86*4882a593Smuzhiyun }
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun rtnl_unlock();
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun r = simple_read_from_buffer(user_buf, count, ppos, buf, offset);
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun kfree(buf);
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun return r;
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun static const struct file_operations ht40allow_map_ops = {
98*4882a593Smuzhiyun .read = ht40allow_map_read,
99*4882a593Smuzhiyun .open = simple_open,
100*4882a593Smuzhiyun .llseek = default_llseek,
101*4882a593Smuzhiyun };
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun #define DEBUGFS_ADD(name) \
104*4882a593Smuzhiyun debugfs_create_file(#name, 0444, phyd, &rdev->wiphy, &name## _ops)
105*4882a593Smuzhiyun
cfg80211_debugfs_rdev_add(struct cfg80211_registered_device * rdev)106*4882a593Smuzhiyun void cfg80211_debugfs_rdev_add(struct cfg80211_registered_device *rdev)
107*4882a593Smuzhiyun {
108*4882a593Smuzhiyun struct dentry *phyd = rdev->wiphy.debugfsdir;
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun DEBUGFS_ADD(rts_threshold);
111*4882a593Smuzhiyun DEBUGFS_ADD(fragmentation_threshold);
112*4882a593Smuzhiyun DEBUGFS_ADD(short_retry_limit);
113*4882a593Smuzhiyun DEBUGFS_ADD(long_retry_limit);
114*4882a593Smuzhiyun DEBUGFS_ADD(ht40allow_map);
115*4882a593Smuzhiyun }
116