Module Name:    src
Committed By:   maya
Date:           Fri Nov  9 21:57:09 UTC 2018

Modified Files:
        src/sys/dev/usb: if_urndis.c if_urndisreg.h

Log Message:
Set and check NDIS version.

Throw away length 1 packets without a warning: we already throw away messages
with (len < sizeof(*msg)) a short while after, but print a warning.

Hardware is allowed to pad USB packets which % wMaxPacketSize length with
such packets for hardware implementation simplicity reasons.

This is described in
https://docs.microsoft.com/en-us/windows-hardware/drivers/network/usb-short-packets

>From Artturi Alm in tech-net, with amendment from pgoyette.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/usb/if_urndis.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/usb/if_urndisreg.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/dev/usb/if_urndis.c
diff -u src/sys/dev/usb/if_urndis.c:1.18 src/sys/dev/usb/if_urndis.c:1.19
--- src/sys/dev/usb/if_urndis.c:1.18	Tue Jun 26 06:48:02 2018
+++ src/sys/dev/usb/if_urndis.c	Fri Nov  9 21:57:09 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urndis.c,v 1.18 2018/06/26 06:48:02 msaitoh Exp $ */
+/*	$NetBSD: if_urndis.c,v 1.19 2018/11/09 21:57:09 maya Exp $ */
 /*	$OpenBSD: if_urndis.c,v 1.31 2011/07/03 15:47:17 matthew Exp $ */
 
 /*
@@ -21,7 +21,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_urndis.c,v 1.18 2018/06/26 06:48:02 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urndis.c,v 1.19 2018/11/09 21:57:09 maya Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -289,7 +289,18 @@ urndis_ctrl_handle_init(struct urndis_so
 		return RNDIS_STATUS_FAILURE;
 	}
 
-	sc->sc_lim_pktsz = le32toh(msg->rm_pktmaxsz);
+	if (le32toh(msg->rm_ver_major) != RNDIS_MAJOR_VERSION ||
+	    le32toh(msg->rm_ver_minor) != RNDIS_MINOR_VERSION) {
+		printf("%s: version not %u.%u (current version: %u.%u)\n",
+		    DEVNAME(sc), RNDIS_MAJOR_VERSION, RNDIS_MINOR_VERSION,
+		    le32toh(msg->rm_ver_major), le32toh(msg->rm_ver_minor));
+
+		return RNDIS_STATUS_FAILURE;
+	}
+
+	sc->sc_maxppt = le32toh(msg->rm_pktmaxcnt);
+	sc->sc_maxtsz = le32toh(msg->rm_pktmaxsz);
+	sc->sc_palign = 1U << le32toh(msg->rm_align);
 
 	return le32toh(msg->rm_status);
 }
@@ -402,8 +413,8 @@ urndis_ctrl_init(struct urndis_softc *sc
 	msg->rm_type = htole32(REMOTE_NDIS_INITIALIZE_MSG);
 	msg->rm_len = htole32(sizeof(*msg));
 	msg->rm_rid = htole32(0);
-	msg->rm_ver_major = htole32(1);
-	msg->rm_ver_minor = htole32(1);
+	msg->rm_ver_major = htole32(RNDIS_MAJOR_VERSION);
+	msg->rm_ver_minor = htole32(RNDIS_MINOR_VERSION);
 	msg->rm_max_xfersz = htole32(RNDIS_BUFSZ);
 
 	DPRINTF(("%s: urndis_ctrl_init send: type %u len %u rid %u ver_major %u "
@@ -743,7 +754,7 @@ urndis_decap(struct urndis_softc *sc, st
 	ifp = GET_IFP(sc);
 	offset = 0;
 
-	while (len > 0) {
+	while (len > 1) {
 		msg = (struct urndis_packet_msg *)((char*)c->sc_buf + offset);
 		m = c->sc_mbuf;
 

Index: src/sys/dev/usb/if_urndisreg.h
diff -u src/sys/dev/usb/if_urndisreg.h:1.3 src/sys/dev/usb/if_urndisreg.h:1.4
--- src/sys/dev/usb/if_urndisreg.h:1.3	Sun Dec  4 10:12:35 2016
+++ src/sys/dev/usb/if_urndisreg.h	Fri Nov  9 21:57:09 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urndisreg.h,v 1.3 2016/12/04 10:12:35 skrll Exp $ */
+/*	$NetBSD: if_urndisreg.h,v 1.4 2018/11/09 21:57:09 maya Exp $ */
 /*	$OpenBSD: if_urndisreg.h,v 1.14 2010/07/08 18:22:01 ckuethe Exp $ */
 
 /*
@@ -47,8 +47,10 @@ struct urndis_softc {
 	struct ethercom			sc_ec;
 
 	/* RNDIS device info */
-	uint32_t			sc_lim_pktsz;
 	uint32_t			sc_filter;
+	uint32_t			sc_maxppt;
+	uint32_t			sc_maxtsz;
+	uint32_t			sc_palign;
 
 	/* USB goo */
 	struct usbd_device *		sc_udev;
@@ -122,6 +124,9 @@ struct urndis_softc {
 
 #define RNDIS_MEDIUM_802_3		0x00000000
 
+#define RNDIS_MAJOR_VERSION		0x00000001U
+#define RNDIS_MINOR_VERSION		0x00000000U
+
 /* Device flags */
 #define RNDIS_DF_CONNECTIONLESS		0x00000001
 #define RNDIS_DF_CONNECTION_ORIENTED	0x00000002

Reply via email to