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.6 2005/12/05 01:04:00 swildner 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 (const char *, struct an_req *);
63 static void an_setval (const char *, struct an_req *);
64 static void an_printwords(u_int16_t *, int);
65 static void an_printspeeds(u_int8_t*, int);
66 static void an_printbool(int);
67 static void an_printhex (char *, int);
68 static void an_printstr (char *, int);
69 static void an_dumpstatus(const char *);
70 static void an_dumpstats(const char *);
71 static void an_dumpconfig(const char *);
72 static void an_dumpcaps (const char *);
73 static void an_dumpssid (const char *);
74 static void an_dumpap (const char *);
75 static void an_setconfig(const char *, int, void *);
76 static void an_setssid (const char *, int, void *);
77 static void an_setap (const char *, int, void *);
78 static void an_setspeed (const char *, int, void *);
79 static void an_readkeyinfo(const char *);
81 static void an_zerocache(const char *);
82 static void an_readcache(const char *);
84 static int an_hex2int (char);
85 static void an_str2key (char *, struct an_ltv_key *);
86 static void an_setkeys (const char *, char *, int);
87 static void an_enable_tx_key(const char *, char *);
88 static void an_enable_leap_mode(const char *, char *);
89 static void usage (char *);
90 static void an_dumprssimap(const char *);
91 int main (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
138 an_getval(const char *iface, struct an_req *areq)
143 bzero((char *)&ifr, sizeof(ifr));
145 strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
146 ifr.ifr_data = (caddr_t)areq;
148 s = socket(AF_INET, SOCK_DGRAM, 0);
153 if (ioctl(s, SIOCGAIRONET, &ifr) == -1) {
155 err(1, "SIOCGAIRONET");
164 an_setval(const char *iface, struct an_req *areq)
169 bzero((char *)&ifr, sizeof(ifr));
171 strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
172 ifr.ifr_data = (caddr_t)areq;
174 s = socket(AF_INET, SOCK_DGRAM, 0);
179 if (ioctl(s, SIOCSAIRONET, &ifr) == -1)
180 err(1, "SIOCSAIRONET");
188 an_printstr(char *str, int len)
192 for (i = 0; i < len - 1; i++) {
197 printf("[ %.*s ]", len, str);
203 an_printwords(u_int16_t *w, int len)
208 for (i = 0; i < len; i++)
216 an_printspeeds(u_int8_t *w, int len)
221 for (i = 0; i < len && w[i]; i++)
222 printf("%2.1fMbps ", w[i] * 0.500);
229 an_printbool(int val)
240 an_printhex(char *ptr, int len)
245 for (i = 0; i < len; i++) {
246 printf("%02x", ptr[i] & 0xFF);
256 an_dumpstatus(const char *iface)
258 struct an_ltv_status *sts;
260 struct an_ltv_rssi_map an_rssimap;
261 int rssimap_valid = 0;
264 * Try to get RSSI to percent and dBM table
267 an_rssimap.an_len = sizeof(an_rssimap);
268 an_rssimap.an_type = AN_RID_RSSI_MAP;
269 rssimap_valid = an_getval(iface, (struct an_req*)&an_rssimap);
272 printf("RSSI table:\t\t[ present ]\n");
274 printf("RSSI table:\t\t[ not available ]\n");
276 areq.an_len = sizeof(areq);
277 areq.an_type = AN_RID_STATUS;
279 an_getval(iface, &areq);
281 sts = (struct an_ltv_status *)&areq;
283 printf("MAC address:\t\t");
284 an_printhex((char *)&sts->an_macaddr, ETHER_ADDR_LEN);
285 printf("\nOperating mode:\t\t[ ");
286 if (sts->an_opmode & AN_STATUS_OPMODE_CONFIGURED)
287 printf("configured ");
288 if (sts->an_opmode & AN_STATUS_OPMODE_MAC_ENABLED)
290 if (sts->an_opmode & AN_STATUS_OPMODE_RX_ENABLED)
292 if (sts->an_opmode & AN_STATUS_OPMODE_IN_SYNC)
294 if (sts->an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
295 printf("associated ");
296 if (sts->an_opmode & AN_STATUS_OPMODE_LEAP)
298 if (sts->an_opmode & AN_STATUS_OPMODE_ERROR)
301 printf("Error code:\t\t");
302 an_printhex((char *)&sts->an_errcode, 1);
304 printf("\nSignal strength:\t[ %d%% ]",
305 an_rssimap.an_entries[
306 sts->an_normalized_strength].an_rss_pct);
308 printf("\nSignal strength:\t[ %d%% ]",
309 sts->an_normalized_strength);
310 printf("\nAverage Noise:\t\t[ %d%% ]",sts->an_avg_noise_prev_min_pc);
312 printf("\nSignal quality:\t\t[ %d%% ]",
313 an_rssimap.an_entries[
314 sts->an_cur_signal_quality].an_rss_pct);
316 printf("\nSignal quality:\t\t[ %d ]",
317 sts->an_cur_signal_quality);
318 printf("\nMax Noise:\t\t[ %d%% ]",sts->an_max_noise_prev_min_pc);
320 * XXX: This uses the old definition of the rate field (units of
321 * 500kbps). Technically the new definition is that this field
322 * contains arbitrary values, but no devices which need this
323 * support exist and the IEEE seems to intend to use the old
324 * definition until they get something big so we'll keep using
325 * it as well because this will work with new cards with
328 printf("\nCurrent TX rate:\t[ %d%s ]", sts->an_current_tx_rate / 2,
329 (sts->an_current_tx_rate % 2) ? ".5" : "");
330 printf("\nCurrent SSID:\t\t");
331 an_printstr((char *)&sts->an_ssid, sts->an_ssidlen);
332 printf("\nCurrent AP name:\t");
333 an_printstr((char *)&sts->an_ap_name, 16);
334 printf("\nCurrent BSSID:\t\t");
335 an_printhex((char *)&sts->an_cur_bssid, ETHER_ADDR_LEN);
336 printf("\nBeacon period:\t\t");
337 an_printwords(&sts->an_beacon_period, 1);
338 printf("\nDTIM period:\t\t");
339 an_printwords(&sts->an_dtim_period, 1);
340 printf("\nATIM duration:\t\t");
341 an_printwords(&sts->an_atim_duration, 1);
342 printf("\nHOP period:\t\t");
343 an_printwords(&sts->an_hop_period, 1);
344 printf("\nChannel set:\t\t");
345 an_printwords(&sts->an_channel_set, 1);
346 printf("\nCurrent channel:\t");
347 an_printwords(&sts->an_cur_channel, 1);
348 printf("\nHops to backbone:\t");
349 an_printwords(&sts->an_hops_to_backbone, 1);
350 printf("\nTotal AP load:\t\t");
351 an_printwords(&sts->an_ap_total_load, 1);
352 printf("\nOur generated load:\t");
353 an_printwords(&sts->an_our_generated_load, 1);
354 printf("\nAccumulated ARL:\t");
355 an_printwords(&sts->an_accumulated_arl, 1);
361 an_dumpcaps(const char *iface)
363 struct an_ltv_caps *caps;
367 areq.an_len = sizeof(areq);
368 areq.an_type = AN_RID_CAPABILITIES;
370 an_getval(iface, &areq);
372 caps = (struct an_ltv_caps *)&areq;
374 printf("OUI:\t\t\t");
375 an_printhex((char *)&caps->an_oui, 3);
376 printf("\nProduct number:\t\t");
377 an_printwords(&caps->an_prodnum, 1);
378 printf("\nManufacturer name:\t");
379 an_printstr((char *)&caps->an_manufname, 32);
380 printf("\nProduce name:\t\t");
381 an_printstr((char *)&caps->an_prodname, 16);
382 printf("\nFirmware version:\t");
383 an_printstr((char *)&caps->an_prodvers, 1);
384 printf("\nOEM MAC address:\t");
385 an_printhex((char *)&caps->an_oemaddr, ETHER_ADDR_LEN);
386 printf("\nAironet MAC address:\t");
387 an_printhex((char *)&caps->an_aironetaddr, ETHER_ADDR_LEN);
388 printf("\nRadio type:\t\t[ ");
389 if (caps->an_radiotype & AN_RADIOTYPE_80211_FH)
391 else if (caps->an_radiotype & AN_RADIOTYPE_80211_DS)
393 else if (caps->an_radiotype & AN_RADIOTYPE_LM2000_DS)
396 printf("unknown (%x)", caps->an_radiotype);
398 printf("\nRegulatory domain:\t");
399 an_printwords(&caps->an_regdomain, 1);
400 printf("\nAssigned CallID:\t");
401 an_printhex((char *)&caps->an_callid, 6);
402 printf("\nSupported speeds:\t");
403 an_printspeeds(caps->an_rates, 8);
404 printf("\nRX Diversity:\t\t[ ");
405 if (caps->an_rx_diversity == AN_DIVERSITY_FACTORY_DEFAULT)
406 printf("factory default");
407 else if (caps->an_rx_diversity == AN_DIVERSITY_ANTENNA_1_ONLY)
408 printf("antenna 1 only");
409 else if (caps->an_rx_diversity == AN_DIVERSITY_ANTENNA_2_ONLY)
410 printf("antenna 2 only");
411 else if (caps->an_rx_diversity == AN_DIVERSITY_ANTENNA_1_AND_2)
412 printf("antenna 1 and 2");
414 printf("\nTX Diversity:\t\t[ ");
415 if (caps->an_tx_diversity == AN_DIVERSITY_FACTORY_DEFAULT)
416 printf("factory default");
417 else if (caps->an_tx_diversity == AN_DIVERSITY_ANTENNA_1_ONLY)
418 printf("antenna 1 only");
419 else if (caps->an_tx_diversity == AN_DIVERSITY_ANTENNA_2_ONLY)
420 printf("antenna 2 only");
421 else if (caps->an_tx_diversity == AN_DIVERSITY_ANTENNA_1_AND_2)
422 printf("antenna 1 and 2");
424 printf("\nSupported power levels:\t");
425 an_printwords(caps->an_tx_powerlevels, 8);
426 printf("\nHardware revision:\t");
427 tmp = ntohs(caps->an_hwrev);
428 an_printhex((char *)&tmp, 2);
429 printf("\nSoftware revision:\t");
430 tmp = ntohs(caps->an_fwrev);
431 an_printhex((char *)&tmp, 2);
432 printf("\nSoftware subrevision:\t");
433 tmp = ntohs(caps->an_fwsubrev);
434 an_printhex((char *)&tmp, 2);
435 printf("\nInterface revision:\t");
436 tmp = ntohs(caps->an_ifacerev);
437 an_printhex((char *)&tmp, 2);
438 printf("\nBootblock revision:\t");
439 tmp = ntohs(caps->an_bootblockrev);
440 an_printhex((char *)&tmp, 2);
446 an_dumpstats(const char *iface)
448 struct an_ltv_stats *stats;
452 areq.an_len = sizeof(areq);
453 areq.an_type = AN_RID_32BITS_CUM;
455 an_getval(iface, &areq);
457 ptr = (caddr_t)&areq;
459 stats = (struct an_ltv_stats *)ptr;
461 printf("RX overruns:\t\t\t\t\t[ %d ]\n", stats->an_rx_overruns);
462 printf("RX PLCP CSUM errors:\t\t\t\t[ %d ]\n",
463 stats->an_rx_plcp_csum_errs);
464 printf("RX PLCP format errors:\t\t\t\t[ %d ]\n",
465 stats->an_rx_plcp_format_errs);
466 printf("RX PLCP length errors:\t\t\t\t[ %d ]\n",
467 stats->an_rx_plcp_len_errs);
468 printf("RX MAC CRC errors:\t\t\t\t[ %d ]\n",
469 stats->an_rx_mac_crc_errs);
470 printf("RX MAC CRC OK:\t\t\t\t\t[ %d ]\n",
471 stats->an_rx_mac_crc_ok);
472 printf("RX WEP errors:\t\t\t\t\t[ %d ]\n",
473 stats->an_rx_wep_errs);
474 printf("RX WEP OK:\t\t\t\t\t[ %d ]\n",
475 stats->an_rx_wep_ok);
476 printf("Long retries:\t\t\t\t\t[ %d ]\n",
477 stats->an_retry_long);
478 printf("Short retries:\t\t\t\t\t[ %d ]\n",
479 stats->an_retry_short);
480 printf("Retries exhausted:\t\t\t\t[ %d ]\n",
481 stats->an_retry_max);
482 printf("Bad ACK:\t\t\t\t\t[ %d ]\n",
484 printf("Bad CTS:\t\t\t\t\t[ %d ]\n",
486 printf("RX good ACKs:\t\t\t\t\t[ %d ]\n",
487 stats->an_rx_ack_ok);
488 printf("RX good CTSs:\t\t\t\t\t[ %d ]\n",
489 stats->an_rx_cts_ok);
490 printf("TX good ACKs:\t\t\t\t\t[ %d ]\n",
491 stats->an_tx_ack_ok);
492 printf("TX good RTSs:\t\t\t\t\t[ %d ]\n",
493 stats->an_tx_rts_ok);
494 printf("TX good CTSs:\t\t\t\t\t[ %d ]\n",
495 stats->an_tx_cts_ok);
496 printf("LMAC multicasts transmitted:\t\t\t[ %d ]\n",
497 stats->an_tx_lmac_mcasts);
498 printf("LMAC broadcasts transmitted:\t\t\t[ %d ]\n",
499 stats->an_tx_lmac_bcasts);
500 printf("LMAC unicast frags transmitted:\t\t\t[ %d ]\n",
501 stats->an_tx_lmac_ucast_frags);
502 printf("LMAC unicasts transmitted:\t\t\t[ %d ]\n",
503 stats->an_tx_lmac_ucasts);
504 printf("Beacons transmitted:\t\t\t\t[ %d ]\n",
505 stats->an_tx_beacons);
506 printf("Beacons received:\t\t\t\t[ %d ]\n",
507 stats->an_rx_beacons);
508 printf("Single transmit collisions:\t\t\t[ %d ]\n",
509 stats->an_tx_single_cols);
510 printf("Multiple transmit collisions:\t\t\t[ %d ]\n",
511 stats->an_tx_multi_cols);
512 printf("Transmits without deferrals:\t\t\t[ %d ]\n",
513 stats->an_tx_defers_no);
514 printf("Transmits deferred due to protocol:\t\t[ %d ]\n",
515 stats->an_tx_defers_prot);
516 printf("Transmits deferred due to energy detect:\t\t[ %d ]\n",
517 stats->an_tx_defers_energy);
518 printf("RX duplicate frames/frags:\t\t\t[ %d ]\n",
520 printf("RX partial frames:\t\t\t\t[ %d ]\n",
521 stats->an_rx_partial);
522 printf("TX max lifetime exceeded:\t\t\t[ %d ]\n",
523 stats->an_tx_too_old);
524 printf("RX max lifetime exceeded:\t\t\t[ %d ]\n",
525 stats->an_tx_too_old);
526 printf("Sync lost due to too many missed beacons:\t[ %d ]\n",
527 stats->an_lostsync_missed_beacons);
528 printf("Sync lost due to ARL exceeded:\t\t\t[ %d ]\n",
529 stats->an_lostsync_arl_exceeded);
530 printf("Sync lost due to deauthentication:\t\t[ %d ]\n",
531 stats->an_lostsync_deauthed);
532 printf("Sync lost due to disassociation:\t\t[ %d ]\n",
533 stats->an_lostsync_disassociated);
534 printf("Sync lost due to excess change in TSF timing:\t[ %d ]\n",
535 stats->an_lostsync_tsf_timing);
536 printf("Host transmitted multicasts:\t\t\t[ %d ]\n",
537 stats->an_tx_host_mcasts);
538 printf("Host transmitted broadcasts:\t\t\t[ %d ]\n",
539 stats->an_tx_host_bcasts);
540 printf("Host transmitted unicasts:\t\t\t[ %d ]\n",
541 stats->an_tx_host_ucasts);
542 printf("Host transmission failures:\t\t\t[ %d ]\n",
543 stats->an_tx_host_failed);
544 printf("Host received multicasts:\t\t\t[ %d ]\n",
545 stats->an_rx_host_mcasts);
546 printf("Host received broadcasts:\t\t\t[ %d ]\n",
547 stats->an_rx_host_bcasts);
548 printf("Host received unicasts:\t\t\t\t[ %d ]\n",
549 stats->an_rx_host_ucasts);
550 printf("Host receive discards:\t\t\t\t[ %d ]\n",
551 stats->an_rx_host_discarded);
552 printf("HMAC transmitted multicasts:\t\t\t[ %d ]\n",
553 stats->an_tx_hmac_mcasts);
554 printf("HMAC transmitted broadcasts:\t\t\t[ %d ]\n",
555 stats->an_tx_hmac_bcasts);
556 printf("HMAC transmitted unicasts:\t\t\t[ %d ]\n",
557 stats->an_tx_hmac_ucasts);
558 printf("HMAC transmissions failed:\t\t\t[ %d ]\n",
559 stats->an_tx_hmac_failed);
560 printf("HMAC received multicasts:\t\t\t[ %d ]\n",
561 stats->an_rx_hmac_mcasts);
562 printf("HMAC received broadcasts:\t\t\t[ %d ]\n",
563 stats->an_rx_hmac_bcasts);
564 printf("HMAC received unicasts:\t\t\t\t[ %d ]\n",
565 stats->an_rx_hmac_ucasts);
566 printf("HMAC receive discards:\t\t\t\t[ %d ]\n",
567 stats->an_rx_hmac_discarded);
568 printf("HMAC transmits accepted:\t\t\t[ %d ]\n",
569 stats->an_tx_hmac_accepted);
570 printf("SSID mismatches:\t\t\t\t[ %d ]\n",
571 stats->an_ssid_mismatches);
572 printf("Access point mismatches:\t\t\t[ %d ]\n",
573 stats->an_ap_mismatches);
574 printf("Speed mismatches:\t\t\t\t[ %d ]\n",
575 stats->an_rates_mismatches);
576 printf("Authentication rejects:\t\t\t\t[ %d ]\n",
577 stats->an_auth_rejects);
578 printf("Authentication timeouts:\t\t\t[ %d ]\n",
579 stats->an_auth_timeouts);
580 printf("Association rejects:\t\t\t\t[ %d ]\n",
581 stats->an_assoc_rejects);
582 printf("Association timeouts:\t\t\t\t[ %d ]\n",
583 stats->an_assoc_timeouts);
584 printf("Management frames received:\t\t\t[ %d ]\n",
585 stats->an_rx_mgmt_pkts);
586 printf("Management frames transmitted:\t\t\t[ %d ]\n",
587 stats->an_tx_mgmt_pkts);
588 printf("Refresh frames received:\t\t\t[ %d ]\n",
589 stats->an_rx_refresh_pkts),
590 printf("Refresh frames transmitted:\t\t\t[ %d ]\n",
591 stats->an_tx_refresh_pkts),
592 printf("Poll frames received:\t\t\t\t[ %d ]\n",
593 stats->an_rx_poll_pkts);
594 printf("Poll frames transmitted:\t\t\t[ %d ]\n",
595 stats->an_tx_poll_pkts);
596 printf("Host requested sync losses:\t\t\t[ %d ]\n",
597 stats->an_lostsync_hostreq);
598 printf("Host transmitted bytes:\t\t\t\t[ %d ]\n",
599 stats->an_host_tx_bytes);
600 printf("Host received bytes:\t\t\t\t[ %d ]\n",
601 stats->an_host_rx_bytes);
602 printf("Uptime in microseconds:\t\t\t\t[ %d ]\n",
603 stats->an_uptime_usecs);
604 printf("Uptime in seconds:\t\t\t\t[ %d ]\n",
605 stats->an_uptime_secs);
606 printf("Sync lost due to better AP:\t\t\t[ %d ]\n",
607 stats->an_lostsync_better_ap);
613 an_dumpap(const char *iface)
615 struct an_ltv_aplist *ap;
618 areq.an_len = sizeof(areq);
619 areq.an_type = AN_RID_APLIST;
621 an_getval(iface, &areq);
623 ap = (struct an_ltv_aplist *)&areq;
624 printf("Access point 1:\t\t\t");
625 an_printhex((char *)&ap->an_ap1, ETHER_ADDR_LEN);
626 printf("\nAccess point 2:\t\t\t");
627 an_printhex((char *)&ap->an_ap2, ETHER_ADDR_LEN);
628 printf("\nAccess point 3:\t\t\t");
629 an_printhex((char *)&ap->an_ap3, ETHER_ADDR_LEN);
630 printf("\nAccess point 4:\t\t\t");
631 an_printhex((char *)&ap->an_ap4, ETHER_ADDR_LEN);
638 an_dumpssid(const char *iface)
640 struct an_ltv_ssidlist *ssid;
643 areq.an_len = sizeof(areq);
644 areq.an_type = AN_RID_SSIDLIST;
646 an_getval(iface, &areq);
648 ssid = (struct an_ltv_ssidlist *)&areq;
649 printf("SSID 1:\t\t\t[ %.*s ]\n", ssid->an_ssid1_len, ssid->an_ssid1);
650 printf("SSID 2:\t\t\t[ %.*s ]\n", ssid->an_ssid2_len, ssid->an_ssid2);
651 printf("SSID 3:\t\t\t[ %.*s ]\n", ssid->an_ssid3_len, ssid->an_ssid3);
657 an_dumpconfig(const char *iface)
659 struct an_ltv_genconfig *cfg;
661 unsigned char diversity;
663 areq.an_len = sizeof(areq);
664 areq.an_type = AN_RID_ACTUALCFG;
666 an_getval(iface, &areq);
668 cfg = (struct an_ltv_genconfig *)&areq;
670 printf("Operating mode:\t\t\t\t[ ");
671 if ((cfg->an_opmode & 0x7) == AN_OPMODE_IBSS_ADHOC)
673 if ((cfg->an_opmode & 0x7) == AN_OPMODE_INFRASTRUCTURE_STATION)
674 printf("infrastructure");
675 if ((cfg->an_opmode & 0x7) == AN_OPMODE_AP)
676 printf("access point");
677 if ((cfg->an_opmode & 0x7) == AN_OPMODE_AP_REPEATER)
678 printf("access point repeater");
680 printf("\nReceive mode:\t\t\t\t[ ");
681 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_BC_MC_ADDR)
682 printf("broadcast/multicast/unicast");
683 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_BC_ADDR)
684 printf("broadcast/unicast");
685 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_ADDR)
687 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_80211_MONITOR_CURBSS)
688 printf("802.11 monitor, current BSSID");
689 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_80211_MONITOR_ANYBSS)
690 printf("802.11 monitor, any BSSID");
691 if ((cfg->an_rxmode & 0x7) == AN_RXMODE_LAN_MONITOR_CURBSS)
692 printf("LAN monitor, current BSSID");
694 printf("\nFragment threshold:\t\t\t");
695 an_printwords(&cfg->an_fragthresh, 1);
696 printf("\nRTS threshold:\t\t\t\t");
697 an_printwords(&cfg->an_rtsthresh, 1);
698 printf("\nMAC address:\t\t\t\t");
699 an_printhex((char *)&cfg->an_macaddr, ETHER_ADDR_LEN);
700 printf("\nSupported rates:\t\t\t");
701 an_printspeeds(cfg->an_rates, 8);
702 printf("\nShort retry limit:\t\t\t");
703 an_printwords(&cfg->an_shortretry_limit, 1);
704 printf("\nLong retry limit:\t\t\t");
705 an_printwords(&cfg->an_longretry_limit, 1);
706 printf("\nTX MSDU lifetime:\t\t\t");
707 an_printwords(&cfg->an_tx_msdu_lifetime, 1);
708 printf("\nRX MSDU lifetime:\t\t\t");
709 an_printwords(&cfg->an_rx_msdu_lifetime, 1);
710 printf("\nStationary:\t\t\t\t");
711 an_printbool(cfg->an_stationary);
712 printf("\nOrdering:\t\t\t\t");
713 an_printbool(cfg->an_ordering);
714 printf("\nDevice type:\t\t\t\t[ ");
715 if (cfg->an_devtype == AN_DEVTYPE_PC4500)
717 else if (cfg->an_devtype == AN_DEVTYPE_PC4800)
720 printf("unknown (%x)", cfg->an_devtype);
722 printf("\nScanning mode:\t\t\t\t[ ");
723 if (cfg->an_scanmode == AN_SCANMODE_ACTIVE)
725 if (cfg->an_scanmode == AN_SCANMODE_PASSIVE)
727 if (cfg->an_scanmode == AN_SCANMODE_AIRONET_ACTIVE)
728 printf("Aironet active");
730 printf("\nProbe delay:\t\t\t\t");
731 an_printwords(&cfg->an_probedelay, 1);
732 printf("\nProbe energy timeout:\t\t\t");
733 an_printwords(&cfg->an_probe_energy_timeout, 1);
734 printf("\nProbe response timeout:\t\t\t");
735 an_printwords(&cfg->an_probe_response_timeout, 1);
736 printf("\nBeacon listen timeout:\t\t\t");
737 an_printwords(&cfg->an_beacon_listen_timeout, 1);
738 printf("\nIBSS join network timeout:\t\t");
739 an_printwords(&cfg->an_ibss_join_net_timeout, 1);
740 printf("\nAuthentication timeout:\t\t\t");
741 an_printwords(&cfg->an_auth_timeout, 1);
742 printf("\nWEP enabled:\t\t\t\t[ ");
743 if (cfg->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE)
745 if (cfg->an_authtype & AN_AUTHTYPE_LEAP)
747 else if (cfg->an_authtype & AN_AUTHTYPE_ALLOW_UNENCRYPTED)
748 printf("mixed cell");
755 printf("\nAuthentication type:\t\t\t[ ");
756 if ((cfg->an_authtype & AN_AUTHTYPE_MASK) == AN_AUTHTYPE_NONE)
758 if ((cfg->an_authtype & AN_AUTHTYPE_MASK) == AN_AUTHTYPE_OPEN)
760 if ((cfg->an_authtype & AN_AUTHTYPE_MASK) == AN_AUTHTYPE_SHAREDKEY)
761 printf("shared key");
763 printf("\nAssociation timeout:\t\t\t");
764 an_printwords(&cfg->an_assoc_timeout, 1);
765 printf("\nSpecified AP association timeout:\t");
766 an_printwords(&cfg->an_specified_ap_timeout, 1);
767 printf("\nOffline scan interval:\t\t\t");
768 an_printwords(&cfg->an_offline_scan_interval, 1);
769 printf("\nOffline scan duration:\t\t\t");
770 an_printwords(&cfg->an_offline_scan_duration, 1);
771 printf("\nLink loss delay:\t\t\t");
772 an_printwords(&cfg->an_link_loss_delay, 1);
773 printf("\nMax beacon loss time:\t\t\t");
774 an_printwords(&cfg->an_max_beacon_lost_time, 1);
775 printf("\nRefresh interval:\t\t\t");
776 an_printwords(&cfg->an_refresh_interval, 1);
777 printf("\nPower save mode:\t\t\t[ ");
778 if (cfg->an_psave_mode == AN_PSAVE_NONE)
780 if (cfg->an_psave_mode == AN_PSAVE_CAM)
781 printf("constantly awake mode");
782 if (cfg->an_psave_mode == AN_PSAVE_PSP)
784 if (cfg->an_psave_mode == AN_PSAVE_PSP_CAM)
785 printf("PSP-CAM (fast PSP)");
787 printf("\nSleep through DTIMs:\t\t\t");
788 an_printbool(cfg->an_sleep_for_dtims);
789 printf("\nPower save listen interval:\t\t");
790 an_printwords(&cfg->an_listen_interval, 1);
791 printf("\nPower save fast listen interval:\t");
792 an_printwords(&cfg->an_fast_listen_interval, 1);
793 printf("\nPower save listen decay:\t\t");
794 an_printwords(&cfg->an_listen_decay, 1);
795 printf("\nPower save fast listen decay:\t\t");
796 an_printwords(&cfg->an_fast_listen_decay, 1);
797 printf("\nAP/ad-hoc Beacon period:\t\t");
798 an_printwords(&cfg->an_beacon_period, 1);
799 printf("\nAP/ad-hoc ATIM duration:\t\t");
800 an_printwords(&cfg->an_atim_duration, 1);
801 printf("\nAP/ad-hoc current channel:\t\t");
802 an_printwords(&cfg->an_ds_channel, 1);
803 printf("\nAP/ad-hoc DTIM period:\t\t\t");
804 an_printwords(&cfg->an_dtim_period, 1);
805 printf("\nRadio type:\t\t\t\t[ ");
806 if (cfg->an_radiotype & AN_RADIOTYPE_80211_FH)
808 else if (cfg->an_radiotype & AN_RADIOTYPE_80211_DS)
810 else if (cfg->an_radiotype & AN_RADIOTYPE_LM2000_DS)
813 printf("unknown (%x)", cfg->an_radiotype);
815 printf("\nRX Diversity:\t\t\t\t[ ");
816 diversity = cfg->an_diversity & 0xFF;
817 if (diversity == AN_DIVERSITY_FACTORY_DEFAULT)
818 printf("factory default");
819 else if (diversity == AN_DIVERSITY_ANTENNA_1_ONLY)
820 printf("antenna 1 only");
821 else if (diversity == AN_DIVERSITY_ANTENNA_2_ONLY)
822 printf("antenna 2 only");
823 else if (diversity == AN_DIVERSITY_ANTENNA_1_AND_2)
824 printf("antenna 1 and 2");
826 printf("\nTX Diversity:\t\t\t\t[ ");
827 diversity = (cfg->an_diversity >> 8) & 0xFF;
828 if (diversity == AN_DIVERSITY_FACTORY_DEFAULT)
829 printf("factory default");
830 else if (diversity == AN_DIVERSITY_ANTENNA_1_ONLY)
831 printf("antenna 1 only");
832 else if (diversity == AN_DIVERSITY_ANTENNA_2_ONLY)
833 printf("antenna 2 only");
834 else if (diversity == AN_DIVERSITY_ANTENNA_1_AND_2)
835 printf("antenna 1 and 2");
837 printf("\nTransmit power level:\t\t\t");
838 an_printwords(&cfg->an_tx_power, 1);
839 printf("\nRSS threshold:\t\t\t\t");
840 an_printwords(&cfg->an_rss_thresh, 1);
841 printf("\nNode name:\t\t\t\t");
842 an_printstr((char *)&cfg->an_nodename, 16);
843 printf("\nARL threshold:\t\t\t\t");
844 an_printwords(&cfg->an_arl_thresh, 1);
845 printf("\nARL decay:\t\t\t\t");
846 an_printwords(&cfg->an_arl_decay, 1);
847 printf("\nARL delay:\t\t\t\t");
848 an_printwords(&cfg->an_arl_delay, 1);
849 printf("\nConfiguration:\t\t\t\t[ ");
850 if (cfg->an_home_product & AN_HOME_NETWORK)
851 printf("Home Configuration");
853 printf("Enterprise Configuration");
858 an_readkeyinfo(iface);
864 an_dumprssimap(const char *iface)
866 struct an_ltv_rssi_map *rssi;
870 areq.an_len = sizeof(areq);
871 areq.an_type = AN_RID_RSSI_MAP;
873 an_getval(iface, &areq);
875 rssi = (struct an_ltv_rssi_map *)&areq;
877 printf("idx\tpct\t dBm\n");
879 for (i = 0; i < 0xFF; i++) {
881 * negate the dBm value: it's the only way the power
884 printf("%3d\t%3d\t%4d\n", i,
885 rssi->an_entries[i].an_rss_pct,
886 - rssi->an_entries[i].an_rss_dbm);
895 fprintf(stderr, "usage: %s -i iface -A (show specified APs)\n", p);
896 fprintf(stderr, "\t%s -i iface -N (show specified SSIDss)\n", p);
897 fprintf(stderr, "\t%s -i iface -S (show NIC status)\n", p);
898 fprintf(stderr, "\t%s -i iface -I (show NIC capabilities)\n", p);
899 fprintf(stderr, "\t%s -i iface -T (show stats counters)\n", p);
900 fprintf(stderr, "\t%s -i iface -C (show current config)\n", p);
901 fprintf(stderr, "\t%s -i iface -R (show RSSI map)\n", p);
902 fprintf(stderr, "\t%s -i iface -t 0-4 (set TX speed)\n", p);
903 fprintf(stderr, "\t%s -i iface -s 0-3 (set power save mode)\n", p);
904 fprintf(stderr, "\t%s -i iface [-v 1-4] -a AP (specify AP)\n", p);
905 fprintf(stderr, "\t%s -i iface -b val (set beacon period)\n", p);
906 fprintf(stderr, "\t%s -i iface [-v 0|1] -d val (set diversity)\n", p);
907 fprintf(stderr, "\t%s -i iface -j val (set netjoin timeout)\n", p);
908 fprintf(stderr, "\t%s -i iface -e 0-4 (enable transmit key)\n", p);
909 fprintf(stderr, "\t%s -i iface [-v 0-8] -k key (set key)\n", p);
910 fprintf(stderr, "\t%s -i iface -K 0-2 (no auth/open/shared secret)\n", p);
911 fprintf(stderr, "\t%s -i iface -W 0-2 (no WEP/full WEP/mixed cell)\n", p);
912 fprintf(stderr, "\t%s -i iface -l val (set station name)\n", p);
913 fprintf(stderr, "\t%s -i iface -m val (set MAC address)\n", p);
914 fprintf(stderr, "\t%s -i iface [-v 1-3] -n SSID "
915 "(specify SSID)\n", p);
916 fprintf(stderr, "\t%s -i iface -o 0|1 (set operating mode)\n", p);
917 fprintf(stderr, "\t%s -i iface -c val (set ad-hoc channel)\n", p);
918 fprintf(stderr, "\t%s -i iface -f val (set frag threshold)\n", p);
919 fprintf(stderr, "\t%s -i iface -r val (set RTS threshold)\n", p);
920 fprintf(stderr, "\t%s -i iface -M 0-15 (set monitor mode)\n", p);
921 fprintf(stderr, "\t%s -i iface -L user (enter LEAP authentication mode)\n", p);
923 fprintf(stderr, "\t%s -i iface -Q print signal quality cache\n", p);
924 fprintf(stderr, "\t%s -i iface -Z zero out signal cache\n", p);
927 fprintf(stderr, "\t%s -h (display this message)\n", p);
934 an_setconfig(const char *iface, int act, void *arg)
936 struct an_ltv_genconfig *cfg;
937 struct an_ltv_caps *caps;
939 struct an_req areq_caps;
940 u_int16_t diversity = 0;
941 struct ether_addr *addr;
944 areq.an_len = sizeof(areq);
945 areq.an_type = AN_RID_GENCONFIG;
946 an_getval(iface, &areq);
947 cfg = (struct an_ltv_genconfig *)&areq;
949 areq_caps.an_len = sizeof(areq);
950 areq_caps.an_type = AN_RID_CAPABILITIES;
951 an_getval(iface, &areq_caps);
952 caps = (struct an_ltv_caps *)&areq_caps;
956 cfg->an_opmode = atoi(arg);
959 cfg->an_ds_channel = atoi(arg);
961 case ACT_SET_PWRSAVE:
962 cfg->an_psave_mode = atoi(arg);
964 case ACT_SET_SCANMODE:
965 cfg->an_scanmode = atoi(arg);
967 case ACT_SET_DIVERSITY_RX:
968 case ACT_SET_DIVERSITY_TX:
971 diversity = AN_DIVERSITY_FACTORY_DEFAULT;
974 diversity = AN_DIVERSITY_ANTENNA_1_ONLY;
977 diversity = AN_DIVERSITY_ANTENNA_2_ONLY;
980 diversity = AN_DIVERSITY_ANTENNA_1_AND_2;
983 errx(1, "bad diversity setting: %d", diversity);
986 if (act == ACT_SET_DIVERSITY_RX) {
987 cfg->an_diversity &= 0xFF00;
988 cfg->an_diversity |= diversity;
990 cfg->an_diversity &= 0x00FF;
991 cfg->an_diversity |= (diversity << 8);
995 for (i = 0; i < 8; i++) {
996 if (caps->an_tx_powerlevels[i] == atoi(arg))
1000 errx(1, "unsupported power level: %dmW", atoi(arg));
1002 cfg->an_tx_power = atoi(arg);
1004 case ACT_SET_RTS_THRESH:
1005 cfg->an_rtsthresh = atoi(arg);
1007 case ACT_SET_RTS_RETRYLIM:
1008 cfg->an_shortretry_limit =
1009 cfg->an_longretry_limit = atoi(arg);
1011 case ACT_SET_BEACON_PERIOD:
1012 cfg->an_beacon_period = atoi(arg);
1014 case ACT_SET_WAKE_DURATION:
1015 cfg->an_atim_duration = atoi(arg);
1017 case ACT_SET_FRAG_THRESH:
1018 cfg->an_fragthresh = atoi(arg);
1020 case ACT_SET_NETJOIN:
1021 cfg->an_ibss_join_net_timeout = atoi(arg);
1023 case ACT_SET_MYNAME:
1024 bzero(cfg->an_nodename, 16);
1025 strncpy((char *)&cfg->an_nodename, optarg, 16);
1028 addr = ether_aton((char *)arg);
1031 errx(1, "badly formatted address");
1032 bzero(cfg->an_macaddr, ETHER_ADDR_LEN);
1033 bcopy((char *)addr, (char *)&cfg->an_macaddr, ETHER_ADDR_LEN);
1035 case ACT_ENABLE_WEP:
1036 switch (atoi (arg)) {
1039 cfg->an_authtype &= ~(AN_AUTHTYPE_PRIVACY_IN_USE
1040 | AN_AUTHTYPE_ALLOW_UNENCRYPTED
1041 | AN_AUTHTYPE_LEAP);
1045 cfg->an_authtype |= AN_AUTHTYPE_PRIVACY_IN_USE;
1046 cfg->an_authtype &= ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
1047 cfg->an_authtype &= ~AN_AUTHTYPE_LEAP;
1051 cfg->an_authtype = AN_AUTHTYPE_PRIVACY_IN_USE
1052 | AN_AUTHTYPE_ALLOW_UNENCRYPTED;
1056 case ACT_SET_KEY_TYPE:
1057 cfg->an_authtype = (cfg->an_authtype & ~AN_AUTHTYPE_MASK)
1060 case ACT_SET_MONITOR_MODE:
1061 areq.an_type = AN_RID_MONITOR_MODE;
1062 cfg->an_len = atoi(arg); /* mode is put in length */
1065 errx(1, "unknown action");
1069 an_setval(iface, &areq);
1074 an_setspeed(const char *iface, int act __unused, void *arg)
1077 struct an_ltv_caps *caps;
1080 areq.an_len = sizeof(areq);
1081 areq.an_type = AN_RID_CAPABILITIES;
1083 an_getval(iface, &areq);
1084 caps = (struct an_ltv_caps *)&areq;
1091 speed = AN_RATE_1MBPS;
1094 speed = AN_RATE_2MBPS;
1097 if (caps->an_rates[2] != AN_RATE_5_5MBPS)
1098 errx(1, "5.5Mbps not supported on this card");
1099 speed = AN_RATE_5_5MBPS;
1102 if (caps->an_rates[3] != AN_RATE_11MBPS)
1103 errx(1, "11Mbps not supported on this card");
1104 speed = AN_RATE_11MBPS;
1107 errx(1, "unsupported speed");
1112 areq.an_type = AN_RID_TX_SPEED;
1113 areq.an_val[0] = speed;
1115 an_setval(iface, &areq);
1120 an_setap(const char *iface, int act, void *arg)
1122 struct an_ltv_aplist *ap;
1124 struct ether_addr *addr;
1126 areq.an_len = sizeof(areq);
1127 areq.an_type = AN_RID_APLIST;
1129 an_getval(iface, &areq);
1130 ap = (struct an_ltv_aplist *)&areq;
1132 addr = ether_aton((char *)arg);
1135 errx(1, "badly formatted address");
1139 bzero(ap->an_ap1, ETHER_ADDR_LEN);
1140 bcopy((char *)addr, (char *)&ap->an_ap1, ETHER_ADDR_LEN);
1143 bzero(ap->an_ap2, ETHER_ADDR_LEN);
1144 bcopy((char *)addr, (char *)&ap->an_ap2, ETHER_ADDR_LEN);
1147 bzero(ap->an_ap3, ETHER_ADDR_LEN);
1148 bcopy((char *)addr, (char *)&ap->an_ap3, ETHER_ADDR_LEN);
1151 bzero(ap->an_ap4, ETHER_ADDR_LEN);
1152 bcopy((char *)addr, (char *)&ap->an_ap4, ETHER_ADDR_LEN);
1155 errx(1, "unknown action");
1159 an_setval(iface, &areq);
1164 an_setssid(const char *iface, int act, void *arg)
1166 struct an_ltv_ssidlist *ssid;
1169 areq.an_len = sizeof(areq);
1170 areq.an_type = AN_RID_SSIDLIST;
1172 an_getval(iface, &areq);
1173 ssid = (struct an_ltv_ssidlist *)&areq;
1177 bzero(ssid->an_ssid1, sizeof(ssid->an_ssid1));
1178 strlcpy(ssid->an_ssid1, (char *)arg, sizeof(ssid->an_ssid1));
1179 ssid->an_ssid1_len = strlen(ssid->an_ssid1);
1182 bzero(ssid->an_ssid2, sizeof(ssid->an_ssid2));
1183 strlcpy(ssid->an_ssid2, (char *)arg, sizeof(ssid->an_ssid2));
1184 ssid->an_ssid2_len = strlen(ssid->an_ssid2);
1187 bzero(ssid->an_ssid3, sizeof(ssid->an_ssid3));
1188 strlcpy(ssid->an_ssid3, (char *)arg, sizeof(ssid->an_ssid3));
1189 ssid->an_ssid3_len = strlen(ssid->an_ssid3);
1192 errx(1, "unknown action");
1196 an_setval(iface, &areq);
1202 an_zerocache(const char *iface)
1206 bzero((char *)&areq, sizeof(areq));
1208 areq.an_type = AN_RID_ZERO_CACHE;
1210 an_getval(iface, &areq);
1216 an_readcache(const char *iface)
1220 struct an_sigcache *sc;
1225 errx(1, "must specify interface name");
1227 bzero((char *)&areq, sizeof(areq));
1228 areq.an_len = AN_MAX_DATALEN;
1229 areq.an_type = AN_RID_READ_CACHE;
1231 an_getval(iface, &areq);
1233 an_sigitems = (int *) &areq.an_val;
1234 pt = ((char *) &areq.an_val);
1236 sc = (struct an_sigcache *) pt;
1238 for (i = 0; i < *an_sigitems; i++) {
1239 printf("[%d/%d]:", i+1, *an_sigitems);
1240 printf(" %02x:%02x:%02x:%02x:%02x:%02x,",
1246 sc->macsrc[5]&0xff);
1247 printf(" %d.%d.%d.%d,",((sc->ipsrc >> 0) & 0xff),
1248 ((sc->ipsrc >> 8) & 0xff),
1249 ((sc->ipsrc >> 16) & 0xff),
1250 ((sc->ipsrc >> 24) & 0xff));
1251 printf(" sig: %d, noise: %d, qual: %d\n",
1265 if (c >= '0' && c <= '9')
1267 if (c >= 'A' && c <= 'F')
1268 return (c - 'A' + 10);
1269 if (c >= 'a' && c <= 'f')
1270 return (c - 'a' + 10);
1276 an_str2key(char *s, struct an_ltv_key *k)
1281 /* Is this a hex string? */
1282 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) {
1283 /* Yes, convert to int. */
1285 p = (char *)&k->key[0];
1286 for (i = 2; s[i] != '\0' && s[i + 1] != '\0'; i+= 2) {
1287 *p++ = (an_hex2int(s[i]) << 4) + an_hex2int(s[i + 1]);
1291 errx(1, "hex strings must be of even length");
1294 /* No, just copy it in. */
1295 bcopy(s, k->key, strlen(s));
1296 k->klen = strlen(s);
1303 an_setkeys(const char *iface, char *key, int keytype)
1306 struct an_ltv_key *k;
1308 bzero((char *)&areq, sizeof(areq));
1309 k = (struct an_ltv_key *)&areq;
1311 if (strlen(key) > 28) {
1312 err(1, "encryption key must be no "
1313 "more than 18 characters long");
1318 k->kindex=keytype/2;
1320 if (!(k->klen==0 || k->klen==5 || k->klen==13)) {
1321 err(1, "encryption key must be 0, 5 or 13 bytes long");
1324 /* default mac and only valid one (from manual) 1.0.0.0.0.0 */
1332 switch(keytype & 1) {
1334 areq.an_len = sizeof(struct an_ltv_key);
1335 areq.an_type = AN_RID_WEP_PERM;
1336 an_setval(iface, &areq);
1339 areq.an_len = sizeof(struct an_ltv_key);
1340 areq.an_type = AN_RID_WEP_TEMP;
1341 an_setval(iface, &areq);
1349 an_readkeyinfo(const char *iface)
1352 struct an_ltv_genconfig *cfg;
1353 struct an_ltv_key *k;
1357 areq.an_len = sizeof(areq);
1358 areq.an_type = AN_RID_ACTUALCFG;
1359 an_getval(iface, &areq);
1360 cfg = (struct an_ltv_genconfig *)&areq;
1361 if (cfg->an_home_product & AN_HOME_NETWORK)
1366 bzero((char *)&areq, sizeof(areq));
1367 k = (struct an_ltv_key *)&areq;
1369 printf("WEP Key status:\n");
1370 areq.an_type = AN_RID_WEP_TEMP; /* read first key */
1371 for(i=0; i<5; i++) {
1372 areq.an_len = sizeof(struct an_ltv_key);
1373 an_getval(iface, &areq);
1374 if (k->kindex == 0xffff)
1378 printf("\tKey %d is unset\n",k->kindex);
1381 printf("\tKey %d is set 40 bits\n",k->kindex);
1384 printf("\tKey %d is set 128 bits\n",k->kindex);
1387 printf("\tWEP Key %d has an unknown size %d\n",
1391 areq.an_type = AN_RID_WEP_PERM; /* read next key */
1394 areq.an_len = sizeof(struct an_ltv_key);
1395 an_getval(iface, &areq);
1396 printf("\tThe active transmit key is %d\n", 4 * home + k->mac[0]);
1402 an_enable_tx_key(const char *iface, char *arg)
1405 struct an_ltv_key *k;
1406 struct an_ltv_genconfig *config;
1408 bzero((char *)&areq, sizeof(areq));
1410 /* set home or not home mode */
1411 areq.an_len = sizeof(struct an_ltv_genconfig);
1412 areq.an_type = AN_RID_GENCONFIG;
1413 an_getval(iface, &areq);
1414 config = (struct an_ltv_genconfig *)&areq;
1415 if (atoi(arg) == 4) {
1416 config->an_home_product |= AN_HOME_NETWORK;
1418 config->an_home_product &= ~AN_HOME_NETWORK;
1420 an_setval(iface, &areq);
1422 bzero((char *)&areq, sizeof(areq));
1424 k = (struct an_ltv_key *)&areq;
1426 /* From a Cisco engineer write the transmit key to use in the
1427 first MAC, index is FFFF*/
1431 k->mac[0]=atoi(arg);
1438 areq.an_len = sizeof(struct an_ltv_key);
1439 areq.an_type = AN_RID_WEP_PERM;
1440 an_setval(iface, &areq);
1446 an_enable_leap_mode(const char *iface, char *username)
1449 struct an_ltv_status *sts;
1450 struct an_ltv_genconfig *cfg;
1451 struct an_ltv_caps *caps;
1452 struct an_ltv_leap_username an_username;
1453 struct an_ltv_leap_password an_password;
1458 char unicode_password[LEAP_PASSWORD_MAX * 2];
1460 areq.an_len = sizeof(areq);
1461 areq.an_type = AN_RID_CAPABILITIES;
1463 an_getval(iface, &areq);
1465 caps = (struct an_ltv_caps *)&areq;
1467 if (!(caps->an_softcaps & AN_AUTHTYPE_LEAP)) {
1468 fprintf(stderr, "Firmware does not support LEAP\n");
1472 bzero(&an_username, sizeof(an_username));
1473 bzero(&an_password, sizeof(an_password));
1475 len = strlen(username);
1476 if (len > LEAP_USERNAME_MAX) {
1477 printf("Username too long (max %d)\n", LEAP_USERNAME_MAX);
1480 strncpy(an_username.an_username, username, len);
1481 an_username.an_username_len = len;
1482 an_username.an_len = sizeof(an_username);
1483 an_username.an_type = AN_RID_LEAPUSERNAME;
1485 password = getpass("Enter LEAP password:");
1487 len = strlen(password);
1488 if (len > LEAP_PASSWORD_MAX) {
1489 printf("Password too long (max %d)\n", LEAP_PASSWORD_MAX);
1493 bzero(&unicode_password, sizeof(unicode_password));
1494 for(i = 0; i < len; i++) {
1495 unicode_password[i * 2] = *password++;
1500 MD4Update(&context, unicode_password, len * 2);
1501 MD4Final(&an_password.an_password[0], &context);
1505 MD4Update (&context, &an_password.an_password[0], 16);
1506 MD4Final (&an_password.an_password[16], &context);
1508 an_password.an_password_len = 32;
1509 an_password.an_len = sizeof(an_password);
1510 an_password.an_type = AN_RID_LEAPPASSWORD;
1512 an_setval(iface, (struct an_req *)&an_username);
1513 an_setval(iface, (struct an_req *)&an_password);
1515 areq.an_len = sizeof(areq);
1516 areq.an_type = AN_RID_GENCONFIG;
1517 an_getval(iface, &areq);
1518 cfg = (struct an_ltv_genconfig *)&areq;
1519 cfg->an_authtype = (AN_AUTHTYPE_PRIVACY_IN_USE | AN_AUTHTYPE_LEAP);
1520 an_setval(iface, &areq);
1522 sts = (struct an_ltv_status *)&areq;
1523 areq.an_type = AN_RID_STATUS;
1525 for (i = 60; i > 0; i--) {
1526 an_getval(iface, &areq);
1527 if (sts->an_opmode & AN_STATUS_OPMODE_LEAP) {
1528 printf("Authenticated\n");
1535 fprintf(stderr, "Failed LEAP authentication\n");
1541 main(int argc, char **argv)
1545 const char *iface = NULL;
1551 /* Get the interface name */
1553 ch = getopt(argc, argv, "i:");
1557 if (argc > 1 && *argv[1] != '-') {
1568 while ((ch = getopt(argc, argv,
1569 "ANISCTRht:a:e:o:s:n:v:d:j:b:c:r:p:w:m:l:k:K:W:QZM:L:")) != -1) {
1573 act = ACT_ZEROCACHE;
1575 errx(1, "ANCACHE not available");
1580 act = ACT_DUMPCACHE;
1582 errx(1, "ANCACHE not available");
1592 act = ACT_DUMPSTATUS;
1598 act = ACT_DUMPSTATS;
1601 act = ACT_DUMPCONFIG;
1604 act = ACT_DUMPRSSIMAP;
1607 act = ACT_SET_TXRATE;
1611 act = ACT_SET_PWRSAVE;
1615 act = ACT_SET_TXPWR;
1619 modifier = atoi(optarg);
1637 errx(1, "bad modifier %d: there "
1638 "are only 4 access point settings",
1646 act = ACT_SET_BEACON_PERIOD;
1652 act = ACT_SET_DIVERSITY_RX;
1655 act = ACT_SET_DIVERSITY_TX;
1658 errx(1, "must specify RX or TX diversity");
1661 if (!isdigit(*optarg)) {
1662 errx(1, "%s is not numeric", optarg);
1668 act = ACT_SET_NETJOIN;
1672 act = ACT_SET_MYNAME;
1683 act = ACT_SET_SSID1;
1686 act = ACT_SET_SSID2;
1689 act = ACT_SET_SSID3;
1692 errx(1, "bad modifier %d: there"
1693 "are only 3 SSID settings", modifier);
1700 act = ACT_SET_OPMODE;
1708 act = ACT_SET_FRAG_THRESH;
1712 act = ACT_ENABLE_WEP;
1716 act = ACT_SET_KEY_TYPE;
1724 act = ACT_ENABLE_TX_KEY;
1728 act = ACT_SET_RTS_RETRYLIM;
1732 act = ACT_SET_RTS_THRESH;
1736 act = ACT_SET_WAKE_DURATION;
1740 act = ACT_SET_MONITOR_MODE;
1744 act = ACT_SET_LEAP_MODE;
1753 if (iface == NULL || (!act && !key))
1757 case ACT_DUMPSTATUS:
1758 an_dumpstatus(iface);
1764 an_dumpstats(iface);
1766 case ACT_DUMPCONFIG:
1767 an_dumpconfig(iface);
1775 case ACT_DUMPRSSIMAP:
1776 an_dumprssimap(iface);
1781 an_setssid(iface, act, arg);
1787 an_setap(iface, act, arg);
1789 case ACT_SET_TXRATE:
1790 an_setspeed(iface, act, arg);
1794 an_zerocache(iface);
1797 an_readcache(iface);
1802 an_setkeys(iface, key, modifier);
1804 case ACT_ENABLE_TX_KEY:
1805 an_enable_tx_key(iface, arg);
1807 case ACT_SET_LEAP_MODE:
1808 an_enable_leap_mode(iface, arg);
1811 an_setconfig(iface, act, arg);