Index: Makefile =================================================================== RCS file: /home/ncvs/src/usr.sbin/Makefile,v retrieving revision 1.249 diff -u -r1.249 Makefile --- Makefile 9 Apr 2003 10:52:10 -0000 1.249 +++ Makefile 21 Apr 2003 18:28:48 -0000 @@ -21,6 +21,7 @@ chown \ chroot \ ckdist \ + cnwctl \ config \ cron \ crunch \ Index: cnwctl/Makefile =================================================================== RCS file: cnwctl/Makefile diff -N cnwctl/Makefile --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ cnwctl/Makefile 21 Apr 2003 18:28:08 -0000 @@ -0,0 +1,6 @@ +# $NetBSD: Makefile,v 1.2 1999/11/29 12:55:07 itojun Exp $ +# PAO2 Id: Makefile,v 1.1.1.1 1997/12/11 14:46:06 itojun Exp +PROG= cnwctl +MAN= cnwctl.8 + +.include Index: cnwctl/cnwctl.8 =================================================================== RCS file: cnwctl/cnwctl.8 diff -N cnwctl/cnwctl.8 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ cnwctl/cnwctl.8 21 Apr 2003 18:28:08 -0000 @@ -0,0 +1,160 @@ +.\" $NetBSD: cnwctl.8,v 1.2 1999/11/29 12:55:07 itojun Exp $ +.\" +.\" Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that this notice is retained, +.\" the conditions in the following notices are met, and terms applying +.\" to contributors in the following notices also apply to Berkeley +.\" Software Design, Inc. +.\" +.\" 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 +.\" Berkeley Software Design, Inc. +.\" 4. Neither the name of the Berkeley Software Design, Inc. nor the names +.\" of its contributors may be used to endorse or promote products derived +.\" from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN, INC. ``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 BERKELEY SOFTWARE DESIGN, INC. 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. +.\" +.\" PAO2 Id: cnwctl.8,v 1.1.1.1 1997/12/11 14:46:06 itojun Exp +.\" +.Dd January 5, 1997 +.Dt CNWCTL 8 +.Os +.Sh NAME +.Nm cnwctl +.Nd display statistics and control Netwave AirSurfer PC Cards +.Sh SYNOPSIS +.Nm cnwctl +.Op Fl d Ar domain +.Op Fl i Ar interface +.Op Fl k Ar scramble-key +.Op Fl sS Op Ar rate +.Sh DESCRIPTION +The +.Nm cnwctl +utility is used to control Netwave AirSurfer PC Cards as well as +display statistics. +The following options are available: +. +.Bl -tag -width indent +.It Fl d +Set the domain of the card to +.Ar domain . +The domain must be between 0x000 and 0x1ff. +The domains 0x000 through 0x0ff are for access to an add-hoc network. +The domains 0x100 through 0x1ff are for access to a Netwave Access Point. +The default domain is 0x000. +A card may only talk to the access point in its domain, or other cards +in its add-hoc domain. +.It Fl i +Use +.Ar interface +as the interface rather than +.Li cnw0 . +.It Fl k +Set the scramble key to +.Ar scramble-key . +The scramble key must be between 0x0000 and 0xffff. +Both the source and the destination must use the same scramble key +in order to communicate. +.It Fl s +Display statistics. +When the optional argument +.Ar rate +(which must be the last argument to the end of the command line) +is specified as a non-zero value, statistics will be displayed +every +.Ar rate +seconds. +At the top of each +.Dq page +of statistics, column labels will be displayed. The first row of +statistics will be totals since boot, subsequent lines are deltas +from the previous row. +If +.Ar rate +is not specified, or is 0 (zero), a single page of statistics will be +displayed. These statistics are more detailed and include: +.Bl -tag -width indent +.It domain +The domain this card is part of. +.It rx +Number of packets received. +.It rxoverflow +Number of overflows detected. +.It rxoverrun +Number of overruns detected. +.It rxcrcerror +Number of CRC errors detected. +Random noise can cause these errors. +.It rxframe +Number of framing errors detected. +.It rxerrors +Number of generic errors detected. +.It rxavail +Number of times a packet was available. +.It tx +Number of packets requested to be sent. +.It txokay +Number of packets sent. +.It txabort +Number of packets aborted (not sent within 9 tries). +.It txlostcd +Number of times carrier detect was lost. +.It txerrors +Number of generic transmit errors detected. +.It txretries +Total number of retries. +.It Ar N Ns No x retries +Number of packets which were retried +.Ar N +times. +.El +.It Fl S +Display status read from the hardware. This option is only available +to the super user. +The +.Ar rate +argument is used as with the +.Fl s +option. +The following fields are displayed +.Bl -tag -width indent +.It link integrity field (lif) +A 0 value implies no links. +.It connection quality (cq) +Probably indicates the quality of the connection to the access point. +.It spu +Unknown meaning. +.It link quality (lq) +Probably indicated the quality of the link to the access point. +.It hhc +Unknown meaning. +.It mhs +Unknown meaning. +.It revision +The revision numbers of the card. +.It id +The ID of the card. +.El +.El +.Sh SEE ALSO +.Xr cnw 4 Index: cnwctl/cnwctl.c =================================================================== RCS file: cnwctl/cnwctl.c diff -N cnwctl/cnwctl.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ cnwctl/cnwctl.c 21 Apr 2003 18:28:08 -0000 @@ -0,0 +1,281 @@ +/* $NetBSD: cnwctl.c,v 1.6 2001/08/18 17:10:04 ad Exp $ */ + +/* + * Copyright (c) 1997 Berkeley Software Design, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that this notice is retained, + * the conditions in the following notices are met, and terms applying + * to contributors in the following notices also apply to Berkeley + * Software Design, Inc. + * + * 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 + * Berkeley Software Design, Inc. + * 4. Neither the name of the Berkeley Software Design, Inc. nor the names + * of its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN, INC. ``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 BERKELEY SOFTWARE DESIGN, INC. 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. + * + * PAO2 Id: cnwctl.c,v 1.1.1.1 1997/12/11 14:46:06 itojun Exp + * $FreeBSD$ + */ + +#include +#include +#include +#include +#include +#include + +#include + +#if !defined(__FreeBSD__) +#include +#else +#include +#endif + + +#include +#include +#include +#include +#include +#include + +int +main(int argc, char **argv) +{ + int c, domain, i, key, rate, sflag, Sflag, skt; + char *e, *interface; + struct ifreq ifr; + struct cnwistats cnwis, onwis; + struct cnwstatus cnws; + struct ttysize ts; + + domain = -1; + key = -1; + Sflag = sflag = 0; + rate = 0; + interface = "cnw0"; + + while ((c = getopt(argc, argv, "d:i:k:sS")) != -1) + switch (c) { + case 'd': + domain = strtol(optarg, &e, 0); + if (e == optarg || *e || domain & ~ 0x1ff) + errx(1, "%s: invalid domain", optarg); + break; + case 'i': + interface = optarg; + break; + case 'k': + key = strtol(optarg, &e, 0); + if (e == optarg || *e || key & ~ 0xffff) + errx(1, "%s: invalid scramble key", optarg); + break; + case 'S': + ++Sflag; + break; + case 's': + ++sflag; + break; + default: usage: + fprintf(stderr, "usage: cnwctl [-i interface] [-d domain] [-k key] [-sS [rate]]\n"); + exit(1); + } + + switch (argc - optind) { + case 0: + break; + case 1: + if (sflag == 0 && Sflag == 0) + goto usage; + if (sflag && Sflag) + errx(1, "only one of -s and -S may be specified with a rate"); + rate = strtol(argv[optind], &e, 0); + if (e == optarg || *e || rate < 1) + errx(1, "%s: invalid rate", optarg); + break; + default: + goto usage; + } + + if ((skt = socket(AF_INET, SOCK_DGRAM, 0)) < 0) + err(1, "socket(AF_INET, SOCK_DGRAM)"); + + if (key >= 0) { + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); + ifr.ifr_key = key; + if (ioctl(skt, SIOCSCNWKEY, (caddr_t)&ifr) < 0) + err(1, "SIOCSCNWKEY"); + } + + if (domain >= 0) { + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); + ifr.ifr_domain = domain; + if (ioctl(skt, SIOCSCNWDOMAIN, (caddr_t)&ifr) < 0) + err(1, "SIOCSCNWDOMAIN"); + } + + if (sflag == 0 && Sflag == 0) + exit (0); + + if (Sflag) { + memset(&cnws, 0, sizeof(cnws)); + strncpy(cnws.ifr.ifr_name, interface, + sizeof(cnws.ifr.ifr_name)); + if (ioctl(skt, SIOCGCNWSTATUS, (caddr_t)&cnws) < 0) + err(1, "SIOCGCNWSTATUS"); + } + + if (sflag) { + memset(&cnwis, 0, sizeof(cnwis)); + strncpy(cnwis.ifr.ifr_name, interface, + sizeof(cnwis.ifr.ifr_name)); + if (ioctl(skt, SIOCGCNWSTATS, (caddr_t)&cnwis) < 0) + err(1, "SIOCGCNWSTATS"); + cnwis.stats.nws_txretries[0] = 0; + + for (i = 1; i < 16; ++i) + cnwis.stats.nws_txretries[0] += + cnwis.stats.nws_txretries[i] * i; + } + + if (rate == 0 && sflag) { + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); + if (ioctl(skt, SIOCGCNWDOMAIN, (caddr_t)&ifr) < 0) + err(1, "SIOCGCNWDOMAIN"); + printf("%s:\n 0x%03x domain\n", interface, ifr.ifr_domain); + printf("%10llu rx\n", (unsigned long long)cnwis.stats.nws_rx); + printf("%10llu rxoverflow\n", + (unsigned long long)cnwis.stats.nws_rxoverflow); + printf("%10llu rxoverrun\n", + (unsigned long long)cnwis.stats.nws_rxoverrun); + printf("%10llu rxcrcerror\n", + (unsigned long long)cnwis.stats.nws_rxcrcerror); + printf("%10llu rxframe\n", + (unsigned long long)cnwis.stats.nws_rxframe); + printf("%10llu rxerrors\n", + (unsigned long long)cnwis.stats.nws_rxerrors); + printf("%10llu rxavail\n", + (unsigned long long)cnwis.stats.nws_rxavail); + + printf("%10llu tx\n", (unsigned long long)cnwis.stats.nws_tx); + printf("%10llu txokay\n", + (unsigned long long)cnwis.stats.nws_txokay); + printf("%10llu txabort\n", + (unsigned long long)cnwis.stats.nws_txabort); + printf("%10llu txlostcd\n", + (unsigned long long)cnwis.stats.nws_txlostcd); + printf("%10llu txerrors\n", + (unsigned long long)cnwis.stats.nws_txerrors); + printf("%10llu txretries\n", + (unsigned long long)cnwis.stats.nws_txretries[0]); + for (i = 1; i < 16; ++i) + if (cnwis.stats.nws_txretries[i]) + printf("%10s %10llu %dx retries\n", "", + (unsigned long long) + cnwis.stats.nws_txretries[i], + i); + } + + if (rate == 0 && Sflag) { + printf(" 0x%02x link integrity field\n", + cnws.data[0x4e]); + printf(" 0x%02x connection quality\n", + cnws.data[0x54]); + printf(" 0x%02x spu\n", + cnws.data[0x55]); + printf(" 0x%02x link quality\n", + cnws.data[0x56]); + printf(" 0x%02x hhc\n", + cnws.data[0x58]); + printf(" 0x%02x mhs\n", + cnws.data[0x6b]); + printf(" %04x %04x revision\n", + *(u_short *)&cnws.data[0x66], *(u_short *)&cnws.data[0x68]); + printf(" %c%c id\n", + cnws.data[0x6e], cnws.data[0x6f]); + } + + if (rate == 0) + exit (0); + + if (ioctl(0, TIOCGWINSZ, &ts) < 0) + ts.ts_lines = 24; + c = 0; + + if (Sflag) for (;;) { + if (c-- == 0) { + printf("lif cq spu lq hhc mhs\n"); + c = ts.ts_lines - 3; + } + printf(" %02x %02x %02x %02x %02x %02x\n", + cnws.data[0x4e], + cnws.data[0x54], + cnws.data[0x55], + cnws.data[0x56], + cnws.data[0x58], + cnws.data[0x6b]); + fflush(stdout); + if (ioctl(skt, SIOCGCNWSTATUS, (caddr_t)&cnws) < 0) + err(1, "SIOCGCNWSTATUS"); + sleep (rate); + } + + for (;;) { + if (c-- == 0) { + printf("%10s %10s %10s %10s %10s %10s\n", + "tx-request", "tx-okay", "tx-error", "tx-retry", + "rx", "rx-error"); + c = ts.ts_lines - 3; + memset(&onwis, 0, sizeof(onwis)); + } + printf("%10llu ", (unsigned long long) + (cnwis.stats.nws_tx - onwis.stats.nws_tx)); + printf("%10llu ", (unsigned long long) + (cnwis.stats.nws_txokay - onwis.stats.nws_txokay)); + printf("%10llu ", (unsigned long long) + (cnwis.stats.nws_txerrors - onwis.stats.nws_txerrors)); + printf("%10llu ", (unsigned long long) + (cnwis.stats.nws_txretries[0] - + onwis.stats.nws_txretries[0])); + printf("%10llu ", (unsigned long long) + (cnwis.stats.nws_rx - onwis.stats.nws_rx)); + printf("%10llu\n", (unsigned long long) + (cnwis.stats.nws_rxerrors - onwis.stats.nws_rxerrors)); + fflush(stdout); + sleep (rate); + onwis = cnwis; + + if (ioctl(skt, SIOCGCNWSTATS, (caddr_t)&cnwis) < 0) + err(1, "SIOCGCNWSTATS"); + cnwis.stats.nws_txretries[0] = 0; + for (i = 1; i < 16; ++i) + cnwis.stats.nws_txretries[0] += + cnwis.stats.nws_txretries[i] * i; + } +}