Home | History | Annotate | Line # | Download | only in wiconfig
wiconfig.c revision 1.28
      1  1.28    dyoung /*	$NetBSD: wiconfig.c,v 1.28 2002/11/16 22:39:57 dyoung Exp $	*/
      2   1.1  sommerfe /*
      3   1.1  sommerfe  * Copyright (c) 1997, 1998, 1999
      4   1.1  sommerfe  *	Bill Paul <wpaul (at) ctr.columbia.edu>.  All rights reserved.
      5   1.1  sommerfe  *
      6   1.1  sommerfe  * Redistribution and use in source and binary forms, with or without
      7   1.1  sommerfe  * modification, are permitted provided that the following conditions
      8   1.1  sommerfe  * are met:
      9   1.1  sommerfe  * 1. Redistributions of source code must retain the above copyright
     10   1.1  sommerfe  *    notice, this list of conditions and the following disclaimer.
     11   1.1  sommerfe  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1  sommerfe  *    notice, this list of conditions and the following disclaimer in the
     13   1.1  sommerfe  *    documentation and/or other materials provided with the distribution.
     14   1.1  sommerfe  * 3. All advertising materials mentioning features or use of this software
     15   1.1  sommerfe  *    must display the following acknowledgement:
     16   1.1  sommerfe  *	This product includes software developed by Bill Paul.
     17   1.1  sommerfe  * 4. Neither the name of the author nor the names of any co-contributors
     18   1.1  sommerfe  *    may be used to endorse or promote products derived from this software
     19   1.1  sommerfe  *    without specific prior written permission.
     20   1.1  sommerfe  *
     21   1.1  sommerfe  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
     22   1.1  sommerfe  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23   1.1  sommerfe  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24   1.1  sommerfe  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
     25   1.1  sommerfe  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26   1.1  sommerfe  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27   1.1  sommerfe  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28   1.1  sommerfe  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29   1.1  sommerfe  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30   1.1  sommerfe  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     31   1.1  sommerfe  * THE POSSIBILITY OF SUCH DAMAGE.
     32   1.1  sommerfe  *
     33   1.8     enami  *	From: Id: wicontrol.c,v 1.6 1999/05/22 16:12:49 wpaul Exp $
     34   1.1  sommerfe  */
     35   1.1  sommerfe 
     36   1.1  sommerfe #include <sys/types.h>
     37   1.1  sommerfe #include <sys/cdefs.h>
     38   1.1  sommerfe #include <sys/param.h>
     39   1.1  sommerfe #include <sys/socket.h>
     40   1.1  sommerfe #include <sys/ioctl.h>
     41   1.1  sommerfe #include <sys/socket.h>
     42   1.1  sommerfe 
     43   1.1  sommerfe #include <net/if.h>
     44   1.2  explorer #ifdef __FreeBSD__
     45   1.2  explorer #include <net/if_var.h>
     46   1.2  explorer #include <net/ethernet.h>
     47   1.2  explorer 
     48   1.2  explorer #include <machine/if_wavelan_ieee.h>
     49   1.2  explorer #else
     50   1.2  explorer #include <netinet/in.h>
     51   1.2  explorer #include <netinet/if_ether.h>
     52   1.2  explorer #ifdef __NetBSD__
     53  1.15    ichiro #include <net/if_ieee80211.h>
     54  1.12    ichiro #include <dev/ic/wi_ieee.h>
     55   1.2  explorer #else
     56   1.2  explorer #include <dev/pcmcia/if_wavelan_ieee.h>
     57   1.2  explorer #endif
     58   1.2  explorer #endif
     59   1.1  sommerfe 
     60   1.1  sommerfe #include <stdio.h>
     61   1.1  sommerfe #include <string.h>
     62   1.2  explorer #include <ctype.h>
     63   1.1  sommerfe #include <stdlib.h>
     64   1.1  sommerfe #include <unistd.h>
     65   1.1  sommerfe #include <errno.h>
     66   1.1  sommerfe #include <err.h>
     67   1.1  sommerfe 
     68   1.1  sommerfe #if !defined(lint)
     69  1.25   thorpej __COPYRIGHT(
     70  1.25   thorpej "@(#) Copyright (c) 1997, 1998, 1999\
     71  1.25   thorpej 	Bill Paul. All rights reserved.");
     72  1.28    dyoung __RCSID("$NetBSD: wiconfig.c,v 1.28 2002/11/16 22:39:57 dyoung Exp $");
     73   1.1  sommerfe #endif
     74   1.1  sommerfe 
     75   1.7     enami struct wi_table {
     76   1.7     enami 	int wi_type;
     77   1.7     enami 	int wi_code;
     78   1.7     enami #define	WI_NONE			0x00
     79   1.7     enami #define	WI_STRING		0x01
     80   1.7     enami #define	WI_BOOL			0x02
     81   1.7     enami #define	WI_WORDS		0x03
     82   1.7     enami #define	WI_HEXBYTES		0x04
     83   1.7     enami #define	WI_KEYSTRUCT		0x05
     84  1.22       dbj #define	WI_BITS			0x06
     85   1.7     enami 	char *wi_label;			/* label used to print info */
     86   1.7     enami 	int wi_opt;			/* option character to set this */
     87   1.7     enami 	char *wi_desc;
     88   1.7     enami 	char *wi_optval;
     89   1.7     enami };
     90   1.7     enami 
     91  1.15    ichiro /* already define in wireg.h XXX */
     92  1.15    ichiro #define	WI_APRATE_0		0x00	/* NONE */
     93  1.15    ichiro #define WI_APRATE_1		0x0A	/* 1 Mbps */
     94  1.15    ichiro #define WI_APRATE_2		0x14	/* 2 Mbps */
     95  1.15    ichiro #define WI_APRATE_5		0x37	/* 5.5 Mbps */
     96  1.15    ichiro #define WI_APRATE_11		0x6E	/* 11 Mbps */
     97  1.15    ichiro 
     98  1.18  christos #ifdef WI_RID_SCAN_APS
     99  1.15    ichiro static void wi_apscan		__P((char *));
    100  1.18  christos static int  get_if_flags	__P((int, const char *));
    101  1.18  christos static int  set_if_flags	__P((int, const char *, int));
    102  1.18  christos #endif
    103   1.1  sommerfe static void wi_getval		__P((char *, struct wi_req *));
    104   1.1  sommerfe static void wi_setval		__P((char *, struct wi_req *));
    105   1.1  sommerfe static void wi_printstr		__P((struct wi_req *));
    106   1.1  sommerfe static void wi_setstr		__P((char *, int, char *));
    107   1.1  sommerfe static void wi_setbytes		__P((char *, int, char *, int));
    108   1.1  sommerfe static void wi_setword		__P((char *, int, int));
    109   1.1  sommerfe static void wi_sethex		__P((char *, int, char *));
    110   1.1  sommerfe static void wi_printwords	__P((struct wi_req *));
    111   1.1  sommerfe static void wi_printbool	__P((struct wi_req *));
    112   1.1  sommerfe static void wi_printhex		__P((struct wi_req *));
    113  1.22       dbj static void wi_printbits	__P((struct wi_req *));
    114   1.1  sommerfe static void wi_dumpinfo		__P((char *));
    115   1.2  explorer static void wi_printkeys	__P((struct wi_req *));
    116   1.1  sommerfe static void wi_dumpstats	__P((char *));
    117   1.7     enami static void usage		__P((void));
    118   1.7     enami static struct wi_table *
    119   1.7     enami 	wi_optlookup __P((struct wi_table *, int));
    120   1.1  sommerfe int main __P((int argc, char **argv));
    121   1.1  sommerfe 
    122  1.18  christos #ifdef WI_RID_SCAN_APS
    123  1.17    ichiro static int get_if_flags(s, name)
    124  1.17    ichiro 	int		s;
    125  1.17    ichiro 	const char	*name;
    126  1.17    ichiro {
    127  1.17    ichiro 	struct ifreq	ifreq;
    128  1.17    ichiro 	int		flags;
    129  1.17    ichiro 
    130  1.17    ichiro 	strncpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name));
    131  1.17    ichiro 	if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifreq) == -1)
    132  1.17    ichiro 		  err(1, "SIOCGIFFLAGS");
    133  1.17    ichiro 	flags = ifreq.ifr_flags;
    134  1.17    ichiro 
    135  1.17    ichiro 	return flags;
    136  1.17    ichiro }
    137  1.17    ichiro 
    138  1.17    ichiro static int set_if_flags(s, name, flags)
    139  1.17    ichiro 	int		s;
    140  1.17    ichiro 	const char	*name;
    141  1.17    ichiro 	int		flags;
    142  1.17    ichiro {
    143  1.17    ichiro 	struct ifreq ifreq;
    144  1.17    ichiro 
    145  1.17    ichiro 	ifreq.ifr_flags = flags;
    146  1.17    ichiro 	strncpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name));
    147  1.17    ichiro 	if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&ifreq) == -1)
    148  1.17    ichiro 		  err(1, "SIOCSIFFLAGS");
    149  1.17    ichiro 
    150  1.17    ichiro 	return 0;
    151  1.17    ichiro }
    152  1.17    ichiro 
    153  1.15    ichiro static void wi_apscan(iface)
    154  1.15    ichiro 	char			*iface;
    155  1.15    ichiro {
    156  1.15    ichiro 	struct wi_req		wreq;
    157  1.15    ichiro 	struct ifreq		ifr;
    158  1.15    ichiro 	int			s;
    159  1.15    ichiro 	int			naps, rate;
    160  1.15    ichiro 	int			retries = 10;
    161  1.17    ichiro 	int			flags;
    162  1.15    ichiro 	struct wi_apinfo	*w;
    163  1.15    ichiro 	int			i, j;
    164  1.15    ichiro 
    165  1.15    ichiro 	if (iface == NULL)
    166  1.15    ichiro 		errx(1, "must specify interface name");
    167  1.17    ichiro 
    168  1.17    ichiro 	s = socket(AF_INET, SOCK_DGRAM, 0);
    169  1.17    ichiro 	if (s == -1)
    170  1.17    ichiro 		err(1, "socket");
    171  1.17    ichiro 	flags = get_if_flags(s, iface);
    172  1.17    ichiro 	if ((flags & IFF_UP) == 0)
    173  1.17    ichiro 		flags = set_if_flags(s, iface, flags | IFF_UP);
    174  1.17    ichiro 
    175  1.15    ichiro 	memset((char *)&wreq, 0, sizeof(wreq));
    176  1.15    ichiro 
    177  1.15    ichiro 	wreq.wi_type = WI_RID_SCAN_APS;
    178  1.15    ichiro 	wreq.wi_len = 4;
    179  1.15    ichiro 	/* note chan. 1 is the least significant bit */
    180  1.24    ichiro 	wreq.wi_val[0] = 0x3fff;	/* 1 bit per channel, 1-14 */
    181  1.24    ichiro 	wreq.wi_val[1] = 0xf;		/* tx rate */
    182  1.15    ichiro 
    183  1.15    ichiro 	/* write the request */
    184  1.15    ichiro 	wi_setval(iface, &wreq);
    185  1.15    ichiro 
    186  1.15    ichiro 	/* now poll for a result */
    187  1.15    ichiro 	memset((char *)&wreq, 0, sizeof(wreq));
    188  1.15    ichiro 
    189  1.15    ichiro 	wreq.wi_type = WI_RID_READ_APS;
    190  1.15    ichiro 	wreq.wi_len = WI_MAX_DATALEN;
    191  1.15    ichiro 
    192  1.15    ichiro 	/* we have to do this ourself as opposed to
    193  1.19    ichiro 	 * using getval, because we cannot bail if
    194  1.15    ichiro  	 * the ioctl fails
    195  1.15    ichiro 	 */
    196  1.15    ichiro 	memset((char *)&ifr, 0, sizeof(ifr));
    197  1.15    ichiro         strcpy(ifr.ifr_name, iface);
    198  1.15    ichiro         ifr.ifr_data = (caddr_t)&wreq;
    199  1.15    ichiro 
    200  1.15    ichiro 	printf("scanning ...");
    201  1.17    ichiro 	fflush(stdout);
    202  1.15    ichiro 	while (ioctl(s, SIOCGWAVELAN, &ifr) == -1) {
    203  1.15    ichiro 		retries--;
    204  1.15    ichiro 		if (retries >= 0) {
    205  1.19    ichiro 			printf("."); fflush(stdout);
    206  1.15    ichiro 			sleep(1);
    207  1.15    ichiro 		} else
    208  1.15    ichiro 			break;
    209  1.15    ichiro 		errno = 0;
    210  1.15    ichiro 	}
    211  1.15    ichiro 
    212  1.15    ichiro 	if (errno) {
    213  1.17    ichiro 		set_if_flags(s, iface, flags);
    214  1.17    ichiro 		close(s);
    215  1.15    ichiro 		err(1, "ioctl");
    216  1.15    ichiro 	}
    217  1.15    ichiro 
    218  1.20       dbj 	naps = *(int *)wreq.wi_val;
    219  1.23       dbj 
    220  1.23       dbj 	if (naps > 0)
    221  1.23       dbj 		printf("\nAP Information\n");
    222  1.23       dbj 	else
    223  1.23       dbj 		printf("\nNo APs available\n");
    224  1.23       dbj 
    225  1.15    ichiro 	w =  (struct wi_apinfo *)(((char *)&wreq.wi_val) + sizeof(int));
    226  1.15    ichiro 	for ( i = 0; i < naps; i++, w++) {
    227  1.15    ichiro 		printf("ap[%d]:\n", i);
    228  1.15    ichiro 		if (w->scanreason) {
    229  1.15    ichiro 			static char *scanm[] = {
    230  1.15    ichiro 				"Host initiated",
    231  1.15    ichiro 				"Firmware initiated",
    232  1.15    ichiro 				"Inquiry request from host"
    233  1.15    ichiro 			};
    234  1.15    ichiro 			printf("\tScanReason:\t\t\t[ %s ]\n",
    235  1.15    ichiro 				scanm[w->scanreason - 1]);
    236  1.15    ichiro 		}
    237  1.15    ichiro 		printf("\tnetname (SSID):\t\t\t[ ");
    238  1.15    ichiro 			for (j = 0; j < w->namelen; j++) {
    239  1.15    ichiro 				printf("%c", w->name[j]);
    240  1.15    ichiro 			}
    241  1.15    ichiro 			printf(" ]\n");
    242  1.15    ichiro 		printf("\tBSSID:\t\t\t\t[ %02x:%02x:%02x:%02x:%02x:%02x ]\n",
    243  1.15    ichiro 			w->bssid[0]&0xff, w->bssid[1]&0xff,
    244  1.15    ichiro 			w->bssid[2]&0xff, w->bssid[3]&0xff,
    245  1.15    ichiro 			w->bssid[4]&0xff, w->bssid[5]&0xff);
    246  1.15    ichiro 		printf("\tChannel:\t\t\t[ %d ]\n", w->channel);
    247  1.15    ichiro 		printf("\tQuality/Signal/Noise [signal]:\t[ %d / %d / %d ]\n"
    248  1.15    ichiro 		       "\t                        [dBm]:\t[ %d / %d / %d ]\n",
    249  1.15    ichiro 			w->quality, w->signal, w->noise,
    250  1.15    ichiro 			w->quality, w->signal - 149, w->noise - 149);
    251  1.21       dbj 		printf("\tBSS Beacon Interval [msec]:\t[ %d ]\n", w->interval);
    252  1.15    ichiro 		printf("\tCapinfo:\t\t\t[ ");
    253  1.15    ichiro 			if (w->capinfo & IEEE80211_CAPINFO_ESS)
    254  1.15    ichiro 				printf("ESS ");
    255  1.15    ichiro 			if (w->capinfo & IEEE80211_CAPINFO_PRIVACY)
    256  1.15    ichiro 				printf("WEP ");
    257  1.15    ichiro 			printf("]\n");
    258  1.15    ichiro 
    259  1.15    ichiro 		switch (w->rate) {
    260  1.15    ichiro 		case WI_APRATE_1:
    261  1.15    ichiro 			rate = 1;
    262  1.15    ichiro 			break;
    263  1.15    ichiro 		case WI_APRATE_2:
    264  1.15    ichiro 			rate = 2;
    265  1.15    ichiro 			break;
    266  1.15    ichiro 		case WI_APRATE_5:
    267  1.15    ichiro 			rate = 5.5;
    268  1.15    ichiro 			break;
    269  1.15    ichiro 		case WI_APRATE_11:
    270  1.15    ichiro 			rate = 11;
    271  1.15    ichiro 			break;
    272  1.15    ichiro 		case WI_APRATE_0:
    273  1.15    ichiro 		default:
    274  1.15    ichiro 			rate = 0;
    275  1.15    ichiro 			break;
    276  1.15    ichiro 		}
    277  1.15    ichiro 		if (rate) printf("\tDataRate [Mbps]:\t\t[ %d ]\n", rate);
    278  1.15    ichiro 	}
    279  1.17    ichiro 
    280  1.17    ichiro 	set_if_flags(s, iface, flags);
    281  1.17    ichiro 	close(s);
    282  1.15    ichiro }
    283  1.18  christos #endif
    284  1.15    ichiro 
    285   1.1  sommerfe static void wi_getval(iface, wreq)
    286   1.1  sommerfe 	char			*iface;
    287   1.1  sommerfe 	struct wi_req		*wreq;
    288   1.1  sommerfe {
    289   1.1  sommerfe 	struct ifreq		ifr;
    290   1.1  sommerfe 	int			s;
    291   1.1  sommerfe 
    292   1.1  sommerfe 	bzero((char *)&ifr, sizeof(ifr));
    293   1.1  sommerfe 
    294   1.1  sommerfe 	strcpy(ifr.ifr_name, iface);
    295   1.1  sommerfe 	ifr.ifr_data = (caddr_t)wreq;
    296   1.1  sommerfe 
    297   1.1  sommerfe 	s = socket(AF_INET, SOCK_DGRAM, 0);
    298   1.1  sommerfe 
    299   1.1  sommerfe 	if (s == -1)
    300   1.1  sommerfe 		err(1, "socket");
    301   1.1  sommerfe 
    302   1.1  sommerfe 	if (ioctl(s, SIOCGWAVELAN, &ifr) == -1)
    303   1.1  sommerfe 		err(1, "SIOCGWAVELAN");
    304   1.1  sommerfe 
    305   1.1  sommerfe 	close(s);
    306   1.1  sommerfe 
    307   1.1  sommerfe 	return;
    308   1.1  sommerfe }
    309   1.1  sommerfe 
    310   1.1  sommerfe static void wi_setval(iface, wreq)
    311   1.1  sommerfe 	char			*iface;
    312   1.1  sommerfe 	struct wi_req		*wreq;
    313   1.1  sommerfe {
    314   1.1  sommerfe 	struct ifreq		ifr;
    315   1.1  sommerfe 	int			s;
    316   1.1  sommerfe 
    317   1.1  sommerfe 	bzero((char *)&ifr, sizeof(ifr));
    318   1.1  sommerfe 
    319   1.1  sommerfe 	strcpy(ifr.ifr_name, iface);
    320   1.1  sommerfe 	ifr.ifr_data = (caddr_t)wreq;
    321   1.1  sommerfe 
    322   1.1  sommerfe 	s = socket(AF_INET, SOCK_DGRAM, 0);
    323   1.1  sommerfe 
    324   1.1  sommerfe 	if (s == -1)
    325   1.1  sommerfe 		err(1, "socket");
    326   1.1  sommerfe 
    327   1.1  sommerfe 	if (ioctl(s, SIOCSWAVELAN, &ifr) == -1)
    328   1.1  sommerfe 		err(1, "SIOCSWAVELAN");
    329   1.1  sommerfe 
    330   1.1  sommerfe 	close(s);
    331   1.1  sommerfe 
    332   1.1  sommerfe 	return;
    333   1.1  sommerfe }
    334   1.1  sommerfe 
    335   1.1  sommerfe void wi_printstr(wreq)
    336   1.1  sommerfe 	struct wi_req		*wreq;
    337   1.1  sommerfe {
    338   1.1  sommerfe 	char			*ptr;
    339   1.1  sommerfe 	int			i;
    340   1.1  sommerfe 
    341   1.1  sommerfe 	if (wreq->wi_type == WI_RID_SERIALNO) {
    342   1.1  sommerfe 		ptr = (char *)&wreq->wi_val;
    343   1.1  sommerfe 		for (i = 0; i < (wreq->wi_len - 1) * 2; i++) {
    344   1.1  sommerfe 			if (ptr[i] == '\0')
    345   1.1  sommerfe 				ptr[i] = ' ';
    346   1.1  sommerfe 		}
    347   1.1  sommerfe 	} else {
    348  1.14    tsubai 		int len = le16toh(wreq->wi_val[0]);
    349  1.14    tsubai 
    350   1.1  sommerfe 		ptr = (char *)&wreq->wi_val[1];
    351  1.14    tsubai 		for (i = 0; i < len; i++) {
    352   1.1  sommerfe 			if (ptr[i] == '\0')
    353   1.1  sommerfe 				ptr[i] = ' ';
    354   1.1  sommerfe 		}
    355   1.1  sommerfe 	}
    356   1.1  sommerfe 
    357   1.1  sommerfe 	ptr[i] = '\0';
    358   1.1  sommerfe 	printf("[ %s ]", ptr);
    359   1.1  sommerfe 
    360   1.1  sommerfe 	return;
    361   1.1  sommerfe }
    362   1.1  sommerfe 
    363   1.1  sommerfe void wi_setstr(iface, code, str)
    364   1.1  sommerfe 	char			*iface;
    365   1.1  sommerfe 	int			code;
    366   1.1  sommerfe 	char			*str;
    367   1.1  sommerfe {
    368   1.1  sommerfe 	struct wi_req		wreq;
    369   1.1  sommerfe 
    370   1.1  sommerfe 	bzero((char *)&wreq, sizeof(wreq));
    371   1.1  sommerfe 
    372   1.1  sommerfe 	if (strlen(str) > 30)
    373   1.1  sommerfe 		errx(1, "string too long");
    374   1.1  sommerfe 
    375   1.1  sommerfe 	wreq.wi_type = code;
    376   1.1  sommerfe 	wreq.wi_len = 18;
    377  1.14    tsubai 	wreq.wi_val[0] = htole16(strlen(str));
    378   1.1  sommerfe 	bcopy(str, (char *)&wreq.wi_val[1], strlen(str));
    379   1.1  sommerfe 
    380   1.1  sommerfe 	wi_setval(iface, &wreq);
    381   1.1  sommerfe 
    382   1.1  sommerfe 	return;
    383   1.1  sommerfe }
    384   1.1  sommerfe 
    385   1.1  sommerfe void wi_setbytes(iface, code, bytes, len)
    386   1.1  sommerfe 	char			*iface;
    387   1.1  sommerfe 	int			code;
    388   1.1  sommerfe 	char			*bytes;
    389   1.1  sommerfe 	int			len;
    390   1.1  sommerfe {
    391   1.1  sommerfe 	struct wi_req		wreq;
    392   1.1  sommerfe 
    393   1.1  sommerfe 	bzero((char *)&wreq, sizeof(wreq));
    394   1.1  sommerfe 
    395   1.1  sommerfe 	wreq.wi_type = code;
    396   1.1  sommerfe 	wreq.wi_len = (len / 2) + 1;
    397   1.1  sommerfe 	bcopy(bytes, (char *)&wreq.wi_val[0], len);
    398   1.1  sommerfe 
    399   1.1  sommerfe 	wi_setval(iface, &wreq);
    400   1.1  sommerfe 
    401   1.1  sommerfe 	return;
    402   1.1  sommerfe }
    403   1.1  sommerfe 
    404   1.1  sommerfe void wi_setword(iface, code, word)
    405   1.1  sommerfe 	char			*iface;
    406   1.1  sommerfe 	int			code;
    407   1.1  sommerfe 	int			word;
    408   1.1  sommerfe {
    409   1.1  sommerfe 	struct wi_req		wreq;
    410   1.1  sommerfe 
    411   1.1  sommerfe 	bzero((char *)&wreq, sizeof(wreq));
    412   1.1  sommerfe 
    413   1.1  sommerfe 	wreq.wi_type = code;
    414   1.1  sommerfe 	wreq.wi_len = 2;
    415  1.14    tsubai 	wreq.wi_val[0] = htole16(word);
    416   1.1  sommerfe 
    417   1.1  sommerfe 	wi_setval(iface, &wreq);
    418   1.1  sommerfe 
    419   1.1  sommerfe 	return;
    420   1.1  sommerfe }
    421   1.1  sommerfe 
    422   1.1  sommerfe void wi_sethex(iface, code, str)
    423   1.1  sommerfe 	char			*iface;
    424   1.1  sommerfe 	int			code;
    425   1.1  sommerfe 	char			*str;
    426   1.1  sommerfe {
    427   1.1  sommerfe 	struct ether_addr	*addr;
    428   1.1  sommerfe 
    429   1.1  sommerfe 	addr = ether_aton(str);
    430   1.1  sommerfe 	if (addr == NULL)
    431   1.1  sommerfe 		errx(1, "badly formatted address");
    432   1.1  sommerfe 
    433   1.1  sommerfe 	wi_setbytes(iface, code, (char *)addr, ETHER_ADDR_LEN);
    434   1.1  sommerfe 
    435   1.1  sommerfe 	return;
    436   1.1  sommerfe }
    437   1.1  sommerfe 
    438   1.2  explorer static void wi_printkeys(wreq)
    439   1.2  explorer         struct wi_req           *wreq;
    440   1.2  explorer {
    441   1.2  explorer         int                     i, j, bn;
    442   1.2  explorer         struct wi_key           *k;
    443   1.2  explorer         struct wi_ltv_keys      *keys;
    444   1.2  explorer         char                    *ptr;
    445   1.2  explorer 
    446   1.2  explorer 	keys = (struct wi_ltv_keys *)wreq;
    447   1.2  explorer 
    448   1.2  explorer 	for (i = 0, bn = 0; i < 4; i++, bn = 0) {
    449   1.2  explorer                 k = &keys->wi_keys[i];
    450   1.2  explorer                 ptr = (char *)k->wi_keydat;
    451  1.14    tsubai                 for (j = 0; j < le16toh(k->wi_keylen); j++) {
    452  1.10  jdolecek 		        if (!isprint((unsigned char) ptr[j])) {
    453   1.2  explorer 			        bn = 1;
    454   1.2  explorer 				break;
    455   1.2  explorer 			}
    456   1.2  explorer 		}
    457   1.2  explorer 
    458   1.2  explorer 		if (bn)	{
    459   1.2  explorer 		        printf("[ 0x");
    460  1.14    tsubai 		        for (j = 0; j < le16toh(k->wi_keylen); j++)
    461   1.2  explorer 			      printf("%02x", ((unsigned char *) ptr)[j]);
    462   1.2  explorer 			printf(" ]");
    463   1.2  explorer 		} else {
    464   1.2  explorer 		        ptr[j] = '\0';
    465   1.2  explorer 			printf("[ %s ]", ptr);
    466   1.2  explorer 		}
    467   1.2  explorer         }
    468   1.2  explorer 
    469   1.2  explorer         return;
    470   1.2  explorer };
    471   1.2  explorer 
    472   1.1  sommerfe void wi_printwords(wreq)
    473   1.1  sommerfe 	struct wi_req		*wreq;
    474   1.1  sommerfe {
    475   1.1  sommerfe 	int			i;
    476   1.1  sommerfe 
    477   1.1  sommerfe 	printf("[ ");
    478   1.1  sommerfe 	for (i = 0; i < wreq->wi_len - 1; i++)
    479  1.14    tsubai 		printf("%d ", le16toh(wreq->wi_val[i]));
    480   1.1  sommerfe 	printf("]");
    481   1.1  sommerfe 
    482   1.1  sommerfe 	return;
    483   1.1  sommerfe }
    484   1.1  sommerfe 
    485   1.1  sommerfe void wi_printbool(wreq)
    486   1.1  sommerfe 	struct wi_req		*wreq;
    487   1.1  sommerfe {
    488  1.14    tsubai 	if (le16toh(wreq->wi_val[0]))
    489   1.1  sommerfe 		printf("[ On ]");
    490   1.1  sommerfe 	else
    491   1.1  sommerfe 		printf("[ Off ]");
    492   1.1  sommerfe 
    493   1.1  sommerfe 	return;
    494   1.1  sommerfe }
    495   1.1  sommerfe 
    496   1.1  sommerfe void wi_printhex(wreq)
    497   1.1  sommerfe 	struct wi_req		*wreq;
    498   1.1  sommerfe {
    499   1.1  sommerfe 	int			i;
    500   1.1  sommerfe 	unsigned char		*c;
    501   1.1  sommerfe 
    502   1.1  sommerfe 	c = (unsigned char *)&wreq->wi_val;
    503   1.1  sommerfe 
    504   1.1  sommerfe 	printf("[ ");
    505   1.1  sommerfe 	for (i = 0; i < (wreq->wi_len - 1) * 2; i++) {
    506   1.1  sommerfe 		printf("%02x", c[i]);
    507   1.1  sommerfe 		if (i < ((wreq->wi_len - 1) * 2) - 1)
    508   1.1  sommerfe 			printf(":");
    509   1.1  sommerfe 	}
    510   1.1  sommerfe 
    511   1.1  sommerfe 	printf(" ]");
    512   1.1  sommerfe 	return;
    513   1.1  sommerfe }
    514   1.1  sommerfe 
    515  1.22       dbj void wi_printbits(wreq)
    516  1.22       dbj 	struct wi_req		*wreq;
    517  1.22       dbj {
    518  1.22       dbj 	int			i;
    519  1.22       dbj 	int bits = le16toh(wreq->wi_val[0]);
    520  1.22       dbj 
    521  1.22       dbj 	printf("[");
    522  1.22       dbj 	for (i = 0; i < 16; i++) {
    523  1.22       dbj 		if (bits & 0x1) {
    524  1.22       dbj 			printf(" %d", i+1);
    525  1.22       dbj 		}
    526  1.22       dbj 		bits >>= 1;
    527  1.22       dbj 	}
    528  1.22       dbj 	printf(" ]");
    529  1.22       dbj 	return;
    530  1.22       dbj }
    531  1.22       dbj 
    532   1.1  sommerfe static struct wi_table wi_table[] = {
    533   1.1  sommerfe 	{ WI_RID_SERIALNO, WI_STRING, "NIC serial number:\t\t\t" },
    534   1.7     enami 	{ WI_RID_NODENAME, WI_STRING, "Station name:\t\t\t\t",
    535   1.7     enami 	    's', "station name" },
    536  1.28    dyoung 	{ WI_RID_OWN_SSID, WI_STRING, "SSID for IBSS creation:\t\t\t" },
    537   1.1  sommerfe 	{ WI_RID_CURRENT_SSID, WI_STRING, "Current netname (SSID):\t\t\t" },
    538  1.28    dyoung 	{ WI_RID_DESIRED_SSID, WI_STRING, "Desired netname (SSID):\t\t\t" },
    539   1.1  sommerfe 	{ WI_RID_CURRENT_BSSID, WI_HEXBYTES, "Current BSSID:\t\t\t\t" },
    540  1.22       dbj 	{ WI_RID_CHANNEL_LIST, WI_BITS, "Channel list:\t\t\t\t" },
    541  1.28    dyoung 	{ WI_RID_OWN_CHNL, WI_WORDS, "IBSS channel:\t\t\t\t" },
    542   1.1  sommerfe 	{ WI_RID_CURRENT_CHAN, WI_WORDS, "Current channel:\t\t\t" },
    543   1.1  sommerfe 	{ WI_RID_COMMS_QUALITY, WI_WORDS, "Comms quality/signal/noise:\t\t" },
    544   1.1  sommerfe 	{ WI_RID_PROMISC, WI_BOOL, "Promiscuous mode:\t\t\t" },
    545  1.28    dyoung 	{ WI_RID_PORTTYPE, WI_WORDS, "Port type:\t\t\t\t" },
    546   1.7     enami 	{ WI_RID_MAC_NODE, WI_HEXBYTES, "MAC address:\t\t\t\t",
    547   1.7     enami 	    'm', "MAC address" },
    548  1.28    dyoung 	{ WI_RID_TX_RATE, WI_WORDS, "TX rate (selection):\t\t\t" },
    549   1.2  explorer 	{ WI_RID_CUR_TX_RATE, WI_WORDS, "TX rate (actual speed):\t\t\t"},
    550  1.27      onoe 	{ WI_RID_CUR_BEACON_INT, WI_WORDS, "Beacon Interval (current) [msec]:\t"},
    551   1.7     enami 	{ WI_RID_MAX_DATALEN, WI_WORDS, "Maximum data length:\t\t\t",
    552   1.7     enami 	    'd', "maximum data length" },
    553   1.7     enami 	{ WI_RID_RTS_THRESH, WI_WORDS, "RTS/CTS handshake threshold:\t\t",
    554   1.7     enami 	    'r', "RTS threshold" },
    555  1.28    dyoung 	{ WI_RID_FRAG_THRESH, WI_WORDS, "fragmentation threshold:\t\t",
    556  1.28    dyoung 	    'g', "fragmentation threshold" },
    557  1.28    dyoung 	{ WI_RID_DBM_ADJUST, WI_WORDS, "RSSI -> dBm adjustment:\t\t\t" },
    558  1.28    dyoung 	{ WI_RID_CREATE_IBSS, WI_BOOL, "Create IBSS:\t\t\t\t" },
    559  1.13    ichiro 	{ WI_RID_MICROWAVE_OVEN, WI_WORDS, "Microwave oven robustness:\t\t",
    560  1.15    ichiro 	    'M', "microwave oven robustness enabled" },
    561  1.13    ichiro 	{ WI_RID_ROAMING_MODE, WI_WORDS, "Roaming mode(1:firm,3:disable):\t\t",
    562  1.15    ichiro 	    'R', "roaming mode" },
    563   1.7     enami 	{ WI_RID_SYSTEM_SCALE, WI_WORDS, "Access point density:\t\t\t",
    564   1.7     enami 	    'a', "system scale" },
    565  1.28    dyoung 	{ WI_RID_PM_ENABLED, WI_WORDS, "Power Mgmt (1=on, 0=off):\t\t" },
    566  1.28    dyoung 	{ WI_RID_MAX_SLEEP, WI_WORDS, "Max sleep time (msec):\t\t\t" },
    567   1.7     enami 	{ 0, WI_NONE }
    568   1.1  sommerfe };
    569   1.1  sommerfe 
    570   1.2  explorer static struct wi_table wi_crypt_table[] = {
    571  1.28    dyoung 	{ WI_RID_ENCRYPTION, WI_BOOL, "WEP encryption:\t\t\t\t" },
    572  1.28    dyoung 	{ WI_RID_CNFAUTHMODE, WI_WORDS, "Authentication type \n(1=OpenSys, 2=Shared Key):\t\t" },
    573   1.2  explorer         { WI_RID_TX_CRYPT_KEY, WI_WORDS, "TX encryption key:\t\t\t" },
    574   1.2  explorer         { WI_RID_DEFLT_CRYPT_KEYS, WI_KEYSTRUCT, "Encryption keys:\t\t\t" },
    575   1.7     enami 	{ 0, WI_NONE }
    576   1.7     enami };
    577   1.7     enami 
    578   1.7     enami static struct wi_table *wi_tables[] = {
    579   1.7     enami 	wi_table,
    580   1.7     enami 	wi_crypt_table,
    581   1.7     enami 	NULL
    582   1.2  explorer };
    583   1.2  explorer 
    584   1.7     enami static struct wi_table *
    585   1.7     enami wi_optlookup(table, opt)
    586   1.7     enami 	struct wi_table *table;
    587   1.7     enami 	int opt;
    588   1.7     enami {
    589   1.7     enami 	struct wi_table *wt;
    590   1.7     enami 
    591   1.7     enami 	for (wt = table; wt->wi_type != 0; wt++)
    592   1.7     enami 		if (wt->wi_opt == opt)
    593   1.7     enami 			return (wt);
    594   1.7     enami 	return (NULL);
    595   1.7     enami }
    596   1.7     enami 
    597   1.1  sommerfe static void wi_dumpinfo(iface)
    598   1.1  sommerfe 	char			*iface;
    599   1.1  sommerfe {
    600   1.1  sommerfe 	struct wi_req		wreq;
    601   1.2  explorer 	int			i, has_wep;
    602   1.1  sommerfe 	struct wi_table		*w;
    603   1.1  sommerfe 
    604   1.2  explorer 	bzero((char *)&wreq, sizeof(wreq));
    605   1.2  explorer 
    606   1.2  explorer 	wreq.wi_len = WI_MAX_DATALEN;
    607   1.2  explorer 	wreq.wi_type = WI_RID_WEP_AVAIL;
    608   1.2  explorer 
    609   1.2  explorer 	wi_getval(iface, &wreq);
    610  1.14    tsubai 	has_wep = le16toh(wreq.wi_val[0]);
    611   1.2  explorer 
    612   1.1  sommerfe 	w = wi_table;
    613   1.1  sommerfe 
    614   1.7     enami 	for (i = 0; w[i].wi_code != WI_NONE; i++) {
    615   1.1  sommerfe 		bzero((char *)&wreq, sizeof(wreq));
    616   1.1  sommerfe 
    617   1.1  sommerfe 		wreq.wi_len = WI_MAX_DATALEN;
    618   1.7     enami 		wreq.wi_type = w[i].wi_type;
    619   1.1  sommerfe 
    620   1.1  sommerfe 		wi_getval(iface, &wreq);
    621   1.7     enami 		printf("%s", w[i].wi_label);
    622   1.7     enami 		switch (w[i].wi_code) {
    623   1.1  sommerfe 		case WI_STRING:
    624   1.1  sommerfe 			wi_printstr(&wreq);
    625   1.1  sommerfe 			break;
    626   1.1  sommerfe 		case WI_WORDS:
    627   1.1  sommerfe 			wi_printwords(&wreq);
    628   1.1  sommerfe 			break;
    629   1.1  sommerfe 		case WI_BOOL:
    630   1.1  sommerfe 			wi_printbool(&wreq);
    631   1.1  sommerfe 			break;
    632   1.1  sommerfe 		case WI_HEXBYTES:
    633   1.1  sommerfe 			wi_printhex(&wreq);
    634  1.22       dbj 			break;
    635  1.22       dbj 		case WI_BITS:
    636  1.22       dbj 			wi_printbits(&wreq);
    637   1.1  sommerfe 			break;
    638   1.1  sommerfe 		default:
    639   1.1  sommerfe 			break;
    640   1.1  sommerfe 		}
    641   1.1  sommerfe 		printf("\n");
    642   1.1  sommerfe 	}
    643   1.1  sommerfe 
    644   1.2  explorer 	if (has_wep) {
    645   1.2  explorer 		w = wi_crypt_table;
    646   1.7     enami 		for (i = 0; w[i].wi_code != WI_NONE; i++) {
    647   1.2  explorer 			bzero((char *)&wreq, sizeof(wreq));
    648   1.2  explorer 
    649   1.2  explorer 			wreq.wi_len = WI_MAX_DATALEN;
    650   1.7     enami 			wreq.wi_type = w[i].wi_type;
    651   1.2  explorer 
    652   1.2  explorer 			wi_getval(iface, &wreq);
    653   1.7     enami 			printf("%s", w[i].wi_label);
    654   1.7     enami 			switch (w[i].wi_code) {
    655   1.2  explorer 			case WI_STRING:
    656   1.2  explorer 				wi_printstr(&wreq);
    657   1.2  explorer 				break;
    658   1.2  explorer 			case WI_WORDS:
    659   1.2  explorer 				if (wreq.wi_type == WI_RID_TX_CRYPT_KEY)
    660  1.14    tsubai 					wreq.wi_val[0] =
    661  1.14    tsubai 					  htole16(le16toh(wreq.wi_val[0]) + 1);
    662   1.2  explorer 				wi_printwords(&wreq);
    663   1.2  explorer 				break;
    664   1.2  explorer 			case WI_BOOL:
    665   1.2  explorer 				wi_printbool(&wreq);
    666   1.2  explorer 				break;
    667   1.2  explorer 			case WI_HEXBYTES:
    668   1.2  explorer 				wi_printhex(&wreq);
    669   1.2  explorer 				break;
    670   1.2  explorer 			case WI_KEYSTRUCT:
    671   1.2  explorer 				wi_printkeys(&wreq);
    672   1.2  explorer 				break;
    673   1.2  explorer 			default:
    674   1.2  explorer 				break;
    675   1.2  explorer 			}
    676   1.2  explorer 			printf("\n");
    677   1.2  explorer 		}
    678   1.2  explorer 	}
    679   1.2  explorer 
    680   1.1  sommerfe 	return;
    681   1.1  sommerfe }
    682   1.1  sommerfe 
    683   1.1  sommerfe static void wi_dumpstats(iface)
    684   1.1  sommerfe 	char			*iface;
    685   1.1  sommerfe {
    686   1.1  sommerfe 	struct wi_req		wreq;
    687   1.1  sommerfe 	struct wi_counters	*c;
    688   1.1  sommerfe 
    689   1.1  sommerfe 	bzero((char *)&wreq, sizeof(wreq));
    690   1.1  sommerfe 	wreq.wi_len = WI_MAX_DATALEN;
    691   1.1  sommerfe 	wreq.wi_type = WI_RID_IFACE_STATS;
    692   1.1  sommerfe 
    693   1.1  sommerfe 	wi_getval(iface, &wreq);
    694   1.1  sommerfe 
    695   1.1  sommerfe 	c = (struct wi_counters *)&wreq.wi_val;
    696   1.1  sommerfe 
    697  1.14    tsubai 	/* XXX native byte order */
    698   1.1  sommerfe 	printf("Transmitted unicast frames:\t\t%d\n",
    699   1.1  sommerfe 	    c->wi_tx_unicast_frames);
    700   1.1  sommerfe 	printf("Transmitted multicast frames:\t\t%d\n",
    701   1.1  sommerfe 	    c->wi_tx_multicast_frames);
    702   1.1  sommerfe 	printf("Transmitted fragments:\t\t\t%d\n",
    703   1.1  sommerfe 	    c->wi_tx_fragments);
    704   1.1  sommerfe 	printf("Transmitted unicast octets:\t\t%d\n",
    705   1.1  sommerfe 	    c->wi_tx_unicast_octets);
    706   1.1  sommerfe 	printf("Transmitted multicast octets:\t\t%d\n",
    707   1.1  sommerfe 	    c->wi_tx_multicast_octets);
    708   1.1  sommerfe 	printf("Single transmit retries:\t\t%d\n",
    709   1.1  sommerfe 	    c->wi_tx_single_retries);
    710   1.1  sommerfe 	printf("Multiple transmit retries:\t\t%d\n",
    711   1.1  sommerfe 	    c->wi_tx_multi_retries);
    712   1.1  sommerfe 	printf("Transmit retry limit exceeded:\t\t%d\n",
    713   1.1  sommerfe 	    c->wi_tx_retry_limit);
    714   1.1  sommerfe 	printf("Transmit discards:\t\t\t%d\n",
    715   1.1  sommerfe 	    c->wi_tx_discards);
    716   1.1  sommerfe 	printf("Transmit discards due to wrong SA:\t%d\n",
    717   1.1  sommerfe 	    c->wi_tx_discards_wrong_sa);
    718   1.1  sommerfe 	printf("Received unicast frames:\t\t%d\n",
    719   1.1  sommerfe 	    c->wi_rx_unicast_frames);
    720   1.1  sommerfe 	printf("Received multicast frames:\t\t%d\n",
    721   1.1  sommerfe 	    c->wi_rx_multicast_frames);
    722   1.1  sommerfe 	printf("Received fragments:\t\t\t%d\n",
    723   1.1  sommerfe 	    c->wi_rx_fragments);
    724   1.1  sommerfe 	printf("Received unicast octets:\t\t%d\n",
    725   1.1  sommerfe 	    c->wi_rx_unicast_octets);
    726   1.1  sommerfe 	printf("Received multicast octets:\t\t%d\n",
    727   1.1  sommerfe 	    c->wi_rx_multicast_octets);
    728   1.1  sommerfe 	printf("Receive FCS errors:\t\t\t%d\n",
    729   1.1  sommerfe 	    c->wi_rx_fcs_errors);
    730   1.1  sommerfe 	printf("Receive discards due to no buffer:\t%d\n",
    731   1.1  sommerfe 	    c->wi_rx_discards_nobuf);
    732   1.1  sommerfe 	printf("Can't decrypt WEP frame:\t\t%d\n",
    733   1.1  sommerfe 	    c->wi_rx_WEP_cant_decrypt);
    734   1.1  sommerfe 	printf("Received message fragments:\t\t%d\n",
    735   1.1  sommerfe 	    c->wi_rx_msg_in_msg_frags);
    736   1.1  sommerfe 	printf("Received message bad fragments:\t\t%d\n",
    737   1.1  sommerfe 	    c->wi_rx_msg_in_bad_msg_frags);
    738   1.1  sommerfe 
    739   1.1  sommerfe 	return;
    740   1.1  sommerfe }
    741   1.1  sommerfe 
    742   1.7     enami static void
    743   1.7     enami usage()
    744   1.1  sommerfe {
    745   1.7     enami 
    746   1.2  explorer 	fprintf(stderr,
    747   1.7     enami 	    "usage: %s interface "
    748  1.28    dyoung 	    "[-oD] [-s station name]\n"
    749  1.28    dyoung 	    "       [-a access point density]\n"
    750   1.2  explorer 	    "       [-m MAC address] [-d max data length] [-r RTS threshold]\n"
    751  1.28    dyoung 	    "       [-M 0|1] [-R 1|3] [-g fragmentation threshold]\n"
    752   1.9     jhawk 	    ,
    753  1.11       cgd 	    getprogname());
    754   1.1  sommerfe 	exit(1);
    755   1.1  sommerfe }
    756   1.1  sommerfe 
    757   1.1  sommerfe int main(argc, argv)
    758   1.1  sommerfe 	int			argc;
    759   1.1  sommerfe 	char			*argv[];
    760   1.1  sommerfe {
    761   1.7     enami 	struct wi_table *wt, **table;
    762  1.28    dyoung 	char *iface;
    763  1.28    dyoung 	int ch, dumpinfo, dumpstats, apscan;
    764   1.7     enami 
    765   1.7     enami #define	SET_OPERAND(opr, desc) do {				\
    766   1.7     enami 	if ((opr) == NULL)					\
    767   1.7     enami 		(opr) = optarg;					\
    768   1.7     enami 	else							\
    769   1.7     enami 		warnx("%s is already specified to %s",		\
    770   1.7     enami 		    desc, (opr));				\
    771   1.7     enami } while (0)
    772   1.7     enami 
    773   1.7     enami 	dumpinfo = 1;
    774   1.7     enami 	dumpstats = 0;
    775  1.15    ichiro 	apscan = 0;
    776  1.28    dyoung 	iface = NULL;
    777   1.2  explorer 
    778   1.2  explorer 	if (argc > 1 && argv[1][0] != '-') {
    779   1.2  explorer 		iface = argv[1];
    780   1.5     enami 		optind++;
    781   1.2  explorer 	}
    782   1.1  sommerfe 
    783   1.3    itojun 	while ((ch = getopt(argc, argv,
    784  1.28    dyoung 	    "a:d:g:hi:m:or:s:M:R:D")) != -1) {
    785   1.7     enami 		if (ch != 'i')
    786   1.7     enami 			dumpinfo = 0;
    787   1.7     enami 		/*
    788   1.7     enami 		 * Lookup generic options and remeber operand if found.
    789   1.7     enami 		 */
    790   1.7     enami 		for (table = wi_tables; *table != NULL; table++)
    791   1.7     enami 			if ((wt = wi_optlookup(*table, ch)) != NULL) {
    792   1.7     enami 				SET_OPERAND(wt->wi_optval, wt->wi_desc);
    793   1.7     enami 				break;
    794   1.7     enami 			}
    795   1.7     enami 		if (wt == NULL)
    796   1.7     enami 			/*
    797   1.7     enami 			 * Handle special options.
    798   1.7     enami 			 */
    799   1.7     enami 			switch (ch) {
    800   1.7     enami 			case 'o':
    801   1.7     enami 				dumpstats = 1;
    802   1.7     enami 				break;
    803   1.7     enami 			case 'i':
    804   1.7     enami 				SET_OPERAND(iface, "interface");
    805   1.7     enami 				break;
    806  1.15    ichiro 			case 'D':
    807  1.15    ichiro 				apscan = 1;
    808  1.15    ichiro 				break;
    809   1.7     enami 			case 'h':
    810   1.7     enami 			default:
    811   1.7     enami 				usage();
    812   1.7     enami 				break;
    813   1.7     enami 			}
    814   1.1  sommerfe 	}
    815   1.1  sommerfe 
    816   1.1  sommerfe 	if (iface == NULL)
    817   1.7     enami 		usage();
    818   1.2  explorer 
    819   1.7     enami 	for (table = wi_tables; *table != NULL; table++)
    820   1.7     enami 		for (wt = *table; wt->wi_code != WI_NONE; wt++)
    821   1.7     enami 			if (wt->wi_optval != NULL) {
    822   1.7     enami 				switch (wt->wi_code) {
    823   1.7     enami 				case WI_BOOL:
    824   1.7     enami 				case WI_WORDS:
    825   1.7     enami 					wi_setword(iface, wt->wi_type,
    826   1.7     enami 					    atoi(wt->wi_optval));
    827   1.7     enami 					break;
    828   1.7     enami 				case WI_STRING:
    829   1.7     enami 					wi_setstr(iface, wt->wi_type,
    830   1.7     enami 					    wt->wi_optval);
    831   1.7     enami 					break;
    832   1.7     enami 				case WI_HEXBYTES:
    833   1.7     enami 					wi_sethex(iface, wt->wi_type,
    834   1.7     enami 					    wt->wi_optval);
    835   1.7     enami 					break;
    836   1.7     enami 				}
    837   1.7     enami 			}
    838   1.7     enami 
    839   1.7     enami 	if (dumpstats)
    840   1.7     enami 		wi_dumpstats(iface);
    841   1.7     enami 	if (dumpinfo)
    842   1.7     enami 		wi_dumpinfo(iface);
    843  1.18  christos 
    844  1.15    ichiro 	if (apscan)
    845  1.18  christos #ifdef WI_RID_SCAN_APS
    846  1.15    ichiro 		wi_apscan(iface);
    847  1.18  christos #else
    848  1.18  christos 		errx(1, "AP scan mode is not available.");
    849  1.18  christos #endif
    850   1.1  sommerfe 
    851   1.1  sommerfe 	exit(0);
    852   1.1  sommerfe }
    853