CVS commit: src/sys/net80211

2023-06-23 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Sat Jun 24 05:12:03 UTC 2023

Modified Files:
src/sys/net80211: ieee80211_crypto_ccmp.c ieee80211_crypto_tkip.c
ieee80211_crypto_wep.c ieee80211_node.c ieee80211_var.h

Log Message:
Fix typo in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/net80211/ieee80211_crypto_ccmp.c
cvs rdiff -u -r1.17 -r1.18 src/sys/net80211/ieee80211_crypto_tkip.c
cvs rdiff -u -r1.13 -r1.14 src/sys/net80211/ieee80211_crypto_wep.c
cvs rdiff -u -r1.82 -r1.83 src/sys/net80211/ieee80211_node.c
cvs rdiff -u -r1.34 -r1.35 src/sys/net80211/ieee80211_var.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_crypto_ccmp.c
diff -u src/sys/net80211/ieee80211_crypto_ccmp.c:1.19 src/sys/net80211/ieee80211_crypto_ccmp.c:1.20
--- src/sys/net80211/ieee80211_crypto_ccmp.c:1.19	Tue Nov  3 15:06:50 2020
+++ src/sys/net80211/ieee80211_crypto_ccmp.c	Sat Jun 24 05:12:03 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_crypto_ccmp.c,v 1.19 2020/11/03 15:06:50 mlelstv Exp $	*/
+/*	$NetBSD: ieee80211_crypto_ccmp.c,v 1.20 2023/06/24 05:12:03 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_ccmp.c,v 1.7 2005/07/11 03:06:23 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_ccmp.c,v 1.19 2020/11/03 15:06:50 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_ccmp.c,v 1.20 2023/06/24 05:12:03 msaitoh Exp $");
 #endif
 
 /*
@@ -164,7 +164,7 @@ ccmp_encap(struct ieee80211_key *k, stru
 	ivp[7] = k->wk_keytsc >> 40;		/* PN5 */
 
 	/*
-	 * Finally, do software encrypt if neeed.
+	 * Finally, do software encrypt if need.
 	 */
 	if ((k->wk_flags & IEEE80211_KEY_SWCRYPT) &&
 	!ccmp_encrypt(k, m, hdrlen))

Index: src/sys/net80211/ieee80211_crypto_tkip.c
diff -u src/sys/net80211/ieee80211_crypto_tkip.c:1.17 src/sys/net80211/ieee80211_crypto_tkip.c:1.18
--- src/sys/net80211/ieee80211_crypto_tkip.c:1.17	Tue Nov  3 15:06:50 2020
+++ src/sys/net80211/ieee80211_crypto_tkip.c	Sat Jun 24 05:12:03 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_crypto_tkip.c,v 1.17 2020/11/03 15:06:50 mlelstv Exp $	*/
+/*	$NetBSD: ieee80211_crypto_tkip.c,v 1.18 2023/06/24 05:12:03 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_tkip.c,v 1.10 2005/08/08 18:46:35 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_tkip.c,v 1.17 2020/11/03 15:06:50 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_tkip.c,v 1.18 2023/06/24 05:12:03 msaitoh Exp $");
 #endif
 
 /*
@@ -191,7 +191,7 @@ tkip_encap(struct ieee80211_key *k, stru
 	ivp[7] = k->wk_keytsc >> 40;		/* TSC5 */
 
 	/*
-	 * Finally, do software encrypt if neeed.
+	 * Finally, do software encrypt if need.
 	 */
 	if (k->wk_flags & IEEE80211_KEY_SWCRYPT) {
 		if (!tkip_encrypt(ctx, k, m, hdrlen))

Index: src/sys/net80211/ieee80211_crypto_wep.c
diff -u src/sys/net80211/ieee80211_crypto_wep.c:1.13 src/sys/net80211/ieee80211_crypto_wep.c:1.14
--- src/sys/net80211/ieee80211_crypto_wep.c:1.13	Tue Nov  3 15:06:50 2020
+++ src/sys/net80211/ieee80211_crypto_wep.c	Sat Jun 24 05:12:03 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_crypto_wep.c,v 1.13 2020/11/03 15:06:50 mlelstv Exp $	*/
+/*	$NetBSD: ieee80211_crypto_wep.c,v 1.14 2023/06/24 05:12:03 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_wep.c,v 1.7 2005/06/10 16:11:24 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_wep.c,v 1.13 2020/11/03 15:06:50 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_wep.c,v 1.14 2023/06/24 05:12:03 msaitoh Exp $");
 #endif
 
 /*
@@ -178,7 +178,7 @@ wep_encap(struct ieee80211_key *k, struc
 	ivp[3] = keyid;
 
 	/*
-	 * Finally, do software encrypt if neeed.
+	 * Finally, do software encrypt if need.
 	 */
 	if ((k->wk_flags & IEEE80211_KEY_SWCRYPT) &&
 	!wep_encrypt(k, m, hdrlen))

Index: src/sys/net80211/ieee80211_node.c
diff -u src/sys/net80211/ieee80211_node.c:1.82 src/sys/net80211/ieee80211_node.c:1.83
--- src/sys/net80211/ieee80211_node.c:1.82	Sun Sep 19 10:34:09 2021
+++ src/sys/net80211/ieee80211_node.c	Sat Jun 24 05:12:03 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_node.c,v 1.82 2021/09/19 10:34:09 andvar Exp $	*/
+/*	$NetBSD: ieee80211_node.c,v 1.83 2023/06/24 05:12:03 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_node.c,v 1.65 2005/08/13 17:50:21 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_node.c,v 1.82 2021/09/19 10:34:09 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: 

CVS commit: src/sys/net80211

2023-06-23 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Sat Jun 24 05:12:03 UTC 2023

Modified Files:
src/sys/net80211: ieee80211_crypto_ccmp.c ieee80211_crypto_tkip.c
ieee80211_crypto_wep.c ieee80211_node.c ieee80211_var.h

Log Message:
Fix typo in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/net80211/ieee80211_crypto_ccmp.c
cvs rdiff -u -r1.17 -r1.18 src/sys/net80211/ieee80211_crypto_tkip.c
cvs rdiff -u -r1.13 -r1.14 src/sys/net80211/ieee80211_crypto_wep.c
cvs rdiff -u -r1.82 -r1.83 src/sys/net80211/ieee80211_node.c
cvs rdiff -u -r1.34 -r1.35 src/sys/net80211/ieee80211_var.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2022-11-18 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Sat Nov 19 07:57:51 UTC 2022

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
ieee80211_input.c: Fix a few debug messages


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.116 src/sys/net80211/ieee80211_input.c:1.117
--- src/sys/net80211/ieee80211_input.c:1.116	Wed Jan 29 05:21:14 2020
+++ src/sys/net80211/ieee80211_input.c	Sat Nov 19 07:57:51 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.116 2020/01/29 05:21:14 thorpej Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.117 2022/11/19 07:57:51 yamt Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.116 2020/01/29 05:21:14 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.117 2022/11/19 07:57:51 yamt Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -182,7 +182,7 @@ ieee80211_input_data(struct ieee80211com
 	case IEEE80211_M_STA:
 		if (dir != IEEE80211_FC1_DIR_FROMDS) {
 			IEEE80211_DISCARD(ic, IEEE80211_MSG_INPUT,
-			wh, "data", "%s", "unknown dir 0x%x", dir);
+			wh, "data", "unknown dir 0x%x", dir);
 			ic->ic_stats.is_rx_wrongdir++;
 			goto out;
 		}
@@ -206,7 +206,7 @@ ieee80211_input_data(struct ieee80211com
 	case IEEE80211_M_AHDEMO:
 		if (dir != IEEE80211_FC1_DIR_NODS) {
 			IEEE80211_DISCARD(ic, IEEE80211_MSG_INPUT,
-			wh, "data", "%s", "unknown dir 0x%x", dir);
+			wh, "data", "unknown dir 0x%x", dir);
 			ic->ic_stats.is_rx_wrongdir++;
 			goto out;
 		}
@@ -217,7 +217,7 @@ ieee80211_input_data(struct ieee80211com
 #ifndef IEEE80211_NO_HOSTAP
 		if (dir != IEEE80211_FC1_DIR_TODS) {
 			IEEE80211_DISCARD(ic, IEEE80211_MSG_INPUT,
-			wh, "data", "%s", "unknown dir 0x%x", dir);
+			wh, "data", "unknown dir 0x%x", dir);
 			ic->ic_stats.is_rx_wrongdir++;
 			goto out;
 		}
@@ -399,7 +399,7 @@ ieee80211_input_management(struct ieee80
 	IEEE80211_NODE_STAT(ni, rx_mgmt);
 	if (dir != IEEE80211_FC1_DIR_NODS) {
 		IEEE80211_DISCARD(ic, IEEE80211_MSG_INPUT,
-		wh, "data", "%s", "unknown dir 0x%x", dir);
+		wh, "data", "unknown dir 0x%x", dir);
 		ic->ic_stats.is_rx_wrongdir++;
 		goto err;
 	}



CVS commit: src/sys/net80211

2022-11-18 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Sat Nov 19 07:57:51 UTC 2022

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
ieee80211_input.c: Fix a few debug messages


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2022-03-14 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Mon Mar 14 07:05:31 UTC 2022

Modified Files:
src/sys/net80211: _ieee80211.h

Log Message:
Additional channel flags.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/net80211/_ieee80211.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/_ieee80211.h
diff -u src/sys/net80211/_ieee80211.h:1.10 src/sys/net80211/_ieee80211.h:1.11
--- src/sys/net80211/_ieee80211.h:1.10	Thu Mar 21 18:30:09 2013
+++ src/sys/net80211/_ieee80211.h	Mon Mar 14 07:05:31 2022
@@ -116,17 +116,47 @@ extern const struct ieee80211_channel ie
 
 /* bits 0-3 are for private use by drivers */
 /* channel attributes */
-#define	IEEE80211_CHAN_TURBO	0x0010	/* Turbo channel */
-#define	IEEE80211_CHAN_CCK	0x0020	/* CCK channel */
-#define	IEEE80211_CHAN_OFDM	0x0040	/* OFDM channel */
-#define	IEEE80211_CHAN_2GHZ	0x0080	/* 2 GHz spectrum channel. */
-#define	IEEE80211_CHAN_5GHZ	0x0100	/* 5 GHz spectrum channel */
-#define	IEEE80211_CHAN_PASSIVE	0x0200	/* Only passive scan allowed */
-#define	IEEE80211_CHAN_DYN	0x0400	/* Dynamic CCK-OFDM channel */
-#define	IEEE80211_CHAN_GFSK	0x0800	/* GFSK channel (FHSS PHY) */
-#define	IEEE80211_CHAN_GSM	0x1000	/* 900 MHz spectrum channel */
-#define	IEEE80211_CHAN_HALF	0x4000	/* Half rate channel */
-#define	IEEE80211_CHAN_QUARTER	0x8000	/* Quarter rate channel */
+#define	IEEE80211_CHAN_TURBO	0x0010	/* Turbo channel */
+#define	IEEE80211_CHAN_CCK	0x0020	/* CCK channel */
+#define	IEEE80211_CHAN_OFDM	0x0040	/* OFDM channel */
+#define	IEEE80211_CHAN_2GHZ	0x0080	/* 2 GHz spectrum channel. */
+#define	IEEE80211_CHAN_5GHZ	0x0100	/* 5 GHz spectrum channel */
+#define	IEEE80211_CHAN_PASSIVE	0x0200	/* Only passive scan allowed */
+#define	IEEE80211_CHAN_DYN	0x0400	/* Dynamic CCK-OFDM channel */
+#define	IEEE80211_CHAN_GFSK	0x0800	/* GFSK channel (FHSS PHY) */
+#define	IEEE80211_CHAN_GSM	0x1000	/* 900 MHz spectrum channel */
+#define	IEEE80211_CHAN_HALF	0x4000	/* Half rate channel */
+#define	IEEE80211_CHAN_QUARTER	0x8000	/* Quarter rate channel */
+#define	IEEE80211_CHAN_HT20	0x0001	/* HT 20 channel */
+#define	IEEE80211_CHAN_HT40U	0x0002	/* HT 40 channel w/ ext	above */
+#define	IEEE80211_CHAN_HT40D	0x0004	/* HT 40 channel w/ ext	below */
+#define	IEEE80211_CHAN_DFS	0x0008	/* DFS required */
+#define	IEEE80211_CHAN_4MSXMIT	0x0010	/* 4ms limit on frame length */
+#define	IEEE80211_CHAN_NOADHOC	0x0020	/* adhoc mode not allowed */
+#define	IEEE80211_CHAN_NOHOSTAP	0x0040	/* hostap mode not allowed */
+#define	IEEE80211_CHAN_11D	0x0080	/* 802.11d required */
+#define	IEEE80211_CHAN_VHT20	0x0100	/* VHT20 channel */
+#define	IEEE80211_CHAN_VHT40U	0x0200	/* VHT40 channel, ext above */
+#define	IEEE80211_CHAN_VHT40D	0x0400	/* VHT40 channel, ext below */
+#define	IEEE80211_CHAN_VHT80	0x0800	/* VHT80 channel */
+#define	IEEE80211_CHAN_VHT80_80	0x1000	/* VHT80+80 channel */
+#define	IEEE80211_CHAN_VHT160	0x2000	/* VHT160 channel */
+#define	IEEE80211_CHAN_HT20	0x0001	/* HT 20 channel */
+#define	IEEE80211_CHAN_HT40U	0x0002	/* HT 40 channel w/ ext	above */
+#define	IEEE80211_CHAN_HT40D	0x0004	/* HT 40 channel w/ ext	below */
+#define	IEEE80211_CHAN_DFS	0x0008	/* DFS required */
+#define	IEEE80211_CHAN_4MSXMIT	0x0010	/* 4ms limit on frame length */
+#define	IEEE80211_CHAN_NOADHOC	0x0020	/* adhoc mode not allowed */
+#define	IEEE80211_CHAN_NOHOSTAP	0x0040	/* hostap mode not allowed */
+#define	IEEE80211_CHAN_11D	0x0080	/* 802.11d required */
+
+#define	IEEE80211_CHAN_HT40	(IEEE80211_CHAN_HT40U | IEEE80211_CHAN_HT40D)
+#define	IEEE80211_CHAN_HT	(IEEE80211_CHAN_HT20 | IEEE80211_CHAN_HT40)
+
+#define	IEEE80211_CHAN_VHT40	(IEEE80211_CHAN_VHT40U | IEEE80211_CHAN_VHT40D)
+#define	IEEE80211_CHAN_VHT	(IEEE80211_CHAN_VHT20 | IEEE80211_CHAN_VHT40 \
+| IEEE80211_CHAN_VHT80 | IEEE80211_CHAN_VHT80_80 \
+| IEEE80211_CHAN_VHT160)
 
 /*
  * Useful combinations of channel characteristics.



CVS commit: src/sys/net80211

2022-03-14 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Mon Mar 14 07:05:31 UTC 2022

Modified Files:
src/sys/net80211: _ieee80211.h

Log Message:
Additional channel flags.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/net80211/_ieee80211.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2021-09-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Sep 21 15:00:34 UTC 2021

Modified Files:
src/sys/net80211: ieee80211_ioctl.c

Log Message:
don't opencode kauth_cred_get()


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/net80211/ieee80211_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_ioctl.c
diff -u src/sys/net80211/ieee80211_ioctl.c:1.68 src/sys/net80211/ieee80211_ioctl.c:1.69
--- src/sys/net80211/ieee80211_ioctl.c:1.68	Sat Jul 24 17:31:38 2021
+++ src/sys/net80211/ieee80211_ioctl.c	Tue Sep 21 11:00:34 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_ioctl.c,v 1.68 2021/07/24 21:31:38 andvar Exp $	*/
+/*	$NetBSD: ieee80211_ioctl.c,v 1.69 2021/09/21 15:00:34 christos Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_ioctl.c,v 1.35 2005/08/30 14:27:47 avatar Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_ioctl.c,v 1.68 2021/07/24 21:31:38 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_ioctl.c,v 1.69 2021/09/21 15:00:34 christos Exp $");
 #endif
 
 /*
@@ -367,7 +367,7 @@ ieee80211_cfgget(struct ieee80211com *ic
 	case WI_RID_DEFLT_CRYPT_KEYS:
 		keys = (struct wi_ltv_keys *)wreq;
 		/* do not show keys to non-root user */
-		error = kauth_authorize_network(curlwp->l_cred,
+		error = kauth_authorize_network(kauth_cred_get(),
 		KAUTH_NETWORK_INTERFACE,
 		KAUTH_REQ_NETWORK_INTERFACE_GETPRIV, ifp,
 		NULL, NULL);
@@ -904,7 +904,8 @@ ieee80211_ioctl_getkey(struct ieee80211c
 	ik.ik_flags = wk->wk_flags & (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV);
 	if (wk->wk_keyix == ic->ic_def_txkey)
 		ik.ik_flags |= IEEE80211_KEY_DEFAULT;
-	if (kauth_authorize_network(curlwp->l_cred, KAUTH_NETWORK_INTERFACE,
+	if (kauth_authorize_network(kauth_cred_get(),
+	KAUTH_NETWORK_INTERFACE,
 	KAUTH_REQ_NETWORK_INTERFACE_GETPRIV, ic->ic_ifp, NULL, NULL) == 0) {
 		/* NB: only root can read key data */
 		ik.ik_keyrsc = wk->wk_keyrsc;
@@ -1357,7 +1358,7 @@ ieee80211_ioctl_get80211_fbsd(struct iee
 			return EINVAL;
 		len = (u_int) ic->ic_nw_keys[kid].wk_keylen;
 		/* NB: only root can read WEP keys */
-		if (kauth_authorize_network(curlwp->l_cred,
+		if (kauth_authorize_network(kauth_cred_get(),
 		KAUTH_NETWORK_INTERFACE,
 		KAUTH_REQ_NETWORK_INTERFACE_GETPRIV, ifp, NULL,
 		NULL) == 0) {
@@ -2582,7 +2583,7 @@ ieee80211_ioctl(struct ieee80211com *ic,
 (struct ieee80211req *) data);
 		break;
 	case SIOCS80211:
-		if ((error = kauth_authorize_network(curlwp->l_cred,
+		if ((error = kauth_authorize_network(kauth_cred_get(),
 		KAUTH_NETWORK_INTERFACE,
 		KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, ifp, (void *)cmd,
 		NULL)) != 0)
@@ -2722,7 +2723,8 @@ ieee80211_ioctl(struct ieee80211com *ic,
 			if (nwkey->i_key[i].i_keydat == NULL)
 continue;
 			/* do not show any keys to non-root user */
-			if ((error = kauth_authorize_network(curlwp->l_cred,
+			if ((error = kauth_authorize_network(
+			kauth_cred_get(),
 			KAUTH_NETWORK_INTERFACE,
 			KAUTH_REQ_NETWORK_INTERFACE_GETPRIV, ifp,
 			(void *)cmd, NULL)) != 0)
@@ -2836,7 +2838,7 @@ ieee80211_ioctl(struct ieee80211com *ic,
 		error = ieee80211_cfgget(ic, cmd, data);
 		break;
 	case SIOCSIFGENERIC:
-		error = kauth_authorize_network(curlwp->l_cred,
+		error = kauth_authorize_network(kauth_cred_get(),
 		KAUTH_NETWORK_INTERFACE,
 		KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, ifp, (void *)cmd,
 		NULL);



CVS commit: src/sys/net80211

2021-09-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Sep 21 15:00:34 UTC 2021

Modified Files:
src/sys/net80211: ieee80211_ioctl.c

Log Message:
don't opencode kauth_cred_get()


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/net80211/ieee80211_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2020-11-03 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Tue Nov  3 15:06:50 UTC 2020

Modified Files:
src/sys/net80211: ieee80211_crypto_ccmp.c ieee80211_crypto_tkip.c
ieee80211_crypto_wep.c

Log Message:
Use kmem_* instead of malloc/free and use interrupt versions as the
code can be called from interrupt.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/net80211/ieee80211_crypto_ccmp.c
cvs rdiff -u -r1.16 -r1.17 src/sys/net80211/ieee80211_crypto_tkip.c
cvs rdiff -u -r1.12 -r1.13 src/sys/net80211/ieee80211_crypto_wep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_crypto_ccmp.c
diff -u src/sys/net80211/ieee80211_crypto_ccmp.c:1.18 src/sys/net80211/ieee80211_crypto_ccmp.c:1.19
--- src/sys/net80211/ieee80211_crypto_ccmp.c:1.18	Tue Jul 28 15:41:26 2020
+++ src/sys/net80211/ieee80211_crypto_ccmp.c	Tue Nov  3 15:06:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_crypto_ccmp.c,v 1.18 2020/07/28 15:41:26 riastradh Exp $	*/
+/*	$NetBSD: ieee80211_crypto_ccmp.c,v 1.19 2020/11/03 15:06:50 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_ccmp.c,v 1.7 2005/07/11 03:06:23 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_ccmp.c,v 1.18 2020/07/28 15:41:26 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_ccmp.c,v 1.19 2020/11/03 15:06:50 mlelstv Exp $");
 #endif
 
 /*
@@ -106,7 +106,7 @@ ccmp_attach(struct ieee80211com *ic, str
 {
 	struct ccmp_ctx *ctx;
 
-	ctx = kmem_zalloc(sizeof(*ctx), KM_NOSLEEP);
+	ctx = kmem_intr_zalloc(sizeof(*ctx), KM_NOSLEEP);
 	if (ctx == NULL) {
 		ic->ic_stats.is_crypto_nomem++;
 		return NULL;
@@ -120,7 +120,7 @@ ccmp_detach(struct ieee80211_key *k)
 {
 	struct ccmp_ctx *ctx = k->wk_private;
 
-	kmem_free(ctx, sizeof(*ctx));
+	kmem_intr_free(ctx, sizeof(*ctx));
 }
 
 static int

Index: src/sys/net80211/ieee80211_crypto_tkip.c
diff -u src/sys/net80211/ieee80211_crypto_tkip.c:1.16 src/sys/net80211/ieee80211_crypto_tkip.c:1.17
--- src/sys/net80211/ieee80211_crypto_tkip.c:1.16	Thu Dec 19 16:29:50 2019
+++ src/sys/net80211/ieee80211_crypto_tkip.c	Tue Nov  3 15:06:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_crypto_tkip.c,v 1.16 2019/12/19 16:29:50 kamil Exp $	*/
+/*	$NetBSD: ieee80211_crypto_tkip.c,v 1.17 2020/11/03 15:06:50 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_tkip.c,v 1.10 2005/08/08 18:46:35 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_tkip.c,v 1.16 2019/12/19 16:29:50 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_tkip.c,v 1.17 2020/11/03 15:06:50 mlelstv Exp $");
 #endif
 
 /*
@@ -49,7 +49,7 @@ __KERNEL_RCSID(0, "$NetBSD: ieee80211_cr
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 
@@ -118,7 +118,7 @@ tkip_attach(struct ieee80211com *ic, str
 {
 	struct tkip_ctx *ctx;
 
-	ctx = malloc(sizeof(struct tkip_ctx), M_DEVBUF, M_NOWAIT | M_ZERO);
+	ctx = kmem_intr_zalloc(sizeof(struct tkip_ctx), KM_NOSLEEP);
 	if (ctx == NULL) {
 		ic->ic_stats.is_crypto_nomem++;
 		return NULL;
@@ -133,7 +133,7 @@ tkip_detach(struct ieee80211_key *k)
 {
 	struct tkip_ctx *ctx = k->wk_private;
 
-	free(ctx, M_DEVBUF);
+	kmem_intr_free(ctx, sizeof(struct tkip_ctx));
 }
 
 static int

Index: src/sys/net80211/ieee80211_crypto_wep.c
diff -u src/sys/net80211/ieee80211_crypto_wep.c:1.12 src/sys/net80211/ieee80211_crypto_wep.c:1.13
--- src/sys/net80211/ieee80211_crypto_wep.c:1.12	Thu May  3 17:14:37 2018
+++ src/sys/net80211/ieee80211_crypto_wep.c	Tue Nov  3 15:06:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_crypto_wep.c,v 1.12 2018/05/03 17:14:37 maxv Exp $	*/
+/*	$NetBSD: ieee80211_crypto_wep.c,v 1.13 2020/11/03 15:06:50 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_wep.c,v 1.7 2005/06/10 16:11:24 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_wep.c,v 1.12 2018/05/03 17:14:37 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_wep.c,v 1.13 2020/11/03 15:06:50 mlelstv Exp $");
 #endif
 
 /*
@@ -45,7 +45,7 @@ __KERNEL_RCSID(0, "$NetBSD: ieee80211_cr
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 
@@ -95,7 +95,7 @@ wep_attach(struct ieee80211com *ic, stru
 {
 	struct wep_ctx *ctx;
 
-	ctx = malloc(sizeof(struct wep_ctx), M_DEVBUF, M_NOWAIT | M_ZERO);
+	ctx = kmem_intr_zalloc(sizeof(struct wep_ctx), KM_NOSLEEP);
 	if (ctx == NULL) {
 		ic->ic_stats.is_crypto_nomem++;
 		return NULL;
@@ -111,7 +111,7 @@ wep_detach(struct ieee80211_key *k)
 {
 	struct wep_ctx *ctx = k->wk_private;
 
-	free(ctx, M_DEVBUF);
+	

CVS commit: src/sys/net80211

2020-11-03 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Tue Nov  3 15:06:50 UTC 2020

Modified Files:
src/sys/net80211: ieee80211_crypto_ccmp.c ieee80211_crypto_tkip.c
ieee80211_crypto_wep.c

Log Message:
Use kmem_* instead of malloc/free and use interrupt versions as the
code can be called from interrupt.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/net80211/ieee80211_crypto_ccmp.c
cvs rdiff -u -r1.16 -r1.17 src/sys/net80211/ieee80211_crypto_tkip.c
cvs rdiff -u -r1.12 -r1.13 src/sys/net80211/ieee80211_crypto_wep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2020-10-06 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Tue Oct  6 23:51:06 UTC 2020

Modified Files:
src/sys/net80211: ieee80211.c

Log Message:
net80211: Initialise the interface with a decent link state.

Link state transitions to UP when a node is joined and DOWN when left.
This means that with the interface UP, the link state could be UNKNOWN
for a while, implying it can be used in BSS mode.
Which is of course false.

Add a function to set an initial link state based on the operating mode.
Also call this when the operating mode changes.

Basically in BSS and MONITOR it starts off down.
BSS will transition UP and DOWN as before, MONITOR will stay down.
IBSS, AHDEMO and HOSTAP will remain as link unknown because the state is
. unknown.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/net80211/ieee80211.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2020-10-06 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Tue Oct  6 23:51:06 UTC 2020

Modified Files:
src/sys/net80211: ieee80211.c

Log Message:
net80211: Initialise the interface with a decent link state.

Link state transitions to UP when a node is joined and DOWN when left.
This means that with the interface UP, the link state could be UNKNOWN
for a while, implying it can be used in BSS mode.
Which is of course false.

Add a function to set an initial link state based on the operating mode.
Also call this when the operating mode changes.

Basically in BSS and MONITOR it starts off down.
BSS will transition UP and DOWN as before, MONITOR will stay down.
IBSS, AHDEMO and HOSTAP will remain as link unknown because the state is
. unknown.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/net80211/ieee80211.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211.c
diff -u src/sys/net80211/ieee80211.c:1.59 src/sys/net80211/ieee80211.c:1.60
--- src/sys/net80211/ieee80211.c:1.59	Sun Mar 15 23:04:51 2020
+++ src/sys/net80211/ieee80211.c	Tue Oct  6 23:51:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211.c,v 1.59 2020/03/15 23:04:51 thorpej Exp $	*/
+/*	$NetBSD: ieee80211.c,v 1.60 2020/10/06 23:51:05 roy Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211.c,v 1.22 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211.c,v 1.59 2020/03/15 23:04:51 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211.c,v 1.60 2020/10/06 23:51:05 roy Exp $");
 #endif
 
 /*
@@ -150,6 +150,30 @@ ieee80211_default_reset(struct ifnet *if
 	return ENETRESET;
 }
 
+static void
+ieee80211_init_link_state(struct ieee80211com *ic)
+{
+	struct ifnet *ifp = ic->ic_ifp;
+
+	/*
+	 * Link state does not make sense in IBSS or HOSTAP modes.
+	 * We know that the link in MONITOR mode is DOWN as we cannot
+	 * transmit, only monitor.
+	 * That leaves BSS mode, which starts off DOWN and will
+	 * transition to UP when it joins a node.
+	 */
+	switch (ic->ic_opmode) {
+	case IEEE80211_M_AHDEMO:
+	case IEEE80211_M_HOSTAP:
+	case IEEE80211_M_IBSS:
+		if_link_state_change(ifp, LINK_STATE_UNKNOWN);
+		break;
+	default:
+		if_link_state_change(ifp, LINK_STATE_DOWN);
+		break;
+	}
+}
+
 void
 ieee80211_ifattach(struct ieee80211com *ic)
 {
@@ -246,6 +270,8 @@ ieee80211_ifattach(struct ieee80211com *
 	 */
 	if (ic->ic_reset == NULL)
 		ic->ic_reset = ieee80211_default_reset;
+
+	ieee80211_init_link_state(ic);
 }
 
 void
@@ -703,6 +729,7 @@ ieee80211_media_change(struct ifnet *ifp
 		 */
 		ieee80211_reset_erp(ic);
 		ieee80211_wme_initparams(ic);	/* after opmode change */
+		ieee80211_init_link_state(ic);	/* after opmode change */
 		error = ENETRESET;
 	}
 #ifdef notdef



CVS commit: src/sys/net80211

2020-07-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 28 15:41:26 UTC 2020

Modified Files:
src/sys/net80211: ieee80211_crypto_ccmp.c

Log Message:
Omit now-unused function.

Ceased to be needed with the AES CCM changes.

For some reason gcc didn't complain about this, but clang did.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/net80211/ieee80211_crypto_ccmp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_crypto_ccmp.c
diff -u src/sys/net80211/ieee80211_crypto_ccmp.c:1.17 src/sys/net80211/ieee80211_crypto_ccmp.c:1.18
--- src/sys/net80211/ieee80211_crypto_ccmp.c:1.17	Sat Jul 25 22:27:05 2020
+++ src/sys/net80211/ieee80211_crypto_ccmp.c	Tue Jul 28 15:41:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_crypto_ccmp.c,v 1.17 2020/07/25 22:27:05 riastradh Exp $	*/
+/*	$NetBSD: ieee80211_crypto_ccmp.c,v 1.18 2020/07/28 15:41:26 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_ccmp.c,v 1.7 2005/07/11 03:06:23 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_ccmp.c,v 1.17 2020/07/25 22:27:05 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_ccmp.c,v 1.18 2020/07/28 15:41:26 riastradh Exp $");
 #endif
 
 /*
@@ -266,14 +266,6 @@ ccmp_demic(struct ieee80211_key *k, stru
 	return 1;
 }
 
-static __inline void
-xor_block(uint8_t *b, const uint8_t *a, size_t len)
-{
-	int i;
-	for (i = 0; i < len; i++)
-		b[i] ^= a[i];
-}
-
 /*
  * Host AP crypt: host-based CCMP encryption implementation for Host AP driver
  *



CVS commit: src/sys/net80211

2020-07-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 28 15:41:26 UTC 2020

Modified Files:
src/sys/net80211: ieee80211_crypto_ccmp.c

Log Message:
Omit now-unused function.

Ceased to be needed with the AES CCM changes.

For some reason gcc didn't complain about this, but clang did.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/net80211/ieee80211_crypto_ccmp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2020-07-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jul 25 22:27:05 UTC 2020

Modified Files:
src/sys/net80211: ieee80211_crypto_ccmp.c

Log Message:
Convert malloc -> kmem.

Switch order of members for better alignment.  Sort includes.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/net80211/ieee80211_crypto_ccmp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_crypto_ccmp.c
diff -u src/sys/net80211/ieee80211_crypto_ccmp.c:1.16 src/sys/net80211/ieee80211_crypto_ccmp.c:1.17
--- src/sys/net80211/ieee80211_crypto_ccmp.c:1.16	Sat Jul 25 22:26:23 2020
+++ src/sys/net80211/ieee80211_crypto_ccmp.c	Sat Jul 25 22:27:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_crypto_ccmp.c,v 1.16 2020/07/25 22:26:23 riastradh Exp $	*/
+/*	$NetBSD: ieee80211_crypto_ccmp.c,v 1.17 2020/07/25 22:27:05 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_ccmp.c,v 1.7 2005/07/11 03:06:23 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_ccmp.c,v 1.16 2020/07/25 22:26:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_ccmp.c,v 1.17 2020/07/25 22:27:05 riastradh Exp $");
 #endif
 
 /*
@@ -47,10 +47,10 @@ __KERNEL_RCSID(0, "$NetBSD: ieee80211_cr
  * its license is included below.
  */
 #include 
-#include 
-#include 
-#include 
 #include 
+#include 
+#include 
+#include 
 
 #include 
 
@@ -67,8 +67,8 @@ __KERNEL_RCSID(0, "$NetBSD: ieee80211_cr
 #define AES_BLOCK_LEN 16
 
 struct ccmp_ctx {
-	struct ieee80211com *cc_ic;	/* for diagnostics */
 	struct aesenc cc_aes;
+	struct ieee80211com *cc_ic;	/* for diagnostics */
 };
 
 static	void *ccmp_attach(struct ieee80211com *, struct ieee80211_key *);
@@ -106,7 +106,7 @@ ccmp_attach(struct ieee80211com *ic, str
 {
 	struct ccmp_ctx *ctx;
 
-	ctx = malloc(sizeof(struct ccmp_ctx), M_DEVBUF, M_NOWAIT | M_ZERO);
+	ctx = kmem_zalloc(sizeof(*ctx), KM_NOSLEEP);
 	if (ctx == NULL) {
 		ic->ic_stats.is_crypto_nomem++;
 		return NULL;
@@ -120,7 +120,7 @@ ccmp_detach(struct ieee80211_key *k)
 {
 	struct ccmp_ctx *ctx = k->wk_private;
 
-	free(ctx, M_DEVBUF);
+	kmem_free(ctx, sizeof(*ctx));
 }
 
 static int



CVS commit: src/sys/net80211

2020-07-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jul 25 22:27:05 UTC 2020

Modified Files:
src/sys/net80211: ieee80211_crypto_ccmp.c

Log Message:
Convert malloc -> kmem.

Switch order of members for better alignment.  Sort includes.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/net80211/ieee80211_crypto_ccmp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2020-07-12 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Jul 13 05:40:25 UTC 2020

Modified Files:
src/sys/net80211: ieee80211_proto.c

Log Message:
i hit an assert in this code but we weren't sure why.

for now, add the ostate and nstate values for further diagnosis
to the assert message.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/net80211/ieee80211_proto.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2020-07-12 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Jul 13 05:40:25 UTC 2020

Modified Files:
src/sys/net80211: ieee80211_proto.c

Log Message:
i hit an assert in this code but we weren't sure why.

for now, add the ostate and nstate values for further diagnosis
to the assert message.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/net80211/ieee80211_proto.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_proto.c
diff -u src/sys/net80211/ieee80211_proto.c:1.34 src/sys/net80211/ieee80211_proto.c:1.35
--- src/sys/net80211/ieee80211_proto.c:1.34	Thu Feb  2 10:05:35 2017
+++ src/sys/net80211/ieee80211_proto.c	Mon Jul 13 05:40:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_proto.c,v 1.34 2017/02/02 10:05:35 nonaka Exp $	*/
+/*	$NetBSD: ieee80211_proto.c,v 1.35 2020/07/13 05:40:25 mrg Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_proto.c,v 1.23 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_proto.c,v 1.34 2017/02/02 10:05:35 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_proto.c,v 1.35 2020/07/13 05:40:25 mrg Exp $");
 #endif
 
 /*
@@ -1103,8 +1103,9 @@ ieee80211_newstate(struct ieee80211com *
 		case IEEE80211_S_SCAN:		/* adhoc/hostap mode */
 		case IEEE80211_S_ASSOC:		/* infra mode */
 			IASSERT(ni->ni_txrate < ni->ni_rates.rs_nrates,
-("%s: bogus xmit rate %u setup\n", __func__,
-	ni->ni_txrate));
+("%s: bogus xmit rate %u setup ostate %x "
+ "nstate %x\n", __func__, ni->ni_txrate,
+ ostate, nstate));
 #ifdef IEEE80211_DEBUG
 			if (ieee80211_msg_debug(ic)) {
 if (ic->ic_opmode == IEEE80211_M_STA)



CVS commit: src/sys/net80211

2020-02-29 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 29 16:56:58 UTC 2020

Modified Files:
src/sys/net80211: ieee80211_output.c

Log Message:
Fix printf to handle various datatypes for MHLEN.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/net80211/ieee80211_output.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2020-02-29 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 29 16:56:58 UTC 2020

Modified Files:
src/sys/net80211: ieee80211_output.c

Log Message:
Fix printf to handle various datatypes for MHLEN.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/net80211/ieee80211_output.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_output.c
diff -u src/sys/net80211/ieee80211_output.c:1.64 src/sys/net80211/ieee80211_output.c:1.65
--- src/sys/net80211/ieee80211_output.c:1.64	Sat Dec 22 13:11:37 2018
+++ src/sys/net80211/ieee80211_output.c	Sat Feb 29 16:56:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_output.c,v 1.64 2018/12/22 13:11:37 maxv Exp $	*/
+/*	$NetBSD: ieee80211_output.c,v 1.65 2020/02/29 16:56:58 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_output.c,v 1.34 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_output.c,v 1.64 2018/12/22 13:11:37 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_output.c,v 1.65 2020/02/29 16:56:58 mlelstv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -436,7 +436,7 @@ ieee80211_mbuf_adjust(struct ieee80211co
 		}
 
 		IASSERT(needed_space <= MHLEN,
-		("not enough room, need %u got %zu\n", needed_space, MHLEN));
+		("not enough room, need %u got %lu\n", needed_space, (u_long)MHLEN));
 
 		/*
 		 * Setup new mbuf to have leading space to prepend the



CVS commit: src/sys/net80211

2020-01-28 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jan 29 05:21:14 UTC 2020

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Adopt .


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.115 src/sys/net80211/ieee80211_input.c:1.116
--- src/sys/net80211/ieee80211_input.c:1.115	Sat Dec 22 13:11:37 2018
+++ src/sys/net80211/ieee80211_input.c	Wed Jan 29 05:21:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.115 2018/12/22 13:11:37 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.116 2020/01/29 05:21:14 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.115 2018/12/22 13:11:37 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.116 2020/01/29 05:21:14 thorpej Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -361,7 +361,7 @@ ieee80211_input_data(struct ieee80211com
 		}
 	}
 
-	ifp->if_ipackets++;
+	if_statinc(ifp, if_ipackets);
 	IEEE80211_NODE_STAT(ni, rx_data);
 	IEEE80211_NODE_STAT_ADD(ni, rx_bytes, m->m_pkthdr.len);
 
@@ -371,7 +371,7 @@ ieee80211_input_data(struct ieee80211com
 	return 0;
 
 err:
-	ifp->if_ierrors++;
+	if_statinc(ifp, if_ierrors);
 out:
 	*mp = m;
 	return -1;
@@ -460,7 +460,7 @@ ieee80211_input_management(struct ieee80
 	return 0;
 
 err:
-	ifp->if_ierrors++;
+	if_statinc(ifp, if_ierrors);
 out:
 	*mp = m;
 	return -1;
@@ -742,7 +742,7 @@ ieee80211_input(struct ieee80211com *ic,
 	}
 
 err:
-	ifp->if_ierrors++;
+	if_statinc(ifp, if_ierrors);
 
 out:
 	if (m != NULL) {
@@ -868,7 +868,7 @@ ieee80211_deliver_data(struct ieee80211c
 		if (ETHER_IS_MULTICAST(eh->ether_dhost)) {
 			m1 = m_copypacket(m, M_DONTWAIT);
 			if (m1 == NULL)
-ifp->if_oerrors++;
+if_statinc(ifp, if_oerrors);
 			else
 m1->m_flags |= M_MCAST;
 		} else {
@@ -907,11 +907,11 @@ ieee80211_deliver_data(struct ieee80211c
 			len = m1->m_pkthdr.len;
 			IFQ_ENQUEUE(>if_snd, m1, error);
 			if (error) {
-ifp->if_oerrors++;
+if_statinc(ifp, if_oerrors);
 m_freem(m);
 m = NULL;
 			}
-			ifp->if_obytes += len;
+			if_statadd(ifp, if_obytes, len);
 		}
 	}
 



CVS commit: src/sys/net80211

2020-01-28 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jan 29 05:21:14 UTC 2020

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Adopt .


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2019-12-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Dec 19 16:29:51 UTC 2019

Modified Files:
src/sys/net80211: ieee80211_crypto_tkip.c

Log Message:
Avoid changing signedness bit with << 24 in ieee80211_crypto_tkip.c

Reported by 


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/net80211/ieee80211_crypto_tkip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_crypto_tkip.c
diff -u src/sys/net80211/ieee80211_crypto_tkip.c:1.15 src/sys/net80211/ieee80211_crypto_tkip.c:1.16
--- src/sys/net80211/ieee80211_crypto_tkip.c:1.15	Mon Sep  3 16:29:36 2018
+++ src/sys/net80211/ieee80211_crypto_tkip.c	Thu Dec 19 16:29:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_crypto_tkip.c,v 1.15 2018/09/03 16:29:36 riastradh Exp $	*/
+/*	$NetBSD: ieee80211_crypto_tkip.c,v 1.16 2019/12/19 16:29:50 kamil Exp $	*/
 
 /*
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_tkip.c,v 1.10 2005/08/08 18:46:35 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_tkip.c,v 1.15 2018/09/03 16:29:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_tkip.c,v 1.16 2019/12/19 16:29:50 kamil Exp $");
 #endif
 
 /*
@@ -231,7 +231,7 @@ tkip_enmic(struct ieee80211_key *k, stru
 static __inline uint64_t
 READ_6(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5)
 {
-	uint32_t iv32 = (b0 << 0) | (b1 << 8) | (b2 << 16) | (b3 << 24);
+	uint32_t iv32 = (b0 << 0) | (b1 << 8) | (b2 << 16) | ((u32)b3 << 24);
 	uint16_t iv16 = (b4 << 0) | (b5 << 8);
 	return (((uint64_t)iv16) << 32) | iv32;
 }
@@ -733,7 +733,7 @@ do {\
 
 static __inline u32 get_le32_split(u8 b0, u8 b1, u8 b2, u8 b3)
 {
-	return b0 | (b1 << 8) | (b2 << 16) | (b3 << 24);
+	return b0 | (b1 << 8) | (b2 << 16) | ((u32)b3 << 24);
 }
 
 static __inline u32 get_le32(const u8 *p)



CVS commit: src/sys/net80211

2019-12-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Dec 19 16:29:51 UTC 2019

Modified Files:
src/sys/net80211: ieee80211_crypto_tkip.c

Log Message:
Avoid changing signedness bit with << 24 in ieee80211_crypto_tkip.c

Reported by 


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/net80211/ieee80211_crypto_tkip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2019-12-19 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Thu Dec 19 15:54:21 UTC 2019

Modified Files:
src/sys/net80211: ieee80211_node.c

Log Message:
Add comment for previous.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/net80211/ieee80211_node.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2019-12-19 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Thu Dec 19 15:54:21 UTC 2019

Modified Files:
src/sys/net80211: ieee80211_node.c

Log Message:
Add comment for previous.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/net80211/ieee80211_node.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_node.c
diff -u src/sys/net80211/ieee80211_node.c:1.77 src/sys/net80211/ieee80211_node.c:1.78
--- src/sys/net80211/ieee80211_node.c:1.77	Thu Dec 19 15:27:07 2019
+++ src/sys/net80211/ieee80211_node.c	Thu Dec 19 15:54:21 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_node.c,v 1.77 2019/12/19 15:27:07 jakllsch Exp $	*/
+/*	$NetBSD: ieee80211_node.c,v 1.78 2019/12/19 15:54:21 jakllsch Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_node.c,v 1.65 2005/08/13 17:50:21 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_node.c,v 1.77 2019/12/19 15:27:07 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_node.c,v 1.78 2019/12/19 15:54:21 jakllsch Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -543,6 +543,7 @@ ieee80211_match_bss(struct ieee80211com 
 	if (ni->ni_fails >= STA_FAILS_MAX)
 		fail |= 0x40;
 
+	/* If no ESS/IBSS is desired, do not match any. */
 	if (ic->ic_des_esslen == 0)
 		fail |= 0x80;
 



CVS commit: src/sys/net80211

2019-12-19 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Thu Dec 19 15:27:07 UTC 2019

Modified Files:
src/sys/net80211: ieee80211_node.c

Log Message:
Do not associate with with any access point if no SSID has been configured.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/net80211/ieee80211_node.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2019-12-19 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Thu Dec 19 15:27:07 UTC 2019

Modified Files:
src/sys/net80211: ieee80211_node.c

Log Message:
Do not associate with with any access point if no SSID has been configured.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/net80211/ieee80211_node.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_node.c
diff -u src/sys/net80211/ieee80211_node.c:1.76 src/sys/net80211/ieee80211_node.c:1.77
--- src/sys/net80211/ieee80211_node.c:1.76	Sun Nov 10 21:16:38 2019
+++ src/sys/net80211/ieee80211_node.c	Thu Dec 19 15:27:07 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_node.c,v 1.76 2019/11/10 21:16:38 chs Exp $	*/
+/*	$NetBSD: ieee80211_node.c,v 1.77 2019/12/19 15:27:07 jakllsch Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_node.c,v 1.65 2005/08/13 17:50:21 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_node.c,v 1.76 2019/11/10 21:16:38 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_node.c,v 1.77 2019/12/19 15:27:07 jakllsch Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -543,6 +543,9 @@ ieee80211_match_bss(struct ieee80211com 
 	if (ni->ni_fails >= STA_FAILS_MAX)
 		fail |= 0x40;
 
+	if (ic->ic_des_esslen == 0)
+		fail |= 0x80;
+
 #ifdef IEEE80211_DEBUG
 	if (ieee80211_msg_scan(ic)) {
 		printf(" %c %s",



CVS commit: src/sys/net80211

2019-10-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Oct  3 17:46:56 UTC 2019

Modified Files:
src/sys/net80211: ieee80211.c

Log Message:
ieee80211_announce: Print supported rates with aprint_debug


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/net80211/ieee80211.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2019-10-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Oct  3 17:46:56 UTC 2019

Modified Files:
src/sys/net80211: ieee80211.c

Log Message:
ieee80211_announce: Print supported rates with aprint_debug


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/net80211/ieee80211.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211.c
diff -u src/sys/net80211/ieee80211.c:1.56 src/sys/net80211/ieee80211.c:1.57
--- src/sys/net80211/ieee80211.c:1.56	Mon Aug 24 22:21:26 2015
+++ src/sys/net80211/ieee80211.c	Thu Oct  3 17:46:56 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211.c,v 1.56 2015/08/24 22:21:26 pooka Exp $	*/
+/*	$NetBSD: ieee80211.c,v 1.57 2019/10/03 17:46:56 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211.c,v 1.22 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211.c,v 1.56 2015/08/24 22:21:26 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211.c,v 1.57 2019/10/03 17:46:56 jmcneill Exp $");
 #endif
 
 /*
@@ -464,7 +464,7 @@ ieee80211_announce(struct ieee80211com *
 	for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) {
 		if ((ic->ic_modecaps & (1if_xname,
 		ieee80211_phymode_name[mode]);
 		rs = >ic_sup_rates[mode];
 		for (i = 0; i < rs->rs_nrates; i++) {
@@ -472,11 +472,11 @@ ieee80211_announce(struct ieee80211com *
 			mword = ieee80211_rate2media(ic, rate, mode);
 			if (mword == 0)
 continue;
-			aprint_normal("%s%d%sMbps", (i != 0 ? " " : ""),
+			aprint_debug("%s%d%sMbps", (i != 0 ? " " : ""),
 			(rate & IEEE80211_RATE_VAL) / 2,
 			((rate & 0x1) != 0 ? ".5" : ""));
 		}
-		aprint_normal("\n");
+		aprint_debug("\n");
 	}
 }
 



CVS commit: src/sys/net80211

2019-08-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Aug 20 09:28:00 UTC 2019

Modified Files:
src/sys/net80211: ieee80211_ioctl.h

Log Message:
Include  for IFNAMSIZ


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/net80211/ieee80211_ioctl.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2019-08-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Aug 20 09:28:00 UTC 2019

Modified Files:
src/sys/net80211: ieee80211_ioctl.h

Log Message:
Include  for IFNAMSIZ


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/net80211/ieee80211_ioctl.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_ioctl.h
diff -u src/sys/net80211/ieee80211_ioctl.h:1.25 src/sys/net80211/ieee80211_ioctl.h:1.26
--- src/sys/net80211/ieee80211_ioctl.h:1.25	Sat Jan 26 21:08:48 2019
+++ src/sys/net80211/ieee80211_ioctl.h	Tue Aug 20 05:28:00 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_ioctl.h,v 1.25 2019/01/27 02:08:48 pgoyette Exp $	*/
+/*	$NetBSD: ieee80211_ioctl.h,v 1.26 2019/08/20 09:28:00 christos Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -39,6 +39,7 @@
  * IEEE 802.11 ioctls.
  */
 #include 
+#include 
 #include 
 #include 
 #include 



CVS commit: src/sys/net80211

2019-05-16 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri May 17 04:08:54 UTC 2019

Modified Files:
src/sys/net80211: ieee80211_ioctl.c

Log Message:
 Remove extra OSIOCSIFMEDIA. This old ioctl is converted to new one in
doifioctl().


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/net80211/ieee80211_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_ioctl.c
diff -u src/sys/net80211/ieee80211_ioctl.c:1.65 src/sys/net80211/ieee80211_ioctl.c:1.66
--- src/sys/net80211/ieee80211_ioctl.c:1.65	Thu Apr 11 11:40:58 2019
+++ src/sys/net80211/ieee80211_ioctl.c	Fri May 17 04:08:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_ioctl.c,v 1.65 2019/04/11 11:40:58 kamil Exp $	*/
+/*	$NetBSD: ieee80211_ioctl.c,v 1.66 2019/05/17 04:08:54 msaitoh Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_ioctl.c,v 1.35 2005/08/30 14:27:47 avatar Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_ioctl.c,v 1.65 2019/04/11 11:40:58 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_ioctl.c,v 1.66 2019/05/17 04:08:54 msaitoh Exp $");
 #endif
 
 /*
@@ -2576,9 +2576,6 @@ ieee80211_ioctl(struct ieee80211com *ic,
 	u_int8_t tmpkey[IEEE80211_WEP_NKID][IEEE80211_KEYBUF_SIZE];
 
 	switch (cmd) {
-#ifdef OSIOCSIFMEDIA
-	case OSIOCSIFMEDIA:
-#endif
 	case SIOCSIFMEDIA:
 	case SIOCGIFMEDIA:
 		error = ifmedia_ioctl(ifp, ifr, >ic_media, cmd);



CVS commit: src/sys/net80211

2019-05-16 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri May 17 04:08:54 UTC 2019

Modified Files:
src/sys/net80211: ieee80211_ioctl.c

Log Message:
 Remove extra OSIOCSIFMEDIA. This old ioctl is converted to new one in
doifioctl().


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/net80211/ieee80211_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-06-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jun 21 17:03:45 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
remove unused arguments


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-06-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jun 21 17:03:45 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
remove unused arguments


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.112 src/sys/net80211/ieee80211_input.c:1.113
--- src/sys/net80211/ieee80211_input.c:1.112	Thu Jun 21 16:53:10 2018
+++ src/sys/net80211/ieee80211_input.c	Thu Jun 21 17:03:45 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.112 2018/06/21 16:53:10 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.113 2018/06/21 17:03:45 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.112 2018/06/21 16:53:10 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.113 2018/06/21 17:03:45 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -132,9 +132,9 @@ static void ieee80211_discard_mac(struct
 #define	IEEE80211_DEBUGVAR(a)
 #endif /* IEEE80211_DEBUG */
 
-static struct mbuf *ieee80211_defrag(struct ieee80211com *,
-	struct ieee80211_node *, struct mbuf *, int);
-static struct mbuf *ieee80211_decap(struct ieee80211com *, struct mbuf *, int);
+static struct mbuf *ieee80211_defrag(struct ieee80211_node *,
+struct mbuf *, int);
+static struct mbuf *ieee80211_decap(struct mbuf *, int);
 static void ieee80211_send_error(struct ieee80211com *, struct ieee80211_node *,
 	const u_int8_t *mac, int subtype, int arg);
 static void ieee80211_deliver_data(struct ieee80211com *,
@@ -291,7 +291,7 @@ ieee80211_input_data(struct ieee80211com
 	 * Next up, any fragmentation.
 	 */
 	if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
-		m = ieee80211_defrag(ic, ni, m, hdrspace);
+		m = ieee80211_defrag(ni, m, hdrspace);
 		if (m == NULL) {
 			/* Fragment dropped or frame not complete yet */
 			goto out;
@@ -314,7 +314,7 @@ ieee80211_input_data(struct ieee80211com
 	/*
 	 * Finally, strip the 802.11 header.
 	 */
-	m = ieee80211_decap(ic, m, hdrspace);
+	m = ieee80211_decap(m, hdrspace);
 	if (m == NULL) {
 		/* don't count Null data frames as errors */
 		if (subtype == IEEE80211_FC0_SUBTYPE_NODATA)
@@ -757,8 +757,7 @@ out:
  * This function reassembles fragments.
  */
 static struct mbuf *
-ieee80211_defrag(struct ieee80211com *ic, struct ieee80211_node *ni,
-	struct mbuf *m, int hdrspace)
+ieee80211_defrag(struct ieee80211_node *ni, struct mbuf *m, int hdrspace)
 {
 	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
 	struct ieee80211_frame *lwh;
@@ -932,7 +931,7 @@ ieee80211_deliver_data(struct ieee80211c
 }
 
 static struct mbuf *
-ieee80211_decap(struct ieee80211com *ic, struct mbuf *m, int hdrlen)
+ieee80211_decap(struct mbuf *m, int hdrlen)
 {
 	struct ieee80211_qosframe_addr4 wh; /* Max size address frames */
 	struct ether_header *eh;



CVS commit: src/sys/net80211

2018-06-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jun 21 16:53:10 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Fix use-after-free, m_cat can free m.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.111 src/sys/net80211/ieee80211_input.c:1.112
--- src/sys/net80211/ieee80211_input.c:1.111	Tue May  8 07:02:07 2018
+++ src/sys/net80211/ieee80211_input.c	Thu Jun 21 16:53:10 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.111 2018/05/08 07:02:07 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.112 2018/06/21 16:53:10 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.111 2018/05/08 07:02:07 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.112 2018/06/21 16:53:10 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -762,14 +762,15 @@ ieee80211_defrag(struct ieee80211com *ic
 {
 	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
 	struct ieee80211_frame *lwh;
-	u_int16_t rxseq;
+	u_int16_t rxseq, iseq;
 	u_int8_t fragno;
 	const u_int8_t more_frag = wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG;
 	struct mbuf *mfrag;
 
 	IASSERT(!IEEE80211_IS_MULTICAST(wh->i_addr1), ("multicast fragm?"));
 
-	rxseq = le16toh(*(u_int16_t *)wh->i_seq);
+	iseq = *(u_int16_t *)wh->i_seq;
+	rxseq = le16toh(iseq);
 	fragno = rxseq & IEEE80211_SEQ_FRAG_MASK;
 
 	/* Quick way out, if there's nothing to defragment */
@@ -827,16 +828,19 @@ ieee80211_defrag(struct ieee80211com *ic
 		}
 		mfrag = m;
 	} else {
+		int mlen;
+
 		/* Strip header and concatenate */
 		m_adj(m, hdrspace);
+		mlen = m->m_pkthdr.len;
 		m_cat(mfrag, m);
 
 		/* NB: m_cat doesn't update the packet header */
-		mfrag->m_pkthdr.len += m->m_pkthdr.len;
+		mfrag->m_pkthdr.len += mlen;
 
 		/* track last seqnum and fragno */
 		lwh = mtod(mfrag, struct ieee80211_frame *);
-		*(u_int16_t *)lwh->i_seq = *(u_int16_t *)wh->i_seq;
+		*(u_int16_t *)lwh->i_seq = iseq;
 	}
 
 	if (more_frag) {



CVS commit: src/sys/net80211

2018-06-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jun 21 16:53:10 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Fix use-after-free, m_cat can free m.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-05-08 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue May  8 07:02:07 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_crypto.c ieee80211_input.c
ieee80211_output.c ieee80211_var.h

Log Message:
Remove three useless debug messages, remove meaningless XXXs, and remove
ieee80211_note_frame (unused).


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/net80211/ieee80211_crypto.c
cvs rdiff -u -r1.110 -r1.111 src/sys/net80211/ieee80211_input.c
cvs rdiff -u -r1.62 -r1.63 src/sys/net80211/ieee80211_output.c
cvs rdiff -u -r1.32 -r1.33 src/sys/net80211/ieee80211_var.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_crypto.c
diff -u src/sys/net80211/ieee80211_crypto.c:1.22 src/sys/net80211/ieee80211_crypto.c:1.23
--- src/sys/net80211/ieee80211_crypto.c:1.22	Tue Apr 10 07:53:36 2018
+++ src/sys/net80211/ieee80211_crypto.c	Tue May  8 07:02:07 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_crypto.c,v 1.22 2018/04/10 07:53:36 maxv Exp $	*/
+/*	$NetBSD: ieee80211_crypto.c,v 1.23 2018/05/08 07:02:07 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto.c,v 1.12 2005/08/08 18:46:35 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto.c,v 1.22 2018/04/10 07:53:36 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto.c,v 1.23 2018/05/08 07:02:07 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -647,9 +647,6 @@ ieee80211_crypto_decap(struct ieee80211c
 	}
 
 	if (m == NULL) {
-		IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO,
-		"[%s] unable to pullup %s header\n",
-		ether_sprintf(wh->i_addr2), cip->ic_name);
 		ic->ic_stats.is_rx_tooshort++;
 		return NULL;
 	}

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.110 src/sys/net80211/ieee80211_input.c:1.111
--- src/sys/net80211/ieee80211_input.c:1.110	Sun Jan 21 14:13:49 2018
+++ src/sys/net80211/ieee80211_input.c	Tue May  8 07:02:07 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.110 2018/01/21 14:13:49 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.111 2018/05/08 07:02:07 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.110 2018/01/21 14:13:49 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.111 2018/05/08 07:02:07 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -173,9 +173,6 @@ ieee80211_input_data(struct ieee80211com
 
 	if (m->m_len < hdrspace &&
 	(m = m_pullup(m, hdrspace)) == NULL) {
-		IEEE80211_DISCARD_MAC(ic, IEEE80211_MSG_ANY,
-		ni->ni_macaddr, NULL,
-		"data too short: expecting %u", hdrspace);
 		ic->ic_stats.is_rx_tooshort++;
 		goto out;
 	}
@@ -3248,23 +3245,6 @@ ieee80211_note(struct ieee80211com *ic, 
 }
 
 void
-ieee80211_note_frame(struct ieee80211com *ic,
-	const struct ieee80211_frame *wh,
-	const char *fmt, ...)
-{
-	char buf[128];		/* XXX */
-	va_list ap;
-	char ebuf[3 * ETHER_ADDR_LEN];
-
-	va_start(ap, fmt);
-	vsnprintf(buf, sizeof(buf), fmt, ap);
-	va_end(ap);
-	if_printf(ic->ic_ifp, "[%s] %s\n",
-	ether_snprintf(ebuf, sizeof(ebuf),
-	ieee80211_getbssid(ic, wh)), buf);
-}
-
-void
 ieee80211_note_mac(struct ieee80211com *ic,
 	const u_int8_t mac[IEEE80211_ADDR_LEN],
 	const char *fmt, ...)

Index: src/sys/net80211/ieee80211_output.c
diff -u src/sys/net80211/ieee80211_output.c:1.62 src/sys/net80211/ieee80211_output.c:1.63
--- src/sys/net80211/ieee80211_output.c:1.62	Thu May  3 17:14:37 2018
+++ src/sys/net80211/ieee80211_output.c	Tue May  8 07:02:07 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_output.c,v 1.62 2018/05/03 17:14:37 maxv Exp $	*/
+/*	$NetBSD: ieee80211_output.c,v 1.63 2018/05/08 07:02:07 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,16 +37,13 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_output.c,v 1.34 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_output.c,v 1.62 2018/05/03 17:14:37 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_output.c,v 1.63 2018/05/08 07:02:07 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
 #endif
 
-#ifdef __NetBSD__
-#endif /* __NetBSD__ */
-
 #include 
 #include  
 #include
@@ -247,7 +244,6 @@ ieee80211_send_nulldata(struct ieee80211
 
 	MGETHDR(m, M_NOWAIT, MT_HEADER);
 	if (m == NULL) {
-		/* XXX debug msg */
 		ic->ic_stats.is_tx_nobuf++;
 		ieee80211_unref_node();
 		return ENOMEM;
@@ -434,8 +430,6 @@ ieee80211_mbuf_adjust(struct ieee80211co
 	if (M_LEADINGSPACE(m) < needed_space - TO_BE_RECLAIMED) {
 		struct mbuf *n = m_gethdr(M_NOWAIT, m->m_type);
 		if (n == NULL) {
-			IEEE80211_DPRINTF(ic, IEEE80211_MSG_OUTPUT,
-			"%s: cannot expand 

CVS commit: src/sys/net80211

2018-05-08 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue May  8 07:02:07 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_crypto.c ieee80211_input.c
ieee80211_output.c ieee80211_var.h

Log Message:
Remove three useless debug messages, remove meaningless XXXs, and remove
ieee80211_note_frame (unused).


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/net80211/ieee80211_crypto.c
cvs rdiff -u -r1.110 -r1.111 src/sys/net80211/ieee80211_input.c
cvs rdiff -u -r1.62 -r1.63 src/sys/net80211/ieee80211_output.c
cvs rdiff -u -r1.32 -r1.33 src/sys/net80211/ieee80211_var.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-05-04 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri May  4 11:25:24 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_ioctl.h

Log Message:
Remove duplicate macros. Reported in PR/29786.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/net80211/ieee80211_ioctl.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_ioctl.h
diff -u src/sys/net80211/ieee80211_ioctl.h:1.23 src/sys/net80211/ieee80211_ioctl.h:1.24
--- src/sys/net80211/ieee80211_ioctl.h:1.23	Fri Apr  8 14:30:47 2016
+++ src/sys/net80211/ieee80211_ioctl.h	Fri May  4 11:25:24 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_ioctl.h,v 1.23 2016/04/08 14:30:47 roy Exp $	*/
+/*	$NetBSD: ieee80211_ioctl.h,v 1.24 2018/05/04 11:25:24 maxv Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -580,10 +580,6 @@ struct ieee80211_auth {
 	int		i_authtype;
 };
 
-#define	IEEE80211_AUTH_NONE	0
-#define	IEEE80211_AUTH_OPEN	1
-#define	IEEE80211_AUTH_SHARED	2
-
 #define	SIOCS80211AUTH		 _IOW('i', 236, struct ieee80211_auth)
 #define	SIOCG80211AUTH		_IOWR('i', 237, struct ieee80211_auth)
 



CVS commit: src/sys/net80211

2018-05-04 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri May  4 11:25:24 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_ioctl.h

Log Message:
Remove duplicate macros. Reported in PR/29786.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/net80211/ieee80211_ioctl.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-05-03 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu May  3 17:14:37 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_crypto_ccmp.c ieee80211_crypto_wep.c
ieee80211_netbsd.h ieee80211_output.c

Log Message:
Remove ovbcopy from net80211.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/net80211/ieee80211_crypto_ccmp.c
cvs rdiff -u -r1.11 -r1.12 src/sys/net80211/ieee80211_crypto_wep.c
cvs rdiff -u -r1.20 -r1.21 src/sys/net80211/ieee80211_netbsd.h
cvs rdiff -u -r1.61 -r1.62 src/sys/net80211/ieee80211_output.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-05-03 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu May  3 17:14:37 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_crypto_ccmp.c ieee80211_crypto_wep.c
ieee80211_netbsd.h ieee80211_output.c

Log Message:
Remove ovbcopy from net80211.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/net80211/ieee80211_crypto_ccmp.c
cvs rdiff -u -r1.11 -r1.12 src/sys/net80211/ieee80211_crypto_wep.c
cvs rdiff -u -r1.20 -r1.21 src/sys/net80211/ieee80211_netbsd.h
cvs rdiff -u -r1.61 -r1.62 src/sys/net80211/ieee80211_output.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_crypto_ccmp.c
diff -u src/sys/net80211/ieee80211_crypto_ccmp.c:1.13 src/sys/net80211/ieee80211_crypto_ccmp.c:1.14
--- src/sys/net80211/ieee80211_crypto_ccmp.c:1.13	Fri Jan 19 07:54:34 2018
+++ src/sys/net80211/ieee80211_crypto_ccmp.c	Thu May  3 17:14:37 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_crypto_ccmp.c,v 1.13 2018/01/19 07:54:34 maxv Exp $	*/
+/*	$NetBSD: ieee80211_crypto_ccmp.c,v 1.14 2018/05/03 17:14:37 maxv Exp $	*/
 
 /*
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_ccmp.c,v 1.7 2005/07/11 03:06:23 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_ccmp.c,v 1.13 2018/01/19 07:54:34 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_ccmp.c,v 1.14 2018/05/03 17:14:37 maxv Exp $");
 #endif
 
 /*
@@ -243,7 +243,7 @@ ccmp_decap(struct ieee80211_key *k, stru
 	/*
 	 * Copy up 802.11 header and strip crypto bits.
 	 */
-	ovbcopy(mtod(m, void *), mtod(m, u_int8_t *) + ccmp.ic_header, hdrlen);
+	memmove(mtod(m, u_int8_t *) + ccmp.ic_header, mtod(m, void *), hdrlen);
 	m_adj(m, ccmp.ic_header);
 	m_adj(m, -ccmp.ic_trailer);
 

Index: src/sys/net80211/ieee80211_crypto_wep.c
diff -u src/sys/net80211/ieee80211_crypto_wep.c:1.11 src/sys/net80211/ieee80211_crypto_wep.c:1.12
--- src/sys/net80211/ieee80211_crypto_wep.c:1.11	Fri Jan 19 07:58:25 2018
+++ src/sys/net80211/ieee80211_crypto_wep.c	Thu May  3 17:14:37 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_crypto_wep.c,v 1.11 2018/01/19 07:58:25 maxv Exp $	*/
+/*	$NetBSD: ieee80211_crypto_wep.c,v 1.12 2018/05/03 17:14:37 maxv Exp $	*/
 
 /*
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_wep.c,v 1.7 2005/06/10 16:11:24 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_wep.c,v 1.11 2018/01/19 07:58:25 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_wep.c,v 1.12 2018/05/03 17:14:37 maxv Exp $");
 #endif
 
 /*
@@ -227,7 +227,7 @@ wep_decap(struct ieee80211_key *k, struc
 	/*
 	 * Copy up 802.11 header and strip crypto bits.
 	 */
-	ovbcopy(mtod(m, void *), mtod(m, u_int8_t *) + wep.ic_header, hdrlen);
+	memmove(mtod(m, u_int8_t *) + wep.ic_header, mtod(m, void *), hdrlen);
 	m_adj(m, wep.ic_header);
 	m_adj(m, -wep.ic_trailer);
 

Index: src/sys/net80211/ieee80211_netbsd.h
diff -u src/sys/net80211/ieee80211_netbsd.h:1.20 src/sys/net80211/ieee80211_netbsd.h:1.21
--- src/sys/net80211/ieee80211_netbsd.h:1.20	Fri Apr 27 06:56:21 2018
+++ src/sys/net80211/ieee80211_netbsd.h	Thu May  3 17:14:37 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ieee80211_netbsd.h,v 1.20 2018/04/27 06:56:21 maxv Exp $ */
+/* $NetBSD: ieee80211_netbsd.h,v 1.21 2018/05/03 17:14:37 maxv Exp $ */
 /*-
  * Copyright (c) 2003-2005 Sam Leffler, Errno Consulting
  * All rights reserved.
@@ -231,7 +231,6 @@ struct ieee80211_michael_event {
 
 #ifdef _KERNEL
 #define	ticks	hardclock_ticks
-#define	ovbcopy(__src, __dst, __n)	((void)memmove(__dst, __src, __n))
 
 void	if_printf(struct ifnet *, const char *, ...);
 void	get_random_bytes(void *, size_t);

Index: src/sys/net80211/ieee80211_output.c
diff -u src/sys/net80211/ieee80211_output.c:1.61 src/sys/net80211/ieee80211_output.c:1.62
--- src/sys/net80211/ieee80211_output.c:1.61	Thu Jan 18 16:23:43 2018
+++ src/sys/net80211/ieee80211_output.c	Thu May  3 17:14:37 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_output.c,v 1.61 2018/01/18 16:23:43 maxv Exp $	*/
+/*	$NetBSD: ieee80211_output.c,v 1.62 2018/05/03 17:14:37 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_output.c,v 1.34 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_output.c,v 1.61 2018/01/18 16:23:43 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_output.c,v 1.62 2018/05/03 17:14:37 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -2084,7 +2084,7 @@ ieee80211_beacon_update(struct ieee80211
 			}
 			if (timlen != bo->bo_tim_len) {
 /* copy up/down trailer */
-ovbcopy(bo->bo_trailer, tie->tim_bitmap+timlen,
+memmove(tie->tim_bitmap+timlen, bo->bo_trailer,
 	bo->bo_trailer_len);
 bo->bo_trailer 

CVS commit: src/sys/net80211

2018-04-10 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Apr 10 07:53:36 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_crypto.c

Log Message:
Improve an XXX of mine, and fix one stat.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/net80211/ieee80211_crypto.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_crypto.c
diff -u src/sys/net80211/ieee80211_crypto.c:1.21 src/sys/net80211/ieee80211_crypto.c:1.22
--- src/sys/net80211/ieee80211_crypto.c:1.21	Fri Jan 19 07:52:37 2018
+++ src/sys/net80211/ieee80211_crypto.c	Tue Apr 10 07:53:36 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_crypto.c,v 1.21 2018/01/19 07:52:37 maxv Exp $	*/
+/*	$NetBSD: ieee80211_crypto.c,v 1.22 2018/04/10 07:53:36 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto.c,v 1.12 2005/08/08 18:46:35 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto.c,v 1.21 2018/01/19 07:52:37 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto.c,v 1.22 2018/04/10 07:53:36 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -529,6 +529,11 @@ ieee80211_crypto_setkey(struct ieee80211
 
 /*
  * Add privacy headers appropriate for the specified key.
+ *
+ * XXX XXX XXX: Here we modify 'm', and potentially reallocate it. We
+ * should pass back to the caller the updated pointer to avoid
+ * use-after-frees. This can be done by changing the argument to be **m,
+ * but many drivers will have to be changed accordingly.
  */
 struct ieee80211_key *
 ieee80211_crypto_encap(struct ieee80211com *ic, struct ieee80211_node *ni,
@@ -581,8 +586,6 @@ ieee80211_crypto_encap(struct ieee80211c
 	hdr = mtod(m, u_int8_t *);
 	memmove(hdr, hdr + cip->ic_header, hdrlen);
 
-	/* XXX pass the updated pointer back to the caller */
-
 	return (cip->ic_encap(k, m, keyid<<6) ? k : NULL);
 }
 
@@ -647,7 +650,7 @@ ieee80211_crypto_decap(struct ieee80211c
 		IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO,
 		"[%s] unable to pullup %s header\n",
 		ether_sprintf(wh->i_addr2), cip->ic_name);
-		ic->ic_stats.is_rx_wepfail++;	/* XXX */
+		ic->ic_stats.is_rx_tooshort++;
 		return NULL;
 	}
 



CVS commit: src/sys/net80211

2018-04-10 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Apr 10 07:53:36 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_crypto.c

Log Message:
Improve an XXX of mine, and fix one stat.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/net80211/ieee80211_crypto.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Jan 21 14:18:21 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_node.h

Log Message:
Switch sp_timoff to u_int16_t, to prevent possible overflow in
ieee80211_recv_mgmt_beacon(). Actually this field is unused.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/net80211/ieee80211_node.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_node.h
diff -u src/sys/net80211/ieee80211_node.h:1.28 src/sys/net80211/ieee80211_node.h:1.29
--- src/sys/net80211/ieee80211_node.h:1.28	Tue Jan 16 18:42:43 2018
+++ src/sys/net80211/ieee80211_node.h	Sun Jan 21 14:18:21 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_node.h,v 1.28 2018/01/16 18:42:43 maxv Exp $	*/
+/*	$NetBSD: ieee80211_node.h,v 1.29 2018/01/21 14:18:21 maxv Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -303,7 +303,7 @@ struct ieee80211_scanparams {
 	u_int8_t	sp_fhindex;
 	u_int8_t	sp_erp;
 	u_int16_t	sp_bintval;
-	u_int8_t	sp_timoff;
+	u_int16_t	sp_timoff;
 	u_int8_t	*sp_tim;
 	u_int8_t	*sp_tstamp;
 	u_int8_t	*sp_country;



CVS commit: src/sys/net80211

2018-01-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Jan 21 14:18:21 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_node.h

Log Message:
Switch sp_timoff to u_int16_t, to prevent possible overflow in
ieee80211_recv_mgmt_beacon(). Actually this field is unused.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/net80211/ieee80211_node.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Jan 21 14:13:49 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Appease the overflow check, 4 is enough.


To generate a diff of this commit:
cvs rdiff -u -r1.109 -r1.110 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.109 src/sys/net80211/ieee80211_input.c:1.110
--- src/sys/net80211/ieee80211_input.c:1.109	Wed Jan 17 16:03:16 2018
+++ src/sys/net80211/ieee80211_input.c	Sun Jan 21 14:13:49 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.109 2018/01/17 16:03:16 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.110 2018/01/21 14:13:49 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.109 2018/01/17 16:03:16 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.110 2018/01/21 14:13:49 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -2141,7 +2141,7 @@ ieee80211_recv_mgmt_beacon(struct ieee80
 			break;
 		case IEEE80211_ELEMID_TIM:
 			/* XXX ATIM? */
-			IEEE80211_VERIFY_LENGTH(frm[1], 5);
+			IEEE80211_VERIFY_LENGTH(frm[1], 4);
 			scan.sp_tim = frm;
 			scan.sp_timoff = frm - mtod(m0, u_int8_t *);
 			break;



CVS commit: src/sys/net80211

2018-01-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Jan 21 14:13:49 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Appease the overflow check, 4 is enough.


To generate a diff of this commit:
cvs rdiff -u -r1.109 -r1.110 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/sys/net80211

2018-01-21 Thread Maxime Villard

Le 20/01/2018 à 20:40, Mindaugas Rasiukevicius a écrit :

Hi,

David Young  wrote:

On Tue, Jan 16, 2018 at 08:39:29AM +, Maxime Villard wrote:

Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 08:39:29 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c



...

IMO, changes like this are important and overdue, however, do keep in
mind the provenance of this code: NetBSD -> FreeBSD.

Maybe you have written off ever re-synching with FreeBSD?  If so, do
you have a plan for integrating useful features like virtual stations
independently of their code?


I can just echo this part.  It is completely unrealistic that NetBSD can
maintain its own 802.11 stack these days. 


Well, I agree, but:


A better approach would be to sync the code with FreeBSD and treat is as
an upstream, trying to merge the fixes back there.  Not sure if diverging
will help syncing the code.


My point, in the changes I made, was to fix several bugs, and along the way,
put the code in a state where it is at least readable a little.

That's not incompatible with syncing the code with FreeBSD afterwards. We
don't have more features as a result of my changes, but at least the ones we
have are less buggy.

Maxime


Re: CVS commit: src/sys/net80211

2018-01-20 Thread maya
I don't think there is any objection, even if adopting the freebsd code
results in kiling less important drivers.

Note that freebsd has similar bugs to what maxv just fixed (I emailed
security-officer@freebsd about the one I saw).


Re: CVS commit: src/sys/net80211

2018-01-20 Thread Mindaugas Rasiukevicius
Hi,

David Young  wrote:
> On Tue, Jan 16, 2018 at 08:39:29AM +, Maxime Villard wrote:
> > Module Name:src
> > Committed By:   maxv
> > Date:   Tue Jan 16 08:39:29 UTC 2018
> > 
> > Modified Files:
> > src/sys/net80211: ieee80211_input.c
> > 
> 
> ...
> 
> IMO, changes like this are important and overdue, however, do keep in
> mind the provenance of this code: NetBSD -> FreeBSD.
> 
> Maybe you have written off ever re-synching with FreeBSD?  If so, do
> you have a plan for integrating useful features like virtual stations
> independently of their code?

I can just echo this part.  It is completely unrealistic that NetBSD can
maintain its own 802.11 stack these days.  A better approach would be to
sync the code with FreeBSD and treat is as an upstream, trying to merge
the fixes back there.  Not sure if diverging will help syncing the code.

IMO, 802.11n (and there is some FreeBSD code for 802.11ac) is much more
useful feature, as it would allow NetBSD users to use decent WiFI speeds.
Currently supported throughput is pretty miserable for these days..

-- 
Mindaugas


CVS commit: src/sys/net80211

2018-01-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jan 19 07:58:25 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_crypto_wep.c

Log Message:
Style, no functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/net80211/ieee80211_crypto_wep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_crypto_wep.c
diff -u src/sys/net80211/ieee80211_crypto_wep.c:1.10 src/sys/net80211/ieee80211_crypto_wep.c:1.11
--- src/sys/net80211/ieee80211_crypto_wep.c:1.10	Wed Jan 17 17:41:38 2018
+++ src/sys/net80211/ieee80211_crypto_wep.c	Fri Jan 19 07:58:25 2018
@@ -1,4 +1,6 @@
-/*-
+/*	$NetBSD: ieee80211_crypto_wep.c,v 1.11 2018/01/19 07:58:25 maxv Exp $	*/
+
+/*
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
  * All rights reserved.
  *
@@ -34,15 +36,15 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_wep.c,v 1.7 2005/06/10 16:11:24 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_wep.c,v 1.10 2018/01/17 17:41:38 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_wep.c,v 1.11 2018/01/19 07:58:25 maxv Exp $");
 #endif
 
 /*
  * IEEE 802.11 WEP crypto support.
  */
 #include 
-#include  
-#include
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -93,8 +95,7 @@ wep_attach(struct ieee80211com *ic, stru
 {
 	struct wep_ctx *ctx;
 
-	ctx = malloc(sizeof(struct wep_ctx),
-		M_DEVBUF, M_NOWAIT | M_ZERO);
+	ctx = malloc(sizeof(struct wep_ctx), M_DEVBUF, M_NOWAIT | M_ZERO);
 	if (ctx == NULL) {
 		ic->ic_stats.is_crypto_nomem++;
 		return NULL;
@@ -190,8 +191,7 @@ wep_encap(struct ieee80211_key *k, struc
  * Add MIC to the frame as needed.
  */
 static int
-wep_enmic(struct ieee80211_key *k, struct mbuf *m,
-int force)
+wep_enmic(struct ieee80211_key *k, struct mbuf *m, int force)
 {
 
 	return 1;
@@ -315,7 +315,10 @@ wep_encrypt(struct ieee80211_key *key, s
 
 	ctx->wc_ic->ic_stats.is_crypto_wep++;
 
-	/* NB: this assumes the header was pulled up */
+	/*
+	 * NB: this assumes the header was pulled up; it was done in
+	 * ieee80211_crypto_encap().
+	 */
 	memcpy(rc4key, mtod(m, u_int8_t *) + hdrlen, IEEE80211_WEP_IVLEN);
 	memcpy(rc4key + IEEE80211_WEP_IVLEN, key->wk_key, key->wk_keylen);
 
@@ -449,8 +452,10 @@ wep_decrypt(struct ieee80211_key *key, s
 	}
 	crc = ~crc;
 
-	/* Encrypt little-endian CRC32 and verify that it matches with
-	 * received ICV */
+	/*
+	 * Encrypt little-endian CRC32 and verify that it matches with
+	 * received ICV
+	 */
 	icv[0] = crc;
 	icv[1] = crc >> 8;
 	icv[2] = crc >> 16;



CVS commit: src/sys/net80211

2018-01-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jan 19 07:58:25 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_crypto_wep.c

Log Message:
Style, no functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/net80211/ieee80211_crypto_wep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jan 19 07:57:50 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_crypto_tkip.c

Log Message:
Style, and check the return value of m_append.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/net80211/ieee80211_crypto_tkip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_crypto_tkip.c
diff -u src/sys/net80211/ieee80211_crypto_tkip.c:1.13 src/sys/net80211/ieee80211_crypto_tkip.c:1.14
--- src/sys/net80211/ieee80211_crypto_tkip.c:1.13	Wed Jan 17 17:41:38 2018
+++ src/sys/net80211/ieee80211_crypto_tkip.c	Fri Jan 19 07:57:50 2018
@@ -1,4 +1,6 @@
-/*-
+/*	$NetBSD: ieee80211_crypto_tkip.c,v 1.14 2018/01/19 07:57:50 maxv Exp $	*/
+
+/*
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
  * All rights reserved.
  *
@@ -34,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_tkip.c,v 1.10 2005/08/08 18:46:35 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_tkip.c,v 1.13 2018/01/17 17:41:38 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_tkip.c,v 1.14 2018/01/19 07:57:50 maxv Exp $");
 #endif
 
 /*
@@ -45,8 +47,8 @@ __KERNEL_RCSID(0, "$NetBSD: ieee80211_cr
  * its license is included below.
  */
 #include 
-#include  
-#include
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -328,7 +330,7 @@ tkip_demic(struct ieee80211_key *k, stru
 
 		ic->ic_stats.is_crypto_tkipdemic++;
 
-		michael_mic(ctx, k->wk_rxmic, 
+		michael_mic(ctx, k->wk_rxmic,
 			m, hdrlen, m->m_pkthdr.len - (hdrlen + tkip.ic_miclen),
 			mic);
 		m_copydata(m, m->m_pkthdr.len - tkip.ic_miclen,
@@ -885,17 +887,21 @@ tkip_encrypt(struct tkip_ctx *ctx, struc
 		ctx->tx_phase1_done = 1;
 	}
 	tkip_mixing_phase2(ctx->tx_rc4key, key->wk_key, ctx->tx_ttak,
-		(u16) key->wk_keytsc);
+		(u16)key->wk_keytsc);
 
 	wep_encrypt(ctx->tx_rc4key,
 		m, hdrlen + tkip.ic_header,
 		m->m_pkthdr.len - (hdrlen + tkip.ic_header),
 		icv);
-	(void) m_append(m, IEEE80211_WEP_CRCLEN, icv);	/* XXX check return */
+
+	if (!m_append(m, IEEE80211_WEP_CRCLEN, icv)) {
+		return 0;
+	}
 
 	key->wk_keytsc++;
 	if ((u16)(key->wk_keytsc) == 0)
 		ctx->tx_phase1_done = 0;
+
 	return 1;
 }
 
@@ -922,9 +928,8 @@ tkip_decrypt(struct tkip_ctx *ctx, struc
 	tkip_mixing_phase2(ctx->rx_rc4key, key->wk_key, ctx->rx_ttak, iv16);
 
 	/* NB: m is unstripped; deduct headers + ICV to get payload */
-	if (wep_decrypt(ctx->rx_rc4key,
-		m, hdrlen + tkip.ic_header,
-	m->m_pkthdr.len - (hdrlen + tkip.ic_header + tkip.ic_trailer))) {
+	if (wep_decrypt(ctx->rx_rc4key, m, hdrlen + tkip.ic_header,
+	m->m_pkthdr.len - (hdrlen + tkip.ic_header + tkip.ic_trailer))) {
 		if (iv32 != (u32)(key->wk_keyrsc >> 16)) {
 			/* Previously cached Phase1 result was already lost, so
 			 * it needs to be recalculated for the next packet. */
@@ -936,6 +941,7 @@ tkip_decrypt(struct tkip_ctx *ctx, struc
 		ctx->tc_ic->ic_stats.is_rx_tkipicv++;
 		return 0;
 	}
+
 	return 1;
 }
 



CVS commit: src/sys/net80211

2018-01-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jan 19 07:57:50 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_crypto_tkip.c

Log Message:
Style, and check the return value of m_append.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/net80211/ieee80211_crypto_tkip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jan 19 07:54:34 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_crypto_ccmp.c

Log Message:
Style, no functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/net80211/ieee80211_crypto_ccmp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_crypto_ccmp.c
diff -u src/sys/net80211/ieee80211_crypto_ccmp.c:1.12 src/sys/net80211/ieee80211_crypto_ccmp.c:1.13
--- src/sys/net80211/ieee80211_crypto_ccmp.c:1.12	Wed Jan 17 17:41:38 2018
+++ src/sys/net80211/ieee80211_crypto_ccmp.c	Fri Jan 19 07:54:34 2018
@@ -1,4 +1,6 @@
-/*-
+/*	$NetBSD: ieee80211_crypto_ccmp.c,v 1.13 2018/01/19 07:54:34 maxv Exp $	*/
+
+/*
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
  * All rights reserved.
  *
@@ -34,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_ccmp.c,v 1.7 2005/07/11 03:06:23 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_ccmp.c,v 1.12 2018/01/17 17:41:38 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_ccmp.c,v 1.13 2018/01/19 07:54:34 maxv Exp $");
 #endif
 
 /*
@@ -46,7 +48,7 @@ __KERNEL_RCSID(0, "$NetBSD: ieee80211_cr
  */
 #include 
 #include 
-#include  
+#include 
 #include 
 #include 
 
@@ -64,7 +66,7 @@ __KERNEL_RCSID(0, "$NetBSD: ieee80211_cr
 
 struct ccmp_ctx {
 	struct ieee80211com *cc_ic;	/* for diagnostics */
-	rijndael_ctx	 cc_aes;
+	rijndael_ctx cc_aes;
 };
 
 static	void *ccmp_attach(struct ieee80211com *, struct ieee80211_key *);
@@ -102,8 +104,7 @@ ccmp_attach(struct ieee80211com *ic, str
 {
 	struct ccmp_ctx *ctx;
 
-	ctx = malloc(sizeof(struct ccmp_ctx),
-		M_DEVBUF, M_NOWAIT | M_ZERO);
+	ctx = malloc(sizeof(struct ccmp_ctx), M_DEVBUF, M_NOWAIT | M_ZERO);
 	if (ctx == NULL) {
 		ic->ic_stats.is_crypto_nomem++;
 		return NULL;
@@ -258,8 +259,7 @@ ccmp_decap(struct ieee80211_key *k, stru
  * Verify and strip MIC from the frame.
  */
 static int
-ccmp_demic(struct ieee80211_key *k, struct mbuf *m,
-int force)
+ccmp_demic(struct ieee80211_key *k, struct mbuf *m, int force)
 {
 	return 1;
 }
@@ -419,6 +419,7 @@ ccmp_encrypt(struct ieee80211_key *key, 
 	for (;;) {
 		if (space > data_len)
 			space = data_len;
+
 		/*
 		 * Do full blocks.
 		 */
@@ -430,6 +431,7 @@ ccmp_encrypt(struct ieee80211_key *key, 
 		}
 		if (data_len <= 0)		/* no more data */
 			break;
+
 		m = m->m_next;
 		if (m == NULL) {		/* last buffer */
 			if (space != 0) {
@@ -472,7 +474,7 @@ ccmp_encrypt(struct ieee80211_key *key, 
 }
 /*
  * This mbuf's contents are insufficient,
- * take 'em all and prepare to advance to
+ * take them all and prepare to advance to
  * the next mbuf.
  */
 xor_block(b+sp, pos_next, n->m_len);
@@ -501,6 +503,7 @@ ccmp_encrypt(struct ieee80211_key *key, 
 if (m == NULL)
 	goto done;
 			}
+
 			/*
 			 * Do bookkeeping.  m now points to the last mbuf
 			 * we grabbed data from.  We know we consumed a
@@ -521,6 +524,7 @@ ccmp_encrypt(struct ieee80211_key *key, 
 			space = m->m_len;
 		}
 	}
+
 done:
 	/* tack on MIC */
 	xor_block(b, s0, ccmp.ic_trailer);
@@ -540,7 +544,8 @@ done:
 } while (0)
 
 static int
-ccmp_decrypt(struct ieee80211_key *key, u_int64_t pn, struct mbuf *m, int hdrlen)
+ccmp_decrypt(struct ieee80211_key *key, u_int64_t pn, struct mbuf *m,
+int hdrlen)
 {
 	struct ccmp_ctx *ctx = key->wk_private;
 	struct ieee80211_frame *wh;
@@ -574,12 +579,14 @@ ccmp_decrypt(struct ieee80211_key *key, 
 		}
 		if (data_len <= 0)		/* no more data */
 			break;
+
 		m = m->m_next;
 		if (m == NULL) {		/* last buffer */
 			if (space != 0)		/* short last block */
 CCMP_DECRYPT(i, b, b0, pos, a, space);
 			break;
 		}
+
 		if (space != 0) {
 			uint8_t *pos_next;
 			u_int space_next;
@@ -614,6 +621,7 @@ ccmp_decrypt(struct ieee80211_key *key, 
 			space = m->m_len;
 		}
 	}
+
 	if (memcmp(mic, a, ccmp.ic_trailer) != 0) {
 		IEEE80211_DPRINTF(ctx->cc_ic, IEEE80211_MSG_CRYPTO,
 			"[%s] AES-CCM decrypt failed; MIC mismatch\n",
@@ -621,6 +629,7 @@ ccmp_decrypt(struct ieee80211_key *key, 
 		ctx->cc_ic->ic_stats.is_rx_ccmpmic++;
 		return 0;
 	}
+
 	return 1;
 }
 #undef CCMP_DECRYPT



CVS commit: src/sys/net80211

2018-01-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jan 19 07:54:34 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_crypto_ccmp.c

Log Message:
Style, no functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/net80211/ieee80211_crypto_ccmp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jan 19 07:53:46 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_crypto_none.c

Log Message:
Style, no functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/net80211/ieee80211_crypto_none.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_crypto_none.c
diff -u src/sys/net80211/ieee80211_crypto_none.c:1.7 src/sys/net80211/ieee80211_crypto_none.c:1.8
--- src/sys/net80211/ieee80211_crypto_none.c:1.7	Thu Nov 16 01:33:40 2006
+++ src/sys/net80211/ieee80211_crypto_none.c	Fri Jan 19 07:53:46 2018
@@ -1,4 +1,6 @@
-/*-
+/*	$NetBSD: ieee80211_crypto_none.c,v 1.8 2018/01/19 07:53:46 maxv Exp $	*/
+
+/*
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
  * All rights reserved.
  *
@@ -34,15 +36,15 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_none.c,v 1.5 2005/06/10 16:11:24 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_none.c,v 1.7 2006/11/16 01:33:40 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_none.c,v 1.8 2018/01/19 07:53:46 maxv Exp $");
 #endif
 
 /*
  * IEEE 802.11 NULL crypto support.
  */
 #include 
-#include  
-#include
+#include 
+#include 
 
 #include 
 



CVS commit: src/sys/net80211

2018-01-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jan 19 07:53:46 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_crypto_none.c

Log Message:
Style, no functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/net80211/ieee80211_crypto_none.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jan 19 07:52:37 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_crypto.c

Log Message:
Style, and make sure that there is a header+trailer included in the
packet. The crypto functions can touch the trailer, but they don't check
whether it's there in the first place.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/net80211/ieee80211_crypto.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jan 19 07:52:37 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_crypto.c

Log Message:
Style, and make sure that there is a header+trailer included in the
packet. The crypto functions can touch the trailer, but they don't check
whether it's there in the first place.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/net80211/ieee80211_crypto.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_crypto.c
diff -u src/sys/net80211/ieee80211_crypto.c:1.20 src/sys/net80211/ieee80211_crypto.c:1.21
--- src/sys/net80211/ieee80211_crypto.c:1.20	Wed Jan 17 17:41:38 2018
+++ src/sys/net80211/ieee80211_crypto.c	Fri Jan 19 07:52:37 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_crypto.c,v 1.20 2018/01/17 17:41:38 maxv Exp $	*/
+/*	$NetBSD: ieee80211_crypto.c,v 1.21 2018/01/19 07:52:37 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto.c,v 1.12 2005/08/08 18:46:35 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto.c,v 1.20 2018/01/17 17:41:38 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto.c,v 1.21 2018/01/19 07:52:37 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -48,7 +48,7 @@ __KERNEL_RCSID(0, "$NetBSD: ieee80211_cr
  * IEEE 802.11 generic crypto support.
  */
 #include 
-#include
+#include 
 
 #include 
 #include 
@@ -72,7 +72,7 @@ __KERNEL_RCSID(0, "$NetBSD: ieee80211_cr
 static const struct ieee80211_cipher *ciphers[IEEE80211_CIPHER_MAX];
 
 #ifdef INET
-#include  
+#include 
 #include 
 #endif
 
@@ -136,7 +136,7 @@ cipher_detach(struct ieee80211_key *key)
 	key->wk_cipher->ic_detach(key);
 }
 
-/* 
+/*
  * Wrappers for driver key management methods.
  */
 static __inline int
@@ -605,7 +605,12 @@ ieee80211_crypto_decap(struct ieee80211c
 	struct mbuf *m = *mp;
 	u_int8_t keyid;
 
-	/* NB: this minimum size data frame could be bigger */
+	KASSERT((m->m_flags & M_PKTHDR) != 0);
+
+	/*
+	 * This minimum size data frame could be bigger. It is re-checked
+	 * below.
+	 */
 	if (m->m_pkthdr.len < IEEE80211_WEP_MINLEN) {
 		IEEE80211_DPRINTF(ic, IEEE80211_MSG_ANY,
 			"%s: WEP data frame too short, len %u\n",
@@ -646,5 +651,16 @@ ieee80211_crypto_decap(struct ieee80211c
 		return NULL;
 	}
 
+	/*
+	 * Ensure there is a header+trailer included.
+	 */
+	if (m->m_pkthdr.len < hdrlen + cip->ic_header + cip->ic_trailer) {
+		IEEE80211_DPRINTF(ic, IEEE80211_MSG_ANY,
+			"%s: WEP data frame too short, len %u\n",
+			__func__, m->m_pkthdr.len);
+		ic->ic_stats.is_rx_tooshort++;
+		return NULL;
+	}
+
 	return (cip->ic_decap(k, m, hdrlen) ? k : NULL);
 }



CVS commit: src/sys/net80211

2018-01-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jan 18 17:59:29 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_node.c

Log Message:
Style, no functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sys/net80211/ieee80211_node.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_node.c
diff -u src/sys/net80211/ieee80211_node.c:1.74 src/sys/net80211/ieee80211_node.c:1.75
--- src/sys/net80211/ieee80211_node.c:1.74	Tue Jan 16 18:53:32 2018
+++ src/sys/net80211/ieee80211_node.c	Thu Jan 18 17:59:29 2018
@@ -1,5 +1,6 @@
-/*	$NetBSD: ieee80211_node.c,v 1.74 2018/01/16 18:53:32 maxv Exp $	*/
-/*-
+/*	$NetBSD: ieee80211_node.c,v 1.75 2018/01/18 17:59:29 maxv Exp $	*/
+
+/*
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
  * All rights reserved.
@@ -36,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_node.c,v 1.65 2005/08/13 17:50:21 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_node.c,v 1.74 2018/01/16 18:53:32 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_node.c,v 1.75 2018/01/18 17:59:29 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -300,8 +301,8 @@ ieee80211_reset_scan(struct ieee80211com
 void
 ieee80211_begin_scan(struct ieee80211com *ic, int reset)
 {
-
 	ic->ic_scan.nt_scangen++;
+
 	/*
 	 * In all but hostap mode scanning starts off in
 	 * an active mode before switching to passive.
@@ -315,6 +316,7 @@ ieee80211_begin_scan(struct ieee80211com
 		"begin %s scan in %s mode, scangen %u\n",
 		(ic->ic_flags & IEEE80211_F_ASCAN) ?  "active" : "passive",
 		ieee80211_phymode_name[ic->ic_curmode], ic->ic_scan.nt_scangen);
+
 	/*
 	 * Clear scan state and flush any previously seen AP's.
 	 */
@@ -365,6 +367,7 @@ ieee80211_next_scan(struct ieee80211com 
 			return 1;
 		}
 	} while (chan != ic->ic_curchan);
+
 	ieee80211_end_scan(ic);
 	return 0;
 }
@@ -455,12 +458,14 @@ ieee80211_create_ibss(struct ieee80211co
 		else
 			ni->ni_bssid[0] |= 0x02;	/* local bit for IBSS */
 	}
+
 	/*
 	 * Fix the channel and related attributes.
 	 */
 	ieee80211_set_chan(ic, ni, chan);
 	ic->ic_curchan = chan;
 	ic->ic_curmode = ieee80211_chan2mode(ic, chan);
+
 	/*
 	 * Do mode-specific rate setup.
 	 */
@@ -476,7 +481,7 @@ ieee80211_create_ibss(struct ieee80211co
 		ieee80211_set11gbasicrates(>ni_rates, IEEE80211_MODE_11B);
 	}
 
-	(void) ieee80211_sta_join(ic, ieee80211_ref_node(ni));
+	(void)ieee80211_sta_join(ic, ieee80211_ref_node(ni));
 }
 
 void
@@ -504,8 +509,8 @@ ieee80211_reset_bss(struct ieee80211com 
 static int
 ieee80211_match_bss(struct ieee80211com *ic, struct ieee80211_node *ni)
 {
-u_int8_t rate;
-int fail;
+	u_int8_t rate;
+	int fail;
 
 	fail = 0;
 	if (isclr(ic->ic_chan_active, ieee80211_chan2ieee(ic, ni->ni_chan)))
@@ -513,6 +518,7 @@ ieee80211_match_bss(struct ieee80211com 
 	if (ic->ic_des_chan != IEEE80211_CHAN_ANYC &&
 	ni->ni_chan != ic->ic_des_chan)
 		fail |= 0x01;
+
 	if (ic->ic_opmode == IEEE80211_M_IBSS) {
 		if ((ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) == 0)
 			fail |= 0x02;
@@ -520,6 +526,7 @@ ieee80211_match_bss(struct ieee80211com 
 		if ((ni->ni_capinfo & IEEE80211_CAPINFO_ESS) == 0)
 			fail |= 0x02;
 	}
+
 	if (ic->ic_flags & IEEE80211_F_PRIVACY) {
 		if ((ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) == 0)
 			fail |= 0x04;
@@ -528,18 +535,23 @@ ieee80211_match_bss(struct ieee80211com 
 		if (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY)
 			fail |= 0x04;
 	}
+
 	rate = ieee80211_fix_rate(ni, IEEE80211_R_DONEGO | IEEE80211_R_DOFRATE);
 	if (rate & IEEE80211_RATE_BASIC)
 		fail |= 0x08;
+
 	if (ic->ic_des_esslen != 0 &&
 	(ni->ni_esslen != ic->ic_des_esslen ||
 	 memcmp(ni->ni_essid, ic->ic_des_essid, ic->ic_des_esslen) != 0))
 		fail |= 0x10;
+
 	if ((ic->ic_flags & IEEE80211_F_DESBSSID) &&
 	!IEEE80211_ADDR_EQ(ic->ic_des_bssid, ni->ni_bssid))
 		fail |= 0x20;
+
 	if (ni->ni_fails >= STA_FAILS_MAX)
 		fail |= 0x40;
+
 #ifdef IEEE80211_DEBUG
 	if (ieee80211_msg_scan(ic)) {
 		printf(" %c %s",
@@ -565,6 +577,7 @@ ieee80211_match_bss(struct ieee80211com 
 		printf("%s\n", fail & 0x10 ? "!" : "");
 	}
 #endif
+
 	return fail;
 }
 
@@ -584,9 +597,8 @@ maxrate(const struct ieee80211_node *ni)
  * Used to select the best scan candidate for association in a BSS.
  */
 static int
-ieee80211_node_compare(struct ieee80211com *ic,
-		   const struct ieee80211_node *a,
-		   const struct ieee80211_node *b)
+ieee80211_node_compare(struct ieee80211com *ic, const struct ieee80211_node *a,
+const struct ieee80211_node *b)
 {
 	u_int8_t maxa, maxb;
 	u_int8_t rssia, rssib;
@@ -675,9 +687,10 @@ ieee80211_end_scan(struct ieee80211com *
 maxrssi[i] = rssi;
 		}
 		IEEE80211_NODE_UNLOCK(nt);
+
 		/* XXX select channel more intelligently */
 		bestchan = -1;
-		for (i = 0; i < IEEE80211_CHAN_MAX; i++)
+		

CVS commit: src/sys/net80211

2018-01-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jan 18 17:59:29 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_node.c

Log Message:
Style, no functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sys/net80211/ieee80211_node.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jan 18 17:57:49 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_netbsd.c

Log Message:
Style, and zero out 'ns' entirely, otherwise some bytes get leaked to
userland (eg ns_rsvd0).


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/net80211/ieee80211_netbsd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_netbsd.c
diff -u src/sys/net80211/ieee80211_netbsd.c:1.29 src/sys/net80211/ieee80211_netbsd.c:1.30
--- src/sys/net80211/ieee80211_netbsd.c:1.29	Sat Jan 14 16:34:44 2017
+++ src/sys/net80211/ieee80211_netbsd.c	Thu Jan 18 17:57:49 2018
@@ -1,5 +1,6 @@
-/* $NetBSD: ieee80211_netbsd.c,v 1.29 2017/01/14 16:34:44 maya Exp $ */
-/*-
+/* $NetBSD: ieee80211_netbsd.c,v 1.30 2018/01/18 17:57:49 maxv Exp $ */
+
+/*
  * Copyright (c) 2003-2005 Sam Leffler, Errno Consulting
  * All rights reserved.
  *
@@ -30,7 +31,7 @@
 #ifdef __FreeBSD__
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_freebsd.c,v 1.8 2005/08/08 18:46:35 sam Exp $");
 #else
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_netbsd.c,v 1.29 2017/01/14 16:34:44 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_netbsd.c,v 1.30 2018/01/18 17:57:49 maxv Exp $");
 #endif
 
 /*
@@ -38,8 +39,8 @@ __KERNEL_RCSID(0, "$NetBSD: ieee80211_ne
  */
 #include 
 #include 
-#include  
-#include
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -89,7 +90,7 @@ ieee80211_init0(void)
 		max_linkhdr = ALIGN(sizeof(struct ieee80211_qosframe_addr4));
 	}
 
-__link_set_foreach(ieee80211_setup, ieee80211_funcs) {
+	__link_set_foreach(ieee80211_setup, ieee80211_funcs) {
 		f = (void*)*ieee80211_setup;
 		(*f)();
 	}
@@ -112,22 +113,25 @@ ieee80211_sysctl_inact(SYSCTLFN_ARGS)
 	struct sysctlnode node;
 
 	node = *rnode;
-	/* sysctl_lookup copies the product from t.  Then, it
+
+	/*
+	 * sysctl_lookup copies the product from t.  Then, it
 	 * copies the new value onto t.
 	 */
 	t = *(int*)rnode->sysctl_data * IEEE80211_INACT_WAIT;
 	node.sysctl_data = 
 	error = sysctl_lookup(SYSCTLFN_CALL());
 	if (error || newp == NULL)
-		return (error);
+		return error;
 
-	/* The new value was in seconds.  Convert to inactivity-wait
+	/*
+	 * The new value was in seconds.  Convert to inactivity-wait
 	 * intervals.  There are IEEE80211_INACT_WAIT seconds per
 	 * interval.
 	 */
 	*(int*)rnode->sysctl_data = t / IEEE80211_INACT_WAIT;
 
-	return (0);
+	return 0;
 }
 
 static int
@@ -263,11 +267,11 @@ ieee80211_sysctl_detach(struct ieee80211
  *
  *	If there is any single 802.11 interface, ieee80211_node_walkfirst
  *	must not return NULL.
- */	
+ */
 static struct ieee80211_node *
 ieee80211_node_walkfirst(struct ieee80211_node_walk *nw, u_short if_index)
 {
-	(void)memset(nw, 0, sizeof(*nw));
+	memset(nw, 0, sizeof(*nw));
 
 	nw->nw_ifindex = if_index;
 
@@ -332,11 +336,13 @@ ieee80211_sysctl_fill_node(struct ieee80
 struct ieee80211_node_sysctl *ns, int ifindex,
 const struct ieee80211_channel *chan0, uint32_t flags)
 {
+	memset(ns, 0, sizeof(*ns));
+
 	ns->ns_ifindex = ifindex;
 	ns->ns_capinfo = ni->ni_capinfo;
 	ns->ns_flags = flags;
-	(void)memcpy(ns->ns_macaddr, ni->ni_macaddr, sizeof(ns->ns_macaddr));
-	(void)memcpy(ns->ns_bssid, ni->ni_bssid, sizeof(ns->ns_bssid));
+	memcpy(ns->ns_macaddr, ni->ni_macaddr, sizeof(ns->ns_macaddr));
+	memcpy(ns->ns_bssid, ni->ni_bssid, sizeof(ns->ns_bssid));
 	if (ni->ni_chan != IEEE80211_CHAN_ANYC) {
 		ns->ns_freq = ni->ni_chan->ic_freq;
 		ns->ns_chanflags = ni->ni_chan->ic_flags;
@@ -347,7 +353,7 @@ ieee80211_sysctl_fill_node(struct ieee80
 	}
 	ns->ns_rssi = ni->ni_rssi;
 	ns->ns_esslen = ni->ni_esslen;
-	(void)memcpy(ns->ns_essid, ni->ni_essid, sizeof(ns->ns_essid));
+	memcpy(ns->ns_essid, ni->ni_essid, sizeof(ns->ns_essid));
 	ns->ns_erp = ni->ni_erp;
 	ns->ns_associd = ni->ni_associd;
 	ns->ns_inact = ni->ni_inact * IEEE80211_INACT_WAIT;
@@ -355,7 +361,7 @@ ieee80211_sysctl_fill_node(struct ieee80
 	ns->ns_rates = ni->ni_rates;
 	ns->ns_txrate = ni->ni_txrate;
 	ns->ns_intval = ni->ni_intval;
-	(void)memcpy(ns->ns_tstamp, >ni_tstamp, sizeof(ns->ns_tstamp));
+	memcpy(ns->ns_tstamp, >ni_tstamp, sizeof(ns->ns_tstamp));
 	ns->ns_txseq = ni->ni_txseqs[0];
 	ns->ns_rxseq = ni->ni_rxseqs[0];
 	ns->ns_fhdwell = ni->ni_fhdwell;
@@ -485,7 +491,7 @@ ieee80211_sysctl_setup(void)
 	"debug", SYSCTL_DESCR("control debugging printfs"),
 	NULL, 0, _debug, 0, CTL_CREATE, CTL_EOL)) != 0)
 		goto err;
-#endif /* IEEE80211_DEBUG */
+#endif
 
 	ieee80211_rssadapt_sysctl_setup(_sysctllog);
 
@@ -524,7 +530,6 @@ ieee80211_drain_ifq(struct ifqueue *ifq)
 	}
 }
 
-
 void
 if_printf(struct ifnet *ifp, const char *fmt, ...)
 {
@@ -538,7 +543,6 @@ if_printf(struct ifnet *ifp, const char 
 	return;
 }
 
-
 /*
  * Allocate and setup a management frame of the specified
  * size.  We return the mbuf and a pointer to the start
@@ -561,6 

CVS commit: src/sys/net80211

2018-01-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jan 18 17:57:49 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_netbsd.c

Log Message:
Style, and zero out 'ns' entirely, otherwise some bytes get leaked to
userland (eg ns_rsvd0).


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/net80211/ieee80211_netbsd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jan 18 16:23:43 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_output.c

Log Message:
Several changes:

 * Make the code more readable.

 * Add a panic in ieee80211_compute_duration(). I'm not sure there's
   a bug here - I don't have the hardware -, but looking at the code, it
   may be possible for 'paylen' to go negative. Obviously that's not the
   correct way to fix it, but at least we'll see if it happens.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/net80211/ieee80211_output.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_output.c
diff -u src/sys/net80211/ieee80211_output.c:1.60 src/sys/net80211/ieee80211_output.c:1.61
--- src/sys/net80211/ieee80211_output.c:1.60	Thu Jan 18 13:24:01 2018
+++ src/sys/net80211/ieee80211_output.c	Thu Jan 18 16:23:43 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_output.c,v 1.60 2018/01/18 13:24:01 maxv Exp $	*/
+/*	$NetBSD: ieee80211_output.c,v 1.61 2018/01/18 16:23:43 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_output.c,v 1.34 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_output.c,v 1.60 2018/01/18 13:24:01 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_output.c,v 1.61 2018/01/18 16:23:43 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -404,6 +404,9 @@ done:
  * 802.11 data frame.  If room isn't already there, arrange for it.
  * Drivers and cipher modules assume we have done the necessary work
  * and fail rudely if they don't find the space they need.
+ *
+ * Basically, we are trying to make sure that the several M_PREPENDs
+ * called after this function do not fail.
  */
 static struct mbuf *
 ieee80211_mbuf_adjust(struct ieee80211com *ic, int hdrsize,
@@ -447,30 +450,30 @@ ieee80211_mbuf_adjust(struct ieee80211co
 		 * required (the latter are added when the driver calls
 		 * back to ieee80211_crypto_encap to do crypto encapsulation).
 		 */
-		/* NB: must be first 'cuz it clobbers m_data */
 		M_MOVE_PKTHDR(n, m);
-		n->m_len = 0;			/* NB: m_gethdr does not set */
+		n->m_len = 0;
 		n->m_data += needed_space;
+
 		/*
 		 * Pull up Ethernet header to create the expected layout.
 		 * We could use m_pullup but that's overkill (i.e. we don't
 		 * need the actual data) and it cannot fail so do it inline
 		 * for speed.
 		 */
-		/* NB: struct ether_header is known to be contiguous */
 		n->m_len += sizeof(struct ether_header);
 		m->m_len -= sizeof(struct ether_header);
 		m->m_data += sizeof(struct ether_header);
+
 		/*
 		 * Replace the head of the chain.
 		 */
 		n->m_next = m;
 		m = n;
 	} else {
-/*
+		/*
 		 * We will overwrite the ethernet header in the
- * 802.11 encapsulation stage.  Make sure that it
- * is writable.
+		 * 802.11 encapsulation stage.  Make sure that it
+		 * is writable.
 		 */
 		wlen = sizeof(struct ether_header);
 	}
@@ -479,13 +482,14 @@ ieee80211_mbuf_adjust(struct ieee80211co
 	 * If we're going to s/w encrypt the mbuf chain make sure it is
 	 * writable.
 	 */
-	if (key != NULL && (key->wk_flags & IEEE80211_KEY_SWCRYPT) != 0)
+	if (key != NULL && (key->wk_flags & IEEE80211_KEY_SWCRYPT) != 0) {
 		wlen = M_COPYALL;
-
+	}
 	if (wlen != 0 && m_makewritable(, 0, wlen, M_DONTWAIT) != 0) {
 		m_freem(m);
 		return NULL;
 	}
+
 	return m;
 #undef TO_BE_RECLAIMED
 }
@@ -843,11 +847,15 @@ ieee80211_compute_duration(const struct 
 
 	hdrlen = ieee80211_anyhdrsize((const void *)wh);
 
-/* Account for padding required by the driver. */
-	if (icflags & IEEE80211_F_DATAPAD)
+	/* Account for padding required by the driver. */
+	if (icflags & IEEE80211_F_DATAPAD) {
 		paylen = len - roundup(hdrlen, sizeof(u_int32_t));
-	else
+		if (paylen < 0) {
+			panic("%s: paylen < 0", __func__);
+		}
+	} else {
 		paylen = len - hdrlen;
+	}
 
 	overlen = IEEE80211_CRC_LEN;
 
@@ -914,7 +922,8 @@ ieee80211_fragment(struct ieee80211com *
 {
 	struct ieee80211_frame *wh, *whf;
 	struct mbuf *m, *prev, *next;
-	u_int totalhdrsize, fragno, fragsize, off, remainder, payload;
+	const u_int totalhdrsize = hdrsize + ciphdrsize;
+	u_int fragno, fragsize, off, remainder, payload;
 
 	IASSERT(m0->m_nextpkt == NULL, ("mbuf already chained?"));
 	IASSERT(m0->m_pkthdr.len > mtu,
@@ -923,7 +932,7 @@ ieee80211_fragment(struct ieee80211com *
 	wh = mtod(m0, struct ieee80211_frame *);
 	/* NB: mark the first frag; it will be propagated below */
 	wh->i_fc[1] |= IEEE80211_FC1_MORE_FRAG;
-	totalhdrsize = hdrsize + ciphdrsize;
+
 	fragno = 1;
 	off = mtu - ciphdrsize;
 	remainder = m0->m_pkthdr.len - off;
@@ -940,6 +949,7 @@ ieee80211_fragment(struct ieee80211com *
 			m = m_gethdr(M_DONTWAIT, MT_DATA);
 		if (m == NULL)
 			goto bad;
+
 		/* leave room to prepend any 

CVS commit: src/sys/net80211

2018-01-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jan 18 16:23:43 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_output.c

Log Message:
Several changes:

 * Make the code more readable.

 * Add a panic in ieee80211_compute_duration(). I'm not sure there's
   a bug here - I don't have the hardware -, but looking at the code, it
   may be possible for 'paylen' to go negative. Obviously that's not the
   correct way to fix it, but at least we'll see if it happens.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/net80211/ieee80211_output.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jan 18 13:24:01 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_output.c

Log Message:
Several changes:

 * Make the code more readable. In particular, declare variables as const
   along the way.

 * Explain what we're doing in ieee80211_send_mgmt(). The
   IEEE80211_FC0_SUBTYPE_PROBE_RESP case has some inconsistencies, but
   they are not inherently wrong so I'm not changing that.

 * When sending IEEE80211_FC0_SUBTYPE_REASSOC_RESP frames, make sure to
   zero out the 'association ID', otherwise two bytes are leaked.

 * Fix a possible memory leak in ieee80211_send_probereq().


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/net80211/ieee80211_output.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_output.c
diff -u src/sys/net80211/ieee80211_output.c:1.59 src/sys/net80211/ieee80211_output.c:1.60
--- src/sys/net80211/ieee80211_output.c:1.59	Tue Sep 26 07:42:06 2017
+++ src/sys/net80211/ieee80211_output.c	Thu Jan 18 13:24:01 2018
@@ -1,5 +1,6 @@
-/*	$NetBSD: ieee80211_output.c,v 1.59 2017/09/26 07:42:06 knakahara Exp $	*/
-/*-
+/*	$NetBSD: ieee80211_output.c,v 1.60 2018/01/18 13:24:01 maxv Exp $	*/
+
+/*
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
  * All rights reserved.
@@ -36,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_output.c,v 1.34 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_output.c,v 1.59 2017/09/26 07:42:06 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_output.c,v 1.60 2018/01/18 13:24:01 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -115,6 +116,7 @@ ieee80211_send_setup(struct ieee80211com
 #define	WH4(wh)	((struct ieee80211_frame_addr4 *)wh)
 
 	wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | type;
+
 	if ((type & IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_DATA) {
 		switch (ic->ic_opmode) {
 		case IEEE80211_M_STA:
@@ -123,6 +125,7 @@ ieee80211_send_setup(struct ieee80211com
 			IEEE80211_ADDR_COPY(wh->i_addr2, sa);
 			IEEE80211_ADDR_COPY(wh->i_addr3, da);
 			break;
+
 		case IEEE80211_M_IBSS:
 		case IEEE80211_M_AHDEMO:
 			wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
@@ -130,12 +133,14 @@ ieee80211_send_setup(struct ieee80211com
 			IEEE80211_ADDR_COPY(wh->i_addr2, sa);
 			IEEE80211_ADDR_COPY(wh->i_addr3, bssid);
 			break;
+
 		case IEEE80211_M_HOSTAP:
 			wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS;
 			IEEE80211_ADDR_COPY(wh->i_addr1, da);
 			IEEE80211_ADDR_COPY(wh->i_addr2, bssid);
 			IEEE80211_ADDR_COPY(wh->i_addr3, sa);
 			break;
+
 		case IEEE80211_M_MONITOR:	/* NB: to quiet compiler */
 			break;
 		}
@@ -145,6 +150,7 @@ ieee80211_send_setup(struct ieee80211com
 		IEEE80211_ADDR_COPY(wh->i_addr2, sa);
 		IEEE80211_ADDR_COPY(wh->i_addr3, bssid);
 	}
+
 	*(u_int16_t *)>i_dur[0] = 0;
 	/* NB: use non-QoS tid */
 	*(u_int16_t *)>i_seq[0] =
@@ -187,9 +193,9 @@ ieee80211_mgmt_output(struct ieee80211co
 	M_SETCTX(m, ni);
 
 	wh = mtod(m, struct ieee80211_frame *);
-	ieee80211_send_setup(ic, ni, wh, 
-		IEEE80211_FC0_TYPE_MGT | type,
-		ic->ic_myaddr, ni->ni_macaddr, ni->ni_bssid);
+	ieee80211_send_setup(ic, ni, wh, IEEE80211_FC0_TYPE_MGT | type,
+	ic->ic_myaddr, ni->ni_macaddr, ni->ni_bssid);
+
 	if ((m->m_flags & M_LINK0) != 0 && ni->ni_challenge != NULL) {
 		m->m_flags &= ~M_LINK0;
 		IEEE80211_DPRINTF(ic, IEEE80211_MSG_AUTH,
@@ -197,6 +203,7 @@ ieee80211_mgmt_output(struct ieee80211co
 			ether_sprintf(wh->i_addr1), __func__);
 		wh->i_fc[1] |= IEEE80211_FC1_WEP;
 	}
+
 #ifdef IEEE80211_DEBUG
 	/* avoid printing too many frames */
 	if ((ieee80211_msg_debug(ic) && doprint(ic, type)) ||
@@ -209,6 +216,7 @@ ieee80211_mgmt_output(struct ieee80211co
 		ieee80211_chan2ieee(ic, ic->ic_curchan));
 	}
 #endif
+
 	IEEE80211_NODE_STAT(ni, tx_mgmt);
 	IF_ENQUEUE(>ic_mgtq, m);
 	if (timer) {
@@ -247,13 +255,17 @@ ieee80211_send_nulldata(struct ieee80211
 	M_SETCTX(m, ni);
 
 	wh = mtod(m, struct ieee80211_frame *);
+
 	ieee80211_send_setup(ic, ni, wh,
-		IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_NODATA,
-		ic->ic_myaddr, ni->ni_macaddr, ni->ni_bssid);
+	IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_NODATA,
+	ic->ic_myaddr, ni->ni_macaddr, ni->ni_bssid);
+
 	/* NB: power management bit is never sent by an AP */
 	if ((ni->ni_flags & IEEE80211_NODE_PWR_MGT) &&
-	ic->ic_opmode != IEEE80211_M_HOSTAP)
+	ic->ic_opmode != IEEE80211_M_HOSTAP) {
 		wh->i_fc[1] |= IEEE80211_FC1_PWR_MGT;
+	}
+
 	m->m_len = m->m_pkthdr.len = sizeof(struct ieee80211_frame);
 
 	IEEE80211_NODE_STAT(ni, tx_data);
@@ -277,7 +289,8 @@ ieee80211_send_nulldata(struct ieee80211
  * applied.
  */
 int
-ieee80211_classify(struct ieee80211com *ic, struct mbuf *m, struct ieee80211_node *ni)
+ieee80211_classify(struct ieee80211com *ic, struct mbuf *m,
+struct ieee80211_node 

CVS commit: src/sys/net80211

2018-01-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jan 18 13:24:01 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_output.c

Log Message:
Several changes:

 * Make the code more readable. In particular, declare variables as const
   along the way.

 * Explain what we're doing in ieee80211_send_mgmt(). The
   IEEE80211_FC0_SUBTYPE_PROBE_RESP case has some inconsistencies, but
   they are not inherently wrong so I'm not changing that.

 * When sending IEEE80211_FC0_SUBTYPE_REASSOC_RESP frames, make sure to
   zero out the 'association ID', otherwise two bytes are leaked.

 * Fix a possible memory leak in ieee80211_send_probereq().


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/net80211/ieee80211_output.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-17 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Jan 17 17:41:38 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_crypto.c ieee80211_crypto_ccmp.c
ieee80211_crypto_tkip.c ieee80211_crypto_wep.c

Log Message:
Style, and fix two pretty bad mistakes in the crypto functions:

 * They call M_PREPEND, but don't pass the updated pointer back to the
   caller.

 * They use memmove on the mbuf data, but they don't ensure that the
   area they touch is contiguous.

This fix is not complete, ieee80211_crypto_encap too needs to pass back
the updated pointer. This will be done in another commit.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/net80211/ieee80211_crypto.c
cvs rdiff -u -r1.11 -r1.12 src/sys/net80211/ieee80211_crypto_ccmp.c
cvs rdiff -u -r1.12 -r1.13 src/sys/net80211/ieee80211_crypto_tkip.c
cvs rdiff -u -r1.9 -r1.10 src/sys/net80211/ieee80211_crypto_wep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_crypto.c
diff -u src/sys/net80211/ieee80211_crypto.c:1.19 src/sys/net80211/ieee80211_crypto.c:1.20
--- src/sys/net80211/ieee80211_crypto.c:1.19	Tue Jan 16 09:04:30 2018
+++ src/sys/net80211/ieee80211_crypto.c	Wed Jan 17 17:41:38 2018
@@ -1,5 +1,6 @@
-/*	$NetBSD: ieee80211_crypto.c,v 1.19 2018/01/16 09:04:30 maxv Exp $	*/
-/*-
+/*	$NetBSD: ieee80211_crypto.c,v 1.20 2018/01/17 17:41:38 maxv Exp $	*/
+
+/*
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
  * All rights reserved.
@@ -36,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto.c,v 1.12 2005/08/08 18:46:35 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto.c,v 1.19 2018/01/16 09:04:30 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto.c,v 1.20 2018/01/17 17:41:38 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -68,22 +69,22 @@ __KERNEL_RCSID(0, "$NetBSD: ieee80211_cr
 /*
  * Table of registered cipher modules.
  */
-static	const struct ieee80211_cipher *ciphers[IEEE80211_CIPHER_MAX];
+static const struct ieee80211_cipher *ciphers[IEEE80211_CIPHER_MAX];
 
 #ifdef INET
 #include  
 #include 
 #endif
 
-static	int _ieee80211_crypto_delkey(struct ieee80211com *,
-		struct ieee80211_key *);
+static int _ieee80211_crypto_delkey(struct ieee80211com *,
+struct ieee80211_key *);
 
 /*
  * Default "null" key management routines.
  */
 static int
 null_key_alloc(struct ieee80211com *ic, const struct ieee80211_key *k,
-	ieee80211_keyix *keyix, ieee80211_keyix *rxkeyix)
+ieee80211_keyix *keyix, ieee80211_keyix *rxkeyix)
 {
 	if (!(>ic_nw_keys[0] <= k &&
 	 k < >ic_nw_keys[IEEE80211_WEP_NKID])) {
@@ -106,20 +107,25 @@ null_key_alloc(struct ieee80211com *ic, 
 	*rxkeyix = IEEE80211_KEYIX_NONE;	/* XXX maybe *keyix? */
 	return 1;
 }
+
 static int
-null_key_delete(struct ieee80211com *ic,
-const struct ieee80211_key *k)
+null_key_delete(struct ieee80211com *ic, const struct ieee80211_key *k)
 {
 	return 1;
 }
-static 	int
-null_key_set(struct ieee80211com *ic,
-const struct ieee80211_key *k,
+
+static int
+null_key_set(struct ieee80211com *ic, const struct ieee80211_key *k,
 const u_int8_t mac[IEEE80211_ADDR_LEN])
 {
 	return 1;
 }
-static void null_key_update(struct ieee80211com *ic) {}
+
+static void
+null_key_update(struct ieee80211com *ic)
+{
+	;
+}
 
 /*
  * Write-arounds for common operations.
@@ -134,23 +140,21 @@ cipher_detach(struct ieee80211_key *key)
  * Wrappers for driver key management methods.
  */
 static __inline int
-dev_key_alloc(struct ieee80211com *ic,
-	const struct ieee80211_key *key,
-	ieee80211_keyix *keyix, ieee80211_keyix *rxkeyix)
+dev_key_alloc(struct ieee80211com *ic, const struct ieee80211_key *key,
+ieee80211_keyix *keyix, ieee80211_keyix *rxkeyix)
 {
 	return ic->ic_crypto.cs_key_alloc(ic, key, keyix, rxkeyix);
 }
 
 static __inline int
-dev_key_delete(struct ieee80211com *ic,
-	const struct ieee80211_key *key)
+dev_key_delete(struct ieee80211com *ic, const struct ieee80211_key *key)
 {
 	return ic->ic_crypto.cs_key_delete(ic, key);
 }
 
 static __inline int
 dev_key_set(struct ieee80211com *ic, const struct ieee80211_key *key,
-	const u_int8_t mac[IEEE80211_ADDR_LEN])
+const u_int8_t mac[IEEE80211_ADDR_LEN])
 {
 	return ic->ic_crypto.cs_key_set(ic, key, mac);
 }
@@ -260,8 +264,8 @@ static const char *cipher_modnames[] = {
  *	ieee80211_key_update_end(ic);
  */
 int
-ieee80211_crypto_newkey(struct ieee80211com *ic,
-	int cipher, int flags, struct ieee80211_key *key)
+ieee80211_crypto_newkey(struct ieee80211com *ic, int cipher, int flags,
+struct ieee80211_key *key)
 {
 #define	N(a)	(sizeof(a) / sizeof(a[0]))
 	const struct ieee80211_cipher *cip;
@@ -279,6 +283,7 @@ ieee80211_crypto_newkey(struct ieee80211
 		return 0;
 	}
 	cip = ciphers[cipher];
+
 	if (cip == NULL) {
 		/*
 		 * Auto-load cipher module if we have a 

CVS commit: src/sys/net80211

2018-01-17 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Jan 17 17:41:38 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_crypto.c ieee80211_crypto_ccmp.c
ieee80211_crypto_tkip.c ieee80211_crypto_wep.c

Log Message:
Style, and fix two pretty bad mistakes in the crypto functions:

 * They call M_PREPEND, but don't pass the updated pointer back to the
   caller.

 * They use memmove on the mbuf data, but they don't ensure that the
   area they touch is contiguous.

This fix is not complete, ieee80211_crypto_encap too needs to pass back
the updated pointer. This will be done in another commit.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/net80211/ieee80211_crypto.c
cvs rdiff -u -r1.11 -r1.12 src/sys/net80211/ieee80211_crypto_ccmp.c
cvs rdiff -u -r1.12 -r1.13 src/sys/net80211/ieee80211_crypto_tkip.c
cvs rdiff -u -r1.9 -r1.10 src/sys/net80211/ieee80211_crypto_wep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-17 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Jan 17 16:03:16 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Several changes:

 * Style in several places, to make the code more readable or easier to
   understand.

 * Instead of checking m->m_pkthdr.len, check m->m_len. m_pkthdr.len is
   the total size of the packet, not the size of the current mbuf (which
   may be smaller).

 * Add a missing length check when handling QoS frames.

 * Cast the lengths passed in IEEE80211_VERIFY_LENGTH to size_t.

 * Remove the length check on scan.sp_xrates, that I added yesterday.
   xrates gets silently truncated in ieee80211_setup_rates().

 * Fix several buffer overflows in the parsers of the MANAGEMENT frames.


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-17 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Jan 17 16:03:16 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Several changes:

 * Style in several places, to make the code more readable or easier to
   understand.

 * Instead of checking m->m_pkthdr.len, check m->m_len. m_pkthdr.len is
   the total size of the packet, not the size of the current mbuf (which
   may be smaller).

 * Add a missing length check when handling QoS frames.

 * Cast the lengths passed in IEEE80211_VERIFY_LENGTH to size_t.

 * Remove the length check on scan.sp_xrates, that I added yesterday.
   xrates gets silently truncated in ieee80211_setup_rates().

 * Fix several buffer overflows in the parsers of the MANAGEMENT frames.


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.108 src/sys/net80211/ieee80211_input.c:1.109
--- src/sys/net80211/ieee80211_input.c:1.108	Tue Jan 16 18:53:32 2018
+++ src/sys/net80211/ieee80211_input.c	Wed Jan 17 16:03:16 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.108 2018/01/16 18:53:32 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.109 2018/01/17 16:03:16 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.108 2018/01/16 18:53:32 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.109 2018/01/17 16:03:16 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -354,8 +354,7 @@ ieee80211_input_data(struct ieee80211com
 		 * any non-PAE frames received without encryption.
 		 */
 		if ((ic->ic_flags & IEEE80211_F_DROPUNENC) &&
-		key == NULL &&
-		eh->ether_type != htons(ETHERTYPE_PAE)) {
+		key == NULL && eh->ether_type != htons(ETHERTYPE_PAE)) {
 			/*
 			 * Drop unencrypted frames.
 			 */
@@ -407,10 +406,9 @@ ieee80211_input_management(struct ieee80
 		ic->ic_stats.is_rx_wrongdir++;
 		goto err;
 	}
-	if (m->m_pkthdr.len < sizeof(struct ieee80211_frame)) {
-		IEEE80211_DISCARD_MAC(ic, IEEE80211_MSG_ANY,
-		ni->ni_macaddr, "mgt", "too short: len %u",
-		m->m_pkthdr.len);
+	if (m->m_len < sizeof(struct ieee80211_frame)) {
+		IEEE80211_DISCARD_MAC(ic, IEEE80211_MSG_ANY, ni->ni_macaddr,
+		"mgt", "too short: len %u", m->m_len);
 		ic->ic_stats.is_rx_tooshort++;
 		goto out;
 	}
@@ -542,10 +540,10 @@ ieee80211_input(struct ieee80211com *ic,
 	if (ic->ic_opmode == IEEE80211_M_MONITOR)
 		goto out;
 
-	if (m->m_pkthdr.len < sizeof(struct ieee80211_frame_min)) {
+	if (m->m_len < sizeof(struct ieee80211_frame_min)) {
 		IEEE80211_DISCARD_MAC(ic, IEEE80211_MSG_ANY,
 		ni->ni_macaddr, NULL,
-		"too short (1): len %u", m->m_pkthdr.len);
+		"too short (1): len %u", m->m_len);
 		ic->ic_stats.is_rx_tooshort++;
 		goto out;
 	}
@@ -607,11 +605,11 @@ ieee80211_input(struct ieee80211com *ic,
 			else if (type == IEEE80211_FC0_TYPE_CTL)
 bssid = wh->i_addr1;
 			else {
-if (m->m_pkthdr.len < sizeof(struct ieee80211_frame)) {
+if (m->m_len < sizeof(struct ieee80211_frame)) {
 	IEEE80211_DISCARD_MAC(ic,
 	IEEE80211_MSG_ANY, ni->ni_macaddr,
 	NULL, "too short (2): len %u",
-	m->m_pkthdr.len);
+	m->m_len);
 	ic->ic_stats.is_rx_tooshort++;
 	goto out;
 }
@@ -674,7 +672,14 @@ ieee80211_input(struct ieee80211com *ic,
 			if (ieee80211_has_qos(wh)) {
 struct ieee80211_qosframe *qosf;
 
-/* XXX mbuf length check */
+if (m->m_len < sizeof(struct ieee80211_qosframe)) {
+	IEEE80211_DISCARD_MAC(ic,
+	IEEE80211_MSG_ANY,
+	ni->ni_macaddr, NULL,
+	"too short (1): len %u", m->m_len);
+	ic->ic_stats.is_rx_tooshort++;
+	goto out;
+}
 qosf = mtod(m, struct ieee80211_qosframe *);
 
 tid = qosf->i_qos[0] & IEEE80211_QOS_TID;
@@ -1089,6 +1094,7 @@ ieee80211_auth_open(struct ieee80211com 
 		ni->ni_macaddr, "open auth",
 		"bad sta auth mode %u", ni->ni_authmode);
 		ic->ic_stats.is_rx_bad_auth++;	/* XXX */
+
 		if (ic->ic_opmode == IEEE80211_M_HOSTAP) {
 			/* XXX hack to workaround calling convention */
 			ieee80211_send_error(ic, ni, wh->i_addr2,
@@ -1097,6 +1103,7 @@ ieee80211_auth_open(struct ieee80211com 
 		}
 		return;
 	}
+
 	switch (ic->ic_opmode) {
 	case IEEE80211_M_IBSS:
 	case IEEE80211_M_AHDEMO:
@@ -1114,13 +1121,16 @@ ieee80211_auth_open(struct ieee80211com 
 			ic->ic_stats.is_rx_bad_auth++;
 			return;
 		}
+
 		/* always accept open authentication requests */
 		if (ni == ic->ic_bss) {
 			ni = ieee80211_dup_bss(>ic_sta, wh->i_addr2);
 			if (ni == NULL)
 return;
-		} else if ((ni->ni_flags & IEEE80211_NODE_AREF) == 0)
-			(void) 

Re: CVS commit: src/sys/net80211

2018-01-17 Thread Roy Marples

On 17/01/2018 01:57, m...@netbsd.org wrote:

On Tue, Jan 16, 2018 at 06:35:08PM -0600, David Young wrote:

I have said it before, that I do think the "concept architecture" of
802.11 VAP is rather broken, but let's be honest: nobody, especially not
I, have had the time in 10+ years to independently implement anything
comparable. *shrug*


What is your issue with VAPs?


My main beef with early VAP implementations is that the user had to 
create a VAP from the physical interface/radio just to get client 
association working.


Thankfully those days have now passed it seems.

But frankly it's just easier to get another interface/radio.

Roy


Re: CVS commit: src/sys/net80211

2018-01-17 Thread Maxime Villard

Le 17/01/2018 à 01:35, David Young a écrit :

On Tue, Jan 16, 2018 at 08:39:29AM +, Maxime Villard wrote:

Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 08:39:29 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Split ieee80211_input into three sub-functions, that parse received
packets depending on their type:

DATA   -> ieee80211_input_data
MANAGEMENT -> ieee80211_input_management
CONTROL-> ieee80211_input_control

No real functional change, but makes the code much clearer.


IMO, changes like this are important and overdue, however, do keep in
mind the provenance of this code: NetBSD -> FreeBSD.


I know.


Maybe you have written off ever re-synching with FreeBSD?  If so, do
you have a plan for integrating useful features like virtual stations
independently of their code?


No, I'm not planning on re-synching with FreeBSD. Their code has very
significantly changed, and we're miles away from that. I'm just clarifying
the code, fixing bugs along the way, without touching the "features"
themselves.

Maxime


Re: CVS commit: src/sys/net80211

2018-01-16 Thread maya
On Tue, Jan 16, 2018 at 06:35:08PM -0600, David Young wrote:
> I have said it before, that I do think the "concept architecture" of
> 802.11 VAP is rather broken, but let's be honest: nobody, especially not
> I, have had the time in 10+ years to independently implement anything
> comparable. *shrug*

What is your issue with VAPs?


Re: CVS commit: src/sys/net80211

2018-01-16 Thread David Young
On Tue, Jan 16, 2018 at 08:39:29AM +, Maxime Villard wrote:
> Module Name:  src
> Committed By: maxv
> Date: Tue Jan 16 08:39:29 UTC 2018
> 
> Modified Files:
>   src/sys/net80211: ieee80211_input.c
> 
> Log Message:
> Split ieee80211_input into three sub-functions, that parse received
> packets depending on their type:
> 
>   DATA   -> ieee80211_input_data
>   MANAGEMENT -> ieee80211_input_management
>   CONTROL-> ieee80211_input_control
> 
> No real functional change, but makes the code much clearer.

IMO, changes like this are important and overdue, however, do keep in
mind the provenance of this code: NetBSD -> FreeBSD.

Maybe you have written off ever re-synching with FreeBSD?  If so, do
you have a plan for integrating useful features like virtual stations
independently of their code?

I have said it before, that I do think the "concept architecture" of
802.11 VAP is rather broken, but let's be honest: nobody, especially not
I, have had the time in 10+ years to independently implement anything
comparable. *shrug*

Dave

-- 
David Young
dyo...@pobox.comUrbana, IL(217) 721-9981


CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 18:53:32 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c ieee80211_node.c

Log Message:
Various fixes: style, remove tiring XXXs, and prevent integer overflow in
ieee80211_setup_rates (normally it already can't happen, because I added a
length check on xrates in ieee80211_recv_mgmt_beacon).


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/sys/net80211/ieee80211_input.c
cvs rdiff -u -r1.73 -r1.74 src/sys/net80211/ieee80211_node.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.107 src/sys/net80211/ieee80211_input.c:1.108
--- src/sys/net80211/ieee80211_input.c:1.107	Tue Jan 16 18:42:43 2018
+++ src/sys/net80211/ieee80211_input.c	Tue Jan 16 18:53:32 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.107 2018/01/16 18:42:43 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.108 2018/01/16 18:53:32 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.107 2018/01/16 18:42:43 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.108 2018/01/16 18:53:32 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -1038,22 +1038,28 @@ ieee80211_decap(struct ieee80211com *ic,
  * Install received rate set information in the node's state block.
  */
 int
-ieee80211_setup_rates(struct ieee80211_node *ni,
-	const u_int8_t *rates, const u_int8_t *xrates, int flags)
+ieee80211_setup_rates(struct ieee80211_node *ni, const u_int8_t *rates,
+const u_int8_t *xrates, int flags)
 {
 	struct ieee80211com *ic = ni->ni_ic;
 	struct ieee80211_rateset *rs = >ni_rates;
 
 	memset(rs, 0, sizeof(*rs));
+
 	rs->rs_nrates = rates[1];
 	memcpy(rs->rs_rates, rates + 2, rs->rs_nrates);
+
 	if (xrates != NULL) {
 		u_int8_t nxrates;
+		size_t totalrate;
+
 		/*
 		 * Tack on 11g extended supported rate element.
 		 */
 		nxrates = xrates[1];
-		if (rs->rs_nrates + nxrates > IEEE80211_RATE_MAXSIZE) {
+		totalrate = (size_t)rs->rs_nrates + (size_t)nxrates;
+
+		if (totalrate > IEEE80211_RATE_MAXSIZE) {
 			IEEE80211_DEBUGVAR(char ebuf[3 * ETHER_ADDR_LEN]);
 			nxrates = IEEE80211_RATE_MAXSIZE - rs->rs_nrates;
 			IEEE80211_DPRINTF(ic, IEEE80211_MSG_XRATE,
@@ -1063,9 +1069,11 @@ ieee80211_setup_rates(struct ieee80211_n
 			 nxrates, xrates[1]);
 			ic->ic_stats.is_rx_rstoobig++;
 		}
+
 		memcpy(rs->rs_rates + rs->rs_nrates, xrates+2, nxrates);
 		rs->rs_nrates += nxrates;
 	}
+
 	return ieee80211_fix_rate(ni, flags);
 }
 
@@ -1869,11 +1877,14 @@ ieee80211_parse_wmeparams(struct ieee802
 		wh, "WME", "too short, len %u", len);
 		return -1;
 	}
+
 	qosinfo = frm[offsetof(struct ieee80211_wme_param, param_qosInfo)];
 	qosinfo &= WME_QOSINFO_COUNT;
+
 	/* XXX do proper check for wraparound */
 	if (qosinfo == wme->wme_wmeChanParams.cap_info)
 		return 0;
+
 	frm += offsetof(struct ieee80211_wme_param, params_acParams);
 	for (i = 0; i < WME_NUM_AC; i++) {
 		struct wmeParams *wmep =
@@ -1886,6 +1897,7 @@ ieee80211_parse_wmeparams(struct ieee802
 		wmep->wmep_txopLimit = LE_READ_2(frm+2);
 		frm += 4;
 	}
+
 	wme->wme_wmeChanParams.cap_info = qosinfo;
 	return 1;
 #undef MS
@@ -2191,7 +2203,7 @@ ieee80211_recv_mgmt_beacon(struct ieee80
 	 * Count frame now that we know it's to be processed.
 	 */
 	if (subtype == IEEE80211_FC0_SUBTYPE_BEACON) {
-		ic->ic_stats.is_rx_beacon++;		/* XXX remove */
+		ic->ic_stats.is_rx_beacon++;
 		IEEE80211_NODE_STAT(ni, rx_beacons);
 	} else {
 		IEEE80211_NODE_STAT(ni, rx_proberesp);
@@ -2219,7 +2231,6 @@ ieee80211_recv_mgmt_beacon(struct ieee80
 			else
 ic->ic_flags &= ~IEEE80211_F_USEPROT;
 			ni->ni_erp = scan.sp_erp;
-			/* XXX statistic */
 		}
 
 		if ((ni->ni_capinfo ^ scan.sp_capinfo) & IEEE80211_CAPINFO_SHORT_SLOTTIME) {
@@ -2237,7 +2248,6 @@ ieee80211_recv_mgmt_beacon(struct ieee80
 			ic->ic_curmode == IEEE80211_MODE_11A ||
 			(ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME));
 			ni->ni_capinfo = scan.sp_capinfo;
-			/* XXX statistic */
 		}
 
 		if (scan.sp_wme != NULL && (ni->ni_flags & IEEE80211_NODE_QOS) &&

Index: src/sys/net80211/ieee80211_node.c
diff -u src/sys/net80211/ieee80211_node.c:1.73 src/sys/net80211/ieee80211_node.c:1.74
--- src/sys/net80211/ieee80211_node.c:1.73	Tue Jan 16 18:42:43 2018
+++ src/sys/net80211/ieee80211_node.c	Tue Jan 16 18:53:32 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_node.c,v 1.73 2018/01/16 18:42:43 maxv Exp $	*/
+/*	$NetBSD: ieee80211_node.c,v 1.74 2018/01/16 18:53:32 maxv Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_node.c,v 1.65 2005/08/13 

CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 18:53:32 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c ieee80211_node.c

Log Message:
Various fixes: style, remove tiring XXXs, and prevent integer overflow in
ieee80211_setup_rates (normally it already can't happen, because I added a
length check on xrates in ieee80211_recv_mgmt_beacon).


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/sys/net80211/ieee80211_input.c
cvs rdiff -u -r1.73 -r1.74 src/sys/net80211/ieee80211_node.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 16:54:54 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Add comments about the length checks, and check xrates.


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 16:54:54 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Add comments about the length checks, and check xrates.


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.105 src/sys/net80211/ieee80211_input.c:1.106
--- src/sys/net80211/ieee80211_input.c:1.105	Tue Jan 16 16:31:37 2018
+++ src/sys/net80211/ieee80211_input.c	Tue Jan 16 16:54:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.105 2018/01/16 16:31:37 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.106 2018/01/16 16:54:54 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.105 2018/01/16 16:31:37 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.106 2018/01/16 16:54:54 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -2057,12 +2057,15 @@ ieee80211_recv_mgmt_beacon(struct ieee80
 
 		switch (*frm) {
 		case IEEE80211_ELEMID_SSID:
+			/* no length check needed */
 			scan.ssid = frm;
 			break;
 		case IEEE80211_ELEMID_RATES:
+			/* no length check needed */
 			scan.rates = frm;
 			break;
 		case IEEE80211_ELEMID_COUNTRY:
+			/* XXX: we don't do anything with this? */
 			scan.country = frm;
 			break;
 		case IEEE80211_ELEMID_FHPARMS:
@@ -2091,6 +2094,12 @@ ieee80211_recv_mgmt_beacon(struct ieee80
 		case IEEE80211_ELEMID_IBSSPARMS:
 			break;
 		case IEEE80211_ELEMID_XRATES:
+			if (frm[1] > IEEE80211_RATE_MAXSIZE) {
+IEEE80211_DISCARD_IE(ic, IEEE80211_MSG_ELEMID,
+wh, "XRATE", "bad len %u", frm[1]);
+ic->ic_stats.is_rx_elem_toobig++;
+break;
+			}
 			scan.xrates = frm;
 			break;
 		case IEEE80211_ELEMID_ERP:
@@ -2103,9 +2112,11 @@ ieee80211_recv_mgmt_beacon(struct ieee80
 			scan.erp = frm[2];
 			break;
 		case IEEE80211_ELEMID_RSN:
+			/* no length check needed */
 			scan.wpa = frm;
 			break;
 		case IEEE80211_ELEMID_VENDOR:
+			/* no length check needed */
 			if (iswpaoui(frm))
 scan.wpa = frm;
 			else if (iswmeparam(frm) || iswmeinfo(frm))



CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 16:31:38 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Gather related code.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.104 src/sys/net80211/ieee80211_input.c:1.105
--- src/sys/net80211/ieee80211_input.c:1.104	Tue Jan 16 16:20:57 2018
+++ src/sys/net80211/ieee80211_input.c	Tue Jan 16 16:31:37 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.104 2018/01/16 16:20:57 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.105 2018/01/16 16:31:37 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.104 2018/01/16 16:20:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.105 2018/01/16 16:31:37 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -1446,37 +1446,6 @@ bad:
 #endif /* !IEEE80211_NO_HOSTAP */
 }
 
-/* Verify the existence and length of __elem or get out. */
-#define IEEE80211_VERIFY_ELEMENT(__elem, __maxlen) do {			\
-	if ((__elem) == NULL) {		\
-		IEEE80211_DISCARD(ic, IEEE80211_MSG_ELEMID,		\
-		wh, ieee80211_mgt_subtype_name[subtype >>		\
-			IEEE80211_FC0_SUBTYPE_SHIFT],			\
-		"%s", "no " #__elem );\
-		ic->ic_stats.is_rx_elem_missing++;			\
-		return;			\
-	}\
-	if ((__elem)[1] > (__maxlen)) {	\
-		IEEE80211_DISCARD(ic, IEEE80211_MSG_ELEMID,		\
-		wh, ieee80211_mgt_subtype_name[subtype >>		\
-			IEEE80211_FC0_SUBTYPE_SHIFT],			\
-		"bad " #__elem " len %d", (__elem)[1]);		\
-		ic->ic_stats.is_rx_elem_toobig++;			\
-		return;			\
-	}\
-} while (0)
-
-#define	IEEE80211_VERIFY_LENGTH(_len, _minlen) do {			\
-	if ((_len) < (_minlen)) {	\
-		IEEE80211_DISCARD(ic, IEEE80211_MSG_ELEMID,		\
-		wh, ieee80211_mgt_subtype_name[subtype >>		\
-			IEEE80211_FC0_SUBTYPE_SHIFT],			\
-		"%s", "ie too short");\
-		ic->ic_stats.is_rx_elem_toosmall++;			\
-		return;			\
-	}\
-} while (0)
-
 #ifdef IEEE80211_DEBUG
 static void
 ieee80211_ssid_mismatch(struct ieee80211com *ic, const char *tag,
@@ -2003,6 +1972,36 @@ ieee80211_update_adhoc_node(struct ieee8
 
 /* -- */
 
+#define IEEE80211_VERIFY_ELEMENT(__elem, __maxlen) do {			\
+	if ((__elem) == NULL) {		\
+		IEEE80211_DISCARD(ic, IEEE80211_MSG_ELEMID,		\
+		wh, ieee80211_mgt_subtype_name[subtype >>		\
+			IEEE80211_FC0_SUBTYPE_SHIFT],			\
+		"%s", "no " #__elem );\
+		ic->ic_stats.is_rx_elem_missing++;			\
+		return;			\
+	}\
+	if ((__elem)[1] > (__maxlen)) {	\
+		IEEE80211_DISCARD(ic, IEEE80211_MSG_ELEMID,		\
+		wh, ieee80211_mgt_subtype_name[subtype >>		\
+			IEEE80211_FC0_SUBTYPE_SHIFT],			\
+		"bad " #__elem " len %d", (__elem)[1]);		\
+		ic->ic_stats.is_rx_elem_toobig++;			\
+		return;			\
+	}\
+} while (0)
+
+#define	IEEE80211_VERIFY_LENGTH(_len, _minlen) do {			\
+	if ((_len) < (_minlen)) {	\
+		IEEE80211_DISCARD(ic, IEEE80211_MSG_ELEMID,		\
+		wh, ieee80211_mgt_subtype_name[subtype >>		\
+			IEEE80211_FC0_SUBTYPE_SHIFT],			\
+		"%s", "ie too short");\
+		ic->ic_stats.is_rx_elem_toosmall++;			\
+		return;			\
+	}\
+} while (0)
+
 static void
 ieee80211_recv_mgmt_beacon(struct ieee80211com *ic, struct mbuf *m0,
 struct ieee80211_node *ni, int subtype, int rssi, u_int32_t rstamp)
@@ -2948,6 +2947,10 @@ ieee80211_recv_mgmt_disassoc(struct ieee
 	}
 }
 
+#undef ISREASSOC
+#undef IEEE80211_VERIFY_LENGTH
+#undef IEEE80211_VERIFY_ELEMENT
+
 /* -- */
 
 void
@@ -2998,10 +3001,6 @@ ieee80211_recv_mgmt(struct ieee80211com 
 	}
 }
 
-#undef ISREASSOC
-#undef IEEE80211_VERIFY_LENGTH
-#undef IEEE80211_VERIFY_ELEMENT
-
 #ifndef IEEE80211_NO_HOSTAP
 /*
  * Handle station power-save state change.



CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 16:31:38 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Gather related code.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 16:20:57 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Style on the new functions.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 16:20:57 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Style on the new functions.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.103 src/sys/net80211/ieee80211_input.c:1.104
--- src/sys/net80211/ieee80211_input.c:1.103	Tue Jan 16 16:09:30 2018
+++ src/sys/net80211/ieee80211_input.c	Tue Jan 16 16:20:57 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.103 2018/01/16 16:09:30 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.104 2018/01/16 16:20:57 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.103 2018/01/16 16:09:30 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.104 2018/01/16 16:20:57 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -2096,9 +2096,8 @@ ieee80211_recv_mgmt_beacon(struct ieee80
 			break;
 		case IEEE80211_ELEMID_ERP:
 			if (frm[1] != 1) {
-IEEE80211_DISCARD_IE(ic,
-IEEE80211_MSG_ELEMID, wh, "ERP",
-"bad len %u", frm[1]);
+IEEE80211_DISCARD_IE(ic, IEEE80211_MSG_ELEMID,
+wh, "ERP", "bad len %u", frm[1]);
 ic->ic_stats.is_rx_elem_toobig++;
 break;
 			}
@@ -2116,8 +2115,7 @@ ieee80211_recv_mgmt_beacon(struct ieee80
 			break;
 		default:
 			IEEE80211_DISCARD_IE(ic, IEEE80211_MSG_ELEMID,
-			wh, "unhandled",
-			"id %u, len %u", *frm, frm[1]);
+			wh, "unhandled", "id %u, len %u", *frm, frm[1]);
 			ic->ic_stats.is_rx_elem_unknown++;
 			break;
 		}
@@ -2141,6 +2139,7 @@ ieee80211_recv_mgmt_beacon(struct ieee80
 		ic->ic_stats.is_rx_badchan++;
 		return;
 	}
+
 	if (scan.chan != scan.bchan &&
 	ic->ic_phytype != IEEE80211_T_FH) {
 		/*
@@ -2161,6 +2160,7 @@ ieee80211_recv_mgmt_beacon(struct ieee80
 		ic->ic_stats.is_rx_chanmismatch++;
 		return;
 	}
+
 	if (!(IEEE80211_BINTVAL_MIN <= scan.bintval &&
 	  scan.bintval <= IEEE80211_BINTVAL_MAX)) {
 		IEEE80211_DISCARD(ic,
@@ -2176,27 +2176,28 @@ ieee80211_recv_mgmt_beacon(struct ieee80
 		ni = ieee80211_refine_node_for_beacon(ic, ni,
 		>ic_channels[scan.chan], scan.ssid);
 	}
+
 	/*
 	 * Count frame now that we know it's to be processed.
 	 */
 	if (subtype == IEEE80211_FC0_SUBTYPE_BEACON) {
 		ic->ic_stats.is_rx_beacon++;		/* XXX remove */
 		IEEE80211_NODE_STAT(ni, rx_beacons);
-	} else
+	} else {
 		IEEE80211_NODE_STAT(ni, rx_proberesp);
+	}
 
 	/*
 	 * When operating in station mode, check for state updates.
 	 * Be careful to ignore beacons received while doing a
 	 * background scan.  We consider only 11g/WMM stuff right now.
 	 */
-	if (ic->ic_opmode == IEEE80211_M_STA &&
-	ni->ni_associd != 0 &&
+	if (ic->ic_opmode == IEEE80211_M_STA && ni->ni_associd != 0 &&
 	((ic->ic_flags & IEEE80211_F_SCAN) == 0 ||
 	 IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_bssid))) {
 		/* record tsf of last beacon */
-		memcpy(ni->ni_tstamp.data, scan.tstamp,
-			sizeof(ni->ni_tstamp));
+		memcpy(ni->ni_tstamp.data, scan.tstamp, sizeof(ni->ni_tstamp));
+
 		if (ni->ni_erp != scan.erp) {
 			IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC,
 			"[%s] erp change: was 0x%x, now 0x%x\n",
@@ -2210,6 +2211,7 @@ ieee80211_recv_mgmt_beacon(struct ieee80
 			ni->ni_erp = scan.erp;
 			/* XXX statistic */
 		}
+
 		if ((ni->ni_capinfo ^ scan.capinfo) & IEEE80211_CAPINFO_SHORT_SLOTTIME) {
 			IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC,
 			"[%s] capabilities change: before 0x%x,"
@@ -,25 +2224,30 @@ ieee80211_recv_mgmt_beacon(struct ieee80
 			 * change dynamically
 			 */
 			ieee80211_set_shortslottime(ic,
-ic->ic_curmode == IEEE80211_MODE_11A ||
-(ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME));
+			ic->ic_curmode == IEEE80211_MODE_11A ||
+			(ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME));
 			ni->ni_capinfo = scan.capinfo;
 			/* XXX statistic */
 		}
-		if (scan.wme != NULL &&
-		(ni->ni_flags & IEEE80211_NODE_QOS) &&
-		ieee80211_parse_wmeparams(ic, scan.wme, wh) > 0)
+
+		if (scan.wme != NULL && (ni->ni_flags & IEEE80211_NODE_QOS) &&
+		ieee80211_parse_wmeparams(ic, scan.wme, wh) > 0) {
 			ieee80211_wme_updateparams(ic);
+		}
+
 		if (scan.tim != NULL) {
 			struct ieee80211_tim_ie *ie =
-			(struct ieee80211_tim_ie *) scan.tim;
+			(struct ieee80211_tim_ie *)scan.tim;
 
 			ni->ni_dtim_count = ie->tim_count;
 			ni->ni_dtim_period = ie->tim_period;
 		}
-		if (ic->ic_flags & IEEE80211_F_SCAN)
-			ieee80211_add_scan(ic, , wh,
-subtype, rssi, rstamp);
+
+		if (ic->ic_flags & IEEE80211_F_SCAN) {
+			ieee80211_add_scan(ic, , wh, subtype, rssi,
+			   

CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 16:09:30 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Introduce ieee80211_recv_mgmt_disassoc.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.102 src/sys/net80211/ieee80211_input.c:1.103
--- src/sys/net80211/ieee80211_input.c:1.102	Tue Jan 16 16:04:16 2018
+++ src/sys/net80211/ieee80211_input.c	Tue Jan 16 16:09:30 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.102 2018/01/16 16:04:16 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.103 2018/01/16 16:09:30 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.102 2018/01/16 16:04:16 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.103 2018/01/16 16:09:30 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -2855,10 +2855,8 @@ ieee80211_recv_mgmt_deauth(struct ieee80
 	}
 }
 
-/* -- */
-
-void
-ieee80211_recv_mgmt(struct ieee80211com *ic, struct mbuf *m0,
+static void
+ieee80211_recv_mgmt_disassoc(struct ieee80211com *ic, struct mbuf *m0,
 struct ieee80211_node *ni, int subtype, int rssi, u_int32_t rstamp)
 {
 	struct ieee80211_frame *wh;
@@ -2869,6 +2867,59 @@ ieee80211_recv_mgmt(struct ieee80211com 
 	frm = (u_int8_t *)(wh + 1);
 	efrm = mtod(m0, u_int8_t *) + m0->m_len;
 
+	u_int16_t reason;
+
+	if (ic->ic_state != IEEE80211_S_RUN &&
+	ic->ic_state != IEEE80211_S_ASSOC &&
+	ic->ic_state != IEEE80211_S_AUTH) {
+		ic->ic_stats.is_rx_mgtdiscard++;
+		return;
+	}
+	/*
+	 * disassoc frame format
+	 *	[2] reason
+	 */
+	IEEE80211_VERIFY_LENGTH(efrm - frm, 2);
+	reason = le16toh(*(u_int16_t *)frm);
+	__USE(reason);
+	ic->ic_stats.is_rx_disassoc++;
+	IEEE80211_NODE_STAT(ni, rx_disassoc);
+
+	if (!IEEE80211_ADDR_EQ(wh->i_addr1, ic->ic_myaddr)) {
+		/* Not intended for this station. */
+		ic->ic_stats.is_rx_mgtdiscard++;
+		return;
+	}
+	IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC,
+	"[%s] recv disassociate (reason %d)\n",
+	ether_snprintf(ebuf, sizeof(ebuf), ni->ni_macaddr), reason);
+	switch (ic->ic_opmode) {
+	case IEEE80211_M_STA:
+		ieee80211_new_state(ic, IEEE80211_S_ASSOC,
+		wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK);
+		break;
+	case IEEE80211_M_HOSTAP:
+#ifndef IEEE80211_NO_HOSTAP
+		if (ni != ic->ic_bss)
+			ieee80211_node_leave(ic, ni);
+#endif /* !IEEE80211_NO_HOSTAP */
+		break;
+	default:
+		ic->ic_stats.is_rx_mgtdiscard++;
+		break;
+	}
+}
+
+/* -- */
+
+void
+ieee80211_recv_mgmt(struct ieee80211com *ic, struct mbuf *m0,
+struct ieee80211_node *ni, int subtype, int rssi, u_int32_t rstamp)
+{
+	struct ieee80211_frame *wh;
+
+	wh = mtod(m0, struct ieee80211_frame *);
+
 	switch (subtype) {
 	case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
 	case IEEE80211_FC0_SUBTYPE_BEACON:
@@ -2897,58 +2948,19 @@ ieee80211_recv_mgmt(struct ieee80211com 
 		ieee80211_recv_mgmt_deauth(ic, m0, ni, subtype, rssi, rstamp);
 		return;
 
-	case IEEE80211_FC0_SUBTYPE_DISASSOC: {
-		u_int16_t reason;
+	case IEEE80211_FC0_SUBTYPE_DISASSOC:
+		ieee80211_recv_mgmt_disassoc(ic, m0, ni, subtype, rssi, rstamp);
+		return;
 
-		if (ic->ic_state != IEEE80211_S_RUN &&
-		ic->ic_state != IEEE80211_S_ASSOC &&
-		ic->ic_state != IEEE80211_S_AUTH) {
-			ic->ic_stats.is_rx_mgtdiscard++;
-			return;
-		}
-		/*
-		 * disassoc frame format
-		 *	[2] reason
-		 */
-		IEEE80211_VERIFY_LENGTH(efrm - frm, 2);
-		reason = le16toh(*(u_int16_t *)frm);
-		__USE(reason);
-		ic->ic_stats.is_rx_disassoc++;
-		IEEE80211_NODE_STAT(ni, rx_disassoc);
-
-		if (!IEEE80211_ADDR_EQ(wh->i_addr1, ic->ic_myaddr)) {
-			/* Not intended for this station. */
-			ic->ic_stats.is_rx_mgtdiscard++;
-			break;
-		}
-		IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC,
-		"[%s] recv disassociate (reason %d)\n",
-		ether_snprintf(ebuf, sizeof(ebuf), ni->ni_macaddr), reason);
-		switch (ic->ic_opmode) {
-		case IEEE80211_M_STA:
-			ieee80211_new_state(ic, IEEE80211_S_ASSOC,
-			wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK);
-			break;
-		case IEEE80211_M_HOSTAP:
-#ifndef IEEE80211_NO_HOSTAP
-			if (ni != ic->ic_bss)
-ieee80211_node_leave(ic, ni);
-#endif /* !IEEE80211_NO_HOSTAP */
-			break;
-		default:
-			ic->ic_stats.is_rx_mgtdiscard++;
-			break;
-		}
-		break;
-	}
 	default:
 		IEEE80211_DISCARD(ic, IEEE80211_MSG_ANY,
 		 wh, "mgt", "subtype 0x%x not handled", subtype);
 		ic->ic_stats.is_rx_badsubtype++;
 		break;
 	}
-#undef ISREASSOC
 }
+
+#undef ISREASSOC
 #undef 

CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 16:09:30 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Introduce ieee80211_recv_mgmt_disassoc.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 16:04:17 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Introduce ieee80211_recv_mgmt_deauth.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 16:04:17 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Introduce ieee80211_recv_mgmt_deauth.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.101 src/sys/net80211/ieee80211_input.c:1.102
--- src/sys/net80211/ieee80211_input.c:1.101	Tue Jan 16 16:00:17 2018
+++ src/sys/net80211/ieee80211_input.c	Tue Jan 16 16:04:16 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.101 2018/01/16 16:00:17 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.102 2018/01/16 16:04:16 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.101 2018/01/16 16:00:17 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.102 2018/01/16 16:04:16 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -2802,6 +2802,59 @@ ieee80211_recv_mgmt_assoc_resp(struct ie
 	ieee80211_new_state(ic, IEEE80211_S_RUN, subtype);
 }
 
+static void
+ieee80211_recv_mgmt_deauth(struct ieee80211com *ic, struct mbuf *m0,
+struct ieee80211_node *ni, int subtype, int rssi, u_int32_t rstamp)
+{
+	struct ieee80211_frame *wh;
+	u_int8_t *frm, *efrm;
+	IEEE80211_DEBUGVAR(char ebuf[3 * ETHER_ADDR_LEN]);
+
+	wh = mtod(m0, struct ieee80211_frame *);
+	frm = (u_int8_t *)(wh + 1);
+	efrm = mtod(m0, u_int8_t *) + m0->m_len;
+
+	u_int16_t reason;
+
+	if (ic->ic_state == IEEE80211_S_SCAN) {
+		ic->ic_stats.is_rx_mgtdiscard++;
+		return;
+	}
+	/*
+	 * deauth frame format
+	 *	[2] reason
+	 */
+	IEEE80211_VERIFY_LENGTH(efrm - frm, 2);
+	reason = le16toh(*(u_int16_t *)frm);
+	__USE(reason);
+	ic->ic_stats.is_rx_deauth++;
+	IEEE80211_NODE_STAT(ni, rx_deauth);
+
+	if (!IEEE80211_ADDR_EQ(wh->i_addr1, ic->ic_myaddr)) {
+		/* Not intended for this station. */
+		ic->ic_stats.is_rx_mgtdiscard++;
+		return;
+	}
+	IEEE80211_DPRINTF(ic, IEEE80211_MSG_AUTH,
+	"[%s] recv deauthenticate (reason %d)\n",
+	ether_snprintf(ebuf, sizeof(ebuf), ni->ni_macaddr), reason);
+	switch (ic->ic_opmode) {
+	case IEEE80211_M_STA:
+		ieee80211_new_state(ic, IEEE80211_S_AUTH,
+		wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK);
+		break;
+	case IEEE80211_M_HOSTAP:
+#ifndef IEEE80211_NO_HOSTAP
+		if (ni != ic->ic_bss)
+			ieee80211_node_leave(ic, ni);
+#endif /* !IEEE80211_NO_HOSTAP */
+		break;
+	default:
+		ic->ic_stats.is_rx_mgtdiscard++;
+		break;
+	}
+}
+
 /* -- */
 
 void
@@ -2840,48 +2893,9 @@ ieee80211_recv_mgmt(struct ieee80211com 
 		ieee80211_recv_mgmt_assoc_resp(ic, m0, ni, subtype, rssi, rstamp);
 		return;
 
-	case IEEE80211_FC0_SUBTYPE_DEAUTH: {
-		u_int16_t reason;
-
-		if (ic->ic_state == IEEE80211_S_SCAN) {
-			ic->ic_stats.is_rx_mgtdiscard++;
-			return;
-		}
-		/*
-		 * deauth frame format
-		 *	[2] reason
-		 */
-		IEEE80211_VERIFY_LENGTH(efrm - frm, 2);
-		reason = le16toh(*(u_int16_t *)frm);
-		__USE(reason);
-		ic->ic_stats.is_rx_deauth++;
-		IEEE80211_NODE_STAT(ni, rx_deauth);
-
-		if (!IEEE80211_ADDR_EQ(wh->i_addr1, ic->ic_myaddr)) {
-			/* Not intended for this station. */
-			ic->ic_stats.is_rx_mgtdiscard++;
-			break;
-		}
-		IEEE80211_DPRINTF(ic, IEEE80211_MSG_AUTH,
-		"[%s] recv deauthenticate (reason %d)\n",
-		ether_snprintf(ebuf, sizeof(ebuf), ni->ni_macaddr), reason);
-		switch (ic->ic_opmode) {
-		case IEEE80211_M_STA:
-			ieee80211_new_state(ic, IEEE80211_S_AUTH,
-			wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK);
-			break;
-		case IEEE80211_M_HOSTAP:
-#ifndef IEEE80211_NO_HOSTAP
-			if (ni != ic->ic_bss)
-ieee80211_node_leave(ic, ni);
-#endif /* !IEEE80211_NO_HOSTAP */
-			break;
-		default:
-			ic->ic_stats.is_rx_mgtdiscard++;
-			break;
-		}
-		break;
-	}
+	case IEEE80211_FC0_SUBTYPE_DEAUTH:
+		ieee80211_recv_mgmt_deauth(ic, m0, ni, subtype, rssi, rstamp);
+		return;
 
 	case IEEE80211_FC0_SUBTYPE_DISASSOC: {
 		u_int16_t reason;



CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 16:00:17 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Introduce ieee80211_recv_mgmt_assoc_resp.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.100 src/sys/net80211/ieee80211_input.c:1.101
--- src/sys/net80211/ieee80211_input.c:1.100	Tue Jan 16 15:55:14 2018
+++ src/sys/net80211/ieee80211_input.c	Tue Jan 16 16:00:17 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.100 2018/01/16 15:55:14 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.101 2018/01/16 16:00:17 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.100 2018/01/16 15:55:14 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.101 2018/01/16 16:00:17 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -2668,17 +2668,148 @@ ieee80211_recv_mgmt_assoc_req(struct iee
 	ieee80211_node_join(ic, ni, resp);
 }
 
+#define	ISREASSOC(_st)	((_st) == IEEE80211_FC0_SUBTYPE_REASSOC_RESP)
+
+static void
+ieee80211_recv_mgmt_assoc_resp(struct ieee80211com *ic, struct mbuf *m0,
+struct ieee80211_node *ni, int subtype, int rssi, u_int32_t rstamp)
+{
+	struct ieee80211_frame *wh;
+	u_int8_t *frm, *efrm;
+	u_int8_t *rates, *xrates, *wpa, *wme;
+	u_int8_t rate;
+	IEEE80211_DEBUGVAR(char ebuf[3 * ETHER_ADDR_LEN]);
+
+	wh = mtod(m0, struct ieee80211_frame *);
+	frm = (u_int8_t *)(wh + 1);
+	efrm = mtod(m0, u_int8_t *) + m0->m_len;
+
+	u_int16_t capinfo, associd;
+	u_int16_t status;
+
+	if (ic->ic_opmode != IEEE80211_M_STA ||
+	ic->ic_state != IEEE80211_S_ASSOC) {
+		ic->ic_stats.is_rx_mgtdiscard++;
+		return;
+	}
+
+	/*
+	 * asresp frame format
+	 *	[2] capability information
+	 *	[2] status
+	 *	[2] association ID
+	 *	[tlv] supported rates
+	 *	[tlv] extended supported rates
+	 *	[tlv] WME
+	 */
+	IEEE80211_VERIFY_LENGTH(efrm - frm, 6);
+	ni = ic->ic_bss;
+	capinfo = le16toh(*(u_int16_t *)frm);
+	frm += 2;
+	status = le16toh(*(u_int16_t *)frm);
+	frm += 2;
+	if (status != 0) {
+		IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC,
+		"[%s] %sassoc failed (reason %d)\n",
+		ether_snprintf(ebuf, sizeof(ebuf), wh->i_addr2),
+		ISREASSOC(subtype) ?  "re" : "", status);
+		if (ni != ic->ic_bss)	/* XXX never true? */
+			ni->ni_fails++;
+		ic->ic_stats.is_rx_auth_fail++;	/* XXX */
+		return;
+	}
+	associd = le16toh(*(u_int16_t *)frm);
+	frm += 2;
+
+	rates = xrates = wpa = wme = NULL;
+	while (frm < efrm) {
+		switch (*frm) {
+		case IEEE80211_ELEMID_RATES:
+			rates = frm;
+			break;
+		case IEEE80211_ELEMID_XRATES:
+			xrates = frm;
+			break;
+		case IEEE80211_ELEMID_VENDOR:
+			if (iswmeoui(frm))
+wme = frm;
+			/* XXX Atheros OUI support */
+			break;
+		}
+		frm += frm[1] + 2;
+	}
+
+	IEEE80211_VERIFY_ELEMENT(rates, IEEE80211_RATE_MAXSIZE);
+	rate = ieee80211_setup_rates(ni, rates, xrates,
+			IEEE80211_R_DOSORT | IEEE80211_R_DOFRATE |
+			IEEE80211_R_DONEGO | IEEE80211_R_DODEL);
+	if (rate & IEEE80211_RATE_BASIC) {
+		IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC,
+		"[%s] %sassoc failed (rate set mismatch)\n",
+		ether_snprintf(ebuf, sizeof(ebuf), wh->i_addr2),
+		ISREASSOC(subtype) ?  "re" : "");
+		if (ni != ic->ic_bss)	/* XXX never true? */
+			ni->ni_fails++;
+		ic->ic_stats.is_rx_assoc_norate++;
+		ieee80211_new_state(ic, IEEE80211_S_SCAN, 0);
+		return;
+	}
+
+	ni->ni_capinfo = capinfo;
+	ni->ni_associd = associd;
+	if (wme != NULL &&
+	ieee80211_parse_wmeparams(ic, wme, wh) >= 0) {
+		ni->ni_flags |= IEEE80211_NODE_QOS;
+		ieee80211_wme_updateparams(ic);
+	} else
+		ni->ni_flags &= ~IEEE80211_NODE_QOS;
+	/*
+	 * Configure state now that we are associated.
+	 *
+	 * XXX may need different/additional driver callbacks?
+	 */
+	if (ic->ic_curmode == IEEE80211_MODE_11A ||
+	(ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE)) {
+		ic->ic_flags |= IEEE80211_F_SHPREAMBLE;
+		ic->ic_flags &= ~IEEE80211_F_USEBARKER;
+	} else {
+		ic->ic_flags &= ~IEEE80211_F_SHPREAMBLE;
+		ic->ic_flags |= IEEE80211_F_USEBARKER;
+	}
+	ieee80211_set_shortslottime(ic,
+		ic->ic_curmode == IEEE80211_MODE_11A ||
+		(ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME));
+	/*
+	 * Honor ERP protection.
+	 *
+	 * NB: ni_erp should zero for non-11g operation.
+	 * XXX check ic_curmode anyway?
+	 */
+	if (ic->ic_curmode == IEEE80211_MODE_11G &&
+	(ni->ni_erp & IEEE80211_ERP_USE_PROTECTION))
+		ic->ic_flags |= IEEE80211_F_USEPROT;
+	else
+		ic->ic_flags &= ~IEEE80211_F_USEPROT;
+	IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC,
+	"[%s] %sassoc success: %s preamble, %s slot time%s%s\n",
+	 

CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 16:00:17 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Introduce ieee80211_recv_mgmt_assoc_resp.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 15:55:14 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Introduce ieee80211_recv_mgmt_assoc_req.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.99 src/sys/net80211/ieee80211_input.c:1.100
--- src/sys/net80211/ieee80211_input.c:1.99	Tue Jan 16 15:48:32 2018
+++ src/sys/net80211/ieee80211_input.c	Tue Jan 16 15:55:14 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.99 2018/01/16 15:48:32 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.100 2018/01/16 15:55:14 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.99 2018/01/16 15:48:32 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.100 2018/01/16 15:55:14 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -2449,6 +2449,225 @@ ieee80211_recv_mgmt_auth(struct ieee8021
 	}
 }
 
+static void
+ieee80211_recv_mgmt_assoc_req(struct ieee80211com *ic, struct mbuf *m0,
+struct ieee80211_node *ni, int subtype, int rssi, u_int32_t rstamp)
+{
+	struct ieee80211_frame *wh;
+	u_int8_t *frm, *efrm;
+	u_int8_t *ssid, *rates, *xrates, *wpa, *wme;
+	int reassoc, resp;
+	u_int8_t rate;
+	IEEE80211_DEBUGVAR(char ebuf[3 * ETHER_ADDR_LEN]);
+
+	wh = mtod(m0, struct ieee80211_frame *);
+	frm = (u_int8_t *)(wh + 1);
+	efrm = mtod(m0, u_int8_t *) + m0->m_len;
+
+	u_int16_t capinfo, lintval;
+	struct ieee80211_rsnparms rsn;
+	u_int8_t reason;
+
+	if (ic->ic_opmode != IEEE80211_M_HOSTAP ||
+	ic->ic_state != IEEE80211_S_RUN) {
+		ic->ic_stats.is_rx_mgtdiscard++;
+		return;
+	}
+
+	if (subtype == IEEE80211_FC0_SUBTYPE_REASSOC_REQ) {
+		reassoc = 1;
+		resp = IEEE80211_FC0_SUBTYPE_REASSOC_RESP;
+	} else {
+		reassoc = 0;
+		resp = IEEE80211_FC0_SUBTYPE_ASSOC_RESP;
+	}
+	/*
+	 * asreq frame format
+	 *	[2] capability information
+	 *	[2] listen interval
+	 *	[6*] current AP address (reassoc only)
+	 *	[tlv] ssid
+	 *	[tlv] supported rates
+	 *	[tlv] extended supported rates
+	 *	[tlv] WPA or RSN
+	 */
+	IEEE80211_VERIFY_LENGTH(efrm - frm, (reassoc ? 10 : 4));
+	if (!IEEE80211_ADDR_EQ(wh->i_addr3, ic->ic_bss->ni_bssid)) {
+		IEEE80211_DISCARD(ic, IEEE80211_MSG_ANY,
+		wh, ieee80211_mgt_subtype_name[subtype >>
+			IEEE80211_FC0_SUBTYPE_SHIFT],
+		"%s", "wrong bssid");
+		ic->ic_stats.is_rx_assoc_bss++;
+		return;
+	}
+	capinfo = le16toh(*(u_int16_t *)frm);	frm += 2;
+	lintval = le16toh(*(u_int16_t *)frm);	frm += 2;
+	if (reassoc)
+		frm += 6;	/* ignore current AP info */
+	ssid = rates = xrates = wpa = wme = NULL;
+	while (frm < efrm) {
+		switch (*frm) {
+		case IEEE80211_ELEMID_SSID:
+			ssid = frm;
+			break;
+		case IEEE80211_ELEMID_RATES:
+			rates = frm;
+			break;
+		case IEEE80211_ELEMID_XRATES:
+			xrates = frm;
+			break;
+		/* XXX verify only one of RSN and WPA ie's? */
+		case IEEE80211_ELEMID_RSN:
+			wpa = frm;
+			break;
+		case IEEE80211_ELEMID_VENDOR:
+			if (iswpaoui(frm))
+wpa = frm;
+			else if (iswmeinfo(frm))
+wme = frm;
+			/* XXX Atheros OUI support */
+			break;
+		}
+		frm += frm[1] + 2;
+	}
+	IEEE80211_VERIFY_ELEMENT(rates, IEEE80211_RATE_MAXSIZE);
+	IEEE80211_VERIFY_ELEMENT(ssid, IEEE80211_NWID_LEN);
+	IEEE80211_VERIFY_SSID(ic->ic_bss, ssid);
+
+	if (ni == ic->ic_bss) {
+		IEEE80211_DPRINTF(ic, IEEE80211_MSG_ANY,
+		"[%s] deny %s request, sta not authenticated\n",
+		ether_snprintf(ebuf, sizeof(ebuf), wh->i_addr2),
+		reassoc ? "reassoc" : "assoc");
+		ieee80211_send_error(ic, ni, wh->i_addr2,
+		IEEE80211_FC0_SUBTYPE_DEAUTH,
+		IEEE80211_REASON_ASSOC_NOT_AUTHED);
+		ic->ic_stats.is_rx_assoc_notauth++;
+		return;
+	}
+	/* assert right associstion security credentials */
+	if (wpa == NULL && (ic->ic_flags & IEEE80211_F_WPA)) {
+		IEEE80211_DPRINTF(ic,
+		IEEE80211_MSG_ASSOC | IEEE80211_MSG_WPA,
+		"[%s] no WPA/RSN IE in association request\n",
+		ether_snprintf(ebuf, sizeof(ebuf), wh->i_addr2));
+		IEEE80211_SEND_MGMT(ic, ni,
+		IEEE80211_FC0_SUBTYPE_DEAUTH,
+		IEEE80211_REASON_RSN_REQUIRED);
+		ieee80211_node_leave(ic, ni);
+		/* XXX distinguish WPA/RSN? */
+		ic->ic_stats.is_rx_assoc_badwpaie++;
+		return;
+	}
+	if (wpa != NULL) {
+		/*
+		 * Parse WPA information element.  Note that
+		 * we initialize the param block from the node
+		 * state so that information in the IE overrides
+		 * our defaults.  The resulting parameters are
+		 * installed below after the association is assured.
+		 */
+		rsn = ni->ni_rsn;
+		if (wpa[0] != IEEE80211_ELEMID_RSN)
+			reason = ieee80211_parse_wpa(ic, wpa, , wh);
+		else
+			reason = 

CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 15:55:14 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Introduce ieee80211_recv_mgmt_assoc_req.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 15:48:32 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Introduce ieee80211_recv_mgmt_auth.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.98 src/sys/net80211/ieee80211_input.c:1.99
--- src/sys/net80211/ieee80211_input.c:1.98	Tue Jan 16 15:42:52 2018
+++ src/sys/net80211/ieee80211_input.c	Tue Jan 16 15:48:32 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.98 2018/01/16 15:42:52 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.99 2018/01/16 15:48:32 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.98 2018/01/16 15:42:52 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.99 2018/01/16 15:48:32 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -2371,6 +2371,84 @@ ieee80211_recv_mgmt_probe_req(struct iee
 	}
 }
 
+static void
+ieee80211_recv_mgmt_auth(struct ieee80211com *ic, struct mbuf *m0,
+struct ieee80211_node *ni, int subtype, int rssi, u_int32_t rstamp)
+{
+	struct ieee80211_frame *wh;
+	u_int8_t *frm, *efrm;
+	IEEE80211_DEBUGVAR(char ebuf[3 * ETHER_ADDR_LEN]);
+
+	wh = mtod(m0, struct ieee80211_frame *);
+	frm = (u_int8_t *)(wh + 1);
+	efrm = mtod(m0, u_int8_t *) + m0->m_len;
+
+	u_int16_t algo, seq, status;
+	/*
+	 * auth frame format
+	 *	[2] algorithm
+	 *	[2] sequence
+	 *	[2] status
+	 *	[tlv*] challenge
+	 */
+	IEEE80211_VERIFY_LENGTH(efrm - frm, 6);
+	algo   = le16toh(*(u_int16_t *)frm);
+	seq= le16toh(*(u_int16_t *)(frm + 2));
+	status = le16toh(*(u_int16_t *)(frm + 4));
+	IEEE80211_DPRINTF(ic, IEEE80211_MSG_AUTH,
+	"[%s] recv auth frame with algorithm %d seq %d\n",
+	ether_snprintf(ebuf, sizeof(ebuf), wh->i_addr2), algo, seq);
+	/*
+	 * Consult the ACL policy module if setup.
+	 */
+	if (ic->ic_acl != NULL &&
+	!ic->ic_acl->iac_check(ic, wh->i_addr2)) {
+		IEEE80211_DISCARD(ic, IEEE80211_MSG_ACL,
+		wh, "auth", "%s", "disallowed by ACL");
+		ic->ic_stats.is_rx_acl++;
+		if (ic->ic_opmode == IEEE80211_M_HOSTAP) {
+			IEEE80211_SEND_MGMT(ic, ni,
+			IEEE80211_FC0_SUBTYPE_AUTH,
+			(seq+1) | (IEEE80211_STATUS_UNSPECIFIED<<16));
+		}
+		return;
+	}
+	if (ic->ic_flags & IEEE80211_F_COUNTERM) {
+		IEEE80211_DISCARD(ic,
+		IEEE80211_MSG_AUTH | IEEE80211_MSG_CRYPTO,
+		wh, "auth", "%s", "TKIP countermeasures enabled");
+		ic->ic_stats.is_rx_auth_countermeasures++;
+#ifndef IEEE80211_NO_HOSTAP
+		if (ic->ic_opmode == IEEE80211_M_HOSTAP) {
+			IEEE80211_SEND_MGMT(ic, ni,
+IEEE80211_FC0_SUBTYPE_AUTH,
+IEEE80211_REASON_MIC_FAILURE);
+		}
+#endif /* !IEEE80211_NO_HOSTAP */
+		return;
+	}
+	if (algo == IEEE80211_AUTH_ALG_SHARED)
+		ieee80211_auth_shared(ic, wh, frm + 6, efrm, ni, rssi,
+		rstamp, seq, status);
+	else if (algo == IEEE80211_AUTH_ALG_OPEN)
+		ieee80211_auth_open(ic, wh, ni, rssi, rstamp, seq,
+		status);
+	else {
+		IEEE80211_DISCARD(ic, IEEE80211_MSG_ANY,
+		wh, "auth", "unsupported alg %d", algo);
+		ic->ic_stats.is_rx_auth_unsupported++;
+#ifndef IEEE80211_NO_HOSTAP
+		if (ic->ic_opmode == IEEE80211_M_HOSTAP) {
+			/* XXX not right */
+			IEEE80211_SEND_MGMT(ic, ni,
+IEEE80211_FC0_SUBTYPE_AUTH,
+(seq+1) | (IEEE80211_STATUS_ALG<<16));
+		}
+#endif /* !IEEE80211_NO_HOSTAP */
+		return;
+	}
+}
+
 /* -- */
 
 void
@@ -2399,73 +2477,9 @@ ieee80211_recv_mgmt(struct ieee80211com 
 		ieee80211_recv_mgmt_probe_req(ic, m0, ni, subtype, rssi, rstamp);
 		return;
 
-	case IEEE80211_FC0_SUBTYPE_AUTH: {
-		u_int16_t algo, seq, status;
-		/*
-		 * auth frame format
-		 *	[2] algorithm
-		 *	[2] sequence
-		 *	[2] status
-		 *	[tlv*] challenge
-		 */
-		IEEE80211_VERIFY_LENGTH(efrm - frm, 6);
-		algo   = le16toh(*(u_int16_t *)frm);
-		seq= le16toh(*(u_int16_t *)(frm + 2));
-		status = le16toh(*(u_int16_t *)(frm + 4));
-		IEEE80211_DPRINTF(ic, IEEE80211_MSG_AUTH,
-		"[%s] recv auth frame with algorithm %d seq %d\n",
-		ether_snprintf(ebuf, sizeof(ebuf), wh->i_addr2), algo, seq);
-		/*
-		 * Consult the ACL policy module if setup.
-		 */
-		if (ic->ic_acl != NULL &&
-		!ic->ic_acl->iac_check(ic, wh->i_addr2)) {
-			IEEE80211_DISCARD(ic, IEEE80211_MSG_ACL,
-			wh, "auth", "%s", "disallowed by ACL");
-			ic->ic_stats.is_rx_acl++;
-			if (ic->ic_opmode == IEEE80211_M_HOSTAP) {
-IEEE80211_SEND_MGMT(ic, ni,
-IEEE80211_FC0_SUBTYPE_AUTH,
-(seq+1) | (IEEE80211_STATUS_UNSPECIFIED<<16));
-			}
-			return;
-		}
-		if (ic->ic_flags & IEEE80211_F_COUNTERM) {
-			

CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 15:48:32 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Introduce ieee80211_recv_mgmt_auth.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 15:42:52 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Start splitting ieee80211_recv_mgmt.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.97 src/sys/net80211/ieee80211_input.c:1.98
--- src/sys/net80211/ieee80211_input.c:1.97	Tue Jan 16 15:18:37 2018
+++ src/sys/net80211/ieee80211_input.c	Tue Jan 16 15:42:52 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.97 2018/01/16 15:18:37 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.98 2018/01/16 15:42:52 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.97 2018/01/16 15:18:37 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.98 2018/01/16 15:42:52 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -2001,369 +2001,403 @@ ieee80211_update_adhoc_node(struct ieee8
 	}
 }
 
-void
-ieee80211_recv_mgmt(struct ieee80211com *ic, struct mbuf *m0,
+/* -- */
+
+static void
+ieee80211_recv_mgmt_beacon(struct ieee80211com *ic, struct mbuf *m0,
 struct ieee80211_node *ni, int subtype, int rssi, u_int32_t rstamp)
 {
-#define	ISPROBE(_st)	((_st) == IEEE80211_FC0_SUBTYPE_PROBE_RESP)
-#define	ISREASSOC(_st)	((_st) == IEEE80211_FC0_SUBTYPE_REASSOC_RESP)
 	struct ieee80211_frame *wh;
 	u_int8_t *frm, *efrm;
-	u_int8_t *ssid, *rates, *xrates, *wpa, *wme;
-	int reassoc, resp, allocbs;
-	u_int8_t rate;
 	IEEE80211_DEBUGVAR(char ebuf[3 * ETHER_ADDR_LEN]);
+	struct ieee80211_scanparams scan;
 
 	wh = mtod(m0, struct ieee80211_frame *);
 	frm = (u_int8_t *)(wh + 1);
 	efrm = mtod(m0, u_int8_t *) + m0->m_len;
 
-	switch (subtype) {
-	case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
-	case IEEE80211_FC0_SUBTYPE_BEACON: {
-		struct ieee80211_scanparams scan;
-
-		/*
-		 * We process beacon/probe response frames:
-		 *o when scanning, or
-		 *o station mode when associated (to collect state
-		 *  updates such as 802.11g slot time), or
-		 *o adhoc mode (to discover neighbors)
-		 * Frames otherwise received are discarded.
-		 */
-		if (!((ic->ic_flags & IEEE80211_F_SCAN) ||
-		  (ic->ic_opmode == IEEE80211_M_STA && ni->ni_associd) ||
-		   ic->ic_opmode == IEEE80211_M_IBSS)) {
-			ic->ic_stats.is_rx_mgtdiscard++;
-			return;
-		}
-
-		/*
-		 * beacon/probe response frame format
-		 *	[8] time stamp
-		 *	[2] beacon interval
-		 *	[2] capability information
-		 *	[tlv] ssid
-		 *	[tlv] supported rates
-		 *	[tlv] country information
-		 *	[tlv] parameter set (FH/DS)
-		 *	[tlv] erp information
-		 *	[tlv] extended supported rates
-		 *	[tlv] WME
-		 *	[tlv] WPA or RSN
-		 */
-		IEEE80211_VERIFY_LENGTH(efrm - frm, 12);
-		memset(, 0, sizeof(scan));
-		scan.tstamp  = frm;frm += 8;
-		scan.bintval = le16toh(*(u_int16_t *)frm);	frm += 2;
-		scan.capinfo = le16toh(*(u_int16_t *)frm);	frm += 2;
-		scan.bchan = ieee80211_chan2ieee(ic, ic->ic_curchan);
-		scan.chan = scan.bchan;
-
-		while (frm + 1 < efrm) {
-			IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2);
+	/*
+	 * We process beacon/probe response frames:
+	 *o when scanning, or
+	 *o station mode when associated (to collect state
+	 *  updates such as 802.11g slot time), or
+	 *o adhoc mode (to discover neighbors)
+	 * Frames otherwise received are discarded.
+	 */
+	if (!((ic->ic_flags & IEEE80211_F_SCAN) ||
+	  (ic->ic_opmode == IEEE80211_M_STA && ni->ni_associd) ||
+	   ic->ic_opmode == IEEE80211_M_IBSS)) {
+		ic->ic_stats.is_rx_mgtdiscard++;
+		return;
+	}
 
-			switch (*frm) {
-			case IEEE80211_ELEMID_SSID:
-scan.ssid = frm;
-break;
-			case IEEE80211_ELEMID_RATES:
-scan.rates = frm;
-break;
-			case IEEE80211_ELEMID_COUNTRY:
-scan.country = frm;
-break;
-			case IEEE80211_ELEMID_FHPARMS:
-IEEE80211_VERIFY_LENGTH(frm[1], 5);
-if (ic->ic_phytype == IEEE80211_T_FH) {
-	scan.fhdwell = LE_READ_2([2]);
-	scan.chan = IEEE80211_FH_CHAN(frm[4], frm[5]);
-	scan.fhindex = frm[6];
-}
-break;
-			case IEEE80211_ELEMID_DSPARMS:
-/*
- * XXX hack this since depending on phytype
- * is problematic for multi-mode devices.
- */
-IEEE80211_VERIFY_LENGTH(frm[1], 1);
-if (ic->ic_phytype != IEEE80211_T_FH)
-	scan.chan = frm[2];
-break;
-			case IEEE80211_ELEMID_TIM:
-/* XXX ATIM? */
-IEEE80211_VERIFY_LENGTH(frm[1], 5);
-scan.tim = frm;
-scan.timoff = frm - mtod(m0, u_int8_t *);
-break;
-			case IEEE80211_ELEMID_IBSSPARMS:
-break;
-			case 

CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 15:42:52 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
Start splitting ieee80211_recv_mgmt.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 15:18:37 UTC 2018

Modified Files:
src/sys/net80211: ieee80211_input.c

Log Message:
More overflows...


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.96 src/sys/net80211/ieee80211_input.c:1.97
--- src/sys/net80211/ieee80211_input.c:1.96	Tue Jan 16 14:37:24 2018
+++ src/sys/net80211/ieee80211_input.c	Tue Jan 16 15:18:37 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.96 2018/01/16 14:37:24 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.97 2018/01/16 15:18:37 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.96 2018/01/16 14:37:24 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.97 2018/01/16 15:18:37 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -2074,6 +2074,7 @@ ieee80211_recv_mgmt(struct ieee80211com 
 scan.country = frm;
 break;
 			case IEEE80211_ELEMID_FHPARMS:
+IEEE80211_VERIFY_LENGTH(frm[1], 5);
 if (ic->ic_phytype == IEEE80211_T_FH) {
 	scan.fhdwell = LE_READ_2([2]);
 	scan.chan = IEEE80211_FH_CHAN(frm[4], frm[5]);
@@ -2085,11 +2086,13 @@ ieee80211_recv_mgmt(struct ieee80211com 
  * XXX hack this since depending on phytype
  * is problematic for multi-mode devices.
  */
+IEEE80211_VERIFY_LENGTH(frm[1], 1);
 if (ic->ic_phytype != IEEE80211_T_FH)
 	scan.chan = frm[2];
 break;
 			case IEEE80211_ELEMID_TIM:
 /* XXX ATIM? */
+IEEE80211_VERIFY_LENGTH(frm[1], 5);
 scan.tim = frm;
 scan.timoff = frm - mtod(m0, u_int8_t *);
 break;



  1   2   >