Module Name:    src
Committed By:   martin
Date:           Wed Jul 15 14:09:04 UTC 2020

Modified Files:
        src/sys/dev/hid [netbsd-9]: hid.h
        src/sys/dev/usb [netbsd-9]: uhid.c usbhid.h

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1010):

        sys/dev/usb/uhid.c: revision 1.112
        sys/dev/usb/uhid.c: revision 1.113
        sys/dev/hid/hid.h: revision 1.4
        sys/dev/hid/hid.h: revision 1.5
        sys/dev/usb/usbhid.h: revision 1.19

Add fido constants, and turn hid "raw" mode for fido devices.

Add ioctls to get and set raw mode.

Use unsigned to avoid undefined behavior. Found by kUBSan.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.3.4.1 src/sys/dev/hid/hid.h
cvs rdiff -u -r1.108.2.1 -r1.108.2.2 src/sys/dev/usb/uhid.c
cvs rdiff -u -r1.18 -r1.18.6.1 src/sys/dev/usb/usbhid.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/hid/hid.h
diff -u src/sys/dev/hid/hid.h:1.3 src/sys/dev/hid/hid.h:1.3.4.1
--- src/sys/dev/hid/hid.h:1.3	Thu Nov 15 23:01:45 2018
+++ src/sys/dev/hid/hid.h	Wed Jul 15 14:09:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hid.h,v 1.3 2018/11/15 23:01:45 jakllsch Exp $	*/
+/*	$NetBSD: hid.h,v 1.3.4.1 2020/07/15 14:09:04 martin Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/hid.h,v 1.7 1999/11/17 22:33:40 n_hibma Exp $ */
 
 /*
@@ -123,7 +123,8 @@ int hid_is_collection(const void *, int,
 #define HUP_CAMERA_CONTROL	0x0090
 #define HUP_ARCADE		0x0091
 #define HUP_VENDOR		0x00ff
-#define HUP_MICROSOFT		0xff00
+#define HUP_FIDO		0xf1d0U
+#define HUP_MICROSOFT		0xff00U
 /* XXX compat */
 #define HUP_APPLE		0x00ff
 #define HUP_WACOM		0xff00
@@ -396,6 +397,9 @@ int hid_is_collection(const void *, int,
 /* Usages, Consumer */
 #define HUC_AC_PAN		0x0238
 
+/* Usages, FIDO */
+#define HUF_U2FHID		0x0001
+
 #define HID_USAGE2(p, u) (((p) << 16) | u)
 #define HID_GET_USAGE(u) ((u) & 0xffff)
 #define HID_GET_USAGE_PAGE(u) (((u) >> 16) & 0xffff)

Index: src/sys/dev/usb/uhid.c
diff -u src/sys/dev/usb/uhid.c:1.108.2.1 src/sys/dev/usb/uhid.c:1.108.2.2
--- src/sys/dev/usb/uhid.c:1.108.2.1	Thu Jan  2 09:42:06 2020
+++ src/sys/dev/usb/uhid.c	Wed Jul 15 14:09:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhid.c,v 1.108.2.1 2020/01/02 09:42:06 martin Exp $	*/
+/*	$NetBSD: uhid.c,v 1.108.2.2 2020/07/15 14:09:04 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004, 2008, 2012 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.108.2.1 2020/01/02 09:42:06 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.108.2.2 2020/07/15 14:09:04 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -104,6 +104,7 @@ struct uhid_softc {
 #define UHID_IMMED	0x02	/* return read data immediately */
 
 	int sc_refcnt;
+	int sc_raw;
 	u_char sc_dying;
 };
 
@@ -184,6 +185,8 @@ uhid_attach(device_t parent, device_t se
 	sc->sc_isize = hid_report_size(desc, size, hid_input,   repid);
 	sc->sc_osize = hid_report_size(desc, size, hid_output,  repid);
 	sc->sc_fsize = hid_report_size(desc, size, hid_feature, repid);
+	sc->sc_raw =  hid_is_collection(desc, size, uha->reportid,
+	    HID_USAGE2(HUP_FIDO, HUF_U2FHID));
 
 	aprint_naive("\n");
 	aprint_normal(": input=%d, output=%d, feature=%d\n",
@@ -482,15 +485,32 @@ uhid_do_write(struct uhid_softc *sc, str
 		return EIO;
 
 	size = sc->sc_osize;
-	error = 0;
 	if (uio->uio_resid != size || size == 0)
 		return EINVAL;
 	error = uiomove(sc->sc_obuf, size, uio);
+#ifdef UHID_DEBUG
+	if (uhiddebug > 5) {
+		uint32_t i;
+
+		DPRINTF(("%s: outdata[%d] =", device_xname(sc->sc_hdev.sc_dev),
+		    error));
+		for (i = 0; i < size; i++)
+			DPRINTF((" %02x", sc->sc_obuf[i]));
+		DPRINTF(("\n"));
+	}
+#endif
 	if (!error) {
-		err = uhidev_set_report(&sc->sc_hdev, UHID_OUTPUT_REPORT,
-					sc->sc_obuf, size);
-		if (err)
+		if (sc->sc_raw)
+			err = uhidev_write(sc->sc_hdev.sc_parent, sc->sc_obuf,
+			    size);
+		else
+			err = uhidev_set_report(&sc->sc_hdev,
+			    UHID_OUTPUT_REPORT, sc->sc_obuf, size);
+		if (err) {
+			DPRINTF(("%s: err = %d\n",
+			    device_xname(sc->sc_hdev.sc_dev), err));
 			error = EIO;
+		}
 	}
 
 	return error;
@@ -582,6 +602,14 @@ uhid_do_ioctl(struct uhid_softc *sc, u_l
 		mutex_exit(proc_lock);
 		break;
 
+	case USB_HID_GET_RAW:
+		*(int *)addr = sc->sc_raw;
+		break;
+
+	case USB_HID_SET_RAW:
+		sc->sc_raw = *(int *)addr;
+		break;
+
 	case USB_GET_REPORT_DESC:
 		uhidev_get_report_desc(sc->sc_hdev.sc_parent, &desc, &size);
 		rd = (struct usb_ctl_report_desc *)addr;

Index: src/sys/dev/usb/usbhid.h
diff -u src/sys/dev/usb/usbhid.h:1.18 src/sys/dev/usb/usbhid.h:1.18.6.1
--- src/sys/dev/usb/usbhid.h:1.18	Sun Jul 15 18:36:51 2018
+++ src/sys/dev/usb/usbhid.h	Wed Jul 15 14:09:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbhid.h,v 1.18 2018/07/15 18:36:51 maya Exp $	*/
+/*	$NetBSD: usbhid.h,v 1.18.6.1 2020/07/15 14:09:04 martin Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usbhid.h,v 1.7 1999/11/17 22:33:51 n_hibma Exp $ */
 
 /*
@@ -36,6 +36,7 @@
 #define _DEV_USB_USBHID_H_
 
 #include <dev/hid/hid.h>
+#include <sys/ioccom.h>
 
 #define UR_GET_HID_DESCRIPTOR	0x06
 #define  UDESC_HID		0x21
@@ -66,4 +67,7 @@ typedef struct usb_hid_descriptor {
 #define UHID_OUTPUT_REPORT 0x02
 #define UHID_FEATURE_REPORT 0x03
 
+#define USB_HID_GET_RAW	_IOR('h', 1, int)
+#define USB_HID_SET_RAW	_IOW('h', 2, int)
+
 #endif /* _DEV_USB_USBHID_H_ */

Reply via email to