debugfs_sta.c 11 KB

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