+static int rx_endpoint, tx_endpoint;
+
+static int parse_descriptors(libusb_device *dev)
+{
+ int err;
+ struct libusb_config_descriptor *desc;
+
+ if (err = libusb_get_active_config_descriptor(dev, &desc)) {
+ log_error("libusb_get_config_descriptor failed: error %d", err);
+ return 0;
+ }
+ if (desc->bNumInterfaces != 1) {
+ log_error("Unexpected number of interfaces: %d", desc->bNumInterfaces);
+ goto failed;
+ }
+
+ const struct libusb_interface *iface = &desc->interface[0];
+ if (iface->num_altsetting != 1) {
+ log_error("Unexpected number of alternate interface settings: %d", iface->num_altsetting);
+ goto failed;
+ }
+
+ const struct libusb_interface_descriptor *ifd = &iface->altsetting[0];
+ if (ifd->bNumEndpoints != 2) {
+ log_error("Unexpected number of endpoints: %d", ifd->bNumEndpoints);
+ goto failed;
+ }
+
+ rx_endpoint = tx_endpoint = -1;
+ for (int i=0; i<2; i++) {
+ const struct libusb_endpoint_descriptor *epd = &ifd->endpoint[i];
+ if (epd->bEndpointAddress & 0x80)
+ rx_endpoint = epd->bEndpointAddress;
+ else
+ tx_endpoint = epd->bEndpointAddress;
+ }
+ if (rx_endpoint < 0 || tx_endpoint < 0) {
+ log_error("Failed to identify endpoints");
+ goto failed;
+ }
+
+ log_pkt("Found endpoints: rx==%02x tx=%02x\n", rx_endpoint, tx_endpoint);
+ libusb_free_config_descriptor(desc);
+ return 1;
+
+failed:
+ libusb_free_config_descriptor(desc);
+ return 0;
+}
+