summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2011-09-06 10:38:00 +0000
committerVitali Lovich <vlovich@aliph.com>2011-09-06 10:53:23 +0100
commitc384ec68aa7471863e989b5be8769e86315c759c (patch)
treed1e9f1ab3e643179a48921f8b5337cfe5248cded
parent328d9fd76aba03b62d0dfb70e95d12108718edf8 (diff)
downloadlibusb-c384ec68aa7471863e989b5be8769e86315c759c.tar.gz
Add new API function libusb_get_device_speed()
Reworked version of my earlier patch, largely modelled after (if not copy and pasted from) Trygve Laugstøl's <trygvis@inamo.no> similar commit 5a6541e0d80fb1f21e2b960bc2337a612f9d74fb in git://git.libusb.org/libusb-trygvis.git http://git.libusb.org/libusb-trygvis.git http://git.libusb.org/?p=libusb-trygvis.git;a=commitdiff;h=5a6541e0d This patch does not add any OS specific code. The supporting code in each backend follows in separate patches. Signed-off-By: Hans de Goede <hdegoede@redhat.com>
-rw-r--r--libusb/core.c12
-rw-r--r--libusb/libusb.h20
-rw-r--r--libusb/libusbi.h1
3 files changed, 33 insertions, 0 deletions
diff --git a/libusb/core.c b/libusb/core.c
index 840ab0c..3969fd5 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -524,6 +524,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);
@@ -737,6 +738,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 d466109..9e97b16 100644
--- a/libusb/libusb.h
+++ b/libusb/libusb.h
@@ -675,6 +675,25 @@ 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
@@ -892,6 +911,7 @@ uint8_t LIBUSB_CALL libusb_get_port_number(libusb_device *dev);
libusb_device * LIBUSB_CALL libusb_get_parent(libusb_device *dev);
int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t* path, uint8_t path_length);
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 c7cf83b..0ea4878 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -279,6 +279,7 @@ struct libusb_device {
struct libusb_device* parent_dev;
uint8_t device_address;
uint8_t num_configurations;
+ enum libusb_speed speed;
struct list_head list;
unsigned long session_data;