Module Name:    src
Committed By:   christos
Date:           Mon Mar  2 18:15:29 UTC 2020

Modified Files:
        src/sys/dev/hid: hid.h
        src/sys/dev/usb: uhid.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/hid/hid.h
cvs rdiff -u -r1.111 -r1.112 src/sys/dev/usb/uhid.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/dev/hid/hid.h
diff -u src/sys/dev/hid/hid.h:1.3 src/sys/dev/hid/hid.h:1.4
--- src/sys/dev/hid/hid.h:1.3	Thu Nov 15 18:01:45 2018
+++ src/sys/dev/hid/hid.h	Mon Mar  2 13:15:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hid.h,v 1.3 2018/11/15 23:01:45 jakllsch Exp $	*/
+/*	$NetBSD: hid.h,v 1.4 2020/03/02 18:15:28 christos Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/hid.h,v 1.7 1999/11/17 22:33:40 n_hibma Exp $ */
 
 /*
@@ -123,6 +123,7 @@ int hid_is_collection(const void *, int,
 #define HUP_CAMERA_CONTROL	0x0090
 #define HUP_ARCADE		0x0091
 #define HUP_VENDOR		0x00ff
+#define HUP_FIDO		0xf1d0
 #define HUP_MICROSOFT		0xff00
 /* XXX compat */
 #define HUP_APPLE		0x00ff
@@ -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.111 src/sys/dev/usb/uhid.c:1.112
--- src/sys/dev/usb/uhid.c:1.111	Wed Jan  1 04:05:03 2020
+++ src/sys/dev/usb/uhid.c	Mon Mar  2 13:15:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhid.c,v 1.111 2020/01/01 09:05:03 maxv Exp $	*/
+/*	$NetBSD: uhid.c,v 1.112 2020/03/02 18:15:28 christos 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.111 2020/01/01 09:05:03 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.112 2020/03/02 18:15:28 christos 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;

Reply via email to