From 78511a88416ccdce76ae80d7463c2b658789d7df Mon Sep 17 00:00:00 2001 From: itojun Date: Sun, 13 Feb 2000 05:39:13 +0000 Subject: [PATCH] bring in latest wi driver (with netbsd-current -> 1.4.1 tweaks) --- netbsd/sys/dev/pcmcia/if_wi.c | 123 ++++++++++++- netbsd/sys/dev/pcmcia/if_wi_ieee.h | 49 +++++- netbsd/sys/dev/pcmcia/if_wireg.h | 32 ++-- netbsd/sys/dev/pcmcia/if_wivar.h | 34 +--- netbsd/usr.sbin/wiconfig/wiconfig.8 | 135 +++++++------- netbsd/usr.sbin/wiconfig/wiconfig.c | 261 +++++++++++++++++++++++++--- 6 files changed, 501 insertions(+), 133 deletions(-) diff --git a/netbsd/sys/dev/pcmcia/if_wi.c b/netbsd/sys/dev/pcmcia/if_wi.c index 9c70420a52..acd3805a36 100644 --- a/netbsd/sys/dev/pcmcia/if_wi.c +++ b/netbsd/sys/dev/pcmcia/if_wi.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_wi.c,v 1.3 1999/09/10 00:30:59 itojun Exp $ */ +/* $NetBSD: if_wi.c,v 1.6 2000/02/12 23:35:28 enami Exp $ */ /* * Copyright (c) 1997, 1998, 1999 @@ -31,7 +31,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: if_wi.c,v 1.3 1999/09/10 00:30:59 itojun Exp $ + * $Id: if_wi.c,v 1.6 2000/02/12 23:35:28 enami Exp $ */ /* @@ -84,6 +84,7 @@ #include #include #include /* for hz */ +#include #include #include @@ -109,13 +110,12 @@ #include #include -#include - #include +#include #if !defined(lint) static const char rcsid[] = - "$Id: if_wi.c,v 1.3 1999/09/10 00:30:59 itojun Exp $"; + "$Id: if_wi.c,v 1.6 2000/02/12 23:35:28 enami Exp $"; #endif #ifdef foo @@ -124,7 +124,10 @@ static u_int8_t wi_mcast_addr[6] = { 0x01, 0x60, 0x1D, 0x00, 0x01, 0x00 }; static int wi_match __P((struct device *, struct cfdata *, void *)); static void wi_attach __P((struct device *, struct device *, void *)); - +#if __NetBSD_Version__ > 104010000 +static int wi_detach __P((struct device *, int)); +static int wi_activate __P((struct device *, enum devact)); +#endif static int wi_intr __P((void *arg)); @@ -160,6 +163,9 @@ static int wi_disable __P((struct wi_softc *)); struct cfattach wi_ca = { sizeof(struct wi_softc), wi_match, wi_attach +#if __NetBSD_Version__ > 104010000 + , wi_detach, wi_activate +#endif }; static int @@ -244,11 +250,14 @@ wi_attach(parent, self, aux) if (pcmcia_io_alloc(sc->sc_pf, 0, WI_IOSIZ, WI_IOSIZ, &sc->sc_pcioh) != 0) { printf(": can't allocate i/o space\n"); + pcmcia_function_disable(sc->sc_pf); return; } if (pcmcia_io_map(sc->sc_pf, PCMCIA_WIDTH_IO16, 0, WI_IOSIZ, &sc->sc_pcioh, &sc->sc_iowin) != 0) { printf(": can't map i/o space\n"); + pcmcia_io_free(sc->sc_pf, &sc->sc_pcioh); + pcmcia_function_disable(sc->sc_pf); return; } sc->wi_btag = sc->sc_pcioh.iot; @@ -314,6 +323,14 @@ wi_attach(parent, self, aux) bzero((char *)&sc->wi_stats, sizeof(sc->wi_stats)); + /* + * Find out if we support WEP on this card. + */ + gen.wi_type = WI_RID_WEP_AVAIL; + gen.wi_len = 2; + wi_read_record(sc, &gen); + sc->wi_has_wep = gen.wi_val; + wi_init(sc); wi_stop(sc); @@ -329,6 +346,9 @@ wi_attach(parent, self, aux) #endif sc->sc_sdhook = shutdownhook_establish(wi_shutdown, sc); + + /* Disable the card now, and turn it on when the interface goes up */ + pcmcia_function_disable(sc->sc_pf); } static void wi_rxeof(sc) @@ -479,6 +499,9 @@ void wi_inquire(xsc) sc = xsc; ifp = &sc->sc_ethercom.ec_if; + if ((sc->sc_dev.dv_flags & DVF_ACTIVE) == 0) + return; + timeout(wi_inquire, sc, hz * 60); /* Don't do this while we're transmitting */ @@ -535,6 +558,8 @@ int wi_intr(arg) struct ifnet *ifp; u_int16_t status; + if ((sc->sc_dev.dv_flags & DVF_ACTIVE) == 0) + return (0); ifp = &sc->sc_ethercom.ec_if; @@ -888,6 +913,12 @@ static void wi_setmulti(sc) bzero((char *)&mcast, sizeof(mcast)); break; } +#if 0 + /* Punt on ranges. */ + if (bcmp(enm->enm_addrlo, enm->enm_addrhi, + sizeof(enm->enm_addrlo)) != 0) + break; +#endif bcopy(enm->enm_addrlo, (char *)&mcast.wi_mcast[i], ETHER_ADDR_LEN); i++; @@ -955,6 +986,16 @@ static void wi_setdef(sc, wreq) case WI_RID_MAX_SLEEP: sc->wi_max_sleep = wreq->wi_val[0]; break; + case WI_RID_ENCRYPTION: + sc->wi_use_wep = wreq->wi_val[0]; + break; + case WI_RID_TX_CRYPT_KEY: + sc->wi_tx_key = wreq->wi_val[0]; + break; + case WI_RID_DEFLT_CRYPT_KEYS: + bcopy((char *)wreq, (char *)&sc->wi_keys, + sizeof(struct wi_ltv_keys)); + break; default: break; } @@ -974,6 +1015,7 @@ static int wi_ioctl(ifp, command, data) struct wi_softc *sc; struct wi_req wreq; struct ifreq *ifr; + struct proc *p = curproc; struct ifaddr *ifa = (struct ifaddr *)data; s = splimp(); @@ -1051,6 +1093,14 @@ static int wi_ioctl(ifp, command, data) bcopy((char *)&sc->wi_stats, (char *)&wreq.wi_val, sizeof(sc->wi_stats)); wreq.wi_len = (sizeof(sc->wi_stats) / 2) + 1; + } else if (wreq.wi_type == WI_RID_DEFLT_CRYPT_KEYS) { + /* For non-root user, return all-zeroes keys */ + if (suser(p->p_ucred, &p->p_acflag)) + bzero((char *)&wreq, + sizeof(struct wi_ltv_keys)); + else + bcopy((char *)&sc->wi_keys, (char *)&wreq, + sizeof(struct wi_ltv_keys)); } else { if (wi_read_record(sc, (struct wi_ltv_gen *)&wreq)) { error = EINVAL; @@ -1060,6 +1110,9 @@ static int wi_ioctl(ifp, command, data) error = copyout(&wreq, ifr->ifr_data, sizeof(wreq)); break; case SIOCSWAVELAN: + error = suser(p->p_ucred, &p->p_acflag); + if (error) + break; error = copyin(ifr->ifr_data, &wreq, sizeof(wreq)); if (error) break; @@ -1148,6 +1201,15 @@ static void wi_init(xsc) memcpy(&mac.wi_mac_addr, sc->sc_macaddr, ETHER_ADDR_LEN); wi_write_record(sc, (struct wi_ltv_gen *)&mac); + /* Configure WEP. */ + if (sc->wi_has_wep) { + WI_SETVAL(WI_RID_ENCRYPTION, sc->wi_use_wep); + WI_SETVAL(WI_RID_TX_CRYPT_KEY, sc->wi_tx_key); + sc->wi_keys.wi_len = (sizeof(struct wi_ltv_keys) / 2) + 1; + sc->wi_keys.wi_type = WI_RID_DEFLT_CRYPT_KEYS; + wi_write_record(sc, (struct wi_ltv_gen *)&sc->wi_keys); + } + /* Initialize promisc mode. */ if (ifp->if_flags & IFF_PROMISC) { WI_SETVAL(WI_RID_PROMISC, 1); @@ -1359,3 +1421,52 @@ static void wi_shutdown(arg) wi_disable(sc); return; } + +#if __NetBSD_Version__ > 104010000 +static int +wi_activate(self, act) + struct device *self; + enum devact act; +{ + struct wi_softc *sc = (struct wi_softc *)self; + int rv = 0, s; + + s = splnet(); + switch (act) { + case DVACT_ACTIVATE: + rv = EOPNOTSUPP; + break; + + case DVACT_DEACTIVATE: + if_deactivate(&sc->sc_ethercom.ec_if); + break; + } + splx(s); + return (rv); +} + +static int +wi_detach(self, flags) + struct device *self; + int flags; +{ + struct wi_softc *sc = (struct wi_softc *)self; + struct ifnet *ifp = &sc->sc_ethercom.ec_if; + + if (ifp->if_flags & IFF_RUNNING) + untimeout(wi_inquire, sc); + wi_disable(sc); + +#if NBPFILTER > 0 + bpfdetach(ifp); +#endif + ether_ifdetach(ifp); + if_detach(ifp); + + /* unmap and free our i/o windows */ + pcmcia_io_unmap(sc->sc_pf, sc->sc_iowin); + pcmcia_io_free(sc->sc_pf, &sc->sc_pcioh); + + return (0); +} +#endif diff --git a/netbsd/sys/dev/pcmcia/if_wi_ieee.h b/netbsd/sys/dev/pcmcia/if_wi_ieee.h index 4660f2b833..55acd14222 100644 --- a/netbsd/sys/dev/pcmcia/if_wi_ieee.h +++ b/netbsd/sys/dev/pcmcia/if_wi_ieee.h @@ -1,3 +1,5 @@ +/* $NetBSD: if_wi_ieee.h,v 1.4 2000/02/04 07:48:29 explorer Exp $ */ + /* * Copyright (c) 1997, 1998, 1999 * Bill Paul . All rights reserved. @@ -29,7 +31,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: if_wi_ieee.h,v 1.1 1999/07/14 22:24:09 sommerfeld Exp $ + * $FreeBSD: src/sys/i386/include/if_wavelan_ieee.h,v 1.4 1999/12/29 04:33:01 peter Exp $ */ #ifndef _IF_WAVELAN_IEEE_H @@ -40,6 +42,8 @@ * Oslo IETF plenary meeting. * The stuff in here should probably go into a generic extension to the * ifmedia goop. + * + * Michael Graff brought over the encryption bits. */ /* @@ -87,6 +91,10 @@ struct wi_req { */ #define WI_RID_IFACE_STATS 0x0100 #define WI_RID_MGMT_XMIT 0x0200 +#ifdef WICACHE +#define WI_RID_ZERO_CACHE 0x0300 +#define WI_RID_READ_CACHE 0x0400 +#endif struct wi_80211_hdr { u_int16_t frame_ctl; @@ -135,7 +143,27 @@ struct wi_mgmt_hdr { u_int16_t seq_ctl; }; -#ifndef _KERNEL +/* + * Lucent/wavelan IEEE signal strength cache + * + * driver keeps cache of last + * MAXWICACHE packets to arrive including signal strength info. + * daemons may read this via ioctl + * + * Each entry in the wi_sigcache has a unique macsrc. + */ +#ifdef WICACHE +#define MAXWICACHE 10 + +struct wi_sigcache { + char macsrc[6]; /* unique MAC address for entry */ + int ipsrc; /* ip address associated with packet */ + int signal; /* signal strength of the packet */ + int noise; /* noise value */ + int quality; /* quality of the packet */ +}; +#endif + struct wi_counters { u_int32_t wi_tx_unicast_frames; u_int32_t wi_tx_multicast_frames; @@ -200,6 +228,8 @@ struct wi_counters { #define WI_RID_WDS_ADDR5 0xFC15 /* port 1 MAC of WDS link node */ #define WI_RID_WDS_ADDR6 0xFC16 /* port 1 MAC of WDS link node */ #define WI_RID_MCAST_PM_BUF 0xFC17 /* PM buffering of mcast */ +#define WI_RID_ENCRYPTION 0xFC20 /* enable/disable WEP */ +#define WI_RID_AUTHTYPE 0xFC21 /* specify authentication type */ /* * Network parameters, dynamic configuration entities @@ -231,8 +261,21 @@ struct wi_counters { #define WI_RID_TX_RATE4 0xFCA2 #define WI_RID_TX_RATE5 0xFCA3 #define WI_RID_TX_RATE6 0xFCA4 +#define WI_RID_DEFLT_CRYPT_KEYS 0xFCB0 +#define WI_RID_TX_CRYPT_KEY 0xFCB1 #define WI_RID_TICK_TIME 0xFCE0 +struct wi_key { + u_int16_t wi_keylen; + u_int8_t wi_keydat[14]; +}; + +struct wi_ltv_keys { + u_int16_t wi_len; + u_int16_t wi_type; + struct wi_key wi_keys[4]; +}; + /* * NIC information */ @@ -290,7 +333,5 @@ struct wi_counters { #define WI_RID_CCA_TIME 0xFDC4 /* clear chan assess time */ #define WI_RID_MAC_PROC_DELAY 0xFDC5 /* MAC processing delay time */ #define WI_RID_DATA_RATES 0xFDC6 /* supported data rates */ -#endif - #endif diff --git a/netbsd/sys/dev/pcmcia/if_wireg.h b/netbsd/sys/dev/pcmcia/if_wireg.h index c4f53a13d4..a888f3fc64 100644 --- a/netbsd/sys/dev/pcmcia/if_wireg.h +++ b/netbsd/sys/dev/pcmcia/if_wireg.h @@ -1,4 +1,4 @@ -/* $NetBSD: if_wireg.h,v 1.2 1999/07/15 14:33:51 sommerfeld Exp $ */ +/* $NetBSD: if_wireg.h,v 1.5 2000/02/04 07:48:29 explorer Exp $ */ /* * Copyright (c) 1997, 1998, 1999 @@ -31,7 +31,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: if_wireg.h,v 1.2 1999/07/15 14:33:51 sommerfeld Exp $ + * $Id: if_wireg.h,v 1.5 2000/02/04 07:48:29 explorer Exp $ */ /* @@ -74,9 +74,19 @@ #define WI_DEFAULT_MAX_SLEEP 100 -#define WI_DEFAULT_NODENAME "NetBSD WaveLAN/IEEE node" +#ifdef __NetBSD__ +#define OS_STRING_NAME "NetBSD" +#endif +#ifdef __FreeBSD__ +#define OS_STRING_NAME "FreeBSD" +#endif +#ifdef __OpenBSD__ +#define OS_STRING_NAME "OpenBSD" +#endif -#define WI_DEFAULT_IBSS "NetBSD IBSS" +#define WI_DEFAULT_NODENAME OS_STRING_NAME " WaveLAN/IEEE node" + +#define WI_DEFAULT_IBSS OS_STRING_NAME " IBSS" #define WI_DEFAULT_CHAN 3 @@ -382,11 +392,9 @@ struct wi_ltv_scalethresh { struct wi_ltv_pcf { u_int16_t wi_len; u_int16_t wi_type; - u_int16_t wi_energy_detect; - u_int16_t wi_carrier_detect; - u_int16_t wi_defer; - u_int16_t wi_cell_search; - u_int16_t wi_range; + u_int16_t wi_medium_occupancy_limit; + u_int16_t wi_cfp_period; + u_int16_t wi_cfp_max_duration; }; /* @@ -503,9 +511,11 @@ struct wi_ltv_mcast { */ struct wi_frame { u_int16_t wi_status; /* 0x00 */ - u_int32_t wi_rsvd0; /* 0x02 */ + u_int16_t wi_rsvd0; /* 0x02 */ + u_int16_t wi_rsvd1; /* 0x04 */ u_int16_t wi_q_info; /* 0x06 */ - u_int16_t wi_rsvd1; /* 0x08 */ + u_int16_t wi_rsvd2; /* 0x08 */ + u_int16_t wi_rsvd3; /* 0x0A */ u_int16_t wi_tx_ctl; /* 0x0C */ u_int16_t wi_frame_ctl; /* 0x0E */ u_int16_t wi_id; /* 0x10 */ diff --git a/netbsd/sys/dev/pcmcia/if_wivar.h b/netbsd/sys/dev/pcmcia/if_wivar.h index df345f364b..3328cdd4a4 100644 --- a/netbsd/sys/dev/pcmcia/if_wivar.h +++ b/netbsd/sys/dev/pcmcia/if_wivar.h @@ -1,4 +1,4 @@ -/* $NetBSD: if_wivar.h,v 1.2 1999/07/14 23:07:29 sommerfeld Exp $ */ +/* $NetBSD: if_wivar.h,v 1.3 2000/02/04 07:48:29 explorer Exp $ */ /* * Copyright (c) 1997, 1998, 1999 @@ -31,7 +31,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: if_wivar.h,v 1.2 1999/07/14 23:07:29 sommerfeld Exp $ + * $Id: if_wivar.h,v 1.3 2000/02/04 07:48:29 explorer Exp $ */ @@ -40,30 +40,6 @@ * Oslo IETF plenary meeting. */ -struct wi_counters { - u_int32_t wi_tx_unicast_frames; - u_int32_t wi_tx_multicast_frames; - u_int32_t wi_tx_fragments; - u_int32_t wi_tx_unicast_octets; - u_int32_t wi_tx_multicast_octets; - u_int32_t wi_tx_deferred_xmits; - u_int32_t wi_tx_single_retries; - u_int32_t wi_tx_multi_retries; - u_int32_t wi_tx_retry_limit; - u_int32_t wi_tx_discards; - u_int32_t wi_rx_unicast_frames; - u_int32_t wi_rx_multicast_frames; - u_int32_t wi_rx_fragments; - u_int32_t wi_rx_unicast_octets; - u_int32_t wi_rx_multicast_octets; - u_int32_t wi_rx_fcs_errors; - u_int32_t wi_rx_discards_nobuf; - u_int32_t wi_tx_discards_wrong_sa; - u_int32_t wi_rx_WEP_cant_decrypt; - u_int32_t wi_rx_msg_in_msg_frags; - u_int32_t wi_rx_msg_in_bad_msg_frags; -}; - struct wi_softc { struct device sc_dev; struct ethercom sc_ethercom; @@ -97,6 +73,10 @@ struct wi_softc { char wi_node_name[32]; char wi_net_name[32]; char wi_ibss_name[32]; - u_int8_t wi_txbuf[1536]; + u_int8_t wi_txbuf[1596]; + int wi_has_wep; + int wi_use_wep; + int wi_tx_key; + struct wi_ltv_keys wi_keys; struct wi_counters wi_stats; }; diff --git a/netbsd/usr.sbin/wiconfig/wiconfig.8 b/netbsd/usr.sbin/wiconfig/wiconfig.8 index 9b8460929d..abf602fefb 100644 --- a/netbsd/usr.sbin/wiconfig/wiconfig.8 +++ b/netbsd/usr.sbin/wiconfig/wiconfig.8 @@ -1,3 +1,5 @@ +.\" $NetBSD: wiconfig.8,v 1.5 2000/02/04 08:01:43 explorer Exp $ +.\" .\" Copyright (c) 1997, 1998, 1999 .\" Bill Paul All rights reserved. .\" @@ -28,50 +30,43 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF .\" THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $Id: wiconfig.8,v 1.3 1999/07/15 14:31:52 sommerfeld Exp $ +.\" From: wicontrol.8,v 1.6 1999/05/22 16:12:47 wpaul Exp $ .\" .Dd April 21, 1999 .Dt WICONFIG 8 -.Os NetBSD 1.5 +.Os .Sh NAME .Nm wiconfig .Nd configure WaveLAN/IEEE devices .Sh SYNOPSIS .Nm wiconfig -.Fl i Ar iface Op Fl o -.Nm wiconfig -.Fl i Ar iface Fl t Ar tx rate -.Nm wiconfig -.Fl i Ar iface Fl n Ar network name -.Nm wiconfig -.Fl i Ar iface Fl s Ar station name -.Nm wiconfig -.Fl i Ar iface Fl c Ar 0|1 -.Nm wiconfig -.Fl i Ar iface Fl q Ar SSID -.Nm wiconfig -.Fl i Ar iface Fl p Ar port type -.Nm wiconfig -.Fl i Ar iface Fl a Ar access point density -.Nm wiconfig -.Fl i Ar iface Fl m Ar mac address -.Nm wiconfig -.Fl i Ar iface Fl d Ar max data length -.Nm wiconfig -.Fl i Ar iface Fl r Ar RTS threshold -.Nm wiconfig -.Fl i Ar iface Fl f Ar frequency -.Nm wiconfig -.Fl i Ar iface Fl P Ar 0|1 -.Nm wiconfig -.Fl i Ar iface Fl S Ar max_sleep_duration +.Ar interface +.Op Fl o +.Op Fl e Ar 0|1 +.Op Fl k Ar key "[ -v 1|2|3|4 ]" +.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 P Ar 0|1 +.Op Fl S Ar max sleep duration +.Op Fl T Ar 1|2|3|4 .Sh DESCRIPTION The .Nm command controls the operation of WaveLAN/IEEE wireless networking devices via the .Xr wi 4 -driver. Most of the parameters that can be changed relate to the +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 @@ -88,16 +83,41 @@ should be the logical interface name associated with the WaveLAN/IEEE device (wi0, wi1, etc...). .Sh OPTIONS The options are as follows: +.Pp .Bl -tag -width Fl -.It Fl i Ar iface Op Fl o +.It Fl o Display the current settings of the specified WaveLAN/IEEE interface. -This retrives the current card settings from the driver and prints them +This retrieves the current card settings from the driver and prints them out. Using the additional .Fl o flag will cause .Nm to print out the statistics counters instead of the card settings. -.It Fl i Ar iface Fl t Ar tx rate +.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 +112 bits, which means the key can be specified as either a 14-character +text string or 28 hexadecimal digits. (The card claims to be 128-bit RC4, +but you can only send 112 bits to the driver. Strange, I wonder where the +other 16 bits come from, and what they are.) +.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 t Ar tx rate Set the transmit rate of the specified interface. The legal values for the transmit rate vary depending on whether the interface is a standard WaveLAN/IEEE or a WaveLAN/IEEE Turbo adapter. The standard @@ -114,44 +134,38 @@ legal transmit rate settings and the corresponding transmit speeds: 5 Fixed High (6Mbps) 6 Auto Rate Select (Standard) 7 Auto Rate Select (Medium) +11 Fixed Turbo (11Mbps) .El .Ed .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 i Ar iface Fl n Ar network name +.It Fl n Ar network name Set the name of the service set (IBSS) 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. -Use -.Fl n Ar '' -to specify an empty network name. -The interface should be set for BSS mode using +is the empty string which should allow the station to connect to the first +available access point. The interface should be set for BSS mode using the .Fl p flag in order for this to work. -.Pp -Note that some other drivers may use the string "ANY" to reflect this -in the driver's user interface. -.It Fl i Ar iface Fl s Ar station name +.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 sofware can poll the names of remote hosts. -.It Fl i Ar iface Fl c Ar 0|1 +.It Fl c Ar 0|1 Allow the station to create a service set (IBSS). Permitted values are 0 (don't create IBSS) and 1 (enable creation of IBSS). The default is 0. .Pp Note: this option is provided for experimental purposes only: enabling the creation of an IBSS on a host system doesn't appear to actually work. -.It Fl i Ar iface Fl q Ar SSID +.It Fl q Ar SSID Specify the name of an IBSS (SSID) to create on a given interface. The .Ar SSID @@ -159,39 +173,39 @@ can be any text string up to 30 characters long. .Pp Note: this option is provided for experimental purposes only: enabling the creation of an IBSS on a host system doesn't appear to actually work. -.It Fl i Ar iface Fl p Ar port type +.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) and 3 (ad-hoc) mode. In ad-hoc mode, the station can -comminicate directly with any other stations within direct radio range +communicate directly with any other stations within direct radio range (provided that they are also operating in ad-hoc mode). In BSS mode, hosts must associate with a service set controlled by an access point, which relays traffic between end stations. The default setting is 3 (ad-hoc mode). -.It Fl i Ar iface Fl a Ar access_point_density +.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 i Ar iface Fl m Ar mac address +.It Fl m Ar MAC address Set the station address for the specified interface. The -.Ar mac address +.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 i Ar iface Fl d Ar max_data_length +.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 i Ar iface Fl r Ar RTS threshold +.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 handhake boundary. 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 2347. -.It Fl i Ar iface Fl f Ar frequency +.It Fl f Ar frequency Set the radio frequency of a given interface. The .Ar frequency should be specfied as a channel ID as shown in the table below. The @@ -225,7 +239,7 @@ and Europe, the default channel is 3. For NICs sold in France, the default channel is 11. For NICs sold in Japan, the only available channel is 14. Note that two stations must be set to the same channel in order to communicate. -.It Fl i Ar iface Fl P Ar 0|1 +.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 @@ -236,13 +250,14 @@ 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 i Ar iface Fl S Ar max_sleep_interval +.It Fl S Ar max sleep interval Specify the sleep interval to use when power management is enabled. The .Are max sleep interval is specified in milliseconds. The default is 100. .El .Sh SEE ALSO +.Xr awi 4 , .Xr wi 4 , .Xr ifconfig 8 .Sh HISTORY @@ -250,10 +265,8 @@ The .Nm command first appeared in .Fx 3.0 , -as -.Xr wicontrol 8 . -It was added to -.Nx 1.5 +as wicontrol(8). It was added to +.Nx 1.5 under its present name. .Sh AUTHOR The diff --git a/netbsd/usr.sbin/wiconfig/wiconfig.c b/netbsd/usr.sbin/wiconfig/wiconfig.c index 44fbbe5851..91bf35b4e4 100644 --- a/netbsd/usr.sbin/wiconfig/wiconfig.c +++ b/netbsd/usr.sbin/wiconfig/wiconfig.c @@ -29,7 +29,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: wiconfig.c,v 1.1 1999/07/14 22:33:34 sommerfeld Exp $ + * $Id: wiconfig.c,v 1.2 2000/02/04 07:59:45 explorer Exp $ */ #include @@ -40,12 +40,24 @@ #include #include -#include - +#ifdef __FreeBSD__ +#include +#include + +#include +#else +#include +#include +#ifdef __NetBSD__ #include +#else +#include +#endif +#endif #include #include +#include #include #include #include @@ -55,7 +67,7 @@ static const char copyright[] = "@(#) Copyright (c) 1997, 1998, 1999\ Bill Paul. All rights reserved."; static const char rcsid[] = - "@(#) $Id: wiconfig.c,v 1.1 1999/07/14 22:33:34 sommerfeld Exp $"; + "@(#) $Id: wiconfig.c,v 1.2 2000/02/04 07:59:45 explorer Exp $"; #endif static void wi_getval __P((char *, struct wi_req *)); @@ -69,8 +81,12 @@ static void wi_printwords __P((struct wi_req *)); static void wi_printbool __P((struct wi_req *)); static void wi_printhex __P((struct wi_req *)); static void wi_dumpinfo __P((char *)); +static void wi_setkeys __P((char *, char *, int)); +static void wi_printkeys __P((struct wi_req *)); static void wi_dumpstats __P((char *)); static void usage __P((char *)); +static int wi_hex2int(char c); +static void wi_str2key __P((char *, struct wi_key *)); int main __P((int argc, char **argv)); static void wi_getval(iface, wreq) @@ -80,6 +96,9 @@ static void wi_getval(iface, wreq) struct ifreq ifr; int s; + if (iface == NULL) + errx(1, "must specify interface name"); + bzero((char *)&ifr, sizeof(ifr)); strcpy(ifr.ifr_name, iface); @@ -237,6 +256,129 @@ void wi_sethex(iface, code, str) return; } +static 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); +} + +static void wi_str2key(s, k) + 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 = n; + } else { + /* No, just copy it in. */ + bcopy(s, k->wi_keydat, strlen(s)); + k->wi_keylen = strlen(s); + } + + return; +} + +static void wi_setkeys(iface, key, idx) + char *iface; + char *key; + int idx; +{ + struct wi_req wreq; + struct wi_ltv_keys *keys; + struct wi_key *k; + + if (iface == NULL) + errx(1, "must specify interface name"); + + bzero((char *)&wreq, sizeof(wreq)); + wreq.wi_len = WI_MAX_DATALEN; + wreq.wi_type = WI_RID_WEP_AVAIL; + + wi_getval(iface, &wreq); + if (wreq.wi_val[0] == 0) + err(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) > 30) + err(1, "encryption key must be no " + "more than 28 hex digits long"); + } else { + if (strlen(key) > 14) + err(1, "encryption key must be no " + "more than 14 characters long"); + } + + if (idx > 3) + err(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); + + return; +} + +static void wi_printkeys(wreq) + 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 < k->wi_keylen; j++) { + if (!isprint(ptr[j])) { + bn = 1; + break; + } + } + + if (bn) { + printf("[ 0x"); + for (j = 0; j < k->wi_keylen; j++) + printf("%02x", ((unsigned char *) ptr)[j]); + printf(" ]"); + } else { + ptr[j] = '\0'; + printf("[ %s ]", ptr); + } + } + + return; +}; + void wi_printwords(wreq) struct wi_req *wreq; { @@ -284,6 +426,7 @@ void wi_printhex(wreq) #define WI_BOOL 0x02 #define WI_WORDS 0x03 #define WI_HEXBYTES 0x04 +#define WI_KEYSTRUCT 0x05 struct wi_table { int wi_code; @@ -305,7 +448,8 @@ static struct wi_table wi_table[] = { { WI_RID_PROMISC, WI_BOOL, "Promiscuous mode:\t\t\t" }, { WI_RID_PORTTYPE, WI_WORDS, "Port type (1=BSS, 3=ad-hoc):\t\t"}, { WI_RID_MAC_NODE, WI_HEXBYTES, "MAC address:\t\t\t\t"}, - { WI_RID_TX_RATE, WI_WORDS, "TX rate:\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_RTS_THRESH, WI_WORDS, "RTS/CTS handshake threshold:\t\t"}, { WI_RID_CREATE_IBSS, WI_BOOL, "Create IBSS:\t\t\t\t" }, { WI_RID_SYSTEM_SCALE, WI_WORDS, "Access point density:\t\t\t" }, @@ -314,13 +458,28 @@ static struct wi_table wi_table[] = { { 0, NULL } }; +static struct wi_table wi_crypt_table[] = { + { WI_RID_ENCRYPTION, WI_BOOL, "WEP encryption:\t\t\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 } +}; + static void wi_dumpinfo(iface) char *iface; { struct wi_req wreq; - int i; + int i, has_wep; struct wi_table *w; + bzero((char *)&wreq, sizeof(wreq)); + + wreq.wi_len = WI_MAX_DATALEN; + wreq.wi_type = WI_RID_WEP_AVAIL; + + wi_getval(iface, &wreq); + has_wep = wreq.wi_val[0]; + w = wi_table; for (i = 0; w[i].wi_type; i++) { @@ -350,6 +509,41 @@ static void wi_dumpinfo(iface) 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]++; + 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; + default: + break; + } + printf("\n"); + } + } + return; } @@ -417,22 +611,13 @@ static void wi_dumpstats(iface) static void usage(p) char *p; { - fprintf(stderr, "usage: %s -i iface\n", p); - fprintf(stderr, "\t%s -i iface -o\n", p); - fprintf(stderr, "\t%s -i iface -t tx rate\n", p); - fprintf(stderr, "\t%s -i iface -n network name\n", p); - fprintf(stderr, "\t%s -i iface -s station name\n", p); - fprintf(stderr, "\t%s -i iface -c 0|1\n", p); - fprintf(stderr, "\t%s -i iface -q SSID\n", p); - fprintf(stderr, "\t%s -i iface -p port type\n", p); - fprintf(stderr, "\t%s -i iface -a access point density\n", p); - fprintf(stderr, "\t%s -i iface -m mac address\n", p); - fprintf(stderr, "\t%s -i iface -d max data length\n", p); - fprintf(stderr, "\t%s -i iface -r RTS threshold\n", p); - fprintf(stderr, "\t%s -i iface -f frequency\n", p); - fprintf(stderr, "\t%s -i iface -P 0|1t\n", p); - fprintf(stderr, "\t%s -i iface -S max sleep duration\n", p); - + fprintf(stderr, + "usage: wiconfig interface " + "[-o] [-t tx rate] [-n network name] [-s station name]\n" + " [-e 0|1] [-k key [-v 1|2|3|4]] [-T 1|2|3|4]\n" + " [-c 0|1] [-q SSID] [-p port type] [-a access point density]\n" + " [-m MAC address] [-d max data length] [-r RTS threshold]\n" + " [-f frequency] [-P 0|1] [-S max sleep duration]\n"); exit(1); } @@ -443,16 +628,25 @@ int main(argc, argv) int ch; char *iface = NULL; char *p = argv[0]; + char *key = NULL; + int modifier = 0; + + if (argc > 1 && argv[1][0] != '-') { + iface = argv[1]; + memcpy(&argv[1], &argv[2], argc * sizeof(char *)); + argc--; + } while((ch = getopt(argc, argv, - "hoc:d:f:i:p:r:q:t:n:s:m:P:S:")) != -1) { + "hoc:d:f:p:r:q:t:n:s:i:m:P:S:T:e:k:v:")) != -1) { switch(ch) { case 'o': wi_dumpstats(iface); exit(0); break; case 'i': - iface = optarg; + if (iface == NULL) + iface = optarg; break; case 'c': wi_setword(iface, WI_RID_CREATE_IBSS, atoi(optarg)); @@ -502,6 +696,22 @@ int main(argc, argv) wi_setword(iface, WI_RID_PM_ENABLED, atoi(optarg)); exit(0); break; + case 'T': + wi_setword(iface, WI_RID_TX_CRYPT_KEY, + atoi(optarg) - 1); + exit(0); + break; + case 'k': + key = optarg; + break; + case 'e': + wi_setword(iface, WI_RID_ENCRYPTION, atoi(optarg)); + exit(0); + break; + case 'v': + modifier = atoi(optarg); + modifier--; + break; case 'h': default: usage(p); @@ -512,6 +722,9 @@ int main(argc, argv) if (iface == NULL) usage(p); + if (key != NULL) + wi_setkeys(iface, key, modifier); + wi_dumpinfo(iface); exit(0);