Skip to content

HIDAPI does not recognize "virtual" HID device #744

Closed

Description

@tuxedo-wse

So with this driver https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=cfd84b3f419bf0aec60ecddc92c61b539c339ec9 there is a virtual HID device i.e. a hid device that exists just in software and is not connected to a bus.

HIDAPI does net seems to recognize this.

My minimal test code:

#include <stdio.h>
#include <hidapi/hidapi.h>

int main() {
    printf("HID Devices:\n");
    struct hid_device_info *devi, *dev = hid_enumerate(0, 0);
    devi = dev;
    while(devi != NULL) {
        printf("%04x:%04x\n", devi->vendor_id, devi->product_id);
        devi = devi->next;
    }
    hid_free_enumeration(dev);
}

Compiled with gcc test.c -lhidapi-hidraw for the hidraw interface, this does not liste the device, while /sys/class/hidraw/ has the device.

Activity

  1. added
    hidrawRelated to Linux/hidraw backend
    on May 21, 2025
  2. mcuee commented on May 21, 2025

    @mcuee
    Member

    Does this device show up as /dev/hidraw*? If this device is not a USB hid device and yet not show up as hidraw device, then hidapi cannot find it.

    Also you need to have permission. You may want to try to run as sudo to see if that helps.

  3. mcuee commented on May 21, 2025

    @mcuee
    Member

    Basically you can run the Linux kernel hid-example to see if that works or not.
    https://github.com/torvalds/linux/blob/master/samples/hidraw/hid-example.c

  4. tuxedo-wse commented on May 21, 2025

    @tuxedo-wse
    ContributorAuthor

    Does this device show up as /dev/hidraw*?

    Yes

    Also you need to have permission. You may want to try to run as sudo to see if that helps.

    I did that but didn't help

  5. tuxedo-wse commented on May 21, 2025

    @tuxedo-wse
    ContributorAuthor

    More testing using hid_open_path:

    #include <stdio.h>
    
    #include <hidapi/hidapi.h>
    
    int main() {
        printf("HID Devices:\n");
        struct hid_device_info *devi, *dev = hid_enumerate(0, 0);
        devi = dev;
        while(devi != NULL) {
            printf("%04x:%04x\n", devi->vendor_id, devi->product_id);
            devi = devi->next;
        }
        hid_free_enumeration(dev);
    
        hid_device *foo = hid_open_path("/dev/hidraw2");
        devi = hid_get_device_info(foo);
        printf("\n%04x:%04x\n", devi->vendor_id, devi->product_id);
        hid_close(foo);
    
        foo = hid_open_path("/dev/hidraw3");
        devi = hid_get_device_info(foo);
        printf("\n%04x:%04x\n", devi->vendor_id, devi->product_id);
        hid_close(foo);
    }
    

    Both /dev/hidraw2 and /dev/hidraw3 exist and i run the programm with root.

    hidraw2 is a normal physical device (I think the usb keyboard), hidraw3 is the virtual device from the driver.

    The hidraw 2 example works fine while the hidraw3 example crashes at the printf step

  6. tuxedo-wse commented on May 21, 2025

    @tuxedo-wse
    ContributorAuthor

    hid_error tells me "couldn't create hid_device_info"

  7. tuxedo-wse commented on May 21, 2025

    @tuxedo-wse
    ContributorAuthor

    Following that trace my educated guess is that the culprit is this switch statement:

    switch (bus_type) {

    It expects the bus type to be USB, BT, I2C, or SPI, but this device is none of that (in the kernel driver it is specified it as BUS_VIRTUAL https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/platform/x86/tuxedo/nb04/wmi_ab.c?id=cfd84b3f419bf0aec60ecddc92c61b539c339ec9#n841 , I guess that is the same define that is asked for here?)

  8. tuxedo-wse commented on May 21, 2025

    @tuxedo-wse
    ContributorAuthor

    there is a switch statement before that with a clear comment:

    /* Filter out unhandled devices right away */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    hidrawRelated to Linux/hidraw backend

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions