2 * Copyright 2003-2005 Devicescape Software, Inc.
3 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
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.
11 #include <linux/debugfs.h>
12 #include <linux/ieee80211.h>
13 #include "ieee80211_i.h"
15 #include "debugfs_sta.h"
20 #define STA_READ(name, buflen, field, format_string) \
21 static ssize_t sta_ ##name## _read(struct file *file, \
22 char __user *userbuf, \
23 size_t count, loff_t *ppos) \
26 struct sta_info *sta = file->private_data; \
28 res = scnprintf(buf, buflen, format_string, sta->field); \
29 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
31 #define STA_READ_D(name, field) STA_READ(name, 20, field, "%d\n")
32 #define STA_READ_U(name, field) STA_READ(name, 20, field, "%u\n")
33 #define STA_READ_LU(name, field) STA_READ(name, 20, field, "%lu\n")
34 #define STA_READ_S(name, field) STA_READ(name, 20, field, "%s\n")
36 #define STA_READ_RATE(name, field) \
37 static ssize_t sta_##name##_read(struct file *file, \
38 char __user *userbuf, \
39 size_t count, loff_t *ppos) \
41 struct sta_info *sta = file->private_data; \
42 struct ieee80211_local *local = wdev_priv(sta->dev->ieee80211_ptr);\
43 struct ieee80211_hw_mode *mode = local->oper_hw_mode; \
45 int res = scnprintf(buf, sizeof(buf), "%d\n", \
47 sta->field < mode->num_rates) ? \
48 mode->rates[sta->field].rate : -1); \
49 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
52 #define STA_OPS(name) \
53 static const struct file_operations sta_ ##name## _ops = { \
54 .read = sta_##name##_read, \
55 .open = mac80211_open_file_generic, \
58 #define STA_OPS_WR(name) \
59 static const struct file_operations sta_ ##name## _ops = { \
60 .read = sta_##name##_read, \
61 .write = sta_##name##_write, \
62 .open = mac80211_open_file_generic, \
65 #define STA_FILE(name, field, format) \
66 STA_READ_##format(name, field) \
69 STA_FILE(aid, aid, D);
70 STA_FILE(dev, dev->name, S);
71 STA_FILE(rx_packets, rx_packets, LU);
72 STA_FILE(tx_packets, tx_packets, LU);
73 STA_FILE(rx_bytes, rx_bytes, LU);
74 STA_FILE(tx_bytes, tx_bytes, LU);
75 STA_FILE(rx_duplicates, num_duplicates, LU);
76 STA_FILE(rx_fragments, rx_fragments, LU);
77 STA_FILE(rx_dropped, rx_dropped, LU);
78 STA_FILE(tx_fragments, tx_fragments, LU);
79 STA_FILE(tx_filtered, tx_filtered_count, LU);
80 STA_FILE(txrate, txrate, RATE);
81 STA_FILE(last_txrate, last_txrate, RATE);
82 STA_FILE(tx_retry_failed, tx_retry_failed, LU);
83 STA_FILE(tx_retry_count, tx_retry_count, LU);
84 STA_FILE(last_rssi, last_rssi, D);
85 STA_FILE(last_signal, last_signal, D);
86 STA_FILE(last_noise, last_noise, D);
87 STA_FILE(channel_use, channel_use, D);
88 STA_FILE(wep_weak_iv_count, wep_weak_iv_count, D);
90 static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
91 size_t count, loff_t *ppos)
94 struct sta_info *sta = file->private_data;
95 int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s",
96 sta->flags & WLAN_STA_AUTH ? "AUTH\n" : "",
97 sta->flags & WLAN_STA_ASSOC ? "ASSOC\n" : "",
98 sta->flags & WLAN_STA_PS ? "PS\n" : "",
99 sta->flags & WLAN_STA_TIM ? "TIM\n" : "",
100 sta->flags & WLAN_STA_PERM ? "PERM\n" : "",
101 sta->flags & WLAN_STA_AUTHORIZED ? "AUTHORIZED\n" : "",
102 sta->flags & WLAN_STA_SHORT_PREAMBLE ? "SHORT PREAMBLE\n" : "",
103 sta->flags & WLAN_STA_WME ? "WME\n" : "",
104 sta->flags & WLAN_STA_WDS ? "WDS\n" : "");
105 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
109 static ssize_t sta_num_ps_buf_frames_read(struct file *file,
110 char __user *userbuf,
111 size_t count, loff_t *ppos)
114 struct sta_info *sta = file->private_data;
115 int res = scnprintf(buf, sizeof(buf), "%u\n",
116 skb_queue_len(&sta->ps_tx_buf));
117 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
119 STA_OPS(num_ps_buf_frames);
121 static ssize_t sta_last_ack_rssi_read(struct file *file, char __user *userbuf,
122 size_t count, loff_t *ppos)
125 struct sta_info *sta = file->private_data;
126 int res = scnprintf(buf, sizeof(buf), "%d %d %d\n",
127 sta->last_ack_rssi[0],
128 sta->last_ack_rssi[1],
129 sta->last_ack_rssi[2]);
130 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
132 STA_OPS(last_ack_rssi);
134 static ssize_t sta_last_ack_ms_read(struct file *file, char __user *userbuf,
135 size_t count, loff_t *ppos)
138 struct sta_info *sta = file->private_data;
139 int res = scnprintf(buf, sizeof(buf), "%d\n",
141 jiffies_to_msecs(jiffies - sta->last_ack) : -1);
142 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
144 STA_OPS(last_ack_ms);
146 static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf,
147 size_t count, loff_t *ppos)
150 struct sta_info *sta = file->private_data;
151 int res = scnprintf(buf, sizeof(buf), "%d\n",
152 jiffies_to_msecs(jiffies - sta->last_rx));
153 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
155 STA_OPS(inactive_ms);
157 static ssize_t sta_last_seq_ctrl_read(struct file *file, char __user *userbuf,
158 size_t count, loff_t *ppos)
160 char buf[15*NUM_RX_DATA_QUEUES], *p = buf;
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, "%x ",
165 le16_to_cpu(sta->last_seq_ctrl[i]));
166 p += scnprintf(p, sizeof(buf)+buf-p, "\n");
167 return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
169 STA_OPS(last_seq_ctrl);
171 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
172 static ssize_t sta_wme_rx_queue_read(struct file *file, char __user *userbuf,
173 size_t count, loff_t *ppos)
175 char buf[15*NUM_RX_DATA_QUEUES], *p = buf;
177 struct sta_info *sta = file->private_data;
178 for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
179 p += scnprintf(p, sizeof(buf)+buf-p, "%u ",
180 sta->wme_rx_queue[i]);
181 p += scnprintf(p, sizeof(buf)+buf-p, "\n");
182 return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
184 STA_OPS(wme_rx_queue);
186 static ssize_t sta_wme_tx_queue_read(struct file *file, char __user *userbuf,
187 size_t count, loff_t *ppos)
189 char buf[15*NUM_TX_DATA_QUEUES], *p = buf;
191 struct sta_info *sta = file->private_data;
192 for (i = 0; i < NUM_TX_DATA_QUEUES; i++)
193 p += scnprintf(p, sizeof(buf)+buf-p, "%u ",
194 sta->wme_tx_queue[i]);
195 p += scnprintf(p, sizeof(buf)+buf-p, "\n");
196 return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
198 STA_OPS(wme_tx_queue);
201 static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
202 size_t count, loff_t *ppos)
204 char buf[768], *p = buf;
206 struct sta_info *sta = file->private_data;
207 p += scnprintf(p, sizeof(buf)+buf-p, "Agg state for STA is:\n");
208 p += scnprintf(p, sizeof(buf)+buf-p, " STA next dialog_token is %d \n "
209 "TIDs info is: \n TID :",
210 (sta->ampdu_mlme.dialog_token_allocator + 1));
211 for (i = 0; i < STA_TID_NUM; i++)
212 p += scnprintf(p, sizeof(buf)+buf-p, "%5d", i);
214 p += scnprintf(p, sizeof(buf)+buf-p, "\n RX :");
215 for (i = 0; i < STA_TID_NUM; i++)
216 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
217 sta->ampdu_mlme.tid_rx[i].state);
219 p += scnprintf(p, sizeof(buf)+buf-p, "\n DTKN:");
220 for (i = 0; i < STA_TID_NUM; i++)
221 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
222 sta->ampdu_mlme.tid_rx[i].dialog_token);
224 p += scnprintf(p, sizeof(buf)+buf-p, "\n TX :");
225 for (i = 0; i < STA_TID_NUM; i++)
226 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
227 sta->ampdu_mlme.tid_tx[i].state);
229 p += scnprintf(p, sizeof(buf)+buf-p, "\n DTKN:");
230 for (i = 0; i < STA_TID_NUM; i++)
231 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
232 sta->ampdu_mlme.tid_tx[i].dialog_token);
234 p += scnprintf(p, sizeof(buf)+buf-p, "\n SSN :");
235 for (i = 0; i < STA_TID_NUM; i++)
236 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
237 sta->ampdu_mlme.tid_tx[i].ssn);
239 p += scnprintf(p, sizeof(buf)+buf-p, "\n");
241 return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
244 static ssize_t sta_agg_status_write(struct file *file,
245 const char __user *user_buf, size_t count, loff_t *ppos)
247 struct sta_info *sta = file->private_data;
248 struct net_device *dev = sta->dev;
249 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
250 struct ieee80211_hw *hw = &local->hw;
252 static int tid_static_tx[16] = {0, 0, 0, 0, 0, 0, 0, 0,
253 0, 0, 0, 0, 0, 0, 0, 0};
254 static int tid_static_rx[16] = {1, 1, 1, 1, 1, 1, 1, 1,
255 1, 1, 1, 1, 1, 1, 1, 1};
259 unsigned int tid_num;
262 memset(buf, 0x00, sizeof(buf));
263 buf_size = min(count, (sizeof(buf)-1));
264 if (copy_from_user(buf, user_buf, buf_size))
267 tid_num = simple_strtoul(buf, &endp, 0);
271 if ((tid_num >= 100) && (tid_num <= 115)) {
272 /* toggle Rx aggregation command */
273 tid_num = tid_num - 100;
274 if (tid_static_rx[tid_num] == 1) {
275 strcpy(state, "off ");
276 ieee80211_sta_stop_rx_ba_session(dev, da, tid_num, 0,
277 WLAN_REASON_QSTA_REQUIRE_SETUP);
278 sta->ampdu_mlme.tid_rx[tid_num].buf_size = 0xFF;
279 tid_static_rx[tid_num] = 0;
281 strcpy(state, "on ");
282 sta->ampdu_mlme.tid_rx[tid_num].buf_size = 0x00;
283 tid_static_rx[tid_num] = 1;
285 printk(KERN_DEBUG "debugfs - try switching tid %u %s\n",
287 } else if ((tid_num >= 0) && (tid_num <= 15)) {
288 /* toggle Tx aggregation command */
289 if (tid_static_tx[tid_num] == 0) {
290 strcpy(state, "on ");
291 rs = ieee80211_start_tx_ba_session(hw, da, tid_num);
293 tid_static_tx[tid_num] = 1;
295 strcpy(state, "off");
296 rs = ieee80211_stop_tx_ba_session(hw, da, tid_num, 1);
298 tid_static_tx[tid_num] = 0;
300 printk(KERN_DEBUG "debugfs - switching tid %u %s, return=%d\n",
306 STA_OPS_WR(agg_status);
308 #define DEBUGFS_ADD(name) \
309 sta->debugfs.name = debugfs_create_file(#name, 0444, \
310 sta->debugfs.dir, sta, &sta_ ##name## _ops);
312 #define DEBUGFS_DEL(name) \
313 debugfs_remove(sta->debugfs.name);\
314 sta->debugfs.name = NULL;
317 void ieee80211_sta_debugfs_add(struct sta_info *sta)
319 struct dentry *stations_dir = sta->local->debugfs.stations;
320 DECLARE_MAC_BUF(mac);
325 print_mac(mac, sta->addr);
327 sta->debugfs.dir = debugfs_create_dir(mac, stations_dir);
328 if (!sta->debugfs.dir)
332 DEBUGFS_ADD(num_ps_buf_frames);
333 DEBUGFS_ADD(last_ack_rssi);
334 DEBUGFS_ADD(last_ack_ms);
335 DEBUGFS_ADD(inactive_ms);
336 DEBUGFS_ADD(last_seq_ctrl);
337 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
338 DEBUGFS_ADD(wme_rx_queue);
339 DEBUGFS_ADD(wme_tx_queue);
341 DEBUGFS_ADD(agg_status);
344 void ieee80211_sta_debugfs_remove(struct sta_info *sta)
347 DEBUGFS_DEL(num_ps_buf_frames);
348 DEBUGFS_DEL(last_ack_rssi);
349 DEBUGFS_DEL(last_ack_ms);
350 DEBUGFS_DEL(inactive_ms);
351 DEBUGFS_DEL(last_seq_ctrl);
352 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
353 DEBUGFS_DEL(wme_rx_queue);
354 DEBUGFS_DEL(wme_tx_queue);
356 DEBUGFS_DEL(agg_status);
358 debugfs_remove(sta->debugfs.dir);
359 sta->debugfs.dir = NULL;