From nobody Thu Mar 03 08:47:12 2022 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 6B15219F3F65; Thu, 3 Mar 2022 08:47:33 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (turbocat.net [IPv6:2a01:4f8:c17:6c4b::2]) (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 mx1.freebsd.org (Postfix) with ESMTPS id 4K8PkX3qk6z4VGx; Thu, 3 Mar 2022 08:47:32 +0000 (UTC) (envelope-from hps@selasky.org) Received: from [10.36.2.165] (unknown [178.17.145.105]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id 7DD1C26003E; Thu, 3 Mar 2022 09:47:27 +0100 (CET) Message-ID: <6f2911c4-63cf-687c-e042-5d687a967096@selasky.org> Date: Thu, 3 Mar 2022 09:47:12 +0100 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 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: git: 82e38b012cc8 - main - usbhid(4): Implement USB_REQUEST command in hid_ioctl method Content-Language: en-US To: Vladimir Kondratyev , src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org References: <202203022336.222NacHn001574@gitrepo.freebsd.org> From: Hans Petter Selasky In-Reply-To: <202203022336.222NacHn001574@gitrepo.freebsd.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4K8PkX3qk6z4VGx X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of hps@selasky.org designates 2a01:4f8:c17:6c4b::2 as permitted sender) smtp.mailfrom=hps@selasky.org X-Spamd-Result: default: False [-3.29 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; R_SPF_ALLOW(-0.20)[+a:mail.turbocat.net]; DMARC_NA(0.00)[selasky.org]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.99)[-0.995]; MLMMJ_DEST(0.00)[dev-commits-src-all,dev-commits-src-main]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:24940, ipnet:2a01:4f8::/32, country:DE]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-ThisMailContainsUnwantedMimeParts: N On 3/3/22 00:36, Vladimir Kondratyev wrote: > The branch main has been updated by wulf: > > URL: https://cgit.FreeBSD.org/src/commit/?id=82e38b012cc832651ba195f5443e7f9fb64ce5d3 > > commit 82e38b012cc832651ba195f5443e7f9fb64ce5d3 > Author: Vladimir Kondratyev > AuthorDate: 2022-03-02 23:35:23 +0000 > Commit: Vladimir Kondratyev > CommitDate: 2022-03-02 23:35:23 +0000 > > usbhid(4): Implement USB_REQUEST command in hid_ioctl method > > This command is intended to be compatible with USB_REQUEST ioctl. > It is required to perform arbitrary control endpoint requests by device > drivers which can switch between HID and native non-HID modes. > > MFC after: 2 month > --- > sys/dev/usb/input/usbhid.c | 31 +++++++++++++++++++++++++++++++ > 1 file changed, 31 insertions(+) > > diff --git a/sys/dev/usb/input/usbhid.c b/sys/dev/usb/input/usbhid.c > index c6f2a1f24303..ed76f6291a11 100644 > --- a/sys/dev/usb/input/usbhid.c > +++ b/sys/dev/usb/input/usbhid.c > @@ -68,6 +68,7 @@ __FBSDID("$FreeBSD$"); > #include > #include > #include > +#include > > #define USB_DEBUG_VAR usbhid_debug > #include > @@ -677,6 +678,35 @@ usbhid_set_protocol(device_t dev, uint16_t protocol) > return (usbhid_sync_xfer(sc, USBHID_CTRL_DT, &req, NULL)); > } > You may also want to add a call to: static int ugen_check_request(struct usb_device *udev, struct usb_device_request *req) { so that non-root drivers won't and can't do damaging commands to the device! --HPS > +static int > +usbhid_ioctl(device_t dev, unsigned long cmd, uintptr_t data) > +{ > + struct usbhid_softc* sc = device_get_softc(dev); > + struct usb_ctl_request *ucr; > + union usbhid_device_request req; > + int error; > + > + switch (cmd) { > + case USB_REQUEST: > + ucr = (struct usb_ctl_request *)data; > + req.ctrl = ucr->ucr_request; > + error = usbhid_xfer_check_len( > + sc, USBHID_CTRL_DT, UGETW(req.ctrl.wLength)); > + if (error) > + break; > + > + error = usbhid_sync_xfer( > + sc, USBHID_CTRL_DT, &req, ucr->ucr_data); > + if (error == 0) > + ucr->ucr_actlen = UGETW(req.ctrl.wLength); > + break; > + default: > + error = EINVAL; > + } > + > + return (error); > +} > + > static void > usbhid_init_device_info(struct usb_attach_arg *uaa, struct hid_device_info *hw) > { > @@ -848,6 +878,7 @@ static device_method_t usbhid_methods[] = { > DEVMETHOD(hid_set_report, usbhid_set_report), > DEVMETHOD(hid_set_idle, usbhid_set_idle), > DEVMETHOD(hid_set_protocol, usbhid_set_protocol), > + DEVMETHOD(hid_ioctl, usbhid_ioctl), > > DEVMETHOD_END > }; >