debugfs_sta.c 12 KB

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