debugfs.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * cfg80211 debugfs
  3. *
  4. * Copyright 2009 Luis R. Rodriguez <lrodriguez@atheros.com>
  5. * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/slab.h>
  12. #include "core.h"
  13. #include "debugfs.h"
  14. static int cfg80211_open_file_generic(struct inode *inode, struct file *file)
  15. {
  16. file->private_data = inode->i_private;
  17. return 0;
  18. }
  19. #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
  20. static ssize_t name## _read(struct file *file, char __user *userbuf, \
  21. size_t count, loff_t *ppos) \
  22. { \
  23. struct wiphy *wiphy= file->private_data; \
  24. char buf[buflen]; \
  25. int res; \
  26. \
  27. res = scnprintf(buf, buflen, fmt "\n", ##value); \
  28. return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
  29. } \
  30. \
  31. static const struct file_operations name## _ops = { \
  32. .read = name## _read, \
  33. .open = cfg80211_open_file_generic, \
  34. .llseek = generic_file_llseek, \
  35. };
  36. DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
  37. wiphy->rts_threshold)
  38. DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
  39. wiphy->frag_threshold);
  40. DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
  41. wiphy->retry_short)
  42. DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
  43. wiphy->retry_long);
  44. static int ht_print_chan(struct ieee80211_channel *chan,
  45. char *buf, int buf_size, int offset)
  46. {
  47. if (WARN_ON(offset > buf_size))
  48. return 0;
  49. if (chan->flags & IEEE80211_CHAN_DISABLED)
  50. return snprintf(buf + offset,
  51. buf_size - offset,
  52. "%d Disabled\n",
  53. chan->center_freq);
  54. return snprintf(buf + offset,
  55. buf_size - offset,
  56. "%d HT40 %c%c\n",
  57. chan->center_freq,
  58. (chan->flags & IEEE80211_CHAN_NO_HT40MINUS) ? ' ' : '-',
  59. (chan->flags & IEEE80211_CHAN_NO_HT40PLUS) ? ' ' : '+');
  60. }
  61. static ssize_t ht40allow_map_read(struct file *file,
  62. char __user *user_buf,
  63. size_t count, loff_t *ppos)
  64. {
  65. struct wiphy *wiphy = file->private_data;
  66. char *buf;
  67. unsigned int offset = 0, buf_size = PAGE_SIZE, i, r;
  68. enum ieee80211_band band;
  69. struct ieee80211_supported_band *sband;
  70. buf = kzalloc(buf_size, GFP_KERNEL);
  71. if (!buf)
  72. return -ENOMEM;
  73. mutex_lock(&cfg80211_mutex);
  74. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  75. sband = wiphy->bands[band];
  76. if (!sband)
  77. continue;
  78. for (i = 0; i < sband->n_channels; i++)
  79. offset += ht_print_chan(&sband->channels[i],
  80. buf, buf_size, offset);
  81. }
  82. mutex_unlock(&cfg80211_mutex);
  83. r = simple_read_from_buffer(user_buf, count, ppos, buf, offset);
  84. kfree(buf);
  85. return r;
  86. }
  87. static const struct file_operations ht40allow_map_ops = {
  88. .read = ht40allow_map_read,
  89. .open = cfg80211_open_file_generic,
  90. .llseek = default_llseek,
  91. };
  92. #define DEBUGFS_ADD(name) \
  93. debugfs_create_file(#name, S_IRUGO, phyd, &rdev->wiphy, &name## _ops);
  94. void cfg80211_debugfs_rdev_add(struct cfg80211_registered_device *rdev)
  95. {
  96. struct dentry *phyd = rdev->wiphy.debugfsdir;
  97. DEBUGFS_ADD(rts_threshold);
  98. DEBUGFS_ADD(fragmentation_threshold);
  99. DEBUGFS_ADD(short_retry_limit);
  100. DEBUGFS_ADD(long_retry_limit);
  101. DEBUGFS_ADD(ht40allow_map);
  102. }