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