debugfs.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 "core.h"
  12. #include "debugfs.h"
  13. static int cfg80211_open_file_generic(struct inode *inode, struct file *file)
  14. {
  15. file->private_data = inode->i_private;
  16. return 0;
  17. }
  18. #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
  19. static ssize_t name## _read(struct file *file, char __user *userbuf, \
  20. size_t count, loff_t *ppos) \
  21. { \
  22. struct wiphy *wiphy= file->private_data; \
  23. char buf[buflen]; \
  24. int res; \
  25. \
  26. res = scnprintf(buf, buflen, fmt "\n", ##value); \
  27. return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
  28. } \
  29. \
  30. static const struct file_operations name## _ops = { \
  31. .read = name## _read, \
  32. .open = cfg80211_open_file_generic, \
  33. };
  34. DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
  35. wiphy->rts_threshold)
  36. DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
  37. wiphy->frag_threshold);
  38. DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
  39. wiphy->retry_short)
  40. DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
  41. wiphy->retry_long);
  42. static int ht_print_chan(struct ieee80211_channel *chan,
  43. char *buf, int buf_size, int offset)
  44. {
  45. if (WARN_ON(offset > buf_size))
  46. return 0;
  47. if (chan->flags & IEEE80211_CHAN_DISABLED)
  48. return snprintf(buf + offset,
  49. buf_size - offset,
  50. "%d Disabled\n",
  51. chan->center_freq);
  52. return snprintf(buf + offset,
  53. buf_size - offset,
  54. "%d HT40 %c%c\n",
  55. chan->center_freq,
  56. (chan->flags & IEEE80211_CHAN_NO_HT40MINUS) ? ' ' : '-',
  57. (chan->flags & IEEE80211_CHAN_NO_HT40PLUS) ? ' ' : '+');
  58. }
  59. static ssize_t ht40allow_map_read(struct file *file,
  60. char __user *user_buf,
  61. size_t count, loff_t *ppos)
  62. {
  63. struct wiphy *wiphy = file->private_data;
  64. char *buf;
  65. unsigned int offset = 0, buf_size = PAGE_SIZE, i, r;
  66. enum ieee80211_band band;
  67. struct ieee80211_supported_band *sband;
  68. buf = kzalloc(buf_size, GFP_KERNEL);
  69. if (!buf)
  70. return -ENOMEM;
  71. mutex_lock(&cfg80211_mutex);
  72. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  73. sband = wiphy->bands[band];
  74. if (!sband)
  75. continue;
  76. for (i = 0; i < sband->n_channels; i++)
  77. offset += ht_print_chan(&sband->channels[i],
  78. buf, buf_size, offset);
  79. }
  80. mutex_unlock(&cfg80211_mutex);
  81. r = simple_read_from_buffer(user_buf, count, ppos, buf, offset);
  82. kfree(buf);
  83. return r;
  84. }
  85. static const struct file_operations ht40allow_map_ops = {
  86. .read = ht40allow_map_read,
  87. .open = cfg80211_open_file_generic,
  88. };
  89. #define DEBUGFS_ADD(name) \
  90. drv->debugfs.name = debugfs_create_file(#name, S_IRUGO, phyd, \
  91. &drv->wiphy, &name## _ops);
  92. #define DEBUGFS_DEL(name) \
  93. debugfs_remove(drv->debugfs.name); \
  94. drv->debugfs.name = NULL;
  95. void cfg80211_debugfs_drv_add(struct cfg80211_registered_device *drv)
  96. {
  97. struct dentry *phyd = drv->wiphy.debugfsdir;
  98. DEBUGFS_ADD(rts_threshold);
  99. DEBUGFS_ADD(fragmentation_threshold);
  100. DEBUGFS_ADD(short_retry_limit);
  101. DEBUGFS_ADD(long_retry_limit);
  102. DEBUGFS_ADD(ht40allow_map);
  103. }
  104. void cfg80211_debugfs_drv_del(struct cfg80211_registered_device *drv)
  105. {
  106. DEBUGFS_DEL(rts_threshold);
  107. DEBUGFS_DEL(fragmentation_threshold);
  108. DEBUGFS_DEL(short_retry_limit);
  109. DEBUGFS_DEL(long_retry_limit);
  110. DEBUGFS_DEL(ht40allow_map);
  111. }