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
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 * $FreeBSD: src/usr.sbin/ancontrol/ancontrol.c,v 1.1.2.9 2003/02/01 03:25:13 ambrisko Exp $
33 * $DragonFly: src/usr.sbin/ancontrol/ancontrol.c,v 1.3 2003/08/08 04:18:44 dillon Exp $
35 * @(#) Copyright (c) 1997, 1998, 1999 Bill Paul. All rights reserved.
36 * @(#) $FreeBSD: src/usr.sbin/ancontrol/ancontrol.c,v 1.1.2.9 2003/02/01 03:25:13 ambrisko Exp
37 * $FreeBSD: src/usr.sbin/ancontrol/ancontrol.c,v 1.1.2.9 2003/02/01 03:25:13 ambrisko Exp $
40 #include <sys/types.h>
41 #include <sys/cdefs.h>
42 #include <sys/param.h>
43 #include <sys/socket.h>
44 #include <sys/ioctl.h>
45 #include <sys/socket.h>
48 #include <net/if_var.h>
49 #include <net/ethernet.h>
51 #include <dev/netif/an/if_aironet_ieee.h>
62 static int an_getval __P((const char *, struct an_req *));
63 static void an_setval __P((const char *, struct an_req *));
64 static void an_printwords __P((u_int16_t *, int));
65 static void an_printspeeds __P((u_int8_t*, int));
66 static void an_printbool __P((int));
67 static void an_printhex __P((char *, int));
68 static void an_printstr __P((char *, int));
69 static void an_dumpstatus __P((const char *));
70 static void an_dumpstats __P((const char *));
71 static void an_dumpconfig __P((const char *));
72 static void an_dumpcaps __P((const char *));
73 static void an_dumpssid __P((const char *));
74 static void an_dumpap __P((const char *));
75 static void an_setconfig __P((const char *, int, void *));
76 static void an_setssid __P((const char *, int, void *));
77 static void an_setap __P((const char *, int, void *));
78 static void an_setspeed __P((const char *, int, void *));
79 static void an_readkeyinfo __P((const char *));
81 static void an_zerocache __P((const char *));
82 static void an_readcache __P((const char *));
84 static int an_hex2int __P((char));
85 static void an_str2key __P((char *, struct an_ltv_key *));
86 static void an_setkeys __P((const char *, char *, int));
87 static void an_enable_tx_key __P((const char *, char *));
88 static void an_enable_leap_mode __P((const char *, char *));
89 static void usage __P((char *));
90 static void __P(an_dumprssimap(const char *));
91 int main __P((int, char **));
93 #define ACT_DUMPSTATS 1
94 #define ACT_DUMPCONFIG 2
95 #define ACT_DUMPSTATUS 3
96 #define ACT_DUMPCAPS 4
97 #define ACT_DUMPSSID 5
100 #define ACT_SET_OPMODE 7
101 #define ACT_SET_SSID1 8
102 #define ACT_SET_SSID2 9
103 #define ACT_SET_SSID3 10
104 #define ACT_SET_FREQ 11
105 #define ACT_SET_AP1 12
106 #define ACT_SET_AP2 13
107 #define ACT_SET_AP3 14
108 #define ACT_SET_AP4 15
109 #define ACT_SET_DRIVERNAME 16
110 #define ACT_SET_SCANMODE 17
111 #define ACT_SET_TXRATE 18
112 #define ACT_SET_RTS_THRESH 19
113 #define ACT_SET_PWRSAVE 20
114 #define ACT_SET_DIVERSITY_RX 21
115 #define ACT_SET_DIVERSITY_TX 22
116 #define ACT_SET_RTS_RETRYLIM 23
117 #define ACT_SET_WAKE_DURATION 24
118 #define ACT_SET_BEACON_PERIOD 25
119 #define ACT_SET_TXPWR 26
120 #define ACT_SET_FRAG_THRESH 27
121 #define ACT_SET_NETJOIN 28
122 #define ACT_SET_MYNAME 29
123 #define ACT_SET_MAC 30
125 #define ACT_DUMPCACHE 31
126 #define ACT_ZEROCACHE 32
128 #define ACT_ENABLE_WEP 33
129 #define ACT_SET_KEY_TYPE 34
130 #define ACT_SET_KEYS 35
131 #define ACT_ENABLE_TX_KEY 36
132 #define ACT_SET_MONITOR_MODE 37
133 #define ACT_SET_LEAP_MODE 38
135 #define ACT_DUMPRSSIMAP 39
137 static int an_getval(iface, areq)
144 bzero((char *)&ifr, sizeof(ifr));
146 strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
147 ifr.ifr_data = (caddr_t)areq;
149 s = socket(AF_INET, SOCK_DGRAM, 0);
154 if (ioctl(s, SIOCGAIRONET, &ifr) == -1) {
156 err(1, "SIOCGAIRONET");
164 static void an_setval(iface, areq)
171 bzero((char *)&ifr, sizeof(ifr));
173 strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
174 ifr.ifr_data = (caddr_t)areq;
176 s = socket(AF_INET, SOCK_DGRAM, 0);
181 if (ioctl(s, SIOCSAIRONET, &ifr) == -1)
182 err(1, "SIOCSAIRONET");
189 static void an_printstr(str, len)
195 for (i = 0; i < len - 1; i++) {
200 printf("[ %.*s ]", len, str);
205 static void an_printwords(w, len)
212 for (i = 0; i < len; i++)
219 static void an_printspeeds(w, len)
226 for (i = 0; i < len && w[i]; i++)
227 printf("%2.1fMbps ", w[i] * 0.500);
233 static void an_printbool(val)
244 static void an_printhex(ptr, len)
251 for (i = 0; i < len; i++) {
252 printf("%02x", ptr[i] & 0xFF);
263 static void an_dumpstatus(iface)
266 struct an_ltv_status *sts;
268 struct an_ltv_rssi_map an_rssimap;
269 int rssimap_valid = 0;
272 * Try to get RSSI to percent and dBM table
275 an_rssimap.an_len = sizeof(an_rssimap);
276 an_rssimap.an_type = AN_RID_RSSI_MAP;
277 rssimap_valid = an_getval(iface, (struct an_req*)&an_rssimap);
280 printf("RSSI table:\t\t[ present ]\n");
282 printf("RSSI table:\t\t[ not available ]\n");
284 areq.an_len = sizeof(areq);
285 areq.an_type = AN_RID_STATUS;
287 an_getval(iface, &areq);
289 sts = (struct an_ltv_status *)&areq;
291 printf("MAC address:\t\t");
292 an_printhex((char *)&sts->an_macaddr, ETHER_ADDR_LEN);
293 printf("\nOperating mode:\t\t[ ");
294 if (sts->an_opmode & AN_STATUS_OPMODE_CONFIGURED)
295 printf("configured ");
296 if (sts->an_opmode & AN_STATUS_OPMODE_MAC_ENABLED)
298 if (sts->an_opmode & AN_STATUS_OPMODE_RX_ENABLED)
300 if (sts->an_opmode & AN_STATUS_OPMODE_IN_SYNC)
302 if (sts->an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
303 printf("associated ");
304 if (sts->an_opmode & AN_STATUS_OPMODE_LEAP)
306 if (sts->an_opmode & AN_STATUS_OPMODE_ERROR)
309 printf("Error code:\t\t");
310 an_printhex((char *)&sts->an_errcode, 1);
312 printf("\nSignal strength:\t[ %d%% ]",
313 an_rssimap.an_entries[
314 sts->an_normalized_strength].an_rss_pct);
316 printf("\nSignal strength:\t[ %d%% ]",
317 sts->an_normalized_strength);
318 printf("\nAverage Noise:\t\t[ %d%% ]",sts->an_avg_noise_prev_min_pc);
320 printf("\nSignal quality:\t\t[ %d%% ]",
321 an_rssimap.an_entries[
322 sts->an_cur_signal_quality].an_rss_pct);
324 printf("\nSignal quality:\t\t[ %d ]",
325 sts->an_cur_signal_quality);
326 printf("\nMax Noise:\t\t[ %d%% ]",sts->an_max_noise_prev_min_pc);
328 * XXX: This uses the old definition of the rate field (units of
329 * 500kbps). Technically the new definition is that this field
330 * contains arbitrary values, but no devices which need this
331 * support exist and the IEEE seems to intend to use the old
332 * definition until they get something big so we'll keep using
333 * it as well because this will work with new cards with
336 printf("\nCurrent TX rate:\t[ %d%s ]", sts->an_current_tx_rate / 2,
337 (sts->an_current_tx_rate % 2) ? ".5" : "");
338 printf("\nCurrent SSID:\t\t");
339 an_printstr((char *)&sts->an_ssid, sts->an_ssidlen);
340 printf("\nCurrent AP name:\t");
341 an_printstr((char *)&sts->an_ap_name, 16);
342 printf("\nCurrent BSSID:\t\t");
343 an_printhex((char *)&sts->an_cur_bssid, ETHER_ADDR_LEN);
344 printf("\nBeacon period:\t\t");
345 an_printwords(&sts->an_beacon_period, 1);
346 printf("\nDTIM period:\t\t");
347 an_printwords(&sts->an_dtim_period, 1);
348 printf("\nATIM duration:\t\t");
349 an_printwords(&sts->an_atim_duration, 1);
350 printf("\nHOP period:\t\t");
351 an_printwords(&sts->an_hop_period, 1);
352 printf("\nChannel set:\t\t");
353 an_printwords(&sts->an_channel_set, 1);
354 printf("\nCurrent channel:\t");
355 an_printwords(&sts->an_cur_channel, 1);
356 printf("\nHops to backbone:\t");
357 an_printwords(&sts->an_hops_to_backbone, 1);
358 printf("\nTotal AP load:\t\t");
359 an_printwords(&sts->an_ap_total_load, 1);
360 printf("\nOur generated load:\t");
361 an_printwords(&sts->an_our_generated_load, 1);
362 printf("\nAccumulated ARL:\t");
363 an_printwords(&sts->an_accumulated_arl, 1);
368 static void an_dumpcaps(iface)
371 struct an_ltv_caps *caps;
375 areq.an_len = sizeof(areq);
376 areq.an_type = AN_RID_CAPABILITIES;
378 an_getval(iface, &areq);
380 caps = (struct an_ltv_caps *)&areq;
382 printf("OUI:\t\t\t");
383 an_printhex((char *)&caps->an_oui, 3);
384 printf("\nProduct number:\t\t");
385 an_printwords(&caps->an_prodnum, 1);
386 printf("\nManufacturer name:\t");
387 an_printstr((char *)&caps->an_manufname, 32);
388 printf("\nProduce name:\t\t");
389 an_printstr((char *)&caps->an_prodname, 16);
390 printf("\nFirmware version:\t");
391 an_printstr((char *)&caps->an_prodvers, 1);
392 printf("\nOEM MAC address:\t");
393 an_printhex((char *)&caps->an_oemaddr, ETHER_ADDR_LEN);
394 printf("\nAironet MAC address:\t");
395 an_printhex((char *)&caps->an_aironetaddr, ETHER_ADDR_LEN);
396 printf("\nRadio type:\t\t[ ");
397 if (caps->an_radiotype & AN_RADIOTYPE_80211_FH)
399 else if (caps->an_radiotype & AN_RADIOTYPE_80211_DS)
401 else if (caps->an_radiotype & AN_RADIOTYPE_LM2000_DS)
404 printf("unknown (%x)", caps->an_radiotype);
406 printf("\nRegulatory domain:\t");
407 an_printwords(&caps->an_regdomain, 1);
408 printf("\nAssigned CallID:\t");
409 an_printhex((char *)&caps->an_callid, 6);
410 printf("\nSupported speeds:\t");
411 an_printspeeds(caps->an_rates, 8);
412 printf("\nRX Diversity:\t\t[ ");
413 if (caps->an_rx_diversity == AN_DIVERSITY_FACTORY_DEFAULT)
414 printf("factory default");
415 else if (caps->an_rx_diversity == AN_DIVERSITY_ANTENNA_1_ONLY)
416 printf("antenna 1 only");
417 else if (caps->an_rx_diversity == AN_DIVERSITY_ANTENNA_2_ONLY)
418 printf("antenna 2 only");
419 else if (caps->an_rx_diversity == AN_DIVERSITY_ANTENNA_1_AND_2)
420 printf("antenna 1 and 2");
422 printf("\nTX Diversity:\t\t[ ");
423 if (caps->an_tx_diversity == AN_DIVERSITY_FACTORY_DEFAULT)
424 printf("factory default");
425 else if (caps->an_tx_diversity == AN_DIVERSITY_ANTENNA_1_ONLY)
426 printf("antenna 1 only");
427 else if (caps->an_tx_diversity == AN_DIVERSITY_ANTENNA_2_ONLY)
428 printf("antenna 2 only");
429 else if (caps->an_tx_diversity == AN_DIVERSITY_ANTENNA_1_AND_2)
430 printf("antenna 1 and 2");
432 printf("\nSupported power levels:\t");
433 an_printwords(caps->an_tx_powerlevels, 8);
434 printf("\nHardware revision:\t");
435 tmp = ntohs(caps->an_hwrev);
436 an_printhex((char *)&tmp, 2);
437 printf("\nSoftware revision:\t");
438 tmp = ntohs(caps->an_fwrev);
439 an_printhex((char *)&tmp, 2);
440 printf("\nSoftware subrevision:\t");
441 tmp = ntohs(caps->an_fwsubrev);
442 an_printhex((char *)&tmp, 2);
443 printf("\nInterface revision:\t");
444 tmp = ntohs(caps->an_ifacerev);
445 an_printhex((char *)&tmp, 2);
446 printf("\nBootblock revision:\t");
447 tmp = ntohs(caps->an_bootblockrev);
448 an_printhex((char *)&tmp, 2);
453 static void an_dumpstats(iface)
456 struct an_ltv_stats *stats;
460 areq.an_len = sizeof(areq);
461 areq.an_type = AN_RID_32BITS_CUM;
463 an_getval(iface, &areq);
465 ptr = (caddr_t)&areq;
467 stats = (struct an_ltv_stats *)ptr;
469 printf("RX overruns:\t\t\t\t\t[ %d ]\n", stats->an_rx_overruns);
470 printf("RX PLCP CSUM errors:\t\t\t\t[ %d ]\n",
471 stats->an_rx_plcp_csum_errs);
472 printf("RX PLCP format errors:\t\t\t\t[ %d ]\n",
473 stats->an_rx_plcp_format_errs);
474 printf("RX PLCP length errors:\t\t\t\t[ %d ]\n",
475 stats->an_rx_plcp_len_errs);
476 printf("RX MAC CRC errors:\t\t\t\t[ %d ]\n",
477 stats->an_rx_mac_crc_errs);
478 printf("RX MAC CRC OK:\t\t\t\t\t[ %d ]\n",
479 stats->an_rx_mac_crc_ok);
480 printf("RX WEP errors:\t\t\t\t\t[ %d ]\n",
481 stats->an_rx_wep_errs);
482 printf("RX WEP OK:\t\t\t\t\t[ %d ]\n",
483 stats->an_rx_wep_ok);
484 printf("Long retries:\t\t\t\t\t[ %d ]\n",
485 stats->an_retry_long);
486 printf("Short retries:\t\t\t\t\t[ %d ]\n",
487 stats->an_retry_short);
488 printf("Retries exhausted:\t\t\t\t[ %d ]\n",
489 stats->an_retry_max);
490 printf("Bad ACK:\t\t\t\t\t[ %d ]\n",
492 printf("Bad CTS:\t\t\t\t\t[ %d ]\n",
494 printf("RX good ACKs:\t\t\t\t\t[ %d ]\n",
495 stats->an_rx_ack_ok);
496 printf("RX good CTSs:\t\t\t\t\t[ %d ]\n",
497 stats->an_rx_cts_ok);
498 printf("TX good ACKs:\t\t\t\t\t[ %d ]\n",
499 stats->an_tx_ack_ok);
500 printf("TX good RTSs:\t\t\t\t\t[ %d ]\n",
501 stats->an_tx_rts_ok);
502 printf("TX good CTSs:\t\t\t\t\t[ %d ]\n",
503 stats->an_tx_cts_ok);
504 printf("LMAC multicasts transmitted:\t\t\t[ %d ]\n",
505 stats->an_tx_lmac_mcasts);
506 printf("LMAC broadcasts transmitted:\t\t\t[ %d ]\n",
507 stats->an_tx_lmac_bcasts);
508 printf("LMAC unicast frags transmitted:\t\t\t[ %d ]\n",
509 stats->an_tx_lmac_ucast_frags);
510 printf("LMAC unicasts transmitted:\t\t\t[ %d ]\n",
511 stats->an_tx_lmac_ucasts);
512 printf("Beacons transmitted:\t\t\t\t[ %d ]\n",
513 stats->an_tx_beacons);
514 printf("Beacons received:\t\t\t\t[ %d ]\n",
515 stats->an_rx_beacons);
516 printf("Single transmit collisions:\t\t\t[ %d ]\n",
517 stats->an_tx_single_cols);
518 printf("Multiple transmit collisions:\t\t\t[ %d ]\n",
519 stats->an_tx_multi_cols);
520 printf("Transmits without deferrals:\t\t\t[ %d ]\n",
521 stats->an_tx_defers_no);
522 printf("Transmits deferred due to protocol:\t\t[ %d ]\n",
523 stats->an_tx_defers_prot);
524 printf("Transmits deferred due to energy detect:\t\t[ %d ]\n",
525 stats->an_tx_defers_energy);
526 printf("RX duplicate frames/frags:\t\t\t[ %d ]\n",
528 printf("RX partial frames:\t\t\t\t[ %d ]\n",
529 stats->an_rx_partial);
530 printf("TX max lifetime exceeded:\t\t\t[ %d ]\n",
531 stats->an_tx_too_old);
532 printf("RX max lifetime exceeded:\t\t\t[ %d ]\n",
533 stats->an_tx_too_old);
534 printf("Sync lost due to too many missed beacons:\t[ %d ]\n",
535 stats->an_lostsync_missed_beacons);
536 printf("Sync lost due to ARL exceeded:\t\t\t[ %d ]\n",
537 stats->an_lostsync_arl_exceeded);
538 printf("Sync lost due to deauthentication:\t\t[ %d ]\n",
539 stats->an_lostsync_deauthed);
540 printf("Sync lost due to disassociation:\t\t[ %d ]\n",
541 stats->an_lostsync_disassociated);
542 printf("Sync lost due to excess change in TSF timing:\t[ %d ]\n",
543 stats->an_lostsync_tsf_timing);
544 printf("Host transmitted multicasts:\t\t\t[ %d ]\n",
545 stats->an_tx_host_mcasts);
546 printf("Host transmitted broadcasts:\t\t\t[ %d ]\n",
547 stats->an_tx_host_bcasts);
548 printf("Host transmitted unicasts:\t\t\t[ %d ]\n",
549 stats->an_tx_host_ucasts);
550 printf("Host transmission failures:\t\t\t[ %d ]\n",
551 stats->an_tx_host_failed);
552 printf("Host received multicasts:\t\t\t[ %d ]\n",
553 stats->an_rx_host_mcasts);
554 printf("Host received broadcasts:\t\t\t[ %d ]\n",
555 stats->an_rx_host_bcasts);
556 printf("Host received unicasts:\t\t\t\t[ %d ]\n",
557 stats->an_rx_host_ucasts);
558 printf("Host receive discards:\t\t\t\t[ %d ]\n",
559 stats->an_rx_host_discarded);
560 printf("HMAC transmitted multicasts:\t\t\t[ %d ]\n",
561 stats->an_tx_hmac_mcasts);
562 printf("HMAC transmitted broadcasts:\t\t\t[ %d ]\n",
563 stats->an_tx_hmac_bcasts);
564 printf("HMAC transmitted unicasts:\t\t\t[ %d ]\n",
565 stats->an_tx_hmac_ucasts);
566 printf("HMAC transmissions failed:\t\t\t[ %d ]\n",
567 stats->an_tx_hmac_failed);
568 printf("HMAC received multicasts:\t\t\t[ %d ]\n",
569 stats->an_rx_hmac_mcasts);
570 printf("HMAC received broadcasts:\t\t\t[ %d ]\n",
571 stats->an_rx_hmac_bcasts);
572 printf("HMAC received unicasts:\t\t\t\t[ %d ]\n",
573 stats->an_rx_hmac_ucasts);
574 printf("HMAC receive discards:\t\t\t\t[ %d ]\n",
575 stats->an_rx_hmac_discarded);
576 printf("HMAC transmits accepted:\t\t\t[ %d ]\n",
577 stats->an_tx_hmac_accepted);
578 printf("SSID mismatches:\t\t\t\t[ %d ]\n",
579 stats->an_ssid_mismatches);
580 printf("Access point mismatches:\t\t\t[ %d ]\n",
581 stats->an_ap_mismatches);
582 printf("Speed mismatches:\t\t\t\t[ %d ]\n",
583 stats->an_rates_mismatches);
584 printf("Authentication rejects:\t\t\t\t[ %d ]\n",
585 stats->an_auth_rejects);
586 printf("Authentication timeouts:\t\t\t[ %d ]\n",
587 stats->an_auth_timeouts);
588 printf("Association rejects:\t\t\t\t[ %d ]\n",
589 stats->an_assoc_rejects);
590 printf("Association timeouts:\t\t\t\t[ %d ]\n",
591 stats->an_assoc_timeouts);
592 printf("Management frames received:\t\t\t[ %d ]\n",
593 stats->an_rx_mgmt_pkts);
594 printf("Management frames transmitted:\t\t\t[ %d ]\n",
595 stats->an_tx_mgmt_pkts);
596 printf("Refresh frames received:\t\t\t[ %d ]\n",
597 stats->an_rx_refresh_pkts),
598 printf("Refresh frames transmitted:\t\t\t[ %d ]\n",
599 stats->an_tx_refresh_pkts),
600 printf("Poll frames received:\t\t\t\t[ %d ]\n",
601 stats->an_rx_poll_pkts);
602 printf("Poll frames transmitted:\t\t\t[ %d ]\n",
603 stats->an_tx_poll_pkts);
604 printf("Host requested sync losses:\t\t\t[ %d ]\n",
605 stats->an_lostsync_hostreq);
606 printf("Host transmitted bytes:\t\t\t\t[ %d ]\n",
607 stats->an_host_tx_bytes);
608 printf("Host received bytes:\t\t\t\t[ %d ]\n",
609 stats->an_host_rx_bytes);
610 printf("Uptime in microseconds:\t\t\t\t[ %d ]\n",
611 stats->an_uptime_usecs);
612 printf("Uptime in seconds:\t\t\t\t[ %d ]\n",
613 stats->an_uptime_secs);
614 printf("Sync lost due to better AP:\t\t\t[ %d ]\n",
615 stats->an_lostsync_better_ap);
620 static void an_dumpap(iface)
623 struct an_ltv_aplist *ap;
626 areq.an_len = sizeof(areq);
627 areq.an_type = AN_RID_APLIST;
629 an_getval(iface, &areq);
631 ap = (struct an_ltv_aplist *)&areq;
632 printf("Access point 1:\t\t\t");
633 an_printhex((char *)&ap->an_ap1, ETHER_ADDR_LEN);
634 printf("\nAccess point 2:\t\t\t");
635 an_printhex((char *)&ap->an_ap2, ETHER_ADDR_LEN);
636 printf("\nAccess point 3:\t\t\t");
637 an_printhex((char *)&ap->an_ap3, ETHER_ADDR_LEN);
638 printf("\nAccess point 4:\t\t\t");
639 an_printhex((char *)&ap->an_ap4, ETHER_ADDR_LEN);
645 static void an_dumpssid(iface)
648 struct an_ltv_ssidlist *ssid;
651 areq.an_len = sizeof(areq);
652 areq.an_type = AN_RID_SSIDLIST;
654 an_getval(iface, &areq);
656 ssid = (struct an_ltv_ssidlist *)&areq;
657 printf("SSID 1:\t\t\t[ %.*s ]\n", ssid->an_ssid1_len, ssid->an_ssid1);
658 printf("SSID 2:\t\t\t[ %.*s ]\n", ssid->an_ssid2_len, ssid->an_ssid2);
659 printf("SSID 3:\t\t\t[ %.*s ]\n", ssid->an_ssid3_len, ssid->an_ssid3);
664 static void an_dumpconfig(iface)
667 struct an_ltv_genconfig *cfg;
669 unsigned char diversity;
671 areq.an_len = sizeof(areq);
672 areq.an_type = AN_RID_ACTUALCFG;
674 an_getval(iface, &areq);
676 cfg = (struct an_ltv_genconfig *)&areq;
678 printf("Operating mode:\t\t\t\t[ ");
679 if ((cfg->an_opmode & 0x7) == AN_OPMODE_IBSS_ADHOC)
681 if ((cfg->an_opmode & 0x7) == AN_OPMODE_INFRASTRUCTURE_STATION)
682 printf("infrastructure");
683 if ((cfg->an_opmode & 0x7) == AN_OPMODE_AP)
684 printf("access point");
685 if ((cfg->an_opmode & 0x7) == AN_OPMODE_AP_REPEATER)
686 printf("access point repeater");
688 printf("\nReceive mode:\t\t\t\t[ ");
689 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_BC_MC_ADDR)
690 printf("broadcast/multicast/unicast");
691 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_BC_ADDR)
692 printf("broadcast/unicast");
693 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_ADDR)
695 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_80211_MONITOR_CURBSS)
696 printf("802.11 monitor, current BSSID");
697 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_80211_MONITOR_ANYBSS)
698 printf("802.11 monitor, any BSSID");
699 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_LAN_MONITOR_CURBSS)
700 printf("LAN monitor, current BSSID");
702 printf("\nFragment threshold:\t\t\t");
703 an_printwords(&cfg->an_fragthresh, 1);
704 printf("\nRTS threshold:\t\t\t\t");
705 an_printwords(&cfg->an_rtsthresh, 1);
706 printf("\nMAC address:\t\t\t\t");
707 an_printhex((char *)&cfg->an_macaddr, ETHER_ADDR_LEN);
708 printf("\nSupported rates:\t\t\t");
709 an_printspeeds(cfg->an_rates, 8);
710 printf("\nShort retry limit:\t\t\t");
711 an_printwords(&cfg->an_shortretry_limit, 1);
712 printf("\nLong retry limit:\t\t\t");
713 an_printwords(&cfg->an_longretry_limit, 1);
714 printf("\nTX MSDU lifetime:\t\t\t");
715 an_printwords(&cfg->an_tx_msdu_lifetime, 1);
716 printf("\nRX MSDU lifetime:\t\t\t");
717 an_printwords(&cfg->an_rx_msdu_lifetime, 1);
718 printf("\nStationary:\t\t\t\t");
719 an_printbool(cfg->an_stationary);
720 printf("\nOrdering:\t\t\t\t");
721 an_printbool(cfg->an_ordering);
722 printf("\nDevice type:\t\t\t\t[ ");
723 if (cfg->an_devtype == AN_DEVTYPE_PC4500)
725 else if (cfg->an_devtype == AN_DEVTYPE_PC4800)
728 printf("unknown (%x)", cfg->an_devtype);
730 printf("\nScanning mode:\t\t\t\t[ ");
731 if (cfg->an_scanmode == AN_SCANMODE_ACTIVE)
733 if (cfg->an_scanmode == AN_SCANMODE_PASSIVE)
735 if (cfg->an_scanmode == AN_SCANMODE_AIRONET_ACTIVE)
736 printf("Aironet active");
738 printf("\nProbe delay:\t\t\t\t");
739 an_printwords(&cfg->an_probedelay, 1);
740 printf("\nProbe energy timeout:\t\t\t");
741 an_printwords(&cfg->an_probe_energy_timeout, 1);
742 printf("\nProbe response timeout:\t\t\t");
743 an_printwords(&cfg->an_probe_response_timeout, 1);
744 printf("\nBeacon listen timeout:\t\t\t");
745 an_printwords(&cfg->an_beacon_listen_timeout, 1);
746 printf("\nIBSS join network timeout:\t\t");
747 an_printwords(&cfg->an_ibss_join_net_timeout, 1);
748 printf("\nAuthentication timeout:\t\t\t");
749 an_printwords(&cfg->an_auth_timeout, 1);
750 printf("\nWEP enabled:\t\t\t\t[ ");
751 if (cfg->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE)
753 if (cfg->an_authtype & AN_AUTHTYPE_LEAP)
755 else if (cfg->an_authtype & AN_AUTHTYPE_ALLOW_UNENCRYPTED)
756 printf("mixed cell");
763 printf("\nAuthentication type:\t\t\t[ ");
764 if ((cfg->an_authtype & AN_AUTHTYPE_MASK) == AN_AUTHTYPE_NONE)
766 if ((cfg->an_authtype & AN_AUTHTYPE_MASK) == AN_AUTHTYPE_OPEN)
768 if ((cfg->an_authtype & AN_AUTHTYPE_MASK) == AN_AUTHTYPE_SHAREDKEY)
769 printf("shared key");
771 printf("\nAssociation timeout:\t\t\t");
772 an_printwords(&cfg->an_assoc_timeout, 1);
773 printf("\nSpecified AP association timeout:\t");
774 an_printwords(&cfg->an_specified_ap_timeout, 1);
775 printf("\nOffline scan interval:\t\t\t");
776 an_printwords(&cfg->an_offline_scan_interval, 1);
777 printf("\nOffline scan duration:\t\t\t");
778 an_printwords(&cfg->an_offline_scan_duration, 1);
779 printf("\nLink loss delay:\t\t\t");
780 an_printwords(&cfg->an_link_loss_delay, 1);
781 printf("\nMax beacon loss time:\t\t\t");
782 an_printwords(&cfg->an_max_beacon_lost_time, 1);
783 printf("\nRefresh interval:\t\t\t");
784 an_printwords(&cfg->an_refresh_interval, 1);
785 printf("\nPower save mode:\t\t\t[ ");
786 if (cfg->an_psave_mode == AN_PSAVE_NONE)
788 if (cfg->an_psave_mode == AN_PSAVE_CAM)
789 printf("constantly awake mode");
790 if (cfg->an_psave_mode == AN_PSAVE_PSP)
792 if (cfg->an_psave_mode == AN_PSAVE_PSP_CAM)
793 printf("PSP-CAM (fast PSP)");
795 printf("\nSleep through DTIMs:\t\t\t");
796 an_printbool(cfg->an_sleep_for_dtims);
797 printf("\nPower save listen interval:\t\t");
798 an_printwords(&cfg->an_listen_interval, 1);
799 printf("\nPower save fast listen interval:\t");
800 an_printwords(&cfg->an_fast_listen_interval, 1);
801 printf("\nPower save listen decay:\t\t");
802 an_printwords(&cfg->an_listen_decay, 1);
803 printf("\nPower save fast listen decay:\t\t");
804 an_printwords(&cfg->an_fast_listen_decay, 1);
805 printf("\nAP/ad-hoc Beacon period:\t\t");
806 an_printwords(&cfg->an_beacon_period, 1);
807 printf("\nAP/ad-hoc ATIM duration:\t\t");
808 an_printwords(&cfg->an_atim_duration, 1);
809 printf("\nAP/ad-hoc current channel:\t\t");
810 an_printwords(&cfg->an_ds_channel, 1);
811 printf("\nAP/ad-hoc DTIM period:\t\t\t");
812 an_printwords(&cfg->an_dtim_period, 1);
813 printf("\nRadio type:\t\t\t\t[ ");
814 if (cfg->an_radiotype & AN_RADIOTYPE_80211_FH)
816 else if (cfg->an_radiotype & AN_RADIOTYPE_80211_DS)
818 else if (cfg->an_radiotype & AN_RADIOTYPE_LM2000_DS)
821 printf("unknown (%x)", cfg->an_radiotype);
823 printf("\nRX Diversity:\t\t\t\t[ ");
824 diversity = cfg->an_diversity & 0xFF;
825 if (diversity == AN_DIVERSITY_FACTORY_DEFAULT)
826 printf("factory default");
827 else if (diversity == AN_DIVERSITY_ANTENNA_1_ONLY)
828 printf("antenna 1 only");
829 else if (diversity == AN_DIVERSITY_ANTENNA_2_ONLY)
830 printf("antenna 2 only");
831 else if (diversity == AN_DIVERSITY_ANTENNA_1_AND_2)
832 printf("antenna 1 and 2");
834 printf("\nTX Diversity:\t\t\t\t[ ");
835 diversity = (cfg->an_diversity >> 8) & 0xFF;
836 if (diversity == AN_DIVERSITY_FACTORY_DEFAULT)
837 printf("factory default");
838 else if (diversity == AN_DIVERSITY_ANTENNA_1_ONLY)
839 printf("antenna 1 only");
840 else if (diversity == AN_DIVERSITY_ANTENNA_2_ONLY)
841 printf("antenna 2 only");
842 else if (diversity == AN_DIVERSITY_ANTENNA_1_AND_2)
843 printf("antenna 1 and 2");
845 printf("\nTransmit power level:\t\t\t");
846 an_printwords(&cfg->an_tx_power, 1);
847 printf("\nRSS threshold:\t\t\t\t");
848 an_printwords(&cfg->an_rss_thresh, 1);
849 printf("\nNode name:\t\t\t\t");
850 an_printstr((char *)&cfg->an_nodename, 16);
851 printf("\nARL threshold:\t\t\t\t");
852 an_printwords(&cfg->an_arl_thresh, 1);
853 printf("\nARL decay:\t\t\t\t");
854 an_printwords(&cfg->an_arl_decay, 1);
855 printf("\nARL delay:\t\t\t\t");
856 an_printwords(&cfg->an_arl_delay, 1);
857 printf("\nConfiguration:\t\t\t\t[ ");
858 if (cfg->an_home_product & AN_HOME_NETWORK)
859 printf("Home Configuration");
861 printf("Enterprise Configuration");
866 an_readkeyinfo(iface);
871 static void an_dumprssimap(iface)
874 struct an_ltv_rssi_map *rssi;
878 areq.an_len = sizeof(areq);
879 areq.an_type = AN_RID_RSSI_MAP;
881 an_getval(iface, &areq);
883 rssi = (struct an_ltv_rssi_map *)&areq;
885 printf("idx\tpct\t dBm\n");
887 for (i = 0; i < 0xFF; i++) {
889 * negate the dBm value: it's the only way the power
892 printf("%3d\t%3d\t%4d\n", i,
893 rssi->an_entries[i].an_rss_pct,
894 - rssi->an_entries[i].an_rss_dbm);
903 fprintf(stderr, "usage: %s -i iface -A (show specified APs)\n", p);
904 fprintf(stderr, "\t%s -i iface -N (show specified SSIDss)\n", p);
905 fprintf(stderr, "\t%s -i iface -S (show NIC status)\n", p);
906 fprintf(stderr, "\t%s -i iface -I (show NIC capabilities)\n", p);
907 fprintf(stderr, "\t%s -i iface -T (show stats counters)\n", p);
908 fprintf(stderr, "\t%s -i iface -C (show current config)\n", p);
909 fprintf(stderr, "\t%s -i iface -R (show RSSI map)\n", p);
910 fprintf(stderr, "\t%s -i iface -t 0-4 (set TX speed)\n", p);
911 fprintf(stderr, "\t%s -i iface -s 0-3 (set power save mode)\n", p);
912 fprintf(stderr, "\t%s -i iface [-v 1-4] -a AP (specify AP)\n", p);
913 fprintf(stderr, "\t%s -i iface -b val (set beacon period)\n", p);
914 fprintf(stderr, "\t%s -i iface [-v 0|1] -d val (set diversity)\n", p);
915 fprintf(stderr, "\t%s -i iface -j val (set netjoin timeout)\n", p);
916 fprintf(stderr, "\t%s -i iface -e 0-4 (enable transmit key)\n", p);
917 fprintf(stderr, "\t%s -i iface [-v 0-8] -k key (set key)\n", p);
918 fprintf(stderr, "\t%s -i iface -K 0-2 (no auth/open/shared secret)\n", p);
919 fprintf(stderr, "\t%s -i iface -W 0-2 (no WEP/full WEP/mixed cell)\n", p);
920 fprintf(stderr, "\t%s -i iface -l val (set station name)\n", p);
921 fprintf(stderr, "\t%s -i iface -m val (set MAC address)\n", p);
922 fprintf(stderr, "\t%s -i iface [-v 1-3] -n SSID "
923 "(specify SSID)\n", p);
924 fprintf(stderr, "\t%s -i iface -o 0|1 (set operating mode)\n", p);
925 fprintf(stderr, "\t%s -i iface -c val (set ad-hoc channel)\n", p);
926 fprintf(stderr, "\t%s -i iface -f val (set frag threshold)\n", p);
927 fprintf(stderr, "\t%s -i iface -r val (set RTS threshold)\n", p);
928 fprintf(stderr, "\t%s -i iface -M 0-15 (set monitor mode)\n", p);
929 fprintf(stderr, "\t%s -i iface -L user (enter LEAP authentication mode)\n", p);
931 fprintf(stderr, "\t%s -i iface -Q print signal quality cache\n", p);
932 fprintf(stderr, "\t%s -i iface -Z zero out signal cache\n", p);
935 fprintf(stderr, "\t%s -h (display this message)\n", p);
941 static void an_setconfig(iface, act, arg)
946 struct an_ltv_genconfig *cfg;
947 struct an_ltv_caps *caps;
949 struct an_req areq_caps;
950 u_int16_t diversity = 0;
951 struct ether_addr *addr;
954 areq.an_len = sizeof(areq);
955 areq.an_type = AN_RID_GENCONFIG;
956 an_getval(iface, &areq);
957 cfg = (struct an_ltv_genconfig *)&areq;
959 areq_caps.an_len = sizeof(areq);
960 areq_caps.an_type = AN_RID_CAPABILITIES;
961 an_getval(iface, &areq_caps);
962 caps = (struct an_ltv_caps *)&areq_caps;
966 cfg->an_opmode = atoi(arg);
969 cfg->an_ds_channel = atoi(arg);
971 case ACT_SET_PWRSAVE:
972 cfg->an_psave_mode = atoi(arg);
974 case ACT_SET_SCANMODE:
975 cfg->an_scanmode = atoi(arg);
977 case ACT_SET_DIVERSITY_RX:
978 case ACT_SET_DIVERSITY_TX:
981 diversity = AN_DIVERSITY_FACTORY_DEFAULT;
984 diversity = AN_DIVERSITY_ANTENNA_1_ONLY;
987 diversity = AN_DIVERSITY_ANTENNA_2_ONLY;
990 diversity = AN_DIVERSITY_ANTENNA_1_AND_2;
993 errx(1, "bad diversity setting: %d", diversity);
996 if (act == ACT_SET_DIVERSITY_RX) {
997 cfg->an_diversity &= 0xFF00;
998 cfg->an_diversity |= diversity;
1000 cfg->an_diversity &= 0x00FF;
1001 cfg->an_diversity |= (diversity << 8);
1005 for (i = 0; i < 8; i++) {
1006 if (caps->an_tx_powerlevels[i] == atoi(arg))
1010 errx(1, "unsupported power level: %dmW", atoi(arg));
1012 cfg->an_tx_power = atoi(arg);
1014 case ACT_SET_RTS_THRESH:
1015 cfg->an_rtsthresh = atoi(arg);
1017 case ACT_SET_RTS_RETRYLIM:
1018 cfg->an_shortretry_limit =
1019 cfg->an_longretry_limit = atoi(arg);
1021 case ACT_SET_BEACON_PERIOD:
1022 cfg->an_beacon_period = atoi(arg);
1024 case ACT_SET_WAKE_DURATION:
1025 cfg->an_atim_duration = atoi(arg);
1027 case ACT_SET_FRAG_THRESH:
1028 cfg->an_fragthresh = atoi(arg);
1030 case ACT_SET_NETJOIN:
1031 cfg->an_ibss_join_net_timeout = atoi(arg);
1033 case ACT_SET_MYNAME:
1034 bzero(cfg->an_nodename, 16);
1035 strncpy((char *)&cfg->an_nodename, optarg, 16);
1038 addr = ether_aton((char *)arg);
1041 errx(1, "badly formatted address");
1042 bzero(cfg->an_macaddr, ETHER_ADDR_LEN);
1043 bcopy((char *)addr, (char *)&cfg->an_macaddr, ETHER_ADDR_LEN);
1045 case ACT_ENABLE_WEP:
1046 switch (atoi (arg)) {
1049 cfg->an_authtype &= ~(AN_AUTHTYPE_PRIVACY_IN_USE
1050 | AN_AUTHTYPE_ALLOW_UNENCRYPTED
1051 | AN_AUTHTYPE_LEAP);
1055 cfg->an_authtype |= AN_AUTHTYPE_PRIVACY_IN_USE;
1056 cfg->an_authtype &= ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
1057 cfg->an_authtype &= ~AN_AUTHTYPE_LEAP;
1061 cfg->an_authtype = AN_AUTHTYPE_PRIVACY_IN_USE
1062 | AN_AUTHTYPE_ALLOW_UNENCRYPTED;
1066 case ACT_SET_KEY_TYPE:
1067 cfg->an_authtype = (cfg->an_authtype & ~AN_AUTHTYPE_MASK)
1070 case ACT_SET_MONITOR_MODE:
1071 areq.an_type = AN_RID_MONITOR_MODE;
1072 cfg->an_len = atoi(arg); /* mode is put in length */
1075 errx(1, "unknown action");
1079 an_setval(iface, &areq);
1083 static void an_setspeed(iface, act, arg)
1089 struct an_ltv_caps *caps;
1092 areq.an_len = sizeof(areq);
1093 areq.an_type = AN_RID_CAPABILITIES;
1095 an_getval(iface, &areq);
1096 caps = (struct an_ltv_caps *)&areq;
1103 speed = AN_RATE_1MBPS;
1106 speed = AN_RATE_2MBPS;
1109 if (caps->an_rates[2] != AN_RATE_5_5MBPS)
1110 errx(1, "5.5Mbps not supported on this card");
1111 speed = AN_RATE_5_5MBPS;
1114 if (caps->an_rates[3] != AN_RATE_11MBPS)
1115 errx(1, "11Mbps not supported on this card");
1116 speed = AN_RATE_11MBPS;
1119 errx(1, "unsupported speed");
1124 areq.an_type = AN_RID_TX_SPEED;
1125 areq.an_val[0] = speed;
1127 an_setval(iface, &areq);
1131 static void an_setap(iface, act, arg)
1136 struct an_ltv_aplist *ap;
1138 struct ether_addr *addr;
1140 areq.an_len = sizeof(areq);
1141 areq.an_type = AN_RID_APLIST;
1143 an_getval(iface, &areq);
1144 ap = (struct an_ltv_aplist *)&areq;
1146 addr = ether_aton((char *)arg);
1149 errx(1, "badly formatted address");
1153 bzero(ap->an_ap1, ETHER_ADDR_LEN);
1154 bcopy((char *)addr, (char *)&ap->an_ap1, ETHER_ADDR_LEN);
1157 bzero(ap->an_ap2, ETHER_ADDR_LEN);
1158 bcopy((char *)addr, (char *)&ap->an_ap2, ETHER_ADDR_LEN);
1161 bzero(ap->an_ap3, ETHER_ADDR_LEN);
1162 bcopy((char *)addr, (char *)&ap->an_ap3, ETHER_ADDR_LEN);
1165 bzero(ap->an_ap4, ETHER_ADDR_LEN);
1166 bcopy((char *)addr, (char *)&ap->an_ap4, ETHER_ADDR_LEN);
1169 errx(1, "unknown action");
1173 an_setval(iface, &areq);
1177 static void an_setssid(iface, act, arg)
1182 struct an_ltv_ssidlist *ssid;
1185 areq.an_len = sizeof(areq);
1186 areq.an_type = AN_RID_SSIDLIST;
1188 an_getval(iface, &areq);
1189 ssid = (struct an_ltv_ssidlist *)&areq;
1193 bzero(ssid->an_ssid1, sizeof(ssid->an_ssid1));
1194 strlcpy(ssid->an_ssid1, (char *)arg, sizeof(ssid->an_ssid1));
1195 ssid->an_ssid1_len = strlen(ssid->an_ssid1);
1198 bzero(ssid->an_ssid2, sizeof(ssid->an_ssid2));
1199 strlcpy(ssid->an_ssid2, (char *)arg, sizeof(ssid->an_ssid2));
1200 ssid->an_ssid2_len = strlen(ssid->an_ssid2);
1203 bzero(ssid->an_ssid3, sizeof(ssid->an_ssid3));
1204 strlcpy(ssid->an_ssid3, (char *)arg, sizeof(ssid->an_ssid3));
1205 ssid->an_ssid3_len = strlen(ssid->an_ssid3);
1208 errx(1, "unknown action");
1212 an_setval(iface, &areq);
1217 static void an_zerocache(iface)
1222 bzero((char *)&areq, sizeof(areq));
1224 areq.an_type = AN_RID_ZERO_CACHE;
1226 an_getval(iface, &areq);
1231 static void an_readcache(iface)
1236 struct an_sigcache *sc;
1241 errx(1, "must specify interface name");
1243 bzero((char *)&areq, sizeof(areq));
1244 areq.an_len = AN_MAX_DATALEN;
1245 areq.an_type = AN_RID_READ_CACHE;
1247 an_getval(iface, &areq);
1249 an_sigitems = (int *) &areq.an_val;
1250 pt = ((char *) &areq.an_val);
1252 sc = (struct an_sigcache *) pt;
1254 for (i = 0; i < *an_sigitems; i++) {
1255 printf("[%d/%d]:", i+1, *an_sigitems);
1256 printf(" %02x:%02x:%02x:%02x:%02x:%02x,",
1262 sc->macsrc[5]&0xff);
1263 printf(" %d.%d.%d.%d,",((sc->ipsrc >> 0) & 0xff),
1264 ((sc->ipsrc >> 8) & 0xff),
1265 ((sc->ipsrc >> 16) & 0xff),
1266 ((sc->ipsrc >> 24) & 0xff));
1267 printf(" sig: %d, noise: %d, qual: %d\n",
1278 static int an_hex2int(c)
1281 if (c >= '0' && c <= '9')
1283 if (c >= 'A' && c <= 'F')
1284 return (c - 'A' + 10);
1285 if (c >= 'a' && c <= 'f')
1286 return (c - 'a' + 10);
1291 static void an_str2key(s, k)
1293 struct an_ltv_key *k;
1298 /* Is this a hex string? */
1299 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) {
1300 /* Yes, convert to int. */
1302 p = (char *)&k->key[0];
1303 for (i = 2; s[i] != '\0' && s[i + 1] != '\0'; i+= 2) {
1304 *p++ = (an_hex2int(s[i]) << 4) + an_hex2int(s[i + 1]);
1308 errx(1, "hex strings must be of even length");
1311 /* No, just copy it in. */
1312 bcopy(s, k->key, strlen(s));
1313 k->klen = strlen(s);
1319 static void an_setkeys(iface, key, keytype)
1325 struct an_ltv_key *k;
1327 bzero((char *)&areq, sizeof(areq));
1328 k = (struct an_ltv_key *)&areq;
1330 if (strlen(key) > 28) {
1331 err(1, "encryption key must be no "
1332 "more than 18 characters long");
1337 k->kindex=keytype/2;
1339 if (!(k->klen==0 || k->klen==5 || k->klen==13)) {
1340 err(1, "encryption key must be 0, 5 or 13 bytes long");
1343 /* default mac and only valid one (from manual) 1.0.0.0.0.0 */
1351 switch(keytype & 1) {
1353 areq.an_len = sizeof(struct an_ltv_key);
1354 areq.an_type = AN_RID_WEP_PERM;
1355 an_setval(iface, &areq);
1358 areq.an_len = sizeof(struct an_ltv_key);
1359 areq.an_type = AN_RID_WEP_TEMP;
1360 an_setval(iface, &areq);
1367 static void an_readkeyinfo(iface)
1371 struct an_ltv_genconfig *cfg;
1372 struct an_ltv_key *k;
1376 areq.an_len = sizeof(areq);
1377 areq.an_type = AN_RID_ACTUALCFG;
1378 an_getval(iface, &areq);
1379 cfg = (struct an_ltv_genconfig *)&areq;
1380 if (cfg->an_home_product & AN_HOME_NETWORK)
1385 bzero((char *)&areq, sizeof(areq));
1386 k = (struct an_ltv_key *)&areq;
1388 printf("WEP Key status:\n");
1389 areq.an_type = AN_RID_WEP_TEMP; /* read first key */
1390 for(i=0; i<5; i++) {
1391 areq.an_len = sizeof(struct an_ltv_key);
1392 an_getval(iface, &areq);
1393 if (k->kindex == 0xffff)
1397 printf("\tKey %d is unset\n",k->kindex);
1400 printf("\tKey %d is set 40 bits\n",k->kindex);
1403 printf("\tKey %d is set 128 bits\n",k->kindex);
1406 printf("\tWEP Key %d has an unknown size %d\n",
1410 areq.an_type = AN_RID_WEP_PERM; /* read next key */
1413 areq.an_len = sizeof(struct an_ltv_key);
1414 an_getval(iface, &areq);
1415 printf("\tThe active transmit key is %d\n", 4 * home + k->mac[0]);
1420 static void an_enable_tx_key(iface, arg)
1425 struct an_ltv_key *k;
1426 struct an_ltv_genconfig *config;
1428 bzero((char *)&areq, sizeof(areq));
1430 /* set home or not home mode */
1431 areq.an_len = sizeof(struct an_ltv_genconfig);
1432 areq.an_type = AN_RID_GENCONFIG;
1433 an_getval(iface, &areq);
1434 config = (struct an_ltv_genconfig *)&areq;
1435 if (atoi(arg) == 4) {
1436 config->an_home_product |= AN_HOME_NETWORK;
1438 config->an_home_product &= ~AN_HOME_NETWORK;
1440 an_setval(iface, &areq);
1442 bzero((char *)&areq, sizeof(areq));
1444 k = (struct an_ltv_key *)&areq;
1446 /* From a Cisco engineer write the transmit key to use in the
1447 first MAC, index is FFFF*/
1451 k->mac[0]=atoi(arg);
1458 areq.an_len = sizeof(struct an_ltv_key);
1459 areq.an_type = AN_RID_WEP_PERM;
1460 an_setval(iface, &areq);
1465 static void an_enable_leap_mode(iface, username)
1470 struct an_ltv_status *sts;
1471 struct an_ltv_genconfig *cfg;
1472 struct an_ltv_caps *caps;
1473 struct an_ltv_leap_username an_username;
1474 struct an_ltv_leap_password an_password;
1479 char unicode_password[LEAP_PASSWORD_MAX * 2];
1481 areq.an_len = sizeof(areq);
1482 areq.an_type = AN_RID_CAPABILITIES;
1484 an_getval(iface, &areq);
1486 caps = (struct an_ltv_caps *)&areq;
1488 if (!caps->an_softcaps & AN_AUTHTYPE_LEAP) {
1489 fprintf(stderr, "Firmware does not support LEAP\n");
1493 bzero(&an_username, sizeof(an_username));
1494 bzero(&an_password, sizeof(an_password));
1496 len = strlen(username);
1497 if (len > LEAP_USERNAME_MAX) {
1498 printf("Username too long (max %d)\n", LEAP_USERNAME_MAX);
1501 strncpy(an_username.an_username, username, len);
1502 an_username.an_username_len = len;
1503 an_username.an_len = sizeof(an_username);
1504 an_username.an_type = AN_RID_LEAPUSERNAME;
1506 password = getpass("Enter LEAP password:");
1508 len = strlen(password);
1509 if (len > LEAP_PASSWORD_MAX) {
1510 printf("Password too long (max %d)\n", LEAP_PASSWORD_MAX);
1514 bzero(&unicode_password, sizeof(unicode_password));
1515 for(i = 0; i < len; i++) {
1516 unicode_password[i * 2] = *password++;
1521 MD4Update(&context, unicode_password, len * 2);
1522 MD4Final(&an_password.an_password[0], &context);
1526 MD4Update (&context, &an_password.an_password[0], 16);
1527 MD4Final (&an_password.an_password[16], &context);
1529 an_password.an_password_len = 32;
1530 an_password.an_len = sizeof(an_password);
1531 an_password.an_type = AN_RID_LEAPPASSWORD;
1533 an_setval(iface, (struct an_req *)&an_username);
1534 an_setval(iface, (struct an_req *)&an_password);
1536 areq.an_len = sizeof(areq);
1537 areq.an_type = AN_RID_GENCONFIG;
1538 an_getval(iface, &areq);
1539 cfg = (struct an_ltv_genconfig *)&areq;
1540 cfg->an_authtype = (AN_AUTHTYPE_PRIVACY_IN_USE | AN_AUTHTYPE_LEAP);
1541 an_setval(iface, &areq);
1543 sts = (struct an_ltv_status *)&areq;
1544 areq.an_type = AN_RID_STATUS;
1546 for (i = 60; i > 0; i--) {
1547 an_getval(iface, &areq);
1548 if (sts->an_opmode & AN_STATUS_OPMODE_LEAP) {
1549 printf("Authenticated\n");
1556 fprintf(stderr, "Failed LEAP authentication\n");
1561 int main(argc, argv)
1567 const char *iface = NULL;
1573 /* Get the interface name */
1575 ch = getopt(argc, argv, "i:");
1579 if (argc > 1 && *argv[1] != '-') {
1590 while ((ch = getopt(argc, argv,
1591 "ANISCTRht:a:e:o:s:n:v:d:j:b:c:r:p:w:m:l:k:K:W:QZM:L:")) != -1) {
1595 act = ACT_ZEROCACHE;
1597 errx(1, "ANCACHE not available");
1602 act = ACT_DUMPCACHE;
1604 errx(1, "ANCACHE not available");
1614 act = ACT_DUMPSTATUS;
1620 act = ACT_DUMPSTATS;
1623 act = ACT_DUMPCONFIG;
1626 act = ACT_DUMPRSSIMAP;
1629 act = ACT_SET_TXRATE;
1633 act = ACT_SET_PWRSAVE;
1637 act = ACT_SET_TXPWR;
1641 modifier = atoi(optarg);
1659 errx(1, "bad modifier %d: there "
1660 "are only 4 access point settings",
1668 act = ACT_SET_BEACON_PERIOD;
1674 act = ACT_SET_DIVERSITY_RX;
1677 act = ACT_SET_DIVERSITY_TX;
1680 errx(1, "must specify RX or TX diversity");
1683 if (!isdigit(*optarg)) {
1684 errx(1, "%s is not numeric", optarg);
1690 act = ACT_SET_NETJOIN;
1694 act = ACT_SET_MYNAME;
1705 act = ACT_SET_SSID1;
1708 act = ACT_SET_SSID2;
1711 act = ACT_SET_SSID3;
1714 errx(1, "bad modifier %d: there"
1715 "are only 3 SSID settings", modifier);
1722 act = ACT_SET_OPMODE;
1730 act = ACT_SET_FRAG_THRESH;
1734 act = ACT_ENABLE_WEP;
1738 act = ACT_SET_KEY_TYPE;
1746 act = ACT_ENABLE_TX_KEY;
1750 act = ACT_SET_RTS_RETRYLIM;
1754 act = ACT_SET_RTS_THRESH;
1758 act = ACT_SET_WAKE_DURATION;
1762 act = ACT_SET_MONITOR_MODE;
1766 act = ACT_SET_LEAP_MODE;
1775 if (iface == NULL || (!act && !key))
1779 case ACT_DUMPSTATUS:
1780 an_dumpstatus(iface);
1786 an_dumpstats(iface);
1788 case ACT_DUMPCONFIG:
1789 an_dumpconfig(iface);
1797 case ACT_DUMPRSSIMAP:
1798 an_dumprssimap(iface);
1803 an_setssid(iface, act, arg);
1809 an_setap(iface, act, arg);
1811 case ACT_SET_TXRATE:
1812 an_setspeed(iface, act, arg);
1816 an_zerocache(iface);
1819 an_readcache(iface);
1824 an_setkeys(iface, key, modifier);
1826 case ACT_ENABLE_TX_KEY:
1827 an_enable_tx_key(iface, arg);
1829 case ACT_SET_LEAP_MODE:
1830 an_enable_leap_mode(iface, arg);
1833 an_setconfig(iface, act, arg);