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