1159784Ssam/*-
2159784Ssam * Copyright (c) 2006 Damien Bergamini <damien.bergamini@free.fr>
3159784Ssam * Copyright (c) 2006 Sam Leffler, Errno Consulting
4159784Ssam * All rights reserved.
5159784Ssam *
6159784Ssam * Redistribution and use in source and binary forms, with or without
7159784Ssam * modification, are permitted provided that the following conditions
8159784Ssam * are met:
9159784Ssam * 1. Redistributions of source code must retain the above copyright
10159784Ssam *    notice, this list of conditions and the following disclaimer.
11159784Ssam * 2. Redistributions in binary form must reproduce the above copyright
12159784Ssam *    notice, this list of conditions and the following disclaimer in the
13159784Ssam *    documentation and/or other materials provided with the distribution.
14159784Ssam *
15159784Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16159784Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17159784Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18159784Ssam * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19159784Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20159784Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21159784Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22159784Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23159784Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24159784Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25159784Ssam * SUCH DAMAGE.
26159784Ssam */
27159784Ssam
28159784Ssam#include <sys/cdefs.h>
29159784Ssam__FBSDID("$FreeBSD$");
30159784Ssam
31159784Ssam#include <sys/types.h>
32159784Ssam#include <sys/sysctl.h>
33159784Ssam
34159784Ssam#include <err.h>
35159784Ssam#include <stdio.h>
36159784Ssam#include <sysexits.h>
37159784Ssam
38159784Ssamstatic void	get_statistics(const char *);
39159784Ssam
40159784Ssamint
41159784Ssammain(int argc, char **argv)
42159784Ssam{
43159784Ssam	get_statistics((argc > 1) ? argv[1] : "ipw0");
44159784Ssam
45159784Ssam	return EX_OK;
46159784Ssam}
47159784Ssam
48159784Ssamstruct statistic {
49159784Ssam	int index;
50159784Ssam	const char *desc;
51159784Ssam	int unit;
52159784Ssam#define INT		1
53159784Ssam#define HEX		2
54159784Ssam#define MASK		HEX
55159784Ssam#define PERCENTAGE	3
56159784Ssam#define BOOL		4
57159784Ssam};
58159784Ssam
59159784Ssam/*-
60159784Ssam * TIM  = Traffic Information Message
61159784Ssam * DTIM = Delivery TIM
62159784Ssam * ATIM = Announcement TIM
63159784Ssam * PSP  = Power Save Poll
64159784Ssam * RTS  = Request To Send
65159784Ssam * CTS  = Clear To Send
66159784Ssam * RSSI = Received Signal Strength Indicator
67159784Ssam */
68159784Ssam
69159784Ssamstatic const struct statistic tbl[] = {
70159784Ssam	{ 1, "Number of frames submitted for transfer", INT },
71159784Ssam	{ 2, "Number of frames transmitted", INT },
72159784Ssam	{ 3, "Number of unicast frames transmitted", INT },
73159784Ssam	{ 4, "Number of unicast frames transmitted at 1Mb/s", INT },
74159784Ssam	{ 5, "Number of unicast frames transmitted at 2Mb/s", INT },
75159784Ssam	{ 6, "Number of unicast frames transmitted at 5.5Mb/s", INT },
76159784Ssam	{ 7, "Number of unicast frames transmitted at 11Mb/s", INT },
77159784Ssam
78159784Ssam	{ 13, "Number of multicast frames transmitted at 1Mb/s", INT },
79159784Ssam	{ 14, "Number of multicast frames transmitted at 2Mb/s", INT },
80159784Ssam	{ 15, "Number of multicast frames transmitted at 5.5Mb/s", INT },
81159784Ssam	{ 16, "Number of multicast frames transmitted at 11Mb/s", INT },
82159784Ssam
83159784Ssam	{ 21, "Number of null frames transmitted", INT },
84159784Ssam	{ 22, "Number of RTS frames transmitted", INT },
85159784Ssam	{ 23, "Number of CTS frames transmitted", INT },
86159784Ssam	{ 24, "Number of ACK frames transmitted", INT },
87159784Ssam	{ 25, "Number of association requests transmitted", INT },
88159784Ssam	{ 26, "Number of association responses transmitted", INT },
89159784Ssam	{ 27, "Number of reassociation requests transmitted", INT },
90159784Ssam	{ 28, "Number of reassociation responses transmitted", INT },
91159784Ssam	{ 29, "Number of probe requests transmitted", INT },
92298881Spfg	{ 30, "Number of probe responses transmitted", INT },
93159784Ssam	{ 31, "Number of beacons transmitted", INT },
94159784Ssam	{ 32, "Number of ATIM frames transmitted", INT },
95159784Ssam	{ 33, "Number of disassociation requests transmitted", INT },
96159784Ssam	{ 34, "Number of authentication requests transmitted", INT },
97159784Ssam	{ 35, "Number of deauthentication requests transmitted", INT },
98159784Ssam
99159784Ssam	{ 41, "Number of bytes transmitted", INT },
100159784Ssam	{ 42, "Number of transmission retries", INT },
101159784Ssam	{ 43, "Number of transmission retries at 1Mb/s", INT },
102159784Ssam	{ 44, "Number of transmission retries at 2Mb/s", INT },
103159784Ssam	{ 45, "Number of transmission retries at 5.5Mb/s", INT },
104159784Ssam	{ 46, "Number of transmission retries at 11Mb/s", INT },
105159784Ssam
106159784Ssam	{ 51, "Number of transmission failures", INT },
107159784Ssam
108159784Ssam	{ 54, "Number of transmission aborted due to slow DMA setup", INT },
109159784Ssam
110159784Ssam	{ 56, "Number of disassociation failures", INT },
111159784Ssam
112159784Ssam	{ 58, "Number of spanning tree frames transmitted", INT },
113159784Ssam	{ 59, "Number of transmission errors due to missing ACK", INT },
114159784Ssam
115159784Ssam	{ 61, "Number of frames received", INT },
116159784Ssam	{ 62, "Number of unicast frames received", INT },
117159784Ssam	{ 63, "Number of unicast frames received at 1Mb/s", INT },
118159784Ssam	{ 64, "Number of unicast frames received at 2Mb/s", INT },
119159784Ssam	{ 65, "Number of unicast frames received at 5.5Mb/s", INT },
120159784Ssam	{ 66, "Number of unicast frames received at 11Mb/s", INT },
121159784Ssam
122159784Ssam	{ 71, "Number of multicast frames received", INT },
123159784Ssam	{ 72, "Number of multicast frames received at 1Mb/s", INT },
124159784Ssam	{ 73, "Number of multicast frames received at 2Mb/s", INT },
125159784Ssam	{ 74, "Number of multicast frames received at 5.5Mb/s", INT },
126159784Ssam	{ 75, "Number of multicast frames received at 11Mb/s", INT },
127159784Ssam
128159784Ssam	{ 80, "Number of null frames received", INT },
129159784Ssam	{ 81, "Number of poll frames received", INT },
130159784Ssam	{ 82, "Number of RTS frames received", INT },
131159784Ssam	{ 83, "Number of CTS frames received", INT },
132159784Ssam	{ 84, "Number of ACK frames received", INT },
133159784Ssam	{ 85, "Number of CF-End frames received", INT },
134159784Ssam	{ 86, "Number of CF-End + CF-Ack frames received", INT },
135159784Ssam	{ 87, "Number of association requests received", INT },
136159784Ssam	{ 88, "Number of association responses received", INT },
137159784Ssam	{ 89, "Number of reassociation requests received", INT },
138159784Ssam	{ 90, "Number of reassociation responses received", INT },
139159784Ssam	{ 91, "Number of probe requests received", INT },
140298881Spfg	{ 92, "Number of probe responses received", INT },
141159784Ssam	{ 93, "Number of beacons received", INT },
142159784Ssam	{ 94, "Number of ATIM frames received", INT },
143159784Ssam	{ 95, "Number of disassociation requests received", INT },
144159784Ssam	{ 96, "Number of authentication requests received", INT },
145159784Ssam	{ 97, "Number of deauthentication requests received", INT },
146159784Ssam
147159784Ssam	{ 101, "Number of bytes received", INT },
148159784Ssam	{ 102, "Number of frames with a bad CRC received", INT },
149159784Ssam	{ 103, "Number of frames with a bad CRC received at 1Mb/s", INT },
150159784Ssam	{ 104, "Number of frames with a bad CRC received at 2Mb/s", INT },
151159784Ssam	{ 105, "Number of frames with a bad CRC received at 5.5Mb/s", INT },
152159784Ssam	{ 106, "Number of frames with a bad CRC received at 11Mb/s", INT },
153159784Ssam
154159784Ssam	{ 112, "Number of duplicated frames received at 1Mb/s", INT },
155159784Ssam	{ 113, "Number of duplicated frames received at 2Mb/s", INT },
156159784Ssam	{ 114, "Number of duplicated frames received at 5.5Mb/s", INT },
157159784Ssam	{ 115, "Number of duplicated frames received at 11Mb/s", INT },
158159784Ssam
159159784Ssam	{ 119, "Number of duplicated frames received", INT },
160159784Ssam
161159784Ssam	{ 123, "Number of frames with a bad protocol received", INT },
162159784Ssam	{ 124, "Boot time", INT },
163159784Ssam	{ 125, "Number of frames dropped due to no buffer", INT },
164159784Ssam	{ 126, "Number of frames dropped due to slow DMA setup", INT },
165159784Ssam
166159784Ssam	{ 128, "Number of frames dropped due to missing fragment", INT },
167159784Ssam	{ 129, "Number of frames dropped due to non-seq fragment", INT },
168159784Ssam	{ 130, "Number of frames dropped due to missing first frame", INT },
169159784Ssam	{ 131, "Number of frames dropped due to incomplete frame", INT },
170159784Ssam
171159784Ssam	{ 137, "Number of PSP adapter suspends", INT },
172159784Ssam	{ 138, "Number of PSP beacon timeouts", INT },
173159784Ssam	{ 139, "Number of PSP PsPollResponse timeouts", INT },
174159784Ssam	{ 140, "Number of PSP mcast frame timeouts", INT },
175159784Ssam	{ 141, "Number of PSP DTIM frames received", INT },
176159784Ssam	{ 142, "Number of PSP TIM frames received", INT },
177159784Ssam	{ 143, "PSP station Id", INT },
178159784Ssam
179159784Ssam	{ 147, "RTC time of last association", INT },
180159784Ssam	{ 148, "Percentage of missed beacons", PERCENTAGE },
181159784Ssam	{ 149, "Percentage of missed transmission retries", PERCENTAGE },
182159784Ssam
183159784Ssam	{ 151, "Number of access points in access points table", INT },
184159784Ssam
185159784Ssam	{ 153, "Number of associations", INT },
186159784Ssam	{ 154, "Number of association failures", INT },
187159784Ssam	{ 156, "Number of full scans", INT },
188159784Ssam	{ 157, "Card disabled", BOOL },
189159784Ssam
190159784Ssam	{ 160, "RSSI at time of association", INT },
191159784Ssam	{ 161, "Number of reassociations due to no probe response", INT },
192159784Ssam	{ 162, "Number of reassociations due to poor line quality", INT },
193159784Ssam	{ 163, "Number of reassociations due to load", INT },
194159784Ssam	{ 164, "Number of reassociations due to access point RSSI level", INT },
195159784Ssam	{ 165, "Number of reassociations due to load leveling", INT },
196159784Ssam
197159784Ssam	{ 170, "Number of times authentication failed", INT },
198159784Ssam	{ 171, "Number of times authentication response failed", INT },
199159784Ssam	{ 172, "Number of entries in association table", INT },
200159784Ssam	{ 173, "Average RSSI", INT },
201159784Ssam
202159784Ssam	{ 176, "Self test status", INT },
203159784Ssam	{ 177, "Power mode", INT },
204159784Ssam	{ 178, "Power index", INT },
205159784Ssam	{ 179, "IEEE country code", HEX },
206159784Ssam	{ 180, "Channels supported for this country", MASK },
207159784Ssam	{ 181, "Number of adapter warm resets", INT },
208159784Ssam	{ 182, "Beacon interval", INT },
209159784Ssam
210159784Ssam	{ 184, "Princeton version", INT },
211159784Ssam	{ 185, "Antenna diversity disabled", BOOL },
212159784Ssam#if notset
213159784Ssam	{ 186, "CCA RSSI", INT },
214159784Ssam	{ 187, "Number of times EEPROM updated", INT },
215159784Ssam#endif
216159784Ssam	{ 188, "Beacon intervals between DTIM", INT },
217159784Ssam	{ 189, "Current channel", INT },
218159784Ssam	{ 190, "RTC time", INT },
219159784Ssam	{ 191, "Operating mode", INT },
220159784Ssam	{ 192, "Transmission rate", HEX },
221159784Ssam	{ 193, "Supported transmission rates", MASK },
222159784Ssam	{ 194, "ATIM window", INT },
223159784Ssam	{ 195, "Supported basic transmission rates", MASK },
224159784Ssam	{ 196, "Adapter highest rate", HEX },
225159784Ssam	{ 197, "Access point highest rate", HEX },
226159784Ssam	{ 198, "Management frame capability", BOOL },
227159784Ssam	{ 199, "Type of authentication", INT },
228159784Ssam	{ 200, "Adapter card platform type", INT },
229159784Ssam	{ 201, "RTS threshold", INT },
230159784Ssam	{ 202, "International mode", BOOL },
231159784Ssam	{ 203, "Fragmentation threshold", INT },
232159784Ssam
233159784Ssam	{ 209, "MAC version", INT },
234159784Ssam	{ 210, "MAC revision", INT },
235159784Ssam	{ 211, "Radio version", INT },
236159784Ssam	{ 212, "NIC manufacturing date+time", INT },
237159784Ssam	{ 213, "Microcode version", INT },
238159784Ssam	{ 214, "RF switch state", INT },
239159784Ssam
240159784Ssam	{ 0, NULL, 0 }
241159784Ssam};
242159784Ssam
243159784Ssamstatic void
244159784Ssamget_statistics(const char *iface)
245159784Ssam{
246159784Ssam	static uint32_t stats[256];
247159784Ssam	const struct statistic *stat;
248159784Ssam	char oid[32];
249159784Ssam	int ifaceno, len;
250159784Ssam
251159784Ssam	if (sscanf(iface, "ipw%u", &ifaceno) != 1)
252159784Ssam		errx(EX_DATAERR, "Invalid interface name '%s'", iface);
253159784Ssam
254159784Ssam	len = sizeof stats;
255159784Ssam	snprintf(oid, sizeof oid, "dev.ipw.%u.stats", ifaceno);
256159784Ssam	if (sysctlbyname(oid, stats, &len, NULL, 0) == -1)
257159784Ssam		err(EX_OSERR, "Can't retrieve statistics");
258159784Ssam
259159784Ssam	for (stat = tbl; stat->index != 0; stat++) {
260159784Ssam		printf("%-60s[", stat->desc);
261159784Ssam		switch (stat->unit) {
262159784Ssam		case INT:
263159829Sobrien			printf("%u", stats[stat->index]);
264159784Ssam			break;
265159784Ssam		case BOOL:
266159784Ssam			printf(stats[stat->index] ? "true" : "false");
267159784Ssam			break;
268159784Ssam		case PERCENTAGE:
269159829Sobrien			printf("%u%%", stats[stat->index]);
270159784Ssam			break;
271159784Ssam		case HEX:
272159784Ssam		default:
273159829Sobrien			printf("0x%08X", stats[stat->index]);
274159784Ssam		}
275159784Ssam		printf("]\n");
276159784Ssam	}
277159784Ssam}
278