summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hessler <phessler@cvs.openbsd.org>2018-11-25 12:14:02 +0000
committerPeter Hessler <phessler@cvs.openbsd.org>2018-11-25 12:14:02 +0000
commite8c90cfc73509c1297d5529255650a4837fde0ec (patch)
treea7886981a8bdc565ea46d17244fc2e56e1c75452
parent298aea3d8c2745b020889aa551cb50e63f45cfcc (diff)
print more details about the join'd networks we have saved when a user runs
ifconfig if joinlist OK stsp@
-rw-r--r--sbin/ifconfig/ifconfig.c77
-rw-r--r--sys/net80211/ieee80211_ioctl.c53
-rw-r--r--sys/net80211/ieee80211_ioctl.h3
-rw-r--r--sys/net80211/ieee80211_node.c6
4 files changed, 131 insertions, 8 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index d2c598130ef..a08d3a32728 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ifconfig.c,v 1.385 2018/11/25 12:10:38 phessler Exp $ */
+/* $OpenBSD: ifconfig.c,v 1.386 2018/11/25 12:14:01 phessler Exp $ */
/* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */
/*
@@ -630,6 +630,7 @@ const char *get_linkstate(int, int);
void status(int, struct sockaddr_dl *, int);
__dead void usage(void);
const char *get_string(const char *, const char *, u_int8_t *, int *);
+int len_string(const u_int8_t *, int);
int print_string(const u_int8_t *, int);
char *sec2str(time_t);
@@ -1652,6 +1653,29 @@ get_string(const char *val, const char *sep, u_int8_t *buf, int *lenp)
}
int
+len_string(const u_int8_t *buf, int len)
+{
+ int i = 0, hasspc = 0;
+
+ if (len < 2 || buf[0] != '0' || tolower(buf[1]) != 'x') {
+ for (; i < len; i++) {
+ /* Only print 7-bit ASCII keys */
+ if (buf[i] & 0x80 || !isprint(buf[i]))
+ break;
+ if (isspace(buf[i]))
+ hasspc++;
+ }
+ }
+ if (i == len) {
+ if (hasspc || len == 0)
+ return len + 2;
+ else
+ return len;
+ } else
+ return (len * 2) + 2;
+}
+
+int
print_string(const u_int8_t *buf, int len)
{
int i = 0, hasspc = 0;
@@ -2429,10 +2453,12 @@ join_status(void)
{
struct ieee80211_joinreq_all ja;
struct ieee80211_join *jn = NULL;
+ struct ieee80211_wpaparams *wpa;
int jsz = 100;
int ojsz;
int i;
int r;
+ int maxlen, len;
bzero(&ja, sizeof(ja));
jn = recallocarray(NULL, 0, jsz, sizeof(*jn));
@@ -2462,13 +2488,54 @@ join_status(void)
if (!ja.ja_nodes)
return;
- fputs("\tjoin: ", stdout);
+ maxlen = 0;
for (i = 0; i < ja.ja_nodes; i++) {
- if (i > 0)
- printf("\t ");
+ len = len_string(jn[i].i_nwid, jn[i].i_len);
+ if (len > maxlen)
+ maxlen = len;
+ }
+ if (maxlen > IEEE80211_NWID_LEN)
+ maxlen = IEEE80211_NWID_LEN - 1;
+
+ for (i = 0; i < ja.ja_nodes; i++) {
+ printf("\t ");
if (jn[i].i_len > IEEE80211_NWID_LEN)
jn[i].i_len = IEEE80211_NWID_LEN;
- print_string(jn[i].i_nwid, jn[i].i_len);
+ len = print_string(jn[i].i_nwid, jn[i].i_len);
+ printf("%-*s", maxlen - len, " ");
+ if (jn[i].i_flags) {
+ const char *sep;
+ printf(" ");
+
+ if (jn[i].i_flags & IEEE80211_JOIN_NWKEY)
+ printf("nwkey");
+
+ if (jn[i].i_flags & IEEE80211_JOIN_WPA) {
+ wpa = &jn[i].i_wpaparams;
+
+ printf("wpaprotos "); sep = "";
+ if (wpa->i_protos & IEEE80211_WPA_PROTO_WPA1) {
+ printf("wpa1");
+ sep = ",";
+ }
+ if (wpa->i_protos & IEEE80211_WPA_PROTO_WPA2)
+ printf("%swpa2", sep);
+
+ printf(" wpaakms ", stdout); sep = "";
+ if (wpa->i_akms & IEEE80211_WPA_AKM_PSK) {
+ printf("psk");
+ sep = ",";
+ }
+ if (wpa->i_akms & IEEE80211_WPA_AKM_8021X)
+ printf("%s802.1x", sep);
+
+ printf(" wpaciphers ");
+ print_cipherset(wpa->i_ciphers);
+
+ printf(" wpagroupcipher ");
+ print_cipherset(wpa->i_groupcipher);
+ }
+ }
putchar('\n');
}
}
diff --git a/sys/net80211/ieee80211_ioctl.c b/sys/net80211/ieee80211_ioctl.c
index 500a5306b06..25beaa041c7 100644
--- a/sys/net80211/ieee80211_ioctl.c
+++ b/sys/net80211/ieee80211_ioctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ieee80211_ioctl.c,v 1.68 2018/10/27 09:55:26 phessler Exp $ */
+/* $OpenBSD: ieee80211_ioctl.c,v 1.69 2018/11/25 12:14:01 phessler Exp $ */
/* $NetBSD: ieee80211_ioctl.c,v 1.15 2004/05/06 02:58:16 dyoung Exp $ */
/*-
@@ -387,6 +387,48 @@ ieee80211_ioctl_getwpaparms(struct ieee80211com *ic,
return 0;
}
+static void
+ieee80211_ess_getwpaparms(struct ieee80211_ess *ess,
+ struct ieee80211_wpaparams *wpa)
+{
+ wpa->i_enabled = (ess->flags & IEEE80211_F_RSNON) ? 1 : 0;
+
+ wpa->i_protos = 0;
+ if (ess->rsnprotos & IEEE80211_PROTO_WPA)
+ wpa->i_protos |= IEEE80211_WPA_PROTO_WPA1;
+ if (ess->rsnprotos & IEEE80211_PROTO_RSN)
+ wpa->i_protos |= IEEE80211_WPA_PROTO_WPA2;
+
+ wpa->i_akms = 0;
+ if (ess->rsnakms & IEEE80211_AKM_PSK)
+ wpa->i_akms |= IEEE80211_WPA_AKM_PSK;
+ if (ess->rsnakms & IEEE80211_AKM_SHA256_PSK)
+ wpa->i_akms |= IEEE80211_WPA_AKM_SHA256_PSK;
+ if (ess->rsnakms & IEEE80211_AKM_8021X)
+ wpa->i_akms |= IEEE80211_WPA_AKM_8021X;
+ if (ess->rsnakms & IEEE80211_AKM_SHA256_8021X)
+ wpa->i_akms |= IEEE80211_WPA_AKM_SHA256_8021X;
+
+ if (ess->rsngroupcipher == IEEE80211_CIPHER_WEP40)
+ wpa->i_groupcipher = IEEE80211_WPA_CIPHER_WEP40;
+ else if (ess->rsngroupcipher == IEEE80211_CIPHER_TKIP)
+ wpa->i_groupcipher = IEEE80211_WPA_CIPHER_TKIP;
+ else if (ess->rsngroupcipher == IEEE80211_CIPHER_CCMP)
+ wpa->i_groupcipher = IEEE80211_WPA_CIPHER_CCMP;
+ else if (ess->rsngroupcipher == IEEE80211_CIPHER_WEP104)
+ wpa->i_groupcipher = IEEE80211_WPA_CIPHER_WEP104;
+ else
+ wpa->i_groupcipher = IEEE80211_WPA_CIPHER_NONE;
+
+ wpa->i_ciphers = 0;
+ if (ess->rsnciphers & IEEE80211_CIPHER_TKIP)
+ wpa->i_ciphers |= IEEE80211_WPA_CIPHER_TKIP;
+ if (ess->rsnciphers & IEEE80211_CIPHER_CCMP)
+ wpa->i_ciphers |= IEEE80211_WPA_CIPHER_CCMP;
+ if (ess->rsnciphers & IEEE80211_CIPHER_USEGROUP)
+ wpa->i_ciphers = IEEE80211_WPA_CIPHER_USEGROUP;
+}
+
int
ieee80211_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
{
@@ -506,6 +548,15 @@ ieee80211_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
memset(&join, 0, sizeof(join));
join.i_len = ess->esslen;
memcpy(&join.i_nwid, ess->essid, join.i_len);
+ if (ess->flags & IEEE80211_F_RSNON)
+ join.i_flags |= IEEE80211_JOIN_WPA;
+ if (ess->flags & IEEE80211_F_PSK)
+ join.i_flags |= IEEE80211_JOIN_WPAPSK;
+ if (ess->flags & IEEE80211_JOIN_8021X)
+ join.i_flags |= IEEE80211_JOIN_8021X;
+ if (ess->flags & IEEE80211_F_WEPON)
+ join.i_flags |= IEEE80211_JOIN_NWKEY;
+ ieee80211_ess_getwpaparms(ess, &join.i_wpaparams);
error = copyout(&join, &ja->ja_node[ja->ja_nodes],
sizeof(ja->ja_node[0]));
if (error)
diff --git a/sys/net80211/ieee80211_ioctl.h b/sys/net80211/ieee80211_ioctl.h
index 868ff95b835..3c5b1c4ef55 100644
--- a/sys/net80211/ieee80211_ioctl.h
+++ b/sys/net80211/ieee80211_ioctl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ieee80211_ioctl.h,v 1.34 2018/09/09 20:32:55 phessler Exp $ */
+/* $OpenBSD: ieee80211_ioctl.h,v 1.35 2018/11/25 12:14:01 phessler Exp $ */
/* $NetBSD: ieee80211_ioctl.h,v 1.7 2004/04/30 22:51:04 dyoung Exp $ */
/*-
@@ -304,6 +304,7 @@ struct ieee80211_joinreq_all {
#define IEEE80211_JOIN_NWKEY 0x08
#define IEEE80211_JOIN_WPA 0x10
#define IEEE80211_JOIN_WPAPSK 0x20
+#define IEEE80211_JOIN_8021X 0x40
/* node and requests */
struct ieee80211_nodereq {
diff --git a/sys/net80211/ieee80211_node.c b/sys/net80211/ieee80211_node.c
index 122fca7d3b6..9a7d7119c0f 100644
--- a/sys/net80211/ieee80211_node.c
+++ b/sys/net80211/ieee80211_node.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ieee80211_node.c,v 1.157 2018/11/20 20:26:01 phessler Exp $ */
+/* $OpenBSD: ieee80211_node.c,v 1.158 2018/11/25 12:14:01 phessler Exp $ */
/* $NetBSD: ieee80211_node.c,v 1.14 2004/05/09 09:18:47 dyoung Exp $ */
/*-
@@ -316,6 +316,10 @@ ieee80211_ess_setwpaparms(struct ieee80211_ess *ess,
ess->flags |= IEEE80211_F_RSNON;
+ if (ess->rsnakms &
+ (IEEE80211_AKM_8021X|IEEE80211_WPA_AKM_SHA256_8021X))
+ ess->flags |= IEEE80211_JOIN_8021X;
+
return ENETRESET;
}