debugfs_sta.c 7.7 KB

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