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