From nobody Fri Feb 09 21:03:05 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TWmXT6fqhz5BL6G; Fri, 9 Feb 2024 21:03:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TWmXT5y2Yz44YG; Fri, 9 Feb 2024 21:03:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707512585; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hFXf92iOqBdhfA/g0BbA5qjrRfmc4xbt43Q4ueqzNn8=; b=It+adpRxIhtxmXHNLkWJKIljJBFJqw+f7cmdiwaQwhKeeo9clD3CUZ2/c3EARsW0OUpOnD Gfp/KXJERyllRazKdmWjpyYKDQL1N2kYIAnfph+eJnTtUixprNognZn+jwzbyIacq1y1wr FegT3Q4C/lr6luyMxdhHPVAmnHTjRuyDVfDW+4vyCIZFX5Wpl78lngb0kXCvKz87/IpACE 8onxvw//PKtv0H6MpG4Xjm9PmX6fqSqXs1B0DNDXjyDScm7Dik4mHSln3454bvDCds3QSn BAvqT+ixguU5aBMatGcjD1FE23x6XtxSf87ZgdC+s6RBV+ZIPPs4X/VXFn8EGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707512585; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hFXf92iOqBdhfA/g0BbA5qjrRfmc4xbt43Q4ueqzNn8=; b=WC3vGiXUcZcko3hkZPJeerdTYrxB07kBJlsNPdyPGIdZZqpyV/PxJARPlB4D9eZoPVqxtD TGwkq7T8MKcq3usFsTtjRgfnwcYGZI1frL75nvvlB7j16is4S7jwlzvWFSw0d44dVzzxwi ouJvp9t5qkfkln8YHUcKuRo/drqS6kbn3WYsBwMONq/MD20bCXjHG5yGh5WfaJKYuVkViC o4LUSlUgXBdrnx9PjhfwLhfVmxeC8rV5tc9cTBXHZnS9Tie8CKL5VICsjDS7atzMWUk3I4 R6OhFtXw4W1ydUgusGfU5SBdwF4a5kJd1sVuVrEiwVS3MtdeMV7xPZhThEtLUw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707512585; a=rsa-sha256; cv=none; b=pK7qaa5DsBzNSRfJoCu/lHjcCUw0MfnoB5pwHGzPvpj+7/JrXPjjdMbdf8Qv14IfE/Rlgh 6xuVn1OJ85FoEmoNT1sadF7FqbUqe7u09/rO+U4OY7ZJBgYzs30/4K/9dwz16nMOuE5asj +V1hYMhkLthztbIgYZVKGRfWNjXXCtVSY8XbXR9ZnFlP3sFXsvmg3esDCSNerYDAxPf9Yl 9LVx7rPlKtWP3P/yFRJX4QRCB8qNMFQ1v9WABcLJBrc41tL5AHgLXiyi1S7id6exn3cdp+ TjDQrIiw+s1K5gVxslx7yy+yFW3MdxSFEVmto7TbkEpuqvOE1iVE3lDRCaQABw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TWmXT3TgdzpW5; Fri, 9 Feb 2024 21:03:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 419L359f089013; Fri, 9 Feb 2024 21:03:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 419L35IJ089010; Fri, 9 Feb 2024 21:03:05 GMT (envelope-from git) Date: Fri, 9 Feb 2024 21:03:05 GMT Message-Id: <202402092103.419L35IJ089010@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Vladimir Kondratyev Subject: git: 2e009b460fe5 - stable/13 - hidraw(4): Implement HIDRAW_GET_DEVICEINFO ioctl List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 2e009b460fe5ddbac96e12a9c3ca05bae11817bf Auto-Submitted: auto-generated The branch stable/13 has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=2e009b460fe5ddbac96e12a9c3ca05bae11817bf commit 2e009b460fe5ddbac96e12a9c3ca05bae11817bf Author: Vladimir Kondratyev AuthorDate: 2023-08-06 11:51:08 +0000 Commit: Vladimir Kondratyev CommitDate: 2024-02-09 20:59:37 +0000 hidraw(4): Implement HIDRAW_GET_DEVICEINFO ioctl In commit c77bfaa75051 uhid(4) gained support for ioctl from USB_GET_DEVICEINFO. This is used in libraries like libfido2 to retrieve information about a device. This commit adds binary compatible version to hidraw(4). PR: 264843 (cherry picked from commit f1d955be2a7367ef755d70257c381f83b8367288) --- share/man/man4/hidraw.4 | 5 ++++- sys/dev/hid/hidraw.c | 28 +++++++++++++++++++++++----- sys/dev/hid/hidraw.h | 15 +++++++++++++++ sys/dev/usb/usb_ioctl.h | 3 ++- 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/share/man/man4/hidraw.4 b/share/man/man4/hidraw.4 index 92e01a8c9a0a..9749277bca51 100644 --- a/share/man/man4/hidraw.4 +++ b/share/man/man4/hidraw.4 @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd July 1, 2018 +.Dd August 6, 2023 .Dt HIDRAW 4 .Os .Sh NAME @@ -145,6 +145,9 @@ The report data begins from the second byte. For devices which do not use numbered reports, the report data begins at the first byte. This call may fail if the device does not support this feature. +.It Dv HIDRAW_GET_DEVICEINFO Pq Vt "struct hidraw_device_info" +Returns information about the device, like vendor ID and product ID. +This call will not issue any hardware transfers. .El .Pp Linux diff --git a/sys/dev/hid/hidraw.c b/sys/dev/hid/hidraw.c index c47a1445f7af..703e16d8bf8f 100644 --- a/sys/dev/hid/hidraw.c +++ b/sys/dev/hid/hidraw.c @@ -564,9 +564,10 @@ hidraw_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, #endif void *buf; struct hidraw_softc *sc; + struct hidraw_device_info *hdi; struct hidraw_gen_descriptor *hgd; struct hidraw_report_descriptor *hrd; - struct hidraw_devinfo *hdi; + struct hidraw_devinfo *hd; const char *devname; uint32_t size; int id, len; @@ -795,6 +796,23 @@ hidraw_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, *(int *)addr = 0; /* XXX: we only support reportid 0? */ return (0); + case HIDRAW_GET_DEVICEINFO: + hdi = (struct hidraw_device_info *)addr; + bzero(hdi, sizeof(struct hidraw_device_info)); + hdi->hdi_product = sc->sc_hw->idProduct; + hdi->hdi_vendor = sc->sc_hw->idVendor; + hdi->hdi_version = sc->sc_hw->idVersion; + hdi->hdi_bustype = sc->sc_hw->idBus; + strlcpy(hdi->hdi_name, sc->sc_hw->name, + sizeof(hdi->hdi_name)); + strlcpy(hdi->hdi_phys, device_get_nameunit(sc->sc_dev), + sizeof(hdi->hdi_phys)); + strlcpy(hdi->hdi_uniq, sc->sc_hw->serial, + sizeof(hdi->hdi_uniq)); + snprintf(hdi->hdi_release, sizeof(hdi->hdi_release), "%x.%02x", + sc->sc_hw->idVersion >> 8, sc->sc_hw->idVersion & 0xff); + return(0); + case HIDIOCGRDESCSIZE: *(int *)addr = sc->sc_hw->rdescsize; return (0); @@ -820,10 +838,10 @@ hidraw_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, return (error); case HIDIOCGRAWINFO: - hdi = (struct hidraw_devinfo *)addr; - hdi->bustype = sc->sc_hw->idBus; - hdi->vendor = sc->sc_hw->idVendor; - hdi->product = sc->sc_hw->idProduct; + hd = (struct hidraw_devinfo *)addr; + hd->bustype = sc->sc_hw->idBus; + hd->vendor = sc->sc_hw->idVendor; + hd->product = sc->sc_hw->idProduct; return (0); } diff --git a/sys/dev/hid/hidraw.h b/sys/dev/hid/hidraw.h index 5e46597be453..4095ddb388bb 100644 --- a/sys/dev/hid/hidraw.h +++ b/sys/dev/hid/hidraw.h @@ -49,6 +49,20 @@ struct hidraw_gen_descriptor { uint8_t reserved[8]; }; +/* Compatible with usb_device_info structure */ +struct hidraw_device_info { + uint16_t hdi_product; + uint16_t hdi_vendor; + uint16_t hdi_version; + uint8_t occupied[18]; /* by usb_device_info */ + uint16_t hdi_bustype; + uint8_t reserved[14]; /* leave space for the future */ + char hdi_name[128]; + char hdi_phys[128]; + char hdi_uniq[64]; + char hdi_release[8]; /* decrypted USB bcdDevice */ +}; + struct hidraw_report_descriptor { uint32_t size; uint8_t value[HID_MAX_DESCRIPTOR_SIZE]; @@ -67,6 +81,7 @@ struct hidraw_devinfo { #define HIDRAW_SET_REPORT _IOW ('U', 24, struct hidraw_gen_descriptor) #define HIDRAW_GET_REPORT_ID _IOR ('U', 25, int) #define HIDRAW_SET_REPORT_DESC _IOW ('U', 26, struct hidraw_gen_descriptor) +#define HIDRAW_GET_DEVICEINFO _IOR ('U', 112, struct hidraw_device_info) /* Linux hidraw-compatible ioctl interface */ #define HIDIOCGRDESCSIZE _IOR('U', 30, int) diff --git a/sys/dev/usb/usb_ioctl.h b/sys/dev/usb/usb_ioctl.h index ba6e5f18d0bb..6d9184723816 100644 --- a/sys/dev/usb/usb_ioctl.h +++ b/sys/dev/usb/usb_ioctl.h @@ -119,7 +119,8 @@ struct usb_device_info { uint8_t udi_hubport; /* parent HUB port */ uint8_t udi_power_mode; /* see "USB_POWER_MODE_XXX" */ uint8_t udi_suspended; /* set if device is suspended */ - uint8_t udi_reserved[16]; /* leave space for the future */ + uint16_t udi_bustypeNo; + uint8_t udi_reserved[14]; /* leave space for the future */ char udi_product[128]; char udi_vendor[128]; char udi_serial[64];