debugfs.c 3.0 KB

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