debugfs.c 2.9 KB

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