debugfs_sta.c 14 KB

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