Remove advertising header from man pages.
[dragonfly.git] / usr.sbin / ancontrol / ancontrol.c
blob822ef95ca018700a00c77d857e3002014d1f9a75
1 /*
2 * Copyright 1997, 1998, 1999
3 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
32 * @(#) Copyright (c) 1997, 1998, 1999 Bill Paul. All rights reserved.
33 * $FreeBSD: src/usr.sbin/ancontrol/ancontrol.c,v 1.1.2.9 2003/02/01 03:25:13 ambrisko Exp $
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/socket.h>
39 #include <sys/ioctl.h>
41 #include <net/if.h>
42 #include <net/if_var.h>
43 #include <net/ethernet.h>
45 #include <dev/netif/an/if_aironet_ieee.h>
47 #include <stdio.h>
48 #include <string.h>
49 #include <stdlib.h>
50 #include <unistd.h>
51 #include <errno.h>
52 #include <err.h>
53 #include <md4.h>
54 #include <ctype.h>
56 static int an_getval (const char *, struct an_req *);
57 static void an_setval (const char *, struct an_req *);
58 static void an_printwords(u_int16_t *, int);
59 static void an_printspeeds(u_int8_t*, int);
60 static void an_printbool(int);
61 static void an_printhex (char *, int);
62 static void an_printstr (char *, int);
63 static void an_dumpstatus(const char *);
64 static void an_dumpstats(const char *);
65 static void an_dumpconfig(const char *);
66 static void an_dumpcaps (const char *);
67 static void an_dumpssid (const char *);
68 static void an_dumpap (const char *);
69 static void an_setconfig(const char *, int, void *);
70 static void an_setssid (const char *, int, void *);
71 static void an_setap (const char *, int, void *);
72 static void an_setspeed (const char *, int, void *);
73 static void an_readkeyinfo(const char *);
74 #ifdef ANCACHE
75 static void an_zerocache(const char *);
76 static void an_readcache(const char *);
77 #endif
78 static int an_hex2int (char);
79 static void an_str2key (char *, struct an_ltv_key *);
80 static void an_setkeys (const char *, char *, int);
81 static void an_enable_tx_key(const char *, char *);
82 static void an_enable_leap_mode(const char *, char *);
83 static void usage (char *);
84 static void an_dumprssimap(const char *);
85 int main (int, char **);
87 #define ACT_DUMPSTATS 1
88 #define ACT_DUMPCONFIG 2
89 #define ACT_DUMPSTATUS 3
90 #define ACT_DUMPCAPS 4
91 #define ACT_DUMPSSID 5
92 #define ACT_DUMPAP 6
94 #define ACT_SET_OPMODE 7
95 #define ACT_SET_SSID1 8
96 #define ACT_SET_SSID2 9
97 #define ACT_SET_SSID3 10
98 #define ACT_SET_FREQ 11
99 #define ACT_SET_AP1 12
100 #define ACT_SET_AP2 13
101 #define ACT_SET_AP3 14
102 #define ACT_SET_AP4 15
103 #define ACT_SET_DRIVERNAME 16
104 #define ACT_SET_SCANMODE 17
105 #define ACT_SET_TXRATE 18
106 #define ACT_SET_RTS_THRESH 19
107 #define ACT_SET_PWRSAVE 20
108 #define ACT_SET_DIVERSITY_RX 21
109 #define ACT_SET_DIVERSITY_TX 22
110 #define ACT_SET_RTS_RETRYLIM 23
111 #define ACT_SET_WAKE_DURATION 24
112 #define ACT_SET_BEACON_PERIOD 25
113 #define ACT_SET_TXPWR 26
114 #define ACT_SET_FRAG_THRESH 27
115 #define ACT_SET_NETJOIN 28
116 #define ACT_SET_MYNAME 29
117 #define ACT_SET_MAC 30
119 #define ACT_DUMPCACHE 31
120 #define ACT_ZEROCACHE 32
122 #define ACT_ENABLE_WEP 33
123 #define ACT_SET_KEY_TYPE 34
124 #define ACT_SET_KEYS 35
125 #define ACT_ENABLE_TX_KEY 36
126 #define ACT_SET_MONITOR_MODE 37
127 #define ACT_SET_LEAP_MODE 38
129 #define ACT_DUMPRSSIMAP 39
131 static int
132 an_getval(const char *iface, struct an_req *areq)
134 struct ifreq ifr;
135 int s, okay = 1;
137 bzero((char *)&ifr, sizeof(ifr));
139 strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
140 ifr.ifr_data = (caddr_t)areq;
142 s = socket(AF_INET, SOCK_DGRAM, 0);
144 if (s == -1)
145 err(1, "socket");
147 if (ioctl(s, SIOCGAIRONET, &ifr) == -1) {
148 okay = 0;
149 err(1, "SIOCGAIRONET");
152 close(s);
154 return okay;
157 static void
158 an_setval(const char *iface, struct an_req *areq)
160 struct ifreq ifr;
161 int s;
163 bzero((char *)&ifr, sizeof(ifr));
165 strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
166 ifr.ifr_data = (caddr_t)areq;
168 s = socket(AF_INET, SOCK_DGRAM, 0);
170 if (s == -1)
171 err(1, "socket");
173 if (ioctl(s, SIOCSAIRONET, &ifr) == -1)
174 err(1, "SIOCSAIRONET");
176 close(s);
178 return;
181 static void
182 an_printstr(char *str, int len)
184 int i;
186 for (i = 0; i < len - 1; i++) {
187 if (str[i] == '\0')
188 str[i] = ' ';
191 printf("[ %.*s ]", len, str);
193 return;
196 static void
197 an_printwords(u_int16_t *w, int len)
199 int i;
201 printf("[ ");
202 for (i = 0; i < len; i++)
203 printf("%d ", w[i]);
204 printf("]");
206 return;
209 static void
210 an_printspeeds(u_int8_t *w, int len)
212 int i;
214 printf("[ ");
215 for (i = 0; i < len && w[i]; i++)
216 printf("%2.1fMbps ", w[i] * 0.500);
217 printf("]");
219 return;
222 static void
223 an_printbool(int val)
225 if (val)
226 printf("[ On ]");
227 else
228 printf("[ Off ]");
230 return;
233 static void
234 an_printhex(char *ptr, int len)
236 int i;
238 printf("[ ");
239 for (i = 0; i < len; i++) {
240 printf("%02x", ptr[i] & 0xFF);
241 if (i < (len - 1))
242 printf(":");
245 printf(" ]");
246 return;
249 static void
250 an_dumpstatus(const char *iface)
252 struct an_ltv_status *sts;
253 struct an_req areq;
254 struct an_ltv_rssi_map an_rssimap;
255 int rssimap_valid = 0;
258 * Try to get RSSI to percent and dBM table
261 an_rssimap.an_len = sizeof(an_rssimap);
262 an_rssimap.an_type = AN_RID_RSSI_MAP;
263 rssimap_valid = an_getval(iface, (struct an_req*)&an_rssimap);
265 if (rssimap_valid)
266 printf("RSSI table:\t\t[ present ]\n");
267 else
268 printf("RSSI table:\t\t[ not available ]\n");
270 areq.an_len = sizeof(areq);
271 areq.an_type = AN_RID_STATUS;
273 an_getval(iface, &areq);
275 sts = (struct an_ltv_status *)&areq;
277 printf("MAC address:\t\t");
278 an_printhex((char *)&sts->an_macaddr, ETHER_ADDR_LEN);
279 printf("\nOperating mode:\t\t[ ");
280 if (sts->an_opmode & AN_STATUS_OPMODE_CONFIGURED)
281 printf("configured ");
282 if (sts->an_opmode & AN_STATUS_OPMODE_MAC_ENABLED)
283 printf("MAC ON ");
284 if (sts->an_opmode & AN_STATUS_OPMODE_RX_ENABLED)
285 printf("RX ON ");
286 if (sts->an_opmode & AN_STATUS_OPMODE_IN_SYNC)
287 printf("synced ");
288 if (sts->an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
289 printf("associated ");
290 if (sts->an_opmode & AN_STATUS_OPMODE_LEAP)
291 printf("LEAP ");
292 if (sts->an_opmode & AN_STATUS_OPMODE_ERROR)
293 printf("error ");
294 printf("]\n");
295 printf("Error code:\t\t");
296 an_printhex((char *)&sts->an_errcode, 1);
297 if (rssimap_valid)
298 printf("\nSignal strength:\t[ %d%% ]",
299 an_rssimap.an_entries[
300 sts->an_normalized_strength].an_rss_pct);
301 else
302 printf("\nSignal strength:\t[ %d%% ]",
303 sts->an_normalized_strength);
304 printf("\nAverage Noise:\t\t[ %d%% ]",sts->an_avg_noise_prev_min_pc);
305 if (rssimap_valid)
306 printf("\nSignal quality:\t\t[ %d%% ]",
307 an_rssimap.an_entries[
308 sts->an_cur_signal_quality].an_rss_pct);
309 else
310 printf("\nSignal quality:\t\t[ %d ]",
311 sts->an_cur_signal_quality);
312 printf("\nMax Noise:\t\t[ %d%% ]",sts->an_max_noise_prev_min_pc);
314 * XXX: This uses the old definition of the rate field (units of
315 * 500kbps). Technically the new definition is that this field
316 * contains arbitrary values, but no devices which need this
317 * support exist and the IEEE seems to intend to use the old
318 * definition until they get something big so we'll keep using
319 * it as well because this will work with new cards with
320 * rate <= 63.5Mbps.
322 printf("\nCurrent TX rate:\t[ %d%s ]", sts->an_current_tx_rate / 2,
323 (sts->an_current_tx_rate % 2) ? ".5" : "");
324 printf("\nCurrent SSID:\t\t");
325 an_printstr((char *)&sts->an_ssid, sts->an_ssidlen);
326 printf("\nCurrent AP name:\t");
327 an_printstr((char *)&sts->an_ap_name, 16);
328 printf("\nCurrent BSSID:\t\t");
329 an_printhex((char *)&sts->an_cur_bssid, ETHER_ADDR_LEN);
330 printf("\nBeacon period:\t\t");
331 an_printwords(&sts->an_beacon_period, 1);
332 printf("\nDTIM period:\t\t");
333 an_printwords(&sts->an_dtim_period, 1);
334 printf("\nATIM duration:\t\t");
335 an_printwords(&sts->an_atim_duration, 1);
336 printf("\nHOP period:\t\t");
337 an_printwords(&sts->an_hop_period, 1);
338 printf("\nChannel set:\t\t");
339 an_printwords(&sts->an_channel_set, 1);
340 printf("\nCurrent channel:\t");
341 an_printwords(&sts->an_cur_channel, 1);
342 printf("\nHops to backbone:\t");
343 an_printwords(&sts->an_hops_to_backbone, 1);
344 printf("\nTotal AP load:\t\t");
345 an_printwords(&sts->an_ap_total_load, 1);
346 printf("\nOur generated load:\t");
347 an_printwords(&sts->an_our_generated_load, 1);
348 printf("\nAccumulated ARL:\t");
349 an_printwords(&sts->an_accumulated_arl, 1);
350 printf("\n");
351 return;
354 static void
355 an_dumpcaps(const char *iface)
357 struct an_ltv_caps *caps;
358 struct an_req areq;
359 u_int16_t tmp;
361 areq.an_len = sizeof(areq);
362 areq.an_type = AN_RID_CAPABILITIES;
364 an_getval(iface, &areq);
366 caps = (struct an_ltv_caps *)&areq;
368 printf("OUI:\t\t\t");
369 an_printhex((char *)&caps->an_oui, 3);
370 printf("\nProduct number:\t\t");
371 an_printwords(&caps->an_prodnum, 1);
372 printf("\nManufacturer name:\t");
373 an_printstr((char *)&caps->an_manufname, 32);
374 printf("\nProduce name:\t\t");
375 an_printstr((char *)&caps->an_prodname, 16);
376 printf("\nFirmware version:\t");
377 an_printstr((char *)&caps->an_prodvers, 1);
378 printf("\nOEM MAC address:\t");
379 an_printhex((char *)&caps->an_oemaddr, ETHER_ADDR_LEN);
380 printf("\nAironet MAC address:\t");
381 an_printhex((char *)&caps->an_aironetaddr, ETHER_ADDR_LEN);
382 printf("\nRadio type:\t\t[ ");
383 if (caps->an_radiotype & AN_RADIOTYPE_80211_FH)
384 printf("802.11 FH");
385 else if (caps->an_radiotype & AN_RADIOTYPE_80211_DS)
386 printf("802.11 DS");
387 else if (caps->an_radiotype & AN_RADIOTYPE_LM2000_DS)
388 printf("LM2000 DS");
389 else
390 printf("unknown (%x)", caps->an_radiotype);
391 printf(" ]");
392 printf("\nRegulatory domain:\t");
393 an_printwords(&caps->an_regdomain, 1);
394 printf("\nAssigned CallID:\t");
395 an_printhex((char *)&caps->an_callid, 6);
396 printf("\nSupported speeds:\t");
397 an_printspeeds(caps->an_rates, 8);
398 printf("\nRX Diversity:\t\t[ ");
399 if (caps->an_rx_diversity == AN_DIVERSITY_FACTORY_DEFAULT)
400 printf("factory default");
401 else if (caps->an_rx_diversity == AN_DIVERSITY_ANTENNA_1_ONLY)
402 printf("antenna 1 only");
403 else if (caps->an_rx_diversity == AN_DIVERSITY_ANTENNA_2_ONLY)
404 printf("antenna 2 only");
405 else if (caps->an_rx_diversity == AN_DIVERSITY_ANTENNA_1_AND_2)
406 printf("antenna 1 and 2");
407 printf(" ]");
408 printf("\nTX Diversity:\t\t[ ");
409 if (caps->an_tx_diversity == AN_DIVERSITY_FACTORY_DEFAULT)
410 printf("factory default");
411 else if (caps->an_tx_diversity == AN_DIVERSITY_ANTENNA_1_ONLY)
412 printf("antenna 1 only");
413 else if (caps->an_tx_diversity == AN_DIVERSITY_ANTENNA_2_ONLY)
414 printf("antenna 2 only");
415 else if (caps->an_tx_diversity == AN_DIVERSITY_ANTENNA_1_AND_2)
416 printf("antenna 1 and 2");
417 printf(" ]");
418 printf("\nSupported power levels:\t");
419 an_printwords(caps->an_tx_powerlevels, 8);
420 printf("\nHardware revision:\t");
421 tmp = ntohs(caps->an_hwrev);
422 an_printhex((char *)&tmp, 2);
423 printf("\nSoftware revision:\t");
424 tmp = ntohs(caps->an_fwrev);
425 an_printhex((char *)&tmp, 2);
426 printf("\nSoftware subrevision:\t");
427 tmp = ntohs(caps->an_fwsubrev);
428 an_printhex((char *)&tmp, 2);
429 printf("\nInterface revision:\t");
430 tmp = ntohs(caps->an_ifacerev);
431 an_printhex((char *)&tmp, 2);
432 printf("\nBootblock revision:\t");
433 tmp = ntohs(caps->an_bootblockrev);
434 an_printhex((char *)&tmp, 2);
435 printf("\n");
436 return;
439 static void
440 an_dumpstats(const char *iface)
442 struct an_ltv_stats *stats;
443 struct an_req areq;
444 caddr_t ptr;
446 areq.an_len = sizeof(areq);
447 areq.an_type = AN_RID_32BITS_CUM;
449 an_getval(iface, &areq);
451 ptr = (caddr_t)&areq;
452 ptr -= 2;
453 stats = (struct an_ltv_stats *)ptr;
455 printf("RX overruns:\t\t\t\t\t[ %d ]\n", stats->an_rx_overruns);
456 printf("RX PLCP CSUM errors:\t\t\t\t[ %d ]\n",
457 stats->an_rx_plcp_csum_errs);
458 printf("RX PLCP format errors:\t\t\t\t[ %d ]\n",
459 stats->an_rx_plcp_format_errs);
460 printf("RX PLCP length errors:\t\t\t\t[ %d ]\n",
461 stats->an_rx_plcp_len_errs);
462 printf("RX MAC CRC errors:\t\t\t\t[ %d ]\n",
463 stats->an_rx_mac_crc_errs);
464 printf("RX MAC CRC OK:\t\t\t\t\t[ %d ]\n",
465 stats->an_rx_mac_crc_ok);
466 printf("RX WEP errors:\t\t\t\t\t[ %d ]\n",
467 stats->an_rx_wep_errs);
468 printf("RX WEP OK:\t\t\t\t\t[ %d ]\n",
469 stats->an_rx_wep_ok);
470 printf("Long retries:\t\t\t\t\t[ %d ]\n",
471 stats->an_retry_long);
472 printf("Short retries:\t\t\t\t\t[ %d ]\n",
473 stats->an_retry_short);
474 printf("Retries exhausted:\t\t\t\t[ %d ]\n",
475 stats->an_retry_max);
476 printf("Bad ACK:\t\t\t\t\t[ %d ]\n",
477 stats->an_no_ack);
478 printf("Bad CTS:\t\t\t\t\t[ %d ]\n",
479 stats->an_no_cts);
480 printf("RX good ACKs:\t\t\t\t\t[ %d ]\n",
481 stats->an_rx_ack_ok);
482 printf("RX good CTSs:\t\t\t\t\t[ %d ]\n",
483 stats->an_rx_cts_ok);
484 printf("TX good ACKs:\t\t\t\t\t[ %d ]\n",
485 stats->an_tx_ack_ok);
486 printf("TX good RTSs:\t\t\t\t\t[ %d ]\n",
487 stats->an_tx_rts_ok);
488 printf("TX good CTSs:\t\t\t\t\t[ %d ]\n",
489 stats->an_tx_cts_ok);
490 printf("LMAC multicasts transmitted:\t\t\t[ %d ]\n",
491 stats->an_tx_lmac_mcasts);
492 printf("LMAC broadcasts transmitted:\t\t\t[ %d ]\n",
493 stats->an_tx_lmac_bcasts);
494 printf("LMAC unicast frags transmitted:\t\t\t[ %d ]\n",
495 stats->an_tx_lmac_ucast_frags);
496 printf("LMAC unicasts transmitted:\t\t\t[ %d ]\n",
497 stats->an_tx_lmac_ucasts);
498 printf("Beacons transmitted:\t\t\t\t[ %d ]\n",
499 stats->an_tx_beacons);
500 printf("Beacons received:\t\t\t\t[ %d ]\n",
501 stats->an_rx_beacons);
502 printf("Single transmit collisions:\t\t\t[ %d ]\n",
503 stats->an_tx_single_cols);
504 printf("Multiple transmit collisions:\t\t\t[ %d ]\n",
505 stats->an_tx_multi_cols);
506 printf("Transmits without deferrals:\t\t\t[ %d ]\n",
507 stats->an_tx_defers_no);
508 printf("Transmits deferred due to protocol:\t\t[ %d ]\n",
509 stats->an_tx_defers_prot);
510 printf("Transmits deferred due to energy detect:\t\t[ %d ]\n",
511 stats->an_tx_defers_energy);
512 printf("RX duplicate frames/frags:\t\t\t[ %d ]\n",
513 stats->an_rx_dups);
514 printf("RX partial frames:\t\t\t\t[ %d ]\n",
515 stats->an_rx_partial);
516 printf("TX max lifetime exceeded:\t\t\t[ %d ]\n",
517 stats->an_tx_too_old);
518 printf("RX max lifetime exceeded:\t\t\t[ %d ]\n",
519 stats->an_tx_too_old);
520 printf("Sync lost due to too many missed beacons:\t[ %d ]\n",
521 stats->an_lostsync_missed_beacons);
522 printf("Sync lost due to ARL exceeded:\t\t\t[ %d ]\n",
523 stats->an_lostsync_arl_exceeded);
524 printf("Sync lost due to deauthentication:\t\t[ %d ]\n",
525 stats->an_lostsync_deauthed);
526 printf("Sync lost due to disassociation:\t\t[ %d ]\n",
527 stats->an_lostsync_disassociated);
528 printf("Sync lost due to excess change in TSF timing:\t[ %d ]\n",
529 stats->an_lostsync_tsf_timing);
530 printf("Host transmitted multicasts:\t\t\t[ %d ]\n",
531 stats->an_tx_host_mcasts);
532 printf("Host transmitted broadcasts:\t\t\t[ %d ]\n",
533 stats->an_tx_host_bcasts);
534 printf("Host transmitted unicasts:\t\t\t[ %d ]\n",
535 stats->an_tx_host_ucasts);
536 printf("Host transmission failures:\t\t\t[ %d ]\n",
537 stats->an_tx_host_failed);
538 printf("Host received multicasts:\t\t\t[ %d ]\n",
539 stats->an_rx_host_mcasts);
540 printf("Host received broadcasts:\t\t\t[ %d ]\n",
541 stats->an_rx_host_bcasts);
542 printf("Host received unicasts:\t\t\t\t[ %d ]\n",
543 stats->an_rx_host_ucasts);
544 printf("Host receive discards:\t\t\t\t[ %d ]\n",
545 stats->an_rx_host_discarded);
546 printf("HMAC transmitted multicasts:\t\t\t[ %d ]\n",
547 stats->an_tx_hmac_mcasts);
548 printf("HMAC transmitted broadcasts:\t\t\t[ %d ]\n",
549 stats->an_tx_hmac_bcasts);
550 printf("HMAC transmitted unicasts:\t\t\t[ %d ]\n",
551 stats->an_tx_hmac_ucasts);
552 printf("HMAC transmissions failed:\t\t\t[ %d ]\n",
553 stats->an_tx_hmac_failed);
554 printf("HMAC received multicasts:\t\t\t[ %d ]\n",
555 stats->an_rx_hmac_mcasts);
556 printf("HMAC received broadcasts:\t\t\t[ %d ]\n",
557 stats->an_rx_hmac_bcasts);
558 printf("HMAC received unicasts:\t\t\t\t[ %d ]\n",
559 stats->an_rx_hmac_ucasts);
560 printf("HMAC receive discards:\t\t\t\t[ %d ]\n",
561 stats->an_rx_hmac_discarded);
562 printf("HMAC transmits accepted:\t\t\t[ %d ]\n",
563 stats->an_tx_hmac_accepted);
564 printf("SSID mismatches:\t\t\t\t[ %d ]\n",
565 stats->an_ssid_mismatches);
566 printf("Access point mismatches:\t\t\t[ %d ]\n",
567 stats->an_ap_mismatches);
568 printf("Speed mismatches:\t\t\t\t[ %d ]\n",
569 stats->an_rates_mismatches);
570 printf("Authentication rejects:\t\t\t\t[ %d ]\n",
571 stats->an_auth_rejects);
572 printf("Authentication timeouts:\t\t\t[ %d ]\n",
573 stats->an_auth_timeouts);
574 printf("Association rejects:\t\t\t\t[ %d ]\n",
575 stats->an_assoc_rejects);
576 printf("Association timeouts:\t\t\t\t[ %d ]\n",
577 stats->an_assoc_timeouts);
578 printf("Management frames received:\t\t\t[ %d ]\n",
579 stats->an_rx_mgmt_pkts);
580 printf("Management frames transmitted:\t\t\t[ %d ]\n",
581 stats->an_tx_mgmt_pkts);
582 printf("Refresh frames received:\t\t\t[ %d ]\n",
583 stats->an_rx_refresh_pkts),
584 printf("Refresh frames transmitted:\t\t\t[ %d ]\n",
585 stats->an_tx_refresh_pkts),
586 printf("Poll frames received:\t\t\t\t[ %d ]\n",
587 stats->an_rx_poll_pkts);
588 printf("Poll frames transmitted:\t\t\t[ %d ]\n",
589 stats->an_tx_poll_pkts);
590 printf("Host requested sync losses:\t\t\t[ %d ]\n",
591 stats->an_lostsync_hostreq);
592 printf("Host transmitted bytes:\t\t\t\t[ %d ]\n",
593 stats->an_host_tx_bytes);
594 printf("Host received bytes:\t\t\t\t[ %d ]\n",
595 stats->an_host_rx_bytes);
596 printf("Uptime in microseconds:\t\t\t\t[ %d ]\n",
597 stats->an_uptime_usecs);
598 printf("Uptime in seconds:\t\t\t\t[ %d ]\n",
599 stats->an_uptime_secs);
600 printf("Sync lost due to better AP:\t\t\t[ %d ]\n",
601 stats->an_lostsync_better_ap);
603 return;
606 static void
607 an_dumpap(const char *iface)
609 struct an_ltv_aplist *ap;
610 struct an_req areq;
612 areq.an_len = sizeof(areq);
613 areq.an_type = AN_RID_APLIST;
615 an_getval(iface, &areq);
617 ap = (struct an_ltv_aplist *)&areq;
618 printf("Access point 1:\t\t\t");
619 an_printhex((char *)&ap->an_ap1, ETHER_ADDR_LEN);
620 printf("\nAccess point 2:\t\t\t");
621 an_printhex((char *)&ap->an_ap2, ETHER_ADDR_LEN);
622 printf("\nAccess point 3:\t\t\t");
623 an_printhex((char *)&ap->an_ap3, ETHER_ADDR_LEN);
624 printf("\nAccess point 4:\t\t\t");
625 an_printhex((char *)&ap->an_ap4, ETHER_ADDR_LEN);
626 printf("\n");
628 return;
631 static void
632 an_dumpssid(const char *iface)
634 struct an_ltv_ssidlist *ssid;
635 struct an_req areq;
637 areq.an_len = sizeof(areq);
638 areq.an_type = AN_RID_SSIDLIST;
640 an_getval(iface, &areq);
642 ssid = (struct an_ltv_ssidlist *)&areq;
643 printf("SSID 1:\t\t\t[ %.*s ]\n", ssid->an_ssid1_len, ssid->an_ssid1);
644 printf("SSID 2:\t\t\t[ %.*s ]\n", ssid->an_ssid2_len, ssid->an_ssid2);
645 printf("SSID 3:\t\t\t[ %.*s ]\n", ssid->an_ssid3_len, ssid->an_ssid3);
647 return;
650 static void
651 an_dumpconfig(const char *iface)
653 struct an_ltv_genconfig *cfg;
654 struct an_req areq;
655 unsigned char diversity;
657 areq.an_len = sizeof(areq);
658 areq.an_type = AN_RID_ACTUALCFG;
660 an_getval(iface, &areq);
662 cfg = (struct an_ltv_genconfig *)&areq;
664 printf("Operating mode:\t\t\t\t[ ");
665 if ((cfg->an_opmode & 0x7) == AN_OPMODE_IBSS_ADHOC)
666 printf("ad-hoc");
667 if ((cfg->an_opmode & 0x7) == AN_OPMODE_INFRASTRUCTURE_STATION)
668 printf("infrastructure");
669 if ((cfg->an_opmode & 0x7) == AN_OPMODE_AP)
670 printf("access point");
671 if ((cfg->an_opmode & 0x7) == AN_OPMODE_AP_REPEATER)
672 printf("access point repeater");
673 printf(" ]");
674 printf("\nReceive mode:\t\t\t\t[ ");
675 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_BC_MC_ADDR)
676 printf("broadcast/multicast/unicast");
677 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_BC_ADDR)
678 printf("broadcast/unicast");
679 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_ADDR)
680 printf("unicast");
681 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_80211_MONITOR_CURBSS)
682 printf("802.11 monitor, current BSSID");
683 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_80211_MONITOR_ANYBSS)
684 printf("802.11 monitor, any BSSID");
685 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_LAN_MONITOR_CURBSS)
686 printf("LAN monitor, current BSSID");
687 printf(" ]");
688 printf("\nFragment threshold:\t\t\t");
689 an_printwords(&cfg->an_fragthresh, 1);
690 printf("\nRTS threshold:\t\t\t\t");
691 an_printwords(&cfg->an_rtsthresh, 1);
692 printf("\nMAC address:\t\t\t\t");
693 an_printhex((char *)&cfg->an_macaddr, ETHER_ADDR_LEN);
694 printf("\nSupported rates:\t\t\t");
695 an_printspeeds(cfg->an_rates, 8);
696 printf("\nShort retry limit:\t\t\t");
697 an_printwords(&cfg->an_shortretry_limit, 1);
698 printf("\nLong retry limit:\t\t\t");
699 an_printwords(&cfg->an_longretry_limit, 1);
700 printf("\nTX MSDU lifetime:\t\t\t");
701 an_printwords(&cfg->an_tx_msdu_lifetime, 1);
702 printf("\nRX MSDU lifetime:\t\t\t");
703 an_printwords(&cfg->an_rx_msdu_lifetime, 1);
704 printf("\nStationary:\t\t\t\t");
705 an_printbool(cfg->an_stationary);
706 printf("\nOrdering:\t\t\t\t");
707 an_printbool(cfg->an_ordering);
708 printf("\nDevice type:\t\t\t\t[ ");
709 if (cfg->an_devtype == AN_DEVTYPE_PC4500)
710 printf("PC4500");
711 else if (cfg->an_devtype == AN_DEVTYPE_PC4800)
712 printf("PC4800");
713 else
714 printf("unknown (%x)", cfg->an_devtype);
715 printf(" ]");
716 printf("\nScanning mode:\t\t\t\t[ ");
717 if (cfg->an_scanmode == AN_SCANMODE_ACTIVE)
718 printf("active");
719 if (cfg->an_scanmode == AN_SCANMODE_PASSIVE)
720 printf("passive");
721 if (cfg->an_scanmode == AN_SCANMODE_AIRONET_ACTIVE)
722 printf("Aironet active");
723 printf(" ]");
724 printf("\nProbe delay:\t\t\t\t");
725 an_printwords(&cfg->an_probedelay, 1);
726 printf("\nProbe energy timeout:\t\t\t");
727 an_printwords(&cfg->an_probe_energy_timeout, 1);
728 printf("\nProbe response timeout:\t\t\t");
729 an_printwords(&cfg->an_probe_response_timeout, 1);
730 printf("\nBeacon listen timeout:\t\t\t");
731 an_printwords(&cfg->an_beacon_listen_timeout, 1);
732 printf("\nIBSS join network timeout:\t\t");
733 an_printwords(&cfg->an_ibss_join_net_timeout, 1);
734 printf("\nAuthentication timeout:\t\t\t");
735 an_printwords(&cfg->an_auth_timeout, 1);
736 printf("\nWEP enabled:\t\t\t\t[ ");
737 if (cfg->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE)
739 if (cfg->an_authtype & AN_AUTHTYPE_LEAP)
740 printf("LEAP");
741 else if (cfg->an_authtype & AN_AUTHTYPE_ALLOW_UNENCRYPTED)
742 printf("mixed cell");
743 else
744 printf("full");
746 else
747 printf("no");
748 printf(" ]");
749 printf("\nAuthentication type:\t\t\t[ ");
750 if ((cfg->an_authtype & AN_AUTHTYPE_MASK) == AN_AUTHTYPE_NONE)
751 printf("none");
752 if ((cfg->an_authtype & AN_AUTHTYPE_MASK) == AN_AUTHTYPE_OPEN)
753 printf("open");
754 if ((cfg->an_authtype & AN_AUTHTYPE_MASK) == AN_AUTHTYPE_SHAREDKEY)
755 printf("shared key");
756 printf(" ]");
757 printf("\nAssociation timeout:\t\t\t");
758 an_printwords(&cfg->an_assoc_timeout, 1);
759 printf("\nSpecified AP association timeout:\t");
760 an_printwords(&cfg->an_specified_ap_timeout, 1);
761 printf("\nOffline scan interval:\t\t\t");
762 an_printwords(&cfg->an_offline_scan_interval, 1);
763 printf("\nOffline scan duration:\t\t\t");
764 an_printwords(&cfg->an_offline_scan_duration, 1);
765 printf("\nLink loss delay:\t\t\t");
766 an_printwords(&cfg->an_link_loss_delay, 1);
767 printf("\nMax beacon loss time:\t\t\t");
768 an_printwords(&cfg->an_max_beacon_lost_time, 1);
769 printf("\nRefresh interval:\t\t\t");
770 an_printwords(&cfg->an_refresh_interval, 1);
771 printf("\nPower save mode:\t\t\t[ ");
772 if (cfg->an_psave_mode == AN_PSAVE_NONE)
773 printf("none");
774 if (cfg->an_psave_mode == AN_PSAVE_CAM)
775 printf("constantly awake mode");
776 if (cfg->an_psave_mode == AN_PSAVE_PSP)
777 printf("PSP");
778 if (cfg->an_psave_mode == AN_PSAVE_PSP_CAM)
779 printf("PSP-CAM (fast PSP)");
780 printf(" ]");
781 printf("\nSleep through DTIMs:\t\t\t");
782 an_printbool(cfg->an_sleep_for_dtims);
783 printf("\nPower save listen interval:\t\t");
784 an_printwords(&cfg->an_listen_interval, 1);
785 printf("\nPower save fast listen interval:\t");
786 an_printwords(&cfg->an_fast_listen_interval, 1);
787 printf("\nPower save listen decay:\t\t");
788 an_printwords(&cfg->an_listen_decay, 1);
789 printf("\nPower save fast listen decay:\t\t");
790 an_printwords(&cfg->an_fast_listen_decay, 1);
791 printf("\nAP/ad-hoc Beacon period:\t\t");
792 an_printwords(&cfg->an_beacon_period, 1);
793 printf("\nAP/ad-hoc ATIM duration:\t\t");
794 an_printwords(&cfg->an_atim_duration, 1);
795 printf("\nAP/ad-hoc current channel:\t\t");
796 an_printwords(&cfg->an_ds_channel, 1);
797 printf("\nAP/ad-hoc DTIM period:\t\t\t");
798 an_printwords(&cfg->an_dtim_period, 1);
799 printf("\nRadio type:\t\t\t\t[ ");
800 if (cfg->an_radiotype & AN_RADIOTYPE_80211_FH)
801 printf("802.11 FH");
802 else if (cfg->an_radiotype & AN_RADIOTYPE_80211_DS)
803 printf("802.11 DS");
804 else if (cfg->an_radiotype & AN_RADIOTYPE_LM2000_DS)
805 printf("LM2000 DS");
806 else
807 printf("unknown (%x)", cfg->an_radiotype);
808 printf(" ]");
809 printf("\nRX Diversity:\t\t\t\t[ ");
810 diversity = cfg->an_diversity & 0xFF;
811 if (diversity == AN_DIVERSITY_FACTORY_DEFAULT)
812 printf("factory default");
813 else if (diversity == AN_DIVERSITY_ANTENNA_1_ONLY)
814 printf("antenna 1 only");
815 else if (diversity == AN_DIVERSITY_ANTENNA_2_ONLY)
816 printf("antenna 2 only");
817 else if (diversity == AN_DIVERSITY_ANTENNA_1_AND_2)
818 printf("antenna 1 and 2");
819 printf(" ]");
820 printf("\nTX Diversity:\t\t\t\t[ ");
821 diversity = (cfg->an_diversity >> 8) & 0xFF;
822 if (diversity == AN_DIVERSITY_FACTORY_DEFAULT)
823 printf("factory default");
824 else if (diversity == AN_DIVERSITY_ANTENNA_1_ONLY)
825 printf("antenna 1 only");
826 else if (diversity == AN_DIVERSITY_ANTENNA_2_ONLY)
827 printf("antenna 2 only");
828 else if (diversity == AN_DIVERSITY_ANTENNA_1_AND_2)
829 printf("antenna 1 and 2");
830 printf(" ]");
831 printf("\nTransmit power level:\t\t\t");
832 an_printwords(&cfg->an_tx_power, 1);
833 printf("\nRSS threshold:\t\t\t\t");
834 an_printwords(&cfg->an_rss_thresh, 1);
835 printf("\nNode name:\t\t\t\t");
836 an_printstr((char *)&cfg->an_nodename, 16);
837 printf("\nARL threshold:\t\t\t\t");
838 an_printwords(&cfg->an_arl_thresh, 1);
839 printf("\nARL decay:\t\t\t\t");
840 an_printwords(&cfg->an_arl_decay, 1);
841 printf("\nARL delay:\t\t\t\t");
842 an_printwords(&cfg->an_arl_delay, 1);
843 printf("\nConfiguration:\t\t\t\t[ ");
844 if (cfg->an_home_product & AN_HOME_NETWORK)
845 printf("Home Configuration");
846 else
847 printf("Enterprise Configuration");
848 printf(" ]");
850 printf("\n");
851 printf("\n");
852 an_readkeyinfo(iface);
854 return;
857 static void
858 an_dumprssimap(const char *iface)
860 struct an_ltv_rssi_map *rssi;
861 struct an_req areq;
862 int i;
864 areq.an_len = sizeof(areq);
865 areq.an_type = AN_RID_RSSI_MAP;
867 an_getval(iface, &areq);
869 rssi = (struct an_ltv_rssi_map *)&areq;
871 printf("idx\tpct\t dBm\n");
873 for (i = 0; i < 0xFF; i++) {
875 * negate the dBm value: it's the only way the power
876 * level makes sense
878 printf("%3d\t%3d\t%4d\n", i,
879 rssi->an_entries[i].an_rss_pct,
880 - rssi->an_entries[i].an_rss_dbm);
883 return;
886 static void
887 usage(char *p)
889 fprintf(stderr, "usage: %s -i iface -A (show specified APs)\n", p);
890 fprintf(stderr, "\t%s -i iface -N (show specified SSIDss)\n", p);
891 fprintf(stderr, "\t%s -i iface -S (show NIC status)\n", p);
892 fprintf(stderr, "\t%s -i iface -I (show NIC capabilities)\n", p);
893 fprintf(stderr, "\t%s -i iface -T (show stats counters)\n", p);
894 fprintf(stderr, "\t%s -i iface -C (show current config)\n", p);
895 fprintf(stderr, "\t%s -i iface -R (show RSSI map)\n", p);
896 fprintf(stderr, "\t%s -i iface -t 0-4 (set TX speed)\n", p);
897 fprintf(stderr, "\t%s -i iface -s 0-3 (set power save mode)\n", p);
898 fprintf(stderr, "\t%s -i iface [-v 1-4] -a AP (specify AP)\n", p);
899 fprintf(stderr, "\t%s -i iface -b val (set beacon period)\n", p);
900 fprintf(stderr, "\t%s -i iface [-v 0|1] -d val (set diversity)\n", p);
901 fprintf(stderr, "\t%s -i iface -j val (set netjoin timeout)\n", p);
902 fprintf(stderr, "\t%s -i iface -e 0-4 (enable transmit key)\n", p);
903 fprintf(stderr, "\t%s -i iface [-v 0-8] -k key (set key)\n", p);
904 fprintf(stderr, "\t%s -i iface -K 0-2 (no auth/open/shared secret)\n", p);
905 fprintf(stderr, "\t%s -i iface -W 0-2 (no WEP/full WEP/mixed cell)\n", p);
906 fprintf(stderr, "\t%s -i iface -l val (set station name)\n", p);
907 fprintf(stderr, "\t%s -i iface -m val (set MAC address)\n", p);
908 fprintf(stderr, "\t%s -i iface [-v 1-3] -n SSID "
909 "(specify SSID)\n", p);
910 fprintf(stderr, "\t%s -i iface -o 0|1 (set operating mode)\n", p);
911 fprintf(stderr, "\t%s -i iface -c val (set ad-hoc channel)\n", p);
912 fprintf(stderr, "\t%s -i iface -f val (set frag threshold)\n", p);
913 fprintf(stderr, "\t%s -i iface -r val (set RTS threshold)\n", p);
914 fprintf(stderr, "\t%s -i iface -M 0-15 (set monitor mode)\n", p);
915 fprintf(stderr, "\t%s -i iface -L user (enter LEAP authentication mode)\n", p);
916 #ifdef ANCACHE
917 fprintf(stderr, "\t%s -i iface -Q print signal quality cache\n", p);
918 fprintf(stderr, "\t%s -i iface -Z zero out signal cache\n", p);
919 #endif
921 fprintf(stderr, "\t%s -h (display this message)\n", p);
924 exit(1);
927 static void
928 an_setconfig(const char *iface, int act, void *arg)
930 struct an_ltv_genconfig *cfg;
931 struct an_ltv_caps *caps;
932 struct an_req areq;
933 struct an_req areq_caps;
934 u_int16_t diversity = 0;
935 struct ether_addr *addr;
936 int i;
938 areq.an_len = sizeof(areq);
939 areq.an_type = AN_RID_GENCONFIG;
940 an_getval(iface, &areq);
941 cfg = (struct an_ltv_genconfig *)&areq;
943 areq_caps.an_len = sizeof(areq);
944 areq_caps.an_type = AN_RID_CAPABILITIES;
945 an_getval(iface, &areq_caps);
946 caps = (struct an_ltv_caps *)&areq_caps;
948 switch(act) {
949 case ACT_SET_OPMODE:
950 cfg->an_opmode = atoi(arg);
951 break;
952 case ACT_SET_FREQ:
953 cfg->an_ds_channel = atoi(arg);
954 break;
955 case ACT_SET_PWRSAVE:
956 cfg->an_psave_mode = atoi(arg);
957 break;
958 case ACT_SET_SCANMODE:
959 cfg->an_scanmode = atoi(arg);
960 break;
961 case ACT_SET_DIVERSITY_RX:
962 case ACT_SET_DIVERSITY_TX:
963 switch(atoi(arg)) {
964 case 0:
965 diversity = AN_DIVERSITY_FACTORY_DEFAULT;
966 break;
967 case 1:
968 diversity = AN_DIVERSITY_ANTENNA_1_ONLY;
969 break;
970 case 2:
971 diversity = AN_DIVERSITY_ANTENNA_2_ONLY;
972 break;
973 case 3:
974 diversity = AN_DIVERSITY_ANTENNA_1_AND_2;
975 break;
976 default:
977 errx(1, "bad diversity setting: %d", diversity);
978 break;
980 if (act == ACT_SET_DIVERSITY_RX) {
981 cfg->an_diversity &= 0xFF00;
982 cfg->an_diversity |= diversity;
983 } else {
984 cfg->an_diversity &= 0x00FF;
985 cfg->an_diversity |= (diversity << 8);
987 break;
988 case ACT_SET_TXPWR:
989 for (i = 0; i < 8; i++) {
990 if (caps->an_tx_powerlevels[i] == atoi(arg))
991 break;
993 if (i == 8)
994 errx(1, "unsupported power level: %dmW", atoi(arg));
996 cfg->an_tx_power = atoi(arg);
997 break;
998 case ACT_SET_RTS_THRESH:
999 cfg->an_rtsthresh = atoi(arg);
1000 break;
1001 case ACT_SET_RTS_RETRYLIM:
1002 cfg->an_shortretry_limit =
1003 cfg->an_longretry_limit = atoi(arg);
1004 break;
1005 case ACT_SET_BEACON_PERIOD:
1006 cfg->an_beacon_period = atoi(arg);
1007 break;
1008 case ACT_SET_WAKE_DURATION:
1009 cfg->an_atim_duration = atoi(arg);
1010 break;
1011 case ACT_SET_FRAG_THRESH:
1012 cfg->an_fragthresh = atoi(arg);
1013 break;
1014 case ACT_SET_NETJOIN:
1015 cfg->an_ibss_join_net_timeout = atoi(arg);
1016 break;
1017 case ACT_SET_MYNAME:
1018 bzero(cfg->an_nodename, 16);
1019 strncpy((char *)&cfg->an_nodename, optarg, 16);
1020 break;
1021 case ACT_SET_MAC:
1022 addr = ether_aton((char *)arg);
1024 if (addr == NULL)
1025 errx(1, "badly formatted address");
1026 bzero(cfg->an_macaddr, ETHER_ADDR_LEN);
1027 bcopy((char *)addr, (char *)&cfg->an_macaddr, ETHER_ADDR_LEN);
1028 break;
1029 case ACT_ENABLE_WEP:
1030 switch (atoi (arg)) {
1031 case 0:
1032 /* no WEP */
1033 cfg->an_authtype &= ~(AN_AUTHTYPE_PRIVACY_IN_USE
1034 | AN_AUTHTYPE_ALLOW_UNENCRYPTED
1035 | AN_AUTHTYPE_LEAP);
1036 break;
1037 case 1:
1038 /* full WEP */
1039 cfg->an_authtype |= AN_AUTHTYPE_PRIVACY_IN_USE;
1040 cfg->an_authtype &= ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
1041 cfg->an_authtype &= ~AN_AUTHTYPE_LEAP;
1042 break;
1043 case 2:
1044 /* mixed cell */
1045 cfg->an_authtype = AN_AUTHTYPE_PRIVACY_IN_USE
1046 | AN_AUTHTYPE_ALLOW_UNENCRYPTED;
1047 break;
1049 break;
1050 case ACT_SET_KEY_TYPE:
1051 cfg->an_authtype = (cfg->an_authtype & ~AN_AUTHTYPE_MASK)
1052 | atoi(arg);
1053 break;
1054 case ACT_SET_MONITOR_MODE:
1055 areq.an_type = AN_RID_MONITOR_MODE;
1056 cfg->an_len = atoi(arg); /* mode is put in length */
1057 break;
1058 default:
1059 errx(1, "unknown action");
1060 break;
1063 an_setval(iface, &areq);
1064 exit(0);
1067 static void
1068 an_setspeed(const char *iface, int act __unused, void *arg)
1070 struct an_req areq;
1071 struct an_ltv_caps *caps;
1072 u_int16_t speed;
1074 areq.an_len = sizeof(areq);
1075 areq.an_type = AN_RID_CAPABILITIES;
1077 an_getval(iface, &areq);
1078 caps = (struct an_ltv_caps *)&areq;
1080 switch(atoi(arg)) {
1081 case 0:
1082 speed = 0;
1083 break;
1084 case 1:
1085 speed = AN_RATE_1MBPS;
1086 break;
1087 case 2:
1088 speed = AN_RATE_2MBPS;
1089 break;
1090 case 3:
1091 if (caps->an_rates[2] != AN_RATE_5_5MBPS)
1092 errx(1, "5.5Mbps not supported on this card");
1093 speed = AN_RATE_5_5MBPS;
1094 break;
1095 case 4:
1096 if (caps->an_rates[3] != AN_RATE_11MBPS)
1097 errx(1, "11Mbps not supported on this card");
1098 speed = AN_RATE_11MBPS;
1099 break;
1100 default:
1101 errx(1, "unsupported speed");
1102 break;
1105 areq.an_len = 6;
1106 areq.an_type = AN_RID_TX_SPEED;
1107 areq.an_val[0] = speed;
1109 an_setval(iface, &areq);
1110 exit(0);
1113 static void
1114 an_setap(const char *iface, int act, void *arg)
1116 struct an_ltv_aplist *ap;
1117 struct an_req areq;
1118 struct ether_addr *addr;
1120 areq.an_len = sizeof(areq);
1121 areq.an_type = AN_RID_APLIST;
1123 an_getval(iface, &areq);
1124 ap = (struct an_ltv_aplist *)&areq;
1126 addr = ether_aton((char *)arg);
1128 if (addr == NULL)
1129 errx(1, "badly formatted address");
1131 switch(act) {
1132 case ACT_SET_AP1:
1133 bzero(ap->an_ap1, ETHER_ADDR_LEN);
1134 bcopy((char *)addr, (char *)&ap->an_ap1, ETHER_ADDR_LEN);
1135 break;
1136 case ACT_SET_AP2:
1137 bzero(ap->an_ap2, ETHER_ADDR_LEN);
1138 bcopy((char *)addr, (char *)&ap->an_ap2, ETHER_ADDR_LEN);
1139 break;
1140 case ACT_SET_AP3:
1141 bzero(ap->an_ap3, ETHER_ADDR_LEN);
1142 bcopy((char *)addr, (char *)&ap->an_ap3, ETHER_ADDR_LEN);
1143 break;
1144 case ACT_SET_AP4:
1145 bzero(ap->an_ap4, ETHER_ADDR_LEN);
1146 bcopy((char *)addr, (char *)&ap->an_ap4, ETHER_ADDR_LEN);
1147 break;
1148 default:
1149 errx(1, "unknown action");
1150 break;
1153 an_setval(iface, &areq);
1154 exit(0);
1157 static void
1158 an_setssid(const char *iface, int act, void *arg)
1160 struct an_ltv_ssidlist *ssid;
1161 struct an_req areq;
1163 areq.an_len = sizeof(areq);
1164 areq.an_type = AN_RID_SSIDLIST;
1166 an_getval(iface, &areq);
1167 ssid = (struct an_ltv_ssidlist *)&areq;
1169 switch (act) {
1170 case ACT_SET_SSID1:
1171 bzero(ssid->an_ssid1, sizeof(ssid->an_ssid1));
1172 strlcpy(ssid->an_ssid1, (char *)arg, sizeof(ssid->an_ssid1));
1173 ssid->an_ssid1_len = strlen(ssid->an_ssid1);
1174 break;
1175 case ACT_SET_SSID2:
1176 bzero(ssid->an_ssid2, sizeof(ssid->an_ssid2));
1177 strlcpy(ssid->an_ssid2, (char *)arg, sizeof(ssid->an_ssid2));
1178 ssid->an_ssid2_len = strlen(ssid->an_ssid2);
1179 break;
1180 case ACT_SET_SSID3:
1181 bzero(ssid->an_ssid3, sizeof(ssid->an_ssid3));
1182 strlcpy(ssid->an_ssid3, (char *)arg, sizeof(ssid->an_ssid3));
1183 ssid->an_ssid3_len = strlen(ssid->an_ssid3);
1184 break;
1185 default:
1186 errx(1, "unknown action");
1187 break;
1190 an_setval(iface, &areq);
1191 exit(0);
1194 #ifdef ANCACHE
1195 static void
1196 an_zerocache(const char *iface)
1198 struct an_req areq;
1200 bzero((char *)&areq, sizeof(areq));
1201 areq.an_len = 0;
1202 areq.an_type = AN_RID_ZERO_CACHE;
1204 an_getval(iface, &areq);
1206 return;
1209 static void
1210 an_readcache(const char *iface)
1212 struct an_req areq;
1213 int *an_sigitems;
1214 struct an_sigcache *sc;
1215 char * pt;
1216 int i;
1218 if (iface == NULL)
1219 errx(1, "must specify interface name");
1221 bzero((char *)&areq, sizeof(areq));
1222 areq.an_len = AN_MAX_DATALEN;
1223 areq.an_type = AN_RID_READ_CACHE;
1225 an_getval(iface, &areq);
1227 an_sigitems = (int *) &areq.an_val;
1228 pt = ((char *) &areq.an_val);
1229 pt += sizeof(int);
1230 sc = (struct an_sigcache *) pt;
1232 for (i = 0; i < *an_sigitems; i++) {
1233 printf("[%d/%d]:", i+1, *an_sigitems);
1234 printf(" %02x:%02x:%02x:%02x:%02x:%02x,",
1235 sc->macsrc[0]&0xff,
1236 sc->macsrc[1]&0xff,
1237 sc->macsrc[2]&0xff,
1238 sc->macsrc[3]&0xff,
1239 sc->macsrc[4]&0xff,
1240 sc->macsrc[5]&0xff);
1241 printf(" %d.%d.%d.%d,",((sc->ipsrc >> 0) & 0xff),
1242 ((sc->ipsrc >> 8) & 0xff),
1243 ((sc->ipsrc >> 16) & 0xff),
1244 ((sc->ipsrc >> 24) & 0xff));
1245 printf(" sig: %d, noise: %d, qual: %d\n",
1246 sc->signal,
1247 sc->noise,
1248 sc->quality);
1249 sc++;
1252 return;
1254 #endif
1256 static int
1257 an_hex2int(char c)
1259 if (c >= '0' && c <= '9')
1260 return (c - '0');
1261 if (c >= 'A' && c <= 'F')
1262 return (c - 'A' + 10);
1263 if (c >= 'a' && c <= 'f')
1264 return (c - 'a' + 10);
1266 return (0);
1269 static void
1270 an_str2key(char *s, struct an_ltv_key *k)
1272 int n, i;
1273 char *p;
1275 /* Is this a hex string? */
1276 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) {
1277 /* Yes, convert to int. */
1278 n = 0;
1279 p = (char *)&k->key[0];
1280 for (i = 2; s[i] != '\0' && s[i + 1] != '\0'; i+= 2) {
1281 *p++ = (an_hex2int(s[i]) << 4) + an_hex2int(s[i + 1]);
1282 n++;
1284 if (s[i] != '\0')
1285 errx(1, "hex strings must be of even length");
1286 k->klen = n;
1287 } else {
1288 /* No, just copy it in. */
1289 bcopy(s, k->key, strlen(s));
1290 k->klen = strlen(s);
1293 return;
1296 static void
1297 an_setkeys(const char *iface, char *key, int keytype)
1299 struct an_req areq;
1300 struct an_ltv_key *k;
1302 bzero((char *)&areq, sizeof(areq));
1303 k = (struct an_ltv_key *)&areq;
1305 if (strlen(key) > 28) {
1306 err(1, "encryption key must be no "
1307 "more than 18 characters long");
1310 an_str2key(key, k);
1312 k->kindex=keytype/2;
1314 if (!(k->klen==0 || k->klen==5 || k->klen==13)) {
1315 err(1, "encryption key must be 0, 5 or 13 bytes long");
1318 /* default mac and only valid one (from manual) 1.0.0.0.0.0 */
1319 k->mac[0]=1;
1320 k->mac[1]=0;
1321 k->mac[2]=0;
1322 k->mac[3]=0;
1323 k->mac[4]=0;
1324 k->mac[5]=0;
1326 switch(keytype & 1) {
1327 case 0:
1328 areq.an_len = sizeof(struct an_ltv_key);
1329 areq.an_type = AN_RID_WEP_PERM;
1330 an_setval(iface, &areq);
1331 break;
1332 case 1:
1333 areq.an_len = sizeof(struct an_ltv_key);
1334 areq.an_type = AN_RID_WEP_TEMP;
1335 an_setval(iface, &areq);
1336 break;
1339 return;
1342 static void
1343 an_readkeyinfo(const char *iface)
1345 struct an_req areq;
1346 struct an_ltv_genconfig *cfg;
1347 struct an_ltv_key *k;
1348 int i;
1349 int home;
1351 areq.an_len = sizeof(areq);
1352 areq.an_type = AN_RID_ACTUALCFG;
1353 an_getval(iface, &areq);
1354 cfg = (struct an_ltv_genconfig *)&areq;
1355 if (cfg->an_home_product & AN_HOME_NETWORK)
1356 home = 1;
1357 else
1358 home = 0;
1360 bzero((char *)&areq, sizeof(areq));
1361 k = (struct an_ltv_key *)&areq;
1363 printf("WEP Key status:\n");
1364 areq.an_type = AN_RID_WEP_TEMP; /* read first key */
1365 for(i=0; i<5; i++) {
1366 areq.an_len = sizeof(struct an_ltv_key);
1367 an_getval(iface, &areq);
1368 if (k->kindex == 0xffff)
1369 break;
1370 switch (k->klen) {
1371 case 0:
1372 printf("\tKey %d is unset\n",k->kindex);
1373 break;
1374 case 5:
1375 printf("\tKey %d is set 40 bits\n",k->kindex);
1376 break;
1377 case 13:
1378 printf("\tKey %d is set 128 bits\n",k->kindex);
1379 break;
1380 default:
1381 printf("\tWEP Key %d has an unknown size %d\n",
1382 i, k->klen);
1385 areq.an_type = AN_RID_WEP_PERM; /* read next key */
1387 k->kindex = 0xffff;
1388 areq.an_len = sizeof(struct an_ltv_key);
1389 an_getval(iface, &areq);
1390 printf("\tThe active transmit key is %d\n", 4 * home + k->mac[0]);
1392 return;
1395 static void
1396 an_enable_tx_key(const char *iface, char *arg)
1398 struct an_req areq;
1399 struct an_ltv_key *k;
1400 struct an_ltv_genconfig *config;
1402 bzero((char *)&areq, sizeof(areq));
1404 /* set home or not home mode */
1405 areq.an_len = sizeof(struct an_ltv_genconfig);
1406 areq.an_type = AN_RID_GENCONFIG;
1407 an_getval(iface, &areq);
1408 config = (struct an_ltv_genconfig *)&areq;
1409 if (atoi(arg) == 4) {
1410 config->an_home_product |= AN_HOME_NETWORK;
1411 }else{
1412 config->an_home_product &= ~AN_HOME_NETWORK;
1414 an_setval(iface, &areq);
1416 bzero((char *)&areq, sizeof(areq));
1418 k = (struct an_ltv_key *)&areq;
1420 /* From a Cisco engineer write the transmit key to use in the
1421 first MAC, index is FFFF*/
1422 k->kindex=0xffff;
1423 k->klen=0;
1425 k->mac[0]=atoi(arg);
1426 k->mac[1]=0;
1427 k->mac[2]=0;
1428 k->mac[3]=0;
1429 k->mac[4]=0;
1430 k->mac[5]=0;
1432 areq.an_len = sizeof(struct an_ltv_key);
1433 areq.an_type = AN_RID_WEP_PERM;
1434 an_setval(iface, &areq);
1436 return;
1439 static void
1440 an_enable_leap_mode(const char *iface, char *username)
1442 struct an_req areq;
1443 struct an_ltv_status *sts;
1444 struct an_ltv_genconfig *cfg;
1445 struct an_ltv_caps *caps;
1446 struct an_ltv_leap_username an_username;
1447 struct an_ltv_leap_password an_password;
1448 char *password;
1449 MD4_CTX context;
1450 int len;
1451 int i;
1452 char unicode_password[LEAP_PASSWORD_MAX * 2];
1454 areq.an_len = sizeof(areq);
1455 areq.an_type = AN_RID_CAPABILITIES;
1457 an_getval(iface, &areq);
1459 caps = (struct an_ltv_caps *)&areq;
1461 if (!(caps->an_softcaps & AN_AUTHTYPE_LEAP)) {
1462 fprintf(stderr, "Firmware does not support LEAP\n");
1463 exit(1);
1466 bzero(&an_username, sizeof(an_username));
1467 bzero(&an_password, sizeof(an_password));
1469 len = strlen(username);
1470 if (len > LEAP_USERNAME_MAX) {
1471 printf("Username too long (max %d)\n", LEAP_USERNAME_MAX);
1472 exit(1);
1474 strncpy(an_username.an_username, username, len);
1475 an_username.an_username_len = len;
1476 an_username.an_len = sizeof(an_username);
1477 an_username.an_type = AN_RID_LEAPUSERNAME;
1479 password = getpass("Enter LEAP password:");
1481 len = strlen(password);
1482 if (len > LEAP_PASSWORD_MAX) {
1483 printf("Password too long (max %d)\n", LEAP_PASSWORD_MAX);
1484 exit(1);
1487 bzero(&unicode_password, sizeof(unicode_password));
1488 for(i = 0; i < len; i++) {
1489 unicode_password[i * 2] = *password++;
1492 /* First half */
1493 MD4Init(&context);
1494 MD4Update(&context, unicode_password, len * 2);
1495 MD4Final(&an_password.an_password[0], &context);
1497 /* Second half */
1498 MD4Init (&context);
1499 MD4Update (&context, &an_password.an_password[0], 16);
1500 MD4Final (&an_password.an_password[16], &context);
1502 an_password.an_password_len = 32;
1503 an_password.an_len = sizeof(an_password);
1504 an_password.an_type = AN_RID_LEAPPASSWORD;
1506 an_setval(iface, (struct an_req *)&an_username);
1507 an_setval(iface, (struct an_req *)&an_password);
1509 areq.an_len = sizeof(areq);
1510 areq.an_type = AN_RID_GENCONFIG;
1511 an_getval(iface, &areq);
1512 cfg = (struct an_ltv_genconfig *)&areq;
1513 cfg->an_authtype = (AN_AUTHTYPE_PRIVACY_IN_USE | AN_AUTHTYPE_LEAP);
1514 an_setval(iface, &areq);
1516 sts = (struct an_ltv_status *)&areq;
1517 areq.an_type = AN_RID_STATUS;
1519 for (i = 60; i > 0; i--) {
1520 an_getval(iface, &areq);
1521 if (sts->an_opmode & AN_STATUS_OPMODE_LEAP) {
1522 printf("Authenticated\n");
1523 break;
1525 sleep(1);
1528 if (i == 0) {
1529 fprintf(stderr, "Failed LEAP authentication\n");
1530 exit(1);
1535 main(int argc, char **argv)
1537 int ch;
1538 int act = 0;
1539 const char *iface = NULL;
1540 int modifier = 0;
1541 char *key = NULL;
1542 void *arg = NULL;
1543 char *p = argv[0];
1545 /* Get the interface name */
1546 opterr = 0;
1547 ch = getopt(argc, argv, "i:");
1548 if (ch == 'i') {
1549 iface = optarg;
1550 } else {
1551 if (argc > 1 && *argv[1] != '-') {
1552 iface = argv[1];
1553 optind = 2;
1554 } else {
1555 iface = "an0";
1556 optind = 1;
1558 optreset = 1;
1560 opterr = 1;
1562 while ((ch = getopt(argc, argv,
1563 "ANISCTRht:a:e:o:s:n:v:d:j:b:c:r:p:w:m:l:k:K:W:QZM:L:")) != -1) {
1564 switch(ch) {
1565 case 'Z':
1566 #ifdef ANCACHE
1567 act = ACT_ZEROCACHE;
1568 #else
1569 errx(1, "ANCACHE not available");
1570 #endif
1571 break;
1572 case 'Q':
1573 #ifdef ANCACHE
1574 act = ACT_DUMPCACHE;
1575 #else
1576 errx(1, "ANCACHE not available");
1577 #endif
1578 break;
1579 case 'A':
1580 act = ACT_DUMPAP;
1581 break;
1582 case 'N':
1583 act = ACT_DUMPSSID;
1584 break;
1585 case 'S':
1586 act = ACT_DUMPSTATUS;
1587 break;
1588 case 'I':
1589 act = ACT_DUMPCAPS;
1590 break;
1591 case 'T':
1592 act = ACT_DUMPSTATS;
1593 break;
1594 case 'C':
1595 act = ACT_DUMPCONFIG;
1596 break;
1597 case 'R':
1598 act = ACT_DUMPRSSIMAP;
1599 break;
1600 case 't':
1601 act = ACT_SET_TXRATE;
1602 arg = optarg;
1603 break;
1604 case 's':
1605 act = ACT_SET_PWRSAVE;
1606 arg = optarg;
1607 break;
1608 case 'p':
1609 act = ACT_SET_TXPWR;
1610 arg = optarg;
1611 break;
1612 case 'v':
1613 modifier = atoi(optarg);
1614 break;
1615 case 'a':
1616 switch(modifier) {
1617 case 0:
1618 case 1:
1619 act = ACT_SET_AP1;
1620 break;
1621 case 2:
1622 act = ACT_SET_AP2;
1623 break;
1624 case 3:
1625 act = ACT_SET_AP3;
1626 break;
1627 case 4:
1628 act = ACT_SET_AP4;
1629 break;
1630 default:
1631 errx(1, "bad modifier %d: there "
1632 "are only 4 access point settings",
1633 modifier);
1634 usage(p);
1635 break;
1637 arg = optarg;
1638 break;
1639 case 'b':
1640 act = ACT_SET_BEACON_PERIOD;
1641 arg = optarg;
1642 break;
1643 case 'd':
1644 switch(modifier) {
1645 case 0:
1646 act = ACT_SET_DIVERSITY_RX;
1647 break;
1648 case 1:
1649 act = ACT_SET_DIVERSITY_TX;
1650 break;
1651 default:
1652 errx(1, "must specify RX or TX diversity");
1653 break;
1655 if (!isdigit(*optarg)) {
1656 errx(1, "%s is not numeric", optarg);
1657 exit(1);
1659 arg = optarg;
1660 break;
1661 case 'j':
1662 act = ACT_SET_NETJOIN;
1663 arg = optarg;
1664 break;
1665 case 'l':
1666 act = ACT_SET_MYNAME;
1667 arg = optarg;
1668 break;
1669 case 'm':
1670 act = ACT_SET_MAC;
1671 arg = optarg;
1672 break;
1673 case 'n':
1674 switch(modifier) {
1675 case 0:
1676 case 1:
1677 act = ACT_SET_SSID1;
1678 break;
1679 case 2:
1680 act = ACT_SET_SSID2;
1681 break;
1682 case 3:
1683 act = ACT_SET_SSID3;
1684 break;
1685 default:
1686 errx(1, "bad modifier %d: there"
1687 "are only 3 SSID settings", modifier);
1688 usage(p);
1689 break;
1691 arg = optarg;
1692 break;
1693 case 'o':
1694 act = ACT_SET_OPMODE;
1695 arg = optarg;
1696 break;
1697 case 'c':
1698 act = ACT_SET_FREQ;
1699 arg = optarg;
1700 break;
1701 case 'f':
1702 act = ACT_SET_FRAG_THRESH;
1703 arg = optarg;
1704 break;
1705 case 'W':
1706 act = ACT_ENABLE_WEP;
1707 arg = optarg;
1708 break;
1709 case 'K':
1710 act = ACT_SET_KEY_TYPE;
1711 arg = optarg;
1712 break;
1713 case 'k':
1714 act = ACT_SET_KEYS;
1715 key = optarg;
1716 break;
1717 case 'e':
1718 act = ACT_ENABLE_TX_KEY;
1719 arg = optarg;
1720 break;
1721 case 'q':
1722 act = ACT_SET_RTS_RETRYLIM;
1723 arg = optarg;
1724 break;
1725 case 'r':
1726 act = ACT_SET_RTS_THRESH;
1727 arg = optarg;
1728 break;
1729 case 'w':
1730 act = ACT_SET_WAKE_DURATION;
1731 arg = optarg;
1732 break;
1733 case 'M':
1734 act = ACT_SET_MONITOR_MODE;
1735 arg = optarg;
1736 break;
1737 case 'L':
1738 act = ACT_SET_LEAP_MODE;
1739 arg = optarg;
1740 break;
1741 case 'h':
1742 default:
1743 usage(p);
1747 if (iface == NULL || (!act && !key))
1748 usage(p);
1750 switch(act) {
1751 case ACT_DUMPSTATUS:
1752 an_dumpstatus(iface);
1753 break;
1754 case ACT_DUMPCAPS:
1755 an_dumpcaps(iface);
1756 break;
1757 case ACT_DUMPSTATS:
1758 an_dumpstats(iface);
1759 break;
1760 case ACT_DUMPCONFIG:
1761 an_dumpconfig(iface);
1762 break;
1763 case ACT_DUMPSSID:
1764 an_dumpssid(iface);
1765 break;
1766 case ACT_DUMPAP:
1767 an_dumpap(iface);
1768 break;
1769 case ACT_DUMPRSSIMAP:
1770 an_dumprssimap(iface);
1771 break;
1772 case ACT_SET_SSID1:
1773 case ACT_SET_SSID2:
1774 case ACT_SET_SSID3:
1775 an_setssid(iface, act, arg);
1776 break;
1777 case ACT_SET_AP1:
1778 case ACT_SET_AP2:
1779 case ACT_SET_AP3:
1780 case ACT_SET_AP4:
1781 an_setap(iface, act, arg);
1782 break;
1783 case ACT_SET_TXRATE:
1784 an_setspeed(iface, act, arg);
1785 break;
1786 #ifdef ANCACHE
1787 case ACT_ZEROCACHE:
1788 an_zerocache(iface);
1789 break;
1790 case ACT_DUMPCACHE:
1791 an_readcache(iface);
1792 break;
1794 #endif
1795 case ACT_SET_KEYS:
1796 an_setkeys(iface, key, modifier);
1797 break;
1798 case ACT_ENABLE_TX_KEY:
1799 an_enable_tx_key(iface, arg);
1800 break;
1801 case ACT_SET_LEAP_MODE:
1802 an_enable_leap_mode(iface, arg);
1803 break;
1804 default:
1805 an_setconfig(iface, act, arg);
1806 break;
1809 exit(0);