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