From 8e9c45859f30d515bdbf18c0ca7904d63405dfb5 Mon Sep 17 00:00:00 2001 From: Benson Leung Date: Tue, 28 Jul 2020 17:15:27 -0700 Subject: Add a way to get iConfiguration Adds a getter for a gusb_device to get the string index for the active configuration's description. --- gusb/gusb-device.c | 30 ++++++++++++++++++++++++++++++ gusb/gusb-device.h | 1 + gusb/libgusb.ver | 6 ++++++ 3 files changed, 37 insertions(+) diff --git a/gusb/gusb-device.c b/gusb/gusb-device.c index be03131..fb29a13 100644 --- a/gusb/gusb-device.c +++ b/gusb/gusb-device.c @@ -1776,6 +1776,36 @@ g_usb_device_get_pid_as_str (GUsbDevice *device) NULL); } +/** + * g_usb_device_get_configuration_index + * @device: a #GUsbDevice + * + * Get the index for the active Configuration string descriptor + * ie, iConfiguration. + * + * Return value: a string descriptor index. + * + * Since: 0.3.5 + **/ +guint8 +g_usb_device_get_configuration_index (GUsbDevice *device) +{ + struct libusb_config_descriptor *config; + gint rc; + guint8 index; + + g_return_val_if_fail (G_USB_IS_DEVICE (device), 0); + + rc = libusb_get_active_config_descriptor (device->priv->device, &config); + g_return_val_if_fail (rc == 0, 0); + + index = config->iConfiguration; + + libusb_free_config_descriptor (config); + return index; +} + + /** * g_usb_device_get_manufacturer_index: * @device: a #GUsbDevice diff --git a/gusb/gusb-device.h b/gusb/gusb-device.h index 7c7ec6f..e5d45f8 100644 --- a/gusb/gusb-device.h +++ b/gusb/gusb-device.h @@ -156,6 +156,7 @@ guint8 g_usb_device_get_device_class (GUsbDevice *device); guint8 g_usb_device_get_device_subclass (GUsbDevice *device); guint8 g_usb_device_get_device_protocol (GUsbDevice *device); +guint8 g_usb_device_get_configuration_index (GUsbDevice *device); guint8 g_usb_device_get_manufacturer_index (GUsbDevice *device); guint8 g_usb_device_get_product_index (GUsbDevice *device); guint8 g_usb_device_get_serial_number_index (GUsbDevice *device); diff --git a/gusb/libgusb.ver b/gusb/libgusb.ver index a58a451..b32ca1c 100644 --- a/gusb/libgusb.ver +++ b/gusb/libgusb.ver @@ -141,3 +141,9 @@ LIBGUSB_0.3.3 { g_usb_interface_get_endpoints; local: *; } LIBGUSB_0.3.1; + +LIBGUSB_0.3.5 { + global: + g_usb_device_get_configuration_index; + local: *; +} LIBGUSB_0.3.3; -- cgit v1.2.1