Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/iwictl iwictl(8) - configure Intel PRO/Wireless 220...



details:   https://anonhg.NetBSD.org/src/rev/68d51ec98409
branches:  trunk
changeset: 572755:68d51ec98409
user:      skrll <skrll%NetBSD.org@localhost>
date:      Tue Jan 11 18:28:37 2005 +0000

description:
iwictl(8) - configure Intel PRO/Wireless 2200AG/2915ABG (iwi(4)) network
adapter.

Written by Damien Bergamini, from http://damien.bergamini.free.fr/ipw/

diffstat:

 usr.sbin/iwictl/Makefile |    9 +
 usr.sbin/iwictl/iwictl.8 |   83 ++++++++++++
 usr.sbin/iwictl/iwictl.c |  312 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 404 insertions(+), 0 deletions(-)

diffs (truncated from 416 to 300 lines):

diff -r ef92ec44d70b -r 68d51ec98409 usr.sbin/iwictl/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/iwictl/Makefile  Tue Jan 11 18:28:37 2005 +0000
@@ -0,0 +1,9 @@
+# $Id: Makefile,v 1.1.1.1 2005/01/11 18:28:37 skrll Exp $
+
+.if ${MACHINE} == "i386"
+PROG   = iwictl
+.endif
+
+MAN    = iwictl.8
+
+.include <bsd.prog.mk>
diff -r ef92ec44d70b -r 68d51ec98409 usr.sbin/iwictl/iwictl.8
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/iwictl/iwictl.8  Tue Jan 11 18:28:37 2005 +0000
@@ -0,0 +1,83 @@
+.\" $Id: iwictl.8,v 1.1.1.1 2005/01/11 18:28:38 skrll Exp $
+.\"
+.\" Copyright (c) 2004, 2005
+.\"    Damien Bergamini <damien.bergamini%free.fr@localhost>. 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 unmodified, 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.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 THE AUTHOR OR CONTRIBUTORS 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.
+.\"
+.Dd September 26, 2004
+.Os
+.Dt IWICTL 8
+.Sh NAME
+.Nm iwictl
+.Nd configure Intel(R) PRO/Wireless 2200BG/2915ABG network adapters
+.Sh SYNOPSIS
+.Nm
+.Op Fl i
+.Ar iface
+.Nm
+.Op Fl i
+.Ar iface Fl d Ar directory
+.Op Fl m Ar bss|ibss
+.Nm
+.Op Fl i
+.Ar iface Fl k
+.Nm
+.Op Fl i
+.Ar iface Fl r
+.Sh DESCRIPTION
+The
+.Nm
+utility controls the operation of Intel(R) PRO/Wireless 2200BG/2915ABG
+networking devices via
+.Xr iwi 4
+driver.
+.Pp
+You should not use this program to configure IEEE 802.11 parameters. Use
+.Xr ifconfig 8
+instead.
+.Sh OPTIONS
+The options are as follows:
+.Bl -tag -width indent
+.It Fl i Ar iface
+Displays adapter's internal statistics.
+.It Fl i Ar iface Fl d Ar directory Oo Fl m Ar bss|ibss Oc
+Download firmware binary image to the adapter. The image is read from the
+.Ar directory
+directory. By default, the firmware binary image for BSS (aka infrastructure
+mode) mode is downloaded unless the
+.Fl m
+flag is given.
+.It Fl i Ar iface Fl k
+Kill the firmware and reset the adapter.
+.It Fl i Ar iface Fl r
+Displays the radio transmitter state (on or off).
+.El
+.Sh SEE ALSO
+.Xr iwi 4 ,
+.Xr ifconfig 8
+.Sh AUTHORS
+The
+.Nm
+utility and this man page were written by
+.An Damien Bergamini Aq damien.bergamini%free.fr@localhost .
diff -r ef92ec44d70b -r 68d51ec98409 usr.sbin/iwictl/iwictl.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/iwictl/iwictl.c  Tue Jan 11 18:28:37 2005 +0000
@@ -0,0 +1,312 @@
+/*     $Id: iwictl.c,v 1.1.1.1 2005/01/11 18:28:38 skrll Exp $ */
+
+/*-
+ * Copyright (c) 2004, 2005
+ *     Damien Bergamini <damien.bergamini%free.fr@localhost>. 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 unmodified, 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 THE AUTHOR OR CONTRIBUTORS 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$Id: iwictl.c,v 1.1.1.1 2005/01/11 18:28:38 skrll Exp $");
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+
+#include <net/if.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysexits.h>
+#include <unistd.h>
+
+#define SIOCSLOADFW     _IOW('i', 137, struct ifreq)
+#define SIOCSKILLFW     _IOW('i', 138, struct ifreq)
+#define SIOCGRADIO     _IOWR('i', 139, struct ifreq)
+#define SIOCGTABLE0    _IOWR('i', 140, struct ifreq)
+
+struct firmware {
+       void    *boot;
+       int     boot_size;
+       void    *ucode;
+       int     ucode_size;
+       void    *main;
+       int     main_size;
+};
+
+struct header {
+       u_int32_t       version;
+       u_int32_t       mode;
+} __attribute__((__packed__));
+
+extern char *optarg;
+extern int optind;
+
+static void usage(void);
+static int do_req(char *, unsigned long, void *);
+static void mmap_file(char *, void **, size_t *);
+static void load_firmware(char *, char *, char *);
+static void kill_firmware(char *);
+static void get_radio_state(char *);
+static void get_statistics(char *);
+
+int
+main(int argc, char **argv)
+{
+       int ch;
+       char *iface = NULL, *mode = "bss", *path = NULL;
+       int noflag = 1, kflag = 0, rflag = 0;
+
+       if (argc > 1 && argv[1][0] != '-') {
+               iface = argv[1];
+               optind++;
+       }
+
+       while ((ch = getopt(argc, argv, "d:i:km:r")) != -1) {
+               if (ch != 'i')
+                       noflag = 0;
+
+               switch (ch) {
+               case 'd':
+                       path = optarg;
+                       break;
+
+               case 'i':
+                       iface = optarg;
+                       break;
+
+               case 'k':
+                       kflag = 1;
+                       break;
+
+               case 'm':
+                       mode = optarg;
+                       break;
+
+               case 'r':
+                       rflag = 1;
+                       break;
+
+               default:
+                       usage();
+               }
+       }
+
+       if (iface == NULL)
+               usage();
+
+       if (kflag && (path != NULL || rflag))
+               usage();
+
+       if (kflag)
+               kill_firmware(iface);
+
+       if (path != NULL)
+               load_firmware(iface, path, mode);
+
+       if (rflag)
+               get_radio_state(iface);
+
+       if (noflag)
+               get_statistics(iface);
+
+       return EX_OK;
+}
+
+static void
+usage(void)
+{
+       extern char *__progname;
+
+       (void)fprintf(stderr, "usage:  %s iface\n"
+           "\t%s iface -d path [-m bss|ibss]\n"
+           "\t%s iface -k\n"
+           "\t%s iface -r\n", __progname, __progname, __progname,
+           __progname);
+
+       exit(EX_USAGE);
+}
+
+static int
+do_req(char *iface, unsigned long req, void *data)
+{
+       int s;
+       struct ifreq ifr;
+       int error;
+
+       if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
+               err(EX_OSERR, "Can't create socket");
+
+       (void)memset(&ifr, 0, sizeof ifr);
+       (void)strncpy(ifr.ifr_name, iface, sizeof ifr.ifr_name);
+       ifr.ifr_data = data;
+       error = ioctl(s, req, &ifr);
+
+       (void)close(s);
+
+       return error;
+}
+
+static void
+mmap_file(char *filename, void **addr, size_t *len)
+{
+       int fd;
+       struct stat st;
+
+       if ((fd = open(filename, O_RDONLY)) == -1)
+               err(EX_OSERR, "%s", filename);
+
+       if (fstat(fd, &st) == -1)
+               err(EX_OSERR, "Unable to stat %s", filename);
+
+       *len = st.st_size;
+
+       if ((*addr = mmap(NULL, st.st_size, PROT_READ, 0, fd, 0)) == NULL)
+               err(EX_OSERR, "Can't map %s into memory", filename);
+
+       *(char **)addr += sizeof (struct header);
+       *len -= sizeof (struct header);
+



Home | Main Index | Thread Index | Old Index