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 <sys/param.h>
 #include <sys/systm.h>
 #include <sys/mbuf.h>
@@ -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->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, retry;
 			u_int16_t rxno, orxno;
 
 			if (ieee80211_has_qos(wh)) {
-				tid = ((struct ieee80211_qosframe *)wh)->
-					i_qos[0] & IEEE80211_QOS_TID;
+				struct ieee80211_qosframe *qosf;
+
+				/* XXX mbuf length check */
+				qosf = mtod(m, struct ieee80211_qosframe *);
+
+				tid = qosf->i_qos[0] & IEEE80211_QOS_TID;
 				if (TID_TO_WME_AC(tid) >= WME_AC_VI)
 					ic->ic_wme.wme_hipri_traffic++;
 				tid++;
-			} else
+			} else {
 				tid = 0;
+			}
+
 			rxseq = le16toh(*(u_int16_t *)wh->i_seq);
 			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 &&
@@ -373,7 +390,7 @@ ieee80211_input(struct ieee80211com *ic,
 			    IEEE80211_ADDR_EQ(wh->i_addr3, ic->ic_myaddr)) {
 				/*
 				 * In IEEE802.11 network, multicast packet
-				 * sent from me is broadcasted from AP.
+				 * sent from me is broadcast from AP.
 				 * It should be silently discarded for
 				 * SIMPLEX interface.
 				 */
@@ -383,6 +400,7 @@ ieee80211_input(struct ieee80211com *ic,
 				goto out;
 			}
 			break;
+
 		case IEEE80211_M_IBSS:
 		case IEEE80211_M_AHDEMO:
 			if (dir != IEEE80211_FC1_DIR_NODS) {
@@ -393,6 +411,7 @@ ieee80211_input(struct ieee80211com *ic,
 			}
 			/* XXX no power-save support */
 			break;
+
 		case IEEE80211_M_HOSTAP:
 #ifndef IEEE80211_NO_HOSTAP
 			if (dir != IEEE80211_FC1_DIR_TODS) {
@@ -430,6 +449,7 @@ ieee80211_input(struct ieee80211com *ic,
 					wh->i_fc[1] & IEEE80211_FC1_PWR_MGT);
 #endif /* !IEEE80211_NO_HOSTAP */
 			break;
+
 		default:
 			/* XXX here to keep compiler happy */
 			goto out;
@@ -505,6 +525,7 @@ ieee80211_input(struct ieee80211com *ic,
 			IEEE80211_NODE_STAT(ni, rx_decap);
 			goto err;
 		}
+
 		eh = mtod(m, struct ether_header *);
 		if (!ieee80211_node_is_authorized(ni)) {
 			/*
@@ -540,6 +561,7 @@ ieee80211_input(struct ieee80211com *ic,
 				goto out;
 			}
 		}
+
 		ifp->if_ipackets++;
 		IEEE80211_NODE_STAT(ni, rx_data);
 		IEEE80211_NODE_STAT_ADD(ni, rx_bytes, m->m_pkthdr.len);
@@ -603,6 +625,7 @@ ieee80211_input(struct ieee80211com *ic,
 			wh = mtod(m, struct ieee80211_frame *);
 			wh->i_fc[1] &= ~IEEE80211_FC1_WEP;
 		}
+
 		bpf_mtap3(ic->ic_rawbpf, m);
 		(*ic->ic_recv_mgmt)(ic, m, ni, subtype, rssi, rstamp);
 		m_freem(m);
@@ -627,8 +650,10 @@ ieee80211_input(struct ieee80211com *ic,
 		/* should not come here */
 		break;
 	}
+
 err:
 	ifp->if_ierrors++;
+
 out:
 	if (m != NULL) {
 		bpf_mtap3(ic->ic_rawbpf, m);
@@ -639,7 +664,7 @@ out:
 }
 
 /*
- * This function reassemble fragments.
+ * This function reassembles fragments.
  */
 static struct mbuf *
 ieee80211_defrag(struct ieee80211com *ic, struct ieee80211_node *ni,

Index: src/sys/net80211/ieee80211_var.h
diff -u src/sys/net80211/ieee80211_var.h:1.31 src/sys/net80211/ieee80211_var.h:1.32
--- src/sys/net80211/ieee80211_var.h:1.31	Tue Sep 27 20:20:06 2016
+++ src/sys/net80211/ieee80211_var.h	Tue Jan 16 07:53:02 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_var.h,v 1.31 2016/09/27 20:20:06 christos Exp $	*/
+/*	$NetBSD: ieee80211_var.h,v 1.32 2018/01/16 07:53:02 maxv Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -359,6 +359,7 @@ ieee80211_anyhdrspace(struct ieee80211co
 	return size;
 }
 
+/* Flags set in ic_debug, used to print debug messages */
 #define	IEEE80211_MSG_DEBUG	0x40000000	/* IFF_DEBUG equivalent */
 #define	IEEE80211_MSG_DUMPPKTS	0x20000000	/* IFF_LINK2 equivalant */
 #define	IEEE80211_MSG_CRYPTO	0x10000000	/* crypto work */
@@ -384,7 +385,6 @@ ieee80211_anyhdrspace(struct ieee80211co
 #define	IEEE80211_MSG_DOTH	0x00000100	/* 802.11h support */
 #define	IEEE80211_MSG_INACT	0x00000080	/* inactivity handling */
 #define	IEEE80211_MSG_ROAM	0x00000040	/* sta-mode roaming */
-
 #define	IEEE80211_MSG_ANY	0xffffffff	/* anything */
 
 #ifdef IEEE80211_DEBUG

Reply via email to