debugfs_sta.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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(key_idx_compression, key_idx_compression, D);
  57. STA_FILE(dev, dev->name, S);
  58. STA_FILE(vlan_id, vlan_id, D);
  59. STA_FILE(rx_packets, rx_packets, LU);
  60. STA_FILE(tx_packets, tx_packets, LU);
  61. STA_FILE(rx_bytes, rx_bytes, LU);
  62. STA_FILE(tx_bytes, tx_bytes, LU);
  63. STA_FILE(rx_duplicates, num_duplicates, LU);
  64. STA_FILE(rx_fragments, rx_fragments, LU);
  65. STA_FILE(rx_dropped, rx_dropped, LU);
  66. STA_FILE(tx_fragments, tx_fragments, LU);
  67. STA_FILE(tx_filtered, tx_filtered_count, LU);
  68. STA_FILE(txrate, txrate, RATE);
  69. STA_FILE(last_txrate, last_txrate, RATE);
  70. STA_FILE(tx_retry_failed, tx_retry_failed, LU);
  71. STA_FILE(tx_retry_count, tx_retry_count, LU);
  72. STA_FILE(last_rssi, last_rssi, D);
  73. STA_FILE(last_signal, last_signal, D);
  74. STA_FILE(last_noise, last_noise, D);
  75. STA_FILE(channel_use, channel_use, D);
  76. STA_FILE(wep_weak_iv_count, wep_weak_iv_count, D);
  77. static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
  78. size_t count, loff_t *ppos)
  79. {
  80. char buf[100];
  81. struct sta_info *sta = file->private_data;
  82. int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s",
  83. sta->flags & WLAN_STA_AUTH ? "AUTH\n" : "",
  84. sta->flags & WLAN_STA_ASSOC ? "ASSOC\n" : "",
  85. sta->flags & WLAN_STA_PS ? "PS\n" : "",
  86. sta->flags & WLAN_STA_TIM ? "TIM\n" : "",
  87. sta->flags & WLAN_STA_PERM ? "PERM\n" : "",
  88. sta->flags & WLAN_STA_AUTHORIZED ? "AUTHORIZED\n" : "",
  89. sta->flags & WLAN_STA_SHORT_PREAMBLE ? "SHORT PREAMBLE\n" : "",
  90. sta->flags & WLAN_STA_WME ? "WME\n" : "",
  91. sta->flags & WLAN_STA_WDS ? "WDS\n" : "");
  92. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  93. }
  94. STA_OPS(flags);
  95. static ssize_t sta_num_ps_buf_frames_read(struct file *file,
  96. char __user *userbuf,
  97. size_t count, loff_t *ppos)
  98. {
  99. char buf[20];
  100. struct sta_info *sta = file->private_data;
  101. int res = scnprintf(buf, sizeof(buf), "%u\n",
  102. skb_queue_len(&sta->ps_tx_buf));
  103. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  104. }
  105. STA_OPS(num_ps_buf_frames);
  106. static ssize_t sta_last_ack_rssi_read(struct file *file, char __user *userbuf,
  107. size_t count, loff_t *ppos)
  108. {
  109. char buf[100];
  110. struct sta_info *sta = file->private_data;
  111. int res = scnprintf(buf, sizeof(buf), "%d %d %d\n",
  112. sta->last_ack_rssi[0],
  113. sta->last_ack_rssi[1],
  114. sta->last_ack_rssi[2]);
  115. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  116. }
  117. STA_OPS(last_ack_rssi);
  118. static ssize_t sta_last_ack_ms_read(struct file *file, char __user *userbuf,
  119. size_t count, loff_t *ppos)
  120. {
  121. char buf[20];
  122. struct sta_info *sta = file->private_data;
  123. int res = scnprintf(buf, sizeof(buf), "%d\n",
  124. sta->last_ack ?
  125. jiffies_to_msecs(jiffies - sta->last_ack) : -1);
  126. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  127. }
  128. STA_OPS(last_ack_ms);
  129. static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf,
  130. size_t count, loff_t *ppos)
  131. {
  132. char buf[20];
  133. struct sta_info *sta = file->private_data;
  134. int res = scnprintf(buf, sizeof(buf), "%d\n",
  135. jiffies_to_msecs(jiffies - sta->last_rx));
  136. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  137. }
  138. STA_OPS(inactive_ms);
  139. static ssize_t sta_last_seq_ctrl_read(struct file *file, char __user *userbuf,
  140. size_t count, loff_t *ppos)
  141. {
  142. char buf[15*NUM_RX_DATA_QUEUES], *p = buf;
  143. int i;
  144. struct sta_info *sta = file->private_data;
  145. for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
  146. p += scnprintf(p, sizeof(buf)+buf-p, "%x ",
  147. sta->last_seq_ctrl[i]);
  148. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  149. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  150. }
  151. STA_OPS(last_seq_ctrl);
  152. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  153. static ssize_t sta_wme_rx_queue_read(struct file *file, char __user *userbuf,
  154. size_t count, loff_t *ppos)
  155. {
  156. char buf[15*NUM_RX_DATA_QUEUES], *p = buf;
  157. int i;
  158. struct sta_info *sta = file->private_data;
  159. for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
  160. p += scnprintf(p, sizeof(buf)+buf-p, "%u ",
  161. sta->wme_rx_queue[i]);
  162. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  163. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  164. }
  165. STA_OPS(wme_rx_queue);
  166. static ssize_t sta_wme_tx_queue_read(struct file *file, char __user *userbuf,
  167. size_t count, loff_t *ppos)
  168. {
  169. char buf[15*NUM_TX_DATA_QUEUES], *p = buf;
  170. int i;
  171. struct sta_info *sta = file->private_data;
  172. for (i = 0; i < NUM_TX_DATA_QUEUES; i++)
  173. p += scnprintf(p, sizeof(buf)+buf-p, "%u ",
  174. sta->wme_tx_queue[i]);
  175. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  176. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  177. }
  178. STA_OPS(wme_tx_queue);
  179. #endif
  180. #define DEBUGFS_ADD(name) \
  181. sta->debugfs.name = debugfs_create_file(#name, 0444, \
  182. sta->debugfs.dir, sta, &sta_ ##name## _ops);
  183. #define DEBUGFS_DEL(name) \
  184. debugfs_remove(sta->debugfs.name);\
  185. sta->debugfs.name = NULL;
  186. void ieee80211_sta_debugfs_add(struct sta_info *sta)
  187. {
  188. char buf[3*6];
  189. struct dentry *stations_dir = sta->local->debugfs.stations;
  190. if (!stations_dir)
  191. return;
  192. sprintf(buf, MAC_FMT, MAC_ARG(sta->addr));
  193. sta->debugfs.dir = debugfs_create_dir(buf, stations_dir);
  194. if (!sta->debugfs.dir)
  195. return;
  196. DEBUGFS_ADD(flags);
  197. DEBUGFS_ADD(num_ps_buf_frames);
  198. DEBUGFS_ADD(last_ack_rssi);
  199. DEBUGFS_ADD(last_ack_ms);
  200. DEBUGFS_ADD(inactive_ms);
  201. DEBUGFS_ADD(last_seq_ctrl);
  202. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  203. DEBUGFS_ADD(wme_rx_queue);
  204. DEBUGFS_ADD(wme_tx_queue);
  205. #endif
  206. }
  207. void ieee80211_sta_debugfs_remove(struct sta_info *sta)
  208. {
  209. DEBUGFS_DEL(flags);
  210. DEBUGFS_DEL(num_ps_buf_frames);
  211. DEBUGFS_DEL(last_ack_rssi);
  212. DEBUGFS_DEL(last_ack_ms);
  213. DEBUGFS_DEL(inactive_ms);
  214. DEBUGFS_DEL(last_seq_ctrl);
  215. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  216. DEBUGFS_DEL(wme_rx_queue);
  217. DEBUGFS_DEL(wme_tx_queue);
  218. #endif
  219. debugfs_remove(sta->debugfs.dir);
  220. sta->debugfs.dir = NULL;
  221. }