Source-Changes-HG archive

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

[src/netbsd-1-4]: src/usr.sbin/wiconfig Pull up revisions 1.1-1.4 (requested ...



details:   https://anonhg.NetBSD.org/src/rev/8e138dd02b39
branches:  netbsd-1-4
changeset: 470567:8e138dd02b39
user:      he <he%NetBSD.org@localhost>
date:      Wed May 10 19:30:00 2000 +0000

description:
Pull up revisions 1.1-1.4 (requested by jhawk):
  Add a driver for ``wi'', Lucent "Orinoco"/Wavelan.

diffstat:

 usr.sbin/wiconfig/wiconfig.c |  738 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 738 insertions(+), 0 deletions(-)

diffs (truncated from 742 to 300 lines):

diff -r d4556aaf50be -r 8e138dd02b39 usr.sbin/wiconfig/wiconfig.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/wiconfig/wiconfig.c      Wed May 10 19:30:00 2000 +0000
@@ -0,0 +1,738 @@
+/*
+ * Copyright (c) 1997, 1998, 1999
+ *     Bill Paul <wpaul%ctr.columbia.edu@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, 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.
+ *
+ *     $Id: wiconfig.c,v 1.4.2.2 2000/05/10 19:30:00 he Exp $
+ */
+
+#include <sys/types.h>
+#include <sys/cdefs.h>
+#include <sys/param.h>
+#include <sys/socket.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>
+#ifdef __NetBSD__
+#include <dev/pcmcia/if_wi_ieee.h>
+#else
+#include <dev/pcmcia/if_wavelan_ieee.h>
+#endif
+#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[] =
+       "@(#) $Id: wiconfig.c,v 1.4.2.2 2000/05/10 19:30:00 he Exp $";
+#endif
+
+static void wi_getval          __P((char *, struct wi_req *));
+static void wi_setval          __P((char *, struct wi_req *));
+static void wi_printstr                __P((struct wi_req *));
+static void wi_setstr          __P((char *, int, char *));
+static void wi_setbytes                __P((char *, int, char *, int));
+static void wi_setword         __P((char *, int, int));
+static void wi_sethex          __P((char *, int, char *));
+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)
+       char                    *iface;
+       struct wi_req           *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);
+       ifr.ifr_data = (caddr_t)wreq;
+
+       s = socket(AF_INET, SOCK_DGRAM, 0);
+
+       if (s == -1)
+               err(1, "socket");
+
+       if (ioctl(s, SIOCGWAVELAN, &ifr) == -1)
+               err(1, "SIOCGWAVELAN");
+
+       close(s);
+
+       return;
+}
+
+static void wi_setval(iface, wreq)
+       char                    *iface;
+       struct wi_req           *wreq;
+{
+       struct ifreq            ifr;
+       int                     s;
+
+       bzero((char *)&ifr, sizeof(ifr));
+
+       strcpy(ifr.ifr_name, iface);
+       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);
+
+       return;
+}
+
+void wi_printstr(wreq)
+       struct wi_req           *wreq;
+{
+       char                    *ptr;
+       int                     i;
+
+       if (wreq->wi_type == WI_RID_SERIALNO) {
+               ptr = (char *)&wreq->wi_val;
+               for (i = 0; i < (wreq->wi_len - 1) * 2; i++) {
+                       if (ptr[i] == '\0')
+                               ptr[i] = ' ';
+               }
+       } else {
+               ptr = (char *)&wreq->wi_val[1];
+               for (i = 0; i < wreq->wi_val[0]; i++) {
+                       if (ptr[i] == '\0')
+                               ptr[i] = ' ';
+               }
+       }
+
+       ptr[i] = '\0';
+       printf("[ %s ]", ptr);
+
+       return;
+}
+
+void wi_setstr(iface, code, str)
+       char                    *iface;
+       int                     code;
+       char                    *str;
+{
+       struct wi_req           wreq;
+
+       if (iface == NULL)
+               errx(1, "must specify interface name");
+
+       if (str == NULL)
+               errx(1, "must specify string");
+
+       bzero((char *)&wreq, sizeof(wreq));
+
+       if (strlen(str) > 30)
+               errx(1, "string too long");
+
+       wreq.wi_type = code;
+       wreq.wi_len = 18;
+       wreq.wi_val[0] = strlen(str);
+       bcopy(str, (char *)&wreq.wi_val[1], strlen(str));
+
+       wi_setval(iface, &wreq);
+
+       return;
+}
+
+void wi_setbytes(iface, code, bytes, len)
+       char                    *iface;
+       int                     code;
+       char                    *bytes;
+       int                     len;
+{
+       struct wi_req           wreq;
+
+       if (iface == NULL)
+               errx(1, "must specify interface name");
+
+       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);
+
+       return;
+}
+
+void wi_setword(iface, code, word)
+       char                    *iface;
+       int                     code;
+       int                     word;
+{
+       struct wi_req           wreq;
+
+       if (iface == NULL)
+               errx(1, "must specify interface name");
+
+       bzero((char *)&wreq, sizeof(wreq));
+
+       wreq.wi_type = code;
+       wreq.wi_len = 2;
+       wreq.wi_val[0] = word;
+
+       wi_setval(iface, &wreq);
+
+       return;
+}
+
+void wi_sethex(iface, code, str)
+       char                    *iface;
+       int                     code;
+       char                    *str;
+{
+       struct ether_addr       *addr;
+
+       if (iface == NULL)
+               errx(1, "must specify interface name");
+       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);
+
+       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));



Home | Main Index | Thread Index | Old Index