debugfs_sta.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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_READ_U(name, field) STA_READ(name, field, "%u\n")
  30. #define STA_READ_S(name, field) STA_READ(name, field, "%s\n")
  31. #define STA_OPS(name) \
  32. static const struct file_operations sta_ ##name## _ops = { \
  33. .read = sta_##name##_read, \
  34. .open = simple_open, \
  35. .llseek = generic_file_llseek, \
  36. }
  37. #define STA_OPS_RW(name) \
  38. static const struct file_operations sta_ ##name## _ops = { \
  39. .read = sta_##name##_read, \
  40. .write = sta_##name##_write, \
  41. .open = simple_open, \
  42. .llseek = generic_file_llseek, \
  43. }
  44. #define STA_FILE(name, field, format) \
  45. STA_READ_##format(name, field) \
  46. STA_OPS(name)
  47. STA_FILE(aid, sta.aid, D);
  48. STA_FILE(dev, sdata->name, S);
  49. STA_FILE(last_signal, last_signal, D);
  50. STA_FILE(last_ack_signal, last_ack_signal, D);
  51. STA_FILE(beacon_loss_count, beacon_loss_count, D);
  52. static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
  53. size_t count, loff_t *ppos)
  54. {
  55. char buf[121];
  56. struct sta_info *sta = file->private_data;
  57. #define TEST(flg) \
  58. test_sta_flag(sta, WLAN_STA_##flg) ? #flg "\n" : ""
  59. int res = scnprintf(buf, sizeof(buf),
  60. "%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",
  61. TEST(AUTH), TEST(ASSOC), TEST(PS_STA),
  62. TEST(PS_DRIVER), TEST(AUTHORIZED),
  63. TEST(SHORT_PREAMBLE),
  64. sta->sta.wme ? "WME\n" : "",
  65. TEST(WDS), TEST(CLEAR_PS_FILT),
  66. TEST(MFP), TEST(BLOCK_BA), TEST(PSPOLL),
  67. TEST(UAPSD), TEST(SP), TEST(TDLS_PEER),
  68. TEST(TDLS_PEER_AUTH), TEST(TDLS_INITIATOR),
  69. TEST(TDLS_CHAN_SWITCH), TEST(TDLS_OFF_CHANNEL),
  70. TEST(4ADDR_EVENT), TEST(INSERTED),
  71. TEST(RATE_CONTROL), TEST(TOFFSET_KNOWN),
  72. TEST(MPSP_OWNER), TEST(MPSP_RECIPIENT));
  73. #undef TEST
  74. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  75. }
  76. STA_OPS(flags);
  77. static ssize_t sta_num_ps_buf_frames_read(struct file *file,
  78. char __user *userbuf,
  79. size_t count, loff_t *ppos)
  80. {
  81. struct sta_info *sta = file->private_data;
  82. char buf[17*IEEE80211_NUM_ACS], *p = buf;
  83. int ac;
  84. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  85. p += scnprintf(p, sizeof(buf)+buf-p, "AC%d: %d\n", ac,
  86. skb_queue_len(&sta->ps_tx_buf[ac]) +
  87. skb_queue_len(&sta->tx_filtered[ac]));
  88. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  89. }
  90. STA_OPS(num_ps_buf_frames);
  91. static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf,
  92. size_t count, loff_t *ppos)
  93. {
  94. struct sta_info *sta = file->private_data;
  95. return mac80211_format_buffer(userbuf, count, ppos, "%d\n",
  96. jiffies_to_msecs(jiffies - sta->last_rx));
  97. }
  98. STA_OPS(inactive_ms);
  99. static ssize_t sta_connected_time_read(struct file *file, char __user *userbuf,
  100. size_t count, loff_t *ppos)
  101. {
  102. struct sta_info *sta = file->private_data;
  103. struct timespec uptime;
  104. struct tm result;
  105. long connected_time_secs;
  106. char buf[100];
  107. int res;
  108. ktime_get_ts(&uptime);
  109. connected_time_secs = uptime.tv_sec - sta->last_connected;
  110. time_to_tm(connected_time_secs, 0, &result);
  111. result.tm_year -= 70;
  112. result.tm_mday -= 1;
  113. res = scnprintf(buf, sizeof(buf),
  114. "years - %ld\nmonths - %d\ndays - %d\nclock - %d:%d:%d\n\n",
  115. result.tm_year, result.tm_mon, result.tm_mday,
  116. result.tm_hour, result.tm_min, result.tm_sec);
  117. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  118. }
  119. STA_OPS(connected_time);
  120. static ssize_t sta_last_seq_ctrl_read(struct file *file, char __user *userbuf,
  121. size_t count, loff_t *ppos)
  122. {
  123. char buf[15*IEEE80211_NUM_TIDS], *p = buf;
  124. int i;
  125. struct sta_info *sta = file->private_data;
  126. for (i = 0; i < IEEE80211_NUM_TIDS; i++)
  127. p += scnprintf(p, sizeof(buf)+buf-p, "%x ",
  128. le16_to_cpu(sta->last_seq_ctrl[i]));
  129. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  130. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  131. }
  132. STA_OPS(last_seq_ctrl);
  133. static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
  134. size_t count, loff_t *ppos)
  135. {
  136. char buf[71 + IEEE80211_NUM_TIDS * 40], *p = buf;
  137. int i;
  138. struct sta_info *sta = file->private_data;
  139. struct tid_ampdu_rx *tid_rx;
  140. struct tid_ampdu_tx *tid_tx;
  141. rcu_read_lock();
  142. p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
  143. sta->ampdu_mlme.dialog_token_allocator + 1);
  144. p += scnprintf(p, sizeof(buf) + buf - p,
  145. "TID\t\tRX\tDTKN\tSSN\t\tTX\tDTKN\tpending\n");
  146. for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
  147. tid_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[i]);
  148. tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[i]);
  149. p += scnprintf(p, sizeof(buf) + buf - p, "%02d", i);
  150. p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x", !!tid_rx);
  151. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
  152. tid_rx ? tid_rx->dialog_token : 0);
  153. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.3x",
  154. tid_rx ? tid_rx->ssn : 0);
  155. p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x", !!tid_tx);
  156. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
  157. tid_tx ? tid_tx->dialog_token : 0);
  158. p += scnprintf(p, sizeof(buf) + buf - p, "\t%03d",
  159. tid_tx ? skb_queue_len(&tid_tx->pending) : 0);
  160. p += scnprintf(p, sizeof(buf) + buf - p, "\n");
  161. }
  162. rcu_read_unlock();
  163. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  164. }
  165. static ssize_t sta_agg_status_write(struct file *file, const char __user *userbuf,
  166. size_t count, loff_t *ppos)
  167. {
  168. char _buf[12] = {}, *buf = _buf;
  169. struct sta_info *sta = file->private_data;
  170. bool start, tx;
  171. unsigned long tid;
  172. int ret;
  173. if (count > sizeof(_buf))
  174. return -EINVAL;
  175. if (copy_from_user(buf, userbuf, count))
  176. return -EFAULT;
  177. buf[sizeof(_buf) - 1] = '\0';
  178. if (strncmp(buf, "tx ", 3) == 0) {
  179. buf += 3;
  180. tx = true;
  181. } else if (strncmp(buf, "rx ", 3) == 0) {
  182. buf += 3;
  183. tx = false;
  184. } else
  185. return -EINVAL;
  186. if (strncmp(buf, "start ", 6) == 0) {
  187. buf += 6;
  188. start = true;
  189. if (!tx)
  190. return -EINVAL;
  191. } else if (strncmp(buf, "stop ", 5) == 0) {
  192. buf += 5;
  193. start = false;
  194. } else
  195. return -EINVAL;
  196. ret = kstrtoul(buf, 0, &tid);
  197. if (ret)
  198. return ret;
  199. if (tid >= IEEE80211_NUM_TIDS)
  200. return -EINVAL;
  201. if (tx) {
  202. if (start)
  203. ret = ieee80211_start_tx_ba_session(&sta->sta, tid, 5000);
  204. else
  205. ret = ieee80211_stop_tx_ba_session(&sta->sta, tid);
  206. } else {
  207. __ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_RECIPIENT,
  208. 3, true);
  209. ret = 0;
  210. }
  211. return ret ?: count;
  212. }
  213. STA_OPS_RW(agg_status);
  214. static ssize_t sta_ht_capa_read(struct file *file, char __user *userbuf,
  215. size_t count, loff_t *ppos)
  216. {
  217. #define PRINT_HT_CAP(_cond, _str) \
  218. do { \
  219. if (_cond) \
  220. p += scnprintf(p, sizeof(buf)+buf-p, "\t" _str "\n"); \
  221. } while (0)
  222. char buf[512], *p = buf;
  223. int i;
  224. struct sta_info *sta = file->private_data;
  225. struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
  226. p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
  227. htc->ht_supported ? "" : "not ");
  228. if (htc->ht_supported) {
  229. p += scnprintf(p, sizeof(buf)+buf-p, "cap: %#.4x\n", htc->cap);
  230. PRINT_HT_CAP((htc->cap & BIT(0)), "RX LDPC");
  231. PRINT_HT_CAP((htc->cap & BIT(1)), "HT20/HT40");
  232. PRINT_HT_CAP(!(htc->cap & BIT(1)), "HT20");
  233. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 0, "Static SM Power Save");
  234. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 1, "Dynamic SM Power Save");
  235. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 3, "SM Power Save disabled");
  236. PRINT_HT_CAP((htc->cap & BIT(4)), "RX Greenfield");
  237. PRINT_HT_CAP((htc->cap & BIT(5)), "RX HT20 SGI");
  238. PRINT_HT_CAP((htc->cap & BIT(6)), "RX HT40 SGI");
  239. PRINT_HT_CAP((htc->cap & BIT(7)), "TX STBC");
  240. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 0, "No RX STBC");
  241. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 1, "RX STBC 1-stream");
  242. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 2, "RX STBC 2-streams");
  243. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 3, "RX STBC 3-streams");
  244. PRINT_HT_CAP((htc->cap & BIT(10)), "HT Delayed Block Ack");
  245. PRINT_HT_CAP(!(htc->cap & BIT(11)), "Max AMSDU length: "
  246. "3839 bytes");
  247. PRINT_HT_CAP((htc->cap & BIT(11)), "Max AMSDU length: "
  248. "7935 bytes");
  249. /*
  250. * For beacons and probe response this would mean the BSS
  251. * does or does not allow the usage of DSSS/CCK HT40.
  252. * Otherwise it means the STA does or does not use
  253. * DSSS/CCK HT40.
  254. */
  255. PRINT_HT_CAP((htc->cap & BIT(12)), "DSSS/CCK HT40");
  256. PRINT_HT_CAP(!(htc->cap & BIT(12)), "No DSSS/CCK HT40");
  257. /* BIT(13) is reserved */
  258. PRINT_HT_CAP((htc->cap & BIT(14)), "40 MHz Intolerant");
  259. PRINT_HT_CAP((htc->cap & BIT(15)), "L-SIG TXOP protection");
  260. p += scnprintf(p, sizeof(buf)+buf-p, "ampdu factor/density: %d/%d\n",
  261. htc->ampdu_factor, htc->ampdu_density);
  262. p += scnprintf(p, sizeof(buf)+buf-p, "MCS mask:");
  263. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
  264. p += scnprintf(p, sizeof(buf)+buf-p, " %.2x",
  265. htc->mcs.rx_mask[i]);
  266. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  267. /* If not set this is meaningless */
  268. if (le16_to_cpu(htc->mcs.rx_highest)) {
  269. p += scnprintf(p, sizeof(buf)+buf-p,
  270. "MCS rx highest: %d Mbps\n",
  271. le16_to_cpu(htc->mcs.rx_highest));
  272. }
  273. p += scnprintf(p, sizeof(buf)+buf-p, "MCS tx params: %x\n",
  274. htc->mcs.tx_params);
  275. }
  276. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  277. }
  278. STA_OPS(ht_capa);
  279. static ssize_t sta_vht_capa_read(struct file *file, char __user *userbuf,
  280. size_t count, loff_t *ppos)
  281. {
  282. char buf[128], *p = buf;
  283. struct sta_info *sta = file->private_data;
  284. struct ieee80211_sta_vht_cap *vhtc = &sta->sta.vht_cap;
  285. p += scnprintf(p, sizeof(buf) + buf - p, "VHT %ssupported\n",
  286. vhtc->vht_supported ? "" : "not ");
  287. if (vhtc->vht_supported) {
  288. p += scnprintf(p, sizeof(buf)+buf-p, "cap: %#.8x\n", vhtc->cap);
  289. p += scnprintf(p, sizeof(buf)+buf-p, "RX MCS: %.4x\n",
  290. le16_to_cpu(vhtc->vht_mcs.rx_mcs_map));
  291. if (vhtc->vht_mcs.rx_highest)
  292. p += scnprintf(p, sizeof(buf)+buf-p,
  293. "MCS RX highest: %d Mbps\n",
  294. le16_to_cpu(vhtc->vht_mcs.rx_highest));
  295. p += scnprintf(p, sizeof(buf)+buf-p, "TX MCS: %.4x\n",
  296. le16_to_cpu(vhtc->vht_mcs.tx_mcs_map));
  297. if (vhtc->vht_mcs.tx_highest)
  298. p += scnprintf(p, sizeof(buf)+buf-p,
  299. "MCS TX highest: %d Mbps\n",
  300. le16_to_cpu(vhtc->vht_mcs.tx_highest));
  301. }
  302. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  303. }
  304. STA_OPS(vht_capa);
  305. static ssize_t sta_current_tx_rate_read(struct file *file, char __user *userbuf,
  306. size_t count, loff_t *ppos)
  307. {
  308. struct sta_info *sta = file->private_data;
  309. struct rate_info rinfo;
  310. u16 rate;
  311. sta_set_rate_info_tx(sta, &sta->last_tx_rate, &rinfo);
  312. rate = cfg80211_calculate_bitrate(&rinfo);
  313. return mac80211_format_buffer(userbuf, count, ppos,
  314. "%d.%d MBit/s\n",
  315. rate/10, rate%10);
  316. }
  317. STA_OPS(current_tx_rate);
  318. static ssize_t sta_last_rx_rate_read(struct file *file, char __user *userbuf,
  319. size_t count, loff_t *ppos)
  320. {
  321. struct sta_info *sta = file->private_data;
  322. struct rate_info rinfo;
  323. u16 rate;
  324. sta_set_rate_info_rx(sta, &rinfo);
  325. rate = cfg80211_calculate_bitrate(&rinfo);
  326. return mac80211_format_buffer(userbuf, count, ppos,
  327. "%d.%d MBit/s\n",
  328. rate/10, rate%10);
  329. }
  330. STA_OPS(last_rx_rate);
  331. #define DEBUGFS_ADD(name) \
  332. debugfs_create_file(#name, 0400, \
  333. sta->debugfs.dir, sta, &sta_ ##name## _ops);
  334. #define DEBUGFS_ADD_COUNTER(name, field) \
  335. if (sizeof(sta->field) == sizeof(u32)) \
  336. debugfs_create_u32(#name, 0400, sta->debugfs.dir, \
  337. (u32 *) &sta->field); \
  338. else \
  339. debugfs_create_u64(#name, 0400, sta->debugfs.dir, \
  340. (u64 *) &sta->field);
  341. void ieee80211_sta_debugfs_add(struct sta_info *sta)
  342. {
  343. struct ieee80211_local *local = sta->local;
  344. struct ieee80211_sub_if_data *sdata = sta->sdata;
  345. struct dentry *stations_dir = sta->sdata->debugfs.subdir_stations;
  346. u8 mac[3*ETH_ALEN];
  347. sta->debugfs.add_has_run = true;
  348. if (!stations_dir)
  349. return;
  350. snprintf(mac, sizeof(mac), "%pM", sta->sta.addr);
  351. /*
  352. * This might fail due to a race condition:
  353. * When mac80211 unlinks a station, the debugfs entries
  354. * remain, but it is already possible to link a new
  355. * station with the same address which triggers adding
  356. * it to debugfs; therefore, if the old station isn't
  357. * destroyed quickly enough the old station's debugfs
  358. * dir might still be around.
  359. */
  360. sta->debugfs.dir = debugfs_create_dir(mac, stations_dir);
  361. if (!sta->debugfs.dir)
  362. return;
  363. DEBUGFS_ADD(flags);
  364. DEBUGFS_ADD(num_ps_buf_frames);
  365. DEBUGFS_ADD(inactive_ms);
  366. DEBUGFS_ADD(connected_time);
  367. DEBUGFS_ADD(last_seq_ctrl);
  368. DEBUGFS_ADD(agg_status);
  369. DEBUGFS_ADD(dev);
  370. DEBUGFS_ADD(last_signal);
  371. DEBUGFS_ADD(beacon_loss_count);
  372. DEBUGFS_ADD(ht_capa);
  373. DEBUGFS_ADD(vht_capa);
  374. DEBUGFS_ADD(last_ack_signal);
  375. DEBUGFS_ADD(current_tx_rate);
  376. DEBUGFS_ADD(last_rx_rate);
  377. DEBUGFS_ADD_COUNTER(rx_packets, rx_packets);
  378. DEBUGFS_ADD_COUNTER(tx_packets, tx_packets);
  379. DEBUGFS_ADD_COUNTER(rx_bytes, rx_bytes);
  380. DEBUGFS_ADD_COUNTER(tx_bytes, tx_bytes);
  381. DEBUGFS_ADD_COUNTER(rx_duplicates, num_duplicates);
  382. DEBUGFS_ADD_COUNTER(rx_fragments, rx_fragments);
  383. DEBUGFS_ADD_COUNTER(rx_dropped, rx_dropped);
  384. DEBUGFS_ADD_COUNTER(tx_fragments, tx_fragments);
  385. DEBUGFS_ADD_COUNTER(tx_filtered, tx_filtered_count);
  386. DEBUGFS_ADD_COUNTER(tx_retry_failed, tx_retry_failed);
  387. DEBUGFS_ADD_COUNTER(tx_retry_count, tx_retry_count);
  388. if (sizeof(sta->driver_buffered_tids) == sizeof(u32))
  389. debugfs_create_x32("driver_buffered_tids", 0400,
  390. sta->debugfs.dir,
  391. (u32 *)&sta->driver_buffered_tids);
  392. else
  393. debugfs_create_x64("driver_buffered_tids", 0400,
  394. sta->debugfs.dir,
  395. (u64 *)&sta->driver_buffered_tids);
  396. drv_sta_add_debugfs(local, sdata, &sta->sta, sta->debugfs.dir);
  397. }
  398. void ieee80211_sta_debugfs_remove(struct sta_info *sta)
  399. {
  400. struct ieee80211_local *local = sta->local;
  401. struct ieee80211_sub_if_data *sdata = sta->sdata;
  402. drv_sta_remove_debugfs(local, sdata, &sta->sta, sta->debugfs.dir);
  403. debugfs_remove_recursive(sta->debugfs.dir);
  404. sta->debugfs.dir = NULL;
  405. }