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