Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-5]: src Pullup 802.11 stuff (approved by jhawk)
details: https://anonhg.NetBSD.org/src/rev/883ff1ff4bde
branches: netbsd-1-5
changeset: 488619:883ff1ff4bde
user: onoe <onoe%NetBSD.org@localhost>
date: Fri Jul 21 18:55:56 2000 +0000
description:
Pullup 802.11 stuff (approved by jhawk)
- add support for nwkey to ifconfig
basesrc/sbin/ifconfig/ifconfig.c 1.88
basesrc/sbin/ifconfig/ifconfig.8 1.39
syssrc/sys/dev/ic/awi.c 1.26
syssrc/sys/dev/ic/awi_wep.c 1.3
syssrc/sys/dev/ic/awivar.h 1.12
syssrc/sys/dev/pcmcia/if_wi.c 1.26
syssrc/sys/net/if.c 1.69
syssrc/sys/net/if_ieee80211.h 1.5
diffstat:
sbin/ifconfig/ifconfig.8 | 25 ++++-
sbin/ifconfig/ifconfig.c | 235 ++++++++++++++++++++++++++++++++++++++---------
sys/dev/ic/awi.c | 8 +-
sys/dev/ic/awi_wep.c | 80 +++++++++++++++-
sys/dev/ic/awivar.h | 4 +-
sys/dev/pcmcia/if_wi.c | 110 +++++++++++++++++++++-
sys/net/if.c | 3 +-
sys/net/if_ieee80211.h | 15 ++-
8 files changed, 428 insertions(+), 52 deletions(-)
diffs (truncated from 664 to 300 lines):
diff -r f68dffcb74b6 -r 883ff1ff4bde sbin/ifconfig/ifconfig.8
--- a/sbin/ifconfig/ifconfig.8 Fri Jul 21 18:54:18 2000 +0000
+++ b/sbin/ifconfig/ifconfig.8 Fri Jul 21 18:55:56 2000 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: ifconfig.8,v 1.32.4.4 2000/07/21 18:45:45 onoe Exp $
+.\" $NetBSD: ifconfig.8,v 1.32.4.5 2000/07/21 18:55:57 onoe Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -300,6 +300,29 @@
Configure network ID for IEEE 802.11-based wireless network interfaces.
.Ar Id
can either be a string or a series of hexadecimal digits.
+.It Cm nwkey Ar key
+(IEEE 802.11 devices only)
+Enable WEP encryption for IEEE 802.11-based wireless network interfaces
+with the
+.Ar key .
+The
+.Ar key
+can either be a string, a series of hexadecimal digits, or a set of keys
+in the form
+.Ar n:k1,k2,k3,k4 ,
+where
+.Ar n
+specifies which of keys will be used for all transmitted packets,
+and four keys,
+.Ar k1
+through
+.Ar k4 ,
+are configured as WEP keys.
+Note that the order must be match within same network if multiple keys
+are used.
+.It Fl nwkey
+(IEEE 802.11 devices only)
+Disable WEP encryption for IEEE 802.11-based wireless network interfaces.
.It Cm tunnel Ar src_addr Ar dest_addr
(IP tunnel devices only)
Configure the physical source and destination address for IP tunnel
diff -r f68dffcb74b6 -r 883ff1ff4bde sbin/ifconfig/ifconfig.c
--- a/sbin/ifconfig/ifconfig.c Fri Jul 21 18:54:18 2000 +0000
+++ b/sbin/ifconfig/ifconfig.c Fri Jul 21 18:55:56 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ifconfig.c,v 1.79.4.2 2000/07/21 18:45:44 onoe Exp $ */
+/* $NetBSD: ifconfig.c,v 1.79.4.3 2000/07/21 18:55:56 onoe Exp $ */
/*-
* Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
@@ -80,7 +80,7 @@
#if 0
static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
#else
-__RCSID("$NetBSD: ifconfig.c,v 1.79.4.2 2000/07/21 18:45:44 onoe Exp $");
+__RCSID("$NetBSD: ifconfig.c,v 1.79.4.3 2000/07/21 18:55:56 onoe Exp $");
#endif
#endif /* not lint */
@@ -159,6 +159,7 @@
void setifmetric __P((const char *, int));
void setifmtu __P((const char *, int));
void setifnwid __P((const char *, int));
+void setifnwkey __P((const char *, int));
void setifnetmask __P((const char *, int));
void setifprefixlen __P((const char *, int));
void setnsellength __P((const char *, int));
@@ -230,6 +231,8 @@
{ "metric", NEXTARG, 0, setifmetric },
{ "mtu", NEXTARG, 0, setifmtu },
{ "nwid", NEXTARG, 0, setifnwid },
+ { "nwkey", NEXTARG, 0, setifnwkey },
+ { "-nwkey", -1, 0, setifnwkey },
{ "broadcast", NEXTARG, 0, setifbroadaddr },
{ "ipdst", NEXTARG, 0, setifipdst },
{ "prefixlen", NEXTARG, 0, setifprefixlen},
@@ -274,6 +277,8 @@
int prefix __P((void *, int));
void status __P((const u_int8_t *, int));
void usage __P((void));
+const char *get_string __P((const char *, const char *, u_int8_t *, int *));
+void print_string __P((const u_int8_t *, int));
char *sec2str __P((time_t));
const char *get_media_type_string __P((int));
@@ -1044,6 +1049,88 @@
warn("SIOCSIFMTU");
}
+const char *
+get_string(val, sep, buf, lenp)
+ const char *val, *sep;
+ u_int8_t *buf;
+ int *lenp;
+{
+ int len;
+ int hexstr;
+ u_int8_t *p;
+
+ len = *lenp;
+ p = buf;
+ hexstr = (val[0] == '0' && tolower((u_char)val[1]) == 'x');
+ if (hexstr)
+ val += 2;
+ for (;;) {
+ if (*val == '\0')
+ break;
+ if (sep != NULL && strchr(sep, *val) != NULL) {
+ val++;
+ break;
+ }
+ if (hexstr) {
+ if (!isxdigit((u_char)val[0]) ||
+ !isxdigit((u_char)val[1])) {
+ warnx("bad hexadecimal digits");
+ return NULL;
+ }
+ }
+ if (p > buf + len) {
+ if (hexstr)
+ warnx("hexadecimal digits too long");
+ else
+ warnx("strings too long");
+ return NULL;
+ }
+ if (hexstr) {
+#define tohex(x) (isdigit(x) ? (x) - '0' : tolower(x) - 'a' + 10)
+ *p++ = (tohex((u_char)val[0]) << 4) |
+ tohex((u_char)val[1]);
+#undef tohex
+ val += 2;
+ } else
+ *p++ = *val++;
+ }
+ len = p - buf;
+ if (len < *lenp)
+ memset(p, 0, *lenp - len);
+ *lenp = len;
+ return val;
+}
+
+void
+print_string(buf, len)
+ const u_int8_t *buf;
+ int len;
+{
+ int i;
+ int hasspc;
+
+ i = 0;
+ hasspc = 0;
+ if (len < 2 || buf[0] != '0' || tolower(buf[1]) != 'x') {
+ for (; i < len; i++) {
+ if (!isprint(buf[i]))
+ break;
+ if (isspace(buf[i]))
+ hasspc++;
+ }
+ }
+ if (i == len) {
+ if (hasspc || len == 0)
+ printf("\"%.*s\"", len, buf);
+ else
+ printf("%.*s", len, buf);
+ } else {
+ printf("0x");
+ for (i = 0; i < len; i++)
+ printf("%02x", buf[i]);
+ }
+}
+
void
setifnwid(val, d)
const char *val;
@@ -1051,37 +1138,11 @@
{
struct ieee80211_nwid nwid;
int len;
- u_int8_t *p;
- memset(&nwid, 0, sizeof(nwid));
- if (val[0] == '0' && (val[1] == 'x' || val[1] == 'X')) {
- val += 2;
- p = nwid.i_nwid;
- while (isxdigit((u_char)val[0]) && isxdigit((u_char)val[1])) {
- if (p >= nwid.i_nwid + sizeof(nwid.i_nwid)) {
- warnx("SIOCS80211NWID: Too long nwid.");
- return;
- }
-#define tohex(x) (isdigit(x) ? (x) - '0' : tolower(x) - 'a' + 10)
- *p++ = (tohex((u_char)val[0]) << 4) |
- tohex((u_char)val[1]);
-#undef tohex
- val += 2;
- }
- if (*val != '\0') {
- warnx("SIOCS80211NWID: Bad hexadecimal digits.");
- return;
- }
- nwid.i_len = p - nwid.i_nwid;
- } else {
- len = strlen(val);
- if (len > sizeof(nwid.i_nwid)) {
- warnx("SIOCS80211NWID: Too long nwid.");
- return;
- }
- nwid.i_len = len;
- memcpy(nwid.i_nwid, val, len);
- }
+ len = sizeof(nwid.i_nwid);
+ if (get_string(val, NULL, nwid.i_nwid, &len) == NULL)
+ return;
+ nwid.i_len = len;
(void)strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_data = (caddr_t)&nwid;
if (ioctl(s, SIOCS80211NWID, (caddr_t)&ifr) < 0)
@@ -1089,10 +1150,59 @@
}
void
+setifnwkey(val, d)
+ const char *val;
+ int d;
+{
+ struct ieee80211_nwkey nwkey;
+ int i;
+ u_int8_t keybuf[IEEE80211_WEP_NKID][16];
+
+ nwkey.i_wepon = 1;
+ nwkey.i_defkid = 1;
+ for (i = 0; i < IEEE80211_WEP_NKID; i++) {
+ nwkey.i_key[i].i_keylen = sizeof(keybuf[i]);
+ nwkey.i_key[i].i_keydat = keybuf[i];
+ }
+ if (d != 0) {
+ /* disable WEP encryption */
+ nwkey.i_wepon = 0;
+ i = 0;
+ } else if (isdigit(val[0]) && val[1] == ':') {
+ /* specifying a full set of four keys */
+ nwkey.i_defkid = val[0] - '0';
+ val += 2;
+ for (i = 0; i < IEEE80211_WEP_NKID; i++) {
+ val = get_string(val, ",", keybuf[i],
+ &nwkey.i_key[i].i_keylen);
+ if (val == NULL)
+ return;
+ }
+ if (*val != '\0') {
+ warnx("SIOCS80211NWKEY: too many keys.");
+ return;
+ }
+ } else {
+ val = get_string(val, NULL, keybuf[0],
+ &nwkey.i_key[0].i_keylen);
+ if (val == NULL)
+ return;
+ i = 1;
+ }
+ for (; i < IEEE80211_WEP_NKID; i++)
+ nwkey.i_key[i].i_keylen = 0;
+ (void)strncpy(nwkey.i_name, name, sizeof(nwkey.i_name));
+ if (ioctl(s, SIOCS80211NWKEY, (caddr_t)&nwkey) < 0)
+ warn("SIOCS80211NWKEY");
+}
+
+void
ieee80211_status()
{
int i;
struct ieee80211_nwid nwid;
+ struct ieee80211_nwkey nwkey;
+ u_int8_t keybuf[IEEE80211_WEP_NKID][16];
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_data = (caddr_t)&nwid;
@@ -1103,21 +1213,55 @@
warnx("SIOCG80211NWID: wrong length of nwid (%d)", nwid.i_len);
return;
}
- i = 0;
- if (nwid.i_nwid[0] != '0' || tolower(nwid.i_nwid[1]) != 'x') {
- for (; i < nwid.i_len; i++) {
- if (!isprint(nwid.i_nwid[i]))
- break;
+ printf("\tnwid ");
+ print_string(nwid.i_nwid, nwid.i_len);
+ memset(&nwkey, 0, sizeof(nwkey));
+ (void)strncpy(nwkey.i_name, name, sizeof(nwkey.i_name));
+ /* show nwkey only when WEP is enabled */
+ if (ioctl(s, SIOCG80211NWKEY, (caddr_t)&nwkey) != 0 ||
+ nwkey.i_wepon == 0) {
+ printf("\n");
+ return;
+ }
+
+ printf(" nwkey ");
+ /* try to retrieve WEP keys */
+ for (i = 0; i < IEEE80211_WEP_NKID; i++) {
+ nwkey.i_key[i].i_keydat = keybuf[i];
+ nwkey.i_key[i].i_keylen = sizeof(keybuf[i]);
+ }
Home |
Main Index |
Thread Index |
Old Index