debugfs_sta.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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. * Copyright 2013-2014 Intel Mobile Communications GmbH
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/debugfs.h>
  12. #include <linux/ieee80211.h>
  13. #include "ieee80211_i.h"
  14. #include "debugfs.h"
  15. #include "debugfs_sta.h"
  16. #include "sta_info.h"
  17. #include "driver-ops.h"
  18. /* sta attributtes */
  19. #define STA_READ(name, field, format_string) \
  20. static ssize_t sta_ ##name## _read(struct file *file, \
  21. char __user *userbuf, \
  22. size_t count, loff_t *ppos) \
  23. { \
  24. struct sta_info *sta = file->private_data; \
  25. return mac80211_format_buffer(userbuf, count, ppos, \
  26. format_string, sta->field); \
  27. }
  28. #define STA_READ_D(name, field) STA_READ(name, field, "%d\n")
  29. #define STA_OPS(name) \
  30. static const struct file_operations sta_ ##name## _ops = { \
  31. .read = sta_##name##_read, \
  32. .open = simple_open, \
  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 = simple_open, \
  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. static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
  47. size_t count, loff_t *ppos)
  48. {
  49. char buf[121];
  50. struct sta_info *sta = file->private_data;
  51. #define TEST(flg) \
  52. test_sta_flag(sta, WLAN_STA_##flg) ? #flg "\n" : ""
  53. int res = scnprintf(buf, sizeof(buf),
  54. "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
  55. TEST(AUTH), TEST(ASSOC), TEST(PS_STA),
  56. TEST(PS_DRIVER), TEST(AUTHORIZED),
  57. TEST(SHORT_PREAMBLE),
  58. sta->sta.wme ? "WME\n" : "",
  59. TEST(WDS), TEST(CLEAR_PS_FILT),
  60. TEST(MFP), TEST(BLOCK_BA), TEST(PSPOLL),
  61. TEST(UAPSD), TEST(SP), TEST(TDLS_PEER),
  62. TEST(TDLS_PEER_AUTH), TEST(TDLS_INITIATOR),
  63. TEST(TDLS_CHAN_SWITCH), TEST(TDLS_OFF_CHANNEL),
  64. TEST(4ADDR_EVENT), TEST(INSERTED),
  65. TEST(RATE_CONTROL), TEST(TOFFSET_KNOWN),
  66. TEST(MPSP_OWNER), TEST(MPSP_RECIPIENT));
  67. #undef TEST
  68. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  69. }
  70. STA_OPS(flags);
  71. static ssize_t sta_num_ps_buf_frames_read(struct file *file,
  72. char __user *userbuf,
  73. size_t count, loff_t *ppos)
  74. {
  75. struct sta_info *sta = file->private_data;
  76. char buf[17*IEEE80211_NUM_ACS], *p = buf;
  77. int ac;
  78. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  79. p += scnprintf(p, sizeof(buf)+buf-p, "AC%d: %d\n", ac,
  80. skb_queue_len(&sta->ps_tx_buf[ac]) +
  81. skb_queue_len(&sta->tx_filtered[ac]));
  82. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  83. }
  84. STA_OPS(num_ps_buf_frames);
  85. static ssize_t sta_last_seq_ctrl_read(struct file *file, char __user *userbuf,
  86. size_t count, loff_t *ppos)
  87. {
  88. char buf[15*IEEE80211_NUM_TIDS], *p = buf;
  89. int i;
  90. struct sta_info *sta = file->private_data;
  91. for (i = 0; i < IEEE80211_NUM_TIDS; i++)
  92. p += scnprintf(p, sizeof(buf)+buf-p, "%x ",
  93. le16_to_cpu(sta->last_seq_ctrl[i]));
  94. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  95. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  96. }
  97. STA_OPS(last_seq_ctrl);
  98. static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
  99. size_t count, loff_t *ppos)
  100. {
  101. char buf[71 + IEEE80211_NUM_TIDS * 40], *p = buf;
  102. int i;
  103. struct sta_info *sta = file->private_data;
  104. struct tid_ampdu_rx *tid_rx;
  105. struct tid_ampdu_tx *tid_tx;
  106. rcu_read_lock();
  107. p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
  108. sta->ampdu_mlme.dialog_token_allocator + 1);
  109. p += scnprintf(p, sizeof(buf) + buf - p,
  110. "TID\t\tRX\tDTKN\tSSN\t\tTX\tDTKN\tpending\n");
  111. for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
  112. tid_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[i]);
  113. tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[i]);
  114. p += scnprintf(p, sizeof(buf) + buf - p, "%02d", i);
  115. p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x", !!tid_rx);
  116. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
  117. tid_rx ? tid_rx->dialog_token : 0);
  118. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.3x",
  119. tid_rx ? tid_rx->ssn : 0);
  120. p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x", !!tid_tx);
  121. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
  122. tid_tx ? tid_tx->dialog_token : 0);
  123. p += scnprintf(p, sizeof(buf) + buf - p, "\t%03d",
  124. tid_tx ? skb_queue_len(&tid_tx->pending) : 0);
  125. p += scnprintf(p, sizeof(buf) + buf - p, "\n");
  126. }
  127. rcu_read_unlock();
  128. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  129. }
  130. static ssize_t sta_agg_status_write(struct file *file, const char __user *userbuf,
  131. size_t count, loff_t *ppos)
  132. {
  133. char _buf[12] = {}, *buf = _buf;
  134. struct sta_info *sta = file->private_data;
  135. bool start, tx;
  136. unsigned long tid;
  137. int ret;
  138. if (count > sizeof(_buf))
  139. return -EINVAL;
  140. if (copy_from_user(buf, userbuf, count))
  141. return -EFAULT;
  142. buf[sizeof(_buf) - 1] = '\0';
  143. if (strncmp(buf, "tx ", 3) == 0) {
  144. buf += 3;
  145. tx = true;
  146. } else if (strncmp(buf, "rx ", 3) == 0) {
  147. buf += 3;
  148. tx = false;
  149. } else
  150. return -EINVAL;
  151. if (strncmp(buf, "start ", 6) == 0) {
  152. buf += 6;
  153. start = true;
  154. if (!tx)
  155. return -EINVAL;
  156. } else if (strncmp(buf, "stop ", 5) == 0) {
  157. buf += 5;
  158. start = false;
  159. } else
  160. return -EINVAL;
  161. ret = kstrtoul(buf, 0, &tid);
  162. if (ret)
  163. return ret;
  164. if (tid >= IEEE80211_NUM_TIDS)
  165. return -EINVAL;
  166. if (tx) {
  167. if (start)
  168. ret = ieee80211_start_tx_ba_session(&sta->sta, tid, 5000);
  169. else
  170. ret = ieee80211_stop_tx_ba_session(&sta->sta, tid);
  171. } else {
  172. __ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_RECIPIENT,
  173. 3, true);
  174. ret = 0;
  175. }
  176. return ret ?: count;
  177. }
  178. STA_OPS_RW(agg_status);
  179. static ssize_t sta_ht_capa_read(struct file *file, char __user *userbuf,
  180. size_t count, loff_t *ppos)
  181. {
  182. #define PRINT_HT_CAP(_cond, _str) \
  183. do { \
  184. if (_cond) \
  185. p += scnprintf(p, sizeof(buf)+buf-p, "\t" _str "\n"); \
  186. } while (0)
  187. char buf[512], *p = buf;
  188. int i;
  189. struct sta_info *sta = file->private_data;
  190. struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
  191. p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
  192. htc->ht_supported ? "" : "not ");
  193. if (htc->ht_supported) {
  194. p += scnprintf(p, sizeof(buf)+buf-p, "cap: %#.4x\n", htc->cap);
  195. PRINT_HT_CAP((htc->cap & BIT(0)), "RX LDPC");
  196. PRINT_HT_CAP((htc->cap & BIT(1)), "HT20/HT40");
  197. PRINT_HT_CAP(!(htc->cap & BIT(1)), "HT20");
  198. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 0, "Static SM Power Save");
  199. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 1, "Dynamic SM Power Save");
  200. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 3, "SM Power Save disabled");
  201. PRINT_HT_CAP((htc->cap & BIT(4)), "RX Greenfield");
  202. PRINT_HT_CAP((htc->cap & BIT(5)), "RX HT20 SGI");
  203. PRINT_HT_CAP((htc->cap & BIT(6)), "RX HT40 SGI");
  204. PRINT_HT_CAP((htc->cap & BIT(7)), "TX STBC");
  205. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 0, "No RX STBC");
  206. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 1, "RX STBC 1-stream");
  207. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 2, "RX STBC 2-streams");
  208. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 3, "RX STBC 3-streams");
  209. PRINT_HT_CAP((htc->cap & BIT(10)), "HT Delayed Block Ack");
  210. PRINT_HT_CAP(!(htc->cap & BIT(11)), "Max AMSDU length: "
  211. "3839 bytes");
  212. PRINT_HT_CAP((htc->cap & BIT(11)), "Max AMSDU length: "
  213. "7935 bytes");
  214. /*
  215. * For beacons and probe response this would mean the BSS
  216. * does or does not allow the usage of DSSS/CCK HT40.
  217. * Otherwise it means the STA does or does not use
  218. * DSSS/CCK HT40.
  219. */
  220. PRINT_HT_CAP((htc->cap & BIT(12)), "DSSS/CCK HT40");
  221. PRINT_HT_CAP(!(htc->cap & BIT(12)), "No DSSS/CCK HT40");
  222. /* BIT(13) is reserved */
  223. PRINT_HT_CAP((htc->cap & BIT(14)), "40 MHz Intolerant");
  224. PRINT_HT_CAP((htc->cap & BIT(15)), "L-SIG TXOP protection");
  225. p += scnprintf(p, sizeof(buf)+buf-p, "ampdu factor/density: %d/%d\n",
  226. htc->ampdu_factor, htc->ampdu_density);
  227. p += scnprintf(p, sizeof(buf)+buf-p, "MCS mask:");
  228. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
  229. p += scnprintf(p, sizeof(buf)+buf-p, " %.2x",
  230. htc->mcs.rx_mask[i]);
  231. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  232. /* If not set this is meaningless */
  233. if (le16_to_cpu(htc->mcs.rx_highest)) {
  234. p += scnprintf(p, sizeof(buf)+buf-p,
  235. "MCS rx highest: %d Mbps\n",
  236. le16_to_cpu(htc->mcs.rx_highest));
  237. }
  238. p += scnprintf(p, sizeof(buf)+buf-p, "MCS tx params: %x\n",
  239. htc->mcs.tx_params);
  240. }
  241. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  242. }
  243. STA_OPS(ht_capa);
  244. static ssize_t sta_vht_capa_read(struct file *file, char __user *userbuf,
  245. size_t count, loff_t *ppos)
  246. {
  247. char buf[128], *p = buf;
  248. struct sta_info *sta = file->private_data;
  249. struct ieee80211_sta_vht_cap *vhtc = &sta->sta.vht_cap;
  250. p += scnprintf(p, sizeof(buf) + buf - p, "VHT %ssupported\n",
  251. vhtc->vht_supported ? "" : "not ");
  252. if (vhtc->vht_supported) {
  253. p += scnprintf(p, sizeof(buf)+buf-p, "cap: %#.8x\n", vhtc->cap);
  254. p += scnprintf(p, sizeof(buf)+buf-p, "RX MCS: %.4x\n",
  255. le16_to_cpu(vhtc->vht_mcs.rx_mcs_map));
  256. if (vhtc->vht_mcs.rx_highest)
  257. p += scnprintf(p, sizeof(buf)+buf-p,
  258. "MCS RX highest: %d Mbps\n",
  259. le16_to_cpu(vhtc->vht_mcs.rx_highest));
  260. p += scnprintf(p, sizeof(buf)+buf-p, "TX MCS: %.4x\n",
  261. le16_to_cpu(vhtc->vht_mcs.tx_mcs_map));
  262. if (vhtc->vht_mcs.tx_highest)
  263. p += scnprintf(p, sizeof(buf)+buf-p,
  264. "MCS TX highest: %d Mbps\n",
  265. le16_to_cpu(vhtc->vht_mcs.tx_highest));
  266. }
  267. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  268. }
  269. STA_OPS(vht_capa);
  270. #define DEBUGFS_ADD(name) \
  271. debugfs_create_file(#name, 0400, \
  272. sta->debugfs.dir, sta, &sta_ ##name## _ops);
  273. #define DEBUGFS_ADD_COUNTER(name, field) \
  274. if (sizeof(sta->field) == sizeof(u32)) \
  275. debugfs_create_u32(#name, 0400, sta->debugfs.dir, \
  276. (u32 *) &sta->field); \
  277. else \
  278. debugfs_create_u64(#name, 0400, sta->debugfs.dir, \
  279. (u64 *) &sta->field);
  280. void ieee80211_sta_debugfs_add(struct sta_info *sta)
  281. {
  282. struct ieee80211_local *local = sta->local;
  283. struct ieee80211_sub_if_data *sdata = sta->sdata;
  284. struct dentry *stations_dir = sta->sdata->debugfs.subdir_stations;
  285. u8 mac[3*ETH_ALEN];
  286. sta->debugfs.add_has_run = true;
  287. if (!stations_dir)
  288. return;
  289. snprintf(mac, sizeof(mac), "%pM", sta->sta.addr);
  290. /*
  291. * This might fail due to a race condition:
  292. * When mac80211 unlinks a station, the debugfs entries
  293. * remain, but it is already possible to link a new
  294. * station with the same address which triggers adding
  295. * it to debugfs; therefore, if the old station isn't
  296. * destroyed quickly enough the old station's debugfs
  297. * dir might still be around.
  298. */
  299. sta->debugfs.dir = debugfs_create_dir(mac, stations_dir);
  300. if (!sta->debugfs.dir)
  301. return;
  302. DEBUGFS_ADD(flags);
  303. DEBUGFS_ADD(num_ps_buf_frames);
  304. DEBUGFS_ADD(last_seq_ctrl);
  305. DEBUGFS_ADD(agg_status);
  306. DEBUGFS_ADD(ht_capa);
  307. DEBUGFS_ADD(vht_capa);
  308. DEBUGFS_ADD_COUNTER(rx_duplicates, rx_stats.num_duplicates);
  309. DEBUGFS_ADD_COUNTER(rx_fragments, rx_stats.fragments);
  310. DEBUGFS_ADD_COUNTER(tx_filtered, status_stats.filtered);
  311. if (sizeof(sta->driver_buffered_tids) == sizeof(u32))
  312. debugfs_create_x32("driver_buffered_tids", 0400,
  313. sta->debugfs.dir,
  314. (u32 *)&sta->driver_buffered_tids);
  315. else
  316. debugfs_create_x64("driver_buffered_tids", 0400,
  317. sta->debugfs.dir,
  318. (u64 *)&sta->driver_buffered_tids);
  319. drv_sta_add_debugfs(local, sdata, &sta->sta, sta->debugfs.dir);
  320. }
  321. void ieee80211_sta_debugfs_remove(struct sta_info *sta)
  322. {
  323. struct ieee80211_local *local = sta->local;
  324. struct ieee80211_sub_if_data *sdata = sta->sdata;
  325. drv_sta_remove_debugfs(local, sdata, &sta->sta, sta->debugfs.dir);
  326. debugfs_remove_recursive(sta->debugfs.dir);
  327. sta->debugfs.dir = NULL;
  328. }