Ticket #77 (new defect)

Opened 7 years ago

Last modified 5 years ago

get_max_packet_size returns bad value when alternative interface is used

Reported by: eddie.cohen Owned by:
Milestone: Component: libusb-1.0
Keywords: Cc:
Blocked By: Blocks:

Description

libusb_get_max_packet_size() and libusb_get_max_iso_packet_size() does not consider current alternative interface.

I have a device which has endpoint 0x81 in both default interface and alternative interface.
When alternative interface is in use, and a call to libusb_get_max_packet_size() takes place, find_endpoint() function stops as soon as it finds the endpoint in the first interface.

Change History

comment:1 Changed 7 years ago by eddie.cohen

(it returns the packet size of this EP in the first interface, instead of in the alternative one)

comment:2 Changed 7 years ago by stuge

Tim commented on this on the mailing list: http://marc.info/?m=129183288916331

comment:3 follow-up: Changed 5 years ago by xiaofan

Tim's comments indicate that this is probably not worth fixing since the libusb user needs to know the device in order to use libusb anyway. Shall we close this ticket?

That's a tricky situation, because neither the front-end nor the
back-end stores the current alternate setting in its state information.
To a certain extent, the application needs to know the max packet sizez
in order to choose an alternate setting, so one could decide this isn't
worth fixing.

comment:4 in reply to: ↑ 3 ; follow-up: Changed 5 years ago by hansdegoede

Replying to xiaofan:

Tim's comments indicate that this is probably not worth fixing since the libusb user needs to know the device in order to use libusb anyway. Shall we close this ticket?

That's a tricky situation, because neither the front-end nor the
back-end stores the current alternate setting in its state information.
To a certain extent, the application needs to know the max packet sizez
in order to choose an alternate setting, so one could decide this isn't
worth fixing.

If an application supports a certain USB class of devices, it will not know the exact details, and instead it will need to get them from the descriptors. Unfortunately libusb has a histtory of getting max packet size wrong. First there was:
int libusb_get_max_packet_size(libusb_device *dev, unsigned char endpoint);

Which does not take the multiplier bits used for isoc endpoints into account and thus gets it wrong for isoc endpoints, then the following was added:
int libusb_get_max_iso_packet_size(libusb_device *dev, unsigned char endpoint);

But that does not take the alt setting into account, instead just taking the first interface descriptor which holds the asked ep, which usually will be alt 0 and for alt 0 isoc max packet size is always 0!

So the second function is really really wrong / useless.

So I suggest adding a third function:
int libusb_get_max_iso_packet_size_for_alt_setting(libusb_device *dev, int alternate_setting, unsigned char endpoint);

Which is actually useful / useable for isoc endpoints, and then documenting that libusb_get_max_iso_packet_size() is broken and should not be used, and tell the user to use libusb_get_max_iso_packet_size_for_alt_setting() instead.

comment:5 in reply to: ↑ 4 Changed 5 years ago by stuge

Replying to hansdegoede:

int libusb_get_max_iso_packet_size_for_alt_setting(libusb_device *dev, int alternate_setting, unsigned char endpoint);

How about:
int libusb_get_wmaxpacketsize(libusb_device *dev, int alternate_setting, unsigned char endpoint);

The primary points being that this applies to any endpoint descriptor, not just isochronous, and that the name is shorter. :)

and then documenting that libusb_get_max_iso_packet_size() is broken and should not be used, and tell the user to use libusb_get_max_iso_packet_size_for_alt_setting() instead.

Yes completely agreed.

Note: See TracTickets for help on using tickets.