summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2005-05-25 07:40:50 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2005-05-25 07:40:50 +0000
commit195394ca0fd77eaf853201a38a23a40bfb1d4e91 (patch)
treefa1f8457ab4564ce39538fc88528d2959064a196 /sbin
parentdddc74b20f5c57dc55e2d67c27ee9a237c8021f3 (diff)
add ifconfig -M option to replace wicontrol -L and -l for ap scanning
and node listing. wicontrol is not supported by net80211 drivers anymore. further improvements will be done. ok dlg@, jsg@
Diffstat (limited to 'sbin')
-rw-r--r--sbin/ifconfig/ifconfig.811
-rw-r--r--sbin/ifconfig/ifconfig.c209
-rw-r--r--sbin/wicontrol/wicontrol.c6
3 files changed, 181 insertions, 45 deletions
diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8
index eef1f889167..980ef6b6c54 100644
--- a/sbin/ifconfig/ifconfig.8
+++ b/sbin/ifconfig/ifconfig.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ifconfig.8,v 1.104 2005/05/24 02:45:18 reyk Exp $
+.\" $OpenBSD: ifconfig.8,v 1.105 2005/05/25 07:40:49 reyk Exp $
.\" $NetBSD: ifconfig.8,v 1.11 1996/01/04 21:27:29 pk Exp $
.\" $FreeBSD: ifconfig.8,v 1.16 1998/02/01 07:03:29 steve Exp $
.\"
@@ -47,15 +47,11 @@
.Oc
.Op Ar parameters
.Nm ifconfig
-.Fl A | Am | a | am
+.Fl aAmM
.Op Ar address_family
.Nm ifconfig
.Fl C
.Nm ifconfig
-.Fl m
-.Ar interface
-.Op Ar address_family
-.Nm ifconfig
.Ar interface
.Cm create
.Nm ifconfig
@@ -165,6 +161,9 @@ but additionally prints interface media information for all interfaces.
Print the names of all network pseudo-devices that
can be created dynamically at runtime using
.Cm ifconfig create .
+.It Fl M
+For the chosen 802.11 interfaces, show the results of an access point
+scan. In Host AP mode, this will dump the list of known nodes.
.It Fl m Ar interface
Print media information for a given
.Ar interface .
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index ccc1ef1e70e..cb255485969 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ifconfig.c,v 1.139 2005/05/24 07:51:53 reyk Exp $ */
+/* $OpenBSD: ifconfig.c,v 1.140 2005/05/25 07:40:49 reyk Exp $ */
/* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */
/*
@@ -136,6 +136,7 @@ int clearaddr, s;
int newaddr = 0;
int af = AF_INET;
int mflag;
+int net80211flag;
int explicit_prefix = 0;
#ifdef INET6
int Lflag = 1;
@@ -358,6 +359,7 @@ int getinfo(struct ifreq *, int);
void getsock(int);
void printif(struct ifreq *, int);
void printb(char *, unsigned short, char *);
+void printb_status(unsigned short, char *);
void status(int, struct sockaddr_dl *);
void usage(int);
const char *get_string(const char *, const char *, u_int8_t *, int *);
@@ -398,6 +400,8 @@ void xns_getaddr(const char *, int);
void ipx_status(int);
void ipx_getaddr(const char *, int);
void ieee80211_status(void);
+void ieee80211_listnodes(void);
+void ieee80211_printnode(struct ieee80211_nodereq *);
/* Known address families */
const struct afswtch {
@@ -447,29 +451,42 @@ main(int argc, char *argv[])
exit(0);
}
argc--, argv++;
- if (!strcmp(*argv, "-a"))
- aflag = 1;
- else if (!strcmp(*argv, "-A")) {
- aflag = 1;
- ifaliases = 1;
- } else if (!strcmp(*argv, "-ma") || !strcmp(*argv, "-am")) {
- aflag = 1;
- mflag = 1;
- } else if (!strcmp(*argv, "-mA") || !strcmp(*argv, "-Am")) {
- aflag = 1;
- ifaliases = 1;
- mflag = 1;
- } else if (!strcmp(*argv, "-m")) {
- mflag = 1;
- argc--, argv++;
- if (argc < 1)
- usage(1);
- if (strlcpy(name, *argv, sizeof(name)) >= IFNAMSIZ)
- errx(1, "interface name '%s' too long", *argv);
- } else if (!strcmp(*argv, "-C")) {
- Cflag = 1;
- } else if (*argv[0] == '-') {
- usage(0);
+ if (*argv[0] == '-') {
+ int nomore = 0;
+
+ for (i = 1; argv[0][i]; i++) {
+ switch (argv[0][i]) {
+ case 'a':
+ aflag = 1;
+ nomore = 1;
+ break;
+ case 'A':
+ aflag = 1;
+ ifaliases = 1;
+ nomore = 1;
+ break;
+ case 'm':
+ mflag = 1;
+ break;
+ case 'M':
+ net80211flag = 1;
+ break;
+ case 'C':
+ Cflag = 1;
+ nomore = 1;
+ break;
+ default:
+ usage(1);
+ break;
+ }
+ }
+ if (nomore == 0) {
+ argc--, argv++;
+ if (argc < 1)
+ usage(1);
+ if (strlcpy(name, *argv, sizeof(name)) >= IFNAMSIZ)
+ errx(1, "interface name '%s' too long", *argv);
+ }
} else if (strlcpy(name, *argv, sizeof(name)) >= IFNAMSIZ)
errx(1, "interface name '%s' too long", *argv);
argc--, argv++;
@@ -1212,6 +1229,9 @@ setifnwkey(const char *val, int d)
struct ieee80211_nwkey nwkey;
u_int8_t keybuf[IEEE80211_WEP_NKID][16];
+ bzero(&nwkey, sizeof(nwkey));
+ bzero(&keybuf, sizeof(keybuf));
+
nwkey.i_wepon = IEEE80211_NWKEY_WEP;
nwkey.i_defkid = 1;
if (d == -1) {
@@ -1257,11 +1277,6 @@ setifnwkey(const char *val, int d)
i = 1;
}
}
- /* zero out any unset keys */
- for (; i < IEEE80211_WEP_NKID; i++) {
- nwkey.i_key[i].i_keylen = 0;
- nwkey.i_key[i].i_keydat = NULL;
- }
(void)strlcpy(nwkey.i_name, name, sizeof(nwkey.i_name));
if (ioctl(s, SIOCS80211NWKEY, (caddr_t)&nwkey) == -1)
warn("SIOCS80211NWKEY");
@@ -1405,7 +1420,7 @@ ieee80211_status(void)
if (len > IEEE80211_NWID_LEN)
len = IEEE80211_NWID_LEN;
fputs("nwid ", stdout);
- print_string(nwid.i_nwid, nwid.i_len);
+ print_string(nwid.i_nwid, len);
putchar(' ');
}
@@ -1483,11 +1498,108 @@ ieee80211_status(void)
printf("powersave on (%dms sleep) ", power.i_maxsleep);
if (itxpower == 0)
- printf("%ddBm %s", txpower.i_val,
- txpower.i_mode == IEEE80211_TXPOWER_MODE_AUTO ?
+ printf("%ddBm %s", txpower.i_val,
+ txpower.i_mode == IEEE80211_TXPOWER_MODE_AUTO ?
"(auto) " : "");
putchar('\n');
+ if (net80211flag)
+ ieee80211_listnodes();
+}
+
+void
+ieee80211_listnodes(void)
+{
+ struct ieee80211_nodereq_all na;
+ struct ieee80211_nodereq nr[512];
+ struct ifreq ifr;
+ int i, ret, down = 0;
+
+ if ((flags & IFF_UP) == 0) {
+ down = 1;
+ setifflags("up", IFF_UP);
+ }
+
+ bzero(&ifr, sizeof(ifr));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+
+ if (ioctl(s, SIOCS80211SCAN, (caddr_t)&ifr) != 0)
+ goto done;
+
+ bzero(&na, sizeof(na));
+ bzero(&nr, sizeof(nr));
+ na.na_node = nr;
+ na.na_size = sizeof(nr);
+ strlcpy(na.na_ifname, name, sizeof(na.na_ifname));
+ ret = 1;
+
+ if (ioctl(s, SIOCG80211ALLNODES, &na) != 0) {
+ warn("SIOCG80211ALLNODES");
+ goto done;
+ }
+
+ if (!na.na_nodes)
+ printf("\t\tnone\n");
+
+ for (i = 0; i < na.na_nodes; i++) {
+ printf("\t\t");
+ ieee80211_printnode(&nr[i]);
+ putchar('\n');
+ }
+
+ ret = 0;
+
+ done:
+ if (down)
+ setifflags("restore", -IFF_UP);
+
+ if (ret != 0)
+ exit(1);
+
+}
+
+void
+ieee80211_printnode(struct ieee80211_nodereq *nr)
+{
+ int len, i, isap;
+
+ if (nr->nr_flags & IEEE80211_NODEREQ_AP) {
+ len = nr->nr_nwid_len;
+ if (len > IEEE80211_NWID_LEN)
+ len = IEEE80211_NWID_LEN;
+ printf("nwid ");
+ print_string(nr->nr_nwid, len);
+ putchar(' ');
+
+ printf("chan %u ", nr->nr_channel);
+ }
+
+ if (nr->nr_flags & IEEE80211_NODEREQ_AP)
+ printf("bssid %s ",
+ ether_ntoa((struct ether_addr*)nr->nr_bssid));
+ else
+ printf("lladdr %s ",
+ ether_ntoa((struct ether_addr*)nr->nr_macaddr));
+
+ printf("%udB ", nr->nr_rssi);
+
+ if (nr->nr_pwrsave)
+ printf("powersave ");
+ if (nr->nr_nrates) {
+ /* Only print the fastest rate */
+ printf("%uM",
+ (nr->nr_rates[nr->nr_nrates - 1] & IEEE80211_RATE_VAL) / 2);
+ putchar(' ');
+ }
+ /* ESS is the default, skip it */
+ nr->nr_capinfo &= ~IEEE80211_CAPINFO_ESS;
+ if (nr->nr_capinfo) {
+ printb_status(nr->nr_capinfo, IEEE80211_CAPINFO_BITS);
+ putchar(' ');
+ }
+ if ((nr->nr_flags & IEEE80211_NODEREQ_AP) == 0)
+ printb_status(IEEE80211_NODEREQ_STATE(nr->nr_state),
+ IEEE80211_NODEREQ_STATE_BITS);
}
void
@@ -2016,7 +2128,6 @@ status(int link, struct sockaddr_dl *sdl)
timeslot_status();
trunk_status();
#endif
- ieee80211_status();
getifgroups();
(void) memset(&ifmr, 0, sizeof(ifmr));
@@ -2083,6 +2194,8 @@ status(int link, struct sockaddr_dl *sdl)
putchar('\n');
}
+ ieee80211_status();
+
if (mflag) {
int type, printed_type = 0;
@@ -3331,6 +3444,31 @@ printb(char *s, unsigned short v, char *bits)
}
}
+/*
+ * A simple version of printb for status output
+ */
+void
+printb_status(unsigned short v, char *bits)
+{
+ int i, any = 0;
+ char c;
+
+ bits++;
+ if (bits) {
+ while ((i = *bits++)) {
+ if (v & (1 << (i-1))) {
+ if (any)
+ putchar(',');
+ any = 1;
+ for (; (c = *bits) > 32; bits++)
+ putchar(tolower(c));
+ } else
+ for (; *bits > 32; bits++)
+ ;
+ }
+ }
+}
+
#ifdef INET6
#define SIN6(x) ((struct sockaddr_in6 *) &(x))
struct sockaddr_in6 *sin6tab[] = {
@@ -3455,9 +3593,7 @@ usage(int value)
"\t[802.2] [802.2tr] [802.3] [snap] [EtherII]\n"
"\t[pppoeac access-concentrator] [-pppoeac]\n"
"\t[pppoesvc service] [-pppoesvc]\n"
- " ifconfig -A | -Am | -a | -am [address_family]\n"
- " ifconfig -C\n"
- " ifconfig -m interface [address_family]\n"
+ " ifconfig [-aAmMC] [interface] [address_family]\n"
" ifconfig interface create\n"
" ifconfig interface destroy\n");
exit(value);
@@ -3572,3 +3708,4 @@ setiflladdr(const char *addr, int param)
if (ioctl(s, SIOCSIFLLADDR, (caddr_t)&ifr) < 0)
warn("SIOCSIFLLADDR");
}
+
diff --git a/sbin/wicontrol/wicontrol.c b/sbin/wicontrol/wicontrol.c
index d3b494460d7..9f3a1e24ec8 100644
--- a/sbin/wicontrol/wicontrol.c
+++ b/sbin/wicontrol/wicontrol.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wicontrol.c,v 1.57 2004/11/24 18:11:15 fgsch Exp $ */
+/* $OpenBSD: wicontrol.c,v 1.58 2005/05/25 07:40:49 reyk Exp $ */
/*
* Copyright (c) 1997, 1998, 1999
@@ -68,7 +68,7 @@
static const char copyright[] = "@(#) Copyright (c) 1997, 1998, 1999\
Bill Paul. All rights reserved.";
static const char rcsid[] =
- "@(#) $OpenBSD: wicontrol.c,v 1.57 2004/11/24 18:11:15 fgsch Exp $";
+ "@(#) $OpenBSD: wicontrol.c,v 1.58 2005/05/25 07:40:49 reyk Exp $";
#endif
int wi_getval(char *, struct wi_req *);
@@ -122,7 +122,7 @@ wi_getval(char *iface, struct wi_req *wreq)
if (error == -1) {
warn("SIOCGWAVELAN (0x%x)", wreq->wi_type);
- if (errno == ENXIO)
+ if (errno == ENXIO || errno == EINVAL)
exit(1);
}
close(s);