xref: /freebsd/tools/tools/iwi/iwistats.c (revision 4b9d6057)
1 
2 /*-
3  * Copyright (c) 2005
4  *	Damien Bergamini <damien.bergamini@free.fr>. 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 unmodified, this list of conditions, and the following
11  *    disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
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] : "iwi0");
42 
43 	return EX_OK;
44 }
45 
46 static const struct statistic {
47 	int 		index;
48 	const char	*desc;
49 } tbl[] = {
50 	{  1, "Current transmission rate" },
51 	{  2, "Fragmentation threshold" },
52 	{  3, "RTS threshold" },
53 	{  4, "Number of frames submitted for transfer" },
54 	{  5, "Number of frames transmitted" },
55 	{  6, "Number of unicast frames transmitted" },
56 	{  7, "Number of unicast 802.11b frames transmitted at 1Mb/s" },
57 	{  8, "Number of unicast 802.11b frames transmitted at 2Mb/s" },
58 	{  9, "Number of unicast 802.11b frames transmitted at 5.5Mb/s" },
59 	{ 10, "Number of unicast 802.11b frames transmitted at 11Mb/s" },
60 
61 	{ 19, "Number of unicast 802.11g frames transmitted at 1Mb/s" },
62 	{ 20, "Number of unicast 802.11g frames transmitted at 2Mb/s" },
63 	{ 21, "Number of unicast 802.11g frames transmitted at 5.5Mb/s" },
64 	{ 22, "Number of unicast 802.11g frames transmitted at 6Mb/s" },
65 	{ 23, "Number of unicast 802.11g frames transmitted at 9Mb/s" },
66 	{ 24, "Number of unicast 802.11g frames transmitted at 11Mb/s" },
67 	{ 25, "Number of unicast 802.11g frames transmitted at 12Mb/s" },
68 	{ 26, "Number of unicast 802.11g frames transmitted at 18Mb/s" },
69 	{ 27, "Number of unicast 802.11g frames transmitted at 24Mb/s" },
70 	{ 28, "Number of unicast 802.11g frames transmitted at 36Mb/s" },
71 	{ 29, "Number of unicast 802.11g frames transmitted at 48Mb/s" },
72 	{ 30, "Number of unicast 802.11g frames transmitted at 54Mb/s" },
73 	{ 31, "Number of multicast frames transmitted" },
74 	{ 32, "Number of multicast 802.11b frames transmitted at 1Mb/s" },
75 	{ 33, "Number of multicast 802.11b frames transmitted at 2Mb/s" },
76 	{ 34, "Number of multicast 802.11b frames transmitted at 5.5Mb/s" },
77 	{ 35, "Number of multicast 802.11b frames transmitted at 11Mb/s" },
78 
79 	{ 44, "Number of multicast 802.11g frames transmitted at 1Mb/s" },
80 	{ 45, "Number of multicast 802.11g frames transmitted at 2Mb/s" },
81 	{ 46, "Number of multicast 802.11g frames transmitted at 5.5Mb/s" },
82 	{ 47, "Number of multicast 802.11g frames transmitted at 6Mb/s" },
83 	{ 48, "Number of multicast 802.11g frames transmitted at 9Mb/s" },
84 	{ 49, "Number of multicast 802.11g frames transmitted at 11Mb/s" },
85 	{ 50, "Number of multicast 802.11g frames transmitted at 12Mb/s" },
86 	{ 51, "Number of multicast 802.11g frames transmitted at 18Mb/s" },
87 	{ 52, "Number of multicast 802.11g frames transmitted at 24Mb/s" },
88 	{ 53, "Number of multicast 802.11g frames transmitted at 36Mb/s" },
89 	{ 54, "Number of multicast 802.11g frames transmitted at 48Mb/s" },
90 	{ 55, "Number of multicast 802.11g frames transmitted at 54Mb/s" },
91 	{ 56, "Number of transmission retries" },
92 	{ 57, "Number of transmission failures" },
93 	{ 58, "Number of CRC errors" },
94 
95 	{ 61, "Number of full scans" },
96 	{ 62, "Number of partial scans" },
97 
98 	{ 64, "Number of bytes transmitted" },
99 	{ 65, "Current RSSI" },
100 	{ 66, "Number of beacons received" },
101 	{ 67, "Number of beacons missed" },
102 
103 	{ -1, NULL }
104 };
105 
106 static void
107 get_statistics(const char *iface)
108 {
109 	static uint32_t stats[256];
110 	const struct statistic *stat;
111 	char oid[32];
112 	size_t len;
113 	int ifaceno;
114 
115 	if (sscanf(iface, "iwi%u", &ifaceno) != 1)
116 		errx(EX_DATAERR, "Invalid interface name '%s'", iface);
117 
118 	len = sizeof(stats);
119 	(void)snprintf(oid, sizeof(oid), "dev.iwi.%u.stats", ifaceno);
120 	if (sysctlbyname(oid, stats, &len, NULL, 0) == -1)
121 		err(EX_OSERR, "Can't retrieve statistics");
122 
123 	for (stat = tbl; stat->index != -1; stat++)
124 		(void)printf("%-60s[%u]\n", stat->desc, stats[stat->index]);
125 }
126