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