]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - net/mac80211/debugfs_sta.c
mac80211: A-MPDU add debugfs support
[linux-2.6-omap-h63xx.git] / net / mac80211 / debugfs_sta.c
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
11 #include <linux/debugfs.h>
12 #include <linux/ieee80211.h>
13 #include "ieee80211_i.h"
14 #include "debugfs.h"
15 #include "debugfs_sta.h"
16 #include "sta_info.h"
17
18 /* sta attributtes */
19
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)          \
24 {                                                                       \
25         int res;                                                        \
26         struct sta_info *sta = file->private_data;                      \
27         char buf[buflen];                                               \
28         res = scnprintf(buf, buflen, format_string, sta->field);        \
29         return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
30 }
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")
35
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)            \
40 {                                                                       \
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;           \
44         char buf[20];                                                   \
45         int res = scnprintf(buf, sizeof(buf), "%d\n",                   \
46                             (sta->field >= 0 &&                         \
47                             sta->field < mode->num_rates) ?             \
48                             mode->rates[sta->field].rate : -1);         \
49         return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
50 }
51
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,                             \
56 }
57
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,                             \
63 }
64
65 #define STA_FILE(name, field, format)                                   \
66                 STA_READ_##format(name, field)                          \
67                 STA_OPS(name)
68
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);
89
90 static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
91                               size_t count, loff_t *ppos)
92 {
93         char buf[100];
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);
106 }
107 STA_OPS(flags);
108
109 static ssize_t sta_num_ps_buf_frames_read(struct file *file,
110                                           char __user *userbuf,
111                                           size_t count, loff_t *ppos)
112 {
113         char buf[20];
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);
118 }
119 STA_OPS(num_ps_buf_frames);
120
121 static ssize_t sta_last_ack_rssi_read(struct file *file, char __user *userbuf,
122                                       size_t count, loff_t *ppos)
123 {
124         char buf[100];
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);
131 }
132 STA_OPS(last_ack_rssi);
133
134 static ssize_t sta_last_ack_ms_read(struct file *file, char __user *userbuf,
135                                     size_t count, loff_t *ppos)
136 {
137         char buf[20];
138         struct sta_info *sta = file->private_data;
139         int res = scnprintf(buf, sizeof(buf), "%d\n",
140                             sta->last_ack ?
141                             jiffies_to_msecs(jiffies - sta->last_ack) : -1);
142         return simple_read_from_buffer(userbuf, count, ppos, buf, res);
143 }
144 STA_OPS(last_ack_ms);
145
146 static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf,
147                                     size_t count, loff_t *ppos)
148 {
149         char buf[20];
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);
154 }
155 STA_OPS(inactive_ms);
156
157 static ssize_t sta_last_seq_ctrl_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, "%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);
168 }
169 STA_OPS(last_seq_ctrl);
170
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)
174 {
175         char buf[15*NUM_RX_DATA_QUEUES], *p = buf;
176         int i;
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);
183 }
184 STA_OPS(wme_rx_queue);
185
186 static ssize_t sta_wme_tx_queue_read(struct file *file, char __user *userbuf,
187                                      size_t count, loff_t *ppos)
188 {
189         char buf[15*NUM_TX_DATA_QUEUES], *p = buf;
190         int i;
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);
197 }
198 STA_OPS(wme_tx_queue);
199 #endif
200
201 static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
202                                         size_t count, loff_t *ppos)
203 {
204         char buf[768], *p = buf;
205         int i;
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);
213
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);
218
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);
223
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);
228
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);
233
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);
238
239         p += scnprintf(p, sizeof(buf)+buf-p, "\n");
240
241         return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
242 }
243
244 static ssize_t sta_agg_status_write(struct file *file,
245                 const char __user *user_buf, size_t count, loff_t *ppos)
246 {
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;
251         u8 *da = sta->addr;
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};
256         char *endp;
257         char buf[32];
258         int buf_size, rs;
259         unsigned int tid_num;
260         char state[4];
261
262         memset(buf, 0x00, sizeof(buf));
263         buf_size = min(count, (sizeof(buf)-1));
264         if (copy_from_user(buf, user_buf, buf_size))
265                 return -EFAULT;
266
267         tid_num = simple_strtoul(buf, &endp, 0);
268         if (endp == buf)
269                 return -EINVAL;
270
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;
280                 } else {
281                         strcpy(state, "on ");
282                         sta->ampdu_mlme.tid_rx[tid_num].buf_size = 0x00;
283                         tid_static_rx[tid_num] = 1;
284                 }
285                 printk(KERN_DEBUG "debugfs - try switching tid %u %s\n",
286                                 tid_num, state);
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);
292                         if (rs == 0)
293                                 tid_static_tx[tid_num] = 1;
294                 } else {
295                         strcpy(state, "off");
296                         rs =  ieee80211_stop_tx_ba_session(hw, da, tid_num, 1);
297                         if (rs == 0)
298                                 tid_static_tx[tid_num] = 0;
299                 }
300                 printk(KERN_DEBUG "debugfs - switching tid %u %s, return=%d\n",
301                                 tid_num, state, rs);
302         }
303
304         return count;
305 }
306 STA_OPS_WR(agg_status);
307
308 #define DEBUGFS_ADD(name) \
309         sta->debugfs.name = debugfs_create_file(#name, 0444, \
310                 sta->debugfs.dir, sta, &sta_ ##name## _ops);
311
312 #define DEBUGFS_DEL(name) \
313         debugfs_remove(sta->debugfs.name);\
314         sta->debugfs.name = NULL;
315
316
317 void ieee80211_sta_debugfs_add(struct sta_info *sta)
318 {
319         struct dentry *stations_dir = sta->local->debugfs.stations;
320         DECLARE_MAC_BUF(mac);
321
322         if (!stations_dir)
323                 return;
324
325         print_mac(mac, sta->addr);
326
327         sta->debugfs.dir = debugfs_create_dir(mac, stations_dir);
328         if (!sta->debugfs.dir)
329                 return;
330
331         DEBUGFS_ADD(flags);
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);
340 #endif
341         DEBUGFS_ADD(agg_status);
342 }
343
344 void ieee80211_sta_debugfs_remove(struct sta_info *sta)
345 {
346         DEBUGFS_DEL(flags);
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);
355 #endif
356         DEBUGFS_DEL(agg_status);
357
358         debugfs_remove(sta->debugfs.dir);
359         sta->debugfs.dir = NULL;
360 }