68 {
69 libusb_device **list;
70 libusb_device_handle *h = NULL;
71 ssize_t cnt = libusb_get_device_list(backend->
ctx, &list);
72
75 }
76
77 if (cnt < 0) {
78 DBG_ERR(
"Failed to get device list: %s", libusb_strerror(cnt));
79 return NULL;
80 }
81
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));
88 continue;
89 }
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));
95 continue;
96 }
97 if (backend->
serial != 0) {
98 unsigned char data[16] = {0};
99
100 ret = libusb_get_string_descriptor_ascii(h, desc.iSerialNumber, data,
101 sizeof(data));
102
103 unsigned long devSerial = strtoul((char *) data, NULL, 10);
104
105 if (devSerial != backend->
serial) {
106 DBG_INFO(
"Device %zd has serial %lu, not matching searched %lu", i,
107 devSerial, backend->
serial);
109 }
110 }
111
112 ret = libusb_claim_interface(h, 0);
114 DBG_ERR(
"Failed to claim interface: %s of device %zd",
115 libusb_strerror(
ret), i);
117 }
118
119 break;
121 libusb_close(h);
122 h = NULL;
123 }
124 }
125
126 libusb_free_device_list(list, 1);
128 if (h) {
129
130
131
133 int transferred = 0;
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);
136 }
137 return true;
138 } else {
139 return false;
140 }
141}
uint32_t next(octet_iterator &it, octet_iterator end)
#define YH_PID
Device product ID.
#define YH_MSG_BUF_SIZE
Maximum length of message buffer.
#define YH_VID
Device vendor ID.