MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / hid_internal_get_info

Function hid_internal_get_info

lib/hidapi/windows/hid.c:593–664  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

591}
592
593static void hid_internal_get_info(const wchar_t* interface_path, struct hid_device_info* dev)
594{
595 wchar_t *device_id = NULL, *compatible_ids = NULL;
596 CONFIGRET cr;
597 DEVINST dev_node;
598
599 /* Get the device id from interface path */
600 device_id = hid_internal_get_device_interface_property(interface_path, &DEVPKEY_Device_InstanceId, DEVPROP_TYPE_STRING);
601 if (!device_id)
602 goto end;
603
604 /* Open devnode from device id */
605 cr = CM_Locate_DevNodeW(&dev_node, (DEVINSTID_W)device_id, CM_LOCATE_DEVNODE_NORMAL);
606 if (cr != CR_SUCCESS)
607 goto end;
608
609 /* Get devnode parent */
610 cr = CM_Get_Parent(&dev_node, dev_node, 0);
611 if (cr != CR_SUCCESS)
612 goto end;
613
614 /* Get the compatible ids from parent devnode */
615 compatible_ids = hid_internal_get_devnode_property(dev_node, &DEVPKEY_Device_CompatibleIds, DEVPROP_TYPE_STRING_LIST);
616 if (!compatible_ids)
617 goto end;
618
619 /* Now we can parse parent's compatible IDs to find out the device bus type */
620 for (wchar_t* compatible_id = compatible_ids; *compatible_id; compatible_id += wcslen(compatible_id) + 1) {
621 /* Normalize to upper case */
622 hid_internal_towupper(compatible_id);
623
624 /* USB devices
625 https://docs.microsoft.com/windows-hardware/drivers/hid/plug-and-play-support
626 https://docs.microsoft.com/windows-hardware/drivers/install/standard-usb-identifiers */
627 if (wcsstr(compatible_id, L"USB") != NULL) {
628 dev->bus_type = HID_API_BUS_USB;
629 hid_internal_get_usb_info(dev, dev_node);
630 break;
631 }
632
633 /* Bluetooth devices
634 https://docs.microsoft.com/windows-hardware/drivers/bluetooth/installing-a-bluetooth-device */
635 if (wcsstr(compatible_id, L"BTHENUM") != NULL) {
636 dev->bus_type = HID_API_BUS_BLUETOOTH;
637 break;
638 }
639
640 /* Bluetooth LE devices */
641 if (wcsstr(compatible_id, L"BTHLEDEVICE") != NULL) {
642 dev->bus_type = HID_API_BUS_BLUETOOTH;
643 hid_internal_get_ble_info(dev, dev_node);
644 break;
645 }
646
647 /* I2C devices
648 https://docs.microsoft.com/windows-hardware/drivers/hid/plug-and-play-support-and-power-management */
649 if (wcsstr(compatible_id, L"PNP0C50") != NULL) {
650 dev->bus_type = HID_API_BUS_I2C;

Callers 1

Tested by

no test coverage detected