debugfs_sta.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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, 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. struct sta_info *sta = file->private_data; \
  23. return mac80211_format_buffer(userbuf, count, ppos, \
  24. format_string, sta->field); \
  25. }
  26. #define STA_READ_D(name, field) STA_READ(name, field, "%d\n")
  27. #define STA_READ_U(name, field) STA_READ(name, field, "%u\n")
  28. #define STA_READ_S(name, field) STA_READ(name, field, "%s\n")
  29. #define STA_OPS(name) \
  30. static const struct file_operations sta_ ##name## _ops = { \
  31. .read = sta_##name##_read, \
  32. .open = mac80211_open_file_generic, \
  33. .llseek = generic_file_llseek, \
  34. }
  35. #define STA_OPS_RW(name) \
  36. static const struct file_operations sta_ ##name## _ops = { \
  37. .read = sta_##name##_read, \
  38. .write = sta_##name##_write, \
  39. .open = mac80211_open_file_generic, \
  40. .llseek = generic_file_llseek, \
  41. }
  42. #define STA_FILE(name, field, format) \
  43. STA_READ_##format(name, field) \
  44. STA_OPS(name)
  45. STA_FILE(aid, sta.aid, D);
  46. STA_FILE(dev, sdata->name, S);
  47. STA_FILE(last_signal, last_signal, D);
  48. static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
  49. size_t count, loff_t *ppos)
  50. {
  51. char buf[100];
  52. struct sta_info *sta = file->private_data;
  53. u32 staflags = get_sta_flags(sta);
  54. int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s",
  55. staflags & WLAN_STA_AUTH ? "AUTH\n" : "",
  56. staflags & WLAN_STA_ASSOC ? "ASSOC\n" : "",
  57. staflags & WLAN_STA_PS_STA ? "PS (sta)\n" : "",
  58. staflags & WLAN_STA_PS_DRIVER ? "PS (driver)\n" : "",
  59. staflags & WLAN_STA_AUTHORIZED ? "AUTHORIZED\n" : "",
  60. staflags & WLAN_STA_SHORT_PREAMBLE ? "SHORT PREAMBLE\n" : "",
  61. staflags & WLAN_STA_WME ? "WME\n" : "",
  62. staflags & WLAN_STA_WDS ? "WDS\n" : "",
  63. staflags & WLAN_STA_MFP ? "MFP\n" : "");
  64. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  65. }
  66. STA_OPS(flags);
  67. static ssize_t sta_num_ps_buf_frames_read(struct file *file,
  68. char __user *userbuf,
  69. size_t count, loff_t *ppos)
  70. {
  71. struct sta_info *sta = file->private_data;
  72. return mac80211_format_buffer(userbuf, count, ppos, "%u\n",
  73. skb_queue_len(&sta->ps_tx_buf));
  74. }
  75. STA_OPS(num_ps_buf_frames);
  76. static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf,
  77. size_t count, loff_t *ppos)
  78. {
  79. struct sta_info *sta = file->private_data;
  80. return mac80211_format_buffer(userbuf, count, ppos, "%d\n",
  81. jiffies_to_msecs(jiffies - sta->last_rx));
  82. }
  83. STA_OPS(inactive_ms);
  84. static ssize_t sta_last_seq_ctrl_read(struct file *file, char __user *userbuf,
  85. size_t count, loff_t *ppos)
  86. {
  87. char buf[15*NUM_RX_DATA_QUEUES], *p = buf;
  88. int i;
  89. struct sta_info *sta = file->private_data;
  90. for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
  91. p += scnprintf(p, sizeof(buf)+buf-p, "%x ",
  92. le16_to_cpu(sta->last_seq_ctrl[i]));
  93. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  94. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  95. }
  96. STA_OPS(last_seq_ctrl);
  97. static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
  98. size_t count, loff_t *ppos)
  99. {
  100. char buf[71 + STA_TID_NUM * 40], *p = buf;
  101. int i;
  102. struct sta_info *sta = file->private_data;
  103. spin_lock_bh(&sta->lock);
  104. p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
  105. sta->ampdu_mlme.dialog_token_allocator + 1);
  106. p += scnprintf(p, sizeof(buf) + buf - p,
  107. "TID\t\tRX active\tDTKN\tSSN\t\tTX\tDTKN\tpending\n");
  108. for (i = 0; i < STA_TID_NUM; i++) {
  109. p += scnprintf(p, sizeof(buf) + buf - p, "%02d", i);
  110. p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x",
  111. !!sta->ampdu_mlme.tid_rx[i]);
  112. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
  113. sta->ampdu_mlme.tid_rx[i] ?
  114. sta->ampdu_mlme.tid_rx[i]->dialog_token : 0);
  115. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.3x",
  116. sta->ampdu_mlme.tid_rx[i] ?
  117. sta->ampdu_mlme.tid_rx[i]->ssn : 0);
  118. p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x",
  119. !!sta->ampdu_mlme.tid_tx[i]);
  120. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
  121. sta->ampdu_mlme.tid_tx[i] ?
  122. sta->ampdu_mlme.tid_tx[i]->dialog_token : 0);
  123. p += scnprintf(p, sizeof(buf) + buf - p, "\t%03d",
  124. sta->ampdu_mlme.tid_tx[i] ?
  125. skb_queue_len(&sta->ampdu_mlme.tid_tx[i]->pending) : 0);
  126. p += scnprintf(p, sizeof(buf) + buf - p, "\n");
  127. }
  128. spin_unlock_bh(&sta->lock);
  129. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  130. }
  131. static ssize_t sta_agg_status_write(struct file *file, const char __user *userbuf,
  132. size_t count, loff_t *ppos)
  133. {
  134. char _buf[12], *buf = _buf;
  135. struct sta_info *sta = file->private_data;
  136. bool start, tx;
  137. unsigned long tid;
  138. int ret;
  139. if (count > sizeof(_buf))
  140. return -EINVAL;
  141. if (copy_from_user(buf, userbuf, count))
  142. return -EFAULT;
  143. buf[sizeof(_buf) - 1] = '\0';
  144. if (strncmp(buf, "tx ", 3) == 0) {
  145. buf += 3;
  146. tx = true;
  147. } else if (strncmp(buf, "rx ", 3) == 0) {
  148. buf += 3;
  149. tx = false;
  150. } else
  151. return -EINVAL;
  152. if (strncmp(buf, "start ", 6) == 0) {
  153. buf += 6;
  154. start = true;
  155. if (!tx)
  156. return -EINVAL;
  157. } else if (strncmp(buf, "stop ", 5) == 0) {
  158. buf += 5;
  159. start = false;
  160. } else
  161. return -EINVAL;
  162. tid = simple_strtoul(buf, NULL, 0);
  163. if (tid >= STA_TID_NUM)
  164. return -EINVAL;
  165. if (tx) {
  166. if (start)
  167. ret = ieee80211_start_tx_ba_session(&sta->sta, tid);
  168. else
  169. ret = ieee80211_stop_tx_ba_session(&sta->sta, tid);
  170. } else {
  171. __ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_RECIPIENT,
  172. 3, true);
  173. ret = 0;
  174. }
  175. return ret ?: count;
  176. }
  177. STA_OPS_RW(agg_status);
  178. static ssize_t sta_ht_capa_read(struct file *file, char __user *userbuf,
  179. size_t count, loff_t *ppos)
  180. {
  181. #define PRINT_HT_CAP(_cond, _str) \
  182. do { \
  183. if (_cond) \
  184. p += scnprintf(p, sizeof(buf)+buf-p, "\t" _str "\n"); \
  185. } while (0)
  186. char buf[512], *p = buf;
  187. int i;
  188. struct sta_info *sta = file->private_data;
  189. struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
  190. p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
  191. htc->ht_supported ? "" : "not ");
  192. if (htc->ht_supported) {
  193. p += scnprintf(p, sizeof(buf)+buf-p, "cap: %#.4x\n", htc->cap);
  194. PRINT_HT_CAP((htc->cap & BIT(0)), "RX LDPC");
  195. PRINT_HT_CAP((htc->cap & BIT(1)), "HT20/HT40");
  196. PRINT_HT_CAP(!(htc->cap & BIT(1)), "HT20");
  197. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 0, "Static SM Power Save");
  198. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 1, "Dynamic SM Power Save");
  199. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 3, "SM Power Save disabled");
  200. PRINT_HT_CAP((htc->cap & BIT(4)), "RX Greenfield");
  201. PRINT_HT_CAP((htc->cap & BIT(5)), "RX HT20 SGI");
  202. PRINT_HT_CAP((htc->cap & BIT(6)), "RX HT40 SGI");
  203. PRINT_HT_CAP((htc->cap & BIT(7)), "TX STBC");
  204. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 0, "No RX STBC");
  205. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 1, "RX STBC 1-stream");
  206. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 2, "RX STBC 2-streams");
  207. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 3, "RX STBC 3-streams");
  208. PRINT_HT_CAP((htc->cap & BIT(10)), "HT Delayed Block Ack");
  209. PRINT_HT_CAP((htc->cap & BIT(11)), "Max AMSDU length: "
  210. "3839 bytes");
  211. PRINT_HT_CAP(!(htc->cap & BIT(11)), "Max AMSDU length: "
  212. "7935 bytes");
  213. /*
  214. * For beacons and probe response this would mean the BSS
  215. * does or does not allow the usage of DSSS/CCK HT40.
  216. * Otherwise it means the STA does or does not use
  217. * DSSS/CCK HT40.
  218. */
  219. PRINT_HT_CAP((htc->cap & BIT(12)), "DSSS/CCK HT40");
  220. PRINT_HT_CAP(!(htc->cap & BIT(12)), "No DSSS/CCK HT40");
  221. /* BIT(13) is reserved */
  222. PRINT_HT_CAP((htc->cap & BIT(14)), "40 MHz Intolerant");
  223. PRINT_HT_CAP((htc->cap & BIT(15)), "L-SIG TXOP protection");
  224. p += scnprintf(p, sizeof(buf)+buf-p, "ampdu factor/density: %d/%d\n",
  225. htc->ampdu_factor, htc->ampdu_density);
  226. p += scnprintf(p, sizeof(buf)+buf-p, "MCS mask:");
  227. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
  228. p += scnprintf(p, sizeof(buf)+buf-p, " %.2x",
  229. htc->mcs.rx_mask[i]);
  230. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  231. /* If not set this is meaningless */
  232. if (le16_to_cpu(htc->mcs.rx_highest)) {
  233. p += scnprintf(p, sizeof(buf)+buf-p,
  234. "MCS rx highest: %d Mbps\n",
  235. le16_to_cpu(htc->mcs.rx_highest));
  236. }
  237. p += scnprintf(p, sizeof(buf)+buf-p, "MCS tx params: %x\n",
  238. htc->mcs.tx_params);
  239. }
  240. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  241. }
  242. STA_OPS(ht_capa);
  243. #define DEBUGFS_ADD(name) \
  244. debugfs_create_file(#name, 0400, \
  245. sta->debugfs.dir, sta, &sta_ ##name## _ops);
  246. #define DEBUGFS_ADD_COUNTER(name, field) \
  247. if (sizeof(sta->field) == sizeof(u32)) \
  248. debugfs_create_u32(#name, 0400, sta->debugfs.dir, \
  249. (u32 *) &sta->field); \
  250. else \
  251. debugfs_create_u64(#name, 0400, sta->debugfs.dir, \
  252. (u64 *) &sta->field);
  253. void ieee80211_sta_debugfs_add(struct sta_info *sta)
  254. {
  255. struct dentry *stations_dir = sta->sdata->debugfs.subdir_stations;
  256. u8 mac[3*ETH_ALEN];
  257. sta->debugfs.add_has_run = true;
  258. if (!stations_dir)
  259. return;
  260. snprintf(mac, sizeof(mac), "%pM", sta->sta.addr);
  261. /*
  262. * This might fail due to a race condition:
  263. * When mac80211 unlinks a station, the debugfs entries
  264. * remain, but it is already possible to link a new
  265. * station with the same address which triggers adding
  266. * it to debugfs; therefore, if the old station isn't
  267. * destroyed quickly enough the old station's debugfs
  268. * dir might still be around.
  269. */
  270. sta->debugfs.dir = debugfs_create_dir(mac, stations_dir);
  271. if (!sta->debugfs.dir)
  272. return;
  273. DEBUGFS_ADD(flags);
  274. DEBUGFS_ADD(num_ps_buf_frames);
  275. DEBUGFS_ADD(inactive_ms);
  276. DEBUGFS_ADD(last_seq_ctrl);
  277. DEBUGFS_ADD(agg_status);
  278. DEBUGFS_ADD(dev);
  279. DEBUGFS_ADD(last_signal);
  280. DEBUGFS_ADD(ht_capa);
  281. DEBUGFS_ADD_COUNTER(rx_packets, rx_packets);
  282. DEBUGFS_ADD_COUNTER(tx_packets, tx_packets);
  283. DEBUGFS_ADD_COUNTER(rx_bytes, rx_bytes);
  284. DEBUGFS_ADD_COUNTER(tx_bytes, tx_bytes);
  285. DEBUGFS_ADD_COUNTER(rx_duplicates, num_duplicates);
  286. DEBUGFS_ADD_COUNTER(rx_fragments, rx_fragments);
  287. DEBUGFS_ADD_COUNTER(rx_dropped, rx_dropped);
  288. DEBUGFS_ADD_COUNTER(tx_fragments, tx_fragments);
  289. DEBUGFS_ADD_COUNTER(tx_filtered, tx_filtered_count);
  290. DEBUGFS_ADD_COUNTER(tx_retry_failed, tx_retry_failed);
  291. DEBUGFS_ADD_COUNTER(tx_retry_count, tx_retry_count);
  292. DEBUGFS_ADD_COUNTER(wep_weak_iv_count, wep_weak_iv_count);
  293. }
  294. void ieee80211_sta_debugfs_remove(struct sta_info *sta)
  295. {
  296. debugfs_remove_recursive(sta->debugfs.dir);
  297. sta->debugfs.dir = NULL;
  298. }