Ticket #173 (new defect)

Opened 4 years ago

Last modified 4 years ago

libusb_get_max_iso_packet_size() with USB3.0, return the USB2.0 value

Reported by: manzo Owned by:
Milestone: Component: libusb-1.0 Darwin backend
Keywords: Cc:
Blocked By: Blocks:

Description

libusb_get_max_iso_packet_size() not consider the libusb_ss_endpoint_companion_descriptor and return the size in the USB2.0 descriptor, for understand in the USB3.0 the isochronous work with burst

I propose this patch:

diff --git a/libusb/core.c b/libusb/core.c
index 90c4247..7043ee3 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -864,7 +864,7 @@ int API_EXPORTED libusb_get_max_iso_packet_size(libusb_device *dev,
        const struct libusb_endpoint_descriptor *ep;
        enum libusb_transfer_type ep_type;
        uint16_t val;
-       int r;
+       int r,s;

        r = libusb_get_active_config_descriptor(dev, &config);
        if (r < 0) {
@@ -877,6 +877,20 @@ int API_EXPORTED libusb_get_max_iso_packet_size(libusb_device *dev,
        if (!ep)
                return LIBUSB_ERROR_NOT_FOUND;

+       s = libusb_get_device_speed(dev);
+       if (s>=4 && ep->extra && ep->extra_length>0) {
+               // USB3.0
+               struct libusb_ss_endpoint_companion_descriptor *ss_ep_companion = NULL;
+               libusb_parse_ss_endpoint_comp(ep->extra, ep->extra_length, &ss_ep_companion);
+               if (ss_ep_companion) {
+                       r = ss_ep_companion->wBytesPerInterval;
+                       libusb_free_ss_endpoint_comp(ss_ep_companion);
+                       libusb_free_config_descriptor(config);
+                       return r;
+               }
+       }
+
+       // USB1.0, USB2.0 low speed, USB2.0 high speed
        val = ep->wMaxPacketSize;
        ep_type = ep->bmAttributes & 0x3;
        libusb_free_config_descriptor(config);

Change History

comment:1 Changed 4 years ago by hjelmn

I am not sure the wBytesPerInterval value is what you want in this case. I think this might be related to #77.

Can you post the complete descriptors for your device to this ticket. You can get them by running the testlibusb1 example in 1.0.16 with the -v option.

Note: See TracTickets for help on using tickets.