xref: /freebsd/tools/tools/ipw/ipwstats.c (revision 3494f7c0)
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/types.h>
29 #include <sys/sysctl.h>
30 
31 #include <err.h>
32 #include <stdio.h>
33 #include <sysexits.h>
34 
35 static void	get_statistics(const char *);
36 
37 int
38 main(int argc, char **argv)
39 {
40 	get_statistics((argc > 1) ? argv[1] : "ipw0");
41 
42 	return EX_OK;
43 }
44 
45 struct statistic {
46 	int index;
47 	const char *desc;
48 	int unit;
49 #define INT		1
50 #define HEX		2
51 #define MASK		HEX
52 #define PERCENTAGE	3
53 #define BOOL		4
54 };
55 
56 /*-
57  * TIM  = Traffic Information Message
58  * DTIM = Delivery TIM
59  * ATIM = Announcement TIM
60  * PSP  = Power Save Poll
61  * RTS  = Request To Send
62  * CTS  = Clear To Send
63  * RSSI = Received Signal Strength Indicator
64  */
65 
66 static const struct statistic tbl[] = {
67 	{ 1, "Number of frames submitted for transfer", INT },
68 	{ 2, "Number of frames transmitted", INT },
69 	{ 3, "Number of unicast frames transmitted", INT },
70 	{ 4, "Number of unicast frames transmitted at 1Mb/s", INT },
71 	{ 5, "Number of unicast frames transmitted at 2Mb/s", INT },
72 	{ 6, "Number of unicast frames transmitted at 5.5Mb/s", INT },
73 	{ 7, "Number of unicast frames transmitted at 11Mb/s", INT },
74 
75 	{ 13, "Number of multicast frames transmitted at 1Mb/s", INT },
76 	{ 14, "Number of multicast frames transmitted at 2Mb/s", INT },
77 	{ 15, "Number of multicast frames transmitted at 5.5Mb/s", INT },
78 	{ 16, "Number of multicast frames transmitted at 11Mb/s", INT },
79 
80 	{ 21, "Number of null frames transmitted", INT },
81 	{ 22, "Number of RTS frames transmitted", INT },
82 	{ 23, "Number of CTS frames transmitted", INT },
83 	{ 24, "Number of ACK frames transmitted", INT },
84 	{ 25, "Number of association requests transmitted", INT },
85 	{ 26, "Number of association responses transmitted", INT },
86 	{ 27, "Number of reassociation requests transmitted", INT },
87 	{ 28, "Number of reassociation responses transmitted", INT },
88 	{ 29, "Number of probe requests transmitted", INT },
89 	{ 30, "Number of probe responses transmitted", INT },
90 	{ 31, "Number of beacons transmitted", INT },
91 	{ 32, "Number of ATIM frames transmitted", INT },
92 	{ 33, "Number of disassociation requests transmitted", INT },
93 	{ 34, "Number of authentication requests transmitted", INT },
94 	{ 35, "Number of deauthentication requests transmitted", INT },
95 
96 	{ 41, "Number of bytes transmitted", INT },
97 	{ 42, "Number of transmission retries", INT },
98 	{ 43, "Number of transmission retries at 1Mb/s", INT },
99 	{ 44, "Number of transmission retries at 2Mb/s", INT },
100 	{ 45, "Number of transmission retries at 5.5Mb/s", INT },
101 	{ 46, "Number of transmission retries at 11Mb/s", INT },
102 
103 	{ 51, "Number of transmission failures", INT },
104 
105 	{ 54, "Number of transmission aborted due to slow DMA setup", INT },
106 
107 	{ 56, "Number of disassociation failures", INT },
108 
109 	{ 58, "Number of spanning tree frames transmitted", INT },
110 	{ 59, "Number of transmission errors due to missing ACK", INT },
111 
112 	{ 61, "Number of frames received", INT },
113 	{ 62, "Number of unicast frames received", INT },
114 	{ 63, "Number of unicast frames received at 1Mb/s", INT },
115 	{ 64, "Number of unicast frames received at 2Mb/s", INT },
116 	{ 65, "Number of unicast frames received at 5.5Mb/s", INT },
117 	{ 66, "Number of unicast frames received at 11Mb/s", INT },
118 
119 	{ 71, "Number of multicast frames received", INT },
120 	{ 72, "Number of multicast frames received at 1Mb/s", INT },
121 	{ 73, "Number of multicast frames received at 2Mb/s", INT },
122 	{ 74, "Number of multicast frames received at 5.5Mb/s", INT },
123 	{ 75, "Number of multicast frames received at 11Mb/s", INT },
124 
125 	{ 80, "Number of null frames received", INT },
126 	{ 81, "Number of poll frames received", INT },
127 	{ 82, "Number of RTS frames received", INT },
128 	{ 83, "Number of CTS frames received", INT },
129 	{ 84, "Number of ACK frames received", INT },
130 	{ 85, "Number of CF-End frames received", INT },
131 	{ 86, "Number of CF-End + CF-Ack frames received", INT },
132 	{ 87, "Number of association requests received", INT },
133 	{ 88, "Number of association responses received", INT },
134 	{ 89, "Number of reassociation requests received", INT },
135 	{ 90, "Number of reassociation responses received", INT },
136 	{ 91, "Number of probe requests received", INT },
137 	{ 92, "Number of probe responses received", INT },
138 	{ 93, "Number of beacons received", INT },
139 	{ 94, "Number of ATIM frames received", INT },
140 	{ 95, "Number of disassociation requests received", INT },
141 	{ 96, "Number of authentication requests received", INT },
142 	{ 97, "Number of deauthentication requests received", INT },
143 
144 	{ 101, "Number of bytes received", INT },
145 	{ 102, "Number of frames with a bad CRC received", INT },
146 	{ 103, "Number of frames with a bad CRC received at 1Mb/s", INT },
147 	{ 104, "Number of frames with a bad CRC received at 2Mb/s", INT },
148 	{ 105, "Number of frames with a bad CRC received at 5.5Mb/s", INT },
149 	{ 106, "Number of frames with a bad CRC received at 11Mb/s", INT },
150 
151 	{ 112, "Number of duplicated frames received at 1Mb/s", INT },
152 	{ 113, "Number of duplicated frames received at 2Mb/s", INT },
153 	{ 114, "Number of duplicated frames received at 5.5Mb/s", INT },
154 	{ 115, "Number of duplicated frames received at 11Mb/s", INT },
155 
156 	{ 119, "Number of duplicated frames received", INT },
157 
158 	{ 123, "Number of frames with a bad protocol received", INT },
159 	{ 124, "Boot time", INT },
160 	{ 125, "Number of frames dropped due to no buffer", INT },
161 	{ 126, "Number of frames dropped due to slow DMA setup", INT },
162 
163 	{ 128, "Number of frames dropped due to missing fragment", INT },
164 	{ 129, "Number of frames dropped due to non-seq fragment", INT },
165 	{ 130, "Number of frames dropped due to missing first frame", INT },
166 	{ 131, "Number of frames dropped due to incomplete frame", INT },
167 
168 	{ 137, "Number of PSP adapter suspends", INT },
169 	{ 138, "Number of PSP beacon timeouts", INT },
170 	{ 139, "Number of PSP PsPollResponse timeouts", INT },
171 	{ 140, "Number of PSP mcast frame timeouts", INT },
172 	{ 141, "Number of PSP DTIM frames received", INT },
173 	{ 142, "Number of PSP TIM frames received", INT },
174 	{ 143, "PSP station Id", INT },
175 
176 	{ 147, "RTC time of last association", INT },
177 	{ 148, "Percentage of missed beacons", PERCENTAGE },
178 	{ 149, "Percentage of missed transmission retries", PERCENTAGE },
179 
180 	{ 151, "Number of access points in access points table", INT },
181 
182 	{ 153, "Number of associations", INT },
183 	{ 154, "Number of association failures", INT },
184 	{ 156, "Number of full scans", INT },
185 	{ 157, "Card disabled", BOOL },
186 
187 	{ 160, "RSSI at time of association", INT },
188 	{ 161, "Number of reassociations due to no probe response", INT },
189 	{ 162, "Number of reassociations due to poor line quality", INT },
190 	{ 163, "Number of reassociations due to load", INT },
191 	{ 164, "Number of reassociations due to access point RSSI level", INT },
192 	{ 165, "Number of reassociations due to load leveling", INT },
193 
194 	{ 170, "Number of times authentication failed", INT },
195 	{ 171, "Number of times authentication response failed", INT },
196 	{ 172, "Number of entries in association table", INT },
197 	{ 173, "Average RSSI", INT },
198 
199 	{ 176, "Self test status", INT },
200 	{ 177, "Power mode", INT },
201 	{ 178, "Power index", INT },
202 	{ 179, "IEEE country code", HEX },
203 	{ 180, "Channels supported for this country", MASK },
204 	{ 181, "Number of adapter warm resets", INT },
205 	{ 182, "Beacon interval", INT },
206 
207 	{ 184, "Princeton version", INT },
208 	{ 185, "Antenna diversity disabled", BOOL },
209 #if notset
210 	{ 186, "CCA RSSI", INT },
211 	{ 187, "Number of times EEPROM updated", INT },
212 #endif
213 	{ 188, "Beacon intervals between DTIM", INT },
214 	{ 189, "Current channel", INT },
215 	{ 190, "RTC time", INT },
216 	{ 191, "Operating mode", INT },
217 	{ 192, "Transmission rate", HEX },
218 	{ 193, "Supported transmission rates", MASK },
219 	{ 194, "ATIM window", INT },
220 	{ 195, "Supported basic transmission rates", MASK },
221 	{ 196, "Adapter highest rate", HEX },
222 	{ 197, "Access point highest rate", HEX },
223 	{ 198, "Management frame capability", BOOL },
224 	{ 199, "Type of authentication", INT },
225 	{ 200, "Adapter card platform type", INT },
226 	{ 201, "RTS threshold", INT },
227 	{ 202, "International mode", BOOL },
228 	{ 203, "Fragmentation threshold", INT },
229 
230 	{ 209, "MAC version", INT },
231 	{ 210, "MAC revision", INT },
232 	{ 211, "Radio version", INT },
233 	{ 212, "NIC manufacturing date+time", INT },
234 	{ 213, "Microcode version", INT },
235 	{ 214, "RF switch state", INT },
236 
237 	{ 0, NULL, 0 }
238 };
239 
240 static void
241 get_statistics(const char *iface)
242 {
243 	static uint32_t stats[256];
244 	const struct statistic *stat;
245 	char oid[32];
246 	int ifaceno, len;
247 
248 	if (sscanf(iface, "ipw%u", &ifaceno) != 1)
249 		errx(EX_DATAERR, "Invalid interface name '%s'", iface);
250 
251 	len = sizeof stats;
252 	snprintf(oid, sizeof oid, "dev.ipw.%u.stats", ifaceno);
253 	if (sysctlbyname(oid, stats, &len, NULL, 0) == -1)
254 		err(EX_OSERR, "Can't retrieve statistics");
255 
256 	for (stat = tbl; stat->index != 0; stat++) {
257 		printf("%-60s[", stat->desc);
258 		switch (stat->unit) {
259 		case INT:
260 			printf("%u", stats[stat->index]);
261 			break;
262 		case BOOL:
263 			printf(stats[stat->index] ? "true" : "false");
264 			break;
265 		case PERCENTAGE:
266 			printf("%u%%", stats[stat->index]);
267 			break;
268 		case HEX:
269 		default:
270 			printf("0x%08X", stats[stat->index]);
271 		}
272 		printf("]\n");
273 	}
274 }
275