From nobody Sun Apr 27 09:09:04 2025 X-Original-To: dev-commits-src-main@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 4Zlgk96DJkz5vXcM; Sun, 27 Apr 2025 09:09: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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Zlgk86mKYz48R5; Sun, 27 Apr 2025 09:09:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745744944; 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=zbcxb6xJ12Hz1aieo6aMsJ6B7bA779RqdtmcIrEazAQ=; b=UNI4/te+Xp6ZgzaSMHGDUyWttECquB4w/K6hb4p38yDPhiTC0qwtcZjTxmPXvxMjZZuoBk hVVAR5hn87gAj+KAYLO4Y1mBeKC0l/1ALS/T127nl+aF3vrfA0WKAbL3OOyXt29MbMRXHI z/Jb7GAosTm/JgkptQ4g32O1I7sxkslZwUQoPKqqrrPKIws1bgVIZFUZt+iPSebrioH0oL k/bsvPysHW2+H3mjLoSt568uBeVmb9GzA1Z8rYbVIcJ5NBaYGYkJQubqki5m7tuJ9j/zuK frJfbuJxHp0SQoj6PTx8BOVOUpfpiJ05TryPEq3Oos+U0APUCZjYapeXXJQwVg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1745744944; a=rsa-sha256; cv=none; b=MnAftZVYiIG51ggE2ifaDgfh5Q1qAFTuG7UUXSoxRE2GdAvyWKSmO9nhCwj74MHTY90RjE 3vm0lhRsmizT1ioSjD+tWIb0IHWkoPTT6lk275rxnMD67pZcyXJqbprD3YoEgbDuys4N9b Lf8RoIegjsrwaYr7E9VVHbyJZzkgJtjGwVqIy8IG3uyMLn1SNU/bqlpvTfTXH9mduUG9T+ fkK/b2mbryj/yrTtb3zUmO6SnrsdQRuXYDZPRqKSE9VCpK14XkD+meZAXPNkqwXSszQhF9 At/00DPOwFtMoT+v2B/dhGwnjM5qjY1Zdi3yqMiG8zhQZJeZs8oep4AqAA3StA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745744944; 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=zbcxb6xJ12Hz1aieo6aMsJ6B7bA779RqdtmcIrEazAQ=; b=ddlU6lEC/nKl/W9n/sfx31TnY8SvUtUo6Sba1OCxUvdzr6lZ9jLdN7gI5KTXzRKi3NwLAO yKxFOdfbtQB28hD4uDN9Fa4BA1fAnciSIKBAYLsThJlqGhC1Lhgs/CdgoNZRjUD0hbpYCx xqPYp6NZd0QdsiihGNI+aFUJIEzd2gxFIilzS+KQg4olz4GqSKjrqc2Cq9L5xCw33miOxu p7YybJMKu6tInaipiyNP0dt67S7YRKLD46px26IhDX2g4m55ikLHdD9ssmRRFK4oqtuLZY qU3TV9X6FHDWnQ4CPW/lD5SarvI6NveOfTwj4OFj/saLZc6U7FDe2/jOn9Heeg== 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 4Zlgk86Bsxz10SV; Sun, 27 Apr 2025 09:09:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 53R99425053707; Sun, 27 Apr 2025 09:09:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53R994SE053704; Sun, 27 Apr 2025 09:09:04 GMT (envelope-from git) Date: Sun, 27 Apr 2025 09:09:04 GMT Message-Id: <202504270909.53R994SE053704@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: fd6690e2d5cd - main - hidraw(4): Add additional hidraw input/output report ioctls List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: fd6690e2d5cd5b15fce2c74ab0cac77a83514f6a Auto-Submitted: auto-generated The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=fd6690e2d5cd5b15fce2c74ab0cac77a83514f6a commit fd6690e2d5cd5b15fce2c74ab0cac77a83514f6a Author: Vladimir Kondratyev AuthorDate: 2025-04-27 09:07:35 +0000 Commit: Vladimir Kondratyev CommitDate: 2025-04-27 09:07:35 +0000 hidraw(4): Add additional hidraw input/output report ioctls to Linux hidraw compatibility API. Respective Linux commit f43d3870cafa made by Dean Camera message is: Currently the hidraw module can only read and write feature HID reports on demand, via dedicated ioctls. Input reports are read from the device through the read() interface, while output reports are written through the write interface(). This is insufficient; it is desirable in many situations to be able to read and write input and output reports through the control interface to cover additional scenarios: - Reading an input report by its report ID, to get initial state - Writing an input report, to set initial input state in the device - Reading an output report by its report ID, to obtain current state - Writing an output report by its report ID, out of band This patch adds these missing ioctl requests to read and write the remaining HID report types. Note that not all HID backends will neccesarily support this (e.g. while the USB link layer supports setting Input reports, others may not). FreeBSD native uhid(4) compatible API already has similar ioctls. MFC after: 3 days --- share/man/man4/hidraw.4 | 12 ++++++++---- sys/dev/hid/hidraw.c | 38 ++++++++++++++++++++++++++++++++++---- sys/dev/hid/hidraw.h | 4 ++++ sys/dev/usb/usb_ioctl.h | 2 +- 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/share/man/man4/hidraw.4 b/share/man/man4/hidraw.4 index f8eb9a21e9d7..0353e49a7425 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 August 6, 2023 +.Dd April 27, 2025 .Dt HIDRAW 4 .Os .Sh NAME @@ -206,10 +206,12 @@ into the memory specified by .Va buf . .It Dv HIDIOCGFEATURE(len) Pq Vt "void[] buf" -Get a feature report from the device. +.It Dv HIDIOCGINPUT(len) Pq Vt "void[] buf" +.It Dv HIDIOCGOUTPUT(len) Pq Vt "void[] buf" +Get respectively a feature, input or output report from the device. Copies a maximum of .Va len -bytes of the feature report data into the memory specified by +bytes of the report data into the memory specified by .Va buf . The first byte of the supplied buffer should be set to the report number of the requested report. @@ -218,7 +220,9 @@ The report will be returned starting at the first byte of the buffer (ie: the report number is not returned). This call may fail if the device does not support this feature. .It Dv HIDIOCSFEATURE(len) Pq Vt "void[] buf" -Set a feature Report in the device. +.It Dv HIDIOCSINPUT(len) Pq Vt "void[] buf" +.It Dv HIDIOCSOUTPUT(len) Pq Vt "void[] buf" +Set respectively a feature, input or output Report in the device. The value of the report is specified by the .Va buf and the diff --git a/sys/dev/hid/hidraw.c b/sys/dev/hid/hidraw.c index 45ef1995063e..7aca66e2dd1d 100644 --- a/sys/dev/hid/hidraw.c +++ b/sys/dev/hid/hidraw.c @@ -3,7 +3,7 @@ * * Copyright (c) 1998 The NetBSD Foundation, Inc. * All rights reserved. - * Copyright (c) 2020 Vladimir Kondratyev + * Copyright (c) 2020, 2025 Vladimir Kondratyev * * This code is derived from software contributed to The NetBSD Foundation * by Lennart Augustsson (lennart@augustsson.net) at @@ -573,6 +573,7 @@ hidraw_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, hid_size_t actsize; int id, len; int error = 0; + uint8_t reptype; DPRINTFN(2, "cmd=%lx\n", cmd); @@ -860,6 +861,8 @@ hidraw_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, return (0); case HIDIOCSFEATURE(0): + case HIDIOCSINPUT(0): + case HIDIOCSOUTPUT(0): if (!(sc->sc_fflags & FWRITE)) return (EPERM); if (len < 2) @@ -869,10 +872,24 @@ hidraw_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, addr = (uint8_t *)addr + 1; len--; } - return (hid_set_report(sc->sc_dev, addr, len, - HID_FEATURE_REPORT, id)); + switch (IOCBASECMD(cmd)) { + case HIDIOCSFEATURE(0): + reptype = HID_FEATURE_REPORT; + break; + case HIDIOCSINPUT(0): + reptype = HID_INPUT_REPORT; + break; + case HIDIOCSOUTPUT(0): + reptype = HID_OUTPUT_REPORT; + break; + default: + panic("Invalid report type"); + } + return (hid_set_report(sc->sc_dev, addr, len, reptype, id)); case HIDIOCGFEATURE(0): + case HIDIOCGINPUT(0): + case HIDIOCGOUTPUT(0): if (!(sc->sc_fflags & FREAD)) return (EPERM); if (len < 2) @@ -882,8 +899,21 @@ hidraw_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, addr = (uint8_t *)addr + 1; len--; } + switch (IOCBASECMD(cmd)) { + case HIDIOCGFEATURE(0): + reptype = HID_FEATURE_REPORT; + break; + case HIDIOCGINPUT(0): + reptype = HID_INPUT_REPORT; + break; + case HIDIOCGOUTPUT(0): + reptype = HID_OUTPUT_REPORT; + break; + default: + panic("Invalid report type"); + } return (hid_get_report(sc->sc_dev, addr, len, NULL, - HID_FEATURE_REPORT, id)); + reptype, id)); case HIDIOCGRAWUNIQ(0): strlcpy(addr, sc->sc_hw->serial, len); diff --git a/sys/dev/hid/hidraw.h b/sys/dev/hid/hidraw.h index 4095ddb388bb..41aaf285fac3 100644 --- a/sys/dev/hid/hidraw.h +++ b/sys/dev/hid/hidraw.h @@ -92,5 +92,9 @@ struct hidraw_devinfo { #define HIDIOCSFEATURE(len) _IOC(IOC_IN, 'U', 35, len) #define HIDIOCGFEATURE(len) _IOC(IOC_INOUT, 'U', 36, len) #define HIDIOCGRAWUNIQ(len) _IOC(IOC_OUT, 'U', 37, len) +#define HIDIOCSINPUT(len) _IOC(IOC_IN, 'U', 38, len) +#define HIDIOCGINPUT(len) _IOC(IOC_INOUT, 'U', 39, len) +#define HIDIOCSOUTPUT(len) _IOC(IOC_IN, 'U', 40, len) +#define HIDIOCGOUTPUT(len) _IOC(IOC_INOUT, 'U', 41, len) #endif /* _HID_HIDRAW_H */ diff --git a/sys/dev/usb/usb_ioctl.h b/sys/dev/usb/usb_ioctl.h index 6d9184723816..85979b9cf778 100644 --- a/sys/dev/usb/usb_ioctl.h +++ b/sys/dev/usb/usb_ioctl.h @@ -239,7 +239,7 @@ struct usb_gen_quirk { #define USB_DEVICESTATS _IOR ('U', 5, struct usb_device_stats) #define USB_DEVICEENUMERATE _IOW ('U', 6, int) -/* Generic HID device. Numbers 26 and 30-39 are occupied by hidraw. */ +/* Generic HID device. Numbers 26 and 30-49 are occupied by hidraw. */ #define USB_GET_REPORT_DESC _IOWR('U', 21, struct usb_gen_descriptor) #define USB_SET_IMMED _IOW ('U', 22, int) #define USB_GET_REPORT _IOWR('U', 23, struct usb_gen_descriptor)