summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo CaƱuelo <ricardo.canuelo@collabora.com>2021-09-30 08:22:21 +0200
committerRichard Hughes <richard@hughsie.com>2021-09-30 10:13:16 +0100
commit4e118c154dde70e196c4381bd97790a9413c3552 (patch)
treed8f59f8524ee99cab1ff697c788c248c3c89a5bb
parent041776c222694e8cd1bf1175fbed9da0c7498a08 (diff)
downloadgusb-master.tar.gz
Add g_usb_device_get_string_descriptor_bytes_fullmaster
Some devices won't answer to a request with a 128-byte data buffer, this allows the user to specify the size of the request data buffer. g_usb_device_get_string_descriptor_bytes still uses the default buffer size (128 bytes).
-rw-r--r--gusb/gusb-device.c47
-rw-r--r--gusb/gusb-device.h19
-rw-r--r--gusb/libgusb.ver6
3 files changed, 57 insertions, 15 deletions
diff --git a/gusb/gusb-device.c b/gusb/gusb-device.c
index 16a5527..184bc39 100644
--- a/gusb/gusb-device.c
+++ b/gusb/gusb-device.c
@@ -916,9 +916,10 @@ g_usb_device_get_string_descriptor (GUsbDevice *device,
}
/**
- * g_usb_device_get_string_descriptor_bytes:
+ * g_usb_device_get_string_descriptor_bytes_full:
* @desc_index: the index for the string descriptor to retrieve
* @langid: the language ID
+ * @length: size of the request data buffer
* @error: a #GError, or %NULL
*
* Get a raw string descriptor from the device. The returned string should be freed
@@ -926,16 +927,17 @@ g_usb_device_get_string_descriptor (GUsbDevice *device,
*
* Return value: (transfer full): a possibly UTF-16 string, or NULL on error.
*
- * Since: 0.3.6
+ * Since: 0.3.8
**/
GBytes *
-g_usb_device_get_string_descriptor_bytes (GUsbDevice *device,
- guint8 desc_index,
- guint16 langid,
- GError **error)
+g_usb_device_get_string_descriptor_bytes_full (GUsbDevice *device,
+ guint8 desc_index,
+ guint16 langid,
+ gsize length,
+ GError **error)
{
gint rc;
- unsigned char buf[128];
+ g_autofree guint8 *buf = g_malloc0(length);
g_return_val_if_fail (G_USB_IS_DEVICE (device), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@@ -947,7 +949,7 @@ g_usb_device_get_string_descriptor_bytes (GUsbDevice *device,
rc = libusb_get_string_descriptor (device->priv->handle,
desc_index, langid,
- buf, sizeof(buf));
+ buf, length);
if (rc < 0) {
g_usb_device_libusb_error_to_gerror (device, rc, error);
return NULL;
@@ -956,6 +958,35 @@ g_usb_device_get_string_descriptor_bytes (GUsbDevice *device,
return g_bytes_new (buf, rc);
}
+/**
+ * g_usb_device_get_string_descriptor_bytes:
+ * @desc_index: the index for the string descriptor to retrieve
+ * @langid: the language ID
+ * @error: a #GError, or %NULL
+ *
+ * Get a raw string descriptor from the device. The returned string should be freed
+ * with g_bytes_unref() when no longer needed.
+ * The descriptor will be at most 128 btes in length, if you need to
+ * issue a request with either a smaller or larger descriptor, you can
+ * use g_usb_device_get_string_descriptor_bytes_full instead.
+ *
+ * Return value: (transfer full): a possibly UTF-16 string, or NULL on error.
+ *
+ * Since: 0.3.6
+ **/
+GBytes *
+g_usb_device_get_string_descriptor_bytes (GUsbDevice *device,
+ guint8 desc_index,
+ guint16 langid,
+ GError **error)
+{
+ return g_usb_device_get_string_descriptor_bytes_full(device,
+ desc_index,
+ langid,
+ 128,
+ error);
+}
+
typedef gssize (GUsbDeviceTransferFinishFunc) (GUsbDevice *device, GAsyncResult *res, GError **error);
typedef struct {
diff --git a/gusb/gusb-device.h b/gusb/gusb-device.h
index 5430fb6..722104a 100644
--- a/gusb/gusb-device.h
+++ b/gusb/gusb-device.h
@@ -212,13 +212,18 @@ gboolean g_usb_device_set_interface_alt (GUsbDevice *device,
guint8 alt,
GError **error);
-gchar *g_usb_device_get_string_descriptor (GUsbDevice *device,
- guint8 desc_index,
- GError **error);
-GBytes *g_usb_device_get_string_descriptor_bytes (GUsbDevice *device,
- guint8 desc_index,
- guint16 langid,
- GError **error);
+gchar *g_usb_device_get_string_descriptor (GUsbDevice *device,
+ guint8 desc_index,
+ GError **error);
+GBytes *g_usb_device_get_string_descriptor_bytes (GUsbDevice *device,
+ guint8 desc_index,
+ guint16 langid,
+ GError **error);
+GBytes *g_usb_device_get_string_descriptor_bytes_full (GUsbDevice *device,
+ guint8 desc_index,
+ guint16 langid,
+ gsize length,
+ GError **error);
/* sync -- TODO: use GCancellable and GUsbSource */
gboolean g_usb_device_control_transfer (GUsbDevice *device,
diff --git a/gusb/libgusb.ver b/gusb/libgusb.ver
index 7c9e044..f59d1a9 100644
--- a/gusb/libgusb.ver
+++ b/gusb/libgusb.ver
@@ -153,3 +153,9 @@ LIBGUSB_0.3.6 {
g_usb_device_get_string_descriptor_bytes;
local: *;
} LIBGUSB_0.3.5;
+
+LIBGUSB_0.3.8 {
+ global:
+ g_usb_device_get_string_descriptor_bytes_full;
+ local: *;
+} LIBGUSB_0.3.6;