debugfs.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. };
  35. DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
  36. wiphy->rts_threshold)
  37. DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
  38. wiphy->frag_threshold);
  39. DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
  40. wiphy->retry_short)
  41. DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
  42. wiphy->retry_long);
  43. static int ht_print_chan(struct ieee80211_channel *chan,
  44. char *buf, int buf_size, int offset)
  45. {
  46. if (WARN_ON(offset > buf_size))
  47. return 0;
  48. if (chan->flags & IEEE80211_CHAN_DISABLED)
  49. return snprintf(buf + offset,
  50. buf_size - offset,
  51. "%d Disabled\n",
  52. chan->center_freq);
  53. return snprintf(buf + offset,
  54. buf_size - offset,
  55. "%d HT40 %c%c\n",
  56. chan->center_freq,
  57. (chan->flags & IEEE80211_CHAN_NO_HT40MINUS) ? ' ' : '-',
  58. (chan->flags & IEEE80211_CHAN_NO_HT40PLUS) ? ' ' : '+');
  59. }
  60. static ssize_t ht40allow_map_read(struct file *file,
  61. char __user *user_buf,
  62. size_t count, loff_t *ppos)
  63. {
  64. struct wiphy *wiphy = file->private_data;
  65. char *buf;
  66. unsigned int offset = 0, buf_size = PAGE_SIZE, i, r;
  67. enum ieee80211_band band;
  68. struct ieee80211_supported_band *sband;
  69. buf = kzalloc(buf_size, GFP_KERNEL);
  70. if (!buf)
  71. return -ENOMEM;
  72. mutex_lock(&cfg80211_mutex);
  73. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  74. sband = wiphy->bands[band];
  75. if (!sband)
  76. continue;
  77. for (i = 0; i < sband->n_channels; i++)
  78. offset += ht_print_chan(&sband->channels[i],
  79. buf, buf_size, offset);
  80. }
  81. mutex_unlock(&cfg80211_mutex);
  82. r = simple_read_from_buffer(user_buf, count, ppos, buf, offset);
  83. kfree(buf);
  84. return r;
  85. }
  86. static const struct file_operations ht40allow_map_ops = {
  87. .read = ht40allow_map_read,
  88. .open = cfg80211_open_file_generic,
  89. };
  90. #define DEBUGFS_ADD(name) \
  91. debugfs_create_file(#name, S_IRUGO, phyd, &rdev->wiphy, &name## _ops);
  92. void cfg80211_debugfs_rdev_add(struct cfg80211_registered_device *rdev)
  93. {
  94. struct dentry *phyd = rdev->wiphy.debugfsdir;
  95. DEBUGFS_ADD(rts_threshold);
  96. DEBUGFS_ADD(fragmentation_threshold);
  97. DEBUGFS_ADD(short_retry_limit);
  98. DEBUGFS_ADD(long_retry_limit);
  99. DEBUGFS_ADD(ht40allow_map);
  100. }