summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2011-02-17 13:17:55 +0100
committerHans de Goede <hdegoede@redhat.com>2011-06-17 11:01:21 +0200
commite42841fe375d33a2124faa0579880233918ea755 (patch)
treea0278d38509ed5f1b1be472a1197a951664ef147
parentae7bd889ec7e968356a83bbbad76cf2797c0fb28 (diff)
downloadlibusb-e42841fe375d33a2124faa0579880233918ea755.tar.gz
Add a libusb_get_device_speed function
Reworked version of my earlier patch, largely modelled (if not copy and pasted) after / from Trygve Laugstøl's <trygvis@inamo.no> similar patch. Note this patch does not add any OS specific code, I've a Linux version in a separate patch. Signed-off-By: Hans de Goede <hdegoede@redhat.com>
-rw-r--r--libusb/core.c12
-rw-r--r--libusb/libusb.h21
-rw-r--r--libusb/libusbi.h1
3 files changed, 34 insertions, 0 deletions
diff --git a/libusb/core.c b/libusb/core.c
index 2a0d5b0..a8aa87d 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -523,6 +523,7 @@ struct libusb_device *usbi_alloc_device(struct libusb_context *ctx,
dev->ctx = ctx;
dev->refcnt = 1;
dev->session_data = session_id;
+ dev->speed = LIBUSB_SPEED_UNKNOWN;
memset(&dev->os_priv, 0, priv_size);
usbi_mutex_lock(&ctx->usb_devs_lock);
@@ -680,6 +681,17 @@ uint8_t API_EXPORTED libusb_get_device_address(libusb_device *dev)
return dev->device_address;
}
+/** \ingroup dev
+ * Get the negotiated speed of the device.
+ * \param dev a device
+ * \returns the device speed or LIBUSB_SPEED_UNKNOWN if the OS doesn't know or
+ * support returning the negotiated speed.
+ */
+enum libusb_speed API_EXPORTED libusb_get_device_speed(libusb_device *dev)
+{
+ return dev->speed;
+}
+
static const struct libusb_endpoint_descriptor *find_endpoint(
struct libusb_config_descriptor *config, unsigned char endpoint)
{
diff --git a/libusb/libusb.h b/libusb/libusb.h
index 45e20ec..3ea2c99 100644
--- a/libusb/libusb.h
+++ b/libusb/libusb.h
@@ -684,6 +684,26 @@ typedef struct libusb_device libusb_device;
*/
typedef struct libusb_device_handle libusb_device_handle;
+/** \ingroup dev
+ * Speed codes. Indicates the speed at which the device is operating.
+ */
+enum libusb_speed {
+ /** The OS doesn't report or know the device speed. */
+ LIBUSB_SPEED_UNKNOWN = 0,
+
+ /** The device is operating at low speed (1.5MBit/s). */
+ LIBUSB_SPEED_LOW = 1,
+
+ /** The device is operating at full speed (12MBit/s). */
+ LIBUSB_SPEED_FULL = 2,
+
+ /** The device is operating at high speed (480MBit/s). */
+ LIBUSB_SPEED_HIGH = 3,
+
+ /** The device is operating at super speed (5000MBit/s). */
+ LIBUSB_SPEED_SUPER = 4,
+};
+
/** \ingroup misc
* Error codes. Most libusb functions return 0 on success or one of these
* codes on failure.
@@ -890,6 +910,7 @@ void LIBUSB_CALL libusb_free_config_descriptor(
struct libusb_config_descriptor *config);
uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev);
uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev);
+enum libusb_speed LIBUSB_CALL libusb_get_device_speed(libusb_device *dev);
int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev,
unsigned char endpoint);
int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev,
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index 1ea7f26..564ee3e 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -276,6 +276,7 @@ struct libusb_device {
uint8_t bus_number;
uint8_t device_address;
uint8_t num_configurations;
+ enum libusb_speed speed;
struct list_head list;
unsigned long session_data;