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-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-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-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.

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

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 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.

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

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-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-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-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-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: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-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: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: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: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: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: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 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 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-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 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) 

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 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: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: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 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: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: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: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;



CVS commit: src/sys/net80211

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

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

Log Message:
Fix overflow.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 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.95 src/sys/net80211/ieee80211_input.c:1.96
--- src/sys/net80211/ieee80211_input.c:1.95	Tue Jan 16 14:01:13 2018
+++ src/sys/net80211/ieee80211_input.c	Tue Jan 16 14:37:24 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.95 2018/01/16 14:01:13 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.96 2018/01/16 14:37:24 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.95 2018/01/16 14:01:13 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.96 2018/01/16 14:37:24 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -2003,8 +2003,7 @@ ieee80211_update_adhoc_node(struct ieee8
 
 void
 ieee80211_recv_mgmt(struct ieee80211com *ic, struct mbuf *m0,
-	struct ieee80211_node *ni,
-	int subtype, int rssi, u_int32_t rstamp)
+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)
@@ -2016,8 +2015,9 @@ ieee80211_recv_mgmt(struct ieee80211com 
 	IEEE80211_DEBUGVAR(char ebuf[3 * ETHER_ADDR_LEN]);
 
 	wh = mtod(m0, struct ieee80211_frame *);
-	frm = (u_int8_t *)[1];
+	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: {
@@ -2037,6 +2037,7 @@ ieee80211_recv_mgmt(struct ieee80211com 
 			ic->ic_stats.is_rx_mgtdiscard++;
 			return;
 		}
+
 		/*
 		 * beacon/probe response frame format
 		 *	[8] time stamp
@@ -2059,7 +2060,9 @@ ieee80211_recv_mgmt(struct ieee80211com 
 		scan.bchan = ieee80211_chan2ieee(ic, ic->ic_curchan);
 		scan.chan = scan.bchan;
 
-		while (frm < efrm) {
+		while (frm + 1 < efrm) {
+			IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2);
+
 			switch (*frm) {
 			case IEEE80211_ELEMID_SSID:
 scan.ssid = frm;
@@ -2122,10 +2125,13 @@ ieee80211_recv_mgmt(struct ieee80211com 
 ic->ic_stats.is_rx_elem_unknown++;
 break;
 			}
+
 			frm += frm[1] + 2;
 		}
+
 		IEEE80211_VERIFY_ELEMENT(scan.rates, IEEE80211_RATE_MAXSIZE);
 		IEEE80211_VERIFY_ELEMENT(scan.ssid, IEEE80211_NWID_LEN);
+
 		if (
 #if IEEE80211_CHAN_MAX < 255
 		scan.chan > IEEE80211_CHAN_MAX ||
@@ -2172,7 +2178,7 @@ ieee80211_recv_mgmt(struct ieee80211com 
 
 		if (ni != ic->ic_bss) {
 			ni = ieee80211_refine_node_for_beacon(ic, ni,
-	>ic_channels[scan.chan], scan.ssid);
+			>ic_channels[scan.chan], scan.ssid);
 		}
 		/*
 		 * Count frame now that we know it's to be processed.



CVS commit: src/sys/net80211

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

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

Log Message:
Fix memory leak. If m1 == m, m = NULL, so it's safe to just call m_freem.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 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.94 src/sys/net80211/ieee80211_input.c:1.95
--- src/sys/net80211/ieee80211_input.c:1.94	Tue Jan 16 09:42:11 2018
+++ src/sys/net80211/ieee80211_input.c	Tue Jan 16 14:01:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.94 2018/01/16 09:42:11 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.95 2018/01/16 14:01:13 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.94 2018/01/16 09:42:11 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.95 2018/01/16 14:01:13 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -891,6 +891,7 @@ ieee80211_deliver_data(struct ieee80211c
 ieee80211_free_node(sta);
 			}
 		}
+
 		if (m1 != NULL) {
 			int len;
 #ifdef ALTQ
@@ -902,13 +903,14 @@ ieee80211_deliver_data(struct ieee80211c
 			IFQ_ENQUEUE(>if_snd, m1, error);
 			if (error) {
 ifp->if_oerrors++;
+m_freem(m);
 m = NULL;
 			}
 			ifp->if_obytes += len;
 		}
 	}
-	if (m != NULL) {
 
+	if (m != NULL) {
 		if (ni->ni_vlan != 0)
 			vlan_set_tag(m, ni->ni_vlan);
 
@@ -919,6 +921,7 @@ ieee80211_deliver_data(struct ieee80211c
 		KASSERT(ifp->if_percpuq);
 		if_percpuq_enqueue(ifp->if_percpuq, m);
 	}
+
 	return;
 }
 



CVS commit: src/sys/net80211

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

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

Log Message:
Style, remove pointless XXXs, and add a comment about LLC.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 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.93 src/sys/net80211/ieee80211_input.c:1.94
--- src/sys/net80211/ieee80211_input.c:1.93	Tue Jan 16 08:39:29 2018
+++ src/sys/net80211/ieee80211_input.c	Tue Jan 16 09:42:11 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.93 2018/01/16 08:39:29 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.94 2018/01/16 09:42:11 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.93 2018/01/16 08:39:29 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.94 2018/01/16 09:42:11 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -177,7 +177,7 @@ ieee80211_input_data(struct ieee80211com
 		ni->ni_macaddr, NULL,
 		"data too short: expecting %u", hdrspace);
 		ic->ic_stats.is_rx_tooshort++;
-		goto out;		/* XXX */
+		goto out;
 	}
 	wh = mtod(m, struct ieee80211_frame *);
 
@@ -300,10 +300,9 @@ ieee80211_input_data(struct ieee80211com
 			goto out;
 		}
 	}
-	wh = NULL;		/* no longer valid, catch any uses */
 
 	/*
-	 * Next strip any MSDU crypto bits.
+	 * Next, strip any MSDU crypto bits.
 	 */
 	if (key != NULL && !ieee80211_crypto_demic(ic, key, m, 0)) {
 		IEEE80211_DISCARD_MAC(ic, IEEE80211_MSG_INPUT,
@@ -763,7 +762,7 @@ ieee80211_defrag(struct ieee80211com *ic
 	struct ieee80211_frame *lwh;
 	u_int16_t rxseq;
 	u_int8_t fragno;
-	u_int8_t more_frag = wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG;
+	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?"));
@@ -818,27 +817,33 @@ ieee80211_defrag(struct ieee80211com *ic
 		}
 	}
 
- 	if (mfrag == NULL) {
+	if (mfrag == NULL) {
 		if (fragno != 0) {		/* !first fragment, discard */
 			IEEE80211_NODE_STAT(ni, rx_defrag);
 			m_freem(m);
 			return NULL;
 		}
 		mfrag = m;
-	} else {/* concatenate */
-		m_adj(m, hdrspace);		/* strip header */
+	} else {
+		/* Strip header and concatenate */
+		m_adj(m, hdrspace);
 		m_cat(mfrag, m);
+
 		/* NB: m_cat doesn't update the packet header */
 		mfrag->m_pkthdr.len += m->m_pkthdr.len;
+
 		/* 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 = *(u_int16_t *)wh->i_seq;
 	}
-	if (more_frag) {			/* more to come, save */
+
+	if (more_frag) {
+		/* more to come, save */
 		ni->ni_rxfragstamp = ticks;
 		ni->ni_rxfrag[0] = mfrag;
 		mfrag = NULL;
 	}
+
 	return mfrag;
 }
 
@@ -920,26 +925,33 @@ ieee80211_deliver_data(struct ieee80211c
 static struct mbuf *
 ieee80211_decap(struct ieee80211com *ic, struct mbuf *m, int hdrlen)
 {
-	struct ieee80211_qosframe_addr4 wh;	/* Max size address frames */
+	struct ieee80211_qosframe_addr4 wh; /* Max size address frames */
 	struct ether_header *eh;
 	struct llc *llc;
 
 	if (m->m_len < hdrlen + sizeof(*llc) &&
 	(m = m_pullup(m, hdrlen + sizeof(*llc))) == NULL) {
-		/* XXX stat, msg */
 		return NULL;
 	}
+
 	memcpy(, mtod(m, void *), hdrlen);
+
 	llc = (struct llc *)(mtod(m, char *) + hdrlen);
-	if (llc->llc_dsap == LLC_SNAP_LSAP && llc->llc_ssap == LLC_SNAP_LSAP &&
-	llc->llc_control == LLC_UI && llc->llc_snap.org_code[0] == 0 &&
-	llc->llc_snap.org_code[1] == 0 && llc->llc_snap.org_code[2] == 0) {
+	if (llc->llc_dsap == LLC_SNAP_LSAP &&
+	llc->llc_ssap == LLC_SNAP_LSAP &&
+	llc->llc_control == LLC_UI &&
+	llc->llc_snap.org_code[0] == 0 &&
+	llc->llc_snap.org_code[1] == 0 &&
+	llc->llc_snap.org_code[2] == 0) {
 		m_adj(m, hdrlen + sizeof(struct llc) - sizeof(*eh));
 		llc = NULL;
 	} else {
+		/* Keep the LLC after the Ethernet header. */
 		m_adj(m, hdrlen - sizeof(*eh));
 	}
+
 	eh = mtod(m, struct ether_header *);
+
 	switch (wh.i_fc[1] & IEEE80211_FC1_DIR_MASK) {
 	case IEEE80211_FC1_DIR_NODS:
 		IEEE80211_ADDR_COPY(eh->ether_dhost, wh.i_addr1);
@@ -958,6 +970,7 @@ ieee80211_decap(struct ieee80211com *ic,
 		IEEE80211_ADDR_COPY(eh->ether_shost, wh.i_addr4);
 		break;
 	}
+
 #ifdef ALIGNED_POINTER
 	if (!ALIGNED_POINTER(mtod(m, char *) + sizeof(*eh), u_int32_t)) {
 		struct mbuf *n, *n0, **np;
@@ -1009,10 +1022,12 @@ ieee80211_decap(struct ieee80211com *ic,
 		m = n0;
 	}
 #endif /* ALIGNED_POINTER */
+
 	if (llc != NULL) {
 		eh = mtod(m, struct ether_header *);
 		eh->ether_type = htons(m->m_pkthdr.len - 

CVS commit: src/sys/net80211

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

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

Log Message:
Update the mbuf pointer when m_pullup succeeds, I forgot this in my last
revision (I only fixed the UAF in one branch). Meanwhile, style.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 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.18 src/sys/net80211/ieee80211_crypto.c:1.19
--- src/sys/net80211/ieee80211_crypto.c:1.18	Sun Dec 10 08:56:23 2017
+++ src/sys/net80211/ieee80211_crypto.c	Tue Jan 16 09:04:30 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_crypto.c,v 1.18 2017/12/10 08:56:23 maxv Exp $	*/
+/*	$NetBSD: ieee80211_crypto.c,v 1.19 2018/01/16 09:04:30 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_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.18 2017/12/10 08:56:23 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto.c,v 1.19 2018/01/16 09:04:30 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -559,6 +559,11 @@ ieee80211_crypto_encap(struct ieee80211c
 	return (cip->ic_encap(k, m, keyid<<6) ? k : NULL);
 }
 
+#define	IEEE80211_WEP_HDRLEN	(IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN)
+#define	IEEE80211_WEP_MINLEN \
+	(sizeof(struct ieee80211_frame) + \
+	IEEE80211_WEP_HDRLEN + IEEE80211_WEP_CRCLEN)
+
 /*
  * Validate and strip privacy headers (and trailer) for a
  * received frame that has the WEP/Privacy bit set.
@@ -567,13 +572,9 @@ struct ieee80211_key *
 ieee80211_crypto_decap(struct ieee80211com *ic,
 	struct ieee80211_node *ni, struct mbuf **mp, int hdrlen)
 {
-#define	IEEE80211_WEP_HDRLEN	(IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN)
-#define	IEEE80211_WEP_MINLEN \
-	(sizeof(struct ieee80211_frame) + \
-	IEEE80211_WEP_HDRLEN + IEEE80211_WEP_CRCLEN)
+	const struct ieee80211_cipher *cip;
 	struct ieee80211_key *k;
 	struct ieee80211_frame *wh;
-	const struct ieee80211_cipher *cip;
 	struct mbuf *m = *mp;
 	u_int8_t keyid;
 
@@ -582,7 +583,7 @@ ieee80211_crypto_decap(struct ieee80211c
 		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++;	/* XXX need unique stat? */
+		ic->ic_stats.is_rx_tooshort++;
 		return NULL;
 	}
 
@@ -595,18 +596,22 @@ ieee80211_crypto_decap(struct ieee80211c
 	wh = mtod(m, struct ieee80211_frame *);
 	m_copydata(m, hdrlen + IEEE80211_WEP_IVLEN, sizeof(keyid), );
 	if (IEEE80211_IS_MULTICAST(wh->i_addr1) ||
-	ni->ni_ucastkey.wk_cipher == _cipher_none)
+	ni->ni_ucastkey.wk_cipher == _cipher_none) {
 		k = >ic_nw_keys[keyid >> 6];
-	else
+	} else {
 		k = >ni_ucastkey;
+	}
 
 	/*
 	 * Insure crypto header is contiguous for all decap work.
 	 */
 	cip = k->wk_cipher;
-	if (m->m_len < hdrlen + cip->ic_header &&
-	(m = m_pullup(m, hdrlen + cip->ic_header)) == NULL) {
-		*mp = NULL;
+	if (m->m_len < hdrlen + cip->ic_header) {
+		m = m_pullup(m, hdrlen + cip->ic_header);
+		*mp = m;
+	}
+
+	if (m == NULL) {
 		IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO,
 		"[%s] unable to pullup %s header\n",
 		ether_sprintf(wh->i_addr2), cip->ic_name);
@@ -615,6 +620,4 @@ ieee80211_crypto_decap(struct ieee80211c
 	}
 
 	return (cip->ic_decap(k, m, hdrlen) ? k : NULL);
-#undef IEEE80211_WEP_MINLEN
-#undef IEEE80211_WEP_HDRLEN
 }



CVS commit: src/sys/net80211

2018-01-16 Thread Maxime Villard
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.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 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.92 src/sys/net80211/ieee80211_input.c:1.93
--- src/sys/net80211/ieee80211_input.c:1.92	Tue Jan 16 07:53:02 2018
+++ src/sys/net80211/ieee80211_input.c	Tue Jan 16 08:39:29 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.92 2018/01/16 07:53:02 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.93 2018/01/16 08:39:29 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.92 2018/01/16 07:53:02 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.93 2018/01/16 08:39:29 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -148,6 +148,359 @@ static void ieee80211_update_adhoc_node(
 struct ieee80211_node *, struct ieee80211_frame *,
 struct ieee80211_scanparams *, int, u_int32_t);
 
+/* -- */
+
+/*
+ * Input code for a DATA frame.
+ */
+static int
+ieee80211_input_data(struct ieee80211com *ic, struct mbuf **mp,
+struct ieee80211_node *ni)
+{
+	struct ifnet *ifp = ic->ic_ifp;
+	struct ieee80211_key *key;
+	struct ieee80211_frame *wh;
+	u_int8_t dir, subtype;
+	struct ether_header *eh;
+	struct mbuf *m = *mp;
+	int hdrspace;
+
+	wh = mtod(m, struct ieee80211_frame *);
+	dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
+	subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
+
+	hdrspace = ieee80211_hdrspace(ic, wh);
+
+	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;		/* XXX */
+	}
+	wh = mtod(m, struct ieee80211_frame *);
+
+	switch (ic->ic_opmode) {
+	case IEEE80211_M_STA:
+		if (dir != IEEE80211_FC1_DIR_FROMDS) {
+			IEEE80211_DISCARD(ic, IEEE80211_MSG_INPUT,
+			wh, "data", "%s", "unknown dir 0x%x", dir);
+			ic->ic_stats.is_rx_wrongdir++;
+			goto out;
+		}
+		if ((ifp->if_flags & IFF_SIMPLEX) &&
+		IEEE80211_IS_MULTICAST(wh->i_addr1) &&
+		IEEE80211_ADDR_EQ(wh->i_addr3, ic->ic_myaddr)) {
+			/*
+			 * In IEEE802.11 network, multicast packet
+			 * sent from me is broadcast from AP.
+			 * It should be silently discarded for
+			 * SIMPLEX interface.
+			 */
+			IEEE80211_DISCARD(ic, IEEE80211_MSG_INPUT,
+			wh, NULL, "%s", "multicast echo");
+			ic->ic_stats.is_rx_mcastecho++;
+			goto out;
+		}
+		break;
+
+	case IEEE80211_M_IBSS:
+	case IEEE80211_M_AHDEMO:
+		if (dir != IEEE80211_FC1_DIR_NODS) {
+			IEEE80211_DISCARD(ic, IEEE80211_MSG_INPUT,
+			wh, "data", "%s", "unknown dir 0x%x", dir);
+			ic->ic_stats.is_rx_wrongdir++;
+			goto out;
+		}
+		/* XXX no power-save support */
+		break;
+
+	case IEEE80211_M_HOSTAP:
+#ifndef IEEE80211_NO_HOSTAP
+		if (dir != IEEE80211_FC1_DIR_TODS) {
+			IEEE80211_DISCARD(ic, IEEE80211_MSG_INPUT,
+			wh, "data", "%s", "unknown dir 0x%x", dir);
+			ic->ic_stats.is_rx_wrongdir++;
+			goto out;
+		}
+		/* check if source STA is associated */
+		if (ni == ic->ic_bss) {
+			IEEE80211_DISCARD(ic, IEEE80211_MSG_INPUT,
+			wh, "data", "%s", "unknown src");
+			ieee80211_send_error(ic, ni, wh->i_addr2,
+			IEEE80211_FC0_SUBTYPE_DEAUTH,
+			IEEE80211_REASON_NOT_AUTHED);
+			ic->ic_stats.is_rx_notassoc++;
+			goto err;
+		}
+		if (ni->ni_associd == 0) {
+			IEEE80211_DISCARD(ic, IEEE80211_MSG_INPUT,
+			wh, "data", "%s", "unassoc src");
+			IEEE80211_SEND_MGMT(ic, ni,
+			IEEE80211_FC0_SUBTYPE_DISASSOC,
+			IEEE80211_REASON_NOT_ASSOCED);
+			ic->ic_stats.is_rx_notassoc++;
+			goto err;
+		}
+
+		/*
+		 * Check for power save state change.
+		 */
+		if (((wh->i_fc[1] & IEEE80211_FC1_PWR_MGT) ^
+		(ni->ni_flags & IEEE80211_NODE_PWR_MGT)))
+			ieee80211_node_pwrsave(ni,
+wh->i_fc[1] & IEEE80211_FC1_PWR_MGT);
+#endif /* !IEEE80211_NO_HOSTAP */
+		break;
+
+	default:
+		/* XXX here to keep compiler happy */
+		goto out;
+	}
+
+	/*
+	 * Handle privacy requirements.  Note that we
+	 * must not be preempted from here until after
+	 * we (potentially) call ieee80211_crypto_demic;
+	 * otherwise we may 

CVS commit: src/sys/net80211

2018-01-15 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan 16 07:53:02 UTC 2018

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

Log Message:
Start cleaning up this mess.


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/sys/net80211/ieee80211_input.c
cvs rdiff -u -r1.31 -r1.32 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_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.91 src/sys/net80211/ieee80211_input.c:1.92
--- src/sys/net80211/ieee80211_input.c:1.91	Sun Dec 10 08:56:23 2017
+++ src/sys/net80211/ieee80211_input.c	Tue Jan 16 07:53:02 2018
@@ -1,5 +1,6 @@
-/*	$NetBSD: ieee80211_input.c,v 1.91 2017/12/10 08:56:23 maxv Exp $	*/
-/*-
+/*	$NetBSD: ieee80211_input.c,v 1.92 2018/01/16 07:53:02 maxv Exp $	*/
+
+/*
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
  * All rights reserved.
@@ -36,16 +37,13 @@
 __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.91 2017/12/10 08:56:23 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.92 2018/01/16 07:53:02 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
 #endif
 
-#ifdef __NetBSD__
-#endif /* __NetBSD__ */
-
 #include 
 #include 
 #include 
@@ -138,7 +136,7 @@ static struct mbuf *ieee80211_defrag(str
 	struct ieee80211_node *, struct mbuf *, int);
 static struct mbuf *ieee80211_decap(struct ieee80211com *, struct mbuf *, int);
 static void ieee80211_send_error(struct ieee80211com *, struct ieee80211_node *,
-		const u_int8_t *mac, int subtype, int arg);
+	const u_int8_t *mac, int subtype, int arg);
 static void ieee80211_deliver_data(struct ieee80211com *,
 	struct ieee80211_node *, struct mbuf *);
 #ifndef IEEE80211_NO_HOSTAP
@@ -172,7 +170,6 @@ ieee80211_input(struct ieee80211com *ic,
 	struct ether_header *eh;
 	int hdrspace;
 	u_int8_t dir, type, subtype;
-	u_int8_t *bssid;
 	u_int16_t rxseq;
 	IEEE80211_DEBUGVAR(char ebuf[3 * ETHER_ADDR_LEN]);
 
@@ -187,6 +184,7 @@ ieee80211_input(struct ieee80211com *ic,
 		m->m_flags &= ~M_HASFCS;
 	}
 	type = -1;			/* undefined */
+
 	/*
 	 * In monitor mode, send everything directly to bpf.
 	 * XXX may want to include the CRC
@@ -201,6 +199,7 @@ ieee80211_input(struct ieee80211com *ic,
 		ic->ic_stats.is_rx_tooshort++;
 		goto out;
 	}
+
 	/*
 	 * Bit of a cheat here, we use a pointer for a 3-address
 	 * frame format but don't reference fields past outside
@@ -220,7 +219,10 @@ ieee80211_input(struct ieee80211com *ic,
 	dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
 	type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
 	subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
+
 	if ((ic->ic_flags & IEEE80211_F_SCAN) == 0) {
+		u_int8_t *bssid;
+
 		switch (ic->ic_opmode) {
 		case IEEE80211_M_STA:
 			bssid = wh->i_addr2;
@@ -234,11 +236,12 @@ ieee80211_input(struct ieee80211com *ic,
 goto out;
 			}
 
-			/* Filter out packets not directed to us in case the
-			 * device is in promiscous mode
+			/*
+			 * Filter out packets not directed to us in case the
+			 * device is in promiscuous mode
 			 */
-			if ((! IEEE80211_IS_MULTICAST(wh->i_addr1))
-			&& (! IEEE80211_ADDR_EQ(wh->i_addr1, ic->ic_myaddr))) {
+			if (!IEEE80211_IS_MULTICAST(wh->i_addr1) &&
+			!IEEE80211_ADDR_EQ(wh->i_addr1, ic->ic_myaddr)) {
 IEEE80211_DISCARD_MAC(ic, IEEE80211_MSG_INPUT,
 bssid, NULL, "not to cur sta: lladdr=%6D, addr1=%6D",
 ic->ic_myaddr, ":", wh->i_addr1, ":");
@@ -246,6 +249,7 @@ ieee80211_input(struct ieee80211com *ic,
 goto out;
 			}
 			break;
+
 		case IEEE80211_M_IBSS:
 		case IEEE80211_M_AHDEMO:
 		case IEEE80211_M_HOSTAP:
@@ -266,6 +270,7 @@ ieee80211_input(struct ieee80211com *ic,
 			}
 			if (type != IEEE80211_FC0_TYPE_DATA)
 break;
+
 			/*
 			 * Data frame, validate the bssid.
 			 */
@@ -283,9 +288,11 @@ ieee80211_input(struct ieee80211com *ic,
 ic->ic_stats.is_rx_wrongbss++;
 goto out;
 			}
+
 			/*
 			 * For adhoc mode we cons up a node when it doesn't
-			 * exist. This should probably done after an ACL check.
+			 * exist. This should probably be done after an ACL
+			 * check.
 			 */
 			if (ni == ic->ic_bss &&
 			ic->ic_opmode != IEEE80211_M_HOSTAP &&
@@ -295,35 +302,45 @@ ieee80211_input(struct ieee80211com *ic,
  * discovered member of the IBSS.
  */
 ni = ieee80211_fakeup_adhoc_node(>ic_sta,
-		wh->i_addr2);
+wh->i_addr2);
 if (ni == NULL) {
 	/* NB: stat kept for alloc failure */
 	goto err;
 }
 			}
 			break;
+
 		default:
 			goto out;
 		}
+
 		ni->ni_rssi = rssi;
 		ni->ni_rstamp = rstamp;
+
 		if (HAS_SEQ(type) && (ic->ic_opmode != IEEE80211_M_STA ||
 		!IEEE80211_IS_MULTICAST(wh->i_addr1))) {
 			u_int8_t tid, 

CVS commit: src/sys/net80211

2017-12-10 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Dec 10 08:56:24 UTC 2017

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

Log Message:
Fix use-after-free: ieee80211_crypto_decap does a pullup on the mbuf but
the updated pointer is not passed back. Looks like it is triggerable
remotely.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/net80211/ieee80211_crypto.c
cvs rdiff -u -r1.11 -r1.12 src/sys/net80211/ieee80211_crypto.h
cvs rdiff -u -r1.90 -r1.91 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_crypto.c
diff -u src/sys/net80211/ieee80211_crypto.c:1.17 src/sys/net80211/ieee80211_crypto.c:1.18
--- src/sys/net80211/ieee80211_crypto.c:1.17	Mon Aug 24 22:21:26 2015
+++ src/sys/net80211/ieee80211_crypto.c	Sun Dec 10 08:56:23 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_crypto.c,v 1.17 2015/08/24 22:21:26 pooka Exp $	*/
+/*	$NetBSD: ieee80211_crypto.c,v 1.18 2017/12/10 08:56:23 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_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.17 2015/08/24 22:21:26 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto.c,v 1.18 2017/12/10 08:56:23 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -565,7 +565,7 @@ ieee80211_crypto_encap(struct ieee80211c
  */
 struct ieee80211_key *
 ieee80211_crypto_decap(struct ieee80211com *ic,
-	struct ieee80211_node *ni, struct mbuf *m, int hdrlen)
+	struct ieee80211_node *ni, struct mbuf **mp, int hdrlen)
 {
 #define	IEEE80211_WEP_HDRLEN	(IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN)
 #define	IEEE80211_WEP_MINLEN \
@@ -574,6 +574,7 @@ ieee80211_crypto_decap(struct ieee80211c
 	struct ieee80211_key *k;
 	struct ieee80211_frame *wh;
 	const struct ieee80211_cipher *cip;
+	struct mbuf *m = *mp;
 	u_int8_t keyid;
 
 	/* NB: this minimum size data frame could be bigger */
@@ -605,6 +606,7 @@ ieee80211_crypto_decap(struct ieee80211c
 	cip = k->wk_cipher;
 	if (m->m_len < hdrlen + cip->ic_header &&
 	(m = m_pullup(m, hdrlen + cip->ic_header)) == NULL) {
+		*mp = NULL;
 		IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO,
 		"[%s] unable to pullup %s header\n",
 		ether_sprintf(wh->i_addr2), cip->ic_name);

Index: src/sys/net80211/ieee80211_crypto.h
diff -u src/sys/net80211/ieee80211_crypto.h:1.11 src/sys/net80211/ieee80211_crypto.h:1.12
--- src/sys/net80211/ieee80211_crypto.h:1.11	Sat Jan  3 03:43:23 2009
+++ src/sys/net80211/ieee80211_crypto.h	Sun Dec 10 08:56:23 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_crypto.h,v 1.11 2009/01/03 03:43:23 yamt Exp $	*/
+/*	$NetBSD: ieee80211_crypto.h,v 1.12 2017/12/10 08:56:23 maxv Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -181,7 +181,7 @@ int	ieee80211_crypto_available(u_int cip
 struct ieee80211_key *ieee80211_crypto_encap(struct ieee80211com *,
 		struct ieee80211_node *, struct mbuf *);
 struct ieee80211_key *ieee80211_crypto_decap(struct ieee80211com *,
-		struct ieee80211_node *, struct mbuf *, int);
+		struct ieee80211_node *, struct mbuf **, int);
 
 /*
  * Check and remove any MIC.

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.90 src/sys/net80211/ieee80211_input.c:1.91
--- src/sys/net80211/ieee80211_input.c:1.90	Sun Dec 10 08:48:15 2017
+++ src/sys/net80211/ieee80211_input.c	Sun Dec 10 08:56:23 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.90 2017/12/10 08:48:15 maxv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.91 2017/12/10 08:56:23 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_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.90 2017/12/10 08:48:15 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.91 2017/12/10 08:56:23 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -454,7 +454,7 @@ ieee80211_input(struct ieee80211com *ic,
 IEEE80211_NODE_STAT(ni, rx_noprivacy);
 goto out;
 			}
-			key = ieee80211_crypto_decap(ic, ni, m, hdrspace);
+			key = ieee80211_crypto_decap(ic, ni, , hdrspace);
 			if (key == NULL) {
 /* NB: stats+msgs handled in crypto_decap */
 IEEE80211_NODE_STAT(ni, rx_wepfail);
@@ -595,7 +595,7 @@ ieee80211_input(struct ieee80211com *ic,
 goto out;
 			}
 			hdrspace = ieee80211_hdrspace(ic, wh);
-			key = ieee80211_crypto_decap(ic, ni, m, hdrspace);
+			key = ieee80211_crypto_decap(ic, ni, , hdrspace);
 			if (key == NULL) {
 /* NB: stats+msgs handled in crypto_decap */

CVS commit: src/sys/net80211

2017-12-10 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Dec 10 08:48:15 UTC 2017

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

Log Message:
Update the pointer after m_pullup, otherwise possible use-after-free.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 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.89 src/sys/net80211/ieee80211_input.c:1.90
--- src/sys/net80211/ieee80211_input.c:1.89	Tue Sep 26 07:42:06 2017
+++ src/sys/net80211/ieee80211_input.c	Sun Dec 10 08:48:15 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.89 2017/09/26 07:42:06 knakahara Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.90 2017/12/10 08:48:15 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_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.89 2017/09/26 07:42:06 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.90 2017/12/10 08:48:15 maxv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -358,6 +358,8 @@ ieee80211_input(struct ieee80211com *ic,
 			ic->ic_stats.is_rx_tooshort++;
 			goto out;		/* XXX */
 		}
+		wh = mtod(m, struct ieee80211_frame *);
+
 		switch (ic->ic_opmode) {
 		case IEEE80211_M_STA:
 			if (dir != IEEE80211_FC1_DIR_FROMDS) {



CVS commit: src/sys/net80211

2017-03-06 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Mar  6 08:36:20 UTC 2017

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

Log Message:
Fix incrementing wrong counter


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 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.87 src/sys/net80211/ieee80211_input.c:1.88
--- src/sys/net80211/ieee80211_input.c:1.87	Thu Feb  2 10:05:35 2017
+++ src/sys/net80211/ieee80211_input.c	Mon Mar  6 08:36:20 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.87 2017/02/02 10:05:35 nonaka Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.88 2017/03/06 08:36:20 ozaki-r Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,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.87 2017/02/02 10:05:35 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.88 2017/03/06 08:36:20 ozaki-r Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -780,7 +780,7 @@ ieee80211_deliver_data(struct ieee80211c
 			len = m1->m_pkthdr.len;
 			IFQ_ENQUEUE(>if_snd, m1, error);
 			if (error) {
-ifp->if_omcasts++;
+ifp->if_oerrors++;
 m = NULL;
 			}
 			ifp->if_obytes += len;



CVS commit: src/sys/net80211

2016-10-09 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Oct  9 14:50:20 UTC 2016

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

Log Message:
PR/51540: Henning Petersen: replace , with ;


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 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.8 src/sys/net80211/ieee80211_crypto_wep.c:1.9
--- src/sys/net80211/ieee80211_crypto_wep.c:1.8	Wed Dec 17 15:51:37 2008
+++ src/sys/net80211/ieee80211_crypto_wep.c	Sun Oct  9 10:50:20 2016
@@ -34,7 +34,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.8 2008/12/17 20:51:37 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_wep.c,v 1.9 2016/10/09 14:50:20 christos Exp $");
 #endif
 
 /*
@@ -421,7 +421,7 @@ wep_decrypt(struct ieee80211_key *key, s
 	}
 
 	off = hdrlen + wep.ic_header;
-	data_len = m->m_pkthdr.len - (off + wep.ic_trailer),
+	data_len = m->m_pkthdr.len - (off + wep.ic_trailer);
 
 	/* Compute CRC32 over unencrypted data and apply RC4 to data */
 	crc = ~0;



CVS commit: src/sys/net80211

2016-09-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Sep 27 20:20:06 UTC 2016

Modified Files:
src/sys/net80211: ieee80211_input.c ieee80211_netbsd.c ieee80211_node.c
ieee80211_rssadapt.c ieee80211_var.h

Log Message:
- use ether_snprintf() so that we don't overwrite our buffer for printing
  ethernet-like addresses
- make this compile againw without IEEE80211_DEBUG.


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/sys/net80211/ieee80211_input.c
cvs rdiff -u -r1.27 -r1.28 src/sys/net80211/ieee80211_netbsd.c
cvs rdiff -u -r1.71 -r1.72 src/sys/net80211/ieee80211_node.c
cvs rdiff -u -r1.20 -r1.21 src/sys/net80211/ieee80211_rssadapt.c
cvs rdiff -u -r1.30 -r1.31 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_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.84 src/sys/net80211/ieee80211_input.c:1.85
--- src/sys/net80211/ieee80211_input.c:1.84	Sat May 14 09:35:40 2016
+++ src/sys/net80211/ieee80211_input.c	Tue Sep 27 16:20:06 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.84 2016/05/14 13:35:40 mlelstv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.85 2016/09/27 20:20:06 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_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.84 2016/05/14 13:35:40 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.85 2016/09/27 20:20:06 christos Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -48,7 +48,7 @@ __KERNEL_RCSID(0, "$NetBSD: ieee80211_in
 
 #include 
 #include 
-#include  
+#include 
 #include 
 #include 
 #include 
@@ -66,7 +66,6 @@ __KERNEL_RCSID(0, "$NetBSD: ieee80211_in
 #include 
 #include 
 
-#include 
 #include 
 
 #include 
@@ -116,6 +115,7 @@ doprint(struct ieee80211com *ic, int sub
 	if ((_ic)->ic_debug & (_m))	\
 		ieee80211_discard_mac(_ic, _mac, _type, _fmt, __VA_ARGS__);\
 } while (0)
+#define	IEEE80211_DEBUGVAR(a) a
 
 static const u_int8_t *ieee80211_getbssid(struct ieee80211com *,
 	const struct ieee80211_frame *);
@@ -130,6 +130,7 @@ static void ieee80211_discard_mac(struct
 #define	IEEE80211_DISCARD(_ic, _m, _wh, _type, _fmt, ...)
 #define	IEEE80211_DISCARD_IE(_ic, _m, _wh, _type, _fmt, ...)
 #define	IEEE80211_DISCARD_MAC(_ic, _m, _mac, _type, _fmt, ...)
+#define	IEEE80211_DEBUGVAR(a)
 #endif /* IEEE80211_DEBUG */
 
 static struct mbuf *ieee80211_defrag(struct ieee80211com *,
@@ -172,6 +173,7 @@ ieee80211_input(struct ieee80211com *ic,
 	u_int8_t dir, type, subtype;
 	u_int8_t *bssid;
 	u_int16_t rxseq;
+	IEEE80211_DEBUGVAR(char ebuf[3 * ETHER_ADDR_LEN]);
 
 	IASSERT(ni != NULL, ("null node"));
 	ni->ni_inact = ni->ni_inact_reload;
@@ -222,7 +224,9 @@ ieee80211_input(struct ieee80211com *ic,
 			if (!IEEE80211_ADDR_EQ(bssid, ni->ni_bssid)) {
 /* not interested in */
 IEEE80211_DISCARD_MAC(ic, IEEE80211_MSG_INPUT,
-bssid, NULL, "%s", "not to bss");
+bssid, NULL, "node %s, %s",
+ether_snprintf(ebuf, sizeof(ebuf),
+ni->ni_bssid), "not to bss");
 ic->ic_stats.is_rx_wrongbss++;
 goto out;
 			}
@@ -265,8 +269,14 @@ ieee80211_input(struct ieee80211com *ic,
 			if (!IEEE80211_ADDR_EQ(bssid, ic->ic_bss->ni_bssid) &&
 			!IEEE80211_ADDR_EQ(bssid, ifp->if_broadcastaddr)) {
 /* not interested in */
+IEEE80211_DEBUGVAR(
+char bbuf[3 * ETHER_ADDR_LEN]);
 IEEE80211_DISCARD_MAC(ic, IEEE80211_MSG_INPUT,
-bssid, NULL, "%s", "not to bss");
+bssid, NULL, "bss %s, broadcast %s, %s",
+ether_snprintf(ebuf, sizeof(ebuf),
+ic->ic_bss->ni_bssid),
+ether_snprintf(bbuf, sizeof(bbuf),
+ifp->if_broadcastaddr), "not to bss");
 ic->ic_stats.is_rx_wrongbss++;
 goto out;
 			}
@@ -553,7 +563,8 @@ ieee80211_input(struct ieee80211com *ic,
 			if_printf(ic->ic_ifp, "received %s from %s rssi %d\n",
 			ieee80211_mgt_subtype_name[subtype >>
 IEEE80211_FC0_SUBTYPE_SHIFT],
-			ether_sprintf(wh->i_addr2), rssi);
+			ether_snprintf(ebuf, sizeof(ebuf), wh->i_addr2),
+			rssi);
 		}
 #endif
 		if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
@@ -919,11 +930,13 @@ ieee80211_setup_rates(struct ieee80211_n
 		 */
 		nxrates = xrates[1];
 		if (rs->rs_nrates + nxrates > IEEE80211_RATE_MAXSIZE) {
+			IEEE80211_DEBUGVAR(char ebuf[3 * ETHER_ADDR_LEN]);
 			nxrates = IEEE80211_RATE_MAXSIZE - rs->rs_nrates;
 			IEEE80211_DPRINTF(ic, IEEE80211_MSG_XRATE,
 			 "[%s] extended rate set too large;"
 			 " only using %u of %u rates\n",
-			 ether_sprintf(ni->ni_macaddr), nxrates, xrates[1]);
+			 ether_snprintf(ebuf, sizeof(ebuf), ni->ni_macaddr),
+			 nxrates, xrates[1]);
 			ic->ic_stats.is_rx_rstoobig++;
 		}
 		

CVS commit: src/sys/net80211

2016-06-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Jun 20 08:57:18 UTC 2016

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

Log Message:
Get rid of invalid KASSERT

The mbuf being checked is allocated in ieee80211_getmgtframe just above,
so checking NULL of its CTX is meaningless.

Pointed out by mlelstv@


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 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.55 src/sys/net80211/ieee80211_output.c:1.56
--- src/sys/net80211/ieee80211_output.c:1.55	Mon Jun 20 08:30:59 2016
+++ src/sys/net80211/ieee80211_output.c	Mon Jun 20 08:57:18 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_output.c,v 1.55 2016/06/20 08:30:59 knakahara Exp $	*/
+/*	$NetBSD: ieee80211_output.c,v 1.56 2016/06/20 08:57:18 ozaki-r Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,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.55 2016/06/20 08:30:59 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_output.c,v 1.56 2016/06/20 08:57:18 ozaki-r Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -184,9 +184,6 @@ ieee80211_mgmt_output(struct ieee80211co
 	M_PREPEND(m, sizeof(struct ieee80211_frame), M_DONTWAIT);
 	if (m == NULL)
 		return ENOMEM;
-#ifdef __FreeBSD__
-	KASSERT(M_GETCTX(m, struct ieee80211_node *) == NULL);
-#endif
 	M_SETCTX(m, ni);
 
 	wh = mtod(m, struct ieee80211_frame *);
@@ -1344,7 +1341,6 @@ ieee80211_send_probereq(struct ieee80211
 	M_PREPEND(m, sizeof(struct ieee80211_frame), M_DONTWAIT);
 	if (m == NULL)
 		return ENOMEM;
-	KASSERT(M_GETCTX(m, struct ieee80211_node *) == NULL);
 	M_SETCTX(m, ni);
 
 	wh = mtod(m, struct ieee80211_frame *);



CVS commit: src/sys/net80211

2016-05-14 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat May 14 13:35:40 UTC 2016

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

Log Message:
In station mode filter packets that or not for us in case the
interface is in promiscous mode or doesn't filter packets itself.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 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.83 src/sys/net80211/ieee80211_input.c:1.84
--- src/sys/net80211/ieee80211_input.c:1.83	Sat May  7 12:36:50 2016
+++ src/sys/net80211/ieee80211_input.c	Sat May 14 13:35:40 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.83 2016/05/07 12:36:50 mlelstv Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.84 2016/05/14 13:35:40 mlelstv Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,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.83 2016/05/07 12:36:50 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.84 2016/05/14 13:35:40 mlelstv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -226,6 +226,18 @@ ieee80211_input(struct ieee80211com *ic,
 ic->ic_stats.is_rx_wrongbss++;
 goto out;
 			}
+
+			/* Filter out packets not directed to us in case the
+			 * device is in promiscous mode
+			 */
+			if ((! IEEE80211_IS_MULTICAST(wh->i_addr1))
+			&& (! IEEE80211_ADDR_EQ(wh->i_addr1, ic->ic_myaddr))) {
+IEEE80211_DISCARD_MAC(ic, IEEE80211_MSG_INPUT,
+bssid, NULL, "not to cur sta: lladdr=%6D, addr1=%6D",
+ic->ic_myaddr, ":", wh->i_addr1, ":");
+ic->ic_stats.is_rx_wrongbss++;
+goto out;
+			}
 			break;
 		case IEEE80211_M_IBSS:
 		case IEEE80211_M_AHDEMO:



CVS commit: src/sys/net80211

2016-05-07 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat May  7 12:36:50 UTC 2016

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

Log Message:
Don't check sequence number on multicast packets in station mode.
Handle overflow of 12bit sequence number.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 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.82 src/sys/net80211/ieee80211_input.c:1.83
--- src/sys/net80211/ieee80211_input.c:1.82	Wed Apr 20 09:01:04 2016
+++ src/sys/net80211/ieee80211_input.c	Sat May  7 12:36:50 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.82 2016/04/20 09:01:04 knakahara Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.83 2016/05/07 12:36:50 mlelstv Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,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.82 2016/04/20 09:01:04 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.83 2016/05/07 12:36:50 mlelstv Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -282,8 +282,11 @@ ieee80211_input(struct ieee80211com *ic,
 		}
 		ni->ni_rssi = rssi;
 		ni->ni_rstamp = rstamp;
-		if (HAS_SEQ(type)) {
-			u_int8_t tid;
+		if (HAS_SEQ(type) && (ic->ic_opmode != IEEE80211_M_STA ||
+		!IEEE80211_IS_MULTICAST(wh->i_addr1))) {
+			u_int8_t tid, retry;
+			u_int16_t rxno, orxno;
+
 			if (ieee80211_has_qos(wh)) {
 tid = ((struct ieee80211_qosframe *)wh)->
 	i_qos[0] & IEEE80211_QOS_TID;
@@ -293,15 +296,20 @@ ieee80211_input(struct ieee80211com *ic,
 			} else
 tid = 0;
 			rxseq = le16toh(*(u_int16_t *)wh->i_seq);
-			if ((wh->i_fc[1] & IEEE80211_FC1_RETRY) &&
-			SEQ_LEQ(rxseq, ni->ni_rxseqs[tid])) {
+			retry = wh->i_fc[1] & IEEE80211_FC1_RETRY;
+			rxno = rxseq >> IEEE80211_SEQ_SEQ_SHIFT;
+			orxno = ni->ni_rxseqs[tid] >> IEEE80211_SEQ_SEQ_SHIFT;
+			if (retry && (
+			(orxno == 4095 && rxno == orxno) ||
+			(orxno != 4095 &&
+			 SEQ_LEQ(rxseq, ni->ni_rxseqs[tid]))
+			)) {
 /* duplicate, discard */
 IEEE80211_DISCARD_MAC(ic, IEEE80211_MSG_INPUT,
 bssid, "duplicate",
 "seqno <%u,%u> fragno <%u,%u> tid %u",
-rxseq >> IEEE80211_SEQ_SEQ_SHIFT,
-ni->ni_rxseqs[tid] >>
-	IEEE80211_SEQ_SEQ_SHIFT,
+rxno,
+orxno,
 rxseq & IEEE80211_SEQ_FRAG_MASK,
 ni->ni_rxseqs[tid] &
 	IEEE80211_SEQ_FRAG_MASK,



CVS commit: src/sys/net80211

2016-04-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Apr 27 20:17:00 UTC 2016

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

Log Message:
Add 80211n ht frame.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 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.26 src/sys/net80211/ieee80211.h:1.27
--- src/sys/net80211/ieee80211.h:1.26	Sat Mar 30 10:14:31 2013
+++ src/sys/net80211/ieee80211.h	Wed Apr 27 16:17:00 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211.h,v 1.26 2013/03/30 14:14:31 christos Exp $	*/
+/*	$NetBSD: ieee80211.h,v 1.27 2016/04/27 20:17:00 christos Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -81,6 +81,17 @@ struct ieee80211_qosframe {
 	/* see below */
 } __packed;
 
+struct ieee80211_htframe {		/* 11n */
+	u_int8_t	i_fc[2];
+	u_int8_t	i_dur[2];
+	u_int8_t	i_addr1[IEEE80211_ADDR_LEN];
+	u_int8_t	i_addr2[IEEE80211_ADDR_LEN];
+	u_int8_t	i_addr3[IEEE80211_ADDR_LEN];
+	u_int8_t	i_seq[2];
+	u_int8_t	i_qos[2];
+	u_int8_t	i_ht[4];
+} __packed;
+
 struct ieee80211_qoscntl {
 	u_int8_t	i_qos[2];
 };



CVS commit: src/sys/net80211

2016-04-08 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Fri Apr  8 14:30:47 UTC 2016

Modified Files:
src/sys/net80211: ieee80211_ioctl.h ieee80211_node.c ieee80211_node.h
ieee80211_rssadapt.h ieee80211_var.h

Log Message:
Revert prior.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/net80211/ieee80211_ioctl.h
cvs rdiff -u -r1.70 -r1.71 src/sys/net80211/ieee80211_node.c
cvs rdiff -u -r1.26 -r1.27 src/sys/net80211/ieee80211_node.h
cvs rdiff -u -r1.8 -r1.9 src/sys/net80211/ieee80211_rssadapt.h
cvs rdiff -u -r1.29 -r1.30 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_ioctl.h
diff -u src/sys/net80211/ieee80211_ioctl.h:1.22 src/sys/net80211/ieee80211_ioctl.h:1.23
--- src/sys/net80211/ieee80211_ioctl.h:1.22	Wed Apr  6 14:42:16 2016
+++ src/sys/net80211/ieee80211_ioctl.h	Fri Apr  8 14:30:47 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_ioctl.h,v 1.22 2016/04/06 14:42:16 roy Exp $	*/
+/*	$NetBSD: ieee80211_ioctl.h,v 1.23 2016/04/08 14:30:47 roy Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -356,7 +356,7 @@ struct ieee80211req_sta_info {
 	u_int16_t	isi_flags;		/* channel flags */
 	u_int16_t	isi_state;		/* state flags */
 	u_int8_t	isi_authmode;		/* authentication algorithm */
-	int8_t		isi_rssi;
+	u_int8_t	isi_rssi;
 	u_int8_t	isi_capinfo;		/* capabilities */
 	u_int8_t	isi_erp;		/* ERP element */
 	u_int8_t	isi_macaddr[IEEE80211_ADDR_LEN];
@@ -524,8 +524,8 @@ struct ieee80211req_scan_result {
 	u_int16_t	isr_len;		/* length (mult of 4) */
 	u_int16_t	isr_freq;		/* MHz */
 	u_int16_t	isr_flags;		/* channel flags */
-	int8_t		isr_noise;
-	int8_t		isr_rssi;
+	u_int8_t	isr_noise;
+	u_int8_t	isr_rssi;
 	u_int8_t	isr_intval;		/* beacon interval */
 	u_int8_t	isr_capinfo;		/* capabilities */
 	u_int8_t	isr_erp;		/* ERP element */

Index: src/sys/net80211/ieee80211_node.c
diff -u src/sys/net80211/ieee80211_node.c:1.70 src/sys/net80211/ieee80211_node.c:1.71
--- src/sys/net80211/ieee80211_node.c:1.70	Wed Apr  6 14:42:16 2016
+++ src/sys/net80211/ieee80211_node.c	Fri Apr  8 14:30:47 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_node.c,v 1.70 2016/04/06 14:42:16 roy Exp $	*/
+/*	$NetBSD: ieee80211_node.c,v 1.71 2016/04/08 14:30:47 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_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.70 2016/04/06 14:42:16 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_node.c,v 1.71 2016/04/08 14:30:47 roy Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -85,7 +85,7 @@ __KERNEL_RCSID(0, "$NetBSD: ieee80211_no
 static struct ieee80211_node *node_alloc(struct ieee80211_node_table *);
 static void node_cleanup(struct ieee80211_node *);
 static void node_free(struct ieee80211_node *);
-static int8_t node_getrssi(const struct ieee80211_node *);
+static u_int8_t node_getrssi(const struct ieee80211_node *);
 
 static void ieee80211_setup_node(struct ieee80211_node_table *,
 		struct ieee80211_node *, const u_int8_t *);
@@ -589,7 +589,7 @@ ieee80211_node_compare(struct ieee80211c
 		   const struct ieee80211_node *b)
 {
 	u_int8_t maxa, maxb;
-	int8_t rssia, rssib;
+	u_int8_t rssia, rssib;
 	int weight;
 
 	/* privacy support preferred */
@@ -1001,7 +1001,7 @@ node_free(struct ieee80211_node *ni)
 	free(ni, M_80211_NODE);
 }
 
-static int8_t
+static u_int8_t
 node_getrssi(const struct ieee80211_node *ni)
 {
 	return ni->ni_rssi;
@@ -2347,12 +2347,12 @@ done:
 		ieee80211_free_node(ni);
 }
 
-int8_t
+u_int8_t
 ieee80211_getrssi(struct ieee80211com *ic)
 {
 #define	NZ(x)	((x) == 0 ? 1 : (x))
 	struct ieee80211_node_table *nt = >ic_sta;
-	int32_t rssi_samples, rssi_total;
+	u_int32_t rssi_samples, rssi_total;
 	struct ieee80211_node *ni;
 
 	rssi_total = 0;

Index: src/sys/net80211/ieee80211_node.h
diff -u src/sys/net80211/ieee80211_node.h:1.26 src/sys/net80211/ieee80211_node.h:1.27
--- src/sys/net80211/ieee80211_node.h:1.26	Wed Apr  6 14:42:16 2016
+++ src/sys/net80211/ieee80211_node.h	Fri Apr  8 14:30:47 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_node.h,v 1.26 2016/04/06 14:42:16 roy Exp $	*/
+/*	$NetBSD: ieee80211_node.h,v 1.27 2016/04/08 14:30:47 roy Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -120,7 +120,7 @@ struct ieee80211_node {
 
 	/* hardware */
 	u_int32_t		ni_rstamp;	/* recv timestamp */
-	int8_t			ni_rssi;	/* recv ssi */
+	u_int8_t		ni_rssi;	/* recv ssi */
 
 	/* header */
 	u_int8_t		ni_macaddr[IEEE80211_ADDR_LEN];
@@ -286,7 +286,7 @@ struct ieee80211_node *ieee80211_fakeup_
 		struct ieee80211_node_table *, const u_int8_t macaddr[]);
 void	ieee80211_node_join(struct 

CVS commit: src/sys/net80211

2016-04-06 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Wed Apr  6 14:42:16 UTC 2016

Modified Files:
src/sys/net80211: ieee80211_ioctl.h ieee80211_node.c ieee80211_node.h
ieee80211_rssadapt.h ieee80211_var.h

Log Message:
ieee80211 users in Other OS export rssi and noise as int8_t.
We should not be the odd one out for no good reason and the majority
of the ieee80211 drivers treat rssi as int8_t.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/net80211/ieee80211_ioctl.h
cvs rdiff -u -r1.69 -r1.70 src/sys/net80211/ieee80211_node.c
cvs rdiff -u -r1.25 -r1.26 src/sys/net80211/ieee80211_node.h
cvs rdiff -u -r1.7 -r1.8 src/sys/net80211/ieee80211_rssadapt.h
cvs rdiff -u -r1.28 -r1.29 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_ioctl.h
diff -u src/sys/net80211/ieee80211_ioctl.h:1.21 src/sys/net80211/ieee80211_ioctl.h:1.22
--- src/sys/net80211/ieee80211_ioctl.h:1.21	Sun Sep  6 06:01:01 2015
+++ src/sys/net80211/ieee80211_ioctl.h	Wed Apr  6 14:42:16 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_ioctl.h,v 1.21 2015/09/06 06:01:01 dholland Exp $	*/
+/*	$NetBSD: ieee80211_ioctl.h,v 1.22 2016/04/06 14:42:16 roy Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -356,7 +356,7 @@ struct ieee80211req_sta_info {
 	u_int16_t	isi_flags;		/* channel flags */
 	u_int16_t	isi_state;		/* state flags */
 	u_int8_t	isi_authmode;		/* authentication algorithm */
-	u_int8_t	isi_rssi;
+	int8_t		isi_rssi;
 	u_int8_t	isi_capinfo;		/* capabilities */
 	u_int8_t	isi_erp;		/* ERP element */
 	u_int8_t	isi_macaddr[IEEE80211_ADDR_LEN];
@@ -524,8 +524,8 @@ struct ieee80211req_scan_result {
 	u_int16_t	isr_len;		/* length (mult of 4) */
 	u_int16_t	isr_freq;		/* MHz */
 	u_int16_t	isr_flags;		/* channel flags */
-	u_int8_t	isr_noise;
-	u_int8_t	isr_rssi;
+	int8_t		isr_noise;
+	int8_t		isr_rssi;
 	u_int8_t	isr_intval;		/* beacon interval */
 	u_int8_t	isr_capinfo;		/* capabilities */
 	u_int8_t	isr_erp;		/* ERP element */

Index: src/sys/net80211/ieee80211_node.c
diff -u src/sys/net80211/ieee80211_node.c:1.69 src/sys/net80211/ieee80211_node.c:1.70
--- src/sys/net80211/ieee80211_node.c:1.69	Mon Aug 24 22:21:26 2015
+++ src/sys/net80211/ieee80211_node.c	Wed Apr  6 14:42:16 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_node.c,v 1.69 2015/08/24 22:21:26 pooka Exp $	*/
+/*	$NetBSD: ieee80211_node.c,v 1.70 2016/04/06 14:42:16 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_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.69 2015/08/24 22:21:26 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_node.c,v 1.70 2016/04/06 14:42:16 roy Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -85,7 +85,7 @@ __KERNEL_RCSID(0, "$NetBSD: ieee80211_no
 static struct ieee80211_node *node_alloc(struct ieee80211_node_table *);
 static void node_cleanup(struct ieee80211_node *);
 static void node_free(struct ieee80211_node *);
-static u_int8_t node_getrssi(const struct ieee80211_node *);
+static int8_t node_getrssi(const struct ieee80211_node *);
 
 static void ieee80211_setup_node(struct ieee80211_node_table *,
 		struct ieee80211_node *, const u_int8_t *);
@@ -589,7 +589,7 @@ ieee80211_node_compare(struct ieee80211c
 		   const struct ieee80211_node *b)
 {
 	u_int8_t maxa, maxb;
-	u_int8_t rssia, rssib;
+	int8_t rssia, rssib;
 	int weight;
 
 	/* privacy support preferred */
@@ -1001,7 +1001,7 @@ node_free(struct ieee80211_node *ni)
 	free(ni, M_80211_NODE);
 }
 
-static u_int8_t
+static int8_t
 node_getrssi(const struct ieee80211_node *ni)
 {
 	return ni->ni_rssi;
@@ -2347,12 +2347,12 @@ done:
 		ieee80211_free_node(ni);
 }
 
-u_int8_t
+int8_t
 ieee80211_getrssi(struct ieee80211com *ic)
 {
 #define	NZ(x)	((x) == 0 ? 1 : (x))
 	struct ieee80211_node_table *nt = >ic_sta;
-	u_int32_t rssi_samples, rssi_total;
+	int32_t rssi_samples, rssi_total;
 	struct ieee80211_node *ni;
 
 	rssi_total = 0;

Index: src/sys/net80211/ieee80211_node.h
diff -u src/sys/net80211/ieee80211_node.h:1.25 src/sys/net80211/ieee80211_node.h:1.26
--- src/sys/net80211/ieee80211_node.h:1.25	Sat Oct 18 08:33:29 2014
+++ src/sys/net80211/ieee80211_node.h	Wed Apr  6 14:42:16 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_node.h,v 1.25 2014/10/18 08:33:29 snj Exp $	*/
+/*	$NetBSD: ieee80211_node.h,v 1.26 2016/04/06 14:42:16 roy Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -120,7 +120,7 @@ struct ieee80211_node {
 
 	/* hardware */
 	u_int32_t		ni_rstamp;	/* recv timestamp */
-	u_int8_t		ni_rssi;	/* recv ssi */
+	int8_t			ni_rssi;	/* recv ssi */
 
 	/* header */
 	u_int8_t		

CVS commit: src/sys/net80211

2015-08-24 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Aug 24 20:58:47 UTC 2015

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

Log Message:
+ include opt_inet.h for INET (or lack thereof)
+ include net/in_ether.h, not netinet/in_ether.h
  (did not cause a meltdown only because opt_inet.h was missing)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/net80211/ieee80211_amrr.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_amrr.c
diff -u src/sys/net80211/ieee80211_amrr.c:1.2 src/sys/net80211/ieee80211_amrr.c:1.3
--- src/sys/net80211/ieee80211_amrr.c:1.2	Tue Dec 11 12:40:10 2007
+++ src/sys/net80211/ieee80211_amrr.c	Mon Aug 24 20:58:47 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_amrr.c,v 1.2 2007/12/11 12:40:10 lukem Exp $	*/
+/*	$NetBSD: ieee80211_amrr.c,v 1.3 2015/08/24 20:58:47 pooka Exp $	*/
 /*	$OpenBSD: ieee80211_amrr.c,v 1.1 2006/06/17 19:07:19 damien Exp $	*/
 
 /*-
@@ -19,7 +19,11 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ieee80211_amrr.c,v 1.2 2007/12/11 12:40:10 lukem Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211_amrr.c,v 1.3 2015/08/24 20:58:47 pooka Exp $);
+
+#ifdef _KERNEL_OPT
+#include opt_inet.h
+#endif
 
 #include sys/param.h
 #include sys/kernel.h
@@ -27,11 +31,11 @@ __KERNEL_RCSID(0, $NetBSD: ieee80211_am
 #include sys/sysctl.h
 
 #include net/if.h
+#include net/if_ether.h
 #include net/if_media.h
 
 #ifdef INET
 #include netinet/in.h
-#include netinet/if_ether.h
 #endif
 
 #include net80211/ieee80211.h



CVS commit: src/sys/net80211

2014-04-06 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Apr  7 00:07:40 UTC 2014

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

Log Message:
Use module-compatible sysctl init instead of link sets.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/net80211/ieee80211_netbsd.c
cvs rdiff -u -r1.18 -r1.19 src/sys/net80211/ieee80211_netbsd.h \
src/sys/net80211/ieee80211_rssadapt.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.25 src/sys/net80211/ieee80211_netbsd.c:1.26
--- src/sys/net80211/ieee80211_netbsd.c:1.25	Tue Feb 25 18:30:12 2014
+++ src/sys/net80211/ieee80211_netbsd.c	Mon Apr  7 00:07:40 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: ieee80211_netbsd.c,v 1.25 2014/02/25 18:30:12 pooka Exp $ */
+/* $NetBSD: ieee80211_netbsd.c,v 1.26 2014/04/07 00:07:40 pooka Exp $ */
 /*-
  * Copyright (c) 2003-2005 Sam Leffler, Errno Consulting
  * All rights reserved.
@@ -30,7 +30,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.25 2014/02/25 18:30:12 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211_netbsd.c,v 1.26 2014/04/07 00:07:40 pooka Exp $);
 #endif
 
 /*
@@ -68,6 +68,8 @@ static struct ieee80211_node *ieee80211_
 struct ieee80211_node_walk *, u_short);
 static int ieee80211_sysctl_node(SYSCTLFN_ARGS);
 
+static void ieee80211_sysctl_setup(void);
+
 #ifdef IEEE80211_DEBUG
 int	ieee80211_debug = 0;
 #endif
@@ -81,6 +83,8 @@ ieee80211_init0(void)
 {
 	ieee80211_setup_func * const *ieee80211_setup, f;
 
+	ieee80211_sysctl_setup();
+
 	if (max_linkhdr  ALIGN(sizeof(struct ieee80211_qosframe_addr4))) {
 		max_linkhdr = ALIGN(sizeof(struct ieee80211_qosframe_addr4));
 	}
@@ -459,28 +463,32 @@ cleanup:
  *
  * TBD condition CTLFLAG_PERMANENT on being a module or not
  */
-SYSCTL_SETUP(sysctl_ieee80211, sysctl ieee80211 subtree setup)
+static struct sysctllog *ieee80211_sysctllog;
+static void
+ieee80211_sysctl_setup(void)
 {
 	int rc;
 	const struct sysctlnode *cnode, *rnode;
 
-	if ((rnode = ieee80211_sysctl_treetop(clog)) == NULL)
+	if ((rnode = ieee80211_sysctl_treetop(ieee80211_sysctllog)) == NULL)
 		return;
 
-	if ((rc = sysctl_createv(clog, 0, rnode, NULL,
+	if ((rc = sysctl_createv(ieee80211_sysctllog, 0, rnode, NULL,
 	CTLFLAG_PERMANENT, CTLTYPE_NODE, nodes, client/peer stations,
 	ieee80211_sysctl_node, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
 		goto err;
 
 #ifdef IEEE80211_DEBUG
 	/* control debugging printfs */
-	if ((rc = sysctl_createv(clog, 0, rnode, cnode,
+	if ((rc = sysctl_createv(ieee80211_sysctllog, 0, rnode, cnode,
 	CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT,
 	debug, SYSCTL_DESCR(control debugging printfs),
 	NULL, 0, ieee80211_debug, 0, CTL_CREATE, CTL_EOL)) != 0)
 		goto err;
 #endif /* IEEE80211_DEBUG */
 
+	ieee80211_rssadapt_sysctl_setup(ieee80211_sysctllog);
+
 	return;
 err:
 	printf(%s: sysctl_createv failed (rc = %d)\n, __func__, rc);

Index: src/sys/net80211/ieee80211_netbsd.h
diff -u src/sys/net80211/ieee80211_netbsd.h:1.18 src/sys/net80211/ieee80211_netbsd.h:1.19
--- src/sys/net80211/ieee80211_netbsd.h:1.18	Thu Jun 27 17:47:18 2013
+++ src/sys/net80211/ieee80211_netbsd.h	Mon Apr  7 00:07:40 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: ieee80211_netbsd.h,v 1.18 2013/06/27 17:47:18 christos Exp $ */
+/* $NetBSD: ieee80211_netbsd.h,v 1.19 2014/04/07 00:07:40 pooka Exp $ */
 /*-
  * Copyright (c) 2003-2005 Sam Leffler, Errno Consulting
  * All rights reserved.
@@ -240,6 +240,8 @@ void	ieee80211_sysctl_attach(struct ieee
 void	ieee80211_sysctl_detach(struct ieee80211com *);
 void	ieee80211_load_module(const char *);
 
+void	ieee80211_rssadapt_sysctl_setup(struct sysctllog **);
+
 void	ieee80211_init(void);
 #define	IEEE80211_CRYPTO_SETUP(name)\
 	static void name(void);	\
Index: src/sys/net80211/ieee80211_rssadapt.c
diff -u src/sys/net80211/ieee80211_rssadapt.c:1.18 src/sys/net80211/ieee80211_rssadapt.c:1.19
--- src/sys/net80211/ieee80211_rssadapt.c:1.18	Tue Feb 25 18:30:12 2014
+++ src/sys/net80211/ieee80211_rssadapt.c	Mon Apr  7 00:07:40 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: ieee80211_rssadapt.c,v 1.18 2014/02/25 18:30:12 pooka Exp $ */
+/* $NetBSD: ieee80211_rssadapt.c,v 1.19 2014/04/07 00:07:40 pooka Exp $ */
 /*-
  * Copyright (c) 2003, 2004 David Young.  All rights reserved.
  *
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, $NetBSD: ieee80211_rssadapt.c,v 1.18 2014/02/25 18:30:12 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211_rssadapt.c,v 1.19 2014/04/07 00:07:40 pooka Exp $);
 #endif
 
 #include sys/param.h
@@ -141,8 +141,8 @@ sysctl_ieee80211_rssadapt_expavgctl(SYSC
  *
  * TBD condition CTLFLAG_PERMANENT on being a module or not
  */

CVS commit: src/sys/net80211

2014-01-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jan 25 00:59:44 UTC 2014

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

Log Message:
fix monitor mode channel.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 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.58 src/sys/net80211/ieee80211_ioctl.c:1.59
--- src/sys/net80211/ieee80211_ioctl.c:1.58	Thu Sep 12 16:44:02 2013
+++ src/sys/net80211/ieee80211_ioctl.c	Fri Jan 24 19:59:44 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_ioctl.c,v 1.58 2013/09/12 20:44:02 martin Exp $	*/
+/*	$NetBSD: ieee80211_ioctl.c,v 1.59 2014/01/25 00:59:44 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.58 2013/09/12 20:44:02 martin Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211_ioctl.c,v 1.59 2014/01/25 00:59:44 christos Exp $);
 #endif
 
 /*
@@ -2837,6 +2837,9 @@ ieee80211_ioctl(struct ieee80211com *ic,
 if (ic-ic_des_chan != IEEE80211_CHAN_ANYC 
 ic-ic_bss-ni_chan != ic-ic_des_chan)
 	error = ENETRESET;
+			} else if (ic-ic_opmode == IEEE80211_M_MONITOR) {
+ic-ic_curchan = ic-ic_ibss_chan;
+error = ENETRESET;
 			} else {
 if (ic-ic_bss-ni_chan != ic-ic_ibss_chan)
 	error = ENETRESET;



CVS commit: src/sys/net80211

2013-09-12 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Sep 12 20:44:02 UTC 2013

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

Log Message:
Fix return value of ieee80211_ioctl_setoptie


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 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.57 src/sys/net80211/ieee80211_ioctl.c:1.58
--- src/sys/net80211/ieee80211_ioctl.c:1.57	Sat Dec 31 20:41:58 2011
+++ src/sys/net80211/ieee80211_ioctl.c	Thu Sep 12 20:44:02 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_ioctl.c,v 1.57 2011/12/31 20:41:58 christos Exp $	*/
+/*	$NetBSD: ieee80211_ioctl.c,v 1.58 2013/09/12 20:44:02 martin 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.57 2011/12/31 20:41:58 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211_ioctl.c,v 1.58 2013/09/12 20:44:02 martin Exp $);
 #endif
 
 /*
@@ -1615,7 +1615,7 @@ ieee80211_ioctl_setoptie(struct ieee8021
 		free(ic-ic_opt_ie, M_DEVBUF);
 	ic-ic_opt_ie = ie;
 	ic-ic_opt_ie_len = ireq-i_len;
-	return 0;
+	return error;
 }
 
 static int



CVS commit: src/sys/net80211

2013-03-30 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Mar 30 19:03:03 UTC 2013

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

Log Message:
Putting extra l's in align does not make it more so.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 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.75 src/sys/net80211/ieee80211_input.c:1.76
--- src/sys/net80211/ieee80211_input.c:1.75	Sat Mar 30 11:12:28 2013
+++ src/sys/net80211/ieee80211_input.c	Sat Mar 30 15:03:02 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.75 2013/03/30 15:12:28 christos Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.76 2013/03/30 19:03:02 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_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.75 2013/03/30 15:12:28 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211_input.c,v 1.76 2013/03/30 19:03:02 christos Exp $);
 #endif
 
 #include opt_inet.h
@@ -1340,7 +1340,7 @@ ieee80211_ssid_mismatch(struct ieee80211
 } while (0)
 #endif /* !IEEE80211_DEBUG */
 
-/* unalligned little endian access */   
+/* unaligned little endian access */
 #define LE_READ_2(p)	\
 	((u_int16_t)	\
 	 const u_int8_t *)(p))[0]  ) |		\



CVS commit: src/sys/net80211

2013-03-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Mar 30 01:05:49 UTC 2013

Modified Files:
src/sys/net80211: ieee80211.h ieee80211_proto.h

Log Message:
EDCA and QOS additions from OpenBSD


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/net80211/ieee80211.h
cvs rdiff -u -r1.19 -r1.20 src/sys/net80211/ieee80211_proto.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.22 src/sys/net80211/ieee80211.h:1.23
--- src/sys/net80211/ieee80211.h:1.22	Mon Aug 20 03:30:10 2012
+++ src/sys/net80211/ieee80211.h	Fri Mar 29 21:05:48 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211.h,v 1.22 2012/08/20 07:30:10 christos Exp $	*/
+/*	$NetBSD: ieee80211.h,v 1.23 2013/03/30 01:05:48 christos Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -149,6 +149,21 @@ struct ieee80211_qosframe_addr4 {
 #define	IEEE80211_FC0_SUBTYPE_QOS		0x80
 #define	IEEE80211_FC0_SUBTYPE_QOS_NULL		0xc0
 
+/*
+ * DS bit usage
+ *
+ * TA = transmitter address
+ * RA = receiver address
+ * DA = destination address
+ * SA = source address
+ *
+ * ToDSFromDS  A1(RA)  A2(TA)  A3  A4  Use
+ * -
+ *  0   0   DA  SA  BSSID   -   IBSS/DLS
+ *  0   1   DA  BSSID   SA  -   AP - STA
+ *  1   0   BSSID   SA  DA  -   AP - STA
+ *  1   1   RA  TA  DA  SA  unspecified (WDS)
+ */
 #define	IEEE80211_FC1_DIR_MASK			0x03
 #define	IEEE80211_FC1_DIR_NODS			0x00	/* STA-STA */
 #define	IEEE80211_FC1_DIR_TODS			0x01	/* STA-AP  */
@@ -188,12 +203,24 @@ struct ieee80211_qosframe_addr4 {
 #define	IEEE80211_QOS_TID			0x000f
 
 /* does frame have QoS sequence control data */
+/* XXX: use ieee80211_has_qos() instead */
 #define	IEEE80211_QOS_HAS_SEQ(wh) \
 	(((wh)-i_fc[0]  \
 	  (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_QOS)) == \
 	  (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS))
 
 /*
+ * EDCA Access Categories.
+ */
+enum ieee80211_edca_ac {
+	EDCA_AC_BK  = 1,	/* Background */
+	EDCA_AC_BE  = 0,	/* Best Effort */
+	EDCA_AC_VI  = 2,	/* Video */
+	EDCA_AC_VO  = 3		/* Voice */
+};
+#define EDCA_NUM_AC	4
+
+/*
  * WME/802.11e information element.
  */
 struct ieee80211_wme_info {
@@ -346,6 +373,50 @@ struct ieee80211_frame_cfend {		/* NB: a
 	/* FCS */
 } __packed;
 
+static __inline int
+ieee80211_has_seq(const struct ieee80211_frame *wh)
+{
+	return (wh-i_fc[0]  IEEE80211_FC0_TYPE_MASK) !=
+	IEEE80211_FC0_TYPE_CTL;
+}
+
+static __inline int
+ieee80211_has_addr4(const struct ieee80211_frame *wh)
+{
+	return (wh-i_fc[1]  IEEE80211_FC1_DIR_MASK) ==
+	IEEE80211_FC1_DIR_DSTODS;
+}
+
+static __inline int
+ieee80211_has_qos(const struct ieee80211_frame *wh)
+{
+	return (wh-i_fc[0] 
+	(IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_QOS)) ==
+	(IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS);
+}
+
+static __inline int
+ieee80211_has_htc(const struct ieee80211_frame *wh)
+{
+	return (wh-i_fc[1]  IEEE80211_FC1_ORDER) 
+	(ieee80211_has_qos(wh) ||
+	 (wh-i_fc[0]  IEEE80211_FC0_TYPE_MASK) ==
+	 IEEE80211_FC0_TYPE_MGT);
+}
+
+static __inline u_int16_t
+ieee80211_get_qos(const struct ieee80211_frame *wh)
+{
+	const u_int8_t *frm;
+
+	if (ieee80211_has_addr4(wh))
+		frm = ((const struct ieee80211_qosframe_addr4 *)wh)-i_qos;
+	else
+		frm = ((const struct ieee80211_qosframe *)wh)-i_qos;
+
+	return le16toh(*(const u_int16_t *)frm);
+}
+
 /*
  * BEACON management packets
  *

Index: src/sys/net80211/ieee80211_proto.h
diff -u src/sys/net80211/ieee80211_proto.h:1.19 src/sys/net80211/ieee80211_proto.h:1.20
--- src/sys/net80211/ieee80211_proto.h:1.19	Thu Jan 10 12:40:10 2013
+++ src/sys/net80211/ieee80211_proto.h	Fri Mar 29 21:05:48 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_proto.h,v 1.19 2013/01/10 17:40:10 christos Exp $	*/
+/*	$NetBSD: ieee80211_proto.h,v 1.20 2013/03/30 01:05:48 christos Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -223,7 +223,7 @@ void	ieee80211_wme_updateparams_locked(s
 
 #define	ieee80211_new_state(_ic, _nstate, _arg) \
 	(((_ic)-ic_newstate)((_ic), (_nstate), (_arg)))
-extern	int ieee80211_compute_duration(const struct ieee80211_frame_min *,
+int	ieee80211_compute_duration(const struct ieee80211_frame_min *,
 		const struct ieee80211_key *, int,
 		uint32_t, int, int, struct ieee80211_duration *,
 		struct ieee80211_duration *, int *, int);
@@ -263,4 +263,5 @@ void	ieee80211_notify_node_join(struct i
 void	ieee80211_notify_node_leave(struct ieee80211com *,
 		struct ieee80211_node *);
 void	ieee80211_notify_scan_done(struct ieee80211com *);
+
 #endif /* !_NET80211_IEEE80211_PROTO_H_ */



CVS commit: src/sys/net80211

2013-03-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Mar 30 01:06:38 UTC 2013

Modified Files:
src/sys/net80211: ieee80211.h ieee80211_proto.h

Log Message:
remove trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/net80211/ieee80211.h
cvs rdiff -u -r1.20 -r1.21 src/sys/net80211/ieee80211_proto.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.23 src/sys/net80211/ieee80211.h:1.24
--- src/sys/net80211/ieee80211.h:1.23	Fri Mar 29 21:05:48 2013
+++ src/sys/net80211/ieee80211.h	Fri Mar 29 21:06:37 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211.h,v 1.23 2013/03/30 01:05:48 christos Exp $	*/
+/*	$NetBSD: ieee80211.h,v 1.24 2013/03/30 01:06:37 christos Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -52,7 +52,7 @@ struct ieee80211_plcp_hdr {
 	u_int16_t	i_crc;
 } __packed;
 
-#define IEEE80211_PLCP_SFD  0xF3A0 
+#define IEEE80211_PLCP_SFD  0xF3A0
 #define IEEE80211_PLCP_SERVICE  0x00
 
 /*
@@ -723,7 +723,7 @@ enum {
 
 #define	IEEE80211_AID(b)	((b) ~ 0xc000)
 
-/* 
+/*
  * RTS frame length parameters.  The default is specified in
  * the 802.11 spec as 512; we treat it as implementation-dependent
  * so it's defined in ieee80211_var.h.  The max may be wrong
@@ -732,7 +732,7 @@ enum {
 #define	IEEE80211_RTS_MIN		1
 #define	IEEE80211_RTS_MAX		2346
 
-/* 
+/*
  * TX fragmentation parameters.  As above for RTS, we treat
  * default as implementation-dependent so define it elsewhere.
  */

Index: src/sys/net80211/ieee80211_proto.h
diff -u src/sys/net80211/ieee80211_proto.h:1.20 src/sys/net80211/ieee80211_proto.h:1.21
--- src/sys/net80211/ieee80211_proto.h:1.20	Fri Mar 29 21:05:48 2013
+++ src/sys/net80211/ieee80211_proto.h	Fri Mar 29 21:06:37 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_proto.h,v 1.20 2013/03/30 01:05:48 christos Exp $	*/
+/*	$NetBSD: ieee80211_proto.h,v 1.21 2013/03/30 01:06:37 christos Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -82,7 +82,7 @@ struct mbuf *ieee80211_get_rts(struct ie
 		const struct ieee80211_frame *, uint16_t);
 struct mbuf *ieee80211_get_cts_to_self(struct ieee80211com *,
 		uint16_t);
-void	ieee80211_pwrsave(struct ieee80211com *, struct ieee80211_node *, 
+void	ieee80211_pwrsave(struct ieee80211com *, struct ieee80211_node *,
 		struct mbuf *);
 
 void	ieee80211_reset_erp(struct ieee80211com *);



CVS commit: src/sys/net80211

2013-03-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Mar 30 03:24:55 UTC 2013

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

Log Message:
remove trailing space


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/net80211/ieee80211_crypto_ccmp.c
cvs rdiff -u -r1.73 -r1.74 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_crypto_ccmp.c
diff -u src/sys/net80211/ieee80211_crypto_ccmp.c:1.8 src/sys/net80211/ieee80211_crypto_ccmp.c:1.9
--- src/sys/net80211/ieee80211_crypto_ccmp.c:1.8	Wed Dec 17 15:51:37 2008
+++ src/sys/net80211/ieee80211_crypto_ccmp.c	Fri Mar 29 23:24:55 2013
@@ -34,7 +34,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.8 2008/12/17 20:51:37 cegger Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211_crypto_ccmp.c,v 1.9 2013/03/30 03:24:55 christos Exp $);
 #endif
 
 /*
@@ -45,8 +45,8 @@ __KERNEL_RCSID(0, $NetBSD: ieee80211_cr
  * it's license is included below.
  */
 #include sys/param.h
-#include sys/systm.h 
-#include sys/mbuf.h   
+#include sys/systm.h
+#include sys/mbuf.h  
 #include sys/malloc.h
 #include sys/kernel.h
 

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.73 src/sys/net80211/ieee80211_input.c:1.74
--- src/sys/net80211/ieee80211_input.c:1.73	Thu Jan 10 12:40:10 2013
+++ src/sys/net80211/ieee80211_input.c	Fri Mar 29 23:24:55 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.73 2013/01/10 17:40:10 christos Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.74 2013/03/30 03:24:55 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_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.73 2013/01/10 17:40:10 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211_input.c,v 1.74 2013/03/30 03:24:55 christos Exp $);
 #endif
 
 #include opt_inet.h
@@ -46,11 +46,11 @@ __KERNEL_RCSID(0, $NetBSD: ieee80211_in
 
 #include sys/param.h
 #include sys/systm.h
-#include sys/mbuf.h   
+#include sys/mbuf.h  
 #include sys/malloc.h
 #include sys/endian.h
 #include sys/kernel.h
- 
+
 #include sys/socket.h
 #include sys/sockio.h
 #include sys/endian.h
@@ -70,7 +70,7 @@ __KERNEL_RCSID(0, $NetBSD: ieee80211_in
 #include net/bpf.h
 
 #ifdef INET
-#include netinet/in.h 
+#include netinet/in.h
 #include net/if_ether.h
 #endif
 
@@ -919,7 +919,7 @@ ieee80211_auth_open(struct ieee80211com 
 		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, 
+			ieee80211_send_error(ic, ni, wh-i_addr2,
 			IEEE80211_FC0_SUBTYPE_AUTH,
 			(seq + 1) | (IEEE80211_STATUS_ALG16));
 		}
@@ -1340,7 +1340,7 @@ ieee80211_ssid_mismatch(struct ieee80211
 } while (0)
 #endif /* !IEEE80211_DEBUG */
 
-/* unalligned little endian access */ 
+/* unalligned little endian access */
 #define LE_READ_2(p)	\
 	((u_int16_t)	\
 	 const u_int8_t *)(p))[0]  ) |		\
@@ -1618,7 +1618,7 @@ ieee80211_parse_rsn(struct ieee80211com 
 	int n;
 
 	/*
-	 * Check the length once for fixed parts: 
+	 * Check the length once for fixed parts:
 	 * version, mcast cipher, and 2 selector counts.
 	 * Other, variable-length data, must be checked separately.
 	 */
@@ -1686,7 +1686,7 @@ ieee80211_parse_rsn(struct ieee80211com 
 	n = LE_READ_2(frm);
 	frm += 2, len -= 2;
 	if (len  n*4) {
-		IEEE80211_DISCARD_IE(ic, 
+		IEEE80211_DISCARD_IE(ic,
 		IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
 		wh, RSN, key mgmt alg data too short; len %u, n %u,
 		len, n);
@@ -1861,7 +1861,7 @@ ieee80211_recv_mgmt(struct ieee80211com 
 		 *  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)) {
@@ -2249,7 +2249,7 @@ ieee80211_recv_mgmt(struct ieee80211com 
 			}
 #endif /* !IEEE80211_NO_HOSTAP */
 			return;
-		} 
+		}
 		break;
 	}
 
@@ -2348,7 +2348,7 @@ ieee80211_recv_mgmt(struct ieee80211com 
 			ieee80211_node_leave(ic, ni);
 			/* XXX distinguish WPA/RSN? */
 			ic-ic_stats.is_rx_assoc_badwpaie++;
-			return;	
+			return;
 		}
 		if (wpa != NULL) {
 			/*
@@ -2723,7 +2723,7 @@ ieee80211_node_pwrsave(struct ieee80211_
 		IEEE80211_NODE_SAVEQ_DEQUEUE(ni, m, qlen);
 		if (m == NULL)
 			break;
-		/* 
+		/*
 		 * If this is the last packet, turn off the TIM bit.
 		 * If there are more 

CVS commit: src/sys/net80211

2013-03-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Mar 30 03:25:47 UTC 2013

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

Log Message:
remove obsolete macro


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 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.24 src/sys/net80211/ieee80211.h:1.25
--- src/sys/net80211/ieee80211.h:1.24	Fri Mar 29 21:06:37 2013
+++ src/sys/net80211/ieee80211.h	Fri Mar 29 23:25:47 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211.h,v 1.24 2013/03/30 01:06:37 christos Exp $	*/
+/*	$NetBSD: ieee80211.h,v 1.25 2013/03/30 03:25:47 christos Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -202,13 +202,6 @@ struct ieee80211_qosframe_addr4 {
 #define	IEEE80211_QOS_ESOP_S			4
 #define	IEEE80211_QOS_TID			0x000f
 
-/* does frame have QoS sequence control data */
-/* XXX: use ieee80211_has_qos() instead */
-#define	IEEE80211_QOS_HAS_SEQ(wh) \
-	(((wh)-i_fc[0]  \
-	  (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_QOS)) == \
-	  (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS))
-
 /*
  * EDCA Access Categories.
  */



CVS commit: src/sys/net80211

2013-03-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Mar 29 02:20:17 UTC 2013

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

Log Message:
trailing blanks police.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 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.64 src/sys/net80211/ieee80211_node.c:1.65
--- src/sys/net80211/ieee80211_node.c:1.64	Thu Jan 10 12:40:10 2013
+++ src/sys/net80211/ieee80211_node.c	Thu Mar 28 22:20:17 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_node.c,v 1.64 2013/01/10 17:40:10 christos Exp $	*/
+/*	$NetBSD: ieee80211_node.c,v 1.65 2013/03/29 02:20:17 christos Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,14 +36,14 @@
 __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.64 2013/01/10 17:40:10 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211_node.c,v 1.65 2013/03/29 02:20:17 christos Exp $);
 #endif
 
 #include opt_inet.h
 
 #include sys/param.h
-#include sys/systm.h 
-#include sys/mbuf.h   
+#include sys/systm.h
+#include sys/mbuf.h
 #include sys/malloc.h
 #include sys/kernel.h
 
@@ -66,7 +66,7 @@ __KERNEL_RCSID(0, $NetBSD: ieee80211_no
 #include net/bpf.h
 
 #ifdef INET
-#include netinet/in.h 
+#include netinet/in.h
 #include net/if_ether.h
 #endif
 
@@ -213,7 +213,7 @@ ieee80211_node_detach(struct ieee80211co
 	}
 }
 
-/* 
+/*
  * Port authorize/unauthorize interfaces for use by an authenticator.
  */
 
@@ -453,7 +453,7 @@ 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);
@@ -763,7 +763,7 @@ ieee80211_end_scan(struct ieee80211com *
 		goto notfound;
 	}
 }
- 
+
 /*
  * Handle 802.11 ad hoc network merge.  The
  * convention, set by the Wireless Ethernet Compatibility Alliance
@@ -846,7 +846,7 @@ ieee80211_sta_join(struct ieee80211com *
 	 * Set the erp state (mostly the slot time) to deal with
 	 * the auto-select case; this should be redundant if the
 	 * mode is locked.
-	 */ 
+	 */
 	ic-ic_curmode = ieee80211_chan2mode(ic, selbs-ni_chan);
 	ic-ic_curchan = selbs-ni_chan;
 	ieee80211_reset_erp(ic);
@@ -1199,7 +1199,7 @@ dump_probe_beacon(u_int8_t subtype, int 
 	printf(\n);
 
 	if (isnew) {
-		printf([%s] caps 0x%x bintval %u erp 0x%x, 
+		printf([%s] caps 0x%x bintval %u erp 0x%x,
 			ether_sprintf(mac), sp-capinfo, sp-bintval, sp-erp);
 		if (sp-country != NULL) {
 #ifdef __FreeBSD__
@@ -1374,7 +1374,7 @@ ieee80211_add_neighbor(struct ieee80211c
  * are required to pass some node so we fall back to ic_bss
  * when this frame is from an unknown sender.  The 802.11 layer
  * knows this means the sender wasn't in the node table and
- * acts accordingly. 
+ * acts accordingly.
  */
 struct ieee80211_node *
 #ifdef IEEE80211_DEBUG_REFCNT



CVS commit: src/sys/net80211

2013-03-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Mar 29 02:26:45 UTC 2013

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

Log Message:
Don't hold 2 locks at the same time, causes lockdebug panic. Triggered by
running usb wifi interfaces as access points. What we do instead is check
the generation number upon restart, and if it changed we give up.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 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.65 src/sys/net80211/ieee80211_node.c:1.66
--- src/sys/net80211/ieee80211_node.c:1.65	Thu Mar 28 22:20:17 2013
+++ src/sys/net80211/ieee80211_node.c	Thu Mar 28 22:26:45 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_node.c,v 1.65 2013/03/29 02:20:17 christos Exp $	*/
+/*	$NetBSD: ieee80211_node.c,v 1.66 2013/03/29 02:26:45 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_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.65 2013/03/29 02:20:17 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211_node.c,v 1.66 2013/03/29 02:26:45 christos Exp $);
 #endif
 
 #include opt_inet.h
@@ -1908,9 +1908,18 @@ ieee80211_timeout_stations(struct ieee80
 		   ic-ic_opmode == IEEE80211_M_AHDEMO);
 	IEEE80211_SCAN_LOCK(nt);
 	gen = ++nt-nt_scangen;
+	IEEE80211_SCAN_UNLOCK(nt);
 	IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE,
 		%s: %s scangen %u\n, __func__, nt-nt_name, gen);
 restart:
+	IEEE80211_SCAN_LOCK(nt);
+	if (gen != nt-nt_scangen) {
+		printf(%s: scan aborted %u\n, __func__, gen);
+		IEEE80211_SCAN_UNLOCK(nt);
+		return;
+	}
+	IEEE80211_SCAN_UNLOCK(nt);
+
 	IEEE80211_NODE_LOCK(nt);
 	TAILQ_FOREACH(ni, nt-nt_node, ni_list) {
 		if (ni-ni_scangen == gen)	/* previously handled */
@@ -2039,8 +2048,6 @@ IEEE80211_DPRINTF(ic, IEEE80211_MSG_POWE
 	}
 	IEEE80211_NODE_UNLOCK(nt);
 
-	IEEE80211_SCAN_UNLOCK(nt);
-
 	nt-nt_inact_timer = IEEE80211_INACT_WAIT;
 }
 
@@ -2052,7 +2059,16 @@ ieee80211_iterate_nodes(struct ieee80211
 
 	IEEE80211_SCAN_LOCK(nt);
 	gen = ++nt-nt_scangen;
+	IEEE80211_SCAN_UNLOCK(nt);
 restart:
+	IEEE80211_SCAN_LOCK(nt);
+	if (gen != nt-nt_scangen) {
+		printf(%s: scan aborted %u\n, __func__, gen);
+		IEEE80211_SCAN_UNLOCK(nt);
+		return;
+	}
+	IEEE80211_SCAN_UNLOCK(nt);
+
 	IEEE80211_NODE_LOCK(nt);
 	TAILQ_FOREACH(ni, nt-nt_node, ni_list) {
 		if (ni-ni_scangen != gen) {
@@ -2065,8 +2081,6 @@ restart:
 		}
 	}
 	IEEE80211_NODE_UNLOCK(nt);
-
-	IEEE80211_SCAN_UNLOCK(nt);
 }
 
 void



CVS commit: src/sys/net80211

2013-03-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Mar 29 02:30:18 UTC 2013

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

Log Message:
one we is enough.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 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.66 src/sys/net80211/ieee80211_node.c:1.67
--- src/sys/net80211/ieee80211_node.c:1.66	Thu Mar 28 22:26:45 2013
+++ src/sys/net80211/ieee80211_node.c	Thu Mar 28 22:30:18 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_node.c,v 1.66 2013/03/29 02:26:45 christos Exp $	*/
+/*	$NetBSD: ieee80211_node.c,v 1.67 2013/03/29 02:30:18 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_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.66 2013/03/29 02:26:45 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211_node.c,v 1.67 2013/03/29 02:30:18 christos Exp $);
 #endif
 
 #include opt_inet.h
@@ -1161,7 +1161,7 @@ ieee80211_find_node(struct ieee80211_nod
 
 /*
  * Fake up a node; this handles node discovery in adhoc mode.
- * Note that for the driver's benefit we we treat this like
+ * Note that for the driver's benefit we treat this like
  * an association so the driver has an opportunity to setup
  * it's private state.
  */



CVS commit: src/sys/net80211

2013-03-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 21 17:10:25 UTC 2013

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

Log Message:
Don't attempt to dereference ANYC (since it is a pointer to 0x1).
Fixes random crashes in hostap mode (race conditions in the interrupt handler
while the interface comes up or down).


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 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.8 src/sys/net80211/_ieee80211.h:1.9
--- src/sys/net80211/_ieee80211.h:1.8	Sat Jan 10 07:53:45 2009
+++ src/sys/net80211/_ieee80211.h	Thu Mar 21 13:10:25 2013
@@ -151,43 +151,35 @@ struct ieee80211_channel {
 #define	IEEE80211_CHAN_ALLTURBO \
 	(IEEE80211_CHAN_ALL | IEEE80211_CHAN_TURBO)
 
-#define	IEEE80211_IS_CHAN_FHSS(_c) \
-	(((_c)-ic_flags  IEEE80211_CHAN_FHSS) == IEEE80211_CHAN_FHSS)
-#define	IEEE80211_IS_CHAN_A(_c) \
-	(((_c)-ic_flags  IEEE80211_CHAN_A) == IEEE80211_CHAN_A)
-#define	IEEE80211_IS_CHAN_B(_c) \
-	(((_c)-ic_flags  IEEE80211_CHAN_B) == IEEE80211_CHAN_B)
-#define	IEEE80211_IS_CHAN_PUREG(_c) \
-	(((_c)-ic_flags  IEEE80211_CHAN_PUREG) == IEEE80211_CHAN_PUREG)
-#define	IEEE80211_IS_CHAN_G(_c) \
-	(((_c)-ic_flags  IEEE80211_CHAN_G) == IEEE80211_CHAN_G)
-#define	IEEE80211_IS_CHAN_ANYG(_c) \
-	(IEEE80211_IS_CHAN_PUREG(_c) || IEEE80211_IS_CHAN_G(_c))
-#define	IEEE80211_IS_CHAN_T(_c) \
-	(((_c)-ic_flags  IEEE80211_CHAN_T) == IEEE80211_CHAN_T)
-#define	IEEE80211_IS_CHAN_108G(_c) \
-	(((_c)-ic_flags  IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G)
-
-#define	IEEE80211_IS_CHAN_2GHZ(_c) \
-	(((_c)-ic_flags  IEEE80211_CHAN_2GHZ) != 0)
-#define	IEEE80211_IS_CHAN_5GHZ(_c) \
-	(((_c)-ic_flags  IEEE80211_CHAN_5GHZ) != 0)
-#define	IEEE80211_IS_CHAN_OFDM(_c) \
-	(((_c)-ic_flags  IEEE80211_CHAN_OFDM) != 0)
-#define	IEEE80211_IS_CHAN_CCK(_c) \
-	(((_c)-ic_flags  IEEE80211_CHAN_CCK) != 0)
-#define	IEEE80211_IS_CHAN_GFSK(_c) \
-	(((_c)-ic_flags  IEEE80211_CHAN_GFSK) != 0)
-#define	IEEE80211_IS_CHAN_HALF(_c) \
-	(((_c)-ic_flags  IEEE80211_CHAN_HALF) != 0)
-#define	IEEE80211_IS_CHAN_QUARTER(_c) \
-	(((_c)-ic_flags  IEEE80211_CHAN_QUARTER) != 0)
+#define IEEE80211_IS_CHAN_ANYC(_c) \
+	((_c) == IEEE80211_CHAN_ANYC)
+
+#define _IEEE80211_IS_CHAN(_c, _ch) \
+	(!IEEE80211_IS_CHAN_ANYC(_c)  \
+	((_c)-ic_flags  IEEE80211_CHAN_ ## _ch) == IEEE80211_CHAN_ ## _ch)
+
+#define	IEEE80211_IS_CHAN_FHSS(_c)	_IEEE80211_IS_CHAN(_c, FHSS)
+#define	IEEE80211_IS_CHAN_A(_c)		_IEEE80211_IS_CHAN(_c, A)
+#define	IEEE80211_IS_CHAN_B(_c)		_IEEE80211_IS_CHAN(_c, B)
+#define	IEEE80211_IS_CHAN_PUREG(_c)	_IEEE80211_IS_CHAN(_c, PUREG)
+#define	IEEE80211_IS_CHAN_G(_c)		_IEEE80211_IS_CHAN(_c, G)
+#define	IEEE80211_IS_CHAN_ANYG(_c)	_IEEE80211_IS_CHAN(_c, ANYG)
+#define	IEEE80211_IS_CHAN_T(_c)		_IEEE80211_IS_CHAN(_c, T)
+#define	IEEE80211_IS_CHAN_108G(_c)	_IEEE80211_IS_CHAN(_c, 108G)
+
+#define	IEEE80211_IS_CHAN_2GHZ(_c) 	_IEEE80211_IS_CHAN(_c, 2GHZ)
+#define	IEEE80211_IS_CHAN_5GHZ(_c) 	_IEEE80211_IS_CHAN(_c, 5GHZ)
+#define	IEEE80211_IS_CHAN_OFDM(_c) 	_IEEE80211_IS_CHAN(_c, OFDM)
+#define	IEEE80211_IS_CHAN_CCK(_c) 	_IEEE80211_IS_CHAN(_c, CCK)
+#define	IEEE80211_IS_CHAN_GFSK(_c) 	_IEEE80211_IS_CHAN(_c, GFSK)
+#define	IEEE80211_IS_CHAN_HALF(_c) 	_IEEE80211_IS_CHAN(_c, HALF)
+#define	IEEE80211_IS_CHAN_QUARTER(_c) 	_IEEE80211_IS_CHAN(_c, QUARTER)
 #define	IEEE80211_IS_CHAN_FULL(_c) \
-	(((_c)-ic_flags  (IEEE80211_CHAN_QUARTER | IEEE80211_CHAN_HALF)) == 0)
-#define	IEEE80211_IS_CHAN_GSM(_c) \
-	(((_c)-ic_flags  IEEE80211_CHAN_GSM) != 0)
-#define	IEEE80211_IS_CHAN_PASSIVE(_c) \
-	(((_c)-ic_flags  IEEE80211_CHAN_PASSIVE) != 0)
+	(!IEEE80211_IS_CHAN_ANYC(_c)  \
+	((_c)-ic_flags  (IEEE80211_CHAN_QUARTER | IEEE80211_CHAN_HALF)) == 0)
+
+#define	IEEE80211_IS_CHAN_GSM(_c) 	_IEEE80211_IS_CHAN(_c, GSM)
+#define	IEEE80211_IS_CHAN_PASSIVE(_c) 	_IEEE80211_IS_CHAN(_c, PASSIVE)
 
 
 /* ni_chan encoding for FH phy */



CVS commit: src/sys/net80211

2013-03-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 21 18:30:09 UTC 2013

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

Log Message:
Instead of always checking for ANYC, make it a valid channel


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/net80211/_ieee80211.h
cvs rdiff -u -r1.53 -r1.54 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.h
diff -u src/sys/net80211/_ieee80211.h:1.9 src/sys/net80211/_ieee80211.h:1.10
--- src/sys/net80211/_ieee80211.h:1.9	Thu Mar 21 13:10:25 2013
+++ src/sys/net80211/_ieee80211.h	Thu Mar 21 14:30:09 2013
@@ -107,11 +107,12 @@ struct ieee80211_channel {
 	u_int16_t	ic_flags;	/* see below */
 };
 
+extern const struct ieee80211_channel ieee80211_channel_anyc;
+
 #define	IEEE80211_CHAN_MAX	255
 #define	IEEE80211_CHAN_BYTES	32	/* howmany(IEEE80211_CHAN_MAX, NBBY) */
 #define	IEEE80211_CHAN_ANY	0x	/* token for ``any channel'' */
-#define	IEEE80211_CHAN_ANYC \
-	((struct ieee80211_channel *) 0x1)
+#define	IEEE80211_CHAN_ANYC 	(__UNCONST(ieee80211_channel_anyc))
 
 /* bits 0-3 are for private use by drivers */
 /* channel attributes */
@@ -155,8 +156,7 @@ struct ieee80211_channel {
 	((_c) == IEEE80211_CHAN_ANYC)
 
 #define _IEEE80211_IS_CHAN(_c, _ch) \
-	(!IEEE80211_IS_CHAN_ANYC(_c)  \
-	((_c)-ic_flags  IEEE80211_CHAN_ ## _ch) == IEEE80211_CHAN_ ## _ch)
+	(((_c)-ic_flags  IEEE80211_CHAN_ ## _ch) == IEEE80211_CHAN_ ## _ch)
 
 #define	IEEE80211_IS_CHAN_FHSS(_c)	_IEEE80211_IS_CHAN(_c, FHSS)
 #define	IEEE80211_IS_CHAN_A(_c)		_IEEE80211_IS_CHAN(_c, A)

Index: src/sys/net80211/ieee80211.c
diff -u src/sys/net80211/ieee80211.c:1.53 src/sys/net80211/ieee80211.c:1.54
--- src/sys/net80211/ieee80211.c:1.53	Mon Apr  5 03:22:24 2010
+++ src/sys/net80211/ieee80211.c	Thu Mar 21 14:30:09 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211.c,v 1.53 2010/04/05 07:22:24 joerg Exp $	*/
+/*	$NetBSD: ieee80211.c,v 1.54 2013/03/21 18:30:09 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.c,v 1.22 2005/08/10 16:22:29 sam Exp $);
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, $NetBSD: ieee80211.c,v 1.53 2010/04/05 07:22:24 joerg Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211.c,v 1.54 2013/03/21 18:30:09 christos Exp $);
 #endif
 
 /*
@@ -73,6 +73,10 @@ __KERNEL_RCSID(0, $NetBSD: ieee80211.c,
 #include net/if_ether.h
 #endif
 
+const struct ieee80211_channel ieee80211_channel_anyc = {
+	0, 0
+};
+
 struct ieee80211com_head ieee80211com_head =
 LIST_HEAD_INITIALIZER(ieee80211com_head);
 



CVS commit: src/sys/net80211

2013-02-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb  4 15:44:45 UTC 2013

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

Log Message:
don't print the interface name 2ice.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 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.22 src/sys/net80211/ieee80211_netbsd.c:1.23
--- src/sys/net80211/ieee80211_netbsd.c:1.22	Wed Nov 14 13:34:05 2012
+++ src/sys/net80211/ieee80211_netbsd.c	Mon Feb  4 10:44:45 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: ieee80211_netbsd.c,v 1.22 2012/11/14 18:34:05 matt Exp $ */
+/* $NetBSD: ieee80211_netbsd.c,v 1.23 2013/02/04 15:44:45 christos Exp $ */
 /*-
  * Copyright (c) 2003-2005 Sam Leffler, Errno Consulting
  * All rights reserved.
@@ -30,7 +30,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.22 2012/11/14 18:34:05 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211_netbsd.c,v 1.23 2013/02/04 15:44:45 christos Exp $);
 #endif
 
 /*
@@ -655,8 +655,8 @@ ieee80211_notify_node_join(struct ieee80
 	struct ifnet *ifp = ic-ic_ifp;
 	struct ieee80211_join_event iev;
 
-	IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, %s: %snode %s join\n,
-	ifp-if_xname, (ni == ic-ic_bss) ? bss  : ,
+	IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, %snode %s join\n,
+	(ni == ic-ic_bss) ? bss  : ,
 	ether_sprintf(ni-ni_macaddr));
 
 	memset(iev, 0, sizeof(iev));
@@ -680,8 +680,8 @@ ieee80211_notify_node_leave(struct ieee8
 	struct ifnet *ifp = ic-ic_ifp;
 	struct ieee80211_leave_event iev;
 
-	IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, %s: %snode %s leave\n,
-	ifp-if_xname, (ni == ic-ic_bss) ? bss  : ,
+	IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, %snode %s leave\n,
+	(ni == ic-ic_bss) ? bss  : ,
 	ether_sprintf(ni-ni_macaddr));
 
 	if (ni == ic-ic_bss) {
@@ -701,7 +701,7 @@ ieee80211_notify_scan_done(struct ieee80
 	struct ifnet *ifp = ic-ic_ifp;
 
 	IEEE80211_DPRINTF(ic, IEEE80211_MSG_SCAN,
-		%s: notify scan done\n, ic-ic_ifp-if_xname);
+		%s, notify scan done\n);
 
 	/* dispatch wireless event indicating scan completed */
 	rt_ieee80211msg(ifp, RTM_IEEE80211_SCAN, NULL, 0);



CVS commit: src/sys/net80211

2012-11-14 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Wed Nov 14 18:34:05 UTC 2012

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

Log Message:
Set max_linkhdr when attaching so when bridging/forwarding ethernet drivers
have a chance to reserve enough space to insert a max-sized 802.11 header.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 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.21 src/sys/net80211/ieee80211_netbsd.c:1.22
--- src/sys/net80211/ieee80211_netbsd.c:1.21	Sat Jun  2 21:36:47 2012
+++ src/sys/net80211/ieee80211_netbsd.c	Wed Nov 14 18:34:05 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: ieee80211_netbsd.c,v 1.21 2012/06/02 21:36:47 dsl Exp $ */
+/* $NetBSD: ieee80211_netbsd.c,v 1.22 2012/11/14 18:34:05 matt Exp $ */
 /*-
  * Copyright (c) 2003-2005 Sam Leffler, Errno Consulting
  * All rights reserved.
@@ -30,7 +30,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.21 2012/06/02 21:36:47 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211_netbsd.c,v 1.22 2012/11/14 18:34:05 matt Exp $);
 #endif
 
 /*
@@ -81,6 +81,10 @@ ieee80211_init0(void)
 {
 	ieee80211_setup_func * const *ieee80211_setup, f;
 
+	if (max_linkhdr  ALIGN(sizeof(struct ieee80211_qosframe_addr4))) {
+		max_linkhdr = ALIGN(sizeof(struct ieee80211_qosframe_addr4));
+	}
+
 __link_set_foreach(ieee80211_setup, ieee80211_funcs) {
 		f = (void*)*ieee80211_setup;
 		(*f)();



CVS commit: src/sys/net80211

2012-08-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Aug 20 07:30:10 UTC 2012

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

Log Message:
add more QoS bits


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 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.21 src/sys/net80211/ieee80211.h:1.22
--- src/sys/net80211/ieee80211.h:1.21	Wed Nov  3 16:05:21 2010
+++ src/sys/net80211/ieee80211.h	Mon Aug 20 03:30:10 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211.h,v 1.21 2010/11/03 20:05:21 christos Exp $	*/
+/*	$NetBSD: ieee80211.h,v 1.22 2012/08/20 07:30:10 christos Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -170,13 +170,22 @@ struct ieee80211_qosframe_addr4 {
 
 #define	IEEE80211_NWID_LEN			32
 
-#define	IEEE80211_QOS_TXOP			0x00ff
+/*
+ * QoS Control field (see 7.1.3.5).
+ */
 /* bit 8 is reserved */
-#define	IEEE80211_QOS_ACKPOLICY			0x60
+#define	IEEE80211_QOS_TXOP			0xff00
+#define	IEEE80211_QOS_AMSDU			0x0080  /* 11n */
+#define	IEEE80211_QOS_ACKPOLICY_NORMAL  0x
+#define	IEEE80211_QOS_ACKPOLICY_NOACK   0x0020
+#define	IEEE80211_QOS_ACKPOLICY_NOEXPLACK   0x0040
+#define	IEEE80211_QOS_ACKPOLICY			0x0060
 #define	IEEE80211_QOS_ACKPOLICY_S		5
-#define	IEEE80211_QOS_ESOP			0x10
+#define	IEEE80211_QOS_ACKPOLICY_MASK		0x0060
+#define	IEEE80211_QOS_ACKPOLICY_BA		0x0060
+#define	IEEE80211_QOS_ESOP			0x0010
 #define	IEEE80211_QOS_ESOP_S			4
-#define	IEEE80211_QOS_TID			0x0f
+#define	IEEE80211_QOS_TID			0x000f
 
 /* does frame have QoS sequence control data */
 #define	IEEE80211_QOS_HAS_SEQ(wh) \



CVS commit: src/sys/net80211

2011-06-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jun 12 00:07:19 UTC 2011

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

Log Message:
Change i_len in ieee80211req to be unsigned and fix other signed/unsigned
issues. From Dan Rosenberg (drosenberg at vsecurity dot com).


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/net80211/ieee80211_acl.c
cvs rdiff -u -r1.55 -r1.56 src/sys/net80211/ieee80211_ioctl.c
cvs rdiff -u -r1.19 -r1.20 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_acl.c
diff -u src/sys/net80211/ieee80211_acl.c:1.8 src/sys/net80211/ieee80211_acl.c:1.9
--- src/sys/net80211/ieee80211_acl.c:1.8	Wed Dec 17 15:51:37 2008
+++ src/sys/net80211/ieee80211_acl.c	Sat Jun 11 20:07:19 2011
@@ -34,7 +34,7 @@
 __FBSDID($FreeBSD: src/sys/net80211/ieee80211_acl.c,v 1.4 2005/08/13 17:31:48 sam Exp $);
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, $NetBSD: ieee80211_acl.c,v 1.8 2008/12/17 20:51:37 cegger Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211_acl.c,v 1.9 2011/06/12 00:07:19 christos Exp $);
 #endif
 
 /*
@@ -79,7 +79,7 @@
 struct aclstate {
 	acl_lock_t		as_lock;
 	int			as_policy;
-	int			as_nacls;
+	uint32_t		as_nacls;
 	TAILQ_HEAD(, acl)	as_list;	/* list of all ACL's */
 	LIST_HEAD(, acl)	as_hash[ACL_HASHSIZE];
 	struct ieee80211com	*as_ic;
@@ -281,7 +281,8 @@
 	struct aclstate *as = ic-ic_as;
 	struct acl *acl;
 	struct ieee80211req_maclist *ap;
-	int error, space, i;
+	int error;
+	uint32_t i, space;
 
 	switch (ireq-i_val) {
 	case IEEE80211_MACCMD_POLICY:

Index: src/sys/net80211/ieee80211_ioctl.c
diff -u src/sys/net80211/ieee80211_ioctl.c:1.55 src/sys/net80211/ieee80211_ioctl.c:1.56
--- src/sys/net80211/ieee80211_ioctl.c:1.55	Sat Apr  2 04:11:32 2011
+++ src/sys/net80211/ieee80211_ioctl.c	Sat Jun 11 20:07:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_ioctl.c,v 1.55 2011/04/02 08:11:32 mbalmer Exp $	*/
+/*	$NetBSD: ieee80211_ioctl.c,v 1.56 2011/06/12 00:07:19 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.55 2011/04/02 08:11:32 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211_ioctl.c,v 1.56 2011/06/12 00:07:19 christos Exp $);
 #endif
 
 /*
@@ -932,9 +932,8 @@
 {
 	size_t len = ireq-i_len;
 
-	if (sizeof(ic-ic_chan_active)  len) {
+	if (len  sizeof(ic-ic_chan_active))
 		len = sizeof(ic-ic_chan_active);
-	}
 	return copyout(ic-ic_chan_active, ireq-i_data, len);
 }
 
@@ -942,7 +941,8 @@
 ieee80211_ioctl_getchaninfo(struct ieee80211com *ic, struct ieee80211req *ireq)
 {
 	struct ieee80211req_chaninfo *chans;
-	int i, space, error;
+	uint32_t i, space;
+	int error;
 
 	/*
 	 * Since channel 0 is not available for DS, channel 1
@@ -1004,7 +1004,7 @@
 {
 	struct ieee80211_node *ni;
 	u_int8_t macaddr[IEEE80211_ADDR_LEN];
-	const int off = __offsetof(struct ieee80211req_sta_stats, is_stats);
+	const size_t off = __offsetof(struct ieee80211req_sta_stats, is_stats);
 	int error;
 
 	if (ireq-i_len  off)
@@ -1075,7 +1075,8 @@
 	struct ieee80211req_scan_result *sr = u.res;
 	struct ieee80211_node_table *nt;
 	struct ieee80211_node *ni;
-	int error, space;
+	int error;
+	uint32_t space;
 	u_int8_t *p, *cp;
 
 	p = ireq-i_data;

Index: src/sys/net80211/ieee80211_ioctl.h
diff -u src/sys/net80211/ieee80211_ioctl.h:1.19 src/sys/net80211/ieee80211_ioctl.h:1.20
--- src/sys/net80211/ieee80211_ioctl.h:1.19	Mon Jul 28 13:54:02 2008
+++ src/sys/net80211/ieee80211_ioctl.h	Sat Jun 11 20:07:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_ioctl.h,v 1.19 2008/07/28 17:54:02 christos Exp $	*/
+/*	$NetBSD: ieee80211_ioctl.h,v 1.20 2011/06/12 00:07:19 christos Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -413,7 +413,7 @@
 	char		i_name[IFNAMSIZ];	/* if_name, e.g. wi0 */
 	u_int16_t	i_type;			/* req type */
 	int16_t		i_val;			/* Index or simple value */
-	int16_t		i_len;			/* Index or simple value */
+	u_int16_t	i_len;			/* Index or simple value */
 	void		*i_data;		/* Extra data */
 };
 



CVS commit: src/sys/net80211

2011-04-03 Thread Matthias Drochner
Module Name:src
Committed By:   drochner
Date:   Sun Apr  3 10:04:32 UTC 2011

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

Log Message:
make michael_mic() robust against degenerate mbuf layouts like
odd sizes in the middle of a chain


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 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.10 src/sys/net80211/ieee80211_crypto_tkip.c:1.11
--- src/sys/net80211/ieee80211_crypto_tkip.c:1.10	Wed Dec 17 20:51:37 2008
+++ src/sys/net80211/ieee80211_crypto_tkip.c	Sun Apr  3 10:04:32 2011
@@ -34,7 +34,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.10 2008/12/17 20:51:37 cegger Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211_crypto_tkip.c,v 1.11 2011/04/03 10:04:32 drochner Exp $);
 #endif
 
 /*
@@ -802,6 +802,8 @@
 	u32 l, r;
 	const uint8_t *data;
 	u_int space;
+	uint8_t spill[4];
+	int nspill = 0;
 
 	michael_mic_hdr(mtod(m, struct ieee80211_frame *), hdr);
 
@@ -824,6 +826,20 @@
 	for (;;) {
 		if (space  data_len)
 			space = data_len;
+		if (nspill) {
+			int n = min(4 - nspill, space);
+			memcpy(spill + nspill, data, n);
+			nspill += n;
+			data += n;
+			space -= n;
+			data_len -= n;
+			if (nspill == 4) {
+l ^= get_le32(spill);
+michael_block(l, r);
+nspill = 0;
+			} else
+goto next;
+		}
 		/* collect 32-bit blocks from current buffer */
 		while (space = sizeof(uint32_t)) {
 			l ^= get_le32(data);
@@ -832,84 +848,27 @@
 			space -= sizeof(uint32_t);
 			data_len -= sizeof(uint32_t);
 		}
-		/*
-		 * NB: when space is zero we make one more trip around
-		 * the loop to advance to the next mbuf where there is
-		 * data.  This handles the case where there are 4*n
-		 * bytes in an mbuf followed by 4 bytes in a later mbuf.
-		 * By making an extra trip we'll drop out of the loop
-		 * with m pointing at the mbuf with 3 bytes and space
-		 * set as required by the remainder handling below.
-		 */
-		if (!data_len || (data_len  sizeof(uint32_t)  space != 0))
+		if (space) {
+			memcpy(spill, data, space);
+			nspill = space;
+			data_len -= space;
+		}
+next:
+		if (!data_len)
 			break;
 		m = m-m_next;
-		if (m == NULL) {
-			IASSERT(0, (out of data, data_len %zu\n, data_len));
-			break;
-		}
-		if (space != 0) {
-			const uint8_t *data_next;
-			/*
-			 * Block straddles buffers, split references.
-			 */
-			data_next = mtod(m, const uint8_t *);
-			IASSERT(m-m_len = sizeof(uint32_t) - space,
-(not enough data in following buffer, 
-m_len %u need %zu\n, m-m_len,
-sizeof(uint32_t) - space));
-			switch (space) {
-			case 1:
-l ^= get_le32_split(data[0], data_next[0],
-	data_next[1], data_next[2]);
-data = data_next + 3;
-space = m-m_len - 3;
-break;
-			case 2:
-l ^= get_le32_split(data[0], data[1],
-	data_next[0], data_next[1]);
-data = data_next + 2;
-space = m-m_len - 2;
-break;
-			case 3:
-l ^= get_le32_split(data[0], data[1],
-	data[2], data_next[0]);
-data = data_next + 1;
-space = m-m_len - 1;
-break;
-			}
-			michael_block(l, r);
-			data_len -= sizeof(uint32_t);
-		} else {
-			/*
-			 * Setup for next buffer.
-			 */
-			data = mtod(m, const uint8_t *);
-			space = m-m_len;
-		}
+		KASSERT(m);
+		/*
+		 * Setup for next buffer.
+		 */
+		data = mtod(m, const uint8_t *);
+		space = m-m_len;
 	}
-	/*
-	 * Catch degenerate cases like mbuf[4*n+1 bytes] followed by
-	 * mbuf[2 bytes].  I don't believe these should happen; if they
-	 * do then we'll need more involved logic.
-	 */
-	KASSERT(data_len = space);
-
 	/* Last block and padding (0x5a, 4..7 x 0) */
-	switch (data_len) {
-	case 0:
-		l ^= get_le32_split(0x5a, 0, 0, 0);
-		break;
-	case 1:
-		l ^= get_le32_split(data[0], 0x5a, 0, 0);
-		break;
-	case 2:
-		l ^= get_le32_split(data[0], data[1], 0x5a, 0);
-		break;
-	case 3:
-		l ^= get_le32_split(data[0], data[1], data[2], 0x5a);
-		break;
-	}
+	spill[nspill++] = 0x5a;
+	for (; nspill  4; nspill++)
+		spill[nspill] = 0;
+	l ^= get_le32(spill);
 	michael_block(l, r);
 	/* l ^= 0; */
 	michael_block(l, r);



CVS commit: src/sys/net80211

2011-02-25 Thread Matthias Scheler
Module Name:src
Committed By:   tron
Date:   Fri Feb 25 10:45:57 UTC 2011

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

Log Message:
Remove duplicate definitions which break the build.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/net80211/ieee80211_radiotap.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_radiotap.h
diff -u src/sys/net80211/ieee80211_radiotap.h:1.23 src/sys/net80211/ieee80211_radiotap.h:1.24
--- src/sys/net80211/ieee80211_radiotap.h:1.23	Fri Feb 25 08:04:18 2011
+++ src/sys/net80211/ieee80211_radiotap.h	Fri Feb 25 10:45:57 2011
@@ -1,5 +1,5 @@
 /* $FreeBSD: src/sys/net80211/ieee80211_radiotap.h,v 1.11 2007/12/13 01:23:40 sam Exp $ */
-/* $NetBSD: ieee80211_radiotap.h,v 1.23 2011/02/25 08:04:18 cegger Exp $ */
+/* $NetBSD: ieee80211_radiotap.h,v 1.24 2011/02/25 10:45:57 tron Exp $ */
 
 /*-
  * Copyright (c) 2003, 2004 David Young.  All rights reserved.
@@ -211,22 +211,6 @@
 	IEEE80211_RADIOTAP_EXT = 31
 };
 
-#ifndef _KERNEL
-/* Channel flags. */
-#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_STURBO	0x2000 /* 11a static turbo channel only */
-#define IEEE80211_CHAN_HALF	0x4000 /* Half rate channel */
-#define IEEE80211_CHAN_QUARTER	0x8000 /* Quarter rate channel */
-#endif /* !_KERNEL */
-
 /* For IEEE80211_RADIOTAP_FLAGS */
 #define	IEEE80211_RADIOTAP_F_CFP	0x01	/* sent/received
 		 * during CFP



CVS commit: src/sys/net80211

2011-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Feb 21 23:50:08 UTC 2011

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

Log Message:
add ieee80211_get_rts and ieee80211_get_cts_to_self from openbsd, ok dyoung@


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/net80211/ieee80211_output.c
cvs rdiff -u -r1.17 -r1.18 src/sys/net80211/ieee80211_proto.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_output.c
diff -u src/sys/net80211/ieee80211_output.c:1.49 src/sys/net80211/ieee80211_output.c:1.50
--- src/sys/net80211/ieee80211_output.c:1.49	Tue Jan 19 22:08:17 2010
+++ src/sys/net80211/ieee80211_output.c	Mon Feb 21 23:50:08 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_output.c,v 1.49 2010/01/19 22:08:17 pooka Exp $	*/
+/*	$NetBSD: ieee80211_output.c,v 1.50 2011/02/21 23:50:08 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_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.49 2010/01/19 22:08:17 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211_output.c,v 1.50 2011/02/21 23:50:08 jmcneill Exp $);
 #endif
 
 #include opt_inet.h
@@ -1706,6 +1706,58 @@
 }
 
 /*
+ * Build a RTS (Request To Send) control frame.
+ */
+struct mbuf *
+ieee80211_get_rts(struct ieee80211com *ic, const struct ieee80211_frame *wh,
+uint16_t dur)
+{
+	struct ieee80211_frame_rts *rts;
+	struct mbuf *m;
+
+	MGETHDR(m, M_DONTWAIT, MT_DATA);
+	if (m == NULL)
+		return NULL;
+
+	m-m_pkthdr.len = m-m_len = sizeof(struct ieee80211_frame_rts);
+
+	rts = mtod(m, struct ieee80211_frame_rts *);
+	rts-i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_CTL |
+	IEEE80211_FC0_SUBTYPE_RTS;
+	rts-i_fc[1] = IEEE80211_FC1_DIR_NODS;
+	*(uint16_t *)rts-i_dur = htole16(dur);
+	IEEE80211_ADDR_COPY(rts-i_ra, wh-i_addr1);
+	IEEE80211_ADDR_COPY(rts-i_ta, wh-i_addr2);
+
+	return m;
+}
+
+/*
+ * Build a CTS-to-self (Clear To Send) control frame.
+ */
+struct mbuf *
+ieee80211_get_cts_to_self(struct ieee80211com *ic, uint16_t dur)
+{
+	struct ieee80211_frame_cts *cts;
+	struct mbuf *m;
+
+	MGETHDR(m, M_DONTWAIT, MT_DATA);
+	if (m == NULL)
+		return NULL;
+
+	m-m_pkthdr.len = m-m_len = sizeof(struct ieee80211_frame_cts);
+
+	cts = mtod(m, struct ieee80211_frame_cts *);
+	cts-i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_CTL |
+	IEEE80211_FC0_SUBTYPE_CTS;
+	cts-i_fc[1] = IEEE80211_FC1_DIR_NODS;
+	*(uint16_t *)cts-i_dur = htole16(dur);
+	IEEE80211_ADDR_COPY(cts-i_ra, ic-ic_myaddr);
+
+	return m;
+}
+
+/*
  * Allocate a beacon frame and fillin the appropriate bits.
  */
 struct mbuf *

Index: src/sys/net80211/ieee80211_proto.h
diff -u src/sys/net80211/ieee80211_proto.h:1.17 src/sys/net80211/ieee80211_proto.h:1.18
--- src/sys/net80211/ieee80211_proto.h:1.17	Mon Jul 28 17:54:02 2008
+++ src/sys/net80211/ieee80211_proto.h	Mon Feb 21 23:50:08 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_proto.h,v 1.17 2008/07/28 17:54:02 christos Exp $	*/
+/*	$NetBSD: ieee80211_proto.h,v 1.18 2011/02/21 23:50:08 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -78,6 +78,10 @@
 		struct ieee80211_node *);
 struct mbuf *ieee80211_encap(struct ieee80211com *, struct mbuf *,
 		struct ieee80211_node *);
+struct mbuf *ieee80211_get_rts(struct ieee80211com *,
+		const struct ieee80211_frame *, uint16_t);
+struct mbuf *ieee80211_get_cts_to_self(struct ieee80211com *,
+		uint16_t);
 void	ieee80211_pwrsave(struct ieee80211com *, struct ieee80211_node *, 
 		struct mbuf *);
 



CVS commit: src/sys/net80211

2010-11-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Nov  3 20:05:22 UTC 2010

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

Log Message:
From: Anon Ymous
add a few constants so that if_otus.c compiles.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 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.20 src/sys/net80211/ieee80211.h:1.21
--- src/sys/net80211/ieee80211.h:1.20	Wed Nov  5 22:28:59 2008
+++ src/sys/net80211/ieee80211.h	Wed Nov  3 16:05:21 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211.h,v 1.20 2008/11/06 03:28:59 dyoung Exp $	*/
+/*	$NetBSD: ieee80211.h,v 1.21 2010/11/03 20:05:21 christos Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -159,7 +159,8 @@
 #define	IEEE80211_FC1_RETRY			0x08
 #define	IEEE80211_FC1_PWR_MGT			0x10
 #define	IEEE80211_FC1_MORE_DATA			0x20
-#define	IEEE80211_FC1_WEP			0x40
+#define	IEEE80211_FC1_PROTECTED			0x40
+#define	IEEE80211_FC1_WEP			0x40	/* pre-RSNA compat */
 #define	IEEE80211_FC1_ORDER			0x80
 
 #define	IEEE80211_SEQ_FRAG_MASK			0x000f
@@ -402,6 +403,7 @@
 	IEEE80211_ELEMID_TIM		= 5,
 	IEEE80211_ELEMID_IBSSPARMS	= 6,
 	IEEE80211_ELEMID_COUNTRY	= 7,
+	IEEE80211_ELEMID_EDCAPARMS	= 12,
 	IEEE80211_ELEMID_CHALLENGE	= 16,
 	/* 17-31 reserved for challenge text extension */
 	IEEE80211_ELEMID_PWRCNSTR	= 32,
@@ -415,10 +417,13 @@
 	IEEE80211_ELEMID_QUIET		= 40,
 	IEEE80211_ELEMID_IBSSDFS	= 41,
 	IEEE80211_ELEMID_ERP		= 42,
-	IEEE80211_ELEMID_HTCAP		= 45,
+	IEEE80211_ELEMID_HTCAP		= 45,	/* 11n */
+	IEEE80211_ELEMID_QOS_CAP	= 46,
 	IEEE80211_ELEMID_RSN		= 48,
 	IEEE80211_ELEMID_XRATES		= 50,
-	IEEE80211_ELEMID_HTINFO		= 61,
+	IEEE80211_ELEMID_TIE		= 56,	/* 11r */
+	IEEE80211_ELEMID_HTINFO		= 61,	/* 11n */
+	IEEE80211_ELEMID_MMIE		= 76,	/* 11w */
 	IEEE80211_ELEMID_TPC		= 150,
 	IEEE80211_ELEMID_CCKM		= 156,
 	IEEE80211_ELEMID_VENDOR		= 221	/* vendor private */



CVS commit: src/sys/net80211

2010-04-01 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Fri Apr  2 03:46:50 UTC 2010

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

Log Message:
Delete ieee80211_setbasicrates().  It's buggy, and we drivers can get
along fine without it.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 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.51 src/sys/net80211/ieee80211.c:1.52
--- src/sys/net80211/ieee80211.c:1.51	Fri Mar 26 17:18:05 2010
+++ src/sys/net80211/ieee80211.c	Fri Apr  2 03:46:50 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211.c,v 1.51 2010/03/26 17:18:05 dyoung Exp $	*/
+/*	$NetBSD: ieee80211.c,v 1.52 2010/04/02 03:46:50 dyoung 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.51 2010/03/26 17:18:05 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211.c,v 1.52 2010/04/02 03:46:50 dyoung Exp $);
 #endif
 
 /*
@@ -92,8 +92,6 @@
 	SLIST_HEAD_INITIALIZER(ieee80211_list);
 static u_int8_t ieee80211_vapmap[32];		/* enough for 256 */
 
-static void ieee80211_setbasicrates(struct ieee80211com *);
-
 static void
 ieee80211_add_vap(struct ieee80211com *ic)
 {
@@ -216,7 +214,6 @@
 	if (ic-ic_caps  IEEE80211_C_WME)
 		ic-ic_flags |= IEEE80211_F_WME;
 #endif
-	ieee80211_setbasicrates(ic);
 	(void) ieee80211_setmode(ic, ic-ic_curmode);
 
 	if (ic-ic_bintval == 0)
@@ -809,41 +806,6 @@
 	{ 12, { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108 } };
 
 /*
- * Mark the basic rates for the 11g rate table based on the
- * operating mode.  For real 11g we mark all the 11b rates
- * and 6, 12, and 24 OFDM.  For 11b compatibility we mark only
- * 11b rates.  There's also a pseudo 11a-mode used to mark only
- * the basic OFDM rates.
- */
-static void
-ieee80211_setbasicrates(struct ieee80211com *ic)
-{
-	static const struct ieee80211_rateset basic[] = {
-	{ 0, { } }, /* IEEE80211_MODE_AUTO */
-	{ 3, { 12, 24, 48 } },  /* IEEE80211_MODE_11A */
-	{ 2, { 2, 4 } },/* IEEE80211_MODE_11B */
-	{ 4, { 2, 4, 11, 22 } },/* IEEE80211_MODE_11G */
-	{ 0, { } }, /* IEEE80211_MODE_TURBO */
-	};
-	enum ieee80211_phymode mode;
-	struct ieee80211_rateset *rs;
-	int i, j;
-
-	for (mode = 0; mode  IEEE80211_MODE_MAX; mode++) {
-		rs = ic-ic_sup_rates[mode];
-		for (i = 0; i  rs-rs_nrates; i++) {
-			rs-rs_rates[i] = IEEE80211_RATE_VAL;
-			for (j = 0; j  basic[mode].rs_nrates; j++) {
-if (basic[mode].rs_rates[j] != rs-rs_rates[i])
-	continue; 
-rs-rs_rates[i] |= IEEE80211_RATE_BASIC;
-break;
-			}
-		}
-	}
-}
-
-/*
  * Set the current phy mode and recalculate the active channel
  * set based on the available channels for this mode.  Also
  * select a new default/current channel if the current one is



CVS commit: src/sys/net80211

2010-03-26 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Fri Mar 26 17:18:05 UTC 2010

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

Log Message:
In ieee80211_media_init(), change a pointer that we never write
through to a pointer to const.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 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.50 src/sys/net80211/ieee80211.c:1.51
--- src/sys/net80211/ieee80211.c:1.50	Tue Jan 19 22:08:17 2010
+++ src/sys/net80211/ieee80211.c	Fri Mar 26 17:18:05 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211.c,v 1.50 2010/01/19 22:08:17 pooka Exp $	*/
+/*	$NetBSD: ieee80211.c,v 1.51 2010/03/26 17:18:05 dyoung 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.50 2010/01/19 22:08:17 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211.c,v 1.51 2010/03/26 17:18:05 dyoung Exp $);
 #endif
 
 /*
@@ -352,7 +352,7 @@
 	struct ifnet *ifp = ic-ic_ifp;
 	struct ifmediareq imr;
 	int i, j, mode, rate, maxrate, mword, mopt, r;
-	struct ieee80211_rateset *rs;
+	const struct ieee80211_rateset *rs;
 	struct ieee80211_rateset allrates;
 
 	/*



CVS commit: src/sys/net80211

2009-09-02 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed Sep  2 22:03:08 UTC 2009

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

Log Message:
Fix ALTQ for bridge mode. Based on FreeBSD's revision 1.115.
Tested by r...@.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 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.67 src/sys/net80211/ieee80211_input.c:1.68
--- src/sys/net80211/ieee80211_input.c:1.67	Wed Dec 17 20:51:37 2008
+++ src/sys/net80211/ieee80211_input.c	Wed Sep  2 22:03:08 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.67 2008/12/17 20:51:37 cegger Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.68 2009/09/02 22:03:08 joerg Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,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.67 2008/12/17 20:51:37 cegger Exp $);
+__KERNEL_RCSID(0, $NetBSD: ieee80211_input.c,v 1.68 2009/09/02 22:03:08 joerg Exp $);
 #endif
 
 #include opt_inet.h
@@ -710,6 +710,7 @@
 	struct ether_header *eh = mtod(m, struct ether_header *);
 	struct ifnet *ifp = ic-ic_ifp;
 	ALTQ_DECL(struct altq_pktattr pktattr;)
+	int error;
 
 	/* perform as a bridge within the AP */
 	if (ic-ic_opmode == IEEE80211_M_HOSTAP 
@@ -756,9 +757,11 @@
 			}
 #endif
 			len = m1-m_pkthdr.len;
-			IF_ENQUEUE(ifp-if_snd, m1);
-			if (m != NULL)
+			IFQ_ENQUEUE(ifp-if_snd, m1, pktattr, error);
+			if (error) {
 ifp-if_omcasts++;
+m = NULL;
+			}
 			ifp-if_obytes += len;
 		}
 	}