Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-9]: src/sys/dev Pull up following revision(s) (requested by riast...



details:   https://anonhg.NetBSD.org/src/rev/bb9042018ce7
branches:  netbsd-9
changeset: 936004:bb9042018ce7
user:      martin <martin%NetBSD.org@localhost>
date:      Wed Jul 15 14:09:04 2020 +0000

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

diffstat:

 sys/dev/hid/hid.h    |   8 ++++++--
 sys/dev/usb/uhid.c   |  40 ++++++++++++++++++++++++++++++++++------
 sys/dev/usb/usbhid.h |   6 +++++-
 3 files changed, 45 insertions(+), 9 deletions(-)

diffs (141 lines):

diff -r 7241618d1956 -r bb9042018ce7 sys/dev/hid/hid.h
--- a/sys/dev/hid/hid.h Wed Jul 15 14:02:36 2020 +0000
+++ b/sys/dev/hid/hid.h Wed Jul 15 14:09:04 2020 +0000
@@ -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 @@
 #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 @@
 /* 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)
diff -r 7241618d1956 -r bb9042018ce7 sys/dev/usb/uhid.c
--- a/sys/dev/usb/uhid.c        Wed Jul 15 14:02:36 2020 +0000
+++ b/sys/dev/usb/uhid.c        Wed Jul 15 14:09:04 2020 +0000
@@ -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 @@
 #define UHID_IMMED     0x02    /* return read data immediately */
 
        int sc_refcnt;
+       int sc_raw;
        u_char sc_dying;
 };
 
@@ -184,6 +185,8 @@
        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 @@
                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 @@
                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;
diff -r 7241618d1956 -r bb9042018ce7 sys/dev/usb/usbhid.h
--- a/sys/dev/usb/usbhid.h      Wed Jul 15 14:02:36 2020 +0000
+++ b/sys/dev/usb/usbhid.h      Wed Jul 15 14:09:04 2020 +0000
@@ -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 @@
 #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_ */



Home | Main Index | Thread Index | Old Index