debugfs_sta.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * Copyright 2003-2005 Devicescape Software, Inc.
  3. * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
  4. * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/debugfs.h>
  11. #include <linux/ieee80211.h>
  12. #include "ieee80211_i.h"
  13. #include "debugfs.h"
  14. #include "debugfs_sta.h"
  15. #include "sta_info.h"
  16. /* sta attributtes */
  17. #define STA_READ(name, buflen, field, format_string) \
  18. static ssize_t sta_ ##name## _read(struct file *file, \
  19. char __user *userbuf, \
  20. size_t count, loff_t *ppos) \
  21. { \
  22. int res; \
  23. struct sta_info *sta = file->private_data; \
  24. char buf[buflen]; \
  25. res = scnprintf(buf, buflen, format_string, sta->field); \
  26. return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
  27. }
  28. #define STA_READ_D(name, field) STA_READ(name, 20, field, "%d\n")
  29. #define STA_READ_U(name, field) STA_READ(name, 20, field, "%u\n")
  30. #define STA_READ_LU(name, field) STA_READ(name, 20, field, "%lu\n")
  31. #define STA_READ_S(name, field) STA_READ(name, 20, field, "%s\n")
  32. #define STA_READ_RATE(name, field) \
  33. static ssize_t sta_##name##_read(struct file *file, \
  34. char __user *userbuf, \
  35. size_t count, loff_t *ppos) \
  36. { \
  37. struct sta_info *sta = file->private_data; \
  38. struct ieee80211_local *local = wdev_priv(sta->dev->ieee80211_ptr);\
  39. struct ieee80211_hw_mode *mode = local->oper_hw_mode; \
  40. char buf[20]; \
  41. int res = scnprintf(buf, sizeof(buf), "%d\n", \
  42. (sta->field >= 0 && \
  43. sta->field < mode->num_rates) ? \
  44. mode->rates[sta->field].rate : -1); \
  45. return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
  46. }
  47. #define STA_OPS(name) \
  48. static const struct file_operations sta_ ##name## _ops = { \
  49. .read = sta_##name##_read, \
  50. .open = mac80211_open_file_generic, \
  51. }
  52. #define STA_FILE(name, field, format) \
  53. STA_READ_##format(name, field) \
  54. STA_OPS(name)
  55. STA_FILE(aid, aid, D);
  56. STA_FILE(dev, dev->name, S);
  57. STA_FILE(rx_packets, rx_packets, LU);
  58. STA_FILE(tx_packets, tx_packets, LU);
  59. STA_FILE(rx_bytes, rx_bytes, LU);
  60. STA_FILE(tx_bytes, tx_bytes, LU);
  61. STA_FILE(rx_duplicates, num_duplicates, LU);
  62. STA_FILE(rx_fragments, rx_fragments, LU);
  63. STA_FILE(rx_dropped, rx_dropped, LU);
  64. STA_FILE(tx_fragments, tx_fragments, LU);
  65. STA_FILE(tx_filtered, tx_filtered_count, LU);
  66. STA_FILE(txrate, txrate, RATE);
  67. STA_FILE(last_txrate, last_txrate, RATE);
  68. STA_FILE(tx_retry_failed, tx_retry_failed, LU);
  69. STA_FILE(tx_retry_count, tx_retry_count, LU);
  70. STA_FILE(last_rssi, last_rssi, D);
  71. STA_FILE(last_signal, last_signal, D);
  72. STA_FILE(last_noise, last_noise, D);
  73. STA_FILE(channel_use, channel_use, D);
  74. STA_FILE(wep_weak_iv_count, wep_weak_iv_count, D);
  75. static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
  76. size_t count, loff_t *ppos)
  77. {
  78. char buf[100];
  79. struct sta_info *sta = file->private_data;
  80. int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s",
  81. sta->flags & WLAN_STA_AUTH ? "AUTH\n" : "",
  82. sta->flags & WLAN_STA_ASSOC ? "ASSOC\n" : "",
  83. sta->flags & WLAN_STA_PS ? "PS\n" : "",
  84. sta->flags & WLAN_STA_TIM ? "TIM\n" : "",
  85. sta->flags & WLAN_STA_PERM ? "PERM\n" : "",
  86. sta->flags & WLAN_STA_AUTHORIZED ? "AUTHORIZED\n" : "",
  87. sta->flags & WLAN_STA_SHORT_PREAMBLE ? "SHORT PREAMBLE\n" : "",
  88. sta->flags & WLAN_STA_WME ? "WME\n" : "",
  89. sta->flags & WLAN_STA_WDS ? "WDS\n" : "");
  90. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  91. }
  92. STA_OPS(flags);
  93. static ssize_t sta_num_ps_buf_frames_read(struct file *file,
  94. char __user *userbuf,
  95. size_t count, loff_t *ppos)
  96. {
  97. char buf[20];
  98. struct sta_info *sta = file->private_data;
  99. int res = scnprintf(buf, sizeof(buf), "%u\n",
  100. skb_queue_len(&sta->ps_tx_buf));
  101. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  102. }
  103. STA_OPS(num_ps_buf_frames);
  104. static ssize_t sta_last_ack_rssi_read(struct file *file, char __user *userbuf,
  105. size_t count, loff_t *ppos)
  106. {
  107. char buf[100];
  108. struct sta_info *sta = file->private_data;
  109. int res = scnprintf(buf, sizeof(buf), "%d %d %d\n",
  110. sta->last_ack_rssi[0],
  111. sta->last_ack_rssi[1],
  112. sta->last_ack_rssi[2]);
  113. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  114. }
  115. STA_OPS(last_ack_rssi);
  116. static ssize_t sta_last_ack_ms_read(struct file *file, char __user *userbuf,
  117. size_t count, loff_t *ppos)
  118. {
  119. char buf[20];
  120. struct sta_info *sta = file->private_data;
  121. int res = scnprintf(buf, sizeof(buf), "%d\n",
  122. sta->last_ack ?
  123. jiffies_to_msecs(jiffies - sta->last_ack) : -1);
  124. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  125. }
  126. STA_OPS(last_ack_ms);
  127. static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf,
  128. size_t count, loff_t *ppos)
  129. {
  130. char buf[20];
  131. struct sta_info *sta = file->private_data;
  132. int res = scnprintf(buf, sizeof(buf), "%d\n",
  133. jiffies_to_msecs(jiffies - sta->last_rx));
  134. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  135. }
  136. STA_OPS(inactive_ms);
  137. static ssize_t sta_last_seq_ctrl_read(struct file *file, char __user *userbuf,
  138. size_t count, loff_t *ppos)
  139. {
  140. char buf[15*NUM_RX_DATA_QUEUES], *p = buf;
  141. int i;
  142. struct sta_info *sta = file->private_data;
  143. for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
  144. p += scnprintf(p, sizeof(buf)+buf-p, "%x ",
  145. le16_to_cpu(sta->last_seq_ctrl[i]));
  146. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  147. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  148. }
  149. STA_OPS(last_seq_ctrl);
  150. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  151. static ssize_t sta_wme_rx_queue_read(struct file *file, char __user *userbuf,
  152. size_t count, loff_t *ppos)
  153. {
  154. char buf[15*NUM_RX_DATA_QUEUES], *p = buf;
  155. int i;
  156. struct sta_info *sta = file->private_data;
  157. for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
  158. p += scnprintf(p, sizeof(buf)+buf-p, "%u ",
  159. sta->wme_rx_queue[i]);
  160. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  161. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  162. }
  163. STA_OPS(wme_rx_queue);
  164. static ssize_t sta_wme_tx_queue_read(struct file *file, char __user *userbuf,
  165. size_t count, loff_t *ppos)
  166. {
  167. char buf[15*NUM_TX_DATA_QUEUES], *p = buf;
  168. int i;
  169. struct sta_info *sta = file->private_data;
  170. for (i = 0; i < NUM_TX_DATA_QUEUES; i++)
  171. p += scnprintf(p, sizeof(buf)+buf-p, "%u ",
  172. sta->wme_tx_queue[i]);
  173. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  174. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  175. }
  176. STA_OPS(wme_tx_queue);
  177. #endif
  178. #define DEBUGFS_ADD(name) \
  179. sta->debugfs.name = debugfs_create_file(#name, 0444, \
  180. sta->debugfs.dir, sta, &sta_ ##name## _ops);
  181. #define DEBUGFS_DEL(name) \
  182. debugfs_remove(sta->debugfs.name);\
  183. sta->debugfs.name = NULL;
  184. void ieee80211_sta_debugfs_add(struct sta_info *sta)
  185. {
  186. struct dentry *stations_dir = sta->local->debugfs.stations;
  187. DECLARE_MAC_BUF(mac);
  188. if (!stations_dir)
  189. return;
  190. print_mac(mac, sta->addr);
  191. sta->debugfs.dir = debugfs_create_dir(mac, stations_dir);
  192. if (!sta->debugfs.dir)
  193. return;
  194. DEBUGFS_ADD(flags);
  195. DEBUGFS_ADD(num_ps_buf_frames);
  196. DEBUGFS_ADD(last_ack_rssi);
  197. DEBUGFS_ADD(last_ack_ms);
  198. DEBUGFS_ADD(inactive_ms);
  199. DEBUGFS_ADD(last_seq_ctrl);
  200. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  201. DEBUGFS_ADD(wme_rx_queue);
  202. DEBUGFS_ADD(wme_tx_queue);
  203. #endif
  204. }
  205. void ieee80211_sta_debugfs_remove(struct sta_info *sta)
  206. {
  207. DEBUGFS_DEL(flags);
  208. DEBUGFS_DEL(num_ps_buf_frames);
  209. DEBUGFS_DEL(last_ack_rssi);
  210. DEBUGFS_DEL(last_ack_ms);
  211. DEBUGFS_DEL(inactive_ms);
  212. DEBUGFS_DEL(last_seq_ctrl);
  213. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  214. DEBUGFS_DEL(wme_rx_queue);
  215. DEBUGFS_DEL(wme_tx_queue);
  216. #endif
  217. debugfs_remove(sta->debugfs.dir);
  218. sta->debugfs.dir = NULL;
  219. }