debugfs_sta.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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_OPS(name) \
  33. static const struct file_operations sta_ ##name## _ops = { \
  34. .read = sta_##name##_read, \
  35. .open = mac80211_open_file_generic, \
  36. }
  37. #define STA_FILE(name, field, format) \
  38. STA_READ_##format(name, field) \
  39. STA_OPS(name)
  40. STA_FILE(aid, sta.aid, D);
  41. STA_FILE(dev, sdata->dev->name, S);
  42. STA_FILE(rx_packets, rx_packets, LU);
  43. STA_FILE(tx_packets, tx_packets, LU);
  44. STA_FILE(rx_bytes, rx_bytes, LU);
  45. STA_FILE(tx_bytes, tx_bytes, LU);
  46. STA_FILE(rx_duplicates, num_duplicates, LU);
  47. STA_FILE(rx_fragments, rx_fragments, LU);
  48. STA_FILE(rx_dropped, rx_dropped, LU);
  49. STA_FILE(tx_fragments, tx_fragments, LU);
  50. STA_FILE(tx_filtered, tx_filtered_count, LU);
  51. STA_FILE(tx_retry_failed, tx_retry_failed, LU);
  52. STA_FILE(tx_retry_count, tx_retry_count, LU);
  53. STA_FILE(last_signal, last_signal, D);
  54. STA_FILE(last_qual, last_qual, D);
  55. STA_FILE(last_noise, last_noise, D);
  56. STA_FILE(wep_weak_iv_count, wep_weak_iv_count, LU);
  57. static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
  58. size_t count, loff_t *ppos)
  59. {
  60. char buf[100];
  61. struct sta_info *sta = file->private_data;
  62. u32 staflags = get_sta_flags(sta);
  63. int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s",
  64. staflags & WLAN_STA_AUTH ? "AUTH\n" : "",
  65. staflags & WLAN_STA_ASSOC ? "ASSOC\n" : "",
  66. staflags & WLAN_STA_PS ? "PS\n" : "",
  67. staflags & WLAN_STA_AUTHORIZED ? "AUTHORIZED\n" : "",
  68. staflags & WLAN_STA_SHORT_PREAMBLE ? "SHORT PREAMBLE\n" : "",
  69. staflags & WLAN_STA_WME ? "WME\n" : "",
  70. staflags & WLAN_STA_WDS ? "WDS\n" : "");
  71. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  72. }
  73. STA_OPS(flags);
  74. static ssize_t sta_num_ps_buf_frames_read(struct file *file,
  75. char __user *userbuf,
  76. size_t count, loff_t *ppos)
  77. {
  78. char buf[20];
  79. struct sta_info *sta = file->private_data;
  80. int res = scnprintf(buf, sizeof(buf), "%u\n",
  81. skb_queue_len(&sta->ps_tx_buf));
  82. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  83. }
  84. STA_OPS(num_ps_buf_frames);
  85. static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf,
  86. size_t count, loff_t *ppos)
  87. {
  88. char buf[20];
  89. struct sta_info *sta = file->private_data;
  90. int res = scnprintf(buf, sizeof(buf), "%d\n",
  91. jiffies_to_msecs(jiffies - sta->last_rx));
  92. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  93. }
  94. STA_OPS(inactive_ms);
  95. static ssize_t sta_last_seq_ctrl_read(struct file *file, char __user *userbuf,
  96. size_t count, loff_t *ppos)
  97. {
  98. char buf[15*NUM_RX_DATA_QUEUES], *p = buf;
  99. int i;
  100. struct sta_info *sta = file->private_data;
  101. for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
  102. p += scnprintf(p, sizeof(buf)+buf-p, "%x ",
  103. le16_to_cpu(sta->last_seq_ctrl[i]));
  104. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  105. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  106. }
  107. STA_OPS(last_seq_ctrl);
  108. static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
  109. size_t count, loff_t *ppos)
  110. {
  111. char buf[768], *p = buf;
  112. int i;
  113. struct sta_info *sta = file->private_data;
  114. p += scnprintf(p, sizeof(buf)+buf-p, "Agg state for STA is:\n");
  115. p += scnprintf(p, sizeof(buf)+buf-p, " STA next dialog_token is %d \n "
  116. "TIDs info is: \n TID :",
  117. (sta->ampdu_mlme.dialog_token_allocator + 1));
  118. for (i = 0; i < STA_TID_NUM; i++)
  119. p += scnprintf(p, sizeof(buf)+buf-p, "%5d", i);
  120. p += scnprintf(p, sizeof(buf)+buf-p, "\n RX :");
  121. for (i = 0; i < STA_TID_NUM; i++)
  122. p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
  123. sta->ampdu_mlme.tid_state_rx[i]);
  124. p += scnprintf(p, sizeof(buf)+buf-p, "\n DTKN:");
  125. for (i = 0; i < STA_TID_NUM; i++)
  126. p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
  127. sta->ampdu_mlme.tid_state_rx[i] ?
  128. sta->ampdu_mlme.tid_rx[i]->dialog_token : 0);
  129. p += scnprintf(p, sizeof(buf)+buf-p, "\n TX :");
  130. for (i = 0; i < STA_TID_NUM; i++)
  131. p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
  132. sta->ampdu_mlme.tid_state_tx[i]);
  133. p += scnprintf(p, sizeof(buf)+buf-p, "\n DTKN:");
  134. for (i = 0; i < STA_TID_NUM; i++)
  135. p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
  136. sta->ampdu_mlme.tid_state_tx[i] ?
  137. sta->ampdu_mlme.tid_tx[i]->dialog_token : 0);
  138. p += scnprintf(p, sizeof(buf)+buf-p, "\n SSN :");
  139. for (i = 0; i < STA_TID_NUM; i++)
  140. p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
  141. sta->ampdu_mlme.tid_state_tx[i] ?
  142. sta->ampdu_mlme.tid_tx[i]->ssn : 0);
  143. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  144. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  145. }
  146. STA_OPS(agg_status);
  147. #define DEBUGFS_ADD(name) \
  148. sta->debugfs.name = debugfs_create_file(#name, 0400, \
  149. sta->debugfs.dir, sta, &sta_ ##name## _ops);
  150. #define DEBUGFS_DEL(name) \
  151. debugfs_remove(sta->debugfs.name);\
  152. sta->debugfs.name = NULL;
  153. void ieee80211_sta_debugfs_add(struct sta_info *sta)
  154. {
  155. struct dentry *stations_dir = sta->local->debugfs.stations;
  156. u8 mac[3*ETH_ALEN];
  157. sta->debugfs.add_has_run = true;
  158. if (!stations_dir)
  159. return;
  160. snprintf(mac, sizeof(mac), "%pM", sta->sta.addr);
  161. /*
  162. * This might fail due to a race condition:
  163. * When mac80211 unlinks a station, the debugfs entries
  164. * remain, but it is already possible to link a new
  165. * station with the same address which triggers adding
  166. * it to debugfs; therefore, if the old station isn't
  167. * destroyed quickly enough the old station's debugfs
  168. * dir might still be around.
  169. */
  170. sta->debugfs.dir = debugfs_create_dir(mac, stations_dir);
  171. if (!sta->debugfs.dir)
  172. return;
  173. DEBUGFS_ADD(flags);
  174. DEBUGFS_ADD(num_ps_buf_frames);
  175. DEBUGFS_ADD(inactive_ms);
  176. DEBUGFS_ADD(last_seq_ctrl);
  177. DEBUGFS_ADD(agg_status);
  178. }
  179. void ieee80211_sta_debugfs_remove(struct sta_info *sta)
  180. {
  181. DEBUGFS_DEL(flags);
  182. DEBUGFS_DEL(num_ps_buf_frames);
  183. DEBUGFS_DEL(inactive_ms);
  184. DEBUGFS_DEL(last_seq_ctrl);
  185. DEBUGFS_DEL(agg_status);
  186. debugfs_remove(sta->debugfs.dir);
  187. sta->debugfs.dir = NULL;
  188. }