diff options
author | 2006-06-27 15:19:33 +0000 | |
---|---|---|
committer | 2006-06-27 15:19:33 +0000 | |
commit | c739d1a5cab3819efc97d28f6ed10c7c8b8ef282 (patch) | |
tree | 9520c9948afe3b76d54f59ac397cf9ba926b8fdd | |
parent | add Lord Kelvin (diff) | |
download | wireguard-openbsd-c739d1a5cab3819efc97d28f6ed10c7c8b8ef282.tar.xz wireguard-openbsd-c739d1a5cab3819efc97d28f6ed10c7c8b8ef282.zip |
bye bye
-rw-r--r-- | sbin/wicontrol/Makefile | 18 | ||||
-rw-r--r-- | sbin/wicontrol/wicontrol.8 | 462 | ||||
-rw-r--r-- | sbin/wicontrol/wicontrol.c | 1032 |
3 files changed, 0 insertions, 1512 deletions
diff --git a/sbin/wicontrol/Makefile b/sbin/wicontrol/Makefile deleted file mode 100644 index fad3465aba0..00000000000 --- a/sbin/wicontrol/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# $OpenBSD: Makefile,v 1.11 2004/12/31 00:37:20 drahn Exp $ -# From: Makefile,v 1.1 1999/05/05 07:37:06 wpaul Exp $ - -.if (${MACHINE} == "i386") || (${MACHINE} == "amd64") || \ - (${MACHINE} == "alpha") || (${MACHINE} == "sparc") || \ - (${MACHINE} == "sparc64") || (${MACHINE_ARCH} == "powerpc") || \ - (${MACHINE_ARCH} == "arm") || (${MACHINE} == "hppa") -PROG= wicontrol -SRCS= wicontrol.c -.else -NOPROG= -.endif - -CFLAGS+= -Wall - -MAN= wicontrol.8 - -.include <bsd.prog.mk> diff --git a/sbin/wicontrol/wicontrol.8 b/sbin/wicontrol/wicontrol.8 deleted file mode 100644 index d939bf40b83..00000000000 --- a/sbin/wicontrol/wicontrol.8 +++ /dev/null @@ -1,462 +0,0 @@ -.\" $OpenBSD: wicontrol.8,v 1.50 2006/01/09 21:43:43 jsg Exp $ -.\" -.\" Copyright (c) 1997, 1998, 1999 -.\" Bill Paul <wpaul@ctr.columbia.edu> All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by Bill Paul. -.\" 4. Neither the name of the author nor the names of any co-contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD -.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -.\" THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD: wicontrol.8,v 1.6 1999/05/22 16:12:47 wpaul Exp $ -.\" -.Dd June 7, 2001 -.Dt WICONTROL 8 -.Os -.Sh NAME -.Nm wicontrol -.Nd configure WaveLAN/IEEE devices -.Sh SYNOPSIS -.Nm wicontrol -.Bk -words -.Op Ar interface -.Op Fl olL -.Op Fl e Ar 0|1 -.Op Fl k Ar key "[ -v 1|2|3|4 ]" -.Op Fl x Ar 0|1 -.Op Fl t Ar tx rate -.Op Fl n Ar network name -.Op Fl s Ar station name -.Op Fl c Ar 0|1 -.Op Fl q Ar SSID -.Op Fl p Ar port type -.Op Fl a Ar access point density -.Op Fl m Ar MAC address -.Op Fl d Ar max data length -.Op Fl r Ar RTS threshold -.Op Fl f Ar frequency -.Op Fl A Ar 1|2|3 -.Op Fl D Ar 0|1|2 -.Op Fl E Ar 0|1|2|3 -.Op Fl F Ar 0|1 -.Op Fl M Ar 0|1 -.Op Fl P Ar 0|1 -.Op Fl R Ar 1|3 -.Op Fl S Ar max sleep duration -.Op Fl T Ar 1|2|3|4 -.Ek -.Sh DESCRIPTION -The -.Nm -command controls the operation of WaveLAN/IEEE wireless networking -devices via the -.Xr wi 4 -and -.Xr awi 4 -drivers. -Most of the parameters that can be changed relate to the -IEEE 802.11 protocol which the WaveLAN implements. -This includes -the station name, whether the station is operating in ad-hoc (point -to point) or BSS (service set) mode, and the network name of a service -set to join (IBSS) if BSS mode is enabled. -The -.Nm -command can also be used to view the current settings of these parameters -and to dump out the values of the card's statistics counters. -.Pp -The -.Ar interface -argument given to -.Nm -should be the logical interface name associated with the WaveLAN/IEEE -device (wi0, wi1, etc...). -If none is given, wi0 is assumed. -.Pp -The -.Nm -command given without any additional flags retrieves the current card -settings from the driver and prints them out. -.Pp -The options are as follows: -.Bl -tag -width Ds -.It Fl o -Display the statistics counters for the specified WaveLAN/IEEE -interface. -The statistics are updated about once a minute. -.It Fl l -[Prism2 only] -List associated stations if the card is in Host AP mode. -.It Fl L -List all available access points. -Only the superuser may use this option. -.It Fl e Ar 0|1 -Enable or disable WEP encryption. -Permitted values are -.Ar 0 -(encryption disabled) or -.Ar 1 -(encryption enabled). -Encryption is off by default. -.It Fl k Ar key "[ -v 1|2|3|4 ]" -Set WEP encryption keys. -There are four default encryption keys that can be programmed. -A specific key can be set using the -.Fl v -flag. -If the -.Fl v -flag is not specified, the first key will be set. -Encryption keys can either -be normal text (i.e., "hello") or a series of hexadecimal digits -(i.e., "0x1234512345"). -For WaveLAN Silver cards, the key is -restricted to 40 bits, hence the key can be either a 5-character text string -or 10 hexadecimal digits. -For WaveLAN Gold cards, the key can be up to -104 bits, which means the key can be specified as either a 13-character -text string or 26 hexadecimal digits. -Either way, the key will be concatenated with a 24-bit IV to generate -the seed for RC4. -Note that -.Nm -has no way to determine whether or not a card is capable of using -104 bit WEP. -Some cards accept a 104 bit key even though they only support 40 bit -keys, in which case WEP encryption will simply fail to work. -.It Fl T Ar 1|2|3|4 -Specify which of the four WEP encryption keys will be used to encrypt -transmitted packets. -.It Fl x Ar 0|1 -[Prism2/Symbol only] -Select between firmware-based (0) and software-based (1) WEP. -Firmware-based WEP is the default. -.It Fl t Ar tx rate -Set the transmit rate of the specified interface. -The legal values -for the transmit rate vary depending on the adapter type. -The standard WaveLAN/IEEE NICs support a maximum transmit rate of 2Mbps, -and the -.Sq Turbo -NICs support a maximum speed of 5.5Mbps. -The WaveLAN/IEEE -.Sq Turbo 11Mb , -Prism-II and Prism-2.5 -NICs support a maximum speed of 11Mbps. -The following table shows the legal transmit rate settings -and the corresponding transmit speeds: -.Bl -column "TX rate" "Auto Rate Select (Standard)" -offset indent -.It Em "TX rate" Ta Em "NIC speed" -.It 1 Ta "Fixed Low (1Mbps)" -.It 2 Ta "Fixed Standard (2Mbps)" -.It 3 Ta "Auto Rate Select (High)" -.It 4 Ta "Fixed Medium (4Mbps)" -.It 5 Ta "Fixed High (5.5Mbps)" -.It 6 Ta "Auto Rate Select (Standard)" -.It 7 Ta "Auto Rate Select (Medium)" -.It 11 Ta "Fixed Turbo (11Mbps)" -.El -.Pp -The standard NICs support only settings 1 through 3. -Turbo NICs support all the above listed speed settings. -The default driver setting is 3 (auto rate select). -.It Fl n Ar network name -Set the name of the service set (BSS or IBSS) or ad-hoc network -that this station wishes to join. -The -.Ar network name -can be any text string up to 30 characters in length. -The default name is the empty string which should allow -the station to connect to the first available access point. -.It Fl s Ar station name -Sets the -.Ar station name -for the specified interface. -The -.Ar station name -is used for diagnostic purposes. -The Lucent WaveMANAGER software can poll the names of remote hosts. -.It Fl c Ar 0|1 -Allow the station to create a service set (IBSS). -Permitted values are 0 (do not create IBSS) and 1 (enable creation of IBSS). -The default is 0. -.Pp -Note: Symbol cards and older Lucent/Prism firmware revisions do not -support the creation of a service set. -.It Fl q Ar SSID -Specify the name (SSID) of an IBSS to create on a given interface. -The -.Ar SSID -can be any text string up to 32 characters long. -If the card is in IBSS creation or hostap mode, the IBSS name is -automatically set to be the same as the -.Em network name . -.It Fl p Ar port type -Set the -.Ar port type -for a specified interface. -The legal values for -.Ar port type -are 1 (BSS mode), 3 (ad-hoc mode), 4 (IBSS mode) and 6 (hostap mode). -The symbolic values -.Dq bss , -.Dq adhoc , -.Dq ibss , -and -.Dq hostap -may also be used. -The hostap mode is only available on Prism-II and Prism-2.5-based NICs. -See below for an explanation of the various port types. -.It Fl a Ar access_point_density -Specify the -.Ar access point density -for a given interface. -Legal values are 1 (low), 2 (medium) and 3 (high). -This setting influences some of the radio modem threshold settings. -.It Fl m Ar MAC address -Set the station address for the specified interface. -The -.Ar MAC address -is specified as a series of six hexadecimal values separated by colons, -e.g.: 00:60:1d:12:34:56. -This programs the new address into the card and updates the interface as well. -.It Fl d Ar max_data_length -Set the maximum receive and transmit frame size for a specified interface. -The -.Ar max data length -can be any number from 350 to 2304. -The default is 2304. -.It Fl r Ar RTS threshold -Set the RTS/CTS threshold for a given interface. -This controls the number of bytes used for the RTS/CTS handshake boundary. -The -.Ar RTS threshold -can be any value between 0 and 2047. -The default is 2047. -.It Fl f Ar frequency -Set the radio frequency of a given interface. -The -.Ar frequency -should be specified as a channel ID as shown in the table below. -The list of available frequencies is dependent on radio regulations specified -by regional authorities. -Recognized regulatory authorities include -the FCC (United States), ETSI (Europe), France and Japan. -Frequencies in the table are specified in MHz. -.Bl -column "Channel" "FCCXXXX" "ETSIXXX" "FranceX" "JapanXX" -offset indent -.Em "Channel FCC ETSI France Japan" -.It 1 Ta "2412 2412 - 2412" -.It 2 Ta "2417 2417 - 2417" -.It 3 Ta "2422* 2422* - 2422" -.It 4 Ta "2427 2427 - 2427" -.It 5 Ta "2432 2432 - 2432" -.It 6 Ta "2437 2437 - 2437" -.It 7 Ta "2442 2442 - 2442" -.It 8 Ta "2447 2447 - 2447" -.It 9 Ta "2452 2452 - 2452" -.It 10 Ta "2457* 2457 2457 2457" -.It 11 Ta "2462* 2462 2462* 2462" -.It 12 Ta "- 2467 2467 2467" -.It 13 Ta "- 2472 2472 2472" -.It 14 Ta "- - - 2484*" -.El -.Pp -If an illegal channel is specified, the -NIC will revert to its default channel, normally one of those indicated -above with a *. -Note that two stations must be set to the same channel in order to -communicate. -Note also that the channels do overlap; the bandwidth required for -each channel is about 20MHz. -When using multiple channels in close proximity it is suggested -that channels be separated by at least 25MHz. -In the US, this means that only channels 1, 6, and 11 may be used -simultaneously without interference. -.It Fl A Ar 1|2|3 -[Prism2/Symbol only] Sets the authentication type for a given interface. -Permitted values are -.Ar 1 -(Open System Authentication), -.Ar 2 -(Shared Key Authentication) and -.Ar 3 -(104-bit Shared Key Authentication). -The 104-bit Shared Key Authentication mode is only available on Symbol cards. -.Pp -When -.Em Open System Authentication -is used, any station may associate with an access point. -In effect, no authentication is done. -Note, however, that if WEP is enabled on the access point, stations will -be able to associate with the access point but will be unable to send and -receive data packets unless they have the correct WEP key. -.br -With -.Em Shared Key Authentication , -on the other hand, only stations that have the same WEP key as the access -point may associate with it. -.br -The default is 1 (Open System Authentication). -.Pp -Note: It is not valid to enable Shared Key Authentication -when no valid WEP keys have been defined. -.It Fl D Ar 0|1|2 -[Symbol only] Select the antenna diversity. -Symbol cards have both a primary and auxiliary antenna. -Either antenna may be used or the card can choose the antenna -with the best reception. -.Bl -column "Value" "Autoselect" -offset indent -.It Sy "Value" Ta Sy "Diversity" -.It 0 Ta Autoselect -.It 1 Ta Primary -.It 2 Ta Auxiliary -.El -.Pp -The default is 0 (Autoselect). -.It Fl E Ar 0|1|2|3 -[Prism only] Sets the enhanced security mode. -A value of 0 disables enhanced security mode. -A value of 1 hides the SSID name in beacon frames -(defeats passive AP scanning). -A value of 2 prevents responses to probe packets with an unspecified SSID. -A value of 3 enables both enhanced security modes. -This option is only available on Prism cards with station firmware >= 1.6.3 -and is really only useful in HostAP mode. -The default is 0. -.It Fl F Ar 0|1 -[Prism2 only] -Enable or disable processing of 802.11b frames. -When enabled, the -.Xr wi 4 -driver will process entire frames instead of stripping -off the 802.11b header that is provided by the card. -Only the superuser may use this option. -.It Fl M Ar 0|1 -Enable or disable -.Dq microwave oven robustness -on a given interface. -When enabled, smaller packets are used to reduce the impact of -consumer microwave ovens that operate in the 2.4Ghz frequency range. -This option may also be useful when there are 2.4Ghz cordless -telephones in the area. -Only works in BSS mode and requires access point support. -Requires Lucent firmware version >= 7.28. -.It Fl P Ar 0|1 -Enable or disable power management on a given interface. -Enabling power management uses an alternating sleep/wake protocol to help -conserve power on mobile stations, at the cost of some increased -receive latency. -Power management is off by default. -Note that power management requires the cooperation of an access -point in order to function; it is not functional in ad-hoc mode. -Also, power management is only implemented in Lucent WavePOINT -firmware version 2.03 or later, and in WaveLAN PCMCIA adapter -firmware 2.00 or later. -Older revisions will silently ignore the power management setting. -Legal values for this parameter are 0 (off) and 1 (on). -.It Fl R Ar 1|3 -Enable or disable roaming function on a given interface. -The legal values are -.Ar 1 -(Roaming handled by firmware) and -.Ar 3 -(Roaming Disabled). -The default is 1. -This option is not available on Symbol cards. -.It Fl S Ar max sleep interval -Specify the sleep interval to use when power management is enabled. -The -.Ar max sleep interval -is specified in milliseconds. -The default is 100. -.El -.Ss Explanation of port types -There are five modes the NIC can operate in: -.Bl -tag -width Ds -offset indent -.It BSS mode -Also known as -.Em infrastructure -mode, this is used when associating with an access point, through -which all traffic passes. -If no service set is specified via the -.Fl n -flag, the NIC will associate with whichever access point has the -strongest signal. -In general, it is a good idea to specify a service set to prevent -possible hijacking of the association. -.It ad-hoc mode -More accurately known as -.Dq ad-hoc demo mode . -This mode does not require an access point; the NIC communicates with -other ad-hoc stations within range on a peer-to-peer basis. -This mode is not specified by the IEEE 802.11 standard and there -may be problems interoperating with NICs manufactured by different -vendors. -.It IBSS mode -Also known as -.Em IEEE ad-hoc -mode or -.Em peer-to-peer -mode. -This is the standardized method of operating without an access point. -Stations associate with a service set created by an IBSS master (see below). -However, actual connections between stations are peer-to-peer as in ad-hoc mode. -Lucent firmware version 6.06 or higher, Prism2 firmware 0.8.0 or higher, -or Symbol firmware version 2.0.0 or higher is required for IBSS mode. -.It IBSS master -Also know as -.Em Host IBSS -mode. -In this mode, the station takes on part of the role of an access point, -however traffic does not pass through it to reach the other stations. -When a group of stations are operating in IBSS mode, one of them must be -the master, specifying the network name of the service set. -Symbol cards do not support operating as an IBSS master. -.It Host AP -In this mode, which is only available on Prism2 cards, the NIC acts -as an access point (base station). -Some tasks, such as beaconing and frame acknowledgement, are handled -automatically by the card firmware. -Authentication and general management of the associated stations, -however, is performed by the -.Xr wi 4 -driver itself. -Note that there are bugs in Host AP mode in Prism firmware revisions -prior to 0.8.3. -.El -.Sh SEE ALSO -.Xr wi 4 , -.Xr hostname.if 5 , -.Xr ifconfig 8 -.Sh HISTORY -The -.Nm -command first appeared in -.Ox 2.6 . -.Sh AUTHORS -The -.Nm -command was written by -.An Bill Paul Aq wpaul@ctr.columbia.edu . diff --git a/sbin/wicontrol/wicontrol.c b/sbin/wicontrol/wicontrol.c deleted file mode 100644 index 9f3a1e24ec8..00000000000 --- a/sbin/wicontrol/wicontrol.c +++ /dev/null @@ -1,1032 +0,0 @@ -/* $OpenBSD: wicontrol.c,v 1.58 2005/05/25 07:40:49 reyk Exp $ */ - -/* - * Copyright (c) 1997, 1998, 1999 - * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Bill Paul. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: wicontrol.c,v 1.6 1999/05/22 16:12:49 wpaul Exp $ - */ - -#include <sys/types.h> -#include <sys/cdefs.h> -#include <sys/param.h> -#include <sys/ioctl.h> -#include <sys/socket.h> - -#include <net/if.h> -#ifdef __FreeBSD__ -#include <net/if_var.h> -#include <net/ethernet.h> - -#include <machine/if_wavelan_ieee.h> -#else -#include <netinet/in.h> -#include <netinet/if_ether.h> -#include <net80211/ieee80211.h> - -#include <dev/ic/if_wi_ieee.h> -#include <dev/ic/if_wireg.h> -#include <dev/ic/if_wi_hostap.h> -#endif - -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#include <stdlib.h> -#include <unistd.h> -#include <errno.h> -#include <err.h> - -#if !defined(lint) -static const char copyright[] = "@(#) Copyright (c) 1997, 1998, 1999\ - Bill Paul. All rights reserved."; -static const char rcsid[] = - "@(#) $OpenBSD: wicontrol.c,v 1.58 2005/05/25 07:40:49 reyk Exp $"; -#endif - -int wi_getval(char *, struct wi_req *); -void wi_setval(char *, struct wi_req *); -void wi_printstr(struct wi_req *); -void wi_setstr(char *, int, char *); -void wi_setbytes(char *, int, char *, int); -void wi_setword(char *, int, char *); -void wi_sethex(char *, int, char *); -void wi_printwords(struct wi_req *); -void wi_printbool(struct wi_req *); -void wi_printhex(struct wi_req *); -void wi_printalgorithm(struct wi_req *wreq); -void wi_printaplist(char *); -void wi_dumpinfo(char *); -void wi_setkeys(char *, int, char *); -void wi_printkeys(struct wi_req *); -void wi_printcardid(struct wi_req *, u_int16_t); -void wi_dumpstats(char *); -void wi_dumpstations(char *); -void printb(char *, unsigned short, char *); -__dead void usage(void); -char *portid(char *); -int get_if_flags(int, const char *); -int set_if_flags(int, const char *, int); -int wi_hex2int(char c); -void wi_str2key(char *s, struct wi_key *k); - -const struct wi_card_ident wi_card_ident[] = { - WI_CARD_IDS -}; - -int -wi_getval(char *iface, struct wi_req *wreq) -{ - struct ifreq ifr; - int error = 0, i, s; - - s = socket(AF_INET, SOCK_DGRAM, 0); - if (s == -1) - err(1, "socket"); - - for (i = 10; --i; sleep(1)) { - bzero((char *)&ifr, sizeof(ifr)); - strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)); - ifr.ifr_data = (caddr_t)wreq; - error = ioctl(s, SIOCGWAVELAN, &ifr); - if (error != -1 || errno != EINPROGRESS) - break; - } - - if (error == -1) { - warn("SIOCGWAVELAN (0x%x)", wreq->wi_type); - if (errno == ENXIO || errno == EINVAL) - exit(1); - } - close(s); - return (error); -} - -void -wi_setval(char *iface, struct wi_req *wreq) -{ - struct ifreq ifr; - int s; - - bzero((char *)&ifr, sizeof(ifr)); - - strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)); - ifr.ifr_data = (caddr_t)wreq; - - s = socket(AF_INET, SOCK_DGRAM, 0); - if (s == -1) - err(1, "socket"); - - if (ioctl(s, SIOCSWAVELAN, &ifr) == -1) - err(1, "SIOCSWAVELAN"); - - close(s); -} - -void -wi_printstr(struct wi_req *wreq) -{ - char *ptr; - int i, max; - - if (wreq->wi_type == WI_RID_SERIALNO) { - ptr = (char *)&wreq->wi_val; - max = MIN(sizeof(wreq->wi_val) - 1, (wreq->wi_len - 1) * 2); - for (i = 0; i < max; i++) { - if (ptr[i] == '\0') - ptr[i] = ' '; - } - } else { - int len = letoh16(wreq->wi_val[0]); - - ptr = (char *)&wreq->wi_val[1]; - max = MIN(sizeof(wreq->wi_val) - 1, len); - for (i = 0; i < max; i++) { - if (ptr[i] == '\0') - ptr[i] = ' '; - } - } - - ptr[i] = '\0'; - printf("[ %s ]", ptr); -} - -void -wi_setstr(char *iface, int code, char *str) -{ - struct wi_req wreq; - - if (str == NULL) - errx(1, "must specify string"); - - bzero((char *)&wreq, sizeof(wreq)); - - if (strlen(str) > IEEE80211_NWID_LEN) - errx(1, "string too long"); - - wreq.wi_type = code; - wreq.wi_len = 18; - wreq.wi_val[0] = htole16(strlen(str)); - bcopy(str, (char *)&wreq.wi_val[1], strlen(str)); - - wi_setval(iface, &wreq); -} - -void -wi_setbytes(char *iface, int code, char *bytes, int len) -{ - struct wi_req wreq; - - bzero((char *)&wreq, sizeof(wreq)); - - wreq.wi_type = code; - wreq.wi_len = (len / 2) + 1; - bcopy(bytes, (char *)&wreq.wi_val[0], len); - - wi_setval(iface, &wreq); -} - -void -wi_setword(char *iface, int code, char *word) -{ - struct wi_req wreq; - int value = strtol(word, NULL, 10); - - bzero((char *)&wreq, sizeof(wreq)); - - wreq.wi_type = code; - wreq.wi_len = 2; - wreq.wi_val[0] = htole16(value); - - wi_setval(iface, &wreq); -} - -void -wi_sethex(char *iface, int code, char *str) -{ - struct ether_addr *addr; - - if (str == NULL) - errx(1, "must specify address"); - - addr = ether_aton(str); - if (addr == NULL) - errx(1, "badly formatted address"); - - wi_setbytes(iface, code, (char *)addr, ETHER_ADDR_LEN); -} - -int -wi_hex2int(char c) -{ - if (c >= '0' && c <= '9') - return (c - '0'); - if (c >= 'A' && c <= 'F') - return (c - 'A' + 10); - if (c >= 'a' && c <= 'f') - return (c - 'a' + 10); - - return (0); -} - -void -wi_str2key(char *s, struct wi_key *k) -{ - int n, i; - char *p; - - /* Is this a hex string? */ - if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) { - /* Yes, convert to int. */ - n = 0; - p = (char *)&k->wi_keydat[0]; - for (i = 2; i < strlen(s); i+= 2) { - *p++ = (wi_hex2int(s[i]) << 4) + wi_hex2int(s[i + 1]); - n++; - } - k->wi_keylen = htole16(n); - } else { - /* No, just copy it in. */ - bcopy(s, k->wi_keydat, strlen(s)); - k->wi_keylen = htole16(strlen(s)); - } -} - -void -wi_setkeys(char *iface, int idx, char *key) -{ - struct wi_req wreq; - struct wi_ltv_keys *keys; - struct wi_key *k; - - bzero((char *)&wreq, sizeof(wreq)); - wreq.wi_len = WI_MAX_DATALEN; - wreq.wi_type = WI_RID_WEP_AVAIL; - - wi_getval(iface, &wreq); - if (letoh16(wreq.wi_val[0]) == 0) - errx(1, "no WEP option available on this card"); - - bzero((char *)&wreq, sizeof(wreq)); - wreq.wi_len = WI_MAX_DATALEN; - wreq.wi_type = WI_RID_DEFLT_CRYPT_KEYS; - - wi_getval(iface, &wreq); - keys = (struct wi_ltv_keys *)&wreq; - - if (key[0] == '0' && (key[1] == 'x' || key[1] == 'X')) { - if (strlen(key) > 28) - errx(1, "encryption key must be no " - "more than 26 hex digits long"); - } else { - if (strlen(key) > 13) - errx(1, "encryption key must be no " - "more than 13 characters long"); - } - - if (idx > 3) - errx(1, "only 4 encryption keys available"); - - k = &keys->wi_keys[idx]; - wi_str2key(key, k); - - wreq.wi_len = (sizeof(struct wi_ltv_keys) / 2) + 1; - wreq.wi_type = WI_RID_DEFLT_CRYPT_KEYS; - wi_setval(iface, &wreq); -} - -void -wi_printkeys(struct wi_req *wreq) -{ - int i, j, bn; - struct wi_key *k; - struct wi_ltv_keys *keys; - char *ptr; - - keys = (struct wi_ltv_keys *)wreq; - - for (i = 0, bn = 0; i < 4; i++, bn = 0) { - k = &keys->wi_keys[i]; - ptr = (char *)k->wi_keydat; - for (j = 0; j < letoh16(k->wi_keylen); j++) { - /* Only print 7-bit ASCII keys */ - if (ptr[j] & 0x80 || !isprint((unsigned char)ptr[j])) { - bn = 1; - break; - } - } - - if (bn) { - printf("[ 0x"); - for (j = 0; j < letoh16(k->wi_keylen); j++) - printf("%02x", ((unsigned char *) ptr)[j]); - printf(" ]"); - } else { - ptr[j] = '\0'; - printf("[ %s ]", ptr); - } - } -} - -void -wi_printcardid(struct wi_req *wreq, u_int16_t chip_id) -{ - const char *chip_name; - const struct wi_card_ident *id; - - if (wreq->wi_len < 4) - return; - - for (id = wi_card_ident; id->firm_type != WI_NOTYPE; id++) { - if (chip_id == id->card_id) - break; - } - if (id->firm_type != WI_NOTYPE) - chip_name = id->card_name; - else { - if (chip_id & htole16(0x8000)) - chip_name = "Unknown PRISM chip"; - else - chip_name = "Unknown Lucent chip"; - } - - /* XXX - doesn't decode Symbol firmware */ - if (chip_id & htole16(0x8000)) - printf("[ %s, Firmware %d.%d.%d ]", chip_name, - letoh16(wreq->wi_val[2]), letoh16(wreq->wi_val[3]), - letoh16(wreq->wi_val[1])); - else - printf("[ %s, Firmware %d.%02d variant %d ]", chip_name, - letoh16(wreq->wi_val[2]), letoh16(wreq->wi_val[3]), - letoh16(wreq->wi_val[1])); -} - -void -wi_printwords(struct wi_req *wreq) -{ - int i; - - printf("[ "); - for (i = 0; i < wreq->wi_len - 1; i++) - printf("%d ", letoh16(wreq->wi_val[i])); - printf("]"); -} - -void -wi_printbool(struct wi_req *wreq) -{ - if (letoh16(wreq->wi_val[0])) - printf("[ On ]"); - else - printf("[ Off ]"); -} - -void -wi_printhex(struct wi_req *wreq) -{ - int i; - unsigned char *c; - - c = (unsigned char *)&wreq->wi_val; - - printf("[ "); - for (i = 0; i < (wreq->wi_len - 1) * 2; i++) { - printf("%02x", c[i]); - if (i < ((wreq->wi_len - 1) * 2) - 1) - printf(":"); - } - - printf(" ]"); -} - -void -wi_printalgorithm(struct wi_req *wreq) -{ - switch(letoh16(wreq->wi_val[0])) { - case WI_CRYPTO_FIRMWARE_WEP: - printf("[ Firmware WEP ]"); - break; - case WI_CRYPTO_SOFTWARE_WEP: - printf("[ Software WEP ]"); - break; - default: - printf("[ Unknown ]"); - break; - } -} - -void -wi_printaplist(char *iface) -{ - int prism2, len, i = 0, j, s, flags, nap; - struct wi_req wreq; - struct wi_scan_p2_hdr *wi_p2_h; - struct wi_scan_res *res; - - s = socket(AF_INET, SOCK_DGRAM, 0); - if (s == -1) - err(1, "socket"); - flags = get_if_flags(s, iface); - if ((flags & IFF_UP) == 0) - flags = set_if_flags(s, iface, flags | IFF_UP); - - /* first determine whether this is a prism2 card or not */ - wreq.wi_len = WI_MAX_DATALEN; - wreq.wi_type = WI_RID_PRISM2; - - if (wi_getval(iface, &wreq) == -1) - goto done; - prism2 = wreq.wi_val[0]; - - /* send out a scan request */ - wreq.wi_len = prism2 ? 3 : 1; - wreq.wi_type = WI_RID_SCAN_REQ; - - if (prism2) { - wreq.wi_val[0] = 0x3FFF; - wreq.wi_val[1] = 0x000F; - } - - wi_setval(iface, &wreq); - - /* - * sleep for 200 milliseconds so there's enough time for the card - * to respond... prism2's take a little longer. - */ - usleep(prism2 ? 700000 : 200000); - - /* get the scan results */ - wreq.wi_len = WI_MAX_DATALEN; - wreq.wi_type = WI_RID_SCAN_RES; - - if (wi_getval(iface, &wreq) == -1) - goto done; - - if (prism2) { - wi_p2_h = (struct wi_scan_p2_hdr *)wreq.wi_val; - - /* if the reason is 0, this info is invalid */ - if (wi_p2_h->wi_reason == 0) - return; - - i = 4; - } - - len = prism2 ? WI_PRISM2_RES_SIZE : WI_WAVELAN_RES_SIZE; - - printf("AP Information\n"); - - for (nap = 0; i < (wreq.wi_len * 2) - len; i += len) { - res = (struct wi_scan_res *)((char *)wreq.wi_val + i); - - res->wi_ssid[letoh16(res->wi_ssid_len)] = '\0'; - res->wi_chan = letoh16(res->wi_chan); - res->wi_noise = letoh16(res->wi_noise); - res->wi_signal = letoh16(res->wi_signal); - res->wi_interval = letoh16(res->wi_interval); - res->wi_capinfo = letoh16(res->wi_capinfo); - - printf("ap[%d]:", nap++); - printf("\tnetname (SSID):\t\t\t[ %s ]\n", res->wi_ssid); - printf("\tBSSID:\t\t\t\t[ %02x:%02x:%02x:%02x:%02x:%02x ]\n", - res->wi_bssid[0], res->wi_bssid[1], - res->wi_bssid[2], res->wi_bssid[3], - res->wi_bssid[4], res->wi_bssid[5]); - printf("\tChannel:\t\t\t[ %d ]\n", res->wi_chan); - printf("\tBeacon Interval:\t\t[ %d ]\n", res->wi_interval); - printf("\tQuality/Signal/Noise [signal]:\t[ %d / %d / %d ]\n", - res->wi_signal - res->wi_noise, res->wi_signal, - res->wi_noise); - if (!prism2) - printf("\t\t\t\t[dBm]:\t[ %d / %d / %d ]\n", - res->wi_signal - res->wi_noise, - res->wi_signal - 149, res->wi_noise - 149); - - if (res->wi_capinfo) { - printf("\tCapinfo:\t\t\t[ "); - if (res->wi_capinfo & WI_CAPINFO_ESS) - printf("ESS "); - if (res->wi_capinfo & WI_CAPINFO_IBSS) - printf("IBSS "); - if (res->wi_capinfo & WI_CAPINFO_PRIV) - printf("PRIV "); - printf("]\n"); - } - - if (prism2) { - printf("\tDataRate [Mbps]:\t\t[ %2.1f ]\n", - res->wi_rate == 0xa ? 1 : - (res->wi_rate == 0x14 ? 2 : - (res->wi_rate == 0x37 ? 5.5 : - (res->wi_rate == 0x6e ? 11 : 0)))); - - printf("\tAvailableRates [Mbps]:\t\t[ "); - for (j = 0; res->wi_srates[j] != 0; j++) { - res->wi_srates[j] = res->wi_srates[j] & - WI_VAR_SRATES_MASK; - printf("%d.%d ", res->wi_srates[j] / 2, - (res->wi_srates[j] % 2) * 5); - } - printf("]\n"); - } - } -done: - set_if_flags(s, iface, flags); - close(s); - return; -} - -#define WI_STRING 0x01 -#define WI_BOOL 0x02 -#define WI_WORDS 0x03 -#define WI_HEXBYTES 0x04 -#define WI_KEYSTRUCT 0x05 -#define WI_CARDINFO 0x06 -#define WI_ALGORITHM 0x07 - -struct wi_table { - int wi_code; - int wi_type; - char *wi_str; -}; - -struct wi_table wi_table[] = { - { WI_RID_SERIALNO, WI_STRING, "NIC serial number:\t\t\t" }, - { WI_RID_NODENAME, WI_STRING, "Station name:\t\t\t\t" }, - { WI_RID_OWN_SSID, WI_STRING, "SSID for IBSS creation:\t\t\t" }, - { WI_RID_CURRENT_SSID, WI_STRING, "Current netname (SSID):\t\t\t" }, - { WI_RID_DESIRED_SSID, WI_STRING, "Desired netname (SSID):\t\t\t" }, - { WI_RID_CURRENT_BSSID, WI_HEXBYTES, "Current BSSID:\t\t\t\t" }, - { WI_RID_CHANNEL_LIST, WI_WORDS, "Channel list:\t\t\t\t" }, - { WI_RID_OWN_CHNL, WI_WORDS, "IBSS channel:\t\t\t\t" }, - { WI_RID_CURRENT_CHAN, WI_WORDS, "Current channel:\t\t\t" }, - { WI_RID_COMMS_QUALITY, WI_WORDS, "Comms quality/signal/noise:\t\t" }, - { WI_RID_PROMISC, WI_BOOL, "Promiscuous mode:\t\t\t" }, - { WI_RID_PROCFRAME, WI_BOOL, "Process 802.11b Frame:\t\t\t" }, - { WI_RID_PORTTYPE, WI_WORDS, "Port type (1=BSS, 3=ad-hoc, 6=Host AP):\t"}, - { WI_RID_MAC_NODE, WI_HEXBYTES, "MAC address:\t\t\t\t"}, - { WI_RID_TX_RATE, WI_WORDS, "TX rate (selection):\t\t\t"}, - { WI_RID_CUR_TX_RATE, WI_WORDS, "TX rate (actual speed):\t\t\t"}, - { WI_RID_MAX_DATALEN, WI_WORDS, "Maximum data length:\t\t\t"}, - { WI_RID_RTS_THRESH, WI_WORDS, "RTS/CTS handshake threshold:\t\t"}, - { WI_RID_CREATE_IBSS, WI_BOOL, "Create IBSS:\t\t\t\t" }, - { WI_RID_SYMBOL_DIVERSITY, WI_WORDS, "Antenna diversity (0=auto,1=pri,2=aux):\t"}, - { WI_RID_MICROWAVE_OVEN, WI_BOOL, "Microwave oven robustness:\t\t"}, - { WI_RID_ROAMING_MODE, WI_WORDS, "Roaming mode(1=firm,3=disable):\t\t"}, - { WI_RID_SYSTEM_SCALE, WI_WORDS, "Access point density:\t\t\t" }, - { WI_RID_PM_ENABLED, WI_BOOL, "Power Management:\t\t\t" }, - { WI_RID_MAX_SLEEP, WI_WORDS, "Max sleep time:\t\t\t\t" }, - { WI_RID_ENH_SECURITY, WI_WORDS, "Enhanced Security mode:\t\t\t" }, - { WI_RID_PRISM2, WI_WORDS, "Intersil Prism2-based card:\t\t" }, - { WI_RID_STA_IDENTITY, WI_CARDINFO, "Card info:\t\t\t\t" }, - { 0, NULL } -}; - -struct wi_table wi_crypt_table[] = { - { WI_RID_ENCRYPTION, WI_BOOL, "Encryption:\t\t\t\t" }, - { WI_FRID_CRYPTO_ALG, WI_ALGORITHM, "Encryption algorithm:\t\t\t" }, - { WI_RID_CNFAUTHMODE, WI_WORDS, - "Authentication type \n(1=OpenSys, 2=Shared Key):\t\t" }, - { WI_RID_TX_CRYPT_KEY, WI_WORDS, "TX encryption key:\t\t\t" }, - { WI_RID_DEFLT_CRYPT_KEYS, WI_KEYSTRUCT, "Encryption keys:\t\t\t" }, - { 0, NULL } -}; - -void -wi_dumpinfo(char *iface) -{ - struct wi_req wreq; - int i, has_wep, chip_id; - struct wi_table *w; - - /* Get chip ID. */ - bzero((char *)&wreq, sizeof(wreq)); - wreq.wi_type = WI_RID_CARD_ID; - wreq.wi_len = 5; - wi_getval(iface, &wreq); - chip_id = letoh16(wreq.wi_val[0]); - - /* Check for WEP support. */ - bzero((char *)&wreq, sizeof(wreq)); - wreq.wi_type = WI_RID_WEP_AVAIL; - wreq.wi_len = 2; - wi_getval(iface, &wreq); - has_wep = letoh16(wreq.wi_val[0]); - - w = wi_table; - - for (i = 0; w[i].wi_type; i++) { - bzero((char *)&wreq, sizeof(wreq)); - - wreq.wi_len = WI_MAX_DATALEN; - wreq.wi_type = w[i].wi_code; - - wi_getval(iface, &wreq); - printf("%s", w[i].wi_str); - switch (w[i].wi_type) { - case WI_STRING: - wi_printstr(&wreq); - break; - case WI_WORDS: - wi_printwords(&wreq); - break; - case WI_BOOL: - wi_printbool(&wreq); - break; - case WI_HEXBYTES: - wi_printhex(&wreq); - break; - case WI_CARDINFO: - wi_printcardid(&wreq, chip_id); - break; - default: - break; - } - printf("\n"); - } - - if (has_wep) { - w = wi_crypt_table; - for (i = 0; w[i].wi_type; i++) { - bzero((char *)&wreq, sizeof(wreq)); - - wreq.wi_len = WI_MAX_DATALEN; - wreq.wi_type = w[i].wi_code; - - wi_getval(iface, &wreq); - printf("%s", w[i].wi_str); - switch (w[i].wi_type) { - case WI_STRING: - wi_printstr(&wreq); - break; - case WI_WORDS: - if (wreq.wi_type == WI_RID_TX_CRYPT_KEY) - wreq.wi_val[0] = - htole16(letoh16(wreq.wi_val[0]) + 1); - wi_printwords(&wreq); - break; - case WI_BOOL: - wi_printbool(&wreq); - break; - case WI_HEXBYTES: - wi_printhex(&wreq); - break; - case WI_KEYSTRUCT: - wi_printkeys(&wreq); - break; - case WI_ALGORITHM: - wi_printalgorithm(&wreq); - break; - default: - break; - } - printf("\n"); - } - } -} - -void -wi_dumpstats(char *iface) -{ - struct wi_req wreq; - struct wi_counters *c; - - bzero((char *)&wreq, sizeof(wreq)); - wreq.wi_len = WI_MAX_DATALEN; - wreq.wi_type = WI_RID_IFACE_STATS; - - wi_getval(iface, &wreq); - - c = (struct wi_counters *)&wreq.wi_val; - - /* XXX native byte order */ - printf("Transmitted unicast frames:\t\t%u\n", - c->wi_tx_unicast_frames); - printf("Transmitted multicast frames:\t\t%u\n", - c->wi_tx_multicast_frames); - printf("Transmitted fragments:\t\t\t%u\n", - c->wi_tx_fragments); - printf("Transmitted unicast octets:\t\t%u\n", - c->wi_tx_unicast_octets); - printf("Transmitted multicast octets:\t\t%u\n", - c->wi_tx_multicast_octets); - printf("Single transmit retries:\t\t%u\n", - c->wi_tx_single_retries); - printf("Multiple transmit retries:\t\t%u\n", - c->wi_tx_multi_retries); - printf("Transmit retry limit exceeded:\t\t%u\n", - c->wi_tx_retry_limit); - printf("Transmit discards:\t\t\t%u\n", - c->wi_tx_discards); - printf("Transmit discards due to wrong SA:\t%u\n", - c->wi_tx_discards_wrong_sa); - printf("Received unicast frames:\t\t%u\n", - c->wi_rx_unicast_frames); - printf("Received multicast frames:\t\t%u\n", - c->wi_rx_multicast_frames); - printf("Received fragments:\t\t\t%u\n", - c->wi_rx_fragments); - printf("Received unicast octets:\t\t%u\n", - c->wi_rx_unicast_octets); - printf("Received multicast octets:\t\t%u\n", - c->wi_rx_multicast_octets); - printf("Receive FCS errors:\t\t\t%u\n", - c->wi_rx_fcs_errors); - printf("Receive discards due to no buffer:\t%u\n", - c->wi_rx_discards_nobuf); - printf("Can't decrypt WEP frame:\t\t%u\n", - c->wi_rx_WEP_cant_decrypt); - printf("Received message fragments:\t\t%u\n", - c->wi_rx_msg_in_msg_frags); - printf("Received message bad fragments:\t\t%u\n", - c->wi_rx_msg_in_bad_msg_frags); -} - -void -wi_dumpstations(char *iface) -{ - struct hostap_getall reqall; - struct hostap_sta stas[WIHAP_MAX_STATIONS]; - struct ifreq ifr; - int i, s; - - bzero(&ifr, sizeof(ifr)); - strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)); - ifr.ifr_data = (caddr_t) & reqall; - bzero(&reqall, sizeof(reqall)); - reqall.size = sizeof(stas); - reqall.addr = stas; - bzero(&stas, sizeof(stas)); - - s = socket(AF_INET, SOCK_DGRAM, 0); - if (s == -1) - err(1, "socket"); - - if (ioctl(s, SIOCHOSTAP_GETALL, &ifr) < 0) - err(1, "SIOCHOSTAP_GETALL"); - - printf("%d station%s:\n", reqall.nstations, reqall.nstations>1?"s":""); - for (i = 0; i < reqall.nstations; i++) { - struct hostap_sta *info = &stas[i]; - - printf("%02x:%02x:%02x:%02x:%02x:%02x asid=%04x", - info->addr[0], info->addr[1], info->addr[2], - info->addr[3], info->addr[4], info->addr[5], - info->asid - 0xc001); - - printb(", flags", info->flags, HOSTAP_FLAGS_BITS); - printb(", caps", info->capinfo, IEEE80211_CAPINFO_BITS); - printb(", rates", info->rates, WI_RATES_BITS); - if (info->sig_info) - printf(", sig=%d/%d", - info->sig_info >> 8, info->sig_info & 0xff); - putchar('\n'); - } - close(s); -} - -__dead void -usage(void) -{ - extern char *__progname; - - fprintf(stderr, - "usage: %s [interface] [-olL] [-t tx rate] [-n network name]\n" - " [-s station name] [-e 0|1] [-k key [-v 1|2|3|4]] [-T 1|2|3|4]\n" - " [-x 0|1] [-F 0|1] [-c 0|1] [-q SSID] [-p port type]\n" - " [-a access point density] [-m MAC address] [-d max data length]\n" - " [-r RTS threshold] [-f frequency] [-M 0|1] [-P 0|1]\n" - " [-S max sleep duration] [-A 1|2|3] [-D 0|1|2] [-R 1|3] [-E 0|1|2|3]\n", - __progname); - exit(1); -} - -struct wi_func { - int key; - void (*function) (char *, int, char *); - int wi_code; - char *optarg; -}; - -struct wi_func wi_opt[] = { - { 'k', wi_setkeys, 0, NULL }, /* MUST be first entry in table */ - { 'a', wi_setword, WI_RID_SYSTEM_SCALE, NULL }, - { 'c', wi_setword, WI_RID_CREATE_IBSS, NULL }, - { 'd', wi_setword, WI_RID_MAX_DATALEN, NULL }, - { 'e', wi_setword, WI_RID_ENCRYPTION, NULL }, - { 'f', wi_setword, WI_RID_OWN_CHNL, NULL }, - { 'm', wi_sethex, WI_RID_MAC_NODE, NULL }, - { 'n', wi_setstr, WI_RID_DESIRED_SSID, NULL }, - { 'p', wi_setword, WI_RID_PORTTYPE, NULL }, - { 'q', wi_setstr, WI_RID_OWN_SSID, NULL }, - { 'r', wi_setword, WI_RID_RTS_THRESH, NULL }, - { 's', wi_setstr, WI_RID_NODENAME, NULL }, - { 't', wi_setword, WI_RID_TX_RATE, NULL }, - { 'x', wi_setword, WI_FRID_CRYPTO_ALG, NULL }, - { 'A', wi_setword, WI_RID_CNFAUTHMODE, NULL }, - { 'D', wi_setword, WI_RID_SYMBOL_DIVERSITY, NULL }, - { 'E', wi_setword, WI_RID_ENH_SECURITY, NULL }, - { 'M', wi_setword, WI_RID_MICROWAVE_OVEN, NULL }, - { 'P', wi_setword, WI_RID_PM_ENABLED, NULL }, - { 'R', wi_setword, WI_RID_ROAMING_MODE, NULL }, - { 'S', wi_setword, WI_RID_MAX_SLEEP, NULL }, - { 'T', wi_setword, WI_RID_TX_CRYPT_KEY, NULL }, - { 'F', wi_setword, WI_RID_PROCFRAME, NULL }, - - /* These options will never be command line options which is why - they are not 'quoted' */ - { 1, wi_setkeys, 0, NULL }, /* Dummy option for key 0 */ - { 2, wi_setkeys, 1, NULL }, /* key 1 */ - { 3, wi_setkeys, 2, NULL }, /* key 2 */ - { 4, wi_setkeys, 3, NULL }, /* key 3 */ - { 0, NULL, 0, NULL } -}; - -int -main(int argc, char *argv[]) -{ - int ch, p, dumpstats = 0, dumpinfo = 1, ifspecified = 0; - int listaps = 0, dumpstations = 0; - char *iface; - - iface = "wi0"; - if (argc > 1 && argv[1][0] != '-') { - iface = argv[1]; - ifspecified = 1; - optind = 2; - } - - while ((ch = getopt(argc, argv, - "a:c:d:e:f:hi:k:lm:n:op:q:r:s:t:v:x:A:D:E:F:LM:S:P:R:T:")) != -1) { - dumpinfo = 0; - for (p = 0; ch && wi_opt[p].key; p++) - if (ch == wi_opt[p].key) { - if (ch == 'p' && !isdigit(*optarg)) - wi_opt[p].optarg = portid(optarg); - else - wi_opt[p].optarg = optarg; - if (ch == 'T') /* key 1-4/0-3 kludge */ - (*optarg)--; - dumpinfo = ch = 0; - } - switch (ch) { - case '\0': - break; - case 'i': - if (!ifspecified) - iface = optarg; - break; - case 'l': - dumpstations++; - break; - case 'L': - listaps++; - break; - case 'o': - dumpstats++; - break; - case 'v': - for (p = 0; wi_opt[p].key; p++) - if (wi_opt[p].key == - strtol(optarg, NULL, 10)) { - wi_opt[p].optarg = wi_opt[0].optarg; - /* prevent multiple -v without - multiple -k */ - wi_opt[0].optarg = NULL; - break; - } - break; - case 'h': - default: - usage(); - break; - } - } - - for (p = 0; wi_opt[p].key; p++) - if (wi_opt[p].optarg != NULL) - wi_opt[p].function(iface, wi_opt[p].wi_code, - wi_opt[p].optarg); - - if (listaps) - wi_printaplist(iface); - - if (dumpstations) - wi_dumpstations(iface); - - if (dumpstats && !listaps && !dumpstations) - wi_dumpstats(iface); - - if (dumpinfo && !dumpstats && !listaps && !dumpstations) - wi_dumpinfo(iface); - - exit(0); -} - -int -get_if_flags(int s, const char *name) -{ - struct ifreq ifr; - int flags; - - bzero(&ifr, sizeof(ifr)); - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); - if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) == -1) - err(1, "SIOCGIFFLAGS"); - flags = ifr.ifr_flags; - - return (flags); -} - -int -set_if_flags(int s, const char *name, int flags) -{ - struct ifreq ifr; - - bzero(&ifr, sizeof(ifr)); - ifr.ifr_flags = flags; - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); - if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&ifr) == -1) - err(1, "SIOCSIFFLAGS"); - - return (0); -} - -/* - * Print a value a la the %b format of the kernel's printf - * (ripped screaming from ifconfig/ifconfig.c) - */ -void -printb(char *s, unsigned short v, char *bits) -{ - int i, any = 0; - char c; - - if (bits && *bits == 8) - printf("%s=%o", s, v); - else - printf("%s=%x", s, v); - bits++; - if (bits) { - putchar('<'); - while ((i = *bits++)) { - if (v & (1 << (i-1))) { - if (any) - putchar(','); - any = 1; - for (; (c = *bits) > 32; bits++) - putchar(c); - } else - for (; *bits > 32; bits++) - ; - } - putchar('>'); - } -} - -char * -portid(char *name) -{ - char *id; - - if (strcasecmp(name, "bss") == 0) - id = "1"; - else if (strcasecmp(name, "adhoc") == 0 || - strcasecmp(name, "ad-hoc") == 0) - id = "3"; - else if (strcasecmp(name, "ibss") == 0) - id = "4"; - else if (strcasecmp(name, "hostap") == 0) - id = "6"; - else - errx(1, "unknown port type %s", name); - - return(id); -} |