debugfs_sta.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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->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_noise, last_noise, D);
  55. STA_FILE(wep_weak_iv_count, wep_weak_iv_count, LU);
  56. static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
  57. size_t count, loff_t *ppos)
  58. {
  59. char buf[100];
  60. struct sta_info *sta = file->private_data;
  61. u32 staflags = get_sta_flags(sta);
  62. int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s",
  63. staflags & WLAN_STA_AUTH ? "AUTH\n" : "",
  64. staflags & WLAN_STA_ASSOC ? "ASSOC\n" : "",
  65. staflags & WLAN_STA_PS_STA ? "PS (sta)\n" : "",
  66. staflags & WLAN_STA_PS_DRIVER ? "PS (driver)\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. staflags & WLAN_STA_MFP ? "MFP\n" : "");
  72. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  73. }
  74. STA_OPS(flags);
  75. static ssize_t sta_num_ps_buf_frames_read(struct file *file,
  76. char __user *userbuf,
  77. size_t count, loff_t *ppos)
  78. {
  79. char buf[20];
  80. struct sta_info *sta = file->private_data;
  81. int res = scnprintf(buf, sizeof(buf), "%u\n",
  82. skb_queue_len(&sta->ps_tx_buf));
  83. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  84. }
  85. STA_OPS(num_ps_buf_frames);
  86. static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf,
  87. size_t count, loff_t *ppos)
  88. {
  89. char buf[20];
  90. struct sta_info *sta = file->private_data;
  91. int res = scnprintf(buf, sizeof(buf), "%d\n",
  92. jiffies_to_msecs(jiffies - sta->last_rx));
  93. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  94. }
  95. STA_OPS(inactive_ms);
  96. static ssize_t sta_last_seq_ctrl_read(struct file *file, char __user *userbuf,
  97. size_t count, loff_t *ppos)
  98. {
  99. char buf[15*NUM_RX_DATA_QUEUES], *p = buf;
  100. int i;
  101. struct sta_info *sta = file->private_data;
  102. for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
  103. p += scnprintf(p, sizeof(buf)+buf-p, "%x ",
  104. le16_to_cpu(sta->last_seq_ctrl[i]));
  105. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  106. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  107. }
  108. STA_OPS(last_seq_ctrl);
  109. static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
  110. size_t count, loff_t *ppos)
  111. {
  112. char buf[64 + STA_TID_NUM * 40], *p = buf;
  113. int i;
  114. struct sta_info *sta = file->private_data;
  115. spin_lock_bh(&sta->lock);
  116. p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
  117. sta->ampdu_mlme.dialog_token_allocator + 1);
  118. p += scnprintf(p, sizeof(buf) + buf - p,
  119. "TID\t\tRX\tDTKN\tSSN\t\tTX\tDTKN\tSSN\tpending\n");
  120. for (i = 0; i < STA_TID_NUM; i++) {
  121. p += scnprintf(p, sizeof(buf) + buf - p, "%02d", i);
  122. p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x",
  123. sta->ampdu_mlme.tid_state_rx[i]);
  124. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
  125. sta->ampdu_mlme.tid_state_rx[i] ?
  126. sta->ampdu_mlme.tid_rx[i]->dialog_token : 0);
  127. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.3x",
  128. sta->ampdu_mlme.tid_state_rx[i] ?
  129. sta->ampdu_mlme.tid_rx[i]->ssn : 0);
  130. p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x",
  131. sta->ampdu_mlme.tid_state_tx[i]);
  132. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
  133. sta->ampdu_mlme.tid_state_tx[i] ?
  134. sta->ampdu_mlme.tid_tx[i]->dialog_token : 0);
  135. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.3x",
  136. sta->ampdu_mlme.tid_state_tx[i] ?
  137. sta->ampdu_mlme.tid_tx[i]->ssn : 0);
  138. p += scnprintf(p, sizeof(buf) + buf - p, "\t%03d",
  139. sta->ampdu_mlme.tid_state_tx[i] ?
  140. skb_queue_len(&sta->ampdu_mlme.tid_tx[i]->pending) : 0);
  141. p += scnprintf(p, sizeof(buf) + buf - p, "\n");
  142. }
  143. spin_unlock_bh(&sta->lock);
  144. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  145. }
  146. STA_OPS(agg_status);
  147. static ssize_t sta_ht_capa_read(struct file *file, char __user *userbuf,
  148. size_t count, loff_t *ppos)
  149. {
  150. #define PRINT_HT_CAP(_cond, _str) \
  151. do { \
  152. if (_cond) \
  153. p += scnprintf(p, sizeof(buf)+buf-p, "\t" _str "\n"); \
  154. } while (0)
  155. char buf[512], *p = buf;
  156. int i;
  157. struct sta_info *sta = file->private_data;
  158. struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
  159. p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
  160. htc->ht_supported ? "" : "not ");
  161. if (htc->ht_supported) {
  162. p += scnprintf(p, sizeof(buf)+buf-p, "cap: %#.4x\n", htc->cap);
  163. PRINT_HT_CAP((htc->cap & BIT(0)), "RX LDCP");
  164. PRINT_HT_CAP((htc->cap & BIT(1)), "HT20/HT40");
  165. PRINT_HT_CAP(!(htc->cap & BIT(1)), "HT20");
  166. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 0, "Static SM Power Save");
  167. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 1, "Dynamic SM Power Save");
  168. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 3, "SM Power Save disabled");
  169. PRINT_HT_CAP((htc->cap & BIT(4)), "RX Greenfield");
  170. PRINT_HT_CAP((htc->cap & BIT(5)), "RX HT20 SGI");
  171. PRINT_HT_CAP((htc->cap & BIT(6)), "RX HT40 SGI");
  172. PRINT_HT_CAP((htc->cap & BIT(7)), "TX STBC");
  173. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 0, "No RX STBC");
  174. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 1, "RX STBC 1-stream");
  175. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 2, "RX STBC 2-streams");
  176. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 3, "RX STBC 3-streams");
  177. PRINT_HT_CAP((htc->cap & BIT(10)), "HT Delayed Block Ack");
  178. PRINT_HT_CAP((htc->cap & BIT(11)), "Max AMSDU length: "
  179. "3839 bytes");
  180. PRINT_HT_CAP(!(htc->cap & BIT(11)), "Max AMSDU length: "
  181. "7935 bytes");
  182. /*
  183. * For beacons and probe response this would mean the BSS
  184. * does or does not allow the usage of DSSS/CCK HT40.
  185. * Otherwise it means the STA does or does not use
  186. * DSSS/CCK HT40.
  187. */
  188. PRINT_HT_CAP((htc->cap & BIT(12)), "DSSS/CCK HT40");
  189. PRINT_HT_CAP(!(htc->cap & BIT(12)), "No DSSS/CCK HT40");
  190. /* BIT(13) is reserved */
  191. PRINT_HT_CAP((htc->cap & BIT(14)), "40 MHz Intolerant");
  192. PRINT_HT_CAP((htc->cap & BIT(15)), "L-SIG TXOP protection");
  193. p += scnprintf(p, sizeof(buf)+buf-p, "ampdu factor/density: %d/%d\n",
  194. htc->ampdu_factor, htc->ampdu_density);
  195. p += scnprintf(p, sizeof(buf)+buf-p, "MCS mask:");
  196. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
  197. p += scnprintf(p, sizeof(buf)+buf-p, " %.2x",
  198. htc->mcs.rx_mask[i]);
  199. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  200. /* If not set this is meaningless */
  201. if (le16_to_cpu(htc->mcs.rx_highest)) {
  202. p += scnprintf(p, sizeof(buf)+buf-p,
  203. "MCS rx highest: %d Mbps\n",
  204. le16_to_cpu(htc->mcs.rx_highest));
  205. }
  206. p += scnprintf(p, sizeof(buf)+buf-p, "MCS tx params: %x\n",
  207. htc->mcs.tx_params);
  208. }
  209. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  210. }
  211. STA_OPS(ht_capa);
  212. #define DEBUGFS_ADD(name) \
  213. debugfs_create_file(#name, 0400, \
  214. sta->debugfs.dir, sta, &sta_ ##name## _ops);
  215. void ieee80211_sta_debugfs_add(struct sta_info *sta)
  216. {
  217. struct dentry *stations_dir = sta->local->debugfs.stations;
  218. u8 mac[3*ETH_ALEN];
  219. sta->debugfs.add_has_run = true;
  220. if (!stations_dir)
  221. return;
  222. snprintf(mac, sizeof(mac), "%pM", sta->sta.addr);
  223. /*
  224. * This might fail due to a race condition:
  225. * When mac80211 unlinks a station, the debugfs entries
  226. * remain, but it is already possible to link a new
  227. * station with the same address which triggers adding
  228. * it to debugfs; therefore, if the old station isn't
  229. * destroyed quickly enough the old station's debugfs
  230. * dir might still be around.
  231. */
  232. sta->debugfs.dir = debugfs_create_dir(mac, stations_dir);
  233. if (!sta->debugfs.dir)
  234. return;
  235. DEBUGFS_ADD(flags);
  236. DEBUGFS_ADD(num_ps_buf_frames);
  237. DEBUGFS_ADD(inactive_ms);
  238. DEBUGFS_ADD(last_seq_ctrl);
  239. DEBUGFS_ADD(agg_status);
  240. DEBUGFS_ADD(dev);
  241. DEBUGFS_ADD(rx_packets);
  242. DEBUGFS_ADD(tx_packets);
  243. DEBUGFS_ADD(rx_bytes);
  244. DEBUGFS_ADD(tx_bytes);
  245. DEBUGFS_ADD(rx_duplicates);
  246. DEBUGFS_ADD(rx_fragments);
  247. DEBUGFS_ADD(rx_dropped);
  248. DEBUGFS_ADD(tx_fragments);
  249. DEBUGFS_ADD(tx_filtered);
  250. DEBUGFS_ADD(tx_retry_failed);
  251. DEBUGFS_ADD(tx_retry_count);
  252. DEBUGFS_ADD(last_signal);
  253. DEBUGFS_ADD(last_noise);
  254. DEBUGFS_ADD(wep_weak_iv_count);
  255. DEBUGFS_ADD(ht_capa);
  256. }
  257. void ieee80211_sta_debugfs_remove(struct sta_info *sta)
  258. {
  259. debugfs_remove_recursive(sta->debugfs.dir);
  260. sta->debugfs.dir = NULL;
  261. }