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