debugfs_sta.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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, buflen, 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. int res; \
  23. struct sta_info *sta = file->private_data; \
  24. char buf[buflen]; \
  25. res = scnprintf(buf, buflen, format_string, sta->field); \
  26. return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
  27. }
  28. #define STA_READ_D(name, field) STA_READ(name, 20, field, "%d\n")
  29. #define STA_READ_U(name, field) STA_READ(name, 20, field, "%u\n")
  30. #define STA_READ_LU(name, field) STA_READ(name, 20, field, "%lu\n")
  31. #define STA_READ_S(name, field) STA_READ(name, 20, field, "%s\n")
  32. #define STA_OPS(name) \
  33. static const struct file_operations sta_ ##name## _ops = { \
  34. .read = sta_##name##_read, \
  35. .open = mac80211_open_file_generic, \
  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 = mac80211_open_file_generic, \
  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(rx_packets, rx_packets, LU);
  49. STA_FILE(tx_packets, tx_packets, LU);
  50. STA_FILE(rx_bytes, rx_bytes, LU);
  51. STA_FILE(tx_bytes, tx_bytes, LU);
  52. STA_FILE(rx_duplicates, num_duplicates, LU);
  53. STA_FILE(rx_fragments, rx_fragments, LU);
  54. STA_FILE(rx_dropped, rx_dropped, LU);
  55. STA_FILE(tx_fragments, tx_fragments, LU);
  56. STA_FILE(tx_filtered, tx_filtered_count, LU);
  57. STA_FILE(tx_retry_failed, tx_retry_failed, LU);
  58. STA_FILE(tx_retry_count, tx_retry_count, LU);
  59. STA_FILE(last_signal, last_signal, D);
  60. STA_FILE(wep_weak_iv_count, wep_weak_iv_count, LU);
  61. static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
  62. size_t count, loff_t *ppos)
  63. {
  64. char buf[100];
  65. struct sta_info *sta = file->private_data;
  66. u32 staflags = get_sta_flags(sta);
  67. int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s",
  68. staflags & WLAN_STA_AUTH ? "AUTH\n" : "",
  69. staflags & WLAN_STA_ASSOC ? "ASSOC\n" : "",
  70. staflags & WLAN_STA_PS_STA ? "PS (sta)\n" : "",
  71. staflags & WLAN_STA_PS_DRIVER ? "PS (driver)\n" : "",
  72. staflags & WLAN_STA_AUTHORIZED ? "AUTHORIZED\n" : "",
  73. staflags & WLAN_STA_SHORT_PREAMBLE ? "SHORT PREAMBLE\n" : "",
  74. staflags & WLAN_STA_WME ? "WME\n" : "",
  75. staflags & WLAN_STA_WDS ? "WDS\n" : "",
  76. staflags & WLAN_STA_MFP ? "MFP\n" : "");
  77. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  78. }
  79. STA_OPS(flags);
  80. static ssize_t sta_num_ps_buf_frames_read(struct file *file,
  81. char __user *userbuf,
  82. size_t count, loff_t *ppos)
  83. {
  84. char buf[20];
  85. struct sta_info *sta = file->private_data;
  86. int res = scnprintf(buf, sizeof(buf), "%u\n",
  87. skb_queue_len(&sta->ps_tx_buf));
  88. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  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. char buf[20];
  95. struct sta_info *sta = file->private_data;
  96. int res = scnprintf(buf, sizeof(buf), "%d\n",
  97. jiffies_to_msecs(jiffies - sta->last_rx));
  98. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  99. }
  100. STA_OPS(inactive_ms);
  101. static ssize_t sta_last_seq_ctrl_read(struct file *file, char __user *userbuf,
  102. size_t count, loff_t *ppos)
  103. {
  104. char buf[15*NUM_RX_DATA_QUEUES], *p = buf;
  105. int i;
  106. struct sta_info *sta = file->private_data;
  107. for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
  108. p += scnprintf(p, sizeof(buf)+buf-p, "%x ",
  109. le16_to_cpu(sta->last_seq_ctrl[i]));
  110. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  111. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  112. }
  113. STA_OPS(last_seq_ctrl);
  114. static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
  115. size_t count, loff_t *ppos)
  116. {
  117. char buf[71 + STA_TID_NUM * 40], *p = buf;
  118. int i;
  119. struct sta_info *sta = file->private_data;
  120. spin_lock_bh(&sta->lock);
  121. p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
  122. sta->ampdu_mlme.dialog_token_allocator + 1);
  123. p += scnprintf(p, sizeof(buf) + buf - p,
  124. "TID\t\tRX active\tDTKN\tSSN\t\tTX\tDTKN\tSSN\tpending\n");
  125. for (i = 0; i < STA_TID_NUM; i++) {
  126. p += scnprintf(p, sizeof(buf) + buf - p, "%02d", i);
  127. p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x",
  128. sta->ampdu_mlme.tid_active_rx[i]);
  129. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
  130. sta->ampdu_mlme.tid_active_rx[i] ?
  131. sta->ampdu_mlme.tid_rx[i]->dialog_token : 0);
  132. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.3x",
  133. sta->ampdu_mlme.tid_active_rx[i] ?
  134. sta->ampdu_mlme.tid_rx[i]->ssn : 0);
  135. p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x",
  136. sta->ampdu_mlme.tid_state_tx[i]);
  137. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
  138. sta->ampdu_mlme.tid_state_tx[i] ?
  139. sta->ampdu_mlme.tid_tx[i]->dialog_token : 0);
  140. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.3x",
  141. sta->ampdu_mlme.tid_state_tx[i] ?
  142. sta->ampdu_mlme.tid_tx[i]->ssn : 0);
  143. p += scnprintf(p, sizeof(buf) + buf - p, "\t%03d",
  144. sta->ampdu_mlme.tid_state_tx[i] ?
  145. skb_queue_len(&sta->ampdu_mlme.tid_tx[i]->pending) : 0);
  146. p += scnprintf(p, sizeof(buf) + buf - p, "\n");
  147. }
  148. spin_unlock_bh(&sta->lock);
  149. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  150. }
  151. static ssize_t sta_agg_status_write(struct file *file, const char __user *userbuf,
  152. size_t count, loff_t *ppos)
  153. {
  154. char _buf[12], *buf = _buf;
  155. struct sta_info *sta = file->private_data;
  156. bool start, tx;
  157. unsigned long tid;
  158. int ret;
  159. if (count > sizeof(_buf))
  160. return -EINVAL;
  161. if (copy_from_user(buf, userbuf, count))
  162. return -EFAULT;
  163. buf[sizeof(_buf) - 1] = '\0';
  164. if (strncmp(buf, "tx ", 3) == 0) {
  165. buf += 3;
  166. tx = true;
  167. } else if (strncmp(buf, "rx ", 3) == 0) {
  168. buf += 3;
  169. tx = false;
  170. } else
  171. return -EINVAL;
  172. if (strncmp(buf, "start ", 6) == 0) {
  173. buf += 6;
  174. start = true;
  175. if (!tx)
  176. return -EINVAL;
  177. } else if (strncmp(buf, "stop ", 5) == 0) {
  178. buf += 5;
  179. start = false;
  180. } else
  181. return -EINVAL;
  182. tid = simple_strtoul(buf, NULL, 0);
  183. if (tid >= STA_TID_NUM)
  184. return -EINVAL;
  185. if (tx) {
  186. if (start)
  187. ret = ieee80211_start_tx_ba_session(&sta->sta, tid);
  188. else
  189. ret = ieee80211_stop_tx_ba_session(&sta->sta, tid,
  190. WLAN_BACK_RECIPIENT);
  191. } else {
  192. __ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_RECIPIENT, 3);
  193. ret = 0;
  194. }
  195. return ret ?: count;
  196. }
  197. STA_OPS_RW(agg_status);
  198. static ssize_t sta_ht_capa_read(struct file *file, char __user *userbuf,
  199. size_t count, loff_t *ppos)
  200. {
  201. #define PRINT_HT_CAP(_cond, _str) \
  202. do { \
  203. if (_cond) \
  204. p += scnprintf(p, sizeof(buf)+buf-p, "\t" _str "\n"); \
  205. } while (0)
  206. char buf[512], *p = buf;
  207. int i;
  208. struct sta_info *sta = file->private_data;
  209. struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
  210. p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
  211. htc->ht_supported ? "" : "not ");
  212. if (htc->ht_supported) {
  213. p += scnprintf(p, sizeof(buf)+buf-p, "cap: %#.4x\n", htc->cap);
  214. PRINT_HT_CAP((htc->cap & BIT(0)), "RX LDPC");
  215. PRINT_HT_CAP((htc->cap & BIT(1)), "HT20/HT40");
  216. PRINT_HT_CAP(!(htc->cap & BIT(1)), "HT20");
  217. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 0, "Static SM Power Save");
  218. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 1, "Dynamic SM Power Save");
  219. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 3, "SM Power Save disabled");
  220. PRINT_HT_CAP((htc->cap & BIT(4)), "RX Greenfield");
  221. PRINT_HT_CAP((htc->cap & BIT(5)), "RX HT20 SGI");
  222. PRINT_HT_CAP((htc->cap & BIT(6)), "RX HT40 SGI");
  223. PRINT_HT_CAP((htc->cap & BIT(7)), "TX STBC");
  224. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 0, "No RX STBC");
  225. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 1, "RX STBC 1-stream");
  226. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 2, "RX STBC 2-streams");
  227. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 3, "RX STBC 3-streams");
  228. PRINT_HT_CAP((htc->cap & BIT(10)), "HT Delayed Block Ack");
  229. PRINT_HT_CAP((htc->cap & BIT(11)), "Max AMSDU length: "
  230. "3839 bytes");
  231. PRINT_HT_CAP(!(htc->cap & BIT(11)), "Max AMSDU length: "
  232. "7935 bytes");
  233. /*
  234. * For beacons and probe response this would mean the BSS
  235. * does or does not allow the usage of DSSS/CCK HT40.
  236. * Otherwise it means the STA does or does not use
  237. * DSSS/CCK HT40.
  238. */
  239. PRINT_HT_CAP((htc->cap & BIT(12)), "DSSS/CCK HT40");
  240. PRINT_HT_CAP(!(htc->cap & BIT(12)), "No DSSS/CCK HT40");
  241. /* BIT(13) is reserved */
  242. PRINT_HT_CAP((htc->cap & BIT(14)), "40 MHz Intolerant");
  243. PRINT_HT_CAP((htc->cap & BIT(15)), "L-SIG TXOP protection");
  244. p += scnprintf(p, sizeof(buf)+buf-p, "ampdu factor/density: %d/%d\n",
  245. htc->ampdu_factor, htc->ampdu_density);
  246. p += scnprintf(p, sizeof(buf)+buf-p, "MCS mask:");
  247. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
  248. p += scnprintf(p, sizeof(buf)+buf-p, " %.2x",
  249. htc->mcs.rx_mask[i]);
  250. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  251. /* If not set this is meaningless */
  252. if (le16_to_cpu(htc->mcs.rx_highest)) {
  253. p += scnprintf(p, sizeof(buf)+buf-p,
  254. "MCS rx highest: %d Mbps\n",
  255. le16_to_cpu(htc->mcs.rx_highest));
  256. }
  257. p += scnprintf(p, sizeof(buf)+buf-p, "MCS tx params: %x\n",
  258. htc->mcs.tx_params);
  259. }
  260. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  261. }
  262. STA_OPS(ht_capa);
  263. #define DEBUGFS_ADD(name) \
  264. debugfs_create_file(#name, 0400, \
  265. sta->debugfs.dir, sta, &sta_ ##name## _ops);
  266. void ieee80211_sta_debugfs_add(struct sta_info *sta)
  267. {
  268. struct dentry *stations_dir = sta->local->debugfs.stations;
  269. u8 mac[3*ETH_ALEN];
  270. sta->debugfs.add_has_run = true;
  271. if (!stations_dir)
  272. return;
  273. snprintf(mac, sizeof(mac), "%pM", sta->sta.addr);
  274. /*
  275. * This might fail due to a race condition:
  276. * When mac80211 unlinks a station, the debugfs entries
  277. * remain, but it is already possible to link a new
  278. * station with the same address which triggers adding
  279. * it to debugfs; therefore, if the old station isn't
  280. * destroyed quickly enough the old station's debugfs
  281. * dir might still be around.
  282. */
  283. sta->debugfs.dir = debugfs_create_dir(mac, stations_dir);
  284. if (!sta->debugfs.dir)
  285. return;
  286. DEBUGFS_ADD(flags);
  287. DEBUGFS_ADD(num_ps_buf_frames);
  288. DEBUGFS_ADD(inactive_ms);
  289. DEBUGFS_ADD(last_seq_ctrl);
  290. DEBUGFS_ADD(agg_status);
  291. DEBUGFS_ADD(dev);
  292. DEBUGFS_ADD(rx_packets);
  293. DEBUGFS_ADD(tx_packets);
  294. DEBUGFS_ADD(rx_bytes);
  295. DEBUGFS_ADD(tx_bytes);
  296. DEBUGFS_ADD(rx_duplicates);
  297. DEBUGFS_ADD(rx_fragments);
  298. DEBUGFS_ADD(rx_dropped);
  299. DEBUGFS_ADD(tx_fragments);
  300. DEBUGFS_ADD(tx_filtered);
  301. DEBUGFS_ADD(tx_retry_failed);
  302. DEBUGFS_ADD(tx_retry_count);
  303. DEBUGFS_ADD(last_signal);
  304. DEBUGFS_ADD(wep_weak_iv_count);
  305. DEBUGFS_ADD(ht_capa);
  306. }
  307. void ieee80211_sta_debugfs_remove(struct sta_info *sta)
  308. {
  309. debugfs_remove_recursive(sta->debugfs.dir);
  310. sta->debugfs.dir = NULL;
  311. }