1 /* $NetBSD: ipwctl.c,v 1.8 2006/08/06 07:31:32 skrll Exp $ */
2 /* Id: ipwctl.c,v 1.1.2.1 2004/08/19 16:24:50 damien Exp */
6 * Damien Bergamini <damien.bergamini@free.fr>. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice unmodified, this list of conditions, and the following
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: ipwctl.c,v 1.8 2006/08/06 07:31:32 skrll Exp $");
34 #include <sys/types.h>
35 #include <sys/ioctl.h>
37 #include <sys/socket.h>
51 #define SIOCGRADIO _IOWR('i', 139, struct ifreq)
52 #define SIOCGTABLE1 _IOWR('i', 140, struct ifreq)
54 static void usage(void) __dead
;
55 static int do_req(const char *, unsigned long, void *);
56 static void get_radio_state(const char *);
57 static void get_statistics(const char *);
60 main(int argc
, char **argv
)
67 ch
= getopt(argc
, argv
, "i:");
71 if (argc
> 1 && argv
[1][0] != '-') {
82 while ((ch
= getopt(argc
, argv
, "kr")) != -1) {
85 get_radio_state(iface
);
93 get_statistics(iface
);
101 (void)fprintf(stderr
, "Usage: %s -i iface\n"
102 "\t%s -i iface -r\n", getprogname(), getprogname());
108 do_req(const char *iface
, unsigned long req
, void *data
)
114 if ((s
= socket(AF_INET
, SOCK_DGRAM
, 0)) == -1)
115 err(EX_OSERR
, "Can't create socket");
117 memset(&ifr
, 0, sizeof(ifr
));
118 strncpy(ifr
.ifr_name
, iface
, sizeof(ifr
.ifr_name
));
120 error
= ioctl(s
, req
, &ifr
);
128 get_radio_state(const char *iface
)
132 if (do_req(iface
, SIOCGRADIO
, &radio
) == -1) {
134 errx(EX_OSERR
, "Can't retrieve radio transmitter "
135 "state: No firmware");
137 err(EX_OSERR
, "Can't retrieve radio transmitter state");
140 (void)printf("Radio is %s\n", radio
? "ON" : "OFF");
155 * TIM = Traffic Information Message
156 * DTIM = Delivery TIM
157 * ATIM = Announcement TIM
158 * PSP = Power Save Poll
159 * RTS = Request To Send
160 * CTS = Clear To Send
161 * RSSI = Received Signal Strength Indicator
164 static const struct statistic tbl
[] = {
165 { 1, "Number of frames submitted for transfer", INT
},
166 { 2, "Number of frames transmitted", INT
},
167 { 3, "Number of unicast frames transmitted", INT
},
168 { 4, "Number of unicast frames transmitted at 1Mb/s", INT
},
169 { 5, "Number of unicast frames transmitted at 2Mb/s", INT
},
170 { 6, "Number of unicast frames transmitted at 5.5Mb/s", INT
},
171 { 7, "Number of unicast frames transmitted at 11Mb/s", INT
},
173 { 13, "Number of multicast frames transmitted at 1Mb/s", INT
},
174 { 14, "Number of multicast frames transmitted at 2Mb/s", INT
},
175 { 15, "Number of multicast frames transmitted at 5.5Mb/s", INT
},
176 { 16, "Number of multicast frames transmitted at 11Mb/s", INT
},
178 { 21, "Number of null frames transmitted", INT
},
179 { 22, "Number of RTS frames transmitted", INT
},
180 { 23, "Number of CTS frames transmitted", INT
},
181 { 24, "Number of ACK frames transmitted", INT
},
182 { 25, "Number of association requests transmitted", INT
},
183 { 26, "Number of association responses transmitted", INT
},
184 { 27, "Number of reassociation requests transmitted", INT
},
185 { 28, "Number of reassociation responses transmitted", INT
},
186 { 29, "Number of probe requests transmitted", INT
},
187 { 30, "Number of probe reponses transmitted", INT
},
188 { 31, "Number of beacons transmitted", INT
},
189 { 32, "Number of ATIM frames transmitted", INT
},
190 { 33, "Number of disassociation requests transmitted", INT
},
191 { 34, "Number of authentification requests transmitted", INT
},
192 { 35, "Number of deauthentification requests transmitted", INT
},
194 { 41, "Number of bytes transmitted", INT
},
195 { 42, "Number of transmission retries", INT
},
196 { 43, "Number of transmission retries at 1Mb/s", INT
},
197 { 44, "Number of transmission retries at 2Mb/s", INT
},
198 { 45, "Number of transmission retries at 5.5Mb/s", INT
},
199 { 46, "Number of transmission retries at 11Mb/s", INT
},
201 { 51, "Number of transmission failures", INT
},
203 { 54, "Number of transmission aborted due to DMA", INT
},
205 { 56, "Number of disassociation failures", INT
},
207 { 58, "Number of spanning tree frames transmitted", INT
},
208 { 59, "Number of transmission errors due to missing ACK", INT
},
210 { 61, "Number of frames received", INT
},
211 { 62, "Number of unicast frames received", INT
},
212 { 63, "Number of unicast frames received at 1Mb/s", INT
},
213 { 64, "Number of unicast frames received at 2Mb/s", INT
},
214 { 65, "Number of unicast frames received at 5.5Mb/s", INT
},
215 { 66, "Number of unicast frames received at 11Mb/s", INT
},
217 { 71, "Number of multicast frames received", INT
},
218 { 72, "Number of multicast frames received at 1Mb/s", INT
},
219 { 73, "Number of multicast frames received at 2Mb/s", INT
},
220 { 74, "Number of multicast frames received at 5.5Mb/s", INT
},
221 { 75, "Number of multicast frames received at 11Mb/s", INT
},
223 { 80, "Number of null frames received", INT
},
224 { 81, "Number of poll frames received", INT
},
225 { 82, "Number of RTS frames received", INT
},
226 { 83, "Number of CTS frames received", INT
},
227 { 84, "Number of ACK frames received", INT
},
228 { 85, "Number of CF-End frames received", INT
},
229 { 86, "Number of CF-End + CF-Ack frames received", INT
},
230 { 87, "Number of association requests received", INT
},
231 { 88, "Number of association responses received", INT
},
232 { 89, "Number of reassociation requests received", INT
},
233 { 90, "Number of reassociation responses received", INT
},
234 { 91, "Number of probe requests received", INT
},
235 { 92, "Number of probe reponses received", INT
},
236 { 93, "Number of beacons received", INT
},
237 { 94, "Number of ATIM frames received", INT
},
238 { 95, "Number of disassociation requests received", INT
},
239 { 96, "Number of authentification requests received", INT
},
240 { 97, "Number of deauthentification requests received", INT
},
242 { 101, "Number of bytes received", INT
},
243 { 102, "Number of frames with a bad CRC received", INT
},
244 { 103, "Number of frames with a bad CRC received at 1Mb/s", INT
},
245 { 104, "Number of frames with a bad CRC received at 2Mb/s", INT
},
246 { 105, "Number of frames with a bad CRC received at 5.5Mb/s", INT
},
247 { 106, "Number of frames with a bad CRC received at 11Mb/s", INT
},
249 { 112, "Number of duplicated frames received at 1Mb/s", INT
},
250 { 113, "Number of duplicated frames received at 2Mb/s", INT
},
251 { 114, "Number of duplicated frames received at 5.5Mb/s", INT
},
252 { 115, "Number of duplicated frames received at 11Mb/s", INT
},
254 { 119, "Number of duplicated frames received", INT
},
256 { 123, "Number of frames with a bad protocol received", INT
},
257 { 124, "Boot time", INT
},
258 { 125, "Number of frames dropped due to missing buffer", INT
},
259 { 126, "Number of frames dropped due to DMA", INT
},
261 { 128, "Number of frames dropped due to missing fragment", INT
},
262 { 129, "Number of frames dropped due to non-seq fragment", INT
},
263 { 130, "Number of frames dropped due to missing first frame", INT
},
264 { 131, "Number of frames dropped due to uncompleted frame", INT
},
266 { 137, "Number of times adapter suspended", INT
},
267 { 138, "Beacon timeout", INT
},
268 { 139, "Number of poll response timeouts", INT
},
270 { 141, "Number of PSP DTIM frames received", INT
},
271 { 142, "Number of PSP TIM frames received", INT
},
272 { 143, "PSP station Id", INT
},
274 { 147, "RTC time of last association", INT
},
275 { 148, "Percentage of missed beacons", PERCENTAGE
},
276 { 149, "Percentage of missed transmission retries", PERCENTAGE
},
278 { 151, "Number of access points in access points table", INT
},
280 { 153, "Number of associations", INT
},
281 { 154, "Number of association failures", INT
},
282 { 156, "Number of full scans", INT
},
283 { 157, "Card disabled", BOOL
},
285 { 160, "RSSI at time of association", INT
},
286 { 161, "Number of reassociations due to no probe response", INT
},
287 { 162, "Number of reassociations due to poor line quality", INT
},
288 { 163, "Number of reassociations due to load", INT
},
289 { 164, "Number of reassociations due to access point RSSI level", INT
},
290 { 165, "Number of reassociations due to load leveling", INT
},
292 { 170, "Number of times authentification failed", INT
},
293 { 171, "Number of times authentification response failed", INT
},
294 { 172, "Number of entries in association table", INT
},
295 { 173, "Average RSSI", INT
},
297 { 176, "Self test status", INT
},
298 { 177, "Power mode", INT
},
299 { 178, "Power index", INT
},
300 { 179, "IEEE country code", HEX
},
301 { 180, "Channels supported for this country", MASK
},
302 { 181, "Number of adapter warm resets", INT
},
303 { 182, "Beacon interval", INT
},
305 { 184, "Princeton version", INT
},
306 { 185, "Antenna diversity disabled", BOOL
},
307 { 186, "CCA RSSI", INT
},
308 { 187, "Number of times EEPROM updated", INT
},
309 { 188, "Beacon intervals between DTIM", INT
},
310 { 189, "Current channel", INT
},
311 { 190, "RTC time", INT
},
312 { 191, "Operating mode", INT
},
313 { 192, "Transmission rate", HEX
},
314 { 193, "Supported transmission rates", MASK
},
315 { 194, "ATIM window", INT
},
316 { 195, "Supported basic transmission rates", MASK
},
317 { 196, "Adapter highest rate", HEX
},
318 { 197, "Access point highest rate", HEX
},
319 { 198, "Management frame capability", BOOL
},
320 { 199, "Type of authentification", INT
},
321 { 200, "Adapter card platform type", INT
},
322 { 201, "RTS threshold", INT
},
323 { 202, "International mode", BOOL
},
324 { 203, "Fragmentation threshold", INT
},
326 { 213, "Microcode version", INT
},
332 get_statistics(const char *iface
)
334 static unsigned long stats
[256]; /* XXX */
335 const struct statistic
*st
;
337 if (do_req(iface
, SIOCGTABLE1
, stats
) == -1) {
339 errx(EX_OSERR
, "Can't retrieve statistics: No "
342 err(EX_OSERR
, "Can't retrieve statistics");
345 for (st
= tbl
; st
->index
!= 0; st
++) {
346 (void)printf("%-60s[", st
->desc
);
349 (void)printf("%lu", stats
[st
->index
]);
353 (void)printf(stats
[st
->index
] ? "true" : "false");
357 (void)printf("%lu%%", stats
[st
->index
]);
362 (void)printf("0x%08lX", stats
[st
->index
]);