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 $
35 #include <sys/types.h>
36 #include <sys/cdefs.h>
37 #include <sys/param.h>
38 #include <sys/socket.h>
39 #include <sys/ioctl.h>
40 #include <sys/socket.h>
43 #include <net/if_var.h>
44 #include <net/ethernet.h>
46 #include <dev/an/if_aironet_ieee.h>
58 static const char copyright[] = "@(#) Copyright (c) 1997, 1998, 1999\
59 Bill Paul. All rights reserved.";
60 static const char rcsid[] =
61 "@(#) $FreeBSD: src/usr.sbin/ancontrol/ancontrol.c,v 1.1.2.9 2003/02/01 03:25:13 ambrisko Exp $";
64 static int an_getval __P((const char *, struct an_req *));
65 static void an_setval __P((const char *, struct an_req *));
66 static void an_printwords __P((u_int16_t *, int));
67 static void an_printspeeds __P((u_int8_t*, int));
68 static void an_printbool __P((int));
69 static void an_printhex __P((char *, int));
70 static void an_printstr __P((char *, int));
71 static void an_dumpstatus __P((const char *));
72 static void an_dumpstats __P((const char *));
73 static void an_dumpconfig __P((const char *));
74 static void an_dumpcaps __P((const char *));
75 static void an_dumpssid __P((const char *));
76 static void an_dumpap __P((const char *));
77 static void an_setconfig __P((const char *, int, void *));
78 static void an_setssid __P((const char *, int, void *));
79 static void an_setap __P((const char *, int, void *));
80 static void an_setspeed __P((const char *, int, void *));
81 static void an_readkeyinfo __P((const char *));
83 static void an_zerocache __P((const char *));
84 static void an_readcache __P((const char *));
86 static int an_hex2int __P((char));
87 static void an_str2key __P((char *, struct an_ltv_key *));
88 static void an_setkeys __P((const char *, char *, int));
89 static void an_enable_tx_key __P((const char *, char *));
90 static void an_enable_leap_mode __P((const char *, char *));
91 static void usage __P((char *));
92 static void __P(an_dumprssimap(const char *));
93 int main __P((int, char **));
95 #define ACT_DUMPSTATS 1
96 #define ACT_DUMPCONFIG 2
97 #define ACT_DUMPSTATUS 3
98 #define ACT_DUMPCAPS 4
99 #define ACT_DUMPSSID 5
102 #define ACT_SET_OPMODE 7
103 #define ACT_SET_SSID1 8
104 #define ACT_SET_SSID2 9
105 #define ACT_SET_SSID3 10
106 #define ACT_SET_FREQ 11
107 #define ACT_SET_AP1 12
108 #define ACT_SET_AP2 13
109 #define ACT_SET_AP3 14
110 #define ACT_SET_AP4 15
111 #define ACT_SET_DRIVERNAME 16
112 #define ACT_SET_SCANMODE 17
113 #define ACT_SET_TXRATE 18
114 #define ACT_SET_RTS_THRESH 19
115 #define ACT_SET_PWRSAVE 20
116 #define ACT_SET_DIVERSITY_RX 21
117 #define ACT_SET_DIVERSITY_TX 22
118 #define ACT_SET_RTS_RETRYLIM 23
119 #define ACT_SET_WAKE_DURATION 24
120 #define ACT_SET_BEACON_PERIOD 25
121 #define ACT_SET_TXPWR 26
122 #define ACT_SET_FRAG_THRESH 27
123 #define ACT_SET_NETJOIN 28
124 #define ACT_SET_MYNAME 29
125 #define ACT_SET_MAC 30
127 #define ACT_DUMPCACHE 31
128 #define ACT_ZEROCACHE 32
130 #define ACT_ENABLE_WEP 33
131 #define ACT_SET_KEY_TYPE 34
132 #define ACT_SET_KEYS 35
133 #define ACT_ENABLE_TX_KEY 36
134 #define ACT_SET_MONITOR_MODE 37
135 #define ACT_SET_LEAP_MODE 38
137 #define ACT_DUMPRSSIMAP 39
139 static int an_getval(iface, areq)
146 bzero((char *)&ifr, sizeof(ifr));
148 strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
149 ifr.ifr_data = (caddr_t)areq;
151 s = socket(AF_INET, SOCK_DGRAM, 0);
156 if (ioctl(s, SIOCGAIRONET, &ifr) == -1) {
158 err(1, "SIOCGAIRONET");
166 static void an_setval(iface, areq)
173 bzero((char *)&ifr, sizeof(ifr));
175 strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
176 ifr.ifr_data = (caddr_t)areq;
178 s = socket(AF_INET, SOCK_DGRAM, 0);
183 if (ioctl(s, SIOCSAIRONET, &ifr) == -1)
184 err(1, "SIOCSAIRONET");
191 static void an_printstr(str, len)
197 for (i = 0; i < len - 1; i++) {
202 printf("[ %.*s ]", len, str);
207 static void an_printwords(w, len)
214 for (i = 0; i < len; i++)
221 static void an_printspeeds(w, len)
228 for (i = 0; i < len && w[i]; i++)
229 printf("%2.1fMbps ", w[i] * 0.500);
235 static void an_printbool(val)
246 static void an_printhex(ptr, len)
253 for (i = 0; i < len; i++) {
254 printf("%02x", ptr[i] & 0xFF);
265 static void an_dumpstatus(iface)
268 struct an_ltv_status *sts;
270 struct an_ltv_rssi_map an_rssimap;
271 int rssimap_valid = 0;
274 * Try to get RSSI to percent and dBM table
277 an_rssimap.an_len = sizeof(an_rssimap);
278 an_rssimap.an_type = AN_RID_RSSI_MAP;
279 rssimap_valid = an_getval(iface, (struct an_req*)&an_rssimap);
282 printf("RSSI table:\t\t[ present ]\n");
284 printf("RSSI table:\t\t[ not available ]\n");
286 areq.an_len = sizeof(areq);
287 areq.an_type = AN_RID_STATUS;
289 an_getval(iface, &areq);
291 sts = (struct an_ltv_status *)&areq;
293 printf("MAC address:\t\t");
294 an_printhex((char *)&sts->an_macaddr, ETHER_ADDR_LEN);
295 printf("\nOperating mode:\t\t[ ");
296 if (sts->an_opmode & AN_STATUS_OPMODE_CONFIGURED)
297 printf("configured ");
298 if (sts->an_opmode & AN_STATUS_OPMODE_MAC_ENABLED)
300 if (sts->an_opmode & AN_STATUS_OPMODE_RX_ENABLED)
302 if (sts->an_opmode & AN_STATUS_OPMODE_IN_SYNC)
304 if (sts->an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
305 printf("associated ");
306 if (sts->an_opmode & AN_STATUS_OPMODE_LEAP)
308 if (sts->an_opmode & AN_STATUS_OPMODE_ERROR)
311 printf("Error code:\t\t");
312 an_printhex((char *)&sts->an_errcode, 1);
314 printf("\nSignal strength:\t[ %d%% ]",
315 an_rssimap.an_entries[
316 sts->an_normalized_strength].an_rss_pct);
318 printf("\nSignal strength:\t[ %d%% ]",
319 sts->an_normalized_strength);
320 printf("\nAverage Noise:\t\t[ %d%% ]",sts->an_avg_noise_prev_min_pc);
322 printf("\nSignal quality:\t\t[ %d%% ]",
323 an_rssimap.an_entries[
324 sts->an_cur_signal_quality].an_rss_pct);
326 printf("\nSignal quality:\t\t[ %d ]",
327 sts->an_cur_signal_quality);
328 printf("\nMax Noise:\t\t[ %d%% ]",sts->an_max_noise_prev_min_pc);
330 * XXX: This uses the old definition of the rate field (units of
331 * 500kbps). Technically the new definition is that this field
332 * contains arbitrary values, but no devices which need this
333 * support exist and the IEEE seems to intend to use the old
334 * definition until they get something big so we'll keep using
335 * it as well because this will work with new cards with
338 printf("\nCurrent TX rate:\t[ %d%s ]", sts->an_current_tx_rate / 2,
339 (sts->an_current_tx_rate % 2) ? ".5" : "");
340 printf("\nCurrent SSID:\t\t");
341 an_printstr((char *)&sts->an_ssid, sts->an_ssidlen);
342 printf("\nCurrent AP name:\t");
343 an_printstr((char *)&sts->an_ap_name, 16);
344 printf("\nCurrent BSSID:\t\t");
345 an_printhex((char *)&sts->an_cur_bssid, ETHER_ADDR_LEN);
346 printf("\nBeacon period:\t\t");
347 an_printwords(&sts->an_beacon_period, 1);
348 printf("\nDTIM period:\t\t");
349 an_printwords(&sts->an_dtim_period, 1);
350 printf("\nATIM duration:\t\t");
351 an_printwords(&sts->an_atim_duration, 1);
352 printf("\nHOP period:\t\t");
353 an_printwords(&sts->an_hop_period, 1);
354 printf("\nChannel set:\t\t");
355 an_printwords(&sts->an_channel_set, 1);
356 printf("\nCurrent channel:\t");
357 an_printwords(&sts->an_cur_channel, 1);
358 printf("\nHops to backbone:\t");
359 an_printwords(&sts->an_hops_to_backbone, 1);
360 printf("\nTotal AP load:\t\t");
361 an_printwords(&sts->an_ap_total_load, 1);
362 printf("\nOur generated load:\t");
363 an_printwords(&sts->an_our_generated_load, 1);
364 printf("\nAccumulated ARL:\t");
365 an_printwords(&sts->an_accumulated_arl, 1);
370 static void an_dumpcaps(iface)
373 struct an_ltv_caps *caps;
377 areq.an_len = sizeof(areq);
378 areq.an_type = AN_RID_CAPABILITIES;
380 an_getval(iface, &areq);
382 caps = (struct an_ltv_caps *)&areq;
384 printf("OUI:\t\t\t");
385 an_printhex((char *)&caps->an_oui, 3);
386 printf("\nProduct number:\t\t");
387 an_printwords(&caps->an_prodnum, 1);
388 printf("\nManufacturer name:\t");
389 an_printstr((char *)&caps->an_manufname, 32);
390 printf("\nProduce name:\t\t");
391 an_printstr((char *)&caps->an_prodname, 16);
392 printf("\nFirmware version:\t");
393 an_printstr((char *)&caps->an_prodvers, 1);
394 printf("\nOEM MAC address:\t");
395 an_printhex((char *)&caps->an_oemaddr, ETHER_ADDR_LEN);
396 printf("\nAironet MAC address:\t");
397 an_printhex((char *)&caps->an_aironetaddr, ETHER_ADDR_LEN);
398 printf("\nRadio type:\t\t[ ");
399 if (caps->an_radiotype & AN_RADIOTYPE_80211_FH)
401 else if (caps->an_radiotype & AN_RADIOTYPE_80211_DS)
403 else if (caps->an_radiotype & AN_RADIOTYPE_LM2000_DS)
406 printf("unknown (%x)", caps->an_radiotype);
408 printf("\nRegulatory domain:\t");
409 an_printwords(&caps->an_regdomain, 1);
410 printf("\nAssigned CallID:\t");
411 an_printhex((char *)&caps->an_callid, 6);
412 printf("\nSupported speeds:\t");
413 an_printspeeds(caps->an_rates, 8);
414 printf("\nRX Diversity:\t\t[ ");
415 if (caps->an_rx_diversity == AN_DIVERSITY_FACTORY_DEFAULT)
416 printf("factory default");
417 else if (caps->an_rx_diversity == AN_DIVERSITY_ANTENNA_1_ONLY)
418 printf("antenna 1 only");
419 else if (caps->an_rx_diversity == AN_DIVERSITY_ANTENNA_2_ONLY)
420 printf("antenna 2 only");
421 else if (caps->an_rx_diversity == AN_DIVERSITY_ANTENNA_1_AND_2)
422 printf("antenna 1 and 2");
424 printf("\nTX Diversity:\t\t[ ");
425 if (caps->an_tx_diversity == AN_DIVERSITY_FACTORY_DEFAULT)
426 printf("factory default");
427 else if (caps->an_tx_diversity == AN_DIVERSITY_ANTENNA_1_ONLY)
428 printf("antenna 1 only");
429 else if (caps->an_tx_diversity == AN_DIVERSITY_ANTENNA_2_ONLY)
430 printf("antenna 2 only");
431 else if (caps->an_tx_diversity == AN_DIVERSITY_ANTENNA_1_AND_2)
432 printf("antenna 1 and 2");
434 printf("\nSupported power levels:\t");
435 an_printwords(caps->an_tx_powerlevels, 8);
436 printf("\nHardware revision:\t");
437 tmp = ntohs(caps->an_hwrev);
438 an_printhex((char *)&tmp, 2);
439 printf("\nSoftware revision:\t");
440 tmp = ntohs(caps->an_fwrev);
441 an_printhex((char *)&tmp, 2);
442 printf("\nSoftware subrevision:\t");
443 tmp = ntohs(caps->an_fwsubrev);
444 an_printhex((char *)&tmp, 2);
445 printf("\nInterface revision:\t");
446 tmp = ntohs(caps->an_ifacerev);
447 an_printhex((char *)&tmp, 2);
448 printf("\nBootblock revision:\t");
449 tmp = ntohs(caps->an_bootblockrev);
450 an_printhex((char *)&tmp, 2);
455 static void an_dumpstats(iface)
458 struct an_ltv_stats *stats;
462 areq.an_len = sizeof(areq);
463 areq.an_type = AN_RID_32BITS_CUM;
465 an_getval(iface, &areq);
467 ptr = (caddr_t)&areq;
469 stats = (struct an_ltv_stats *)ptr;
471 printf("RX overruns:\t\t\t\t\t[ %d ]\n", stats->an_rx_overruns);
472 printf("RX PLCP CSUM errors:\t\t\t\t[ %d ]\n",
473 stats->an_rx_plcp_csum_errs);
474 printf("RX PLCP format errors:\t\t\t\t[ %d ]\n",
475 stats->an_rx_plcp_format_errs);
476 printf("RX PLCP length errors:\t\t\t\t[ %d ]\n",
477 stats->an_rx_plcp_len_errs);
478 printf("RX MAC CRC errors:\t\t\t\t[ %d ]\n",
479 stats->an_rx_mac_crc_errs);
480 printf("RX MAC CRC OK:\t\t\t\t\t[ %d ]\n",
481 stats->an_rx_mac_crc_ok);
482 printf("RX WEP errors:\t\t\t\t\t[ %d ]\n",
483 stats->an_rx_wep_errs);
484 printf("RX WEP OK:\t\t\t\t\t[ %d ]\n",
485 stats->an_rx_wep_ok);
486 printf("Long retries:\t\t\t\t\t[ %d ]\n",
487 stats->an_retry_long);
488 printf("Short retries:\t\t\t\t\t[ %d ]\n",
489 stats->an_retry_short);
490 printf("Retries exhausted:\t\t\t\t[ %d ]\n",
491 stats->an_retry_max);
492 printf("Bad ACK:\t\t\t\t\t[ %d ]\n",
494 printf("Bad CTS:\t\t\t\t\t[ %d ]\n",
496 printf("RX good ACKs:\t\t\t\t\t[ %d ]\n",
497 stats->an_rx_ack_ok);
498 printf("RX good CTSs:\t\t\t\t\t[ %d ]\n",
499 stats->an_rx_cts_ok);
500 printf("TX good ACKs:\t\t\t\t\t[ %d ]\n",
501 stats->an_tx_ack_ok);
502 printf("TX good RTSs:\t\t\t\t\t[ %d ]\n",
503 stats->an_tx_rts_ok);
504 printf("TX good CTSs:\t\t\t\t\t[ %d ]\n",
505 stats->an_tx_cts_ok);
506 printf("LMAC multicasts transmitted:\t\t\t[ %d ]\n",
507 stats->an_tx_lmac_mcasts);
508 printf("LMAC broadcasts transmitted:\t\t\t[ %d ]\n",
509 stats->an_tx_lmac_bcasts);
510 printf("LMAC unicast frags transmitted:\t\t\t[ %d ]\n",
511 stats->an_tx_lmac_ucast_frags);
512 printf("LMAC unicasts transmitted:\t\t\t[ %d ]\n",
513 stats->an_tx_lmac_ucasts);
514 printf("Beacons transmitted:\t\t\t\t[ %d ]\n",
515 stats->an_tx_beacons);
516 printf("Beacons received:\t\t\t\t[ %d ]\n",
517 stats->an_rx_beacons);
518 printf("Single transmit collisions:\t\t\t[ %d ]\n",
519 stats->an_tx_single_cols);
520 printf("Multiple transmit collisions:\t\t\t[ %d ]\n",
521 stats->an_tx_multi_cols);
522 printf("Transmits without deferrals:\t\t\t[ %d ]\n",
523 stats->an_tx_defers_no);
524 printf("Transmits deferred due to protocol:\t\t[ %d ]\n",
525 stats->an_tx_defers_prot);
526 printf("Transmits deferred due to energy detect:\t\t[ %d ]\n",
527 stats->an_tx_defers_energy);
528 printf("RX duplicate frames/frags:\t\t\t[ %d ]\n",
530 printf("RX partial frames:\t\t\t\t[ %d ]\n",
531 stats->an_rx_partial);
532 printf("TX max lifetime exceeded:\t\t\t[ %d ]\n",
533 stats->an_tx_too_old);
534 printf("RX max lifetime exceeded:\t\t\t[ %d ]\n",
535 stats->an_tx_too_old);
536 printf("Sync lost due to too many missed beacons:\t[ %d ]\n",
537 stats->an_lostsync_missed_beacons);
538 printf("Sync lost due to ARL exceeded:\t\t\t[ %d ]\n",
539 stats->an_lostsync_arl_exceeded);
540 printf("Sync lost due to deauthentication:\t\t[ %d ]\n",
541 stats->an_lostsync_deauthed);
542 printf("Sync lost due to disassociation:\t\t[ %d ]\n",
543 stats->an_lostsync_disassociated);
544 printf("Sync lost due to excess change in TSF timing:\t[ %d ]\n",
545 stats->an_lostsync_tsf_timing);
546 printf("Host transmitted multicasts:\t\t\t[ %d ]\n",
547 stats->an_tx_host_mcasts);
548 printf("Host transmitted broadcasts:\t\t\t[ %d ]\n",
549 stats->an_tx_host_bcasts);
550 printf("Host transmitted unicasts:\t\t\t[ %d ]\n",
551 stats->an_tx_host_ucasts);
552 printf("Host transmission failures:\t\t\t[ %d ]\n",
553 stats->an_tx_host_failed);
554 printf("Host received multicasts:\t\t\t[ %d ]\n",
555 stats->an_rx_host_mcasts);
556 printf("Host received broadcasts:\t\t\t[ %d ]\n",
557 stats->an_rx_host_bcasts);
558 printf("Host received unicasts:\t\t\t\t[ %d ]\n",
559 stats->an_rx_host_ucasts);
560 printf("Host receive discards:\t\t\t\t[ %d ]\n",
561 stats->an_rx_host_discarded);
562 printf("HMAC transmitted multicasts:\t\t\t[ %d ]\n",
563 stats->an_tx_hmac_mcasts);
564 printf("HMAC transmitted broadcasts:\t\t\t[ %d ]\n",
565 stats->an_tx_hmac_bcasts);
566 printf("HMAC transmitted unicasts:\t\t\t[ %d ]\n",
567 stats->an_tx_hmac_ucasts);
568 printf("HMAC transmissions failed:\t\t\t[ %d ]\n",
569 stats->an_tx_hmac_failed);
570 printf("HMAC received multicasts:\t\t\t[ %d ]\n",
571 stats->an_rx_hmac_mcasts);
572 printf("HMAC received broadcasts:\t\t\t[ %d ]\n",
573 stats->an_rx_hmac_bcasts);
574 printf("HMAC received unicasts:\t\t\t\t[ %d ]\n",
575 stats->an_rx_hmac_ucasts);
576 printf("HMAC receive discards:\t\t\t\t[ %d ]\n",
577 stats->an_rx_hmac_discarded);
578 printf("HMAC transmits accepted:\t\t\t[ %d ]\n",
579 stats->an_tx_hmac_accepted);
580 printf("SSID mismatches:\t\t\t\t[ %d ]\n",
581 stats->an_ssid_mismatches);
582 printf("Access point mismatches:\t\t\t[ %d ]\n",
583 stats->an_ap_mismatches);
584 printf("Speed mismatches:\t\t\t\t[ %d ]\n",
585 stats->an_rates_mismatches);
586 printf("Authentication rejects:\t\t\t\t[ %d ]\n",
587 stats->an_auth_rejects);
588 printf("Authentication timeouts:\t\t\t[ %d ]\n",
589 stats->an_auth_timeouts);
590 printf("Association rejects:\t\t\t\t[ %d ]\n",
591 stats->an_assoc_rejects);
592 printf("Association timeouts:\t\t\t\t[ %d ]\n",
593 stats->an_assoc_timeouts);
594 printf("Management frames received:\t\t\t[ %d ]\n",
595 stats->an_rx_mgmt_pkts);
596 printf("Management frames transmitted:\t\t\t[ %d ]\n",
597 stats->an_tx_mgmt_pkts);
598 printf("Refresh frames received:\t\t\t[ %d ]\n",
599 stats->an_rx_refresh_pkts),
600 printf("Refresh frames transmitted:\t\t\t[ %d ]\n",
601 stats->an_tx_refresh_pkts),
602 printf("Poll frames received:\t\t\t\t[ %d ]\n",
603 stats->an_rx_poll_pkts);
604 printf("Poll frames transmitted:\t\t\t[ %d ]\n",
605 stats->an_tx_poll_pkts);
606 printf("Host requested sync losses:\t\t\t[ %d ]\n",
607 stats->an_lostsync_hostreq);
608 printf("Host transmitted bytes:\t\t\t\t[ %d ]\n",
609 stats->an_host_tx_bytes);
610 printf("Host received bytes:\t\t\t\t[ %d ]\n",
611 stats->an_host_rx_bytes);
612 printf("Uptime in microseconds:\t\t\t\t[ %d ]\n",
613 stats->an_uptime_usecs);
614 printf("Uptime in seconds:\t\t\t\t[ %d ]\n",
615 stats->an_uptime_secs);
616 printf("Sync lost due to better AP:\t\t\t[ %d ]\n",
617 stats->an_lostsync_better_ap);
622 static void an_dumpap(iface)
625 struct an_ltv_aplist *ap;
628 areq.an_len = sizeof(areq);
629 areq.an_type = AN_RID_APLIST;
631 an_getval(iface, &areq);
633 ap = (struct an_ltv_aplist *)&areq;
634 printf("Access point 1:\t\t\t");
635 an_printhex((char *)&ap->an_ap1, ETHER_ADDR_LEN);
636 printf("\nAccess point 2:\t\t\t");
637 an_printhex((char *)&ap->an_ap2, ETHER_ADDR_LEN);
638 printf("\nAccess point 3:\t\t\t");
639 an_printhex((char *)&ap->an_ap3, ETHER_ADDR_LEN);
640 printf("\nAccess point 4:\t\t\t");
641 an_printhex((char *)&ap->an_ap4, ETHER_ADDR_LEN);
647 static void an_dumpssid(iface)
650 struct an_ltv_ssidlist *ssid;
653 areq.an_len = sizeof(areq);
654 areq.an_type = AN_RID_SSIDLIST;
656 an_getval(iface, &areq);
658 ssid = (struct an_ltv_ssidlist *)&areq;
659 printf("SSID 1:\t\t\t[ %.*s ]\n", ssid->an_ssid1_len, ssid->an_ssid1);
660 printf("SSID 2:\t\t\t[ %.*s ]\n", ssid->an_ssid2_len, ssid->an_ssid2);
661 printf("SSID 3:\t\t\t[ %.*s ]\n", ssid->an_ssid3_len, ssid->an_ssid3);
666 static void an_dumpconfig(iface)
669 struct an_ltv_genconfig *cfg;
671 unsigned char diversity;
673 areq.an_len = sizeof(areq);
674 areq.an_type = AN_RID_ACTUALCFG;
676 an_getval(iface, &areq);
678 cfg = (struct an_ltv_genconfig *)&areq;
680 printf("Operating mode:\t\t\t\t[ ");
681 if ((cfg->an_opmode & 0x7) == AN_OPMODE_IBSS_ADHOC)
683 if ((cfg->an_opmode & 0x7) == AN_OPMODE_INFRASTRUCTURE_STATION)
684 printf("infrastructure");
685 if ((cfg->an_opmode & 0x7) == AN_OPMODE_AP)
686 printf("access point");
687 if ((cfg->an_opmode & 0x7) == AN_OPMODE_AP_REPEATER)
688 printf("access point repeater");
690 printf("\nReceive mode:\t\t\t\t[ ");
691 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_BC_MC_ADDR)
692 printf("broadcast/multicast/unicast");
693 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_BC_ADDR)
694 printf("broadcast/unicast");
695 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_ADDR)
697 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_80211_MONITOR_CURBSS)
698 printf("802.11 monitor, current BSSID");
699 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_80211_MONITOR_ANYBSS)
700 printf("802.11 monitor, any BSSID");
701 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_LAN_MONITOR_CURBSS)
702 printf("LAN monitor, current BSSID");
704 printf("\nFragment threshold:\t\t\t");
705 an_printwords(&cfg->an_fragthresh, 1);
706 printf("\nRTS threshold:\t\t\t\t");
707 an_printwords(&cfg->an_rtsthresh, 1);
708 printf("\nMAC address:\t\t\t\t");
709 an_printhex((char *)&cfg->an_macaddr, ETHER_ADDR_LEN);
710 printf("\nSupported rates:\t\t\t");
711 an_printspeeds(cfg->an_rates, 8);
712 printf("\nShort retry limit:\t\t\t");
713 an_printwords(&cfg->an_shortretry_limit, 1);
714 printf("\nLong retry limit:\t\t\t");
715 an_printwords(&cfg->an_longretry_limit, 1);
716 printf("\nTX MSDU lifetime:\t\t\t");
717 an_printwords(&cfg->an_tx_msdu_lifetime, 1);
718 printf("\nRX MSDU lifetime:\t\t\t");
719 an_printwords(&cfg->an_rx_msdu_lifetime, 1);
720 printf("\nStationary:\t\t\t\t");
721 an_printbool(cfg->an_stationary);
722 printf("\nOrdering:\t\t\t\t");
723 an_printbool(cfg->an_ordering);
724 printf("\nDevice type:\t\t\t\t[ ");
725 if (cfg->an_devtype == AN_DEVTYPE_PC4500)
727 else if (cfg->an_devtype == AN_DEVTYPE_PC4800)
730 printf("unknown (%x)", cfg->an_devtype);
732 printf("\nScanning mode:\t\t\t\t[ ");
733 if (cfg->an_scanmode == AN_SCANMODE_ACTIVE)
735 if (cfg->an_scanmode == AN_SCANMODE_PASSIVE)
737 if (cfg->an_scanmode == AN_SCANMODE_AIRONET_ACTIVE)
738 printf("Aironet active");
740 printf("\nProbe delay:\t\t\t\t");
741 an_printwords(&cfg->an_probedelay, 1);
742 printf("\nProbe energy timeout:\t\t\t");
743 an_printwords(&cfg->an_probe_energy_timeout, 1);
744 printf("\nProbe response timeout:\t\t\t");
745 an_printwords(&cfg->an_probe_response_timeout, 1);
746 printf("\nBeacon listen timeout:\t\t\t");
747 an_printwords(&cfg->an_beacon_listen_timeout, 1);
748 printf("\nIBSS join network timeout:\t\t");
749 an_printwords(&cfg->an_ibss_join_net_timeout, 1);
750 printf("\nAuthentication timeout:\t\t\t");
751 an_printwords(&cfg->an_auth_timeout, 1);
752 printf("\nWEP enabled:\t\t\t\t[ ");
753 if (cfg->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE)
755 if (cfg->an_authtype & AN_AUTHTYPE_LEAP)
757 else if (cfg->an_authtype & AN_AUTHTYPE_ALLOW_UNENCRYPTED)
758 printf("mixed cell");
765 printf("\nAuthentication type:\t\t\t[ ");
766 if ((cfg->an_authtype & AN_AUTHTYPE_MASK) == AN_AUTHTYPE_NONE)
768 if ((cfg->an_authtype & AN_AUTHTYPE_MASK) == AN_AUTHTYPE_OPEN)
770 if ((cfg->an_authtype & AN_AUTHTYPE_MASK) == AN_AUTHTYPE_SHAREDKEY)
771 printf("shared key");
773 printf("\nAssociation timeout:\t\t\t");
774 an_printwords(&cfg->an_assoc_timeout, 1);
775 printf("\nSpecified AP association timeout:\t");
776 an_printwords(&cfg->an_specified_ap_timeout, 1);
777 printf("\nOffline scan interval:\t\t\t");
778 an_printwords(&cfg->an_offline_scan_interval, 1);
779 printf("\nOffline scan duration:\t\t\t");
780 an_printwords(&cfg->an_offline_scan_duration, 1);
781 printf("\nLink loss delay:\t\t\t");
782 an_printwords(&cfg->an_link_loss_delay, 1);
783 printf("\nMax beacon loss time:\t\t\t");
784 an_printwords(&cfg->an_max_beacon_lost_time, 1);
785 printf("\nRefresh interval:\t\t\t");
786 an_printwords(&cfg->an_refresh_interval, 1);
787 printf("\nPower save mode:\t\t\t[ ");
788 if (cfg->an_psave_mode == AN_PSAVE_NONE)
790 if (cfg->an_psave_mode == AN_PSAVE_CAM)
791 printf("constantly awake mode");
792 if (cfg->an_psave_mode == AN_PSAVE_PSP)
794 if (cfg->an_psave_mode == AN_PSAVE_PSP_CAM)
795 printf("PSP-CAM (fast PSP)");
797 printf("\nSleep through DTIMs:\t\t\t");
798 an_printbool(cfg->an_sleep_for_dtims);
799 printf("\nPower save listen interval:\t\t");
800 an_printwords(&cfg->an_listen_interval, 1);
801 printf("\nPower save fast listen interval:\t");
802 an_printwords(&cfg->an_fast_listen_interval, 1);
803 printf("\nPower save listen decay:\t\t");
804 an_printwords(&cfg->an_listen_decay, 1);
805 printf("\nPower save fast listen decay:\t\t");
806 an_printwords(&cfg->an_fast_listen_decay, 1);
807 printf("\nAP/ad-hoc Beacon period:\t\t");
808 an_printwords(&cfg->an_beacon_period, 1);
809 printf("\nAP/ad-hoc ATIM duration:\t\t");
810 an_printwords(&cfg->an_atim_duration, 1);
811 printf("\nAP/ad-hoc current channel:\t\t");
812 an_printwords(&cfg->an_ds_channel, 1);
813 printf("\nAP/ad-hoc DTIM period:\t\t\t");
814 an_printwords(&cfg->an_dtim_period, 1);
815 printf("\nRadio type:\t\t\t\t[ ");
816 if (cfg->an_radiotype & AN_RADIOTYPE_80211_FH)
818 else if (cfg->an_radiotype & AN_RADIOTYPE_80211_DS)
820 else if (cfg->an_radiotype & AN_RADIOTYPE_LM2000_DS)
823 printf("unknown (%x)", cfg->an_radiotype);
825 printf("\nRX Diversity:\t\t\t\t[ ");
826 diversity = cfg->an_diversity & 0xFF;
827 if (diversity == AN_DIVERSITY_FACTORY_DEFAULT)
828 printf("factory default");
829 else if (diversity == AN_DIVERSITY_ANTENNA_1_ONLY)
830 printf("antenna 1 only");
831 else if (diversity == AN_DIVERSITY_ANTENNA_2_ONLY)
832 printf("antenna 2 only");
833 else if (diversity == AN_DIVERSITY_ANTENNA_1_AND_2)
834 printf("antenna 1 and 2");
836 printf("\nTX Diversity:\t\t\t\t[ ");
837 diversity = (cfg->an_diversity >> 8) & 0xFF;
838 if (diversity == AN_DIVERSITY_FACTORY_DEFAULT)
839 printf("factory default");
840 else if (diversity == AN_DIVERSITY_ANTENNA_1_ONLY)
841 printf("antenna 1 only");
842 else if (diversity == AN_DIVERSITY_ANTENNA_2_ONLY)
843 printf("antenna 2 only");
844 else if (diversity == AN_DIVERSITY_ANTENNA_1_AND_2)
845 printf("antenna 1 and 2");
847 printf("\nTransmit power level:\t\t\t");
848 an_printwords(&cfg->an_tx_power, 1);
849 printf("\nRSS threshold:\t\t\t\t");
850 an_printwords(&cfg->an_rss_thresh, 1);
851 printf("\nNode name:\t\t\t\t");
852 an_printstr((char *)&cfg->an_nodename, 16);
853 printf("\nARL threshold:\t\t\t\t");
854 an_printwords(&cfg->an_arl_thresh, 1);
855 printf("\nARL decay:\t\t\t\t");
856 an_printwords(&cfg->an_arl_decay, 1);
857 printf("\nARL delay:\t\t\t\t");
858 an_printwords(&cfg->an_arl_delay, 1);
859 printf("\nConfiguration:\t\t\t\t[ ");
860 if (cfg->an_home_product & AN_HOME_NETWORK)
861 printf("Home Configuration");
863 printf("Enterprise Configuration");
868 an_readkeyinfo(iface);
873 static void an_dumprssimap(iface)
876 struct an_ltv_rssi_map *rssi;
880 areq.an_len = sizeof(areq);
881 areq.an_type = AN_RID_RSSI_MAP;
883 an_getval(iface, &areq);
885 rssi = (struct an_ltv_rssi_map *)&areq;
887 printf("idx\tpct\t dBm\n");
889 for (i = 0; i < 0xFF; i++) {
891 * negate the dBm value: it's the only way the power
894 printf("%3d\t%3d\t%4d\n", i,
895 rssi->an_entries[i].an_rss_pct,
896 - rssi->an_entries[i].an_rss_dbm);
905 fprintf(stderr, "usage: %s -i iface -A (show specified APs)\n", p);
906 fprintf(stderr, "\t%s -i iface -N (show specified SSIDss)\n", p);
907 fprintf(stderr, "\t%s -i iface -S (show NIC status)\n", p);
908 fprintf(stderr, "\t%s -i iface -I (show NIC capabilities)\n", p);
909 fprintf(stderr, "\t%s -i iface -T (show stats counters)\n", p);
910 fprintf(stderr, "\t%s -i iface -C (show current config)\n", p);
911 fprintf(stderr, "\t%s -i iface -R (show RSSI map)\n", p);
912 fprintf(stderr, "\t%s -i iface -t 0-4 (set TX speed)\n", p);
913 fprintf(stderr, "\t%s -i iface -s 0-3 (set power save mode)\n", p);
914 fprintf(stderr, "\t%s -i iface [-v 1-4] -a AP (specify AP)\n", p);
915 fprintf(stderr, "\t%s -i iface -b val (set beacon period)\n", p);
916 fprintf(stderr, "\t%s -i iface [-v 0|1] -d val (set diversity)\n", p);
917 fprintf(stderr, "\t%s -i iface -j val (set netjoin timeout)\n", p);
918 fprintf(stderr, "\t%s -i iface -e 0-4 (enable transmit key)\n", p);
919 fprintf(stderr, "\t%s -i iface [-v 0-8] -k key (set key)\n", p);
920 fprintf(stderr, "\t%s -i iface -K 0-2 (no auth/open/shared secret)\n", p);
921 fprintf(stderr, "\t%s -i iface -W 0-2 (no WEP/full WEP/mixed cell)\n", p);
922 fprintf(stderr, "\t%s -i iface -l val (set station name)\n", p);
923 fprintf(stderr, "\t%s -i iface -m val (set MAC address)\n", p);
924 fprintf(stderr, "\t%s -i iface [-v 1-3] -n SSID "
925 "(specify SSID)\n", p);
926 fprintf(stderr, "\t%s -i iface -o 0|1 (set operating mode)\n", p);
927 fprintf(stderr, "\t%s -i iface -c val (set ad-hoc channel)\n", p);
928 fprintf(stderr, "\t%s -i iface -f val (set frag threshold)\n", p);
929 fprintf(stderr, "\t%s -i iface -r val (set RTS threshold)\n", p);
930 fprintf(stderr, "\t%s -i iface -M 0-15 (set monitor mode)\n", p);
931 fprintf(stderr, "\t%s -i iface -L user (enter LEAP authentication mode)\n", p);
933 fprintf(stderr, "\t%s -i iface -Q print signal quality cache\n", p);
934 fprintf(stderr, "\t%s -i iface -Z zero out signal cache\n", p);
937 fprintf(stderr, "\t%s -h (display this message)\n", p);
943 static void an_setconfig(iface, act, arg)
948 struct an_ltv_genconfig *cfg;
949 struct an_ltv_caps *caps;
951 struct an_req areq_caps;
952 u_int16_t diversity = 0;
953 struct ether_addr *addr;
956 areq.an_len = sizeof(areq);
957 areq.an_type = AN_RID_GENCONFIG;
958 an_getval(iface, &areq);
959 cfg = (struct an_ltv_genconfig *)&areq;
961 areq_caps.an_len = sizeof(areq);
962 areq_caps.an_type = AN_RID_CAPABILITIES;
963 an_getval(iface, &areq_caps);
964 caps = (struct an_ltv_caps *)&areq_caps;
968 cfg->an_opmode = atoi(arg);
971 cfg->an_ds_channel = atoi(arg);
973 case ACT_SET_PWRSAVE:
974 cfg->an_psave_mode = atoi(arg);
976 case ACT_SET_SCANMODE:
977 cfg->an_scanmode = atoi(arg);
979 case ACT_SET_DIVERSITY_RX:
980 case ACT_SET_DIVERSITY_TX:
983 diversity = AN_DIVERSITY_FACTORY_DEFAULT;
986 diversity = AN_DIVERSITY_ANTENNA_1_ONLY;
989 diversity = AN_DIVERSITY_ANTENNA_2_ONLY;
992 diversity = AN_DIVERSITY_ANTENNA_1_AND_2;
995 errx(1, "bad diversity setting: %d", diversity);
998 if (act == ACT_SET_DIVERSITY_RX) {
999 cfg->an_diversity &= 0xFF00;
1000 cfg->an_diversity |= diversity;
1002 cfg->an_diversity &= 0x00FF;
1003 cfg->an_diversity |= (diversity << 8);
1007 for (i = 0; i < 8; i++) {
1008 if (caps->an_tx_powerlevels[i] == atoi(arg))
1012 errx(1, "unsupported power level: %dmW", atoi(arg));
1014 cfg->an_tx_power = atoi(arg);
1016 case ACT_SET_RTS_THRESH:
1017 cfg->an_rtsthresh = atoi(arg);
1019 case ACT_SET_RTS_RETRYLIM:
1020 cfg->an_shortretry_limit =
1021 cfg->an_longretry_limit = atoi(arg);
1023 case ACT_SET_BEACON_PERIOD:
1024 cfg->an_beacon_period = atoi(arg);
1026 case ACT_SET_WAKE_DURATION:
1027 cfg->an_atim_duration = atoi(arg);
1029 case ACT_SET_FRAG_THRESH:
1030 cfg->an_fragthresh = atoi(arg);
1032 case ACT_SET_NETJOIN:
1033 cfg->an_ibss_join_net_timeout = atoi(arg);
1035 case ACT_SET_MYNAME:
1036 bzero(cfg->an_nodename, 16);
1037 strncpy((char *)&cfg->an_nodename, optarg, 16);
1040 addr = ether_aton((char *)arg);
1043 errx(1, "badly formatted address");
1044 bzero(cfg->an_macaddr, ETHER_ADDR_LEN);
1045 bcopy((char *)addr, (char *)&cfg->an_macaddr, ETHER_ADDR_LEN);
1047 case ACT_ENABLE_WEP:
1048 switch (atoi (arg)) {
1051 cfg->an_authtype &= ~(AN_AUTHTYPE_PRIVACY_IN_USE
1052 | AN_AUTHTYPE_ALLOW_UNENCRYPTED
1053 | AN_AUTHTYPE_LEAP);
1057 cfg->an_authtype |= AN_AUTHTYPE_PRIVACY_IN_USE;
1058 cfg->an_authtype &= ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
1059 cfg->an_authtype &= ~AN_AUTHTYPE_LEAP;
1063 cfg->an_authtype = AN_AUTHTYPE_PRIVACY_IN_USE
1064 | AN_AUTHTYPE_ALLOW_UNENCRYPTED;
1068 case ACT_SET_KEY_TYPE:
1069 cfg->an_authtype = (cfg->an_authtype & ~AN_AUTHTYPE_MASK)
1072 case ACT_SET_MONITOR_MODE:
1073 areq.an_type = AN_RID_MONITOR_MODE;
1074 cfg->an_len = atoi(arg); /* mode is put in length */
1077 errx(1, "unknown action");
1081 an_setval(iface, &areq);
1085 static void an_setspeed(iface, act, arg)
1091 struct an_ltv_caps *caps;
1094 areq.an_len = sizeof(areq);
1095 areq.an_type = AN_RID_CAPABILITIES;
1097 an_getval(iface, &areq);
1098 caps = (struct an_ltv_caps *)&areq;
1105 speed = AN_RATE_1MBPS;
1108 speed = AN_RATE_2MBPS;
1111 if (caps->an_rates[2] != AN_RATE_5_5MBPS)
1112 errx(1, "5.5Mbps not supported on this card");
1113 speed = AN_RATE_5_5MBPS;
1116 if (caps->an_rates[3] != AN_RATE_11MBPS)
1117 errx(1, "11Mbps not supported on this card");
1118 speed = AN_RATE_11MBPS;
1121 errx(1, "unsupported speed");
1126 areq.an_type = AN_RID_TX_SPEED;
1127 areq.an_val[0] = speed;
1129 an_setval(iface, &areq);
1133 static void an_setap(iface, act, arg)
1138 struct an_ltv_aplist *ap;
1140 struct ether_addr *addr;
1142 areq.an_len = sizeof(areq);
1143 areq.an_type = AN_RID_APLIST;
1145 an_getval(iface, &areq);
1146 ap = (struct an_ltv_aplist *)&areq;
1148 addr = ether_aton((char *)arg);
1151 errx(1, "badly formatted address");
1155 bzero(ap->an_ap1, ETHER_ADDR_LEN);
1156 bcopy((char *)addr, (char *)&ap->an_ap1, ETHER_ADDR_LEN);
1159 bzero(ap->an_ap2, ETHER_ADDR_LEN);
1160 bcopy((char *)addr, (char *)&ap->an_ap2, ETHER_ADDR_LEN);
1163 bzero(ap->an_ap3, ETHER_ADDR_LEN);
1164 bcopy((char *)addr, (char *)&ap->an_ap3, ETHER_ADDR_LEN);
1167 bzero(ap->an_ap4, ETHER_ADDR_LEN);
1168 bcopy((char *)addr, (char *)&ap->an_ap4, ETHER_ADDR_LEN);
1171 errx(1, "unknown action");
1175 an_setval(iface, &areq);
1179 static void an_setssid(iface, act, arg)
1184 struct an_ltv_ssidlist *ssid;
1187 areq.an_len = sizeof(areq);
1188 areq.an_type = AN_RID_SSIDLIST;
1190 an_getval(iface, &areq);
1191 ssid = (struct an_ltv_ssidlist *)&areq;
1195 bzero(ssid->an_ssid1, sizeof(ssid->an_ssid1));
1196 strlcpy(ssid->an_ssid1, (char *)arg, sizeof(ssid->an_ssid1));
1197 ssid->an_ssid1_len = strlen(ssid->an_ssid1);
1200 bzero(ssid->an_ssid2, sizeof(ssid->an_ssid2));
1201 strlcpy(ssid->an_ssid2, (char *)arg, sizeof(ssid->an_ssid2));
1202 ssid->an_ssid2_len = strlen(ssid->an_ssid2);
1205 bzero(ssid->an_ssid3, sizeof(ssid->an_ssid3));
1206 strlcpy(ssid->an_ssid3, (char *)arg, sizeof(ssid->an_ssid3));
1207 ssid->an_ssid3_len = strlen(ssid->an_ssid3);
1210 errx(1, "unknown action");
1214 an_setval(iface, &areq);
1219 static void an_zerocache(iface)
1224 bzero((char *)&areq, sizeof(areq));
1226 areq.an_type = AN_RID_ZERO_CACHE;
1228 an_getval(iface, &areq);
1233 static void an_readcache(iface)
1238 struct an_sigcache *sc;
1243 errx(1, "must specify interface name");
1245 bzero((char *)&areq, sizeof(areq));
1246 areq.an_len = AN_MAX_DATALEN;
1247 areq.an_type = AN_RID_READ_CACHE;
1249 an_getval(iface, &areq);
1251 an_sigitems = (int *) &areq.an_val;
1252 pt = ((char *) &areq.an_val);
1254 sc = (struct an_sigcache *) pt;
1256 for (i = 0; i < *an_sigitems; i++) {
1257 printf("[%d/%d]:", i+1, *an_sigitems);
1258 printf(" %02x:%02x:%02x:%02x:%02x:%02x,",
1264 sc->macsrc[5]&0xff);
1265 printf(" %d.%d.%d.%d,",((sc->ipsrc >> 0) & 0xff),
1266 ((sc->ipsrc >> 8) & 0xff),
1267 ((sc->ipsrc >> 16) & 0xff),
1268 ((sc->ipsrc >> 24) & 0xff));
1269 printf(" sig: %d, noise: %d, qual: %d\n",
1280 static int an_hex2int(c)
1283 if (c >= '0' && c <= '9')
1285 if (c >= 'A' && c <= 'F')
1286 return (c - 'A' + 10);
1287 if (c >= 'a' && c <= 'f')
1288 return (c - 'a' + 10);
1293 static void an_str2key(s, k)
1295 struct an_ltv_key *k;
1300 /* Is this a hex string? */
1301 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) {
1302 /* Yes, convert to int. */
1304 p = (char *)&k->key[0];
1305 for (i = 2; s[i] != '\0' && s[i + 1] != '\0'; i+= 2) {
1306 *p++ = (an_hex2int(s[i]) << 4) + an_hex2int(s[i + 1]);
1310 errx(1, "hex strings must be of even length");
1313 /* No, just copy it in. */
1314 bcopy(s, k->key, strlen(s));
1315 k->klen = strlen(s);
1321 static void an_setkeys(iface, key, keytype)
1327 struct an_ltv_key *k;
1329 bzero((char *)&areq, sizeof(areq));
1330 k = (struct an_ltv_key *)&areq;
1332 if (strlen(key) > 28) {
1333 err(1, "encryption key must be no "
1334 "more than 18 characters long");
1339 k->kindex=keytype/2;
1341 if (!(k->klen==0 || k->klen==5 || k->klen==13)) {
1342 err(1, "encryption key must be 0, 5 or 13 bytes long");
1345 /* default mac and only valid one (from manual) 1.0.0.0.0.0 */
1353 switch(keytype & 1) {
1355 areq.an_len = sizeof(struct an_ltv_key);
1356 areq.an_type = AN_RID_WEP_PERM;
1357 an_setval(iface, &areq);
1360 areq.an_len = sizeof(struct an_ltv_key);
1361 areq.an_type = AN_RID_WEP_TEMP;
1362 an_setval(iface, &areq);
1369 static void an_readkeyinfo(iface)
1373 struct an_ltv_genconfig *cfg;
1374 struct an_ltv_key *k;
1378 areq.an_len = sizeof(areq);
1379 areq.an_type = AN_RID_ACTUALCFG;
1380 an_getval(iface, &areq);
1381 cfg = (struct an_ltv_genconfig *)&areq;
1382 if (cfg->an_home_product & AN_HOME_NETWORK)
1387 bzero((char *)&areq, sizeof(areq));
1388 k = (struct an_ltv_key *)&areq;
1390 printf("WEP Key status:\n");
1391 areq.an_type = AN_RID_WEP_TEMP; /* read first key */
1392 for(i=0; i<5; i++) {
1393 areq.an_len = sizeof(struct an_ltv_key);
1394 an_getval(iface, &areq);
1395 if (k->kindex == 0xffff)
1399 printf("\tKey %d is unset\n",k->kindex);
1402 printf("\tKey %d is set 40 bits\n",k->kindex);
1405 printf("\tKey %d is set 128 bits\n",k->kindex);
1408 printf("\tWEP Key %d has an unknown size %d\n",
1412 areq.an_type = AN_RID_WEP_PERM; /* read next key */
1415 areq.an_len = sizeof(struct an_ltv_key);
1416 an_getval(iface, &areq);
1417 printf("\tThe active transmit key is %d\n", 4 * home + k->mac[0]);
1422 static void an_enable_tx_key(iface, arg)
1427 struct an_ltv_key *k;
1428 struct an_ltv_genconfig *config;
1430 bzero((char *)&areq, sizeof(areq));
1432 /* set home or not home mode */
1433 areq.an_len = sizeof(struct an_ltv_genconfig);
1434 areq.an_type = AN_RID_GENCONFIG;
1435 an_getval(iface, &areq);
1436 config = (struct an_ltv_genconfig *)&areq;
1437 if (atoi(arg) == 4) {
1438 config->an_home_product |= AN_HOME_NETWORK;
1440 config->an_home_product &= ~AN_HOME_NETWORK;
1442 an_setval(iface, &areq);
1444 bzero((char *)&areq, sizeof(areq));
1446 k = (struct an_ltv_key *)&areq;
1448 /* From a Cisco engineer write the transmit key to use in the
1449 first MAC, index is FFFF*/
1453 k->mac[0]=atoi(arg);
1460 areq.an_len = sizeof(struct an_ltv_key);
1461 areq.an_type = AN_RID_WEP_PERM;
1462 an_setval(iface, &areq);
1467 static void an_enable_leap_mode(iface, username)
1472 struct an_ltv_status *sts;
1473 struct an_ltv_genconfig *cfg;
1474 struct an_ltv_caps *caps;
1475 struct an_ltv_leap_username an_username;
1476 struct an_ltv_leap_password an_password;
1481 char unicode_password[LEAP_PASSWORD_MAX * 2];
1483 areq.an_len = sizeof(areq);
1484 areq.an_type = AN_RID_CAPABILITIES;
1486 an_getval(iface, &areq);
1488 caps = (struct an_ltv_caps *)&areq;
1490 if (!caps->an_softcaps & AN_AUTHTYPE_LEAP) {
1491 fprintf(stderr, "Firmware does not support LEAP\n");
1495 bzero(&an_username, sizeof(an_username));
1496 bzero(&an_password, sizeof(an_password));
1498 len = strlen(username);
1499 if (len > LEAP_USERNAME_MAX) {
1500 printf("Username too long (max %d)\n", LEAP_USERNAME_MAX);
1503 strncpy(an_username.an_username, username, len);
1504 an_username.an_username_len = len;
1505 an_username.an_len = sizeof(an_username);
1506 an_username.an_type = AN_RID_LEAPUSERNAME;
1508 password = getpass("Enter LEAP password:");
1510 len = strlen(password);
1511 if (len > LEAP_PASSWORD_MAX) {
1512 printf("Password too long (max %d)\n", LEAP_PASSWORD_MAX);
1516 bzero(&unicode_password, sizeof(unicode_password));
1517 for(i = 0; i < len; i++) {
1518 unicode_password[i * 2] = *password++;
1523 MD4Update(&context, unicode_password, len * 2);
1524 MD4Final(&an_password.an_password[0], &context);
1528 MD4Update (&context, &an_password.an_password[0], 16);
1529 MD4Final (&an_password.an_password[16], &context);
1531 an_password.an_password_len = 32;
1532 an_password.an_len = sizeof(an_password);
1533 an_password.an_type = AN_RID_LEAPPASSWORD;
1535 an_setval(iface, (struct an_req *)&an_username);
1536 an_setval(iface, (struct an_req *)&an_password);
1538 areq.an_len = sizeof(areq);
1539 areq.an_type = AN_RID_GENCONFIG;
1540 an_getval(iface, &areq);
1541 cfg = (struct an_ltv_genconfig *)&areq;
1542 cfg->an_authtype = (AN_AUTHTYPE_PRIVACY_IN_USE | AN_AUTHTYPE_LEAP);
1543 an_setval(iface, &areq);
1545 sts = (struct an_ltv_status *)&areq;
1546 areq.an_type = AN_RID_STATUS;
1548 for (i = 60; i > 0; i--) {
1549 an_getval(iface, &areq);
1550 if (sts->an_opmode & AN_STATUS_OPMODE_LEAP) {
1551 printf("Authenticated\n");
1558 fprintf(stderr, "Failed LEAP authentication\n");
1563 int main(argc, argv)
1569 const char *iface = NULL;
1575 /* Get the interface name */
1577 ch = getopt(argc, argv, "i:");
1581 if (argc > 1 && *argv[1] != '-') {
1592 while ((ch = getopt(argc, argv,
1593 "ANISCTRht:a:e:o:s:n:v:d:j:b:c:r:p:w:m:l:k:K:W:QZM:L:")) != -1) {
1597 act = ACT_ZEROCACHE;
1599 errx(1, "ANCACHE not available");
1604 act = ACT_DUMPCACHE;
1606 errx(1, "ANCACHE not available");
1616 act = ACT_DUMPSTATUS;
1622 act = ACT_DUMPSTATS;
1625 act = ACT_DUMPCONFIG;
1628 act = ACT_DUMPRSSIMAP;
1631 act = ACT_SET_TXRATE;
1635 act = ACT_SET_PWRSAVE;
1639 act = ACT_SET_TXPWR;
1643 modifier = atoi(optarg);
1661 errx(1, "bad modifier %d: there "
1662 "are only 4 access point settings",
1670 act = ACT_SET_BEACON_PERIOD;
1676 act = ACT_SET_DIVERSITY_RX;
1679 act = ACT_SET_DIVERSITY_TX;
1682 errx(1, "must specify RX or TX diversity");
1685 if (!isdigit(*optarg)) {
1686 errx(1, "%s is not numeric", optarg);
1692 act = ACT_SET_NETJOIN;
1696 act = ACT_SET_MYNAME;
1707 act = ACT_SET_SSID1;
1710 act = ACT_SET_SSID2;
1713 act = ACT_SET_SSID3;
1716 errx(1, "bad modifier %d: there"
1717 "are only 3 SSID settings", modifier);
1724 act = ACT_SET_OPMODE;
1732 act = ACT_SET_FRAG_THRESH;
1736 act = ACT_ENABLE_WEP;
1740 act = ACT_SET_KEY_TYPE;
1748 act = ACT_ENABLE_TX_KEY;
1752 act = ACT_SET_RTS_RETRYLIM;
1756 act = ACT_SET_RTS_THRESH;
1760 act = ACT_SET_WAKE_DURATION;
1764 act = ACT_SET_MONITOR_MODE;
1768 act = ACT_SET_LEAP_MODE;
1777 if (iface == NULL || (!act && !key))
1781 case ACT_DUMPSTATUS:
1782 an_dumpstatus(iface);
1788 an_dumpstats(iface);
1790 case ACT_DUMPCONFIG:
1791 an_dumpconfig(iface);
1799 case ACT_DUMPRSSIMAP:
1800 an_dumprssimap(iface);
1805 an_setssid(iface, act, arg);
1811 an_setap(iface, act, arg);
1813 case ACT_SET_TXRATE:
1814 an_setspeed(iface, act, arg);
1818 an_zerocache(iface);
1821 an_readcache(iface);
1826 an_setkeys(iface, key, modifier);
1828 case ACT_ENABLE_TX_KEY:
1829 an_enable_tx_key(iface, arg);
1831 case ACT_SET_LEAP_MODE:
1832 an_enable_leap_mode(iface, arg);
1835 an_setconfig(iface, act, arg);