debugfs_sta.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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_WR(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, aid, D);
  47. STA_FILE(dev, dev->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_rssi, last_rssi, D);
  60. STA_FILE(last_signal, last_signal, D);
  61. STA_FILE(last_noise, last_noise, D);
  62. STA_FILE(channel_use, channel_use, D);
  63. STA_FILE(wep_weak_iv_count, wep_weak_iv_count, D);
  64. static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
  65. size_t count, loff_t *ppos)
  66. {
  67. char buf[100];
  68. struct sta_info *sta = file->private_data;
  69. int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s",
  70. sta->flags & WLAN_STA_AUTH ? "AUTH\n" : "",
  71. sta->flags & WLAN_STA_ASSOC ? "ASSOC\n" : "",
  72. sta->flags & WLAN_STA_PS ? "PS\n" : "",
  73. sta->flags & WLAN_STA_TIM ? "TIM\n" : "",
  74. sta->flags & WLAN_STA_PERM ? "PERM\n" : "",
  75. sta->flags & WLAN_STA_AUTHORIZED ? "AUTHORIZED\n" : "",
  76. sta->flags & WLAN_STA_SHORT_PREAMBLE ? "SHORT PREAMBLE\n" : "",
  77. sta->flags & WLAN_STA_WME ? "WME\n" : "",
  78. sta->flags & WLAN_STA_WDS ? "WDS\n" : "");
  79. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  80. }
  81. STA_OPS(flags);
  82. static ssize_t sta_num_ps_buf_frames_read(struct file *file,
  83. char __user *userbuf,
  84. size_t count, loff_t *ppos)
  85. {
  86. char buf[20];
  87. struct sta_info *sta = file->private_data;
  88. int res = scnprintf(buf, sizeof(buf), "%u\n",
  89. skb_queue_len(&sta->ps_tx_buf));
  90. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  91. }
  92. STA_OPS(num_ps_buf_frames);
  93. static ssize_t sta_last_ack_rssi_read(struct file *file, char __user *userbuf,
  94. size_t count, loff_t *ppos)
  95. {
  96. char buf[100];
  97. struct sta_info *sta = file->private_data;
  98. int res = scnprintf(buf, sizeof(buf), "%d %d %d\n",
  99. sta->last_ack_rssi[0],
  100. sta->last_ack_rssi[1],
  101. sta->last_ack_rssi[2]);
  102. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  103. }
  104. STA_OPS(last_ack_rssi);
  105. static ssize_t sta_last_ack_ms_read(struct file *file, char __user *userbuf,
  106. size_t count, loff_t *ppos)
  107. {
  108. char buf[20];
  109. struct sta_info *sta = file->private_data;
  110. int res = scnprintf(buf, sizeof(buf), "%d\n",
  111. sta->last_ack ?
  112. jiffies_to_msecs(jiffies - sta->last_ack) : -1);
  113. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  114. }
  115. STA_OPS(last_ack_ms);
  116. static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf,
  117. size_t count, loff_t *ppos)
  118. {
  119. char buf[20];
  120. struct sta_info *sta = file->private_data;
  121. int res = scnprintf(buf, sizeof(buf), "%d\n",
  122. jiffies_to_msecs(jiffies - sta->last_rx));
  123. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  124. }
  125. STA_OPS(inactive_ms);
  126. static ssize_t sta_last_seq_ctrl_read(struct file *file, char __user *userbuf,
  127. size_t count, loff_t *ppos)
  128. {
  129. char buf[15*NUM_RX_DATA_QUEUES], *p = buf;
  130. int i;
  131. struct sta_info *sta = file->private_data;
  132. for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
  133. p += scnprintf(p, sizeof(buf)+buf-p, "%x ",
  134. le16_to_cpu(sta->last_seq_ctrl[i]));
  135. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  136. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  137. }
  138. STA_OPS(last_seq_ctrl);
  139. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  140. static ssize_t sta_wme_rx_queue_read(struct file *file, char __user *userbuf,
  141. size_t count, loff_t *ppos)
  142. {
  143. char buf[15*NUM_RX_DATA_QUEUES], *p = buf;
  144. int i;
  145. struct sta_info *sta = file->private_data;
  146. for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
  147. p += scnprintf(p, sizeof(buf)+buf-p, "%u ",
  148. sta->wme_rx_queue[i]);
  149. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  150. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  151. }
  152. STA_OPS(wme_rx_queue);
  153. static ssize_t sta_wme_tx_queue_read(struct file *file, char __user *userbuf,
  154. size_t count, loff_t *ppos)
  155. {
  156. char buf[15*NUM_TX_DATA_QUEUES], *p = buf;
  157. int i;
  158. struct sta_info *sta = file->private_data;
  159. for (i = 0; i < NUM_TX_DATA_QUEUES; i++)
  160. p += scnprintf(p, sizeof(buf)+buf-p, "%u ",
  161. sta->wme_tx_queue[i]);
  162. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  163. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  164. }
  165. STA_OPS(wme_tx_queue);
  166. #endif
  167. static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
  168. size_t count, loff_t *ppos)
  169. {
  170. char buf[768], *p = buf;
  171. int i;
  172. struct sta_info *sta = file->private_data;
  173. p += scnprintf(p, sizeof(buf)+buf-p, "Agg state for STA is:\n");
  174. p += scnprintf(p, sizeof(buf)+buf-p, " STA next dialog_token is %d \n "
  175. "TIDs info is: \n TID :",
  176. (sta->ampdu_mlme.dialog_token_allocator + 1));
  177. for (i = 0; i < STA_TID_NUM; i++)
  178. p += scnprintf(p, sizeof(buf)+buf-p, "%5d", i);
  179. p += scnprintf(p, sizeof(buf)+buf-p, "\n RX :");
  180. for (i = 0; i < STA_TID_NUM; i++)
  181. p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
  182. sta->ampdu_mlme.tid_rx[i].state);
  183. p += scnprintf(p, sizeof(buf)+buf-p, "\n DTKN:");
  184. for (i = 0; i < STA_TID_NUM; i++)
  185. p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
  186. sta->ampdu_mlme.tid_rx[i].dialog_token);
  187. p += scnprintf(p, sizeof(buf)+buf-p, "\n TX :");
  188. for (i = 0; i < STA_TID_NUM; i++)
  189. p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
  190. sta->ampdu_mlme.tid_tx[i].state);
  191. p += scnprintf(p, sizeof(buf)+buf-p, "\n DTKN:");
  192. for (i = 0; i < STA_TID_NUM; i++)
  193. p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
  194. sta->ampdu_mlme.tid_tx[i].dialog_token);
  195. p += scnprintf(p, sizeof(buf)+buf-p, "\n SSN :");
  196. for (i = 0; i < STA_TID_NUM; i++)
  197. p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
  198. sta->ampdu_mlme.tid_tx[i].ssn);
  199. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  200. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  201. }
  202. static ssize_t sta_agg_status_write(struct file *file,
  203. const char __user *user_buf, size_t count, loff_t *ppos)
  204. {
  205. struct sta_info *sta = file->private_data;
  206. struct net_device *dev = sta->dev;
  207. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  208. struct ieee80211_hw *hw = &local->hw;
  209. u8 *da = sta->addr;
  210. static int tid_static_tx[16] = {0, 0, 0, 0, 0, 0, 0, 0,
  211. 0, 0, 0, 0, 0, 0, 0, 0};
  212. static int tid_static_rx[16] = {1, 1, 1, 1, 1, 1, 1, 1,
  213. 1, 1, 1, 1, 1, 1, 1, 1};
  214. char *endp;
  215. char buf[32];
  216. int buf_size, rs;
  217. unsigned int tid_num;
  218. char state[4];
  219. memset(buf, 0x00, sizeof(buf));
  220. buf_size = min(count, (sizeof(buf)-1));
  221. if (copy_from_user(buf, user_buf, buf_size))
  222. return -EFAULT;
  223. tid_num = simple_strtoul(buf, &endp, 0);
  224. if (endp == buf)
  225. return -EINVAL;
  226. if ((tid_num >= 100) && (tid_num <= 115)) {
  227. /* toggle Rx aggregation command */
  228. tid_num = tid_num - 100;
  229. if (tid_static_rx[tid_num] == 1) {
  230. strcpy(state, "off ");
  231. ieee80211_sta_stop_rx_ba_session(dev, da, tid_num, 0,
  232. WLAN_REASON_QSTA_REQUIRE_SETUP);
  233. sta->ampdu_mlme.tid_rx[tid_num].buf_size = 0xFF;
  234. tid_static_rx[tid_num] = 0;
  235. } else {
  236. strcpy(state, "on ");
  237. sta->ampdu_mlme.tid_rx[tid_num].buf_size = 0x00;
  238. tid_static_rx[tid_num] = 1;
  239. }
  240. printk(KERN_DEBUG "debugfs - try switching tid %u %s\n",
  241. tid_num, state);
  242. } else if ((tid_num >= 0) && (tid_num <= 15)) {
  243. /* toggle Tx aggregation command */
  244. if (tid_static_tx[tid_num] == 0) {
  245. strcpy(state, "on ");
  246. rs = ieee80211_start_tx_ba_session(hw, da, tid_num);
  247. if (rs == 0)
  248. tid_static_tx[tid_num] = 1;
  249. } else {
  250. strcpy(state, "off");
  251. rs = ieee80211_stop_tx_ba_session(hw, da, tid_num, 1);
  252. if (rs == 0)
  253. tid_static_tx[tid_num] = 0;
  254. }
  255. printk(KERN_DEBUG "debugfs - switching tid %u %s, return=%d\n",
  256. tid_num, state, rs);
  257. }
  258. return count;
  259. }
  260. STA_OPS_WR(agg_status);
  261. #define DEBUGFS_ADD(name) \
  262. sta->debugfs.name = debugfs_create_file(#name, 0444, \
  263. sta->debugfs.dir, sta, &sta_ ##name## _ops);
  264. #define DEBUGFS_DEL(name) \
  265. debugfs_remove(sta->debugfs.name);\
  266. sta->debugfs.name = NULL;
  267. void ieee80211_sta_debugfs_add(struct sta_info *sta)
  268. {
  269. struct dentry *stations_dir = sta->local->debugfs.stations;
  270. DECLARE_MAC_BUF(mac);
  271. if (!stations_dir)
  272. return;
  273. print_mac(mac, sta->addr);
  274. sta->debugfs.dir = debugfs_create_dir(mac, stations_dir);
  275. if (!sta->debugfs.dir)
  276. return;
  277. DEBUGFS_ADD(flags);
  278. DEBUGFS_ADD(num_ps_buf_frames);
  279. DEBUGFS_ADD(last_ack_rssi);
  280. DEBUGFS_ADD(last_ack_ms);
  281. DEBUGFS_ADD(inactive_ms);
  282. DEBUGFS_ADD(last_seq_ctrl);
  283. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  284. DEBUGFS_ADD(wme_rx_queue);
  285. DEBUGFS_ADD(wme_tx_queue);
  286. #endif
  287. DEBUGFS_ADD(agg_status);
  288. }
  289. void ieee80211_sta_debugfs_remove(struct sta_info *sta)
  290. {
  291. DEBUGFS_DEL(flags);
  292. DEBUGFS_DEL(num_ps_buf_frames);
  293. DEBUGFS_DEL(last_ack_rssi);
  294. DEBUGFS_DEL(last_ack_ms);
  295. DEBUGFS_DEL(inactive_ms);
  296. DEBUGFS_DEL(last_seq_ctrl);
  297. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  298. DEBUGFS_DEL(wme_rx_queue);
  299. DEBUGFS_DEL(wme_tx_queue);
  300. #endif
  301. DEBUGFS_DEL(agg_status);
  302. debugfs_remove(sta->debugfs.dir);
  303. sta->debugfs.dir = NULL;
  304. }