Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to retrieve bus_type for some devices on Windows #502

Open
AlexGuo1998 opened this issue Feb 4, 2023 · 6 comments
Open

Unable to retrieve bus_type for some devices on Windows #502

AlexGuo1998 opened this issue Feb 4, 2023 · 6 comments
Labels
Windows Related to Windows backend

Comments

@AlexGuo1998
Copy link

On windows, we currently inspect the parent devnode to get bus_type:

hidapi/windows/hid.c

Lines 498 to 552 in 4ebce6b

/* Get devnode parent */
cr = CM_Get_Parent(&dev_node, dev_node, 0);
if (cr != CR_SUCCESS)
goto end;
/* Get the compatible ids from parent devnode */
compatible_ids = hid_internal_get_devnode_property(dev_node, &DEVPKEY_Device_CompatibleIds, DEVPROP_TYPE_STRING_LIST);
if (!compatible_ids)
goto end;
/* Now we can parse parent's compatible IDs to find out the device bus type */
for (wchar_t* compatible_id = compatible_ids; *compatible_id; compatible_id += wcslen(compatible_id) + 1) {
/* Normalize to upper case */
for (wchar_t* p = compatible_id; *p; ++p) *p = towupper(*p);
/* USB devices
https://docs.microsoft.com/windows-hardware/drivers/hid/plug-and-play-support
https://docs.microsoft.com/windows-hardware/drivers/install/standard-usb-identifiers */
if (wcsstr(compatible_id, L"USB") != NULL) {
dev->bus_type = HID_API_BUS_USB;
break;
}
/* Bluetooth devices
https://docs.microsoft.com/windows-hardware/drivers/bluetooth/installing-a-bluetooth-device */
if (wcsstr(compatible_id, L"BTHENUM") != NULL) {
dev->bus_type = HID_API_BUS_BLUETOOTH;
break;
}
/* Bluetooth LE devices */
if (wcsstr(compatible_id, L"BTHLEDEVICE") != NULL) {
/* HidD_GetProductString/HidD_GetManufacturerString/HidD_GetSerialNumberString is not working for BLE HID devices
Request this info via dev node properties instead.
https://docs.microsoft.com/answers/questions/401236/hidd-getproductstring-with-ble-hid-device.html */
hid_internal_get_ble_info(dev, dev_node);
dev->bus_type = HID_API_BUS_BLUETOOTH;
break;
}
/* I2C devices
https://docs.microsoft.com/windows-hardware/drivers/hid/plug-and-play-support-and-power-management */
if (wcsstr(compatible_id, L"PNP0C50") != NULL) {
dev->bus_type = HID_API_BUS_I2C;
break;
}
/* SPI devices
https://docs.microsoft.com/windows-hardware/drivers/hid/plug-and-play-for-spi */
if (wcsstr(compatible_id, L"PNP0C51") != NULL) {
dev->bus_type = HID_API_BUS_SPI;
break;
}
}

However, some filtered HID device (e.g. imbushuo/mac-precision-touchpad) whose parent is the filter driver, which don't have a correct compatible_id. The device tree is like this:

...                                           (page usage)
Microsoft Bluetooth Enumerator
|- Bluetooth HID device                                   <- 3
   |- Apple Multi-touch Auxiliary Services    (FF00 0014)
   |- Apple Multi-touch Trackpad HID Filter               <- 2
      |- Microsoft Input Configuration Device (000D 000E)
      |- HID Compactible Trackpad             (000D 0005) <- 1

If we want to know the bus_type for (1), according to the code, we're inspecting the compatible_id for (2), which is empty.

However if we go one step further we hit (3), which has the correct compatible_id: BTHENUM\{GUID}. Now we know it's a Bluetooth device.


I suggest we go all the way up, until to the root to find a recognizable compatible_id, and stop after we found one.

I don't really know if this is the correct / sane thing to do. Could you give me some ideas?


BTW, on a UEFI laptop some devices have a ancestor with a compatible_id like *PNP0A03, but no more recognizable value. Do you know what that is? (Maybe we can open another issue for this?)

@Youw Youw added the Windows Related to Windows backend label Feb 4, 2023
@Youw
Copy link
Member

Youw commented Feb 4, 2023

is #464 of any relevance to the issue described here?

@AlexGuo1998
Copy link
Author

I'm not quite sure but maybe no.

In this situation, we don't even find USB in any of the compatible_ids, while #464 attempts to add some extra logic in if(wcsstr(compatible_id, L"USB") != NULL)

@JoergAtGithub
Copy link
Contributor

@DJm00n can you help with this Bluetooth bus_type issue?

@Youw
Copy link
Member

Youw commented Feb 5, 2023

I suggest we go all the way up, until to the root to find a recognizable compatible_id, and stop after we found one.

This does sounds like a good solution. But I guess i has to be in line with other changes (including #464).

@DJm00n
Copy link
Contributor

DJm00n commented Mar 13, 2023

@AlexGuo1998 thank you for reporting. I'll review cr = CM_Get_Parent(&dev_node, dev_node, 0); after #464 get merged.

PS: according to the C:\Windows\INF\pci.inf PNP0A03 is a "PCI Bus".

@mcuee
Copy link
Member

mcuee commented May 2, 2023

@DJm00n

#464 has been merged. Maybe you want to take a look at this issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Windows Related to Windows backend
Projects
None yet
Development

No branches or pull requests

5 participants