debugfs_sta.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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, 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. struct sta_info *sta = file->private_data; \
  23. return mac80211_format_buffer(userbuf, count, ppos, \
  24. format_string, sta->field); \
  25. }
  26. #define STA_READ_D(name, field) STA_READ(name, field, "%d\n")
  27. #define STA_READ_U(name, field) STA_READ(name, field, "%u\n")
  28. #define STA_READ_S(name, field) STA_READ(name, field, "%s\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(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[121];
  52. struct sta_info *sta = file->private_data;
  53. #define TEST(flg) \
  54. test_sta_flag(sta, WLAN_STA_##flg) ? #flg "\n" : ""
  55. int res = scnprintf(buf, sizeof(buf),
  56. "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
  57. TEST(AUTH), TEST(ASSOC), TEST(PS_STA),
  58. TEST(PS_DRIVER), TEST(AUTHORIZED),
  59. TEST(SHORT_PREAMBLE),
  60. TEST(WME), 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(4ADDR_EVENT),
  64. TEST(INSERTED), TEST(RATE_CONTROL),
  65. TEST(TOFFSET_KNOWN));
  66. #undef TEST
  67. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  68. }
  69. STA_OPS(flags);
  70. static ssize_t sta_num_ps_buf_frames_read(struct file *file,
  71. char __user *userbuf,
  72. size_t count, loff_t *ppos)
  73. {
  74. struct sta_info *sta = file->private_data;
  75. char buf[17*IEEE80211_NUM_ACS], *p = buf;
  76. int ac;
  77. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  78. p += scnprintf(p, sizeof(buf)+buf-p, "AC%d: %d\n", ac,
  79. skb_queue_len(&sta->ps_tx_buf[ac]) +
  80. skb_queue_len(&sta->tx_filtered[ac]));
  81. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  82. }
  83. STA_OPS(num_ps_buf_frames);
  84. static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf,
  85. size_t count, loff_t *ppos)
  86. {
  87. struct sta_info *sta = file->private_data;
  88. return mac80211_format_buffer(userbuf, count, ppos, "%d\n",
  89. jiffies_to_msecs(jiffies - sta->last_rx));
  90. }
  91. STA_OPS(inactive_ms);
  92. static ssize_t sta_connected_time_read(struct file *file, char __user *userbuf,
  93. size_t count, loff_t *ppos)
  94. {
  95. struct sta_info *sta = file->private_data;
  96. struct timespec uptime;
  97. struct tm result;
  98. long connected_time_secs;
  99. char buf[100];
  100. int res;
  101. do_posix_clock_monotonic_gettime(&uptime);
  102. connected_time_secs = uptime.tv_sec - sta->last_connected;
  103. time_to_tm(connected_time_secs, 0, &result);
  104. result.tm_year -= 70;
  105. result.tm_mday -= 1;
  106. res = scnprintf(buf, sizeof(buf),
  107. "years - %ld\nmonths - %d\ndays - %d\nclock - %d:%d:%d\n\n",
  108. result.tm_year, result.tm_mon, result.tm_mday,
  109. result.tm_hour, result.tm_min, result.tm_sec);
  110. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  111. }
  112. STA_OPS(connected_time);
  113. static ssize_t sta_last_seq_ctrl_read(struct file *file, char __user *userbuf,
  114. size_t count, loff_t *ppos)
  115. {
  116. char buf[15*NUM_RX_DATA_QUEUES], *p = buf;
  117. int i;
  118. struct sta_info *sta = file->private_data;
  119. for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
  120. p += scnprintf(p, sizeof(buf)+buf-p, "%x ",
  121. le16_to_cpu(sta->last_seq_ctrl[i]));
  122. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  123. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  124. }
  125. STA_OPS(last_seq_ctrl);
  126. static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
  127. size_t count, loff_t *ppos)
  128. {
  129. char buf[71 + STA_TID_NUM * 40], *p = buf;
  130. int i;
  131. struct sta_info *sta = file->private_data;
  132. struct tid_ampdu_rx *tid_rx;
  133. struct tid_ampdu_tx *tid_tx;
  134. rcu_read_lock();
  135. p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
  136. sta->ampdu_mlme.dialog_token_allocator + 1);
  137. p += scnprintf(p, sizeof(buf) + buf - p,
  138. "TID\t\tRX active\tDTKN\tSSN\t\tTX\tDTKN\tpending\n");
  139. for (i = 0; i < STA_TID_NUM; i++) {
  140. tid_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[i]);
  141. tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[i]);
  142. p += scnprintf(p, sizeof(buf) + buf - p, "%02d", i);
  143. p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x", !!tid_rx);
  144. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
  145. tid_rx ? tid_rx->dialog_token : 0);
  146. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.3x",
  147. tid_rx ? tid_rx->ssn : 0);
  148. p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x", !!tid_tx);
  149. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
  150. tid_tx ? tid_tx->dialog_token : 0);
  151. p += scnprintf(p, sizeof(buf) + buf - p, "\t%03d",
  152. tid_tx ? skb_queue_len(&tid_tx->pending) : 0);
  153. p += scnprintf(p, sizeof(buf) + buf - p, "\n");
  154. }
  155. rcu_read_unlock();
  156. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  157. }
  158. static ssize_t sta_agg_status_write(struct file *file, const char __user *userbuf,
  159. size_t count, loff_t *ppos)
  160. {
  161. char _buf[12], *buf = _buf;
  162. struct sta_info *sta = file->private_data;
  163. bool start, tx;
  164. unsigned long tid;
  165. int ret;
  166. if (count > sizeof(_buf))
  167. return -EINVAL;
  168. if (copy_from_user(buf, userbuf, count))
  169. return -EFAULT;
  170. buf[sizeof(_buf) - 1] = '\0';
  171. if (strncmp(buf, "tx ", 3) == 0) {
  172. buf += 3;
  173. tx = true;
  174. } else if (strncmp(buf, "rx ", 3) == 0) {
  175. buf += 3;
  176. tx = false;
  177. } else
  178. return -EINVAL;
  179. if (strncmp(buf, "start ", 6) == 0) {
  180. buf += 6;
  181. start = true;
  182. if (!tx)
  183. return -EINVAL;
  184. } else if (strncmp(buf, "stop ", 5) == 0) {
  185. buf += 5;
  186. start = false;
  187. } else
  188. return -EINVAL;
  189. tid = simple_strtoul(buf, NULL, 0);
  190. if (tid >= STA_TID_NUM)
  191. return -EINVAL;
  192. if (tx) {
  193. if (start)
  194. ret = ieee80211_start_tx_ba_session(&sta->sta, tid, 5000);
  195. else
  196. ret = ieee80211_stop_tx_ba_session(&sta->sta, tid);
  197. } else {
  198. __ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_RECIPIENT,
  199. 3, true);
  200. ret = 0;
  201. }
  202. return ret ?: count;
  203. }
  204. STA_OPS_RW(agg_status);
  205. static ssize_t sta_ht_capa_read(struct file *file, char __user *userbuf,
  206. size_t count, loff_t *ppos)
  207. {
  208. #define PRINT_HT_CAP(_cond, _str) \
  209. do { \
  210. if (_cond) \
  211. p += scnprintf(p, sizeof(buf)+buf-p, "\t" _str "\n"); \
  212. } while (0)
  213. char buf[512], *p = buf;
  214. int i;
  215. struct sta_info *sta = file->private_data;
  216. struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
  217. p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
  218. htc->ht_supported ? "" : "not ");
  219. if (htc->ht_supported) {
  220. p += scnprintf(p, sizeof(buf)+buf-p, "cap: %#.4x\n", htc->cap);
  221. PRINT_HT_CAP((htc->cap & BIT(0)), "RX LDPC");
  222. PRINT_HT_CAP((htc->cap & BIT(1)), "HT20/HT40");
  223. PRINT_HT_CAP(!(htc->cap & BIT(1)), "HT20");
  224. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 0, "Static SM Power Save");
  225. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 1, "Dynamic SM Power Save");
  226. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 3, "SM Power Save disabled");
  227. PRINT_HT_CAP((htc->cap & BIT(4)), "RX Greenfield");
  228. PRINT_HT_CAP((htc->cap & BIT(5)), "RX HT20 SGI");
  229. PRINT_HT_CAP((htc->cap & BIT(6)), "RX HT40 SGI");
  230. PRINT_HT_CAP((htc->cap & BIT(7)), "TX STBC");
  231. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 0, "No RX STBC");
  232. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 1, "RX STBC 1-stream");
  233. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 2, "RX STBC 2-streams");
  234. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 3, "RX STBC 3-streams");
  235. PRINT_HT_CAP((htc->cap & BIT(10)), "HT Delayed Block Ack");
  236. PRINT_HT_CAP(!(htc->cap & BIT(11)), "Max AMSDU length: "
  237. "3839 bytes");
  238. PRINT_HT_CAP((htc->cap & BIT(11)), "Max AMSDU length: "
  239. "7935 bytes");
  240. /*
  241. * For beacons and probe response this would mean the BSS
  242. * does or does not allow the usage of DSSS/CCK HT40.
  243. * Otherwise it means the STA does or does not use
  244. * DSSS/CCK HT40.
  245. */
  246. PRINT_HT_CAP((htc->cap & BIT(12)), "DSSS/CCK HT40");
  247. PRINT_HT_CAP(!(htc->cap & BIT(12)), "No DSSS/CCK HT40");
  248. /* BIT(13) is reserved */
  249. PRINT_HT_CAP((htc->cap & BIT(14)), "40 MHz Intolerant");
  250. PRINT_HT_CAP((htc->cap & BIT(15)), "L-SIG TXOP protection");
  251. p += scnprintf(p, sizeof(buf)+buf-p, "ampdu factor/density: %d/%d\n",
  252. htc->ampdu_factor, htc->ampdu_density);
  253. p += scnprintf(p, sizeof(buf)+buf-p, "MCS mask:");
  254. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
  255. p += scnprintf(p, sizeof(buf)+buf-p, " %.2x",
  256. htc->mcs.rx_mask[i]);
  257. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  258. /* If not set this is meaningless */
  259. if (le16_to_cpu(htc->mcs.rx_highest)) {
  260. p += scnprintf(p, sizeof(buf)+buf-p,
  261. "MCS rx highest: %d Mbps\n",
  262. le16_to_cpu(htc->mcs.rx_highest));
  263. }
  264. p += scnprintf(p, sizeof(buf)+buf-p, "MCS tx params: %x\n",
  265. htc->mcs.tx_params);
  266. }
  267. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  268. }
  269. STA_OPS(ht_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 dentry *stations_dir = sta->sdata->debugfs.subdir_stations;
  283. u8 mac[3*ETH_ALEN];
  284. sta->debugfs.add_has_run = true;
  285. if (!stations_dir)
  286. return;
  287. snprintf(mac, sizeof(mac), "%pM", sta->sta.addr);
  288. /*
  289. * This might fail due to a race condition:
  290. * When mac80211 unlinks a station, the debugfs entries
  291. * remain, but it is already possible to link a new
  292. * station with the same address which triggers adding
  293. * it to debugfs; therefore, if the old station isn't
  294. * destroyed quickly enough the old station's debugfs
  295. * dir might still be around.
  296. */
  297. sta->debugfs.dir = debugfs_create_dir(mac, stations_dir);
  298. if (!sta->debugfs.dir)
  299. return;
  300. DEBUGFS_ADD(flags);
  301. DEBUGFS_ADD(num_ps_buf_frames);
  302. DEBUGFS_ADD(inactive_ms);
  303. DEBUGFS_ADD(connected_time);
  304. DEBUGFS_ADD(last_seq_ctrl);
  305. DEBUGFS_ADD(agg_status);
  306. DEBUGFS_ADD(dev);
  307. DEBUGFS_ADD(last_signal);
  308. DEBUGFS_ADD(ht_capa);
  309. DEBUGFS_ADD_COUNTER(rx_packets, rx_packets);
  310. DEBUGFS_ADD_COUNTER(tx_packets, tx_packets);
  311. DEBUGFS_ADD_COUNTER(rx_bytes, rx_bytes);
  312. DEBUGFS_ADD_COUNTER(tx_bytes, tx_bytes);
  313. DEBUGFS_ADD_COUNTER(rx_duplicates, num_duplicates);
  314. DEBUGFS_ADD_COUNTER(rx_fragments, rx_fragments);
  315. DEBUGFS_ADD_COUNTER(rx_dropped, rx_dropped);
  316. DEBUGFS_ADD_COUNTER(tx_fragments, tx_fragments);
  317. DEBUGFS_ADD_COUNTER(tx_filtered, tx_filtered_count);
  318. DEBUGFS_ADD_COUNTER(tx_retry_failed, tx_retry_failed);
  319. DEBUGFS_ADD_COUNTER(tx_retry_count, tx_retry_count);
  320. DEBUGFS_ADD_COUNTER(wep_weak_iv_count, wep_weak_iv_count);
  321. }
  322. void ieee80211_sta_debugfs_remove(struct sta_info *sta)
  323. {
  324. debugfs_remove_recursive(sta->debugfs.dir);
  325. sta->debugfs.dir = NULL;
  326. }