1 /* $NetBSD: iwictl.c,v 1.7 2006/08/09 11:57:51 skrll Exp $ */
4 * Copyright (c) 2004, 2005
5 * Damien Bergamini <damien.bergamini@free.fr>. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
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.
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
30 #include <sys/cdefs.h>
31 __RCSID("$NetBSD: iwictl.c,v 1.7 2006/08/09 11:57:51 skrll Exp $");
33 #include <sys/types.h>
34 #include <sys/ioctl.h>
36 #include <sys/socket.h>
50 #define SIOCGRADIO _IOWR('i', 139, struct ifreq)
51 #define SIOCGTABLE0 _IOWR('i', 140, struct ifreq)
53 static void usage(void) __dead
;
54 static int do_req(const char *, unsigned long, void *);
55 static void get_radio_state(const char *);
56 static void get_statistics(const char *);
59 main(int argc
, char **argv
)
63 int noflag
= 1, rflag
= 0;
66 if (argc
> 1 && argv
[1][0] != '-') {
71 while ((ch
= getopt(argc
, argv
, "i:r")) != -1) {
93 get_radio_state(iface
);
96 get_statistics(iface
);
104 (void)fprintf(stderr
, "Usage: %s [-i] iface\n"
105 "\t%s [-i] iface -r\n", getprogname(), getprogname());
111 do_req(const char *iface
, unsigned long req
, void *data
)
117 if ((s
= socket(AF_INET
, SOCK_DGRAM
, 0)) == -1)
118 err(EX_OSERR
, "Can't create socket");
120 (void)memset(&ifr
, 0, sizeof(ifr
));
121 (void)strncpy(ifr
.ifr_name
, iface
, sizeof(ifr
.ifr_name
));
123 error
= ioctl(s
, req
, &ifr
);
132 get_radio_state(const char *iface
)
136 if (do_req(iface
, SIOCGRADIO
, &radio
) == -1)
137 err(EX_OSERR
, "Can't read radio");
139 (void)printf("Radio is %s\n", radio
? "ON" : "OFF");
147 static const struct statistic tbl
[] = {
148 { 1, "Current transmission rate" },
149 { 2, "Fragmentation threshold" },
150 { 3, "RTS threshold" },
151 { 4, "Number of frames submitted for transfer" },
152 { 5, "Number of frames transmitted" },
153 { 6, "Number of unicast frames transmitted" },
154 { 7, "Number of unicast 802.11b frames transmitted at 1Mb/s" },
155 { 8, "Number of unicast 802.11b frames transmitted at 2Mb/s" },
156 { 9, "Number of unicast 802.11b frames transmitted at 5.5Mb/s" },
157 { 10, "Number of unicast 802.11b frames transmitted at 11Mb/s" },
159 { 19, "Number of unicast 802.11g frames transmitted at 1Mb/s" },
160 { 20, "Number of unicast 802.11g frames transmitted at 2Mb/s" },
161 { 21, "Number of unicast 802.11g frames transmitted at 5.5Mb/s" },
162 { 22, "Number of unicast 802.11g frames transmitted at 6Mb/s" },
163 { 23, "Number of unicast 802.11g frames transmitted at 9Mb/s" },
164 { 24, "Number of unicast 802.11g frames transmitted at 11Mb/s" },
165 { 25, "Number of unicast 802.11g frames transmitted at 12Mb/s" },
166 { 26, "Number of unicast 802.11g frames transmitted at 18Mb/s" },
167 { 27, "Number of unicast 802.11g frames transmitted at 24Mb/s" },
168 { 28, "Number of unicast 802.11g frames transmitted at 36Mb/s" },
169 { 29, "Number of unicast 802.11g frames transmitted at 48Mb/s" },
170 { 30, "Number of unicast 802.11g frames transmitted at 54Mb/s" },
171 { 31, "Number of multicast frames transmitted" },
172 { 32, "Number of multicast 802.11b frames transmitted at 1Mb/s" },
173 { 33, "Number of multicast 802.11b frames transmitted at 2Mb/s" },
174 { 34, "Number of multicast 802.11b frames transmitted at 5.5Mb/s" },
175 { 35, "Number of multicast 802.11b frames transmitted at 11Mb/s" },
177 { 44, "Number of multicast 802.11g frames transmitted at 1Mb/s" },
178 { 45, "Number of multicast 802.11g frames transmitted at 2Mb/s" },
179 { 46, "Number of multicast 802.11g frames transmitted at 5.5Mb/s" },
180 { 47, "Number of multicast 802.11g frames transmitted at 6Mb/s" },
181 { 48, "Number of multicast 802.11g frames transmitted at 9Mb/s" },
182 { 49, "Number of multicast 802.11g frames transmitted at 11Mb/s" },
183 { 50, "Number of multicast 802.11g frames transmitted at 12Mb/s" },
184 { 51, "Number of multicast 802.11g frames transmitted at 18Mb/s" },
185 { 52, "Number of multicast 802.11g frames transmitted at 24Mb/s" },
186 { 53, "Number of multicast 802.11g frames transmitted at 36Mb/s" },
187 { 54, "Number of multicast 802.11g frames transmitted at 48Mb/s" },
188 { 55, "Number of multicast 802.11g frames transmitted at 54Mb/s" },
189 { 56, "Number of transmission retries" },
190 { 57, "Number of transmission failures" },
191 { 58, "Number of frames with a bad CRC received" },
193 { 61, "Number of full scans" },
194 { 62, "Number of partial scans" },
196 { 64, "Number of bytes transmitted" },
197 { 65, "Current RSSI" },
198 { 66, "Number of beacons received" },
199 { 67, "Number of beacons missed" },
205 get_statistics(const char *iface
)
207 static u_int32_t stats
[256];
208 const struct statistic
*st
;
210 if (do_req(iface
, SIOCGTABLE0
, stats
) == -1)
211 err(EX_OSERR
, "Can't read statistics");
213 for (st
= tbl
; st
->index
!= 0; st
++)
214 (void)printf("%-60s[%u]\n", st
->desc
, stats
[st
->index
]);