diff options
author | Orhan aib Kavrakoglu <aibok42@gmail.com> | 2022-07-21 09:32:21 +0300 |
---|---|---|
committer | Tormod Volden <debian.tormod@gmail.com> | 2023-01-20 17:50:55 +0100 |
commit | 6c2149662ad777e72856e968c2c68ebddf7d49a7 (patch) | |
tree | 6a629af538ffe19a90513a7c84bd88e3fdd904f6 | |
parent | b1445d91462234acd2a2371d7e5850beed5f3bc8 (diff) | |
download | libusb-6c2149662ad777e72856e968c2c68ebddf7d49a7.tar.gz |
core: Factor out helper get_endpoint_max_packet_size()
[Tormod: Initialize r to please compilers]
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
-rw-r--r-- | libusb/core.c | 56 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
2 files changed, 34 insertions, 24 deletions
diff --git a/libusb/core.c b/libusb/core.c index e43e47c..848679b 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -1081,6 +1081,38 @@ out: return r; } +static int get_endpoint_max_packet_size(libusb_device *dev, + const struct libusb_endpoint_descriptor *ep) +{ + struct libusb_ss_endpoint_companion_descriptor *ss_ep_cmp; + enum libusb_endpoint_transfer_type ep_type; + uint16_t val; + int r = 0; + int speed; + + speed = libusb_get_device_speed(dev); + if (speed >= LIBUSB_SPEED_SUPER) { + r = libusb_get_ss_endpoint_companion_descriptor(dev->ctx, ep, &ss_ep_cmp); + if (r == LIBUSB_SUCCESS) { + r = ss_ep_cmp->wBytesPerInterval; + libusb_free_ss_endpoint_companion_descriptor(ss_ep_cmp); + } + } + + /* If the device isn't a SuperSpeed device or retrieving the SS endpoint didn't worked. */ + if (speed < LIBUSB_SPEED_SUPER || r < 0) { + val = ep->wMaxPacketSize; + ep_type = (enum libusb_endpoint_transfer_type) (ep->bmAttributes & 0x3); + + r = val & 0x07ff; + if (ep_type == LIBUSB_ENDPOINT_TRANSFER_TYPE_ISOCHRONOUS + || ep_type == LIBUSB_ENDPOINT_TRANSFER_TYPE_INTERRUPT) + r *= (1 + ((val >> 11) & 3)); + } + + return r; +} + /** \ingroup libusb_dev * Calculate the maximum packet size which a specific endpoint is capable is * sending or receiving in the duration of 1 microframe @@ -1114,11 +1146,7 @@ int API_EXPORTED libusb_get_max_iso_packet_size(libusb_device *dev, { struct libusb_config_descriptor *config; const struct libusb_endpoint_descriptor *ep; - struct libusb_ss_endpoint_companion_descriptor *ss_ep_cmp; - enum libusb_endpoint_transfer_type ep_type; - uint16_t val; int r; - int speed; r = libusb_get_active_config_descriptor(dev, &config); if (r < 0) { @@ -1133,25 +1161,7 @@ int API_EXPORTED libusb_get_max_iso_packet_size(libusb_device *dev, goto out; } - speed = libusb_get_device_speed(dev); - if (speed >= LIBUSB_SPEED_SUPER) { - r = libusb_get_ss_endpoint_companion_descriptor(dev->ctx, ep, &ss_ep_cmp); - if (r == LIBUSB_SUCCESS) { - r = ss_ep_cmp->wBytesPerInterval; - libusb_free_ss_endpoint_companion_descriptor(ss_ep_cmp); - } - } - - /* If the device isn't a SuperSpeed device or retrieving the SS endpoint didn't worked. */ - if (speed < LIBUSB_SPEED_SUPER || r < 0) { - val = ep->wMaxPacketSize; - ep_type = (enum libusb_endpoint_transfer_type) (ep->bmAttributes & 0x3); - - r = val & 0x07ff; - if (ep_type == LIBUSB_ENDPOINT_TRANSFER_TYPE_ISOCHRONOUS - || ep_type == LIBUSB_ENDPOINT_TRANSFER_TYPE_INTERRUPT) - r *= (1 + ((val >> 11) & 3)); - } + r = get_endpoint_max_packet_size(dev, ep); out: libusb_free_config_descriptor(config); diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 15fdcc8..cd5097b 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11772 +#define LIBUSB_NANO 11773 |