debugfs_sta.c 11 KB

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