Bug 264843 - hidraw(4) lacks support for USB_GET_DEVICEINFO
Summary: hidraw(4) lacks support for USB_GET_DEVICEINFO
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 13.1-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: Vladimir Kondratyev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-06-23 10:51 UTC by Michael Gmelin
Modified: 2024-02-09 21:09 UTC (History)
1 user (show)

See Also:
linimon: mfc-stable13?


Attachments
HIDRAW_DEVINFO ioctl support (2.82 KB, patch)
2022-09-24 12:31 UTC, Vladimir Kondratyev
no flags Details | Diff
HIDRAW_GET_DEVICEINFO.patch (2.86 KB, patch)
2022-09-24 15:58 UTC, Vladimir Kondratyev
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Gmelin freebsd_committer freebsd_triage 2022-06-23 10:51:02 UTC
In https://cgit.freebsd.org/src/commit/sys/dev/usb/input/uhid.c?id=c77bfaa75051254e1d uhid(4) gained support for ioctl from USB_GET_DEVICEINFO. This is used in libraries like libfido2 to retrieve information about a device. Even though some of this information can be retrieved using hidraw(4), some values like retrieving vendor and product name in distinct fields isn't possible. It also breaks compatibility with uhid(4).

I looked at the code, but realized that whatever I would try doing myself would be hacky, therefore I'm opening this PR to either have somebody implement it or give some advise how to approach it best.
Comment 1 Vladimir Kondratyev freebsd_committer freebsd_triage 2022-09-24 12:31:07 UTC
Created attachment 236789 [details]
HIDRAW_DEVINFO ioctl support

Please test attached patch
Comment 2 Vladimir Kondratyev freebsd_committer freebsd_triage 2022-09-24 15:58:44 UTC
Created attachment 236791 [details]
HIDRAW_GET_DEVICEINFO.patch

Actually, uhid(4) uses USB_DEVINFO alias called USB_GET_DEVICEINFO rather than USB_DEVINFO itself.

Patch updated.
Comment 3 Vladimir Kondratyev freebsd_committer freebsd_triage 2022-11-16 22:44:19 UTC
Is retrieving of vendor and product name in distinct fields strictly necessary?
Evdev device name which is exposed as USB_GET_DEVICEINFO`s product name in this patch is a composition of both USB vendor and product strings.
Comment 4 Michael Gmelin freebsd_committer freebsd_triage 2022-12-09 17:22:48 UTC
(In reply to Vladimir Kondratyev from comment #3)

It would be really helpful if it was possible (since the vendor/product distinction is very common and not having it means hacky patches like "Vendor=FreeBSD Product=Some Manufcaturer's device called XYZ"
Comment 5 Vladimir Kondratyev freebsd_committer freebsd_triage 2022-12-09 19:31:27 UTC
(In reply to Michael Gmelin from comment #4)

The patch exposes HID device name as USB_GET_DEVICEINFO's product name. In usbhid(4) case device name is a concatenation of vendor string and product string. See line 745 of sys/dev/usb/input/usbhid.c. That means that hidraw(4) and uhid(4) exports the same data but uses different format

hidraw format:
Product: USB vendor string + USB product string
Vendor:  device_nameunit()

uhid format:
Product: USB product string
Vendor:  USB vendor string

I can add support for uhid style USB_GET_DEVICEINFO product/vendor format for Yubico devices through direct call to ugen_fill_deviceinfo() for compatibility reasons, but I see no reasons to do that for all USB devices.
Comment 6 commit-hook freebsd_committer freebsd_triage 2023-08-06 11:52:14 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=f1d955be2a7367ef755d70257c381f83b8367288

commit f1d955be2a7367ef755d70257c381f83b8367288
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2023-08-06 11:51:08 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2023-08-06 11:51:08 +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
    MFC after:      1 month
    Requested by:   grembo

 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(-)
Comment 7 Vladimir Kondratyev freebsd_committer freebsd_triage 2023-08-29 22:33:36 UTC
See https://reviews.freebsd.org/D41639
Comment 8 Mark Johnston freebsd_committer freebsd_triage 2024-01-26 20:48:34 UTC
Is there anything left to do for this PR?
Comment 9 Mark Linimon freebsd_committer freebsd_triage 2024-02-08 02:58:44 UTC
^Triage: now see https://reviews.freebsd.org/D41639 .  Leaving open only for MFC possibility.
Comment 10 commit-hook freebsd_committer freebsd_triage 2024-02-09 21:03:58 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=2e009b460fe5ddbac96e12a9c3ca05bae11817bf

commit 2e009b460fe5ddbac96e12a9c3ca05bae11817bf
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2023-08-06 11:51:08 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
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(-)
Comment 11 Vladimir Kondratyev freebsd_committer freebsd_triage 2024-02-09 21:09:01 UTC
I have no intention to implement exact copy of USB_GET_DEVICEINFO ioctl in hidraw. It will be done in separate u2f driver. See https://reviews.freebsd.org/D41639