xref: /freebsd/tools/tools/ipw/ipwstats.c (revision aa0a1e58)
1 /*-
2  * Copyright (c) 2006 Damien Bergamini <damien.bergamini@free.fr>
3  * Copyright (c) 2006 Sam Leffler, Errno Consulting
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30 
31 #include <sys/types.h>
32 #include <sys/sysctl.h>
33 
34 #include <err.h>
35 #include <stdio.h>
36 #include <sysexits.h>
37 
38 static void	get_statistics(const char *);
39 
40 int
41 main(int argc, char **argv)
42 {
43 	get_statistics((argc > 1) ? argv[1] : "ipw0");
44 
45 	return EX_OK;
46 }
47 
48 struct statistic {
49 	int index;
50 	const char *desc;
51 	int unit;
52 #define INT		1
53 #define HEX		2
54 #define MASK		HEX
55 #define PERCENTAGE	3
56 #define BOOL		4
57 };
58 
59 /*-
60  * TIM  = Traffic Information Message
61  * DTIM = Delivery TIM
62  * ATIM = Announcement TIM
63  * PSP  = Power Save Poll
64  * RTS  = Request To Send
65  * CTS  = Clear To Send
66  * RSSI = Received Signal Strength Indicator
67  */
68 
69 static const struct statistic tbl[] = {
70 	{ 1, "Number of frames submitted for transfer", INT },
71 	{ 2, "Number of frames transmitted", INT },
72 	{ 3, "Number of unicast frames transmitted", INT },
73 	{ 4, "Number of unicast frames transmitted at 1Mb/s", INT },
74 	{ 5, "Number of unicast frames transmitted at 2Mb/s", INT },
75 	{ 6, "Number of unicast frames transmitted at 5.5Mb/s", INT },
76 	{ 7, "Number of unicast frames transmitted at 11Mb/s", INT },
77 
78 	{ 13, "Number of multicast frames transmitted at 1Mb/s", INT },
79 	{ 14, "Number of multicast frames transmitted at 2Mb/s", INT },
80 	{ 15, "Number of multicast frames transmitted at 5.5Mb/s", INT },
81 	{ 16, "Number of multicast frames transmitted at 11Mb/s", INT },
82 
83 	{ 21, "Number of null frames transmitted", INT },
84 	{ 22, "Number of RTS frames transmitted", INT },
85 	{ 23, "Number of CTS frames transmitted", INT },
86 	{ 24, "Number of ACK frames transmitted", INT },
87 	{ 25, "Number of association requests transmitted", INT },
88 	{ 26, "Number of association responses transmitted", INT },
89 	{ 27, "Number of reassociation requests transmitted", INT },
90 	{ 28, "Number of reassociation responses transmitted", INT },
91 	{ 29, "Number of probe requests transmitted", INT },
92 	{ 30, "Number of probe reponses transmitted", INT },
93 	{ 31, "Number of beacons transmitted", INT },
94 	{ 32, "Number of ATIM frames transmitted", INT },
95 	{ 33, "Number of disassociation requests transmitted", INT },
96 	{ 34, "Number of authentication requests transmitted", INT },
97 	{ 35, "Number of deauthentication requests transmitted", INT },
98 
99 	{ 41, "Number of bytes transmitted", INT },
100 	{ 42, "Number of transmission retries", INT },
101 	{ 43, "Number of transmission retries at 1Mb/s", INT },
102 	{ 44, "Number of transmission retries at 2Mb/s", INT },
103 	{ 45, "Number of transmission retries at 5.5Mb/s", INT },
104 	{ 46, "Number of transmission retries at 11Mb/s", INT },
105 
106 	{ 51, "Number of transmission failures", INT },
107 
108 	{ 54, "Number of transmission aborted due to slow DMA setup", INT },
109 
110 	{ 56, "Number of disassociation failures", INT },
111 
112 	{ 58, "Number of spanning tree frames transmitted", INT },
113 	{ 59, "Number of transmission errors due to missing ACK", INT },
114 
115 	{ 61, "Number of frames received", INT },
116 	{ 62, "Number of unicast frames received", INT },
117 	{ 63, "Number of unicast frames received at 1Mb/s", INT },
118 	{ 64, "Number of unicast frames received at 2Mb/s", INT },
119 	{ 65, "Number of unicast frames received at 5.5Mb/s", INT },
120 	{ 66, "Number of unicast frames received at 11Mb/s", INT },
121 
122 	{ 71, "Number of multicast frames received", INT },
123 	{ 72, "Number of multicast frames received at 1Mb/s", INT },
124 	{ 73, "Number of multicast frames received at 2Mb/s", INT },
125 	{ 74, "Number of multicast frames received at 5.5Mb/s", INT },
126 	{ 75, "Number of multicast frames received at 11Mb/s", INT },
127 
128 	{ 80, "Number of null frames received", INT },
129 	{ 81, "Number of poll frames received", INT },
130 	{ 82, "Number of RTS frames received", INT },
131 	{ 83, "Number of CTS frames received", INT },
132 	{ 84, "Number of ACK frames received", INT },
133 	{ 85, "Number of CF-End frames received", INT },
134 	{ 86, "Number of CF-End + CF-Ack frames received", INT },
135 	{ 87, "Number of association requests received", INT },
136 	{ 88, "Number of association responses received", INT },
137 	{ 89, "Number of reassociation requests received", INT },
138 	{ 90, "Number of reassociation responses received", INT },
139 	{ 91, "Number of probe requests received", INT },
140 	{ 92, "Number of probe reponses received", INT },
141 	{ 93, "Number of beacons received", INT },
142 	{ 94, "Number of ATIM frames received", INT },
143 	{ 95, "Number of disassociation requests received", INT },
144 	{ 96, "Number of authentication requests received", INT },
145 	{ 97, "Number of deauthentication requests received", INT },
146 
147 	{ 101, "Number of bytes received", INT },
148 	{ 102, "Number of frames with a bad CRC received", INT },
149 	{ 103, "Number of frames with a bad CRC received at 1Mb/s", INT },
150 	{ 104, "Number of frames with a bad CRC received at 2Mb/s", INT },
151 	{ 105, "Number of frames with a bad CRC received at 5.5Mb/s", INT },
152 	{ 106, "Number of frames with a bad CRC received at 11Mb/s", INT },
153 
154 	{ 112, "Number of duplicated frames received at 1Mb/s", INT },
155 	{ 113, "Number of duplicated frames received at 2Mb/s", INT },
156 	{ 114, "Number of duplicated frames received at 5.5Mb/s", INT },
157 	{ 115, "Number of duplicated frames received at 11Mb/s", INT },
158 
159 	{ 119, "Number of duplicated frames received", INT },
160 
161 	{ 123, "Number of frames with a bad protocol received", INT },
162 	{ 124, "Boot time", INT },
163 	{ 125, "Number of frames dropped due to no buffer", INT },
164 	{ 126, "Number of frames dropped due to slow DMA setup", INT },
165 
166 	{ 128, "Number of frames dropped due to missing fragment", INT },
167 	{ 129, "Number of frames dropped due to non-seq fragment", INT },
168 	{ 130, "Number of frames dropped due to missing first frame", INT },
169 	{ 131, "Number of frames dropped due to incomplete frame", INT },
170 
171 	{ 137, "Number of PSP adapter suspends", INT },
172 	{ 138, "Number of PSP beacon timeouts", INT },
173 	{ 139, "Number of PSP PsPollResponse timeouts", INT },
174 	{ 140, "Number of PSP mcast frame timeouts", INT },
175 	{ 141, "Number of PSP DTIM frames received", INT },
176 	{ 142, "Number of PSP TIM frames received", INT },
177 	{ 143, "PSP station Id", INT },
178 
179 	{ 147, "RTC time of last association", INT },
180 	{ 148, "Percentage of missed beacons", PERCENTAGE },
181 	{ 149, "Percentage of missed transmission retries", PERCENTAGE },
182 
183 	{ 151, "Number of access points in access points table", INT },
184 
185 	{ 153, "Number of associations", INT },
186 	{ 154, "Number of association failures", INT },
187 	{ 156, "Number of full scans", INT },
188 	{ 157, "Card disabled", BOOL },
189 
190 	{ 160, "RSSI at time of association", INT },
191 	{ 161, "Number of reassociations due to no probe response", INT },
192 	{ 162, "Number of reassociations due to poor line quality", INT },
193 	{ 163, "Number of reassociations due to load", INT },
194 	{ 164, "Number of reassociations due to access point RSSI level", INT },
195 	{ 165, "Number of reassociations due to load leveling", INT },
196 
197 	{ 170, "Number of times authentication failed", INT },
198 	{ 171, "Number of times authentication response failed", INT },
199 	{ 172, "Number of entries in association table", INT },
200 	{ 173, "Average RSSI", INT },
201 
202 	{ 176, "Self test status", INT },
203 	{ 177, "Power mode", INT },
204 	{ 178, "Power index", INT },
205 	{ 179, "IEEE country code", HEX },
206 	{ 180, "Channels supported for this country", MASK },
207 	{ 181, "Number of adapter warm resets", INT },
208 	{ 182, "Beacon interval", INT },
209 
210 	{ 184, "Princeton version", INT },
211 	{ 185, "Antenna diversity disabled", BOOL },
212 #if notset
213 	{ 186, "CCA RSSI", INT },
214 	{ 187, "Number of times EEPROM updated", INT },
215 #endif
216 	{ 188, "Beacon intervals between DTIM", INT },
217 	{ 189, "Current channel", INT },
218 	{ 190, "RTC time", INT },
219 	{ 191, "Operating mode", INT },
220 	{ 192, "Transmission rate", HEX },
221 	{ 193, "Supported transmission rates", MASK },
222 	{ 194, "ATIM window", INT },
223 	{ 195, "Supported basic transmission rates", MASK },
224 	{ 196, "Adapter highest rate", HEX },
225 	{ 197, "Access point highest rate", HEX },
226 	{ 198, "Management frame capability", BOOL },
227 	{ 199, "Type of authentication", INT },
228 	{ 200, "Adapter card platform type", INT },
229 	{ 201, "RTS threshold", INT },
230 	{ 202, "International mode", BOOL },
231 	{ 203, "Fragmentation threshold", INT },
232 
233 	{ 209, "MAC version", INT },
234 	{ 210, "MAC revision", INT },
235 	{ 211, "Radio version", INT },
236 	{ 212, "NIC manufacturing date+time", INT },
237 	{ 213, "Microcode version", INT },
238 	{ 214, "RF switch state", INT },
239 
240 	{ 0, NULL, 0 }
241 };
242 
243 static void
244 get_statistics(const char *iface)
245 {
246 	static uint32_t stats[256];
247 	const struct statistic *stat;
248 	char oid[32];
249 	int ifaceno, len;
250 
251 	if (sscanf(iface, "ipw%u", &ifaceno) != 1)
252 		errx(EX_DATAERR, "Invalid interface name '%s'", iface);
253 
254 	len = sizeof stats;
255 	snprintf(oid, sizeof oid, "dev.ipw.%u.stats", ifaceno);
256 	if (sysctlbyname(oid, stats, &len, NULL, 0) == -1)
257 		err(EX_OSERR, "Can't retrieve statistics");
258 
259 	for (stat = tbl; stat->index != 0; stat++) {
260 		printf("%-60s[", stat->desc);
261 		switch (stat->unit) {
262 		case INT:
263 			printf("%u", stats[stat->index]);
264 			break;
265 		case BOOL:
266 			printf(stats[stat->index] ? "true" : "false");
267 			break;
268 		case PERCENTAGE:
269 			printf("%u%%", stats[stat->index]);
270 			break;
271 		case HEX:
272 		default:
273 			printf("0x%08X", stats[stat->index]);
274 		}
275 		printf("]\n");
276 	}
277 }
278