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_FILE(name, field, format) \
59 STA_READ_##format(name, field) \
62 STA_FILE(aid
, aid
, D
);
63 STA_FILE(key_idx_compression
, key_idx_compression
, D
);
64 STA_FILE(dev
, dev
->name
, S
);
65 STA_FILE(vlan_id
, vlan_id
, D
);
66 STA_FILE(rx_packets
, rx_packets
, LU
);
67 STA_FILE(tx_packets
, tx_packets
, LU
);
68 STA_FILE(rx_bytes
, rx_bytes
, LU
);
69 STA_FILE(tx_bytes
, tx_bytes
, LU
);
70 STA_FILE(rx_duplicates
, num_duplicates
, LU
);
71 STA_FILE(rx_fragments
, rx_fragments
, LU
);
72 STA_FILE(rx_dropped
, rx_dropped
, LU
);
73 STA_FILE(tx_fragments
, tx_fragments
, LU
);
74 STA_FILE(tx_filtered
, tx_filtered_count
, LU
);
75 STA_FILE(txrate
, txrate
, RATE
);
76 STA_FILE(last_txrate
, last_txrate
, RATE
);
77 STA_FILE(tx_retry_failed
, tx_retry_failed
, LU
);
78 STA_FILE(tx_retry_count
, tx_retry_count
, LU
);
79 STA_FILE(last_rssi
, last_rssi
, D
);
80 STA_FILE(last_signal
, last_signal
, D
);
81 STA_FILE(last_noise
, last_noise
, D
);
82 STA_FILE(channel_use
, channel_use
, D
);
83 STA_FILE(wep_weak_iv_count
, wep_weak_iv_count
, D
);
85 static ssize_t
sta_flags_read(struct file
*file
, char __user
*userbuf
,
86 size_t count
, loff_t
*ppos
)
89 struct sta_info
*sta
= file
->private_data
;
90 int res
= scnprintf(buf
, sizeof(buf
), "%s%s%s%s%s%s%s%s%s",
91 sta
->flags
& WLAN_STA_AUTH
? "AUTH\n" : "",
92 sta
->flags
& WLAN_STA_ASSOC
? "ASSOC\n" : "",
93 sta
->flags
& WLAN_STA_PS
? "PS\n" : "",
94 sta
->flags
& WLAN_STA_TIM
? "TIM\n" : "",
95 sta
->flags
& WLAN_STA_PERM
? "PERM\n" : "",
96 sta
->flags
& WLAN_STA_AUTHORIZED
? "AUTHORIZED\n" : "",
97 sta
->flags
& WLAN_STA_SHORT_PREAMBLE
? "SHORT PREAMBLE\n" : "",
98 sta
->flags
& WLAN_STA_WME
? "WME\n" : "",
99 sta
->flags
& WLAN_STA_WDS
? "WDS\n" : "");
100 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, res
);
104 static ssize_t
sta_num_ps_buf_frames_read(struct file
*file
,
105 char __user
*userbuf
,
106 size_t count
, loff_t
*ppos
)
109 struct sta_info
*sta
= file
->private_data
;
110 int res
= scnprintf(buf
, sizeof(buf
), "%u\n",
111 skb_queue_len(&sta
->ps_tx_buf
));
112 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, res
);
114 STA_OPS(num_ps_buf_frames
);
116 static ssize_t
sta_last_ack_rssi_read(struct file
*file
, char __user
*userbuf
,
117 size_t count
, loff_t
*ppos
)
120 struct sta_info
*sta
= file
->private_data
;
121 int res
= scnprintf(buf
, sizeof(buf
), "%d %d %d\n",
122 sta
->last_ack_rssi
[0],
123 sta
->last_ack_rssi
[1],
124 sta
->last_ack_rssi
[2]);
125 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, res
);
127 STA_OPS(last_ack_rssi
);
129 static ssize_t
sta_last_ack_ms_read(struct file
*file
, char __user
*userbuf
,
130 size_t count
, loff_t
*ppos
)
133 struct sta_info
*sta
= file
->private_data
;
134 int res
= scnprintf(buf
, sizeof(buf
), "%d\n",
136 jiffies_to_msecs(jiffies
- sta
->last_ack
) : -1);
137 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, res
);
139 STA_OPS(last_ack_ms
);
141 static ssize_t
sta_inactive_ms_read(struct file
*file
, char __user
*userbuf
,
142 size_t count
, loff_t
*ppos
)
145 struct sta_info
*sta
= file
->private_data
;
146 int res
= scnprintf(buf
, sizeof(buf
), "%d\n",
147 jiffies_to_msecs(jiffies
- sta
->last_rx
));
148 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, res
);
150 STA_OPS(inactive_ms
);
152 static ssize_t
sta_last_seq_ctrl_read(struct file
*file
, char __user
*userbuf
,
153 size_t count
, loff_t
*ppos
)
155 char buf
[15*NUM_RX_DATA_QUEUES
], *p
= buf
;
157 struct sta_info
*sta
= file
->private_data
;
158 for (i
= 0; i
< NUM_RX_DATA_QUEUES
; i
++)
159 p
+= scnprintf(p
, sizeof(buf
)+buf
-p
, "%x ",
160 sta
->last_seq_ctrl
[i
]);
161 p
+= scnprintf(p
, sizeof(buf
)+buf
-p
, "\n");
162 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, p
- buf
);
164 STA_OPS(last_seq_ctrl
);
166 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
167 static ssize_t
sta_wme_rx_queue_read(struct file
*file
, char __user
*userbuf
,
168 size_t count
, loff_t
*ppos
)
170 char buf
[15*NUM_RX_DATA_QUEUES
], *p
= buf
;
172 struct sta_info
*sta
= file
->private_data
;
173 for (i
= 0; i
< NUM_RX_DATA_QUEUES
; i
++)
174 p
+= scnprintf(p
, sizeof(buf
)+buf
-p
, "%u ",
175 sta
->wme_rx_queue
[i
]);
176 p
+= scnprintf(p
, sizeof(buf
)+buf
-p
, "\n");
177 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, p
- buf
);
179 STA_OPS(wme_rx_queue
);
181 static ssize_t
sta_wme_tx_queue_read(struct file
*file
, char __user
*userbuf
,
182 size_t count
, loff_t
*ppos
)
184 char buf
[15*NUM_TX_DATA_QUEUES
], *p
= buf
;
186 struct sta_info
*sta
= file
->private_data
;
187 for (i
= 0; i
< NUM_TX_DATA_QUEUES
; i
++)
188 p
+= scnprintf(p
, sizeof(buf
)+buf
-p
, "%u ",
189 sta
->wme_tx_queue
[i
]);
190 p
+= scnprintf(p
, sizeof(buf
)+buf
-p
, "\n");
191 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, p
- buf
);
193 STA_OPS(wme_tx_queue
);
196 #define DEBUGFS_ADD(name) \
197 sta->debugfs.name = debugfs_create_file(#name, 0444, \
198 sta->debugfs.dir, sta, &sta_ ##name## _ops);
200 #define DEBUGFS_DEL(name) \
201 debugfs_remove(sta->debugfs.name);\
202 sta->debugfs.name = NULL;
205 void ieee80211_sta_debugfs_add(struct sta_info
*sta
)
208 struct dentry
*stations_dir
= sta
->local
->debugfs
.stations
;
213 sprintf(buf
, MAC_FMT
, MAC_ARG(sta
->addr
));
215 sta
->debugfs
.dir
= debugfs_create_dir(buf
, stations_dir
);
216 if (!sta
->debugfs
.dir
)
220 DEBUGFS_ADD(num_ps_buf_frames
);
221 DEBUGFS_ADD(last_ack_rssi
);
222 DEBUGFS_ADD(last_ack_ms
);
223 DEBUGFS_ADD(inactive_ms
);
224 DEBUGFS_ADD(last_seq_ctrl
);
225 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
226 DEBUGFS_ADD(wme_rx_queue
);
227 DEBUGFS_ADD(wme_tx_queue
);
231 void ieee80211_sta_debugfs_remove(struct sta_info
*sta
)
234 DEBUGFS_DEL(num_ps_buf_frames
);
235 DEBUGFS_DEL(last_ack_rssi
);
236 DEBUGFS_DEL(last_ack_ms
);
237 DEBUGFS_DEL(inactive_ms
);
238 DEBUGFS_DEL(last_seq_ctrl
);
239 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
240 DEBUGFS_DEL(wme_rx_queue
);
241 DEBUGFS_DEL(wme_tx_queue
);
244 debugfs_remove(sta
->debugfs
.dir
);
245 sta
->debugfs
.dir
= NULL
;