0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/slab.h>
0010 #include "core.h"
0011 #include "debugfs.h"
0012
0013 #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
0014 static ssize_t name## _read(struct file *file, char __user *userbuf, \
0015 size_t count, loff_t *ppos) \
0016 { \
0017 struct wiphy *wiphy = file->private_data; \
0018 char buf[buflen]; \
0019 int res; \
0020 \
0021 res = scnprintf(buf, buflen, fmt "\n", ##value); \
0022 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
0023 } \
0024 \
0025 static const struct file_operations name## _ops = { \
0026 .read = name## _read, \
0027 .open = simple_open, \
0028 .llseek = generic_file_llseek, \
0029 }
0030
0031 DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
0032 wiphy->rts_threshold);
0033 DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
0034 wiphy->frag_threshold);
0035 DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
0036 wiphy->retry_short);
0037 DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
0038 wiphy->retry_long);
0039
0040 static int ht_print_chan(struct ieee80211_channel *chan,
0041 char *buf, int buf_size, int offset)
0042 {
0043 if (WARN_ON(offset > buf_size))
0044 return 0;
0045
0046 if (chan->flags & IEEE80211_CHAN_DISABLED)
0047 return scnprintf(buf + offset,
0048 buf_size - offset,
0049 "%d Disabled\n",
0050 chan->center_freq);
0051
0052 return scnprintf(buf + offset,
0053 buf_size - offset,
0054 "%d HT40 %c%c\n",
0055 chan->center_freq,
0056 (chan->flags & IEEE80211_CHAN_NO_HT40MINUS) ?
0057 ' ' : '-',
0058 (chan->flags & IEEE80211_CHAN_NO_HT40PLUS) ?
0059 ' ' : '+');
0060 }
0061
0062 static ssize_t ht40allow_map_read(struct file *file,
0063 char __user *user_buf,
0064 size_t count, loff_t *ppos)
0065 {
0066 struct wiphy *wiphy = file->private_data;
0067 char *buf;
0068 unsigned int offset = 0, buf_size = PAGE_SIZE, i;
0069 enum nl80211_band band;
0070 struct ieee80211_supported_band *sband;
0071 ssize_t r;
0072
0073 buf = kzalloc(buf_size, GFP_KERNEL);
0074 if (!buf)
0075 return -ENOMEM;
0076
0077 for (band = 0; band < NUM_NL80211_BANDS; band++) {
0078 sband = wiphy->bands[band];
0079 if (!sband)
0080 continue;
0081 for (i = 0; i < sband->n_channels; i++)
0082 offset += ht_print_chan(&sband->channels[i],
0083 buf, buf_size, offset);
0084 }
0085
0086 r = simple_read_from_buffer(user_buf, count, ppos, buf, offset);
0087
0088 kfree(buf);
0089
0090 return r;
0091 }
0092
0093 static const struct file_operations ht40allow_map_ops = {
0094 .read = ht40allow_map_read,
0095 .open = simple_open,
0096 .llseek = default_llseek,
0097 };
0098
0099 #define DEBUGFS_ADD(name) \
0100 debugfs_create_file(#name, 0444, phyd, &rdev->wiphy, &name## _ops)
0101
0102 void cfg80211_debugfs_rdev_add(struct cfg80211_registered_device *rdev)
0103 {
0104 struct dentry *phyd = rdev->wiphy.debugfsdir;
0105
0106 DEBUGFS_ADD(rts_threshold);
0107 DEBUGFS_ADD(fragmentation_threshold);
0108 DEBUGFS_ADD(short_retry_limit);
0109 DEBUGFS_ADD(long_retry_limit);
0110 DEBUGFS_ADD(ht40allow_map);
0111 }