70 libusb_device_handle *h = NULL;
71 ssize_t cnt = libusb_get_device_list(backend->
ctx, &list);
78 DBG_ERR(
"Failed to get device list: %s", libusb_strerror(cnt));
82 for (ssize_t i = 0; i < cnt; i++) {
83 struct libusb_device_descriptor desc;
84 int ret = libusb_get_device_descriptor(list[i], &desc);
86 DBG_INFO(
"Failed to get descriptor for device %zd: %s", i,
87 libusb_strerror(
ret));
90 if (desc.idVendor ==
YH_VID && desc.idProduct ==
YH_PID) {
91 ret = libusb_open(list[i], &h);
92 if (
ret != 0 || h == NULL) {
93 DBG_INFO(
"Failed to open device for index %zd: %s", i,
94 libusb_strerror(
ret));
97 if (backend->
serial != 0) {
98 unsigned char data[16] = {0};
100 ret = libusb_get_string_descriptor_ascii(h, desc.iSerialNumber, data,
103 unsigned long devSerial = strtoul((
char *) data, NULL, 10);
105 if (devSerial != backend->
serial) {
106 DBG_INFO(
"Device %zd has serial %lu, not matching searched %lu", i,
107 devSerial, backend->
serial);
112 ret = libusb_claim_interface(h, 0);
114 DBG_ERR(
"Failed to claim interface: %s of device %zd",
115 libusb_strerror(
ret), i);
126 libusb_free_device_list(list, 1);
134 if (libusb_bulk_transfer(h, 0x81,
buf,
sizeof(
buf), &transferred, 1) == 0) {
135 DBG_INFO(
"%d bytes of stale data read from device", transferred);