Home | History | Annotate | Line # | Download | only in wiconfig
wiconfig.c revision 1.2
      1 /*
      2  * Copyright (c) 1997, 1998, 1999
      3  *	Bill Paul <wpaul (at) ctr.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  *	$Id: wiconfig.c,v 1.2 2000/02/04 07:59:45 explorer Exp $
     33  */
     34 
     35 #include <sys/types.h>
     36 #include <sys/cdefs.h>
     37 #include <sys/param.h>
     38 #include <sys/socket.h>
     39 #include <sys/ioctl.h>
     40 #include <sys/socket.h>
     41 
     42 #include <net/if.h>
     43 #ifdef __FreeBSD__
     44 #include <net/if_var.h>
     45 #include <net/ethernet.h>
     46 
     47 #include <machine/if_wavelan_ieee.h>
     48 #else
     49 #include <netinet/in.h>
     50 #include <netinet/if_ether.h>
     51 #ifdef __NetBSD__
     52 #include <dev/pcmcia/if_wi_ieee.h>
     53 #else
     54 #include <dev/pcmcia/if_wavelan_ieee.h>
     55 #endif
     56 #endif
     57 
     58 #include <stdio.h>
     59 #include <string.h>
     60 #include <ctype.h>
     61 #include <stdlib.h>
     62 #include <unistd.h>
     63 #include <errno.h>
     64 #include <err.h>
     65 
     66 #if !defined(lint)
     67 static const char copyright[] = "@(#) Copyright (c) 1997, 1998, 1999\
     68 	Bill Paul. All rights reserved.";
     69 static const char rcsid[] =
     70 	"@(#) $Id: wiconfig.c,v 1.2 2000/02/04 07:59:45 explorer Exp $";
     71 #endif
     72 
     73 static void wi_getval		__P((char *, struct wi_req *));
     74 static void wi_setval		__P((char *, struct wi_req *));
     75 static void wi_printstr		__P((struct wi_req *));
     76 static void wi_setstr		__P((char *, int, char *));
     77 static void wi_setbytes		__P((char *, int, char *, int));
     78 static void wi_setword		__P((char *, int, int));
     79 static void wi_sethex		__P((char *, int, char *));
     80 static void wi_printwords	__P((struct wi_req *));
     81 static void wi_printbool	__P((struct wi_req *));
     82 static void wi_printhex		__P((struct wi_req *));
     83 static void wi_dumpinfo		__P((char *));
     84 static void wi_setkeys		__P((char *, char *, int));
     85 static void wi_printkeys	__P((struct wi_req *));
     86 static void wi_dumpstats	__P((char *));
     87 static void usage		__P((char *));
     88 static int  wi_hex2int(char c);
     89 static void wi_str2key		__P((char *, struct wi_key *));
     90 int main __P((int argc, char **argv));
     91 
     92 static void wi_getval(iface, wreq)
     93 	char			*iface;
     94 	struct wi_req		*wreq;
     95 {
     96 	struct ifreq		ifr;
     97 	int			s;
     98 
     99 	if (iface == NULL)
    100 		errx(1, "must specify interface name");
    101 
    102 	bzero((char *)&ifr, sizeof(ifr));
    103 
    104 	strcpy(ifr.ifr_name, iface);
    105 	ifr.ifr_data = (caddr_t)wreq;
    106 
    107 	s = socket(AF_INET, SOCK_DGRAM, 0);
    108 
    109 	if (s == -1)
    110 		err(1, "socket");
    111 
    112 	if (ioctl(s, SIOCGWAVELAN, &ifr) == -1)
    113 		err(1, "SIOCGWAVELAN");
    114 
    115 	close(s);
    116 
    117 	return;
    118 }
    119 
    120 static void wi_setval(iface, wreq)
    121 	char			*iface;
    122 	struct wi_req		*wreq;
    123 {
    124 	struct ifreq		ifr;
    125 	int			s;
    126 
    127 	bzero((char *)&ifr, sizeof(ifr));
    128 
    129 	strcpy(ifr.ifr_name, iface);
    130 	ifr.ifr_data = (caddr_t)wreq;
    131 
    132 	s = socket(AF_INET, SOCK_DGRAM, 0);
    133 
    134 	if (s == -1)
    135 		err(1, "socket");
    136 
    137 	if (ioctl(s, SIOCSWAVELAN, &ifr) == -1)
    138 		err(1, "SIOCSWAVELAN");
    139 
    140 	close(s);
    141 
    142 	return;
    143 }
    144 
    145 void wi_printstr(wreq)
    146 	struct wi_req		*wreq;
    147 {
    148 	char			*ptr;
    149 	int			i;
    150 
    151 	if (wreq->wi_type == WI_RID_SERIALNO) {
    152 		ptr = (char *)&wreq->wi_val;
    153 		for (i = 0; i < (wreq->wi_len - 1) * 2; i++) {
    154 			if (ptr[i] == '\0')
    155 				ptr[i] = ' ';
    156 		}
    157 	} else {
    158 		ptr = (char *)&wreq->wi_val[1];
    159 		for (i = 0; i < wreq->wi_val[0]; i++) {
    160 			if (ptr[i] == '\0')
    161 				ptr[i] = ' ';
    162 		}
    163 	}
    164 
    165 	ptr[i] = '\0';
    166 	printf("[ %s ]", ptr);
    167 
    168 	return;
    169 }
    170 
    171 void wi_setstr(iface, code, str)
    172 	char			*iface;
    173 	int			code;
    174 	char			*str;
    175 {
    176 	struct wi_req		wreq;
    177 
    178 	if (iface == NULL)
    179 		errx(1, "must specify interface name");
    180 
    181 	if (str == NULL)
    182 		errx(1, "must specify string");
    183 
    184 	bzero((char *)&wreq, sizeof(wreq));
    185 
    186 	if (strlen(str) > 30)
    187 		errx(1, "string too long");
    188 
    189 	wreq.wi_type = code;
    190 	wreq.wi_len = 18;
    191 	wreq.wi_val[0] = strlen(str);
    192 	bcopy(str, (char *)&wreq.wi_val[1], strlen(str));
    193 
    194 	wi_setval(iface, &wreq);
    195 
    196 	return;
    197 }
    198 
    199 void wi_setbytes(iface, code, bytes, len)
    200 	char			*iface;
    201 	int			code;
    202 	char			*bytes;
    203 	int			len;
    204 {
    205 	struct wi_req		wreq;
    206 
    207 	if (iface == NULL)
    208 		errx(1, "must specify interface name");
    209 
    210 	bzero((char *)&wreq, sizeof(wreq));
    211 
    212 	wreq.wi_type = code;
    213 	wreq.wi_len = (len / 2) + 1;
    214 	bcopy(bytes, (char *)&wreq.wi_val[0], len);
    215 
    216 	wi_setval(iface, &wreq);
    217 
    218 	return;
    219 }
    220 
    221 void wi_setword(iface, code, word)
    222 	char			*iface;
    223 	int			code;
    224 	int			word;
    225 {
    226 	struct wi_req		wreq;
    227 
    228 	bzero((char *)&wreq, sizeof(wreq));
    229 
    230 	wreq.wi_type = code;
    231 	wreq.wi_len = 2;
    232 	wreq.wi_val[0] = word;
    233 
    234 	wi_setval(iface, &wreq);
    235 
    236 	return;
    237 }
    238 
    239 void wi_sethex(iface, code, str)
    240 	char			*iface;
    241 	int			code;
    242 	char			*str;
    243 {
    244 	struct ether_addr	*addr;
    245 
    246 	if (str == NULL)
    247 		errx(1, "must specify address");
    248 
    249 	addr = ether_aton(str);
    250 
    251 	if (addr == NULL)
    252 		errx(1, "badly formatted address");
    253 
    254 	wi_setbytes(iface, code, (char *)addr, ETHER_ADDR_LEN);
    255 
    256 	return;
    257 }
    258 
    259 static int
    260 wi_hex2int(char c)
    261 {
    262         if (c >= '0' && c <= '9')
    263                 return (c - '0');
    264 	if (c >= 'A' && c <= 'F')
    265 	        return (c - 'A' + 10);
    266 	if (c >= 'a' && c <= 'f')
    267                 return (c - 'a' + 10);
    268 
    269 	return (0);
    270 }
    271 
    272 static void wi_str2key(s, k)
    273         char                    *s;
    274         struct wi_key           *k;
    275 {
    276         int                     n, i;
    277         char                    *p;
    278 
    279         /* Is this a hex string? */
    280         if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) {
    281                 /* Yes, convert to int. */
    282                 n = 0;
    283                 p = (char *)&k->wi_keydat[0];
    284                 for (i = 2; i < strlen(s); i+= 2) {
    285                         *p++ = (wi_hex2int(s[i]) << 4) + wi_hex2int(s[i + 1]);
    286                         n++;
    287                 }
    288                 k->wi_keylen = n;
    289         } else {
    290                 /* No, just copy it in. */
    291                 bcopy(s, k->wi_keydat, strlen(s));
    292                 k->wi_keylen = strlen(s);
    293         }
    294 
    295         return;
    296 }
    297 
    298 static void wi_setkeys(iface, key, idx)
    299         char                    *iface;
    300         char                    *key;
    301         int                     idx;
    302 {
    303         struct wi_req           wreq;
    304         struct wi_ltv_keys      *keys;
    305         struct wi_key           *k;
    306 
    307 	if (iface == NULL)
    308 		errx(1, "must specify interface name");
    309 
    310         bzero((char *)&wreq, sizeof(wreq));
    311         wreq.wi_len = WI_MAX_DATALEN;
    312         wreq.wi_type = WI_RID_WEP_AVAIL;
    313 
    314         wi_getval(iface, &wreq);
    315         if (wreq.wi_val[0] == 0)
    316                 err(1, "no WEP option available on this card");
    317 
    318         bzero((char *)&wreq, sizeof(wreq));
    319         wreq.wi_len = WI_MAX_DATALEN;
    320         wreq.wi_type = WI_RID_DEFLT_CRYPT_KEYS;
    321 
    322         wi_getval(iface, &wreq);
    323         keys = (struct wi_ltv_keys *)&wreq;
    324 
    325         if (key[0] == '0' && (key[1] == 'x' || key[1] == 'X')) {
    326 	        if (strlen(key) > 30)
    327 		        err(1, "encryption key must be no "
    328 			    "more than 28 hex digits long");
    329 	} else {
    330 	        if (strlen(key) > 14)
    331 		        err(1, "encryption key must be no "
    332 			    "more than 14 characters long");
    333 	}
    334 
    335         if (idx > 3)
    336                 err(1, "only 4 encryption keys available");
    337 
    338         k = &keys->wi_keys[idx];
    339         wi_str2key(key, k);
    340 
    341         wreq.wi_len = (sizeof(struct wi_ltv_keys) / 2) + 1;
    342         wreq.wi_type = WI_RID_DEFLT_CRYPT_KEYS;
    343         wi_setval(iface, &wreq);
    344 
    345         return;
    346 }
    347 
    348 static void wi_printkeys(wreq)
    349         struct wi_req           *wreq;
    350 {
    351         int                     i, j, bn;
    352         struct wi_key           *k;
    353         struct wi_ltv_keys      *keys;
    354         char                    *ptr;
    355 
    356 	keys = (struct wi_ltv_keys *)wreq;
    357 
    358 	for (i = 0, bn = 0; i < 4; i++, bn = 0) {
    359                 k = &keys->wi_keys[i];
    360                 ptr = (char *)k->wi_keydat;
    361                 for (j = 0; j < k->wi_keylen; j++) {
    362 		        if (!isprint(ptr[j])) {
    363 			        bn = 1;
    364 				break;
    365 			}
    366 		}
    367 
    368 		if (bn)	{
    369 		        printf("[ 0x");
    370 		        for (j = 0; j < k->wi_keylen; j++)
    371 			      printf("%02x", ((unsigned char *) ptr)[j]);
    372 			printf(" ]");
    373 		} else {
    374 		        ptr[j] = '\0';
    375 			printf("[ %s ]", ptr);
    376 		}
    377         }
    378 
    379         return;
    380 };
    381 
    382 void wi_printwords(wreq)
    383 	struct wi_req		*wreq;
    384 {
    385 	int			i;
    386 
    387 	printf("[ ");
    388 	for (i = 0; i < wreq->wi_len - 1; i++)
    389 		printf("%d ", wreq->wi_val[i]);
    390 	printf("]");
    391 
    392 	return;
    393 }
    394 
    395 void wi_printbool(wreq)
    396 	struct wi_req		*wreq;
    397 {
    398 	if (wreq->wi_val[0])
    399 		printf("[ On ]");
    400 	else
    401 		printf("[ Off ]");
    402 
    403 	return;
    404 }
    405 
    406 void wi_printhex(wreq)
    407 	struct wi_req		*wreq;
    408 {
    409 	int			i;
    410 	unsigned char		*c;
    411 
    412 	c = (unsigned char *)&wreq->wi_val;
    413 
    414 	printf("[ ");
    415 	for (i = 0; i < (wreq->wi_len - 1) * 2; i++) {
    416 		printf("%02x", c[i]);
    417 		if (i < ((wreq->wi_len - 1) * 2) - 1)
    418 			printf(":");
    419 	}
    420 
    421 	printf(" ]");
    422 	return;
    423 }
    424 
    425 #define WI_STRING		0x01
    426 #define WI_BOOL			0x02
    427 #define WI_WORDS		0x03
    428 #define WI_HEXBYTES		0x04
    429 #define WI_KEYSTRUCT            0x05
    430 
    431 struct wi_table {
    432 	int			wi_code;
    433 	int			wi_type;
    434 	char			*wi_str;
    435 };
    436 
    437 static struct wi_table wi_table[] = {
    438 	{ WI_RID_SERIALNO, WI_STRING, "NIC serial number:\t\t\t" },
    439 	{ WI_RID_NODENAME, WI_STRING, "Station name:\t\t\t\t" },
    440 	{ WI_RID_OWN_SSID, WI_STRING, "SSID for IBSS creation:\t\t\t" },
    441 	{ WI_RID_CURRENT_SSID, WI_STRING, "Current netname (SSID):\t\t\t" },
    442 	{ WI_RID_DESIRED_SSID, WI_STRING, "Desired netname (SSID):\t\t\t" },
    443 	{ WI_RID_CURRENT_BSSID, WI_HEXBYTES, "Current BSSID:\t\t\t\t" },
    444 	{ WI_RID_CHANNEL_LIST, WI_WORDS, "Channel list:\t\t\t\t" },
    445 	{ WI_RID_OWN_CHNL, WI_WORDS, "IBSS channel:\t\t\t\t" },
    446 	{ WI_RID_CURRENT_CHAN, WI_WORDS, "Current channel:\t\t\t" },
    447 	{ WI_RID_COMMS_QUALITY, WI_WORDS, "Comms quality/signal/noise:\t\t" },
    448 	{ WI_RID_PROMISC, WI_BOOL, "Promiscuous mode:\t\t\t" },
    449 	{ WI_RID_PORTTYPE, WI_WORDS, "Port type (1=BSS, 3=ad-hoc):\t\t"},
    450 	{ WI_RID_MAC_NODE, WI_HEXBYTES, "MAC address:\t\t\t\t"},
    451 	{ WI_RID_TX_RATE, WI_WORDS, "TX rate (selection):\t\t\t"},
    452 	{ WI_RID_CUR_TX_RATE, WI_WORDS, "TX rate (actual speed):\t\t\t"},
    453 	{ WI_RID_RTS_THRESH, WI_WORDS, "RTS/CTS handshake threshold:\t\t"},
    454 	{ WI_RID_CREATE_IBSS, WI_BOOL, "Create IBSS:\t\t\t\t" },
    455 	{ WI_RID_SYSTEM_SCALE, WI_WORDS, "Access point density:\t\t\t" },
    456 	{ WI_RID_PM_ENABLED, WI_WORDS, "Power Mgmt (1=on, 0=off):\t\t" },
    457 	{ WI_RID_MAX_SLEEP, WI_WORDS, "Max sleep time:\t\t\t\t" },
    458 	{ 0, NULL }
    459 };
    460 
    461 static struct wi_table wi_crypt_table[] = {
    462         { WI_RID_ENCRYPTION, WI_BOOL, "WEP encryption:\t\t\t\t" },
    463         { WI_RID_TX_CRYPT_KEY, WI_WORDS, "TX encryption key:\t\t\t" },
    464         { WI_RID_DEFLT_CRYPT_KEYS, WI_KEYSTRUCT, "Encryption keys:\t\t\t" },
    465         { 0, NULL }
    466 };
    467 
    468 static void wi_dumpinfo(iface)
    469 	char			*iface;
    470 {
    471 	struct wi_req		wreq;
    472 	int			i, has_wep;
    473 	struct wi_table		*w;
    474 
    475 	bzero((char *)&wreq, sizeof(wreq));
    476 
    477 	wreq.wi_len = WI_MAX_DATALEN;
    478 	wreq.wi_type = WI_RID_WEP_AVAIL;
    479 
    480 	wi_getval(iface, &wreq);
    481 	has_wep = wreq.wi_val[0];
    482 
    483 	w = wi_table;
    484 
    485 	for (i = 0; w[i].wi_type; i++) {
    486 		bzero((char *)&wreq, sizeof(wreq));
    487 
    488 		wreq.wi_len = WI_MAX_DATALEN;
    489 		wreq.wi_type = w[i].wi_code;
    490 
    491 		wi_getval(iface, &wreq);
    492 		printf("%s", w[i].wi_str);
    493 		switch(w[i].wi_type) {
    494 		case WI_STRING:
    495 			wi_printstr(&wreq);
    496 			break;
    497 		case WI_WORDS:
    498 			wi_printwords(&wreq);
    499 			break;
    500 		case WI_BOOL:
    501 			wi_printbool(&wreq);
    502 			break;
    503 		case WI_HEXBYTES:
    504 			wi_printhex(&wreq);
    505 			break;
    506 		default:
    507 			break;
    508 		}
    509 		printf("\n");
    510 	}
    511 
    512 	if (has_wep) {
    513 		w = wi_crypt_table;
    514 		for (i = 0; w[i].wi_type; i++) {
    515 			bzero((char *)&wreq, sizeof(wreq));
    516 
    517 			wreq.wi_len = WI_MAX_DATALEN;
    518 			wreq.wi_type = w[i].wi_code;
    519 
    520 			wi_getval(iface, &wreq);
    521 			printf("%s", w[i].wi_str);
    522 			switch(w[i].wi_type) {
    523 			case WI_STRING:
    524 				wi_printstr(&wreq);
    525 				break;
    526 			case WI_WORDS:
    527 				if (wreq.wi_type == WI_RID_TX_CRYPT_KEY)
    528 					wreq.wi_val[0]++;
    529 				wi_printwords(&wreq);
    530 				break;
    531 			case WI_BOOL:
    532 				wi_printbool(&wreq);
    533 				break;
    534 			case WI_HEXBYTES:
    535 				wi_printhex(&wreq);
    536 				break;
    537 			case WI_KEYSTRUCT:
    538 				wi_printkeys(&wreq);
    539 				break;
    540 			default:
    541 				break;
    542 			}
    543 			printf("\n");
    544 		}
    545 	}
    546 
    547 	return;
    548 }
    549 
    550 static void wi_dumpstats(iface)
    551 	char			*iface;
    552 {
    553 	struct wi_req		wreq;
    554 	struct wi_counters	*c;
    555 
    556 	if (iface == NULL)
    557 		errx(1, "must specify interface name");
    558 
    559 	bzero((char *)&wreq, sizeof(wreq));
    560 	wreq.wi_len = WI_MAX_DATALEN;
    561 	wreq.wi_type = WI_RID_IFACE_STATS;
    562 
    563 	wi_getval(iface, &wreq);
    564 
    565 	c = (struct wi_counters *)&wreq.wi_val;
    566 
    567 	printf("Transmitted unicast frames:\t\t%d\n",
    568 	    c->wi_tx_unicast_frames);
    569 	printf("Transmitted multicast frames:\t\t%d\n",
    570 	    c->wi_tx_multicast_frames);
    571 	printf("Transmitted fragments:\t\t\t%d\n",
    572 	    c->wi_tx_fragments);
    573 	printf("Transmitted unicast octets:\t\t%d\n",
    574 	    c->wi_tx_unicast_octets);
    575 	printf("Transmitted multicast octets:\t\t%d\n",
    576 	    c->wi_tx_multicast_octets);
    577 	printf("Single transmit retries:\t\t%d\n",
    578 	    c->wi_tx_single_retries);
    579 	printf("Multiple transmit retries:\t\t%d\n",
    580 	    c->wi_tx_multi_retries);
    581 	printf("Transmit retry limit exceeded:\t\t%d\n",
    582 	    c->wi_tx_retry_limit);
    583 	printf("Transmit discards:\t\t\t%d\n",
    584 	    c->wi_tx_discards);
    585 	printf("Transmit discards due to wrong SA:\t%d\n",
    586 	    c->wi_tx_discards_wrong_sa);
    587 	printf("Received unicast frames:\t\t%d\n",
    588 	    c->wi_rx_unicast_frames);
    589 	printf("Received multicast frames:\t\t%d\n",
    590 	    c->wi_rx_multicast_frames);
    591 	printf("Received fragments:\t\t\t%d\n",
    592 	    c->wi_rx_fragments);
    593 	printf("Received unicast octets:\t\t%d\n",
    594 	    c->wi_rx_unicast_octets);
    595 	printf("Received multicast octets:\t\t%d\n",
    596 	    c->wi_rx_multicast_octets);
    597 	printf("Receive FCS errors:\t\t\t%d\n",
    598 	    c->wi_rx_fcs_errors);
    599 	printf("Receive discards due to no buffer:\t%d\n",
    600 	    c->wi_rx_discards_nobuf);
    601 	printf("Can't decrypt WEP frame:\t\t%d\n",
    602 	    c->wi_rx_WEP_cant_decrypt);
    603 	printf("Received message fragments:\t\t%d\n",
    604 	    c->wi_rx_msg_in_msg_frags);
    605 	printf("Received message bad fragments:\t\t%d\n",
    606 	    c->wi_rx_msg_in_bad_msg_frags);
    607 
    608 	return;
    609 }
    610 
    611 static void usage(p)
    612 	char			*p;
    613 {
    614 	fprintf(stderr,
    615 	    "usage: wiconfig interface "
    616 	    "[-o] [-t tx rate] [-n network name] [-s station name]\n"
    617 	    "       [-e 0|1] [-k key [-v 1|2|3|4]] [-T 1|2|3|4]\n"
    618 	    "       [-c 0|1] [-q SSID] [-p port type] [-a access point density]\n"
    619 	    "       [-m MAC address] [-d max data length] [-r RTS threshold]\n"
    620 	    "       [-f frequency] [-P 0|1] [-S max sleep duration]\n");
    621 	exit(1);
    622 }
    623 
    624 int main(argc, argv)
    625 	int			argc;
    626 	char			*argv[];
    627 {
    628 	int			ch;
    629 	char			*iface = NULL;
    630 	char			*p = argv[0];
    631 	char                    *key = NULL;
    632 	int                     modifier = 0;
    633 
    634 	if (argc > 1 && argv[1][0] != '-') {
    635 		iface = argv[1];
    636 		memcpy(&argv[1], &argv[2], argc * sizeof(char *));
    637 		argc--;
    638 	}
    639 
    640 	while((ch = getopt(argc, argv,
    641 	    "hoc:d:f:p:r:q:t:n:s:i:m:P:S:T:e:k:v:")) != -1) {
    642 		switch(ch) {
    643 		case 'o':
    644 			wi_dumpstats(iface);
    645 			exit(0);
    646 			break;
    647 		case 'i':
    648 			if (iface == NULL)
    649 				iface = optarg;
    650 			break;
    651 		case 'c':
    652 			wi_setword(iface, WI_RID_CREATE_IBSS, atoi(optarg));
    653 			exit(0);
    654 			break;
    655 		case 'd':
    656 			wi_setword(iface, WI_RID_MAX_DATALEN, atoi(optarg));
    657 			exit(0);
    658 			break;
    659 		case 'f':
    660 			wi_setword(iface, WI_RID_OWN_CHNL, atoi(optarg));
    661 			exit(0);
    662 			break;
    663 		case 'p':
    664 			wi_setword(iface, WI_RID_PORTTYPE, atoi(optarg));
    665 			exit(0);
    666 			break;
    667 		case 'r':
    668 			wi_setword(iface, WI_RID_RTS_THRESH, atoi(optarg));
    669 			exit(0);
    670 			break;
    671 		case 't':
    672 			wi_setword(iface, WI_RID_TX_RATE, atoi(optarg));
    673 			exit(0);
    674 			break;
    675 		case 'n':
    676 			wi_setstr(iface, WI_RID_DESIRED_SSID, optarg);
    677 			exit(0);
    678 			break;
    679 		case 's':
    680 			wi_setstr(iface, WI_RID_NODENAME, optarg);
    681 			exit(0);
    682 			break;
    683 		case 'm':
    684 			wi_sethex(iface, WI_RID_MAC_NODE, optarg);
    685 			exit(0);
    686 			break;
    687 		case 'q':
    688 			wi_setstr(iface, WI_RID_OWN_SSID, optarg);
    689 			exit(0);
    690 			break;
    691 		case 'S':
    692 			wi_setword(iface, WI_RID_MAX_SLEEP, atoi(optarg));
    693 			exit(0);
    694 			break;
    695 		case 'P':
    696 			wi_setword(iface, WI_RID_PM_ENABLED, atoi(optarg));
    697 			exit(0);
    698 			break;
    699 		case 'T':
    700 			wi_setword(iface, WI_RID_TX_CRYPT_KEY,
    701 				   atoi(optarg) - 1);
    702 			exit(0);
    703 			break;
    704 		case 'k':
    705 		        key = optarg;
    706 			break;
    707 		case 'e':
    708 		        wi_setword(iface, WI_RID_ENCRYPTION, atoi(optarg));
    709 			exit(0);
    710 			break;
    711 		case 'v':
    712 		        modifier = atoi(optarg);
    713 			modifier--;
    714 			break;
    715 		case 'h':
    716 		default:
    717 			usage(p);
    718 			break;
    719 		}
    720 	}
    721 
    722 	if (iface == NULL)
    723 		usage(p);
    724 
    725 	if (key != NULL)
    726 	        wi_setkeys(iface, key, modifier);
    727 
    728 	wi_dumpinfo(iface);
    729 
    730 	exit(0);
    731 }
    732