debugfs_sta.c 12 KB

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